|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.xml.serialize.transition.BaseMarkupSerializer
Base class for a serializer supporting both DOM and SAX pretty serializing of XML/HTML/XHTML documents. Derives classes perform the method-specific serializing, this class provides the common serializing mechanisms.
The serializer must be initialized with the proper writer and
output format before it can be used by calling #init
.
The serializer can be reused any number of times, but cannot
be used concurrently by two threads.
If an output stream is used, the encoding is taken from the output format (defaults to UTF-8). If a writer is used, make sure the writer uses the same encoding (if applies) as specified in the output format.
The serializer supports both DOM and SAX. DOM serializing is done
by calling serialize(org.w3c.dom.Element)
and SAX serializing is done by firing
SAX events and using the serializer as a document handler.
This also applies to derived class.
If an I/O exception occurs while serializing, the serializer
will not throw an exception directly, but only throw it
at the end of serializing (either DOM or SAX's DocumentHandler.endDocument()
.
For elements that are not specified as whitespace preserving, the serializer will potentially break long text lines at space boundaries, indent lines, and serialize elements on separate lines. Line terminators will be regarded as spaces, and spaces at beginning of line will be stripped.
When indenting, the serializer is capable of detecting seemingly element content, and serializing these elements indented on separate lines. An element is serialized indented when it is the first or last child of an element, or immediate following or preceding another element.
Serializer
,
DOMSerializer
Method Summary | |
ContentHandler |
asContentHandler()
|
DocumentHandler |
asDocumentHandler()
|
DOMSerializer |
asDOMSerializer()
|
void |
attributeDecl(java.lang.String eName,
java.lang.String aName,
java.lang.String type,
java.lang.String valueDefault,
java.lang.String value)
|
void |
characters(char[] chars,
int start,
int length)
|
void |
comment(char[] chars,
int start,
int length)
|
void |
comment(java.lang.String text)
|
void |
elementDecl(java.lang.String name,
java.lang.String model)
|
void |
endCDATA()
|
void |
endDocument()
Called at the end of the document to wrap it up. |
void |
endDTD()
|
void |
endEntity(java.lang.String name)
|
void |
endNonEscaping()
|
void |
endPrefixMapping(java.lang.String prefix)
|
void |
endPreserving()
|
void |
externalEntityDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId)
|
OutputFormat |
getOutputFormat()
Returns the output format for this serializer. |
java.io.OutputStream |
getOutputStream()
|
java.io.Writer |
getWriter()
|
void |
ignorableWhitespace(char[] chars,
int start,
int length)
|
void |
internalEntityDecl(java.lang.String name,
java.lang.String value)
|
void |
notationDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId)
|
void |
processingInstruction(java.lang.String target,
java.lang.String code)
|
boolean |
reset()
|
void |
serialize(Document doc)
Serializes the DOM document using the previously specified writer and output format. |
void |
serialize(DocumentFragment frag)
Serializes the DOM document fragmnt using the previously specified writer and output format. |
void |
serialize(Element elem)
Serializes the DOM element using the previously specified writer and output format. |
void |
serializeXPathReturnNode(Node node)
Serialize a node from the node-set value returned by an XPath expression. |
void |
setDocumentLocator(Locator locator)
|
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. |
void |
skippedEntity(java.lang.String name)
|
void |
startCDATA()
|
void |
startDocument()
|
void |
startDTD(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId)
|
void |
startEntity(java.lang.String name)
|
void |
startNonEscaping()
|
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String uri)
|
void |
startPreserving()
|
void |
unparsedEntityDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId,
java.lang.String notationName)
|
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Method Detail |
public DocumentHandler asDocumentHandler() throws java.io.IOException
public ContentHandler asContentHandler() throws java.io.IOException
public DOMSerializer asDOMSerializer() throws java.io.IOException
public void setOutputStream(java.io.OutputStream output)
The encoding specified in the OutputFormat
is used, or
if no encoding was specified, the default for the selected
output method.
output
- The output streampublic java.io.OutputStream getOutputStream()
public 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 java.io.Writer getWriter()
public void setOutputFormat(OutputFormat format)
format
- The output format to usepublic OutputFormat getOutputFormat()
public boolean reset()
public void serialize(Element elem) throws java.io.IOException
elem
- The element to serializepublic void serialize(DocumentFragment frag) throws java.io.IOException
elem
- The element to serializepublic void serialize(Document doc) throws java.io.IOException
doc
- The document to serializepublic void startDocument() throws SAXException
public void characters(char[] chars, int start, int length)
public void ignorableWhitespace(char[] chars, int start, int length)
public void processingInstruction(java.lang.String target, java.lang.String code)
public void comment(char[] chars, int start, int length)
public void comment(java.lang.String text)
public void startCDATA()
public void endCDATA()
public void startNonEscaping()
public void endNonEscaping()
public void startPreserving()
public void endPreserving()
public void endDocument() throws SAXException
public void startEntity(java.lang.String name)
public void endEntity(java.lang.String name)
public void setDocumentLocator(Locator locator)
public void skippedEntity(java.lang.String name) throws SAXException
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws SAXException
public void endPrefixMapping(java.lang.String prefix) throws SAXException
public void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
public void endDTD()
public void elementDecl(java.lang.String name, java.lang.String model)
public void attributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String valueDefault, java.lang.String value)
public void internalEntityDecl(java.lang.String name, java.lang.String value)
public void externalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
public void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
public void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
public void serializeXPathReturnNode(Node node) throws java.io.IOException
node
- The node to serialize
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |