|
|||||||||
| Home >> All >> org >> apache >> xml >> [ serializer overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.xml.serializer
Class ToXMLSAXHandler

java.lang.Objectorg.apache.xml.serializer.SerializerBase
org.apache.xml.serializer.ToSAXHandler
org.apache.xml.serializer.ToXMLSAXHandler
- All Implemented Interfaces:
- org.xml.sax.ContentHandler, org.xml.sax.ext.DeclHandler, org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler, DOMSerializer, org.xml.sax.ErrorHandler, ExtendedContentHandler, ExtendedLexicalHandler, org.xml.sax.ext.LexicalHandler, SerializationHandler, Serializer, SerializerConstants, XSLOutputAttributes
- public 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 output is known to be XML.
| Field Summary | |
protected boolean |
m_escapeSetting
Keeps track of whether output escaping is currently enabled |
| Fields inherited from class org.apache.xml.serializer.ToSAXHandler |
m_lexHandler, m_saxHandler, m_state |
| Fields inherited from class org.apache.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_needToOutputDocTypeDecl, m_prefixMap, m_sourceLocator, m_standaloneWasSpecified, m_tracer, m_writer |
| Fields inherited from interface org.apache.xml.serializer.ExtendedContentHandler |
HTML_ATTREMPTY, HTML_ATTRURL, NO_BAD_CHARS |
| Fields inherited from interface org.apache.xml.serializer.SerializerConstants |
BEGCDATA, CDATA_CONTINUE, CDATA_DELIMITER_CLOSE, CDATA_DELIMITER_OPEN, CNTCDATA, DEFAULT_SAX_SERIALIZER, EMPTYSTRING, ENDCDATA, ENTITY_AMP, ENTITY_CRLF, ENTITY_GT, ENTITY_LT, ENTITY_QUOT, XML_PREFIX, XMLNS_PREFIX, XMLNS_URI |
| 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)
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)
Report an attribute type declaration. |
void |
characters(char[] ch,
int off,
int len)
Receive notification of character data. |
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)
Report an XML comment anywhere in the document. |
void |
elementDecl(java.lang.String arg0,
java.lang.String arg1)
Report an element type declaration. |
void |
endCDATA()
Report the end of a CDATA section. |
void |
endDocument()
Receives notification of the end of the document. |
void |
endDTD()
Report the end of DTD declarations. |
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)
Receive notification of the end of an element. |
void |
endPrefixMapping(java.lang.String prefix)
End the scope of a prefix-URI mapping. |
private void |
ensurePrefixIsDeclared(java.lang.String ns,
java.lang.String rawName)
|
void |
externalEntityDecl(java.lang.String arg0,
java.lang.String arg1,
java.lang.String arg2)
Report a parsed external entity declaration. |
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)
Receive notification of ignorable whitespace in element content. |
void |
indent(int n)
Do nothing for SAX. |
void |
internalEntityDecl(java.lang.String arg0,
java.lang.String arg1)
Report an internal entity declaration. |
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). |
private void |
resetToXMLSAXHandler()
Reset all of the fields owned by ToXMLSAXHandler class |
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)
Receive notification of a skipped entity. |
void |
startCDATA()
Report the start of a CDATA section. |
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)
Report the beginning of some internal and external XML entities. |
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String uri)
Begin the scope of a prefix-URI Namespace mapping. |
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.apache.xml.serializer.ToSAXHandler |
addUniqueAttribute, characters, comment, error, fatalError, flushPending, getShouldOutputNSAttr, setCdataSectionElements, setContentHandler, setLexHandler, setShouldOutputNSAttr, setTransformState, startDocumentInternal, startDTD, warning |
| 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
| 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.
getOutputStream
public java.io.OutputStream getOutputStream()
- Description copied from interface:
Serializer - Get the output stream where the events will be serialized to.
getWriter
public java.io.Writer getWriter()
- Description copied from interface:
Serializer - Get the character stream where the events will be serialized to.
indent
public void indent(int n)
throws org.xml.sax.SAXException
- Do nothing for SAX.
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.
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.
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.
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 java.util.Properties is used, or if no encoding was specified, the default for the selected output method.
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 java.util.Properties must be identical to the output format used with the 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
- Description copied from interface:
org.xml.sax.ext.DeclHandler - Report an attribute type declaration.
Only the effective (first) declaration for an attribute will be reported. The type will be one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", a parenthesized token group with the separator "|" and all whitespace removed, or the word "NOTATION" followed by a space followed by a parenthesized token group with all whitespace removed.
The value will be the value as reported to applications, appropriately normalized and with entity and character references expanded.
elementDecl
public void elementDecl(java.lang.String arg0, java.lang.String arg1) throws org.xml.sax.SAXException
- Description copied from interface:
org.xml.sax.ext.DeclHandler - Report an element type declaration.
The content model will consist of the string "EMPTY", the string "ANY", or a parenthesised group, optionally followed by an occurrence indicator. The model will be normalized so that all parameter entities are fully resolved and all whitespace is removed,and will include the enclosing parentheses. Other normalization (such as removing redundant parentheses or simplifying occurrence indicators) is at the discretion of the parser.
externalEntityDecl
public void externalEntityDecl(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2) throws org.xml.sax.SAXException
- Description copied from interface:
org.xml.sax.ext.DeclHandler - Report a parsed external entity declaration.
Only the effective (first) declaration for each entity will be reported.
If the system identifier is a URL, the parser must resolve it fully before passing it to the application.
internalEntityDecl
public void internalEntityDecl(java.lang.String arg0, java.lang.String arg1) throws org.xml.sax.SAXException
- Description copied from interface:
org.xml.sax.ext.DeclHandler - Report an internal entity declaration.
Only the effective (first) declaration for each entity will be reported. All parameter entities in the value will be expanded, but general entities will not.
endDocument
public void endDocument()
throws org.xml.sax.SAXException
- Receives notification of the end of the document.
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:
closeStartTagin classToSAXHandler
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:
closeCDATAin classToSAXHandler
endElement
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
- Description copied from interface:
org.xml.sax.ContentHandler - Receive notification of the end of an element.
The SAX parser will invoke this method at the end of every element in the XML document; there will be a corresponding startElement 55 event for every endElement event (even when the element is empty).
For information on the names, see startElement.
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException
- Description copied from interface:
org.xml.sax.ContentHandler - End the scope of a prefix-URI mapping.
See startPrefixMapping 55 for details. These events will always occur immediately after the corresponding endElement 55 event, but the order of endPrefixMapping 55 events is not otherwise guaranteed.
ignorableWhitespace
public void ignorableWhitespace(char[] arg0,
int arg1,
int arg2)
throws org.xml.sax.SAXException
- Description copied from interface:
org.xml.sax.ContentHandler - Receive notification of ignorable whitespace in element content.
Validating Parsers must use this method to report each chunk of whitespace in element content (see the W3C XML 1.0 recommendation, section 2.10): non-validating parsers may also use this method if they are capable of parsing and using content models.
SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.
The application must not attempt to read from the array outside of the specified range.
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.
- Specified by:
setDocumentLocatorin interfaceorg.xml.sax.ContentHandler- Overrides:
setDocumentLocatorin classSerializerBase
skippedEntity
public void skippedEntity(java.lang.String arg0) throws org.xml.sax.SAXException
- Description copied from interface:
org.xml.sax.ContentHandler - Receive notification of a skipped entity.
This is not called for entity references within markup constructs
such as element start tags or markup declarations. (The XML
recommendation requires reporting skipped external entities.
SAX also reports internal entity expansion/non-expansion, except
within markup constructs.)
The Parser will invoke this method each time the entity is skipped. Non-validating processors may skip entities if they have not seen the declarations (because, for example, the entity was declared in an external DTD subset). All processors may skip external entities, depending on the values of the
http://xml.org/sax/features/external-general-entitiesand thehttp://xml.org/sax/features/external-parameter-entitiesproperties.
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXException
- Description copied from interface:
org.xml.sax.ContentHandler - Begin the scope of a prefix-URI Namespace mapping.
The information from this event is not necessary for normal Namespace processing: the SAX XML reader will automatically replace prefixes for element and attribute names when the
http://xml.org/sax/features/namespacesfeature is true (the default).There are cases, however, when applications need to use prefixes in character data or in attribute values, where they cannot safely be expanded automatically; the start/endPrefixMapping event supplies the information to the application to expand prefixes in those contexts itself, if necessary.
Note that start/endPrefixMapping events are not guaranteed to be properly nested relative to each other: all startPrefixMapping events will occur immediately before the corresponding startElement 55 event, and all endPrefixMapping 55 events will occur immediately after the corresponding endElement 55 event, but their order is not otherwise guaranteed.
There should never be start/endPrefixMapping events for the "xml" prefix, since it is predeclared and immutable.
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.
comment
public void comment(char[] arg0,
int arg1,
int arg2)
throws org.xml.sax.SAXException
- Description copied from interface:
org.xml.sax.ext.LexicalHandler - Report an XML comment anywhere in the document.
This callback will be used for comments inside or outside the document element, including comments in the external DTD subset (if read). Comments in the DTD must be properly nested inside start/endDTD and start/endEntity events (if used).
endCDATA
public void endCDATA()
throws org.xml.sax.SAXException
- Description copied from interface:
org.xml.sax.ext.LexicalHandler - Report the end of a CDATA section.
endDTD
public void endDTD()
throws org.xml.sax.SAXException
- Description copied from interface:
org.xml.sax.ext.LexicalHandler - Report the end of DTD declarations.
This method is intended to report the end of the DOCTYPE declaration; if the document has no DOCTYPE declaration, this method will not be invoked.
startEntity
public void startEntity(java.lang.String arg0) throws org.xml.sax.SAXException
- Description copied from interface:
org.xml.sax.ext.LexicalHandler - Report the beginning of some internal and external XML entities.
The reporting of parameter entities (including the external DTD subset) is optional, and SAX2 drivers that report LexicalHandler events may not implement it; you can use the
http://xml.org/sax/features/lexical-handler/parameter-entitiesfeature to query or control the reporting of parameter entities.General entities are reported with their regular names, parameter entities have '%' prepended to their names, and the external DTD subset has the pseudo-entity name "[dtd]".
When a SAX2 driver is providing these events, all other events must be properly nested within start/end entity events. There is no additional requirement that events from DeclHandler or DTDHandler be properly ordered.
Note that skipped entities will be reported through the skippedEntity 55 event, which is part of the ContentHandler interface.
Because of the streaming event model that SAX uses, some entity boundaries cannot be reported under any circumstances:
- general entities within attribute values
- parameter entities within declarations
These will be silently expanded, with no indication of where the original entity boundaries were.
Note also that the boundaries of character references (which are not really entities anyway) are not reported.
All start/endEntity events must be properly nested.
characters
public void characters(java.lang.String chars) throws org.xml.sax.SAXException
- Description copied from class:
ToSAXHandler - Receive notification of character data.
- Specified by:
charactersin interfaceExtendedContentHandler- Overrides:
charactersin classToSAXHandler
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.- Specified by:
startElementin interfaceExtendedContentHandler- Overrides:
startElementin classToSAXHandler
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.
- Specified by:
startElementin interfaceExtendedContentHandler- Overrides:
startElementin classToSAXHandler
characters
public void characters(char[] ch,
int off,
int len)
throws org.xml.sax.SAXException
- Description copied from interface:
org.xml.sax.ContentHandler - Receive notification of character data.
The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.
The application must not attempt to read from the array outside of the specified range.
Individual characters may consist of more than one Java
charvalue. There are two important cases where this happens, because characters can't be represented in just sixteen bits. In one case, characters are represented in a Surrogate Pair, using two special Unicode values. Such characters are in the so-called "Astral Planes", with a code point above U+FFFF. A second case involves composite characters, such as a base character combining with one or more accent characters.Your code should not assume that algorithms using
char-at-a-time idioms will be working in character units; in some cases they will split characters. This is relevant wherever XML permits arbitrary characters, such as attribute values, processing instruction data, and comments as well as in data reported from this method. It's also generally relevant whenever Java code manipulates internationalized text; the issue isn't unique to XML.Note that some parsers will report whitespace in element content using the ignorableWhitespace 55 method rather than this one (validating parsers must do so).
endElement
public void endElement(java.lang.String elemName) throws org.xml.sax.SAXException
- Description copied from interface:
ExtendedContentHandler - 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.
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.
- Specified by:
namespaceAfterStartElementin interfaceExtendedContentHandler- Overrides:
namespaceAfterStartElementin classSerializerBase
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.
- Specified by:
processingInstructionin interfaceorg.xml.sax.ContentHandler- Overrides:
processingInstructionin classToSAXHandler
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
- Description copied from interface:
org.xml.sax.ext.LexicalHandler - Report the start of a CDATA section.
The contents of the CDATA section will be reported through the regular characters 55 event; this event is intended only to report the boundary.
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.
- Specified by:
startElementin interfaceorg.xml.sax.ContentHandler- Overrides:
startElementin classToSAXHandler
ensurePrefixIsDeclared
private void ensurePrefixIsDeclared(java.lang.String ns, java.lang.String rawName) throws org.xml.sax.SAXException
addAttribute
public void addAttribute(java.lang.String uri, java.lang.String localName, java.lang.String rawName, java.lang.String type, java.lang.String value) 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.
- Specified by:
addAttributein interfaceExtendedContentHandler- Overrides:
addAttributein classSerializerBase
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:
resetin interfaceSerializer- Overrides:
resetin classToSAXHandler
resetToXMLSAXHandler
private void resetToXMLSAXHandler()
- Reset all of the fields owned by ToXMLSAXHandler class
|
|||||||||
| Home >> All >> org >> apache >> xml >> [ serializer overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC