Package org.znerd.xmlenc
Class XMLEncoder
- java.lang.Object
-
- org.znerd.xmlenc.XMLEncoder
-
public class XMLEncoder extends java.lang.ObjectEncodes character streams for an XML document.The following encodings are supported:
UTF-8UTF-16US-ASCII, with aliasASCII- all
ISO-8859encodings
- Since:
- xmlenc 0.1
- Version:
- $Revision: 1.210 $ $Date: 2005/10/24 09:54:53 $
- Author:
- Ernst de Haan (ernst.dehaan@nl.wanadoo.com), Jochen Schwoerer (j.schwoerer [at] web.de), Anthony Goubard (anthony.goubard@nl.wanadoo.com)
-
-
Constructor Summary
Constructors Constructor Description XMLEncoder(java.lang.String encoding)Deprecated.Deprecated since xmlenc 0.47.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidattribute(java.io.Writer out, java.lang.String name, java.lang.String value, char quotationMark, boolean escapeAmpersands)Writes an attribute assignment.voiddeclaration(java.io.Writer out)Writes an XML declaration.static XMLEncodergetEncoder(java.lang.String encoding)Retrieves anXMLEncoderfor the specified encoding.java.lang.StringgetEncoding()Returns the encoding.voidtext(java.io.Writer out, char c)Deprecated.Deprecated since xmlenc 0.51.voidtext(java.io.Writer out, char[] ch, int start, int length, boolean escapeAmpersands)Writes text from the specified character array.voidtext(java.io.Writer out, char c, boolean escapeAmpersands)Writes the specified character.voidtext(java.io.Writer out, java.lang.String text, boolean escapeAmpersands)Writes the specified text.voidwhitespace(java.io.Writer out, char[] ch, int start, int length)Writes whitespace from the specified character array.voidwhitespace(java.io.Writer out, java.lang.String s)Writes the specified whitespace string.
-
-
-
Constructor Detail
-
XMLEncoder
public XMLEncoder(java.lang.String encoding) throws java.lang.IllegalArgumentException, java.io.UnsupportedEncodingExceptionDeprecated.Deprecated since xmlenc 0.47. Use the factory methodgetEncoder(String)instead.Constructs a newXMLEncoderinstance.- Parameters:
encoding- the name of the encoding, notnull.- Throws:
java.lang.IllegalArgumentException- ifencoding == null.java.io.UnsupportedEncodingException- if the specified encoding is not supported.
-
-
Method Detail
-
getEncoder
public static final XMLEncoder getEncoder(java.lang.String encoding) throws java.lang.IllegalArgumentException, java.io.UnsupportedEncodingException
Retrieves anXMLEncoderfor the specified encoding. If no suitable instance can be returned, then an exception is thrown.- Parameters:
encoding- the name of the encoding, notnull.- Returns:
- an
XMLEncoderinstance that matches the specified encoding, nevernull. - Throws:
java.lang.IllegalArgumentException- ifencoding == null.java.io.UnsupportedEncodingException- if the specified encoding is not supported.
-
getEncoding
public java.lang.String getEncoding()
Returns the encoding.- Returns:
- the encoding passed to the constructor, never
null.
-
declaration
public void declaration(java.io.Writer out) throws java.lang.NullPointerException, java.io.IOExceptionWrites an XML declaration.- Parameters:
out- the character stream to write to, notnull.- Throws:
java.lang.NullPointerException- ifout == null.java.io.IOException- if an I/O error occurs.
-
text
public void text(java.io.Writer out, java.lang.String text, boolean escapeAmpersands) throws java.lang.NullPointerException, InvalidXMLException, java.io.IOExceptionWrites the specified text. Any characters that are non-printable in this encoding will be escaped. It must be specified whether ampersands should be escaped. Unless ampersands are escaped, entity references can be written.- Parameters:
out- the character stream to write to, notnull.text- the text to be written, notnull.escapeAmpersands- flag that indicates whether ampersands should be escaped.- Throws:
java.lang.NullPointerException- ifout == null || text == null.InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs.
-
text
public void text(java.io.Writer out, char[] ch, int start, int length, boolean escapeAmpersands) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException, InvalidXMLException, java.io.IOExceptionWrites text from the specified character array. Any characters that are non-printable in this encoding will be escaped. It must be specified whether ampersands should be escaped. Unless ampersands are escaped, entity references can be written.- Parameters:
out- the character stream to write to, notnull.ch- the character array from which to retrieve the text to be written, notnull.start- the start index intoch, must be >= 0.length- the number of characters to take fromch, starting at thestartindex.escapeAmpersands- flag that indicates if ampersands should be escaped.- Throws:
java.lang.NullPointerException- ifout == null || ch == null.java.lang.IndexOutOfBoundsException- ifstart < 0 || start + length > ch.length; this may not be checked before the character stream is written to, so this may cause a partial failure.InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs.
-
text
public void text(java.io.Writer out, char c) throws InvalidXMLException, java.io.IOExceptionDeprecated.Deprecated since xmlenc 0.51. Use the text methodtext(Writer, char, boolean)instead.Writes the specified character. If the character is non-printable in this encoding, then it will be escaped. It is safe for this method to assume that the specified character does not need to be escaped unless the encoding does not support the character.- Parameters:
out- the character stream to write to, notnull.c- the character to be written.- Throws:
InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs.
-
text
public void text(java.io.Writer out, char c, boolean escapeAmpersands) throws InvalidXMLException, java.io.IOExceptionWrites the specified character. If the character is non-printable in this encoding, then it will be escaped. It is safe for this method to assume that the specified character does not need to be escaped unless the encoding does not support the character.- Parameters:
out- the character stream to write to, notnull.c- the character to be written.escapeAmpersands- flag that indicates if ampersands should be escaped.- Throws:
InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs.
-
whitespace
public void whitespace(java.io.Writer out, java.lang.String s) throws java.lang.NullPointerException, InvalidXMLException, java.io.IOExceptionWrites the specified whitespace string.- Parameters:
out- the character stream to write to, notnull.s- the character string to be written, notnull.- Throws:
java.lang.NullPointerException- ifout == null || s == null.InvalidXMLException- if the specified character string contains a character that is invalid as whitespace.java.io.IOException- if an I/O error occurs.
-
whitespace
public void whitespace(java.io.Writer out, char[] ch, int start, int length) throws java.lang.NullPointerException, java.lang.IndexOutOfBoundsException, InvalidXMLException, java.io.IOExceptionWrites whitespace from the specified character array.- Parameters:
out- the character stream to write to, notnull.ch- the character array from which to retrieve the text to be written, notnull.start- the start index intoch, must be >= 0.length- the number of characters to take fromch, starting at thestartindex.- Throws:
java.lang.NullPointerException- ifout == null || ch == null.java.lang.IndexOutOfBoundsException- ifstart < 0 || start + length > ch.length; this may not be checked before the character stream is written to, so this may cause a partial failure.InvalidXMLException- if the specified character array contains a character that is invalid as whitespace.java.io.IOException- if an I/O error occurs.
-
attribute
public void attribute(java.io.Writer out, java.lang.String name, java.lang.String value, char quotationMark, boolean escapeAmpersands) throws java.lang.NullPointerException, java.io.IOExceptionWrites an attribute assignment.- Parameters:
out- the character stream to write to, notnull.name- the name of the attribute, notnull.value- the value of the attribute, notnull.quotationMark- the quotation mark, must be either the apostrophe ('\'') or the quote character ('"').- Throws:
java.lang.NullPointerException- ifout == null || value == null.java.lang.IllegalArgumentException- ifquotationMark != '\'' && quotationMark != '"'.java.io.IOException- if an I/O error occurs.
-
-