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
ConstructorDescriptionCreates a SAX event handler that generates XML / HTML Strings from the events caught using a new
and the OpenCms default encoding.StringWriter
CmsXmlSaxWriter
(Writer writer) Creates a SAX event handler that generates XML / HTML Strings from the events caught using a new
and the given encoding.StringWriter
CmsXmlSaxWriter
(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 new
and the given encoding.StringWriter
-
Method Summary
Modifier and TypeMethodDescriptionvoid
characters
(char[] buf, int offset, int len) void
comment
(char[] ch, int start, int length) void
endCDATA()
void
void
endDTD()
void
endElement
(String namespaceURI, String localName, String qualifiedName) void
Returns the encoding this XML Sax writer was initialized with.Returns the Writer where the XML is written to.boolean
Returnstrue
if 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).boolean
Returnstrue
if XML entities are to be encoded in the generated output (not in CDATA elements).void
setEncoding
(String value) Sets the encoding to use for the generated output.void
setEscapeUnknownChars
(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).void
setEscapeXml
(boolean value) If set totrue
, then XML entities are to be encoded in the generated output (not in CDATA elements).void
void
void
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
Methods 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 new
and the OpenCms default encoding.StringWriter
-
CmsXmlSaxWriter
Creates a SAX event handler that generates XML / HTML Strings from the events caught using a new
and 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 new
and 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:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
- Throws:
SAXException
- See Also:
-
comment
- Specified by:
comment
in interfaceLexicalHandler
- See Also:
-
endCDATA
- Specified by:
endCDATA
in interfaceLexicalHandler
- Throws:
SAXException
- See Also:
-
endDocument
- Specified by:
endDocument
in interfaceContentHandler
- Overrides:
endDocument
in classDefaultHandler
- Throws:
SAXException
- See Also:
-
endDTD
- Specified by:
endDTD
in interfaceLexicalHandler
- See Also:
-
endElement
public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException - Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Throws:
SAXException
- See Also:
-
endEntity
- Specified by:
endEntity
in 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
Returnstrue
if 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:
true
if charactes that are not part of the selected encoding are to be replaced with the HTML entity representation
-
isEscapeXml
Returnstrue
if XML entities are to be encoded in the generated output (not in CDATA elements).- Returns:
true
if 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:
startCDATA
in interfaceLexicalHandler
- See Also:
-
startDocument
- Specified by:
startDocument
in interfaceContentHandler
- Overrides:
startDocument
in classDefaultHandler
- Throws:
SAXException
- See Also:
-
startDTD
- Specified by:
startDTD
in interfaceLexicalHandler
- Throws:
SAXException
- See Also:
-
startElement
public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes attributes) throws SAXException - Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Throws:
SAXException
- See Also:
-
startEntity
- Specified by:
startEntity
in interfaceLexicalHandler
- See Also:
-