org.znerd.xmlenc
public class XMLEncoder extends Object
The following encodings are supported:
UTF-8
UTF-16
US-ASCII
, with alias ASCII
ISO-8859
encodings
Constructor and Description |
---|
XMLEncoder(String encoding)
Deprecated.
Deprecated since xmlenc 0.47.
Use the factory method
getEncoder(String) instead. |
Modifier and Type | Method and Description |
---|---|
void |
attribute(Writer out,
String name,
String value,
char quotationMark,
boolean escapeAmpersands)
Writes an attribute assignment.
|
void |
declaration(Writer out)
Writes an XML declaration.
|
static XMLEncoder |
getEncoder(String encoding)
Retrieves an
XMLEncoder for the specified encoding. |
String |
getEncoding()
Returns the encoding.
|
void |
text(Writer out,
char c)
Deprecated.
Deprecated since xmlenc 0.51.
Use the text method
text(Writer, char, boolean) instead. |
void |
text(Writer out,
char[] ch,
int start,
int length,
boolean escapeAmpersands)
Writes text from the specified character array.
|
void |
text(Writer out,
char c,
boolean escapeAmpersands)
Writes the specified character.
|
void |
text(Writer out,
String text,
boolean escapeAmpersands)
Writes the specified text.
|
void |
whitespace(Writer out,
char[] ch,
int start,
int length)
Writes whitespace from the specified character array.
|
void |
whitespace(Writer out,
String s)
Writes the specified whitespace string.
|
public XMLEncoder(String encoding) throws IllegalArgumentException, UnsupportedEncodingException
getEncoder(String)
instead.XMLEncoder
instance.encoding
- the name of the encoding, not null
.IllegalArgumentException
- if encoding == null
.UnsupportedEncodingException
- if the specified encoding is not supported.public static final XMLEncoder getEncoder(String encoding) throws IllegalArgumentException, UnsupportedEncodingException
XMLEncoder
for the specified encoding. If no
suitable instance can be returned, then an exception is thrown.encoding
- the name of the encoding, not null
.XMLEncoder
instance that matches the specified
encoding, never null
.IllegalArgumentException
- if encoding == null
.UnsupportedEncodingException
- if the specified encoding is not supported.public String getEncoding()
null
.public void declaration(Writer out) throws NullPointerException, IOException
out
- the character stream to write to, not null
.NullPointerException
- if out == null
.IOException
- if an I/O error occurs.public void text(Writer out, String text, boolean escapeAmpersands) throws NullPointerException, InvalidXMLException, IOException
out
- the character stream to write to, not null
.text
- the text to be written, not null
.escapeAmpersands
- flag that indicates whether ampersands should be escaped.NullPointerException
- if out == null || text == null
.InvalidXMLException
- if the specified text contains an invalid character.IOException
- if an I/O error occurs.public void text(Writer out, char[] ch, int start, int length, boolean escapeAmpersands) throws NullPointerException, IndexOutOfBoundsException, InvalidXMLException, IOException
out
- the character stream to write to, not null
.ch
- the character array from which to retrieve the text to be written,
not null
.start
- the start index into ch
, must be >= 0.length
- the number of characters to take from ch
, starting at
the start
index.escapeAmpersands
- flag that indicates if ampersands should be escaped.NullPointerException
- if out == null || ch == null
.IndexOutOfBoundsException
- if start < 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.IOException
- if an I/O error occurs.public void text(Writer out, char c) throws InvalidXMLException, IOException
text(Writer, char, boolean)
instead.out
- the character stream to write to, not null
.c
- the character to be written.InvalidXMLException
- if the specified text contains an invalid character.IOException
- if an I/O error occurs.public void text(Writer out, char c, boolean escapeAmpersands) throws InvalidXMLException, IOException
out
- the character stream to write to, not null
.c
- the character to be written.escapeAmpersands
- flag that indicates if ampersands should be escaped.InvalidXMLException
- if the specified text contains an invalid character.IOException
- if an I/O error occurs.public void whitespace(Writer out, String s) throws NullPointerException, InvalidXMLException, IOException
out
- the character stream to write to, not null
.s
- the character string to be written, not null
.NullPointerException
- if out == null || s == null
.InvalidXMLException
- if the specified character string contains a character that is
invalid as whitespace.IOException
- if an I/O error occurs.public void whitespace(Writer out, char[] ch, int start, int length) throws NullPointerException, IndexOutOfBoundsException, InvalidXMLException, IOException
out
- the character stream to write to, not null
.ch
- the character array from which to retrieve the text to be written,
not null
.start
- the start index into ch
, must be >= 0.length
- the number of characters to take from ch
, starting at
the start
index.NullPointerException
- if out == null || ch == null
.IndexOutOfBoundsException
- if start < 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.IOException
- if an I/O error occurs.public void attribute(Writer out, String name, String value, char quotationMark, boolean escapeAmpersands) throws NullPointerException, IOException
out
- the character stream to write to, not null
.name
- the name of the attribute, not null
.value
- the value of the attribute, not null
.quotationMark
- the quotation mark, must be either the apostrophe ('\''
)
or the quote character ('"'
).NullPointerException
- if out == null || value == null
.IllegalArgumentException
- if quotationMark != '\'' && quotationMark != '"'
.IOException
- if an I/O error occurs.