|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Interface to a serializer implementation. A serializer is used for serializing a document through one of three interfaces. The serializer object serves as an anchor point for setting the output stream and output format, for obtaining any of these interfaces, and for resetting the serializer.
A serializer is created from SerializerFactory
.
Prior to using the serializer, the output format and output stream or writer should be set. The serializer is then used in one of three ways:
asDocumentHandler()
asContentHandler()
asDOMSerializer()
(see DOMSerializer
)
The serializer may be reused with the same output format and output
stream, or different output format and output stream, by calling
the reset()
method after completing serialization. The
document handler or DOMSerializer
must be re-acquired after
a successful return from reset()
.
A serializer is not thread safe. Only one thread should call the asXXX methods and use the returned document handler, or DOM serializer.
Example:
ser = SerializerFactory.getSerializer( Method.XML ); emptyDoc( ser, System.out ); emptyDoc( ser, System.err ); . . . void emptyDoc( Serializer ser, OutputStream os ) { ser.setOutputStream( os ); ser.asDocumentHandler().startDocument(); ser.asDocumentHandler().startElement( "empty", new AttributeListImpl() ); ser.asDocumentHandler().endElement( "empty" ); ser.asDocumentHandler().endDocument(); ser.reset(); }
Method Summary | |
org.xml.sax.ContentHandler |
asContentHandler()
Return a ContentHandler interface into this serializer. |
org.xml.sax.DocumentHandler |
asDocumentHandler()
Return a DocumentHandler interface into this serializer. |
DOMSerializer |
asDOMSerializer()
Return a DOMSerializer interface into this serializer. |
OutputFormat |
getOutputFormat()
Returns the output format for this serializer. |
boolean |
reset()
Resets the serializer. |
void |
setOutputFormat(OutputFormat format)
Specifies an output format for this serializer. |
void |
setOutputStream(java.io.OutputStream output)
Specifies an output stream to which the document should be serialized. |
void |
setWriter(java.io.Writer writer)
Specifies a writer to which the document should be serialized. |
Method Detail |
public void setOutputStream(java.io.OutputStream output) throws java.io.UnsupportedEncodingException
The encoding specified in the OutputFormat
is used, or
if no encoding was specified, the default for the selected
output method.
output
- The output streamUnsupportedEncodingException
- The encoding specified in
the output format is not supportedpublic void setWriter(java.io.Writer writer)
The encoding specified for the OutputFormat
must be
identical to the output format used with the writer.
writer
- The output writer streampublic void setOutputFormat(OutputFormat format)
format
- The output format to usepublic OutputFormat getOutputFormat()
public org.xml.sax.DocumentHandler asDocumentHandler()
DocumentHandler
interface into this serializer.
If the serializer does not support the DocumentHandler
interface, it should return null.public org.xml.sax.ContentHandler asContentHandler()
ContentHandler
interface into this serializer.
If the serializer does not support the ContentHandler
interface, it should return null.public DOMSerializer asDOMSerializer()
DOMSerializer
interface into this serializer.
If the serializer does not support the DOMSerializer
interface, it should return null.public boolean reset()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |