org.opencms.util
Class CmsXmlSaxWriter

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.opencms.util.CmsXmlSaxWriter
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, LexicalHandler

public class CmsXmlSaxWriter
extends DefaultHandler
implements LexicalHandler

Simple SAX event handler that generates a XML file from the events caught.

This is to be used for writing large XML files where keeping a DOM structure in memory might cause out-of-memory issues, like e.g. when writing the OpenCms export files.

Since:
6.0.0
Version:
$Revision: 1.12 $
Author:
Alexander Kandzior

Constructor Summary
CmsXmlSaxWriter(Writer writer, String encoding)
          A SAX event handler that generates XML Strings from the events caught and writes them to the given Writer.
 
Method Summary
 void characters(char[] buf, int offset, int len)
           
 void comment(char[] ch, int start, int length)
           
 void endCDATA()
           
 void endDocument()
           
 void endDTD()
           
 void endElement(String namespaceURI, String localName, String qualifiedName)
           
 void endEntity(String name)
           
 Writer getWriter()
          Returns the Writer where the XML is written to.
 void startCDATA()
           
 void startDocument()
           
 void startDTD(String name, String publicId, String systemId)
           
 void startElement(String namespaceURI, String localName, String qualifiedName, Attributes attributes)
           
 void startEntity(String name)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsXmlSaxWriter

public CmsXmlSaxWriter(Writer writer,
                       String encoding)
A SAX event handler that generates XML Strings from the events caught and writes them to the given Writer.

Parameters:
writer - the Writer to write to output to
encoding - the encoding for the XML output file header
Method Detail

characters

public void characters(char[] buf,
                       int offset,
                       int len)
                throws SAXException
Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
Throws:
SAXException
See Also:
ContentHandler.characters(char[], int, int)

comment

public void comment(char[] ch,
                    int start,
                    int length)
Specified by:
comment in interface LexicalHandler
See Also:
LexicalHandler.comment(char[], int, int)

endCDATA

public void endCDATA()
              throws SAXException
Specified by:
endCDATA in interface LexicalHandler
Throws:
SAXException
See Also:
LexicalHandler.endCDATA()

endDocument

public void endDocument()
                 throws SAXException
Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class DefaultHandler
Throws:
SAXException
See Also:
ContentHandler.endDocument()

endDTD

public void endDTD()
Specified by:
endDTD in interface LexicalHandler
See Also:
LexicalHandler.endDTD()

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qualifiedName)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Throws:
SAXException
See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)

endEntity

public void endEntity(String name)
Specified by:
endEntity in interface LexicalHandler
See Also:
LexicalHandler.endEntity(java.lang.String)

getWriter

public Writer getWriter()
Returns the Writer where the XML is written to.

Returns:
the Writer where the XML is written to

startCDATA

public void startCDATA()
Specified by:
startCDATA in interface LexicalHandler
See Also:
LexicalHandler.startCDATA()

startDocument

public void startDocument()
                   throws SAXException
Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class DefaultHandler
Throws:
SAXException
See Also:
ContentHandler.startDocument()

startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
Specified by:
startDTD in interface LexicalHandler
See Also:
LexicalHandler.startDTD(java.lang.String, java.lang.String, java.lang.String)

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qualifiedName,
                         Attributes attributes)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Throws:
SAXException
See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

startEntity

public void startEntity(String name)
Specified by:
startEntity in interface LexicalHandler
See Also:
LexicalHandler.startEntity(java.lang.String)