Class ToXmlContentHandler
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.apache.jackrabbit.commons.xml.ToXmlContentHandler
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler,org.xml.sax.DTDHandler,org.xml.sax.EntityResolver,org.xml.sax.ErrorHandler
public class ToXmlContentHandler extends org.xml.sax.helpers.DefaultHandlerSimple XML serializer. This content handler serializes the received SAX events as XML to a givenWriterorOutputStream. The serialization assumes that the incoming SAX events are well-formed, i.e. that all elements are properly nested, that element and attribute names are valid and that no invalid XML characters are included. Assuming these preconditions are met, the result will be a well-formed XML stream.This serializer does not have any special support for namespaces. For example, namespace prefixes are declared in the resulting XML stream if and only if the corresponding "xmlns" attributes are explicitly included in the
Attributesinstances passed instartElement(String, String, String, Attributes)calls.As a convenience this class inherits the
DefaultHandlerclass instead of just theContentHandlerinterface. This makes it easier to pass instances of this class to methods likeSAXParser.parse(String, DefaultHandler)that expect a DefaultHandler instance instead of a ContentHandler.
-
-
Constructor Summary
Constructors Constructor Description ToXmlContentHandler()Creates an XML serializer that writes the serialized XML stream to an internal buffer.ToXmlContentHandler(java.io.OutputStream stream)Creates an XML serializer that writes the serialized XML stream to the given output stream using the UTF-8 character encoding.ToXmlContentHandler(java.io.OutputStream stream, java.lang.String encoding)Creates an XML serializer that writes the serialized XML stream to the given output stream using the given character encoding.ToXmlContentHandler(java.io.Writer writer)Creates an XML serializer that writes the serialized XML stream to the given writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcharacters(char[] ch, int start, int length)Escapes and outputs the given characters.voidendDocument()Ends the XML serialization by flushing the output stream.voidendElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)Outputs the specified end tag.voidignorableWhitespace(char[] ch, int start, int length)Escapes and outputs the given characters.voidprocessingInstruction(java.lang.String target, java.lang.String data)Serializes a processing instruction.voidstartDocument()Starts the XML serialization by outputting the <?xml?> header.voidstartElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)Outputs the specified start tag with the given attributes.java.lang.StringtoString()Returns the serialized XML document (assuming the default no-argument constructor was used).
-
-
-
Constructor Detail
-
ToXmlContentHandler
public ToXmlContentHandler(java.io.OutputStream stream, java.lang.String encoding) throws java.io.UnsupportedEncodingExceptionCreates an XML serializer that writes the serialized XML stream to the given output stream using the given character encoding.- Parameters:
stream- XML output streamencoding- character encoding- Throws:
java.io.UnsupportedEncodingException- if the encoding is not supported
-
ToXmlContentHandler
public ToXmlContentHandler(java.io.OutputStream stream)
Creates an XML serializer that writes the serialized XML stream to the given output stream using the UTF-8 character encoding.- Parameters:
stream- XML output stream
-
ToXmlContentHandler
public ToXmlContentHandler(java.io.Writer writer)
Creates an XML serializer that writes the serialized XML stream to the given writer.- Parameters:
writer- XML output stream
-
ToXmlContentHandler
public ToXmlContentHandler()
Creates an XML serializer that writes the serialized XML stream to an internal buffer. Use thetoString()method to access the serialized XML document.
-
-
Method Detail
-
startDocument
public void startDocument() throws org.xml.sax.SAXExceptionStarts the XML serialization by outputting the <?xml?> header.- Specified by:
startDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
startDocumentin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
endDocument
public void endDocument() throws org.xml.sax.SAXExceptionEnds the XML serialization by flushing the output stream.- Specified by:
endDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
endDocumentin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXExceptionSerializes a processing instruction.- Specified by:
processingInstructionin interfaceorg.xml.sax.ContentHandler- Overrides:
processingInstructionin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
startElement
public void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXExceptionOutputs the specified start tag with the given attributes.- Specified by:
startElementin interfaceorg.xml.sax.ContentHandler- Overrides:
startElementin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
characters
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionEscapes and outputs the given characters.- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Overrides:
charactersin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionEscapes and outputs the given characters.- Specified by:
ignorableWhitespacein interfaceorg.xml.sax.ContentHandler- Overrides:
ignorableWhitespacein classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
endElement
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXExceptionOutputs the specified end tag.- Specified by:
endElementin interfaceorg.xml.sax.ContentHandler- Overrides:
endElementin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
toString
public java.lang.String toString()
Returns the serialized XML document (assuming the default no-argument constructor was used).- Overrides:
toStringin classjava.lang.Object- Returns:
- serialized XML document
-
-