|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.topologi.diffx.xml.esc.XMLEscapeWriterASCII
public final class XMLEscapeWriterASCII
A utility class for escaping XML data when the intended encoding is ASCII or ASCII compatible.
Any unicode code point greater then (#x7E) will be encoded usnig the numeric character entity.
Constructor Summary | |
---|---|
XMLEscapeWriterASCII(Writer writer)
Creates a new XML escape writer using the utf-8 encoding. |
Method Summary | |
---|---|
String |
getEncoding()
Returns the encoding for this writer. |
void |
writeAttValue(char[] ch,
int off,
int len)
Writes a well-formed attribute value. |
void |
writeAttValue(String value)
Default implementation calling the XMLEscapeWriter.writeAttValue(char[], int, int) . |
void |
writeText(char c)
Replace characters which are invalid in element values, by the corresponding entity in a given String . |
void |
writeText(char[] ch,
int off,
int len)
Writes a well-formed XML literal text value. |
void |
writeText(String value)
Default implementation calling the XMLEscapeWriter.writeAttValue(char[], int, int) . |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.topologi.diffx.xml.esc.XMLEscapeWriter |
---|
getEncoding, writeAttValue, writeText |
Constructor Detail |
---|
public XMLEscapeWriterASCII(Writer writer) throws NullPointerException
writer
- The writer to wrap.
NullPointerException
- if the writer is null
.Method Detail |
---|
public void writeAttValue(char[] ch, int off, int len) throws IOException
XMLEscapeWriter
This method must replace any character in the specified value by the corresponding numeric character reference or the predefined XML general entities, if the character is not allowed or not in the encoding range.
Attribute values must not contain any ampersand (#x26) or less than (#x3C) characters. This method will replace them by the corresponding named entity.
Quotes and apostrophes must also be escaped depending on what was used in the attribute markup. Since this method is not aware of which type of quotes was used, both are escaped. Double quotes (#x22) are escaped using a named character entity. In case the end result is HTML 4, single quotes (#x27) are escaped using a numeric character entity.
Characters in ranges (#x00-#x1F) and (#x80-#x9F) are silently ignored except for line feed (#x0A), carriage return (#x0D) and tab (#x09).
writeAttValue
in interface XMLEscapeWriter
ch
- The value that needs to be attribute-escaped.off
- The start (offset) of the characters.len
- The length of characters to.
IOException
- If thrown by the underlying writer.public void writeText(char[] ch, int off, int len) throws IOException
XMLEscapeWriter
This method must replace any character in the specified text by the corresponding numeric character reference or the predefined XML general entities, if the character is not allowed or not in the encoding range.
Literal text values must not contain any 'ampersand' (#x26) or 'less than' (#x3C) characters. This method will replace them by the corresponding named entity.
Out of precaution this method may also encode the 'greater than' (#xCE) character, in case it follows "]]".
Characters in ranges (#x00-#x1F) and (#x80-#x9F) are silently ignored except for line feed (#x0A), carriage return (#x0D) and tab (#x09).
writeText
in interface XMLEscapeWriter
ch
- The value that needs to be attribute-escaped.off
- The start (offset) of the characters.len
- The length of characters to.
IOException
- If thrown by the underlying writer.public void writeText(char c) throws IOException
String
.
these characters are:
Note: this function assumes that there are no entities in the given String. If there are existing entities, then the ampersand character will be escaped by the ampersand entity. Writes the character so that the text value for the element remains well-formed.
Some implementations may unable to deal with java characters outside the Basic Multilingual Plane (BMP). As a result, java characters which correspond to UTF-16 surrogate pairs (#xD800 - 0xDFFF) in may be not be handled appropriately.
Unicode Transformation Format (UTF) implementation should copy the java character verbatim.
writeText
in interface XMLEscapeWriter
c
- The character that needs to be text-escaped.
IOException
- If thrown by the underlying writer.public final void writeAttValue(String value) throws IOException
XMLEscapeWriter.writeAttValue(char[], int, int)
.
Writes a well-formed attribute value.
Method provided for convenience, using the same specifications as
XMLEscapeWriter.writeAttValue(char[], int, int)
.
writeAttValue
in interface XMLEscapeWriter
value
- The value that needs to be attribute-escaped.
IOException
- If thrown by the underlying writer.public final void writeText(String value) throws IOException
XMLEscapeWriter.writeAttValue(char[], int, int)
.
Writes the text string so that the text value for the element remains
well-formed.
Method provided for convenience, using the same specifications as
XMLEscapeWriter.writeText(char[], int, int)
.
This method should do nothing if the given value is null
.
writeText
in interface XMLEscapeWriter
value
- The text that needs to be text-escaped.
IOException
- If thrown by the underlying writer.public final String getEncoding()
getEncoding
in interface XMLEscapeWriter
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |