org.apache.xml.serialize
public abstract class BaseMarkupSerializer extends Object implements ContentHandler, DocumentHandler, LexicalHandler, DTDHandler, DeclHandler, DOMSerializer, Serializer
The serializer must be initialized with the proper writer and output format before it can be used by calling BaseMarkupSerializer or BaseMarkupSerializer for the writer and BaseMarkupSerializer for the output format.
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 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 org.xml.sax.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.
Version: $Revision: 1.57 $ $Date: 2005/05/02 21:58:58 $
See Also: Serializer LSSerializer
Field Summary | |
---|---|
protected Node | fCurrentNode Current node that is being processed |
protected DOMErrorImpl | fDOMError |
protected DOMErrorHandler | fDOMErrorHandler |
protected LSSerializerFilter | fDOMFilter |
protected short | features |
protected StringBuffer | fStrBuffer Temporary buffer to store character data |
protected String | _docTypePublicId
The system identifier of the document type, if known. |
protected String | _docTypeSystemId
The system identifier of the document type, if known. |
protected EncodingInfo | _encodingInfo |
protected OutputFormat | _format
The output format associated with this serializer. |
protected boolean | _indenting
True if indenting printer. |
protected Hashtable | _prefixes
Association between namespace URIs (keys) and prefixes (values).
|
protected Printer | _printer
The printer used for printing text parts. |
protected boolean | _started
If the document has been started (header serialized), this
flag is set to true so it's not started twice. |
Constructor Summary | |
---|---|
protected | BaseMarkupSerializer(OutputFormat format)
Protected constructor can only be used by derived class.
|
Method Summary | |
---|---|
ContentHandler | asContentHandler() |
DocumentHandler | asDocumentHandler() |
DOMSerializer | asDOMSerializer() |
void | attributeDecl(String eName, String aName, String type, String valueDefault, String value) |
void | characters(char[] chars, int start, int length) |
protected void | characters(String text)
Called to print the text contents in the prevailing element format.
|
protected void | checkUnboundNamespacePrefixedNode(Node node)
DOM level 3:
Check a node to determine if it contains unbound namespace prefixes.
|
void | comment(char[] chars, int start, int length) |
void | comment(String text) |
protected ElementState | content()
Must be called by a method about to print any type of content.
|
void | elementDecl(String name, String model) |
void | endCDATA() |
void | endDocument()
Called at the end of the document to wrap it up.
|
void | endDTD() |
void | endEntity(String name) |
void | endNonEscaping() |
void | endPrefixMapping(String prefix) |
void | endPreserving() |
protected ElementState | enterElementState(String namespaceURI, String localName, String rawName, boolean preserveSpace)
Enter a new element state for the specified element.
|
void | externalEntityDecl(String name, String publicId, String systemId) |
protected void | fatalError(String message) |
protected ElementState | getElementState()
Return the state of the current element.
|
protected abstract String | getEntityRef(int ch)
Returns the suitable entity reference for this character value,
or null if no such entity exists. |
protected String | getPrefix(String namespaceURI)
Returns the namespace prefix for the specified URI.
|
void | ignorableWhitespace(char[] chars, int start, int length) |
void | internalEntityDecl(String name, String value) |
protected boolean | isDocumentState()
Returns true if in the state of the document.
|
protected ElementState | leaveElementState()
Leave the current element state and return to the
state of the parent element. |
protected DOMError | modifyDOMError(String message, short severity, String type, Node node)
The method modifies global DOM error object
|
void | notationDecl(String name, String publicId, String systemId) |
protected void | prepare() |
protected void | printCDATAText(String text) |
protected void | printDoctypeURL(String url)
Print a document type public or system identifier URL.
|
protected void | printEscaped(int ch) |
protected void | printEscaped(String source)
Escapes a string so it may be printed as text content or attribute
value. |
protected void | printText(char[] chars, int start, int length, boolean preserveSpace, boolean unescaped)
Called to print additional text with whitespace handling.
|
protected void | printText(String text, boolean preserveSpace, boolean unescaped) |
void | processingInstruction(String target, String code) |
void | processingInstructionIO(String target, String code) |
boolean | reset() |
void | serialize(Element elem)
Serializes the DOM element 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(Document doc)
Serializes the DOM document using the previously specified
writer and output format. |
protected abstract void | serializeElement(Element elem)
Called to serializee the DOM element. |
protected void | serializeNode(Node node)
Serialize the DOM node. |
protected void | serializePreRoot()
Comments and PIs cannot be serialized before the root element,
because the root element serializes the document type, which
generally comes first. |
void | setDocumentLocator(Locator locator) |
void | setOutputByteStream(OutputStream output) |
void | setOutputCharStream(Writer writer) |
void | setOutputFormat(OutputFormat format) |
void | skippedEntity(String name) |
void | startCDATA() |
void | startDocument() |
void | startDTD(String name, String publicId, String systemId) |
void | startEntity(String name) |
void | startNonEscaping() |
void | startPrefixMapping(String prefix, String uri) |
void | startPreserving() |
protected void | surrogates(int high, int low) |
void | unparsedEntityDecl(String name, String publicId, String systemId, String notationName) |
Parameters: text The text to print unescaped True is should print unescaped
Throws: IOException An I/O exception occured while serializing
Parameters: node The node to check for unbound namespace prefices
Returns: The current element state
Throws: IOException An I/O exception occured while serializing
Throws: SAXException An I/O exception occured during serializing
Returns: Current element state, or null
Returns: Current element state
Parameters: ch Character value
Returns: Character entity name, or null
Parameters: namespaceURI The namespace URI
Returns: The namespace prefix if known, or null
Returns: True if in the state of the document
Returns: Previous element state
Parameters: message severity type
Returns: a DOMError
Parameters: url The document type url to print
Parameters: source The string to escape
Parameters: text The text to print preserveSpace Space preserving flag unescaped Print unescaped
Parameters: elem The element to serialize
Throws: IOException An I/O exception occured while serializing
Parameters: elem The element to serialize
Throws: IOException An I/O exception occured while serializing
Parameters: doc The document to serialize
Throws: IOException An I/O exception occured while serializing
Parameters: elem The element to serialize
Throws: IOException An I/O exception occured while serializing
Parameters: node The node to serialize
Throws: IOException An I/O exception occured while serializing
See Also: BaseMarkupSerializer
Throws: IOException An I/O exception occured while serializing