org.apache.tika.sax
Class ToXMLContentHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.apache.tika.sax.ToTextContentHandler
          extended by org.apache.tika.sax.ToXMLContentHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
Direct Known Subclasses:
ToHTMLContentHandler

public class ToXMLContentHandler
extends ToTextContentHandler

SAX event handler that serializes the XML document to a character stream. The incoming SAX events are expected to be well-formed (properly nested, etc.) and to explicitly include namespace declaration attributes and corresponding namespace prefixes in element and attribute names.

Since:
Apache Tika 0.10

Field Summary
protected  boolean inStartElement
           
protected  java.util.Map<java.lang.String,java.lang.String> namespaces
           
 
Constructor Summary
ToXMLContentHandler()
           
ToXMLContentHandler(java.io.OutputStream stream, java.lang.String encoding)
          Creates an XML serializer that writes to the given byte stream using the given character encoding.
ToXMLContentHandler(java.lang.String encoding)
           
 
Method Summary
 void characters(char[] ch, int start, int length)
          Writes the given characters to the given character stream.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
           
 void startDocument()
          Writes the XML prefix.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
           
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
           
protected  void write(char ch)
          Writes the given character as-is.
protected  void write(java.lang.String string)
          Writes the given string of character as-is.
 
Methods inherited from class org.apache.tika.sax.ToTextContentHandler
endDocument, ignorableWhitespace, toString
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

inStartElement

protected boolean inStartElement

namespaces

protected final java.util.Map<java.lang.String,java.lang.String> namespaces
Constructor Detail

ToXMLContentHandler

public ToXMLContentHandler(java.io.OutputStream stream,
                           java.lang.String encoding)
                    throws java.io.UnsupportedEncodingException
Creates an XML serializer that writes to the given byte stream using the given character encoding.

Parameters:
stream - output stream
encoding - output encoding
Throws:
java.io.UnsupportedEncodingException - if the encoding is unsupported

ToXMLContentHandler

public ToXMLContentHandler(java.lang.String encoding)

ToXMLContentHandler

public ToXMLContentHandler()
Method Detail

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Writes the XML prefix.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Overrides:
startPrefixMapping in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Description copied from class: ToTextContentHandler
Writes the given characters to the given character stream.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class ToTextContentHandler
Throws:
org.xml.sax.SAXException

write

protected void write(char ch)
              throws org.xml.sax.SAXException
Writes the given character as-is.

Parameters:
ch - character to be written
Throws:
org.xml.sax.SAXException - if the character could not be written

write

protected void write(java.lang.String string)
              throws org.xml.sax.SAXException
Writes the given string of character as-is.

Parameters:
string - string of character to be written
Throws:
org.xml.sax.SAXException - if the character string could not be written


Copyright © 2007-2011 The Apache Software Foundation. All Rights Reserved.