org.apache.xmlrpc

Class XmlWriter

class XmlWriter extends OutputStreamWriter

A XML writer intended for single-thread usage. If you feed it a ByteArrayInputStream, it may be necessary to call writer.flush() before calling buffer.toByteArray() to get the data written to your byte buffer.

Author: Hannes Wallnoefer Daniel L. Rall

See Also: Tim Bray's Annotated XML Spec

Field Summary
protected static StringAMPERSAND_ENTITY
protected static Base64base64Codec
protected static StringCLOSING_TAG_START
DateTooldateTool
Thread-safe wrapper for the DateFormat object used to parse date/time values.
static Propertiesencodings
Mapping between Java encoding names and "real" names used in XML prolog.
protected static StringGREATER_THAN_ENTITY
booleanhasWrittenProlog
Whether the XML prolog has been written.
static StringISO8859_1
Java's name for the ISO-8859-1 encoding.
protected static StringLESS_THAN_ENTITY
static char[]PROLOG
protected static StringPROLOG_END
protected static StringPROLOG_START
protected static StringSINGLE_TAG_END
protected static TypeDecodertypeDecoder
Class to delegate type decoding to.
static StringUTF16
Java's name for the UTF-16 encoding.
static StringUTF8
Java's name for the UTF-8 encoding.
Constructor Summary
XmlWriter(OutputStream out, String enc)
Creates a new instance.
Method Summary
protected static StringcanonicalizeEncoding(String javaEncoding)
Tranforms a Java encoding to the canonical XML form (if a mapping is available).
protected voidchardata(String text)
Writes text as PCDATA.
protected voidemptyElement(String elem)
protected voidendElement(String elem)
static StringforceUnicode(String encoding)
static booleanisValidXMLChar(char c)
Section 2.2 of the XML spec describes which Unicode code points are valid in XML:
#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
Code points outside this set must be entity encoded to be represented in XML.
protected static voidsetTypeDecoder(TypeDecoder newTypeDecoder)
protected voidstartElement(String elem)
voidwrite(char[] cbuf, int off, int len)
A mostly pass-through implementation wrapping OutputStreamWriter.write() which assures that the XML prolog is written before any other data.
voidwrite(char c)
A mostly pass-through implementation wrapping OutputStreamWriter.write() which assures that the XML prolog is written before any other data.
voidwrite(String str, int off, int len)
A mostly pass-through implementation wrapping OutputStreamWriter.write() which assures that the XML prolog is written before any other data.
protected voidwrite(byte[] byteData)
This is used to write out the Base64 output...
voidwriteCharacterReference(char c)
Writes characters like '\r' (0xd) as "
".
voidwriteObject(Object obj)
Writes the XML representation of a supported Java object type.

Field Detail

AMPERSAND_ENTITY

protected static final String AMPERSAND_ENTITY

base64Codec

protected static final Base64 base64Codec

CLOSING_TAG_START

protected static final String CLOSING_TAG_START

dateTool

DateTool dateTool
Thread-safe wrapper for the DateFormat object used to parse date/time values.

encodings

private static Properties encodings
Mapping between Java encoding names and "real" names used in XML prolog.

See Also: Java character set names

GREATER_THAN_ENTITY

protected static final String GREATER_THAN_ENTITY

hasWrittenProlog

boolean hasWrittenProlog
Whether the XML prolog has been written.

ISO8859_1

static final String ISO8859_1
Java's name for the ISO-8859-1 encoding.

LESS_THAN_ENTITY

protected static final String LESS_THAN_ENTITY

PROLOG

private static final char[] PROLOG

PROLOG_END

protected static final String PROLOG_END

PROLOG_START

protected static final String PROLOG_START

SINGLE_TAG_END

protected static final String SINGLE_TAG_END

typeDecoder

protected static TypeDecoder typeDecoder
Class to delegate type decoding to.

UTF16

static final String UTF16
Java's name for the UTF-16 encoding.

UTF8

static final String UTF8
Java's name for the UTF-8 encoding.

Constructor Detail

XmlWriter

public XmlWriter(OutputStream out, String enc)
Creates a new instance.

Parameters: out The stream to write output to. enc The encoding to using for outputing XML. Only UTF-8 and UTF-16 are supported. If another encoding is specified, UTF-8 will be used instead for widest XML parser interoperability.

Throws: UnsupportedEncodingException Since unsupported encodings are internally converted to UTF-8, this should only be seen as the result of an internal error.

Method Detail

canonicalizeEncoding

protected static String canonicalizeEncoding(String javaEncoding)

Deprecated: This method will not be visible in 2.0.

Tranforms a Java encoding to the canonical XML form (if a mapping is available).

Parameters: javaEncoding The name of the encoding as known by Java.

Returns: The XML encoding (if a mapping is available); otherwise, the encoding as provided.

chardata

protected void chardata(String text)
Writes text as PCDATA.

Parameters: text The data to write.

Throws: XmlRpcException Unsupported character data found. IOException Problem writing data.

emptyElement

protected void emptyElement(String elem)

Parameters: elem

Throws: IOException

endElement

protected void endElement(String elem)

Parameters: elem

Throws: IOException

forceUnicode

private static String forceUnicode(String encoding)

Parameters: encoding A caller-specified encoding.

Returns: An Unicode encoding.

isValidXMLChar

private static final boolean isValidXMLChar(char c)
Section 2.2 of the XML spec describes which Unicode code points are valid in XML:
#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
Code points outside this set must be entity encoded to be represented in XML.

Parameters: c The character to inspect.

Returns: Whether the specified character is valid in XML.

setTypeDecoder

protected static void setTypeDecoder(TypeDecoder newTypeDecoder)

startElement

protected void startElement(String elem)

Parameters: elem

Throws: IOException

write

public void write(char[] cbuf, int off, int len)
A mostly pass-through implementation wrapping OutputStreamWriter.write() which assures that the XML prolog is written before any other data.

See Also: java.io.OutputStreamWriter.write(char[], int, int)

write

public void write(char c)
A mostly pass-through implementation wrapping OutputStreamWriter.write() which assures that the XML prolog is written before any other data.

See Also: java.io.OutputStreamWriter.write(char)

write

public void write(String str, int off, int len)
A mostly pass-through implementation wrapping OutputStreamWriter.write() which assures that the XML prolog is written before any other data.

See Also: java.io.OutputStreamWriter.write(String, int, int)

write

protected void write(byte[] byteData)
This is used to write out the Base64 output...

writeCharacterReference

private void writeCharacterReference(char c)
Writes characters like '\r' (0xd) as "
".

writeObject

public void writeObject(Object obj)
Writes the XML representation of a supported Java object type.

Parameters: obj The Object to write.

Throws: XmlRpcException Unsupported character data found. IOException Problem writing data. IllegalArgumentException If a null parameter is passed to this method (not supported by the XML-RPC specification).

Copyright B) 1999-2002 Apache Software Foundation. All Rights Reserved.