Top Description Inners Fields Constructors Methods
com.sun.faces.util

public Class HtmlUtils

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .IOException, .OutputStreamWriter, .UnsupportedEncodingException, .Writer, java.nio.charset.Charset, java.util.Arrays, .BitSet, .HashSet, .Set, com.sun.faces.RIConstants, com.sun.faces.config.WebConfiguration

Utility class for HTML. Kudos to Adam Winer (Oracle) for much of this code.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
HtmlUtils.MyByteArrayOutputStream

Private implementation of ByteArrayOutputStream.

Field Summary

Modifier and TypeField and Description
private static char
private static final char[]
private static String[]
private static String[]
private static String[]
private static final char[]
private static final BitSet
private static String[][]
private static final char[]
private static String[]
private static final char[]
private static String[]
private static String[]
private static String[]
private static final char[]
private static final int
private static String[]
private static String[]
private static final char[]
private static char[][]
private static final Set<String>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static int
_writeDecRef(Writer out, char[] buffer, int bufferIndex, int bufferLength, char ch)

Writes a character as a decimal escape.

private static int
addToBuffer(Writer out, char[] buffer, int bufferIndex, int bufferLength, char ch)

Add a character to the buffer, flushing the buffer if the buffer is full, and returning the new buffer index

private static int
addToBuffer(Writer out, char[] buffer, int bufferIndex, int bufferLength, char[] toAdd)

Add an array of characters to the buffer, flushing the buffer if the buffer is full, and returning the new buffer index.

private static void
encodeURIString(Writer out, String text, String encoding, int start)

private static void
encodeURIString(Writer out, char[] textBuff, String encoding, int start, int end)

private static int
flushBuffer(Writer out, char[] buffer, int bufferIndex)

Flush the contents of the buffer to the output stream and return the reset buffer index

private static char
intToHex(int i)

private static boolean
isAmpEscaped(String text, int idx)

private static boolean
isAmpEscaped(char[] text, int idx)

public static boolean
public static boolean
private static boolean
public static boolean
public static boolean
public static void
writeAttribute(Writer out, boolean escapeUnicode, boolean escapeIsocode, char[] buff, String text, char[] textBuff, boolean isScriptInAttributeValueEnabled)

Write a string attribute.

public static void
writeAttribute(Writer out, boolean escapeUnicode, boolean escapeIsocode, char[] buffer, char[] text)

public static void
writeAttribute(Writer out, boolean escapeUnicode, boolean escapeIsocode, char[] buff, char[] text, int start, int length, boolean isScriptInAttributeValueEnabled)

Write a character array attribute.

public static void
writeText(Writer out, boolean escapeUnicode, boolean escapeIsocode, char[] buffer, char[] text)

public static void
writeText(Writer out, boolean escapeUnicode, boolean escapeIsocode, char[] buff, char[] text, int start, int length)

Write char array text.

public static void
writeText(Writer out, boolean escapeUnicode, boolean escapeIsocode, char[] buff, String text, char[] textBuff)

Write String text.

private static int
writeTextChar(Writer out, boolean escapeUnicode, boolean escapeIsocode, char ch, int buffIndex, char[] buff, int buffLength)

public static void
writeTextForXML(Writer out, String text, char[] outbuf)

public static void
private static void
public static void
writeURL(Writer
a Writer for the output
out
,
String
the unencoded (or partially encoded) String
text
,
char[] textBuff, String
the character set encoding for after the first question mark
queryEncoding
)

Writes a string into URL-encoded format out to a Writer.

public static void
writeURL(Writer
a Writer for the output
out
,
char[]
char[] containing the content to write
textBuff
,
int start, int len, String
the character set encoding for after the first question mark
queryEncoding
)

Writes a string into URL-encoded format out to a Writer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_LAST_EMPTY_ELEMENT_STARTback to summary
private static char _LAST_EMPTY_ELEMENT_START
AMP_CHARSback to summary
private static final char[] AMP_CHARS
aNamesback to summary
private static String[] aNames
bNamesback to summary
private static String[] bNames
cNamesback to summary
private static String[] cNames
DEC_REF_STARTback to summary
private static final char[] DEC_REF_START
DONT_ENCODE_SETback to summary
private static final BitSet DONT_ENCODE_SET
emptyElementArrback to summary
private static String[][] emptyElementArr
EURO_CHARSback to summary
private static final char[] EURO_CHARS
fNamesback to summary
private static String[] fNames
GT_CHARSback to summary
private static final char[] GT_CHARS
hNamesback to summary
private static String[] hNames
iNamesback to summary
private static String[] iNames
lNamesback to summary
private static String[] lNames
LT_CHARSback to summary
private static final char[] LT_CHARS
MAX_BYTES_PER_CHARback to summary
private static final int MAX_BYTES_PER_CHAR
mNamesback to summary
private static String[] mNames
pNamesback to summary
private static String[] pNames
QUOT_CHARSback to summary
private static final char[] QUOT_CHARS
sISO8859_1_Entitiesback to summary
private static char[][] sISO8859_1_Entities
UTF_CHARSETback to summary
private static final Set<String> UTF_CHARSET

Constructor Detail

HtmlUtilsback to summary
private HtmlUtils()

Method Detail

_writeDecRefback to summary
private static int _writeDecRef(Writer out, char[] buffer, int bufferIndex, int bufferLength, char ch) throws IOException

Writes a character as a decimal escape. Hex escapes are smaller than the decimal version, but Netscape didn't support hex escapes until 4.7.4.

addToBufferback to summary
private static int addToBuffer(Writer out, char[] buffer, int bufferIndex, int bufferLength, char ch) throws IOException

Add a character to the buffer, flushing the buffer if the buffer is full, and returning the new buffer index

addToBufferback to summary
private static int addToBuffer(Writer out, char[] buffer, int bufferIndex, int bufferLength, char[] toAdd) throws IOException

Add an array of characters to the buffer, flushing the buffer if the buffer is full, and returning the new buffer index.

encodeURIStringback to summary
private static void encodeURIString(Writer out, String text, String encoding, int start) throws IOException
encodeURIStringback to summary
private static void encodeURIString(Writer out, char[] textBuff, String encoding, int start, int end) throws IOException
flushBufferback to summary
private static int flushBuffer(Writer out, char[] buffer, int bufferIndex) throws IOException

Flush the contents of the buffer to the output stream and return the reset buffer index

intToHexback to summary
private static char intToHex(int i)
isAmpEscapedback to summary
private static boolean isAmpEscaped(String text, int idx)
isAmpEscapedback to summary
private static boolean isAmpEscaped(char[] text, int idx)
isEmptyElementback to summary
public static boolean isEmptyElement(String name)
isISO8859_1encodingback to summary
public static boolean isISO8859_1encoding(String encoding)
isPrintableControlCharback to summary
private static boolean isPrintableControlChar(int ch)
isUTFencodingback to summary
public static boolean isUTFencoding(String encoding)
validateEncodingback to summary
public static boolean validateEncoding(String encoding)
writeAttributeback to summary
public static void writeAttribute(Writer out, boolean escapeUnicode, boolean escapeIsocode, char[] buff, String text, char[] textBuff, boolean isScriptInAttributeValueEnabled) throws IOException

Write a string attribute. Note that this code is duplicated below for character arrays - change both places if you make any changes!!!

writeAttributeback to summary
public static void writeAttribute(Writer out, boolean escapeUnicode, boolean escapeIsocode, char[] buffer, char[] text) throws IOException
writeAttributeback to summary
public static void writeAttribute(Writer out, boolean escapeUnicode, boolean escapeIsocode, char[] buff, char[] text, int start, int length, boolean isScriptInAttributeValueEnabled) throws IOException

Write a character array attribute. Note that this code is duplicated above for string - change both places if you make any changes!!!

writeTextback to summary
public static void writeText(Writer out, boolean escapeUnicode, boolean escapeIsocode, char[] buffer, char[] text) throws IOException
writeTextback to summary
public static void writeText(Writer out, boolean escapeUnicode, boolean escapeIsocode, char[] buff, char[] text, int start, int length) throws IOException

Write char array text.

writeTextback to summary
public static void writeText(Writer out, boolean escapeUnicode, boolean escapeIsocode, char[] buff, String text, char[] textBuff) throws IOException

Write String text.

writeTextCharback to summary
private static int writeTextChar(Writer out, boolean escapeUnicode, boolean escapeIsocode, char ch, int buffIndex, char[] buff, int buffLength) throws IOException
writeTextForXMLback to summary
public static void writeTextForXML(Writer out, String text, char[] outbuf) throws IOException
writeUnescapedTextForXMLback to summary
public static void writeUnescapedTextForXML(Writer out, String text) throws IOException
writeURIDoubleHexback to summary
private static void writeURIDoubleHex(Writer out, int i) throws IOException
writeURLback to summary
public static void writeURL(Writer out, String text, char[] textBuff, String queryEncoding) throws IOException, UnsupportedEncodingException

Writes a string into URL-encoded format out to a Writer.

All characters before the start of the query string will be encoded using UTF-8.

Characters after the start of the query string will be encoded using a client-defined encoding. You'll need to use the encoding that the server will expect. (HTML forms will generate query strings using the character encoding that the HTML itself was generated in.)

All characters will be encoded as needed for URLs, with the exception of the percent symbol ("%"). Because this is the character itself used for escaping, attempting to escape this character would cause this code to double-escape some strings. It also may be necessary to pre-escape some characters. In particular, a question mark ("?") is considered the start of the query string.

NOTE: This is method is duplicated below. The difference being the acceptance of a char[] for the text to write. Any changes made here, should be made below.

Parameters
out:Writer

a Writer for the output

text:String

the unencoded (or partially encoded) String

queryEncoding:String

the character set encoding for after the first question mark

writeURLback to summary
public static void writeURL(Writer out, char[] textBuff, int start, int len, String queryEncoding) throws IOException, UnsupportedEncodingException

Writes a string into URL-encoded format out to a Writer.

All characters before the start of the query string will be encoded using UTF-8.

Characters after the start of the query string will be encoded using a client-defined encoding. You'll need to use the encoding that the server will expect. (HTML forms will generate query strings using the character encoding that the HTML itself was generated in.)

All characters will be encoded as needed for URLs, with the exception of the percent symbol ("%"). Because this is the character itself used for escaping, attempting to escape this character would cause this code to double-escape some strings. It also may be necessary to pre-escape some characters. In particular, a question mark ("?") is considered the start of the query string.

NOTE: This is method is duplicated above. The difference being the acceptance of a String for the text to write. Any changes made here, should be made above.

Parameters
out:Writer

a Writer for the output

textBuff:char[]

char[] containing the content to write

queryEncoding:String

the character set encoding for after the first question mark

com.sun.faces.util back to summary

private Class HtmlUtils.MyByteArrayOutputStream

extends ByteArrayOutputStream
Class Inheritance

Private implementation of ByteArrayOutputStream.

Field Summary

Inherited from java.io.ByteArrayOutputStream:
bufcount

Constructor Summary

AccessConstructor and Description
public
MyByteArrayOutputStream(int initialCapacity)

Method Summary

Modifier and TypeMethod and Description
public byte[]

Returns:

buf
getBuf
()

Obtain access to the underlying byte array to prevent unecessary temp object creation.

Inherited from java.io.ByteArrayOutputStream:
closeresetsizetoByteArraytoStringtoStringtoStringtoStringwritewritewriteByteswriteTo

Constructor Detail

MyByteArrayOutputStreamback to summary
public MyByteArrayOutputStream(int initialCapacity)

Method Detail

getBufback to summary
public byte[] getBuf()

Obtain access to the underlying byte array to prevent unecessary temp object creation.

Returns:byte[]

buf