FileDocCategorySizeDatePackage
SimpleHTMLEncoder.javaAPI DocApache Lucene 1.91824Mon Feb 20 09:18:22 GMT 2006org.apache.lucene.search.highlight

SimpleHTMLEncoder

public class SimpleHTMLEncoder extends Object implements Encoder
Simple {@link Encoder} implementation to escape text for HTML output
author
Nicko Cadell

Fields Summary
Constructors Summary
public SimpleHTMLEncoder()

	
Methods Summary
public java.lang.StringencodeText(java.lang.String originalText)

		return htmlEncode(originalText);
	
public static final java.lang.StringhtmlEncode(java.lang.String plainText)
Encode string into HTML

		if (plainText == null || plainText.length() == 0)
		{
			return "";
		}

		StringBuffer result = new StringBuffer(plainText.length());

		for (int index=0; index<plainText.length(); index++) 
		{
			char ch = plainText.charAt(index);

			switch (ch) 
			{
			case '"":
				result.append(""");
				break;

			case '&":
				result.append("&");
				break;

			case '<":
				result.append("<");
				break;

			case '>":
				result.append(">");
				break;

			default:
				   if (ch < 128) 
				   {
			           result.append(ch);
			       } 
				   else 
			       {
			           result.append("&#").append((int)ch).append(";");
			       }
			}
		}

		return result.toString();