Top Description Fields Constructors Methods
com.sun.org.apache.xml.internal.serializer

public abstract Class ToSAXHandler

extends SerializerBase
Class Inheritance
Known Direct Subclasses
com.sun.org.apache.xml.internal.serializer.ToTextSAXHandler, com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler, com.sun.org.apache.xml.internal.serializer.ToHTMLSAXHandler
Imports
java.util.List, org.xml.sax.Attributes, .ContentHandler, .ErrorHandler, .SAXException, .SAXParseException, org.xml.sax.ext.LexicalHandler

This class is used to provide a base behavior to be inherited by other To...SAXHandler serializers. This class is not a public API.

Field Summary

Modifier and TypeField and Description
protected LexicalHandler
m_lexHandler

Underlying LexicalHandler.

protected ContentHandler
m_saxHandler

Underlying SAX handler.

private boolean
m_shouldGenerateNSAttribute

A startPrefixMapping() call on a ToSAXHandler will pass that call on to the wrapped ContentHandler, but should we also mirror these calls with matching attributes, if so this field is true.

protected TransformStateSetter
m_state

If this is true, then the content handler wrapped by this serializer implements the TransformState interface which will give the content handler access to the state of the transform.

Inherited from com.sun.org.apache.xml.internal.serializer.SerializerBase:
m_attrBuffm_attributesm_CdataElemsm_cdataTagOpenm_charsBuffm_docIsEmptym_doctypePublicm_doctypeSystemm_doIndentm_elemContextm_errListenerm_indentAmountm_inEntityRefm_inExternalDTDm_isStandalonem_mediatypem_needToCallSetDocumentInfom_needToCallStartDocumentm_needToOutputDocTypeDeclm_prefixMapm_shouldNotWriteXMLHeaderm_sourceLocatorm_standaloneWasSpecifiedm_StringOfCDATASectionsm_tracerm_versionm_writer

Constructor Summary

AccessConstructor and Description
public
public
public
ToSAXHandler(ContentHandler handler, String encoding)

Method Summary

Modifier and TypeMethod and Description
public void
addUniqueAttribute(String
the fully qualified attribute name.
qName
,
String
the attribute value
value
,
int
a bitwise flag
flags
)

Implements com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler.addUniqueAttribute.

Add a unique attribute

public void
characters(String
The string of characters to process.
chars
)

Implements com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler.characters.

Receive notification of character data.

public void
characters(Node
the Node to serialize
node
)

Overrides com.sun.org.apache.xml.internal.serializer.SerializerBase.characters.

Implements com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler.characters.

This method gets the node's value as a String and uses that String as if it were an input character notification.

protected void
protected void
public void
comment(String
the comment, but unlike the SAX comment() method this method takes a String rather than a character array.
comment
)

Overrides com.sun.org.apache.xml.internal.serializer.SerializerBase.comment.

Implements com.sun.org.apache.xml.internal.serializer.ExtendedLexicalHandler.comment.

Receive notification of a comment.

public void
error(SAXParseException
The error information encapsulated in a SAX parse exception.
exc
)

Overrides com.sun.org.apache.xml.internal.serializer.SerializerBase.error.

Implements org.xml.sax.ErrorHandler.error.

Receive notification of a recoverable error.

public void
fatalError(SAXParseException
The error information encapsulated in a SAXParseException.
exc
)

Overrides com.sun.org.apache.xml.internal.serializer.SerializerBase.fatalError.

Implements org.xml.sax.ErrorHandler.fatalError.

Receive notification of a non-recoverable, fatal error.

public void
flushPending()

Implements com.sun.org.apache.xml.internal.serializer.SerializationHandler.flushPending.

This method flushes any pending events, which can be startDocument() closing the opening tag of an element, or closing an open CDATA section.

pack-priv boolean
getShouldOutputNSAttr()

Returns true if namespace declarations from calls such as startPrefixMapping("prefix1","uri1") should also be mirrored with self generated additional attributes of elements that declare the namespace, for example the attribute xmlns:prefix1="uri1"

public void
processingInstruction(String
the processing instruction target
target
,
String
the processing instruction data, or null if none was supplied. The data does not include any whitespace separating it from the target
data
)

Implements org.xml.sax.ContentHandler.processingInstruction.

Do nothing as this is an abstract class.

public boolean

Returns:

true if the class was successfuly reset.
reset
()

Overrides com.sun.org.apache.xml.internal.serializer.SerializerBase.reset.

Implements com.sun.org.apache.xml.internal.serializer.Serializer.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).

private void
resetToSAXHandler()

Reset all of the fields owned by ToSAXHandler class

public void
setCdataSectionElements(List<String>
pairs of namespace URI and local names that identify elements whose text elements are to be output as CDATA sections. The namespace of the local element must be the given URI to match. The qName is not given because the prefix does not matter, only the namespace URI to which that prefix would map matters, so the prefix itself is not relevant in specifying which elements have their text to be output as CDATA sections.
URI_and_localNames
)

Implements com.sun.org.apache.xml.internal.serializer.XSLOutputAttributes.setCdataSectionElements.

Does nothing.

public void
setContentHandler(ContentHandler
The ContentHandler to set
_saxHandler
)

Implements com.sun.org.apache.xml.internal.serializer.SerializationHandler.setContentHandler.

Sets the SAX ContentHandler.

public void
setLexHandler(LexicalHandler
The LexicalHandler to set
_lexHandler
)

Sets the LexicalHandler.

public void
setShouldOutputNSAttr(boolean
whether or not namespace declarations should appear as attributes
doOutputNSAttr
)

Set whether or not namespace declarations (e.g. xmlns:foo) should appear as attributes of elements

public void
setTransformState(TransformStateSetter
A reference to a TransformState object
ts
)

Pass in a reference to a TransformState object, which can be used during SAX ContentHandler events to obtain information about he state of the transformation.

protected void
public void
startDTD(String
The document type name.
arg0
,
String
The declared public identifier for the external DTD subset, or null if none was declared.
arg1
,
String
The declared system identifier for the external DTD subset, or null if none was declared. (Note that this is not resolved against the document base URI.)
arg2
)

Implements org.xml.sax.ext.LexicalHandler.startDTD.

Do nothing.

public void
startElement(String
the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed
arg0
,
String
the local name (without prefix), or the empty string if Namespace processing is not being performed
arg1
,
String
the qualified name (with prefix), or the empty string if qualified names are not available
arg2
,
Attributes
the attributes attached to the element. If there are no attributes, it shall be an empty Attributes object. The value of this object after startElement returns is undefined
arg3
)

Implements org.xml.sax.ContentHandler.startElement.

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.

public void
startElement(String
the URI of the namespace of the element (optional)
uri
,
String
the element name, but without prefix (optional)
localName
,
String
the element name, with prefix, if any (required)
qName
)

Implements com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler.startElement.

Receives notification that an element starts, but attributes are not fully known yet.

public void
startElement(String
the element name, with prefix (if any).
qName
)

Implements com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler.startElement.

An element starts, but attributes are not fully known yet.

public void
warning(SAXParseException
The warning information encapsulated in a SAX parse exception.
exc
)

Overrides com.sun.org.apache.xml.internal.serializer.SerializerBase.warning.

Implements org.xml.sax.ErrorHandler.warning.

Receive notification of a warning.

Inherited from com.sun.org.apache.xml.internal.serializer.SerializerBase:
addAttributeaddAttributeaddAttributeaddAttributeAlwaysaddAttributesaddXSLAttributeasContentHandlerasDOM3SerializerasDOMSerializerclosedocumentIsEmptyendEntityentityReferencefireCDATAEventfireCharEventfireCommentEventfireEndDocfireEndElemfireEndEntityfireEntityReferencefireEscapingEventfireStartDocfireStartElemfireStartEntitygetDoctypePublicgetDoctypeSystemgetEncodinggetFirstCharLocNamegetIndentgetIndentAmountgetLocalNamegetMediaTypegetNamespaceMappingsgetNamespaceURIgetNamespaceURIFromPrefixgetOmitXMLDeclarationgetOutputPropDefaultKeysgetOutputPropertygetOutputPropertyDefaultgetOutputPropertyNonDefaultgetOutputPropKeysgetPrefixgetPrefixPartgetStandalonegetTransformergetVersioninitCDATAinitCdataElemsinTemporaryOutputStateisCdataSectionisInEntityRefnamespaceAfterStartElementnotationDeclpatchNamesetDoctypesetDoctypePublicsetDoctypeSystemsetDocumentInfosetDocumentLocatorsetDTDEntityExpansionsetEncodingsetIndentsetIndentAmountsetIsStandalonesetMediaTypesetNamespaceMappingssetOmitXMLDeclarationsetOutputPropertysetOutputPropertyDefaultsetPropsetSourceLocatorsetStandalonesetStandaloneInternalsetTransformersetVersionstartDocumentunparsedEntityDecl

Field Detail

m_lexHandlerback to summary
protected LexicalHandler m_lexHandler

Underlying LexicalHandler. Taken from XSLTC

m_saxHandlerback to summary
protected ContentHandler m_saxHandler

Underlying SAX handler. Taken from XSLTC

m_shouldGenerateNSAttributeback to summary
private boolean m_shouldGenerateNSAttribute

A startPrefixMapping() call on a ToSAXHandler will pass that call on to the wrapped ContentHandler, but should we also mirror these calls with matching attributes, if so this field is true. For example if this field is true then a call such as startPrefixMapping("prefix1","uri1") will also cause the additional internally generated attribute xmlns:prefix1="uri1" to be effectively added to the attributes passed to the wrapped ContentHandler.

m_stateback to summary
protected TransformStateSetter m_state

If this is true, then the content handler wrapped by this serializer implements the TransformState interface which will give the content handler access to the state of the transform.

Constructor Detail

ToSAXHandlerback to summary
public ToSAXHandler()
ToSAXHandlerback to summary
public ToSAXHandler(ContentHandler hdlr, LexicalHandler lex, String encoding)
ToSAXHandlerback to summary
public ToSAXHandler(ContentHandler handler, String encoding)

Method Detail

addUniqueAttributeback to summary
public void addUniqueAttribute(String qName, String value, int flags) throws SAXException

Implements com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler.addUniqueAttribute.

Add a unique attribute

Parameters
qName:String

Doc from com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler.addUniqueAttribute.

the fully qualified attribute name.

value:String

Doc from com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler.addUniqueAttribute.

the attribute value

flags:int

Doc from com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler.addUniqueAttribute.

a bitwise flag

charactersback to summary
public void characters(String chars) throws SAXException

Implements com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler.characters.

Receive notification of character data.

Parameters
chars:String

The string of characters to process.

See Also
ExtendedContentHandler#characters(String)
charactersback to summary
public void characters(Node node) throws SAXException

Overrides com.sun.org.apache.xml.internal.serializer.SerializerBase.characters.

Implements com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler.characters.

This method gets the node's value as a String and uses that String as if it were an input character notification.

Parameters
node:Node

the Node to serialize

closeCDATAback to summary
protected void closeCDATA() throws SAXException
closeStartTagback to summary
protected void closeStartTag() throws SAXException
commentback to summary
public void comment(String comment) throws SAXException

Overrides com.sun.org.apache.xml.internal.serializer.SerializerBase.comment.

Implements com.sun.org.apache.xml.internal.serializer.ExtendedLexicalHandler.comment.

Receive notification of a comment.

Parameters
comment:String

Doc from com.sun.org.apache.xml.internal.serializer.ExtendedLexicalHandler.comment.

the comment, but unlike the SAX comment() method this method takes a String rather than a character array.

See Also
ExtendedLexicalHandler#comment(String)
errorback to summary
public void error(SAXParseException exc) throws SAXException

Overrides com.sun.org.apache.xml.internal.serializer.SerializerBase.error.

Implements org.xml.sax.ErrorHandler.error.

Doc from org.xml.sax.ErrorHandler.error.

Receive notification of a recoverable error.

This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a validating parser would use this callback to report the violation of a validity constraint. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser should report a fatal error even if the XML recommendation does not require it to do so.

Filters may use this method to report other, non-XML errors as well.

Parameters
exc:SAXParseException

The error information encapsulated in a SAX parse exception.

Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
See Also
org.xml.sax.ErrorHandler#error(SAXParseException)
fatalErrorback to summary
public void fatalError(SAXParseException exc) throws SAXException

Overrides com.sun.org.apache.xml.internal.serializer.SerializerBase.fatalError.

Implements org.xml.sax.ErrorHandler.fatalError.

Doc from org.xml.sax.ErrorHandler.fatalError.

Receive notification of a non-recoverable, fatal error.

As defined in section 1.2 of the W3C XML 1.0 Recommendation, fatal errors are those that would make it impossible for a parser to continue normal processing. These include violation of a well-formedness constraint, invalid encoding, and forbidden structural errors as described in the W3C XML 1.0 Recommendation.

Parameters
exc:SAXParseException

The error information encapsulated in a SAXParseException.

Exceptions
SAXException:
if the application chooses to discontinue the parsing
See Also
org.xml.sax.ErrorHandler#fatalError(SAXParseException)
flushPendingback to summary
public void flushPending() throws SAXException

Implements com.sun.org.apache.xml.internal.serializer.SerializationHandler.flushPending.

This method flushes any pending events, which can be startDocument() closing the opening tag of an element, or closing an open CDATA section.

getShouldOutputNSAttrback to summary
pack-priv boolean getShouldOutputNSAttr()

Returns true if namespace declarations from calls such as startPrefixMapping("prefix1","uri1") should also be mirrored with self generated additional attributes of elements that declare the namespace, for example the attribute xmlns:prefix1="uri1"

processingInstructionback to summary
public void processingInstruction(String target, String data) throws SAXException

Implements org.xml.sax.ContentHandler.processingInstruction.

Do nothing as this is an abstract class. All subclasses will need to define their behavior if it is different.

Parameters
target:String

Doc from org.xml.sax.ContentHandler.processingInstruction.

the processing instruction target

data:String

Doc from org.xml.sax.ContentHandler.processingInstruction.

the processing instruction data, or null if none was supplied. The data does not include any whitespace separating it from the target

Exceptions
SAXException:

Doc from org.xml.sax.ContentHandler.processingInstruction.

any SAX exception, possibly wrapping another exception

See Also
org.xml.sax.ContentHandler#processingInstruction(String, String)
resetback to summary
public boolean reset()

Overrides com.sun.org.apache.xml.internal.serializer.SerializerBase.reset.

Implements com.sun.org.apache.xml.internal.serializer.Serializer.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).

Returns:boolean

true if the class was successfuly reset.

See Also
Serializer#reset()
resetToSAXHandlerback to summary
private void resetToSAXHandler()

Reset all of the fields owned by ToSAXHandler class

setCdataSectionElementsback to summary
public void setCdataSectionElements(List<String> URI_and_localNames)

Implements com.sun.org.apache.xml.internal.serializer.XSLOutputAttributes.setCdataSectionElements.

Does nothing. The setting of CDATA section elements has an impact on stream serializers.

Parameters
URI_and_localNames:List<String>

Doc from com.sun.org.apache.xml.internal.serializer.XSLOutputAttributes.setCdataSectionElements.

pairs of namespace URI and local names that identify elements whose text elements are to be output as CDATA sections. The namespace of the local element must be the given URI to match. The qName is not given because the prefix does not matter, only the namespace URI to which that prefix would map matters, so the prefix itself is not relevant in specifying which elements have their text to be output as CDATA sections.

See Also
SerializationHandler#setCdataSectionElements(java.util.List<String>)
setContentHandlerback to summary
public void setContentHandler(ContentHandler _saxHandler)

Implements com.sun.org.apache.xml.internal.serializer.SerializationHandler.setContentHandler.

Sets the SAX ContentHandler.

Parameters
_saxHandler:ContentHandler

The ContentHandler to set

setLexHandlerback to summary
public void setLexHandler(LexicalHandler _lexHandler)

Sets the LexicalHandler.

Parameters
_lexHandler:LexicalHandler

The LexicalHandler to set

setShouldOutputNSAttrback to summary
public void setShouldOutputNSAttr(boolean doOutputNSAttr)

Set whether or not namespace declarations (e.g. xmlns:foo) should appear as attributes of elements

Parameters
doOutputNSAttr:boolean

whether or not namespace declarations should appear as attributes

setTransformStateback to summary
public void setTransformState(TransformStateSetter ts)

Pass in a reference to a TransformState object, which can be used during SAX ContentHandler events to obtain information about he state of the transformation. This method will be called before each startDocument event.

Parameters
ts:TransformStateSetter

A reference to a TransformState object

startDocumentInternalback to summary
protected void startDocumentInternal() throws SAXException

Overrides com.sun.org.apache.xml.internal.serializer.SerializerBase.startDocumentInternal.

Pass callback to the SAX Handler

startDTDback to summary
public void startDTD(String arg0, String arg1, String arg2) throws SAXException

Implements org.xml.sax.ext.LexicalHandler.startDTD.

Do nothing.

Parameters
arg0:String

Doc from org.xml.sax.ext.LexicalHandler.startDTD.

The document type name.

arg1:String

Doc from org.xml.sax.ext.LexicalHandler.startDTD.

The declared public identifier for the external DTD subset, or null if none was declared.

arg2:String

Doc from org.xml.sax.ext.LexicalHandler.startDTD.

The declared system identifier for the external DTD subset, or null if none was declared. (Note that this is not resolved against the document base URI.)

Exceptions
SAXException:

Doc from org.xml.sax.ext.LexicalHandler.startDTD.

The application may raise an exception.

See Also
org.xml.sax.ext.LexicalHandler#startDTD(String, String, String)
startElementback to summary
public void startElement(String arg0, String arg1, String arg2, Attributes arg3) throws SAXException

Implements org.xml.sax.ContentHandler.startElement.

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.

Parameters
arg0:String

Doc from org.xml.sax.ContentHandler.startElement.

the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed

arg1:String

Doc from org.xml.sax.ContentHandler.startElement.

the local name (without prefix), or the empty string if Namespace processing is not being performed

arg2:String

Doc from org.xml.sax.ContentHandler.startElement.

the qualified name (with prefix), or the empty string if qualified names are not available

arg3:Attributes

Doc from org.xml.sax.ContentHandler.startElement.

the attributes attached to the element. If there are no attributes, it shall be an empty Attributes object. The value of this object after startElement returns is undefined

Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
See Also
org.xml.sax.ContentHandler#startElement, org.xml.sax.ContentHandler#endElement, org.xml.sax.AttributeList, org.xml.sax.ContentHandler#startElement(String, String, String, Attributes)
startElementback to summary
public void startElement(String uri, String localName, String qName) throws SAXException

Implements com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler.startElement.

Receives notification that an element starts, but attributes are not fully known yet.

Parameters
uri:String

the URI of the namespace of the element (optional)

localName:String

the element name, but without prefix (optional)

qName:String

the element name, with prefix, if any (required)

See Also
ExtendedContentHandler#startElement(String, String, String)
startElementback to summary
public void startElement(String qName) throws SAXException

Implements com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler.startElement.

An element starts, but attributes are not fully known yet.

Parameters
qName:String

the element name, with prefix (if any).

See Also
ExtendedContentHandler#startElement(String)
warningback to summary
public void warning(SAXParseException exc) throws SAXException

Overrides com.sun.org.apache.xml.internal.serializer.SerializerBase.warning.

Implements org.xml.sax.ErrorHandler.warning.

Doc from org.xml.sax.ErrorHandler.warning.

Receive notification of a warning.

SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML recommendation. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end.

Filters may use this method to report other, non-XML warnings as well.

Parameters
exc:SAXParseException

The warning information encapsulated in a SAX parse exception.

Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
See Also
org.xml.sax.ErrorHandler#warning(SAXParseException)