Package org.opencms.util
Class CmsXmlSaxWriter
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.opencms.util.CmsXmlSaxWriter
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler
,org.xml.sax.DTDHandler
,org.xml.sax.EntityResolver
,org.xml.sax.ErrorHandler
,org.xml.sax.ext.LexicalHandler
public class CmsXmlSaxWriter extends org.xml.sax.helpers.DefaultHandler implements org.xml.sax.ext.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
Constructors Constructor Description 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(java.io.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(java.io.Writer writer, java.lang.String encoding)
A SAX event handler that generates XML / HTML Strings from the events caught and writes them to the given Writer.CmsXmlSaxWriter(java.lang.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
characters(char[] buf, int offset, int len)
void
comment(char[] ch, int start, int length)
void
endCDATA()
void
endDocument()
void
endDTD()
void
endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qualifiedName)
void
endEntity(java.lang.String name)
java.lang.String
getEncoding()
Returns the encoding this XML Sax writer was initialized with.java.io.Writer
getWriter()
Returns the Writer where the XML is written to.boolean
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).boolean
isEscapeXml()
Returnstrue
if XML entities are to be encoded in the generated output (not in CDATA elements).void
setEncoding(java.lang.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
startCDATA()
void
startDocument()
void
startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
void
startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qualifiedName, org.xml.sax.Attributes attributes)
void
startEntity(java.lang.String name)
-
-
-
Constructor Detail
-
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
public CmsXmlSaxWriter(java.lang.String encoding)
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
public CmsXmlSaxWriter(java.io.Writer writer)
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
public CmsXmlSaxWriter(java.io.Writer writer, java.lang.String encoding)
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 Detail
-
characters
public void characters(char[] buf, int offset, int len) throws org.xml.sax.SAXException
- Specified by:
characters
in interfaceorg.xml.sax.ContentHandler
- Overrides:
characters
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
- See Also:
ContentHandler.characters(char[], int, int)
-
comment
public void comment(char[] ch, int start, int length)
- Specified by:
comment
in interfaceorg.xml.sax.ext.LexicalHandler
- See Also:
LexicalHandler.comment(char[], int, int)
-
endCDATA
public void endCDATA() throws org.xml.sax.SAXException
- Specified by:
endCDATA
in interfaceorg.xml.sax.ext.LexicalHandler
- Throws:
org.xml.sax.SAXException
- See Also:
LexicalHandler.endCDATA()
-
endDocument
public void endDocument() throws org.xml.sax.SAXException
- Specified by:
endDocument
in interfaceorg.xml.sax.ContentHandler
- Overrides:
endDocument
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
- See Also:
ContentHandler.endDocument()
-
endDTD
public void endDTD()
- Specified by:
endDTD
in interfaceorg.xml.sax.ext.LexicalHandler
- See Also:
LexicalHandler.endDTD()
-
endElement
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qualifiedName) throws org.xml.sax.SAXException
- Specified by:
endElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
endElement
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
- See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
-
endEntity
public void endEntity(java.lang.String name)
- Specified by:
endEntity
in interfaceorg.xml.sax.ext.LexicalHandler
- See Also:
LexicalHandler.endEntity(java.lang.String)
-
getEncoding
public java.lang.String getEncoding()
Returns the encoding this XML Sax writer was initialized with.- Returns:
- the encoding this XML Sax writer was initialized with
-
getWriter
public java.io.Writer getWriter()
Returns the Writer where the XML is written to.- Returns:
- the Writer where the XML is written to
-
isEscapeUnknownChars
public boolean 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
public boolean 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
public void setEncoding(java.lang.String value)
Sets the encoding to use for the generated output.- Parameters:
value
- the encoding to use for the generated output
-
setEscapeUnknownChars
public 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).- Parameters:
value
- indicates to escape unknown characters with XML entities or not
-
setEscapeXml
public void setEscapeXml(boolean value)
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
public void startCDATA()
- Specified by:
startCDATA
in interfaceorg.xml.sax.ext.LexicalHandler
- See Also:
LexicalHandler.startCDATA()
-
startDocument
public void startDocument() throws org.xml.sax.SAXException
- Specified by:
startDocument
in interfaceorg.xml.sax.ContentHandler
- Overrides:
startDocument
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
- See Also:
ContentHandler.startDocument()
-
startDTD
public void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException
- Specified by:
startDTD
in interfaceorg.xml.sax.ext.LexicalHandler
- Throws:
org.xml.sax.SAXException
- See Also:
LexicalHandler.startDTD(java.lang.String, java.lang.String, java.lang.String)
-
startElement
public void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qualifiedName, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException
- Specified by:
startElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
startElement
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
- See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
-
startEntity
public void startEntity(java.lang.String name)
- Specified by:
startEntity
in interfaceorg.xml.sax.ext.LexicalHandler
- See Also:
LexicalHandler.startEntity(java.lang.String)
-
-