Class ToXMLSAXHandler
- All Implemented Interfaces:
DOMSerializer
,ExtendedContentHandler
,ExtendedLexicalHandler
,SerializationHandler
,Serializer
,ContentHandler
,DTDHandler
,ErrorHandler
,DeclHandler
,LexicalHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
To insert ]]> in a CDATA section by ending the last CDATA section with ]] and starting the next CDATA section with >static final String
The constant "]]>"static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
Define the XML version.Fields inherited from class org.apache.xml.serializer.SerializerBase
PKG_NAME, PKG_PATH
Fields inherited from interface org.apache.xml.serializer.ExtendedContentHandler
HTML_ATTREMPTY, HTML_ATTRURL, NO_BAD_CHARS
-
Constructor Summary
ConstructorsConstructorDescriptionToXMLSAXHandler
(ContentHandler handler, String encoding) ToXMLSAXHandler
(ContentHandler handler, LexicalHandler lex, String encoding) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttribute
(String uri, String localName, String rawName, String type, String value, boolean XSLAttribute) Adds the given attribute to the set of attributes, and also makes sure that the needed prefix/uri mapping is declared, but only if there is a currently open element.void
void
characters
(char[] ch, int off, int len) void
characters
(String chars) Receive notification of character data.void
Closes ane open cdata tag, and unlike the this.endCDATA() method (from the LexicalHandler) interface, this "internal" method will send the endCDATA() call to the wrapped handler.void
comment
(char[] arg0, int arg1, int arg2) void
elementDecl
(String arg0, String arg1) void
endCDATA()
void
Receives notification of the end of the document.void
endDTD()
void
endElement
(String elemName) This method is used to notify that an element has ended.void
endElement
(String namespaceURI, String localName, String qName) void
endPrefixMapping
(String prefix) void
externalEntityDecl
(String arg0, String arg1, String arg2) Returns the output format properties for this serializer.Get the output stream where the events will be serialized to.Get the character stream where the events will be serialized to.void
ignorableWhitespace
(char[] arg0, int arg1, int arg2) void
indent
(int n) Do nothing for SAX.void
internalEntityDecl
(String arg0, String arg1) void
namespaceAfterStartElement
(String prefix, String uri) Send a namespace declaration in the output document.void
processingInstruction
(String target, String data) Do nothing as this is an abstract class.boolean
reset()
Try's to reset the super class and reset this class for re-use, so that you don't need to create a new serializer (mostly for performance reasons).void
Notify that the serializer should take this DOM node as input to be serialized.void
setDocumentLocator
(Locator arg0) Receive an object for locating the origin of SAX document events.boolean
setEscaping
(boolean escape) Turns special character escaping on/off.void
setOutputFormat
(Properties format) Specifies an output format for this serializer.void
setOutputStream
(OutputStream output) Specifies an output stream to which the document should be serialized.void
Specifies a writer to which the document should be serialized.void
skippedEntity
(String arg0) void
void
startElement
(String elementName) An element starts, but attributes are not fully known yet.void
startElement
(String elementNamespaceURI, String elementLocalName, String elementName) Start an element in the output document.void
startElement
(String namespaceURI, String localName, String name, Attributes atts) Receive notification of the beginning of an element, although this is a SAX method additional namespace or attribute information can occur before or after this call, that is associated with this element.void
startEntity
(String arg0) void
startPrefixMapping
(String prefix, String uri) boolean
startPrefixMapping
(String prefix, String uri, boolean shouldFlush) Remember the prefix/uri mapping at the current nested element depth.Methods inherited from class org.apache.xml.serializer.ToSAXHandler
addUniqueAttribute, characters, comment, error, fatalError, flushPending, setCdataSectionElements, setContentHandler, setLexHandler, setShouldOutputNSAttr, setTransformState, startDTD, warning
Methods inherited from class org.apache.xml.serializer.SerializerBase
addAttribute, addAttribute, addAttributeAlways, addAttributes, addXSLAttribute, asContentHandler, asDOM3Serializer, asDOMSerializer, close, documentIsEmpty, endEntity, entityReference, fireEndEntity, getDoctypePublic, getDoctypeSystem, getEncoding, getIndent, getIndentAmount, getMediaType, getNamespaceMappings, getNamespaceURI, getNamespaceURIFromPrefix, getOmitXMLDeclaration, getOutputProperty, getOutputPropertyDefault, getOutputPropertyNonDefault, getPrefix, getStandalone, getTransformer, getVersion, notationDecl, setDoctype, setDoctypePublic, setDoctypeSystem, setDTDEntityExpansion, setEncoding, setIndent, setIndentAmount, setMediaType, setNamespaceMappings, setOmitXMLDeclaration, setOutputProperty, setOutputPropertyDefault, setSourceLocator, setStandalone, setTransformer, setVersion, startDocument, unparsedEntityDecl
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Field Details
-
CDATA_CONTINUE
To insert ]]> in a CDATA section by ending the last CDATA section with ]] and starting the next CDATA section with >- See Also:
-
CDATA_DELIMITER_CLOSE
The constant "]]>"- See Also:
-
CDATA_DELIMITER_OPEN
- See Also:
-
EMPTYSTRING
- See Also:
-
ENTITY_AMP
- See Also:
-
ENTITY_CRLF
- See Also:
-
ENTITY_GT
- See Also:
-
ENTITY_LT
- See Also:
-
ENTITY_QUOT
- See Also:
-
XML_PREFIX
- See Also:
-
XMLNS_PREFIX
- See Also:
-
XMLNS_URI
- See Also:
-
DEFAULT_SAX_SERIALIZER
-
XMLVERSION11
Define the XML version.- See Also:
-
XMLVERSION10
- See Also:
-
-
Constructor Details
-
ToXMLSAXHandler
public ToXMLSAXHandler() -
ToXMLSAXHandler
-
ToXMLSAXHandler
-
-
Method Details
-
getOutputFormat
Description copied from interface:Serializer
Returns the output format properties for this serializer.- Returns:
- The output format key/value pairs in use.
- See Also:
-
getOutputStream
Description copied from interface:Serializer
Get the output stream where the events will be serialized to.- Returns:
- reference to the result stream, or null if only a writer was set.
- See Also:
-
getWriter
Description copied from interface:Serializer
Get the character stream where the events will be serialized to.- Returns:
- Reference to the result Writer, or null.
- See Also:
-
indent
Do nothing for SAX.- Throws:
SAXException
-
serialize
Description copied from interface:SerializationHandler
Notify that the serializer should take this DOM node as input to be serialized.- Parameters:
node
- the DOM node to be serialized.- Throws:
IOException
- See Also:
-
setEscaping
Description copied from interface:SerializationHandler
Turns special character escaping on/off. Note that characters will never, even if this option is set to 'true', be escaped within CDATA sections in output XML documents.- Parameters:
escape
- true if escaping is to be set on.- Throws:
SAXException
- See Also:
-
setOutputFormat
Description copied from interface:Serializer
Specifies an output format for this serializer. It the serializer has already been associated with an output format, it will switch to the new format. This method should not be called while the serializer is in the process of serializing a document.The standard property keys supported are: "method", "version", "encoding", "omit-xml-declaration", "standalone", doctype-public", "doctype-system", "cdata-section-elements", "indent", "media-type". These property keys and their values are described in the XSLT recommendation, see
invalid @link
{@link <a href="http://www.w3.org/TR/1999/REC-xslt-19991116">
The non-standard property keys supported are defined in
OutputPropertiesFactory
.This method can be called multiple times before a document is serialized. Each time it is called more, or over-riding property values, can be specified. One property value that can not be changed is that of the "method" property key.
The value of the "cdata-section-elements" property key is a whitespace separated list of elements. If the element is in a namespace then value is passed in this format: {uri}localName
If the "cdata-section-elements" key is specified on multiple calls to this method the set of elements specified in the value is not replaced from one call to the next, but it is cumulative across the calls.
- Parameters:
format
- The output format to use, as a set of key/value pairs.- See Also:
-
setOutputStream
Description copied from interface:Serializer
Specifies an output stream to which the document should be serialized. This method should not be called while the serializer is in the process of serializing a document.The encoding specified in the output
Properties
is used, or if no encoding was specified, the default for the selected output method.Only one of setWriter() or setOutputStream() should be called.
- Parameters:
output
- The output stream- See Also:
-
setWriter
Description copied from interface:Serializer
Specifies a writer to which the document should be serialized. This method should not be called while the serializer is in the process of serializing a document.The encoding specified for the output
Properties
must be identical to the output format used with the writer.Only one of setWriter() or setOutputStream() should be called.
- Parameters:
writer
- The output writer stream- See Also:
-
attributeDecl
public void attributeDecl(String arg0, String arg1, String arg2, String arg3, String arg4) throws SAXException - Throws:
SAXException
- See Also:
-
elementDecl
- Throws:
SAXException
- See Also:
-
externalEntityDecl
- Throws:
SAXException
- See Also:
-
internalEntityDecl
- Throws:
SAXException
- See Also:
-
endDocument
Receives notification of the end of the document.- Throws:
SAXException
- See Also:
-
closeCDATA
Closes ane open cdata tag, and unlike the this.endCDATA() method (from the LexicalHandler) interface, this "internal" method will send the endCDATA() call to the wrapped handler.- Throws:
SAXException
-
endElement
- Throws:
SAXException
- See Also:
-
endPrefixMapping
- Throws:
SAXException
- See Also:
-
ignorableWhitespace
- Throws:
SAXException
- See Also:
-
setDocumentLocator
Description copied from class:SerializerBase
Receive an object for locating the origin of SAX document events.- Specified by:
setDocumentLocator
in interfaceContentHandler
- Overrides:
setDocumentLocator
in classSerializerBase
- Parameters:
arg0
- An object that can return the location of any SAX document event. Receive an object for locating the origin of SAX document events.SAX parsers are strongly encouraged (though not absolutely required) to supply a locator: if it does so, it must supply the locator to the application by invoking this method before invoking any of the other methods in the DocumentHandler interface.
The locator allows the application to determine the end position of any document-related event, even if the parser is not reporting an error. Typically, the application will use this information for reporting its own errors (such as character content that does not match an application's business rules). The information returned by the locator is probably not sufficient for use with a search engine.
Note that the locator will return correct information only during the invocation of the events in this interface. The application should not attempt to use it at any other time.
- See Also:
-
skippedEntity
- Throws:
SAXException
- See Also:
-
startPrefixMapping
- Parameters:
prefix
- The prefix that maps to the URIuri
- The URI for the namespace- Throws:
SAXException
- See Also:
-
startPrefixMapping
public boolean startPrefixMapping(String prefix, String uri, boolean shouldFlush) throws SAXException Remember the prefix/uri mapping at the current nested element depth.- Parameters:
prefix
- The prefix that maps to the URIuri
- The URI for the namespaceshouldFlush
- a flag indicating if the mapping applies to the current element or an up coming child (not used).- Returns:
- boolean false if the prefix mapping was already in effect (in other words we are just re-declaring), true if this is a new, never before seen mapping for the element.
- Throws:
SAXException
- See Also:
-
comment
- Throws:
SAXException
- See Also:
-
endCDATA
- Throws:
SAXException
- See Also:
-
endDTD
- Throws:
SAXException
- See Also:
-
startEntity
- Throws:
SAXException
- See Also:
-
characters
Description copied from class:ToSAXHandler
Receive notification of character data.- Specified by:
characters
in interfaceExtendedContentHandler
- Overrides:
characters
in classToSAXHandler
- Parameters:
chars
- The string of characters to process.- Throws:
SAXException
- See Also:
-
startElement
public void startElement(String elementNamespaceURI, String elementLocalName, String elementName) throws SAXException Start an element in the output document. This might be an XML element (data type) or a CDATA section.- Specified by:
startElement
in interfaceExtendedContentHandler
- Overrides:
startElement
in classToSAXHandler
- Parameters:
elementNamespaceURI
- the URI of the namespace of the element (optional)elementLocalName
- the element name, but without prefix (optional)elementName
- the element name, with prefix, if any (required)- Throws:
SAXException
- See Also:
-
startElement
Description copied from class:ToSAXHandler
An element starts, but attributes are not fully known yet.- Specified by:
startElement
in interfaceExtendedContentHandler
- Overrides:
startElement
in classToSAXHandler
- Parameters:
elementName
- the element name, with prefix (if any).- Throws:
SAXException
- See Also:
-
characters
- Throws:
SAXException
-
endElement
Description copied from interface:ExtendedContentHandler
This method is used to notify that an element has ended. Unlike the standard SAX methodendElement(namespaceURI,localName,qName)
only the last parameter is passed. If needed the serializer can derive the localName from the qualified name and derive the namespaceURI from its implementation.- Parameters:
elemName
- the fully qualified element name.- Throws:
SAXException
- See Also:
-
namespaceAfterStartElement
Send a namespace declaration in the output document. The namespace declaration will not be include if the namespace is already in scope with the same prefix.- Specified by:
namespaceAfterStartElement
in interfaceExtendedContentHandler
- Overrides:
namespaceAfterStartElement
in classSerializerBase
- Parameters:
prefix
- the URI of the namespaceuri
- the prefix associated with the given URI.- Throws:
SAXException
- See Also:
-
processingInstruction
Description copied from class:ToSAXHandler
Do nothing as this is an abstract class. All subclasses will need to define their behavior if it is different.- Specified by:
processingInstruction
in interfaceContentHandler
- Overrides:
processingInstruction
in classToSAXHandler
- Throws:
SAXException
- See Also:
-
startCDATA
- Throws:
SAXException
-
startElement
public void startElement(String namespaceURI, String localName, String name, Attributes atts) throws SAXException Description copied from class:ToSAXHandler
Receive notification of the beginning of an element, although this is a SAX method additional namespace or attribute information can occur before or after this call, that is associated with this element.- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classToSAXHandler
- Throws:
SAXException
- Any SAX exception, possibly wrapping another exception.SAXException
- See Also:
-
addAttribute
public void addAttribute(String uri, String localName, String rawName, String type, String value, boolean XSLAttribute) throws SAXException Adds the given attribute to the set of attributes, and also makes sure that the needed prefix/uri mapping is declared, but only if there is a currently open element.- Specified by:
addAttribute
in interfaceExtendedContentHandler
- Overrides:
addAttribute
in classSerializerBase
- Parameters:
uri
- the URI of the attributelocalName
- the local name of the attributerawName
- the qualified name of the attributetype
- the type of the attribute (probably CDATA)value
- the value of the attributeXSLAttribute
- true if this attribute is coming from an xsl:attribute element- Throws:
SAXException
- See Also:
-
reset
public boolean reset()Try's to reset the super class and reset this class for re-use, so that you don't need to create a new serializer (mostly for performance reasons).- Specified by:
reset
in interfaceSerializer
- Overrides:
reset
in classToSAXHandler
- Returns:
- true if the class was successfuly reset.
- See Also:
-