Package org.opencms.util
Class CmsXmlSaxWriter
java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.opencms.util.CmsXmlSaxWriter
- All Implemented Interfaces:
ContentHandler,DTDHandler,EntityResolver,ErrorHandler,LexicalHandler
Simple SAX event handler that generates a XML (or HTML) file from the events caught.
This can 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.
It can also be used if a is needed that should
generate a XML / HTML file from a series of SAX events.ContentHandler
- Since:
- 6.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a SAX event handler that generates XML / HTML Strings from the events caught using a newand the OpenCms default encoding.StringWriterCmsXmlSaxWriter(Writer writer) Creates a SAX event handler that generates XML / HTML Strings from the events caught using a newand the given encoding.StringWriterCmsXmlSaxWriter(Writer writer, String encoding) A SAX event handler that generates XML / HTML Strings from the events caught and writes them to the given Writer.CmsXmlSaxWriter(String encoding) Creates a SAX event handler that generates XML / HTML Strings from the events caught using a newand the given encoding.StringWriter -
Method Summary
Modifier and TypeMethodDescriptionvoidcharacters(char[] buf, int offset, int len) voidcomment(char[] ch, int start, int length) voidendCDATA()voidvoidendDTD()voidendElement(String namespaceURI, String localName, String qualifiedName) voidReturns the encoding this XML Sax writer was initialized with.Returns the Writer where the XML is written to.booleanReturnstrueif charactes that are not part of the selected encoding are to be replaced with the HTML{entity representation in the generated output (not in CDATA elements).booleanReturnstrueif XML entities are to be encoded in the generated output (not in CDATA elements).voidsetEncoding(String value) Sets the encoding to use for the generated output.voidsetEscapeUnknownChars(boolean value) If set totrue, then charactes that are not part of the selected encoding are to be replaced with the XML{entity representation in the generated output (not in CDATA elements).voidsetEscapeXml(boolean value) If set totrue, then XML entities are to be encoded in the generated output (not in CDATA elements).voidvoidvoidvoidstartElement(String namespaceURI, String localName, String qualifiedName, Attributes attributes) voidstartEntity(String name) Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warningMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.xml.sax.ContentHandler
declaration
-
Constructor Details
-
CmsXmlSaxWriter
public CmsXmlSaxWriter()Creates a SAX event handler that generates XML / HTML Strings from the events caught using a newand the OpenCms default encoding.StringWriter -
CmsXmlSaxWriter
Creates a SAX event handler that generates XML / HTML Strings from the events caught using a newand the given encoding.StringWriter- Parameters:
encoding- the encoding for the XML file
-
CmsXmlSaxWriter
Creates a SAX event handler that generates XML / HTML Strings from the events caught using a newand the given encoding.StringWriter- Parameters:
writer- the Writer to write to output to
-
CmsXmlSaxWriter
A SAX event handler that generates XML / HTML Strings from the events caught and writes them to the given Writer.- Parameters:
writer- the Writer to write to output toencoding- the encoding for the XML file
-
-
Method Details
-
characters
- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler- Throws:
SAXException- See Also:
-
comment
- Specified by:
commentin interfaceLexicalHandler- See Also:
-
endCDATA
- Specified by:
endCDATAin interfaceLexicalHandler- Throws:
SAXException- See Also:
-
endDocument
- Specified by:
endDocumentin interfaceContentHandler- Overrides:
endDocumentin classDefaultHandler- Throws:
SAXException- See Also:
-
endDTD
- Specified by:
endDTDin interfaceLexicalHandler- See Also:
-
endElement
public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException - Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Throws:
SAXException- See Also:
-
endEntity
- Specified by:
endEntityin interfaceLexicalHandler- See Also:
-
getEncoding
Returns the encoding this XML Sax writer was initialized with.- Returns:
- the encoding this XML Sax writer was initialized with
-
getWriter
Returns the Writer where the XML is written to.- Returns:
- the Writer where the XML is written to
-
isEscapeUnknownChars
Returnstrueif charactes that are not part of the selected encoding are to be replaced with the HTML{entity representation in the generated output (not in CDATA elements).- Returns:
trueif charactes that are not part of the selected encoding are to be replaced with the HTML entity representation
-
isEscapeXml
Returnstrueif XML entities are to be encoded in the generated output (not in CDATA elements).- Returns:
trueif XML entities are to be encoded in the generated output (not in CDATA elements)
-
setEncoding
Sets the encoding to use for the generated output.- Parameters:
value- the encoding to use for the generated output
-
setEscapeUnknownChars
If set totrue, then charactes that are not part of the selected encoding are to be replaced with the XML{entity representation in the generated output (not in CDATA elements).- Parameters:
value- indicates to escape unknown characters with XML entities or not
-
setEscapeXml
If set totrue, then XML entities are to be encoded in the generated output (not in CDATA elements).- Parameters:
value- indicates to to escape characters with XML entities or not
-
startCDATA
- Specified by:
startCDATAin interfaceLexicalHandler- See Also:
-
startDocument
- Specified by:
startDocumentin interfaceContentHandler- Overrides:
startDocumentin classDefaultHandler- Throws:
SAXException- See Also:
-
startDTD
- Specified by:
startDTDin interfaceLexicalHandler- Throws:
SAXException- See Also:
-
startElement
public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes attributes) throws SAXException - Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- Throws:
SAXException- See Also:
-
startEntity
- Specified by:
startEntityin interfaceLexicalHandler- See Also:
-