//bean file
package lovejsp;
public class encodeHtml
{
private String html="no input html";
public String getHtml()
{
return HTMLEncode(html);
}
public void setHtml(String html)
{
this.html = html ;
}
private static String HTMLEncode(String text)
{
if (text==null)
return "";
StringBuffer results = null;
char[] orig = null;
int beg = 0,len=text.length();
for (int i=0;i
{
char c = text.charAt(i);
switch(c){
case 0:
case "&":
case "<":
case ">":
case """:
if (results == null)
{
orig = text.toCharArray();
results = new StringBuffer(len+10);
}
if (i>beg)
results.append(orig,beg,i-beg);
beg = i + 1;
switch (c)
{
default : continue;
case "&": results.append("&"); break;
case "<": results.append("<"); break;
case ">": results.append(">"); break;
case """: results.append("""); break;
}
break;
} //switch
}// for i
if (results == null)
return text;
results.append(orig,beg,len-beg);
return results.toString();
}// HTMLEncode
} |