public class SerializingContentHandler extends DefaultContentHandler
ContentHandler
that serializes SAX events to a given
Result
instance. The JAXP SAXTransformerFactory
facility is used for the serialization.
This class explicitly ensures that all namespace prefixes are also present as xmlns attributes in the serialized XML document. This avoids problems with Xalan's serialization behaviour which was (at least during JDK 1.4) to ignore namespaces if they were not present as xmlns attributes.
NOTE: The code in this class was originally written for Apache Cocoon and is included with some modifications here in Apache Jackrabbit. See the org.apache.cocoon.serialization.AbstractTextSerializer class in the cocoon-pipeline-impl component for the original code.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ENCODING
The character encoding used for serialization (UTF-8).
|
Modifier and Type | Method and Description |
---|---|
void |
endDocument()
Delegated to
DefaultContentHandler.handler . |
void |
endElement(java.lang.String eltUri,
java.lang.String eltLocalName,
java.lang.String eltQName)
Receive notification of the end of an element.
|
void |
endPrefixMapping(java.lang.String prefix)
End the scope of a prefix-URI mapping:
remove entry from mapping tables.
|
static org.xml.sax.helpers.DefaultHandler |
getSerializer(java.io.OutputStream output)
Creates a serializing content handler that writes to the given stream.
|
static org.xml.sax.helpers.DefaultHandler |
getSerializer(javax.xml.transform.Result result)
Creates a serializing content handler that writes to the given result.
|
static org.xml.sax.helpers.DefaultHandler |
getSerializer(java.io.Writer writer)
Creates a serializing content handler that writes to the given writer.
|
void |
startDocument()
Delegated to
DefaultContentHandler.handler . |
void |
startElement(java.lang.String eltUri,
java.lang.String eltLocalName,
java.lang.String eltQName,
org.xml.sax.Attributes attrs)
Ensure all namespace declarations are present as
xmlns: attributes
and add those needed before calling superclass. |
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String uri)
Track mappings to be able to add
xmlns: attributes
in startElement() . |
characters, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity
public static final java.lang.String ENCODING
public static org.xml.sax.helpers.DefaultHandler getSerializer(java.io.OutputStream output) throws org.xml.sax.SAXException
output
- serialization targetorg.xml.sax.SAXException
- if the content handler could not be initializedpublic static org.xml.sax.helpers.DefaultHandler getSerializer(java.io.Writer writer) throws org.xml.sax.SAXException
writer
- serialization targetorg.xml.sax.SAXException
- if the content handler could not be initializedpublic static org.xml.sax.helpers.DefaultHandler getSerializer(javax.xml.transform.Result result) throws org.xml.sax.SAXException
result
- serialization targetorg.xml.sax.SAXException
- if the content handler could not be initializedpublic void startDocument() throws org.xml.sax.SAXException
DefaultContentHandler
DefaultContentHandler.handler
.startDocument
in interface org.xml.sax.ContentHandler
startDocument
in class DefaultContentHandler
org.xml.sax.SAXException
- if an error occurspublic void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXException
xmlns:
attributes
in startElement()
.startPrefixMapping
in interface org.xml.sax.ContentHandler
startPrefixMapping
in class DefaultContentHandler
prefix
- passed throughuri
- passed throughorg.xml.sax.SAXException
- if an error occurspublic void startElement(java.lang.String eltUri, java.lang.String eltLocalName, java.lang.String eltQName, org.xml.sax.Attributes attrs) throws org.xml.sax.SAXException
xmlns:
attributes
and add those needed before calling superclass. This is a workaround for a Xalan bug
(at least in version 2.0.1) : org.apache.xalan.serialize.SerializerToXML
ignores start/endPrefixMapping()
.startElement
in interface org.xml.sax.ContentHandler
startElement
in class DefaultContentHandler
eltUri
- passed througheltLocalName
- passed througheltQName
- passed throughattrs
- passed throughorg.xml.sax.SAXException
- if an error occurspublic void endElement(java.lang.String eltUri, java.lang.String eltLocalName, java.lang.String eltQName) throws org.xml.sax.SAXException
endElement
in interface org.xml.sax.ContentHandler
endElement
in class DefaultContentHandler
eltUri
- passed througheltLocalName
- passed througheltQName
- passed throughorg.xml.sax.SAXException
- if an error occurspublic void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException
endPrefixMapping
in interface org.xml.sax.ContentHandler
endPrefixMapping
in class DefaultContentHandler
prefix
- passed throughorg.xml.sax.SAXException
- if an error occurspublic void endDocument() throws org.xml.sax.SAXException
DefaultContentHandler
DefaultContentHandler.handler
.endDocument
in interface org.xml.sax.ContentHandler
endDocument
in class DefaultContentHandler
org.xml.sax.SAXException
- if an error occurs"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"