org.ajax4jsf.xml.serializer
Class ToXMLSAXHandler

java.lang.Object
  extended by org.ajax4jsf.xml.serializer.SerializerBase
      extended by org.ajax4jsf.xml.serializer.ToSAXHandler
          extended by org.ajax4jsf.xml.serializer.ToXMLSAXHandler
All Implemented Interfaces:
DOMSerializer, SerializationHandler, Serializer, org.xml.sax.DTDHandler, org.xml.sax.ErrorHandler, org.xml.sax.ext.DeclHandler

public final class ToXMLSAXHandler
extends ToSAXHandler

This class receives notification of SAX-like events, and with gathered information over these calls it will invoke the equivalent SAX methods on a handler, the ultimate xsl:output method is known to be "xml". This class is not a public API, it is only public because it is used by Xalan.


Field Summary
static java.lang.String CDATA_CONTINUE
          To insert ]]> in a CDATA section by ending the last CDATA section with ]] and starting the next CDATA section with >
static java.lang.String CDATA_DELIMITER_CLOSE
          The constant "]]>"
static java.lang.String CDATA_DELIMITER_OPEN
           
static java.lang.String DEFAULT_SAX_SERIALIZER
           
static java.lang.String EMPTYSTRING
           
static java.lang.String ENTITY_AMP
           
static java.lang.String ENTITY_CRLF
           
static java.lang.String ENTITY_GT
           
static java.lang.String ENTITY_LT
           
static java.lang.String ENTITY_QUOT
           
static int HTML_ATTREMPTY
           
static int HTML_ATTRURL
           
protected  boolean m_escapeSetting
          Keeps track of whether output escaping is currently enabled
static int NO_BAD_CHARS
           
static java.lang.String XML_PREFIX
           
static java.lang.String XMLNS_PREFIX
           
static java.lang.String XMLNS_URI
           
static java.lang.String XMLVERSION10
           
static java.lang.String XMLVERSION11
          Define the XML version.
 
Fields inherited from class org.ajax4jsf.xml.serializer.ToSAXHandler
m_lexHandler, m_saxHandler, m_state
 
Fields inherited from class org.ajax4jsf.xml.serializer.SerializerBase
m_attrBuff, m_attributes, m_cdataSectionElements, m_cdataTagOpen, m_charsBuff, m_doIndent, m_elemContext, m_indentAmount, m_inEntityRef, m_inExternalDTD, m_needToCallStartDocument, m_prefixMap, m_sourceLocator, m_standaloneWasSpecified, m_tracer, m_writer
 
Constructor Summary
ToXMLSAXHandler()
           
ToXMLSAXHandler(org.xml.sax.ContentHandler handler, org.xml.sax.ext.LexicalHandler lex, java.lang.String encoding)
           
ToXMLSAXHandler(org.xml.sax.ContentHandler handler, java.lang.String encoding)
           
 
Method Summary
 void addAttribute(java.lang.String uri, java.lang.String localName, java.lang.String rawName, java.lang.String type, java.lang.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 attributeDecl(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2, java.lang.String arg3, java.lang.String arg4)
           
 void characters(char[] ch, int off, int len)
           
 void characters(java.lang.String chars)
          Receive notification of character data.
 void 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.
protected  void closeStartTag()
          This method is called when all the data needed for a call to the SAX handler's startElement() method has been gathered.
 void comment(char[] arg0, int arg1, int arg2)
           
 void elementDecl(java.lang.String arg0, java.lang.String arg1)
           
 void endCDATA()
           
 void endDocument()
          Receives notification of the end of the document.
 void endDTD()
           
 void endElement(java.lang.String elemName)
          This method is used to notify that an element has ended.
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
           
 void endPrefixMapping(java.lang.String prefix)
           
 void externalEntityDecl(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2)
           
 java.util.Properties getOutputFormat()
          Returns the output format properties for this serializer.
 java.io.OutputStream getOutputStream()
          Get the output stream where the events will be serialized to.
 java.io.Writer getWriter()
          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(java.lang.String arg0, java.lang.String arg1)
           
 void namespaceAfterStartElement(java.lang.String prefix, java.lang.String uri)
          Send a namespace declaration in the output document.
protected  boolean popNamespace(java.lang.String prefix)
          Undeclare the namespace that is currently pointed to by a given prefix.
 void processingInstruction(java.lang.String target, java.lang.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 serialize(org.w3c.dom.Node node)
          Notify that the serializer should take this DOM node as input to be serialized.
 void setDocumentLocator(org.xml.sax.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(java.util.Properties format)
          Specifies an output format for this serializer.
 void setOutputStream(java.io.OutputStream output)
          Specifies an output stream to which the document should be serialized.
 void setWriter(java.io.Writer writer)
          Specifies a writer to which the document should be serialized.
 void skippedEntity(java.lang.String arg0)
           
 void startCDATA()
           
 void startElement(java.lang.String elementName)
          An element starts, but attributes are not fully known yet.
 void startElement(java.lang.String elementNamespaceURI, java.lang.String elementLocalName, java.lang.String elementName)
          Start an element in the output document.
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String name, org.xml.sax.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(java.lang.String arg0)
           
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
           
 boolean startPrefixMapping(java.lang.String prefix, java.lang.String uri, boolean shouldFlush)
          Remember the prefix/uri mapping at the current nested element depth.
 
Methods inherited from class org.ajax4jsf.xml.serializer.ToSAXHandler
addUniqueAttribute, characters, comment, error, fatalError, flushPending, setCdataSectionElements, setContentHandler, setLexHandler, setShouldOutputNSAttr, setTransformState, startDocumentInternal, startDTD, warning
 
Methods inherited from class org.ajax4jsf.xml.serializer.SerializerBase
addAttribute, addAttribute, addAttributeAlways, addAttributes, addXSLAttribute, asContentHandler, asDOMSerializer, close, endEntity, entityReference, fireCDATAEvent, fireCharEvent, fireCommentEvent, fireEndDoc, fireEndElem, fireEndEntity, fireEntityReference, fireEscapingEvent, fireStartDoc, fireStartElem, fireStartEntity, getDoctypePublic, getDoctypeSystem, getEncoding, getIndent, getIndentAmount, getLocalName, getMediaType, getNamespaceMappings, getNamespaceURI, getNamespaceURIFromPrefix, getOmitXMLDeclaration, getPrefix, getPrefixPart, getStandalone, getTransformer, getVersion, initCDATA, isCdataSection, notationDecl, patchName, setDoctype, setDoctypePublic, setDoctypeSystem, setDTDEntityExpansion, setEncoding, setIndent, setIndentAmount, setMediaType, setNamespaceMappings, setOmitXMLDeclaration, setSourceLocator, setStandalone, setStandaloneInternal, setTransformer, setVersion, startDocument, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_escapeSetting

protected boolean m_escapeSetting
Keeps track of whether output escaping is currently enabled


NO_BAD_CHARS

public static final int NO_BAD_CHARS
See Also:
Constant Field Values

HTML_ATTREMPTY

public static final int HTML_ATTREMPTY
See Also:
Constant Field Values

HTML_ATTRURL

public static final int HTML_ATTRURL
See Also:
Constant Field Values

CDATA_CONTINUE

public static final java.lang.String CDATA_CONTINUE
To insert ]]> in a CDATA section by ending the last CDATA section with ]] and starting the next CDATA section with >

See Also:
Constant Field Values

CDATA_DELIMITER_CLOSE

public static final java.lang.String CDATA_DELIMITER_CLOSE
The constant "]]>"

See Also:
Constant Field Values

CDATA_DELIMITER_OPEN

public static final java.lang.String CDATA_DELIMITER_OPEN
See Also:
Constant Field Values

EMPTYSTRING

public static final java.lang.String EMPTYSTRING
See Also:
Constant Field Values

ENTITY_AMP

public static final java.lang.String ENTITY_AMP
See Also:
Constant Field Values

ENTITY_CRLF

public static final java.lang.String ENTITY_CRLF
See Also:
Constant Field Values

ENTITY_GT

public static final java.lang.String ENTITY_GT
See Also:
Constant Field Values

ENTITY_LT

public static final java.lang.String ENTITY_LT
See Also:
Constant Field Values

ENTITY_QUOT

public static final java.lang.String ENTITY_QUOT
See Also:
Constant Field Values

XML_PREFIX

public static final java.lang.String XML_PREFIX
See Also:
Constant Field Values

XMLNS_PREFIX

public static final java.lang.String XMLNS_PREFIX
See Also:
Constant Field Values

XMLNS_URI

public static final java.lang.String XMLNS_URI
See Also:
Constant Field Values

DEFAULT_SAX_SERIALIZER

public static final java.lang.String DEFAULT_SAX_SERIALIZER
See Also:
Constant Field Values

XMLVERSION11

public static final java.lang.String XMLVERSION11
Define the XML version.

See Also:
Constant Field Values

XMLVERSION10

public static final java.lang.String XMLVERSION10
See Also:
Constant Field Values
Constructor Detail

ToXMLSAXHandler

public ToXMLSAXHandler()

ToXMLSAXHandler

public ToXMLSAXHandler(org.xml.sax.ContentHandler handler,
                       java.lang.String encoding)

ToXMLSAXHandler

public ToXMLSAXHandler(org.xml.sax.ContentHandler handler,
                       org.xml.sax.ext.LexicalHandler lex,
                       java.lang.String encoding)
Method Detail

getOutputFormat

public java.util.Properties 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:
Serializer.getOutputFormat()

getOutputStream

public java.io.OutputStream 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:
Serializer.getOutputStream()

getWriter

public java.io.Writer 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:
Serializer.getWriter()

indent

public void indent(int n)
            throws org.xml.sax.SAXException
Do nothing for SAX.

Throws:
org.xml.sax.SAXException

serialize

public void serialize(org.w3c.dom.Node node)
               throws java.io.IOException
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:
java.io.IOException - if an I/O exception occured while serializing
See Also:
DOMSerializer.serialize(Node)

setEscaping

public boolean setEscaping(boolean escape)
                    throws org.xml.sax.SAXException
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:
org.xml.sax.SAXException
See Also:
SerializationHandler.setEscaping(boolean)

setOutputFormat

public void setOutputFormat(java.util.Properties format)
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 XSLT 1.0 recommendation

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:
Serializer.setOutputFormat(Properties)

setOutputStream

public void setOutputStream(java.io.OutputStream output)
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:
Serializer.setOutputStream(OutputStream)

setWriter

public void setWriter(java.io.Writer writer)
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:
Serializer.setWriter(Writer)

attributeDecl

public void attributeDecl(java.lang.String arg0,
                          java.lang.String arg1,
                          java.lang.String arg2,
                          java.lang.String arg3,
                          java.lang.String arg4)
                   throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
DeclHandler.attributeDecl(String, String, String, String, String)

elementDecl

public void elementDecl(java.lang.String arg0,
                        java.lang.String arg1)
                 throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
DeclHandler.elementDecl(String, String)

externalEntityDecl

public void externalEntityDecl(java.lang.String arg0,
                               java.lang.String arg1,
                               java.lang.String arg2)
                        throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
DeclHandler.externalEntityDecl(String, String, String)

internalEntityDecl

public void internalEntityDecl(java.lang.String arg0,
                               java.lang.String arg1)
                        throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
DeclHandler.internalEntityDecl(String, String)

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Receives notification of the end of the document.

Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.endDocument()

closeStartTag

protected void closeStartTag()
                      throws org.xml.sax.SAXException
This method is called when all the data needed for a call to the SAX handler's startElement() method has been gathered.

Overrides:
closeStartTag in class ToSAXHandler
Throws:
org.xml.sax.SAXException

closeCDATA

public void closeCDATA()
                throws org.xml.sax.SAXException
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.

Overrides:
closeCDATA in class ToSAXHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.endElement(String, String, String)

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.endPrefixMapping(String)

ignorableWhitespace

public void ignorableWhitespace(char[] arg0,
                                int arg1,
                                int arg2)
                         throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.ignorableWhitespace(char[], int, int)

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator arg0)
Description copied from class: SerializerBase
Receive an object for locating the origin of SAX document events.

Overrides:
setDocumentLocator in class SerializerBase
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:
ContentHandler.setDocumentLocator(Locator)

skippedEntity

public void skippedEntity(java.lang.String arg0)
                   throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.skippedEntity(String)

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Parameters:
prefix - The prefix that maps to the URI
uri - The URI for the namespace
Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.startPrefixMapping(String, String)

startPrefixMapping

public boolean startPrefixMapping(java.lang.String prefix,
                                  java.lang.String uri,
                                  boolean shouldFlush)
                           throws org.xml.sax.SAXException
Remember the prefix/uri mapping at the current nested element depth.

Parameters:
prefix - The prefix that maps to the URI
uri - The URI for the namespace
shouldFlush - 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:
org.xml.sax.SAXException
See Also:
ContentHandler.startPrefixMapping(String, String)

comment

public void comment(char[] arg0,
                    int arg1,
                    int arg2)
             throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
LexicalHandler.comment(char[], int, int)

endCDATA

public void endCDATA()
              throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
LexicalHandler.endCDATA()

endDTD

public void endDTD()
            throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
LexicalHandler.endDTD()

startEntity

public void startEntity(java.lang.String arg0)
                 throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
LexicalHandler.startEntity(String)

characters

public void characters(java.lang.String chars)
                throws org.xml.sax.SAXException
Description copied from class: ToSAXHandler
Receive notification of character data.

Overrides:
characters in class ToSAXHandler
Parameters:
chars - The string of characters to process.
Throws:
org.xml.sax.SAXException
See Also:
ExtendedContentHandler.characters(String)

startElement

public void startElement(java.lang.String elementNamespaceURI,
                         java.lang.String elementLocalName,
                         java.lang.String elementName)
                  throws org.xml.sax.SAXException
Start an element in the output document. This might be an XML element (data type) or a CDATA section.

Overrides:
startElement in class ToSAXHandler
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:
org.xml.sax.SAXException
See Also:
ExtendedContentHandler.startElement(String, String, String)

startElement

public void startElement(java.lang.String elementName)
                  throws org.xml.sax.SAXException
Description copied from class: ToSAXHandler
An element starts, but attributes are not fully known yet.

Overrides:
startElement in class ToSAXHandler
Parameters:
elementName - the element name, with prefix (if any).
Throws:
org.xml.sax.SAXException
See Also:
ExtendedContentHandler.startElement(String)

characters

public void characters(char[] ch,
                       int off,
                       int len)
                throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String elemName)
                throws org.xml.sax.SAXException
This method is used to notify that an element has ended. Unlike the standard SAX method
 endElement(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:
org.xml.sax.SAXException
See Also:
ExtendedContentHandler.endElement(String)

namespaceAfterStartElement

public void namespaceAfterStartElement(java.lang.String prefix,
                                       java.lang.String uri)
                                throws org.xml.sax.SAXException
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.

Overrides:
namespaceAfterStartElement in class SerializerBase
Parameters:
prefix - the URI of the namespace
uri - the prefix associated with the given URI.
Throws:
org.xml.sax.SAXException
See Also:
ExtendedContentHandler.namespaceAfterStartElement(String, String)

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
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.

Overrides:
processingInstruction in class ToSAXHandler
Throws:
org.xml.sax.SAXException
See Also:
Send a processing instruction to the output document

popNamespace

protected boolean popNamespace(java.lang.String prefix)
Undeclare the namespace that is currently pointed to by a given prefix. Inform SAX handler if prefix was previously mapped.


startCDATA

public void startCDATA()
                throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String name,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.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.

Overrides:
startElement in class ToSAXHandler
Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.startElement(String, String, String, Attributes)

addAttribute

public void addAttribute(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String rawName,
                         java.lang.String type,
                         java.lang.String value,
                         boolean XSLAttribute)
                  throws org.xml.sax.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.

Overrides:
addAttribute in class SerializerBase
Parameters:
uri - the URI of the attribute
localName - the local name of the attribute
rawName - the qualified name of the attribute
type - the type of the attribute (probably CDATA)
value - the value of the attribute
XSLAttribute - true if this attribute is coming from an xsl:attribute element
Throws:
org.xml.sax.SAXException
See Also:
ExtendedContentHandler.addAttribute(String, String, String, String, String)

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 interface Serializer
Overrides:
reset in class ToSAXHandler
Returns:
true if the class was successfuly reset.
See Also:
Serializer.reset()


Copyright © 2010. All Rights Reserved.