public static String htmlEncode(String inHtmlString)
{
String fromCharString="<>&";
String[] toStringArray = { "<", ">", "&" };
return encode(inHtmlString, fromCharString, toStringArray);
}
public static String encode(final String inS
, String fromCharString
, String[] toCharStringArray)
{
// return empty strings as they are
if (inS == null)
{
return inS;
}
if (inS.length() == 0)
{
return inS;
}
StringBuffer thisBuffer = new StringBuffer();
for(int i=0;i<inS.length();i++)
{
char thisChar = inS.charAt(i);
//it is not an escape character
String translatedString =
StringUtils.translateCharacter(thisChar
, fromCharString
, toCharStringArray);
if (translatedString == null)
{
//this character is not one of the
//chars that needs to be translated
thisBuffer.append(thisChar);
continue;
}
//needs translation
thisBuffer.append(translatedString);
}// end of for
return thisBuffer.toString();
}// end of func
public static String translateCharacter(char inChar
, String fromString
, String[] toStringArray)
{
int i = fromString.indexOf(inChar);
if (i == -1)
{
return null;
}
//Available in the in string
return toStringArray[i];
}
String html1 = new String("<p>Helloworld a < b</p>");
String eHtml1 = StringUtils.htmlEncode(html1);
System.out.println(html1 + "===>>" + eHtml1);
public class HtmlEncoderPart extends AFactoryPart
{
protected Object executeRequestForPart(String requestName, Map inArgs)
throws RequestExecutionException
{
try
{
String encodingKey= AppObjects.getValue(requestName + ".encodingKey");
String inEncodeString = (String)inArgs.get(encodingKey);
if (inEncodeString == null)
{
throw new RequestExecutionException("Encoding key not found in the args");
}
//encoding key value found
return StringUtils.htmlEncode(inEncodeString);
}
catch(ConfigException x)
{
throw new RequestExecutionException("Error:config errror",x);
}
}//eof-function
}//eof-class
request.encode_f1.classname=com.ai.parts.HtmlEncoderPart
request.encode_f1.encodingKey=field1
request.encode_f1.resultName=encoded_field1
Once this part is inserted into the execution pipeline there will be two fields available for painting "field1" and "encoded_field1".