package com.middle.taglib;
import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class Replace extends BodyTagSupport
{
public Replace()
{
}
public void setReplace(String replace)
{
this.replace = replace;
}
public void setValue(String value)
{
this.value = value;
}
public void setWith(String with)
{
this.with = with;
}
public int doEndTag()
throws JspException
{
JspWriter out = pageContext.getOut();
BodyContent body = getBodyContent();
String inputStr;
if(value != null)
inputStr = value;
else
if(body != null && body.getString() != null)
inputStr = body.getString();
else
inputStr = "";
try
{
String outStr = inputStr.replaceAll(replace, with);
out.print(outStr);
}
catch(IOException ex)
{
throw new JspTagException("IOException: " + ex.toString());
}
return super.doEndTag();
}
private static final long serialVersionUID = 1L;
private String with;
private String replace;
private String value;
}