org.apache.xmlrpc

Class XmlWriter


(package private) 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.
Authors:
Hannes Wallnoefer
Daniel L. Rall
See Also:
Tim Bray's Annotated XML Spec

Field Summary

protected static String
AMPERSAND_ENTITY
protected static String
CLOSING_TAG_START
protected static String
GREATER_THAN_ENTITY
(package private) static String
ISO8859_1
Java's name for the ISO-8859-1 encoding.
protected static String
LESS_THAN_ENTITY
private static char[]
PROLOG
protected static String
PROLOG_END
protected static String
PROLOG_START
protected static String
SINGLE_TAG_END
(package private) static String
UTF16
Java's name for the UTF-16 encoding.
(package private) static String
UTF8
Java's name for the UTF-8 encoding.
protected static Base64
base64Codec
(package private) DateTool
dateTool
Thread-safe wrapper for the DateFormat object used to parse date/time values.
private static Properties
encodings
Mapping between Java encoding names and "real" names used in XML prolog.
(package private) boolean
hasWrittenProlog
Whether the XML prolog has been written.
protected static TypeDecoder
typeDecoder
Class to delegate type decoding to.

Constructor Summary

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

Method Summary

protected static String
canonicalizeEncoding(String javaEncoding)
Deprecated. This method will not be visible in 2.0.
protected void
chardata(String text)
Writes text as PCDATA.
protected void
emptyElement(String elem)
protected void
endElement(String elem)
private static String
forceUnicode(String encoding)
private static 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.
protected static void
setTypeDecoder(TypeDecoder newTypeDecoder)
protected void
startElement(String elem)
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.
protected void
write(byte[] byteData)
This is used to write out the Base64 output...
void
write(char c)
A mostly pass-through implementation wrapping OutputStreamWriter.write() which assures that the XML prolog is written before any other data.
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.
private void
writeCharacterReference(char c)
Writes characters like '\r' (0xd) as "
".
void
writeObject(Object obj)
Writes the XML representation of a supported Java object type.

Field Details

AMPERSAND_ENTITY

protected static final String AMPERSAND_ENTITY

CLOSING_TAG_START

protected static final String CLOSING_TAG_START

GREATER_THAN_ENTITY

protected static final String GREATER_THAN_ENTITY

ISO8859_1

(package private) 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

UTF16

(package private) static final String UTF16
Java's name for the UTF-16 encoding.

UTF8

(package private) static final String UTF8
Java's name for the UTF-8 encoding.

base64Codec

protected static final Base64 base64Codec

dateTool

(package private)  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.

hasWrittenProlog

(package private)  boolean hasWrittenProlog
Whether the XML prolog has been written.

typeDecoder

protected static TypeDecoder typeDecoder
Class to delegate type decoding to.

Constructor Details

XmlWriter

public XmlWriter(OutputStream out,
                 String enc)
            throws UnsupportedEncodingException
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.

Method Details

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)
            throws XmlRpcException,
                   IOException
Writes text as PCDATA.
Parameters:
text - The data to write.
Throws:
XmlRpcException - Unsupported character data found.

emptyElement

protected void emptyElement(String elem)
            throws IOException
Parameters:
elem -

endElement

protected void endElement(String elem)
            throws IOException
Parameters:
elem -

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)
            throws IOException
Parameters:
elem -

write

public void write(String str,
                  int off,
                  int len)
            throws IOException
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)
            throws IOException
This is used to write out the Base64 output...

write

public void write(char c)
            throws IOException
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(char[] cbuf,
                  int off,
                  int len)
            throws IOException
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)

writeCharacterReference

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

writeObject

public void writeObject(Object obj)
            throws XmlRpcException,
                   IOException
Writes the XML representation of a supported Java object type.
Parameters:
obj - The Object to write.
Throws:
XmlRpcException - Unsupported character data found.

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