public class EmptySerializer extends java.lang.Object implements SerializationHandler
HTML_ATTREMPTY, HTML_ATTRURL, NO_BAD_CHARS
Constructor and Description |
---|
EmptySerializer() |
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(java.lang.String name,
java.lang.String value)
Add an attribute to the current element.
|
void |
addAttribute(java.lang.String uri,
java.lang.String localName,
java.lang.String rawName,
java.lang.String type,
java.lang.String value)
Add at attribute to the current element, not from an xsl:attribute
element.
|
void |
addAttribute(java.lang.String uri,
java.lang.String localName,
java.lang.String rawName,
java.lang.String type,
java.lang.String value,
boolean XSLAttribute)
Add at attribute to the current element
|
void |
addAttributes(Attributes atts)
Add attributes to the current element
|
void |
addUniqueAttribute(java.lang.String name,
java.lang.String value,
int flags)
Add a unique attribute to the current element.
|
void |
addXSLAttribute(java.lang.String qName,
java.lang.String value,
java.lang.String uri)
Add an attribute from an xsl:attribute element.
|
ContentHandler |
asContentHandler()
Return a
ContentHandler interface to provide SAX input to. |
java.lang.Object |
asDOM3Serializer()
Return an Object into this serializer to be cast to a DOM3Serializer.
|
DOMSerializer |
asDOMSerializer()
Return a
DOMSerializer interface into this serializer. |
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[] arg0,
int arg1,
int arg2)
Receive notification of character data.
|
void |
characters(Node node)
This method is used to notify of a character event, but passing the data
as a DOM Node rather than the standard character array.
|
void |
characters(java.lang.String chars)
This method is used to notify of a character event, but passing the data
as a character String rather than the standard character array.
|
void |
close() |
void |
comment(char[] arg0,
int arg1,
int arg2)
Report an XML comment anywhere in the document.
|
void |
comment(java.lang.String comment)
This method is used to notify of a comment
|
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()
Receive notification of the end of a 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 arg0,
java.lang.String arg1,
java.lang.String arg2)
Receive notification of the end of an element.
|
void |
endEntity(java.lang.String arg0)
Report the end of an entity.
|
void |
endPrefixMapping(java.lang.String arg0)
End the scope of a prefix-URI mapping.
|
void |
entityReference(java.lang.String entityName)
Notify of an entity reference.
|
void |
error(SAXParseException arg0)
Receive notification of a recoverable error.
|
void |
externalEntityDecl(java.lang.String arg0,
java.lang.String arg1,
java.lang.String arg2)
Report a parsed external entity declaration.
|
void |
fatalError(SAXParseException arg0)
Receive notification of a non-recoverable error.
|
void |
flushPending()
A SerializationHandler accepts SAX-like events, so
it can accumulate attributes or namespace nodes after
a startElement().
|
java.lang.String |
getDoctypePublic()
Returns the previously set value of the value to be used as the public
identifier in the document type declaration (DTD).
|
java.lang.String |
getDoctypeSystem()
Returns the previously set value of the value to be used
as the system identifier in the document type declaration (DTD).
|
java.lang.String |
getEncoding() |
boolean |
getIndent() |
int |
getIndentAmount() |
java.lang.String |
getMediaType() |
NamespaceMappings |
getNamespaceMappings()
This method returns an object that has the current namespace mappings in
effect.
|
java.lang.String |
getNamespaceURI(java.lang.String name,
boolean isElement)
This method gets the prefix associated with a current element or
attribute name.
|
java.lang.String |
getNamespaceURIFromPrefix(java.lang.String prefix)
This method returns the namespace URI currently associated with the
prefix.
|
boolean |
getOmitXMLDeclaration() |
java.util.Properties |
getOutputFormat()
Returns the output format properties for this serializer.
|
java.lang.String |
getOutputProperty(java.lang.String name)
Get the value for a property that affects seraialization,
if a property was set return that value, otherwise return
the default value, otherwise return null.
|
java.lang.String |
getOutputPropertyDefault(java.lang.String name)
Get the default value for a property that affects seraialization,
or null if there is none.
|
java.io.OutputStream |
getOutputStream()
Get the output stream where the events will be serialized to.
|
java.lang.String |
getPrefix(java.lang.String uri)
This method returns the prefix that currently maps to the given namespace
URI.
|
java.lang.String |
getStandalone() |
Transformer |
getTransformer()
Get the transformer associated with the serializer.
|
java.lang.String |
getVersion() |
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 |
internalEntityDecl(java.lang.String arg0,
java.lang.String arg1)
Report an internal entity declaration.
|
void |
namespaceAfterStartElement(java.lang.String uri,
java.lang.String prefix)
This method is used to notify that a prefix mapping is to start, but
after an element is started.
|
void |
notationDecl(java.lang.String arg0,
java.lang.String arg1,
java.lang.String arg2)
Receive notification of a notation declaration event.
|
void |
processingInstruction(java.lang.String arg0,
java.lang.String arg1)
Receive notification of a processing instruction.
|
boolean |
reset()
This method resets the serializer.
|
void |
serialize(Node node)
Notify that the serializer should take this DOM node as input to be
serialized.
|
void |
setCdataSectionElements(java.util.Hashtable h) |
void |
setCdataSectionElements(java.util.Vector URI_and_localNames)
Sets the value coming from the xsl:output cdata-section-elements
stylesheet property.
|
void |
setContentHandler(ContentHandler ch)
Set the SAX Content handler that the serializer sends its output to.
|
void |
setDoctype(java.lang.String system,
java.lang.String pub)
Set the value coming from the xsl:output doctype-public and doctype-system stylesheet properties
|
void |
setDoctypePublic(java.lang.String doctype)
Set the value coming from the xsl:output doctype-public stylesheet attribute.
|
void |
setDoctypeSystem(java.lang.String doctype)
Set the value coming from the xsl:output doctype-system stylesheet attribute.
|
void |
setDocumentLocator(Locator arg0)
Receive an object for locating the origin of SAX document events.
|
void |
setDTDEntityExpansion(boolean expand)
Default behavior is to expand DTD entities,
that is the initall default value is true.
|
void |
setEncoding(java.lang.String encoding)
Sets the character encoding coming from the xsl:output encoding stylesheet attribute.
|
boolean |
setEscaping(boolean escape)
Turns special character escaping on/off.
|
void |
setIndent(boolean indent)
Sets the value coming from the xsl:output indent stylesheet
attribute.
|
void |
setIndentAmount(int spaces)
Set the number of spaces to indent for each indentation level.
|
void |
setMediaType(java.lang.String mediatype)
Sets the value coming from the xsl:output media-type stylesheet attribute.
|
void |
setNamespaceMappings(NamespaceMappings mappings)
Used only by TransformerSnapshotImpl to restore the serialization
to a previous state.
|
void |
setOmitXMLDeclaration(boolean b)
Sets the value coming from the xsl:output omit-xml-declaration stylesheet attribute
|
void |
setOutputFormat(java.util.Properties format)
Specifies an output format for this serializer.
|
void |
setOutputProperty(java.lang.String name,
java.lang.String val)
Set the non-default value for a property that affects seraialization.
|
void |
setOutputPropertyDefault(java.lang.String name,
java.lang.String val)
Set the default value for a property that affects seraialization.
|
void |
setOutputStream(java.io.OutputStream output)
Specifies an output stream to which the document should be
serialized.
|
void |
setSourceLocator(SourceLocator locator)
This method is used to set the source locator, which might be used to
generated an error message.
|
void |
setStandalone(java.lang.String standalone)
Sets the value coming from the xsl:output standalone stylesheet attribute.
|
void |
setTransformer(Transformer transformer)
Set the transformer associated with the serializer.
|
void |
setVersion(java.lang.String version)
Sets the value coming from the xsl:output version attribute.
|
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 |
startDocument()
Receive notification of the beginning of a document.
|
void |
startDTD(java.lang.String arg0,
java.lang.String arg1,
java.lang.String arg2)
Report the start of DTD declarations, if any.
|
void |
startElement(java.lang.String qName)
This method is used to notify of the start of an element
|
void |
startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
This method is used to notify that an element is starting.
|
void |
startElement(java.lang.String arg0,
java.lang.String arg1,
java.lang.String arg2,
Attributes arg3)
Receive notification of the beginning of an element.
|
void |
startEntity(java.lang.String arg0)
Report the beginning of some internal and external XML entities.
|
void |
startPrefixMapping(java.lang.String arg0,
java.lang.String arg1)
Begin the scope of a prefix-URI Namespace mapping.
|
boolean |
startPrefixMapping(java.lang.String prefix,
java.lang.String uri,
boolean shouldFlush)
This method is used to notify that a prefix maping is to start, which can
be for the current element, or for the one to come.
|
void |
unparsedEntityDecl(java.lang.String arg0,
java.lang.String arg1,
java.lang.String arg2,
java.lang.String arg3)
Receive notification of an unparsed entity declaration event.
|
void |
warning(SAXParseException arg0)
Receive notification of a warning.
|
public ContentHandler asContentHandler() throws java.io.IOException
Serializer
ContentHandler
interface to provide SAX input to.
Through the returned object the document to be serailized,
as a series of SAX events, can be provided to the serialzier.
If the serializer does not support the ContentHandler
interface, it will return null.
In principle only one of asDOMSerializer() or asContentHander() should be called.
asContentHandler
in interface Serializer
ContentHandler
interface into this serializer,
or null if the serializer is not SAX 2 capablejava.io.IOException
- An I/O exception occuredSerializer.asContentHandler()
public void setContentHandler(ContentHandler ch)
SerializationHandler
setContentHandler
in interface SerializationHandler
SerializationHandler.setContentHandler(org.xml.sax.ContentHandler)
public void close()
close
in interface SerializationHandler
SerializationHandler.close()
public java.util.Properties getOutputFormat()
Serializer
getOutputFormat
in interface Serializer
Serializer.getOutputFormat()
public java.io.OutputStream getOutputStream()
Serializer
getOutputStream
in interface Serializer
Serializer.getOutputStream()
public java.io.Writer getWriter()
Serializer
getWriter
in interface Serializer
Serializer.getWriter()
public boolean reset()
Serializer
reset
in interface Serializer
Serializer.reset()
public void serialize(Node node) throws java.io.IOException
SerializationHandler
serialize
in interface DOMSerializer
serialize
in interface SerializationHandler
node
- the DOM node to be serialized.java.io.IOException
- if an I/O exception occured while serializingSerializationHandler.serialize(org.w3c.dom.Node)
public void setCdataSectionElements(java.util.Vector URI_and_localNames)
URI_and_localNames
- 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.XSLOutputAttributes.setCdataSectionElements(java.util.Vector)
public boolean setEscaping(boolean escape) throws SAXException
SerializationHandler
setEscaping
in interface SerializationHandler
escape
- true if escaping is to be set on.SAXException
SerializationHandler.setEscaping(boolean)
public void setIndent(boolean indent)
indent
- true if the output document should be indented to visually
indicate its structure.XSLOutputAttributes.setIndent(boolean)
public void setIndentAmount(int spaces)
SerializationHandler
setIndentAmount
in interface SerializationHandler
spaces
- the number of spaces to indent for each indentation level.SerializationHandler.setIndentAmount(int)
public void setOutputFormat(java.util.Properties format)
Serializer
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.
setOutputFormat
in interface Serializer
format
- The output format to use, as a set of key/value pairs.Serializer.setOutputFormat(java.util.Properties)
public void setOutputStream(java.io.OutputStream output)
Serializer
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.
setOutputStream
in interface Serializer
output
- The output streamSerializer.setOutputStream(java.io.OutputStream)
public void setVersion(java.lang.String version)
version
- the version of the output format.XSLOutputAttributes.setVersion(java.lang.String)
public void setWriter(java.io.Writer writer)
Serializer
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.
setWriter
in interface Serializer
writer
- The output writer streamSerializer.setWriter(java.io.Writer)
public void setTransformer(Transformer transformer)
SerializationHandler
setTransformer
in interface SerializationHandler
transformer
- the transformer associated with the serializer.SerializationHandler.setTransformer(javax.xml.transform.Transformer)
public Transformer getTransformer()
SerializationHandler
getTransformer
in interface SerializationHandler
SerializationHandler.getTransformer()
public void flushPending() throws SAXException
SerializationHandler
If the SerializationHandler has a Writer or OutputStream, a call to this method will flush such accumulated events as a closed start tag for an element.
If the SerializationHandler wraps a ContentHandler, a call to this method will flush such accumulated events as a SAX (not SAX-like) calls to startPrefixMapping() and startElement().
If one calls endDocument() then one need not call this method since a call to endDocument() will do what this method does. However, in some circumstances, such as with document fragments, endDocument() is not called and it may be necessary to call this method to flush any pending events.
For performance reasons this method should not be called very often.
flushPending
in interface SerializationHandler
SAXException
SerializationHandler.flushPending()
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 SAXException
ExtendedContentHandler
addAttribute
in interface ExtendedContentHandler
uri
- the namespace URI of the attribute namelocalName
- the local name of the attribute (without prefix)rawName
- the qualified name of the attributetype
- the attribute type typically character data (CDATA)value
- the value of the attributeXSLAttribute
- true if the added attribute is coming from an xsl:attribute elementSAXException
ExtendedContentHandler.addAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void addAttributes(Attributes atts) throws SAXException
ExtendedContentHandler
addAttributes
in interface ExtendedContentHandler
atts
- the attributes to add.SAXException
ExtendedContentHandler.addAttributes(org.xml.sax.Attributes)
public void addAttribute(java.lang.String name, java.lang.String value)
ExtendedContentHandler
addAttribute
in interface ExtendedContentHandler
ExtendedContentHandler.addAttribute(java.lang.String, java.lang.String)
public void characters(java.lang.String chars) throws SAXException
ExtendedContentHandler
characters
in interface ExtendedContentHandler
chars
- the character dataSAXException
ExtendedContentHandler.characters(java.lang.String)
public void endElement(java.lang.String elemName) throws SAXException
ExtendedContentHandler
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.
endElement
in interface ExtendedContentHandler
elemName
- the fully qualified element name.SAXException
ExtendedContentHandler.endElement(java.lang.String)
public void startDocument() throws SAXException
ContentHandler
The SAX parser will invoke this method only once, before any
other event callbacks (except for setDocumentLocator
).
startDocument
in interface ContentHandler
SAXException
- any SAX exception, possibly
wrapping another exceptionContentHandler.startDocument()
public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) throws SAXException
ExtendedContentHandler
startElement(uri,localName,qname,atts)but without the attributes.
startElement
in interface ExtendedContentHandler
uri
- the namespace URI of the elementlocalName
- the local name (without prefix) of the elementqName
- the qualified name of the elementSAXException
ExtendedContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String)
public void startElement(java.lang.String qName) throws SAXException
ExtendedContentHandler
startElement
in interface ExtendedContentHandler
qName
- the fully qualified name of the elementSAXException
ExtendedContentHandler.startElement(java.lang.String)
public void namespaceAfterStartElement(java.lang.String uri, java.lang.String prefix) throws SAXException
ExtendedContentHandler
startPrefixMapping(prefix,uri)is used just before an element starts and applies to the element to come, not to the current element. This method applies to the current element. For example one could make the calls in this order:
startElement("prfx8:elem9") namespaceAfterStartElement("http://namespace8","prfx8")
namespaceAfterStartElement
in interface ExtendedContentHandler
uri
- the namespace URI being declaredprefix
- the prefix that maps to the given namespaceSAXException
ExtendedContentHandler.namespaceAfterStartElement(java.lang.String, java.lang.String)
public boolean startPrefixMapping(java.lang.String prefix, java.lang.String uri, boolean shouldFlush) throws SAXException
ExtendedContentHandler
startPrefixMapping
in interface ExtendedContentHandler
prefix
- the prefix that maps to the given URIuri
- the namespace URI of the given prefixshouldFlush
- if true this call is like the SAX
startPrefixMapping(prefix,uri) call and the mapping applies to the
element to come. If false the mapping applies to the current element.SAXException
ExtendedContentHandler.startPrefixMapping(java.lang.String, java.lang.String, boolean)
public void entityReference(java.lang.String entityName) throws SAXException
ExtendedContentHandler
entityReference
in interface ExtendedContentHandler
entityName
- the name of the entitySAXException
ExtendedContentHandler.entityReference(java.lang.String)
public NamespaceMappings getNamespaceMappings()
ExtendedContentHandler
getNamespaceMappings
in interface ExtendedContentHandler
ExtendedContentHandler.getNamespaceMappings()
public java.lang.String getPrefix(java.lang.String uri)
ExtendedContentHandler
getPrefix
in interface ExtendedContentHandler
uri
- the namespace URIExtendedContentHandler.getPrefix(java.lang.String)
public java.lang.String getNamespaceURI(java.lang.String name, boolean isElement)
ExtendedContentHandler
getNamespaceURI
in interface ExtendedContentHandler
name
- the qualified name of an element, or attributeisElement
- true if it is an element name, false if it is an
atttribute nameExtendedContentHandler.getNamespaceURI(java.lang.String, boolean)
public java.lang.String getNamespaceURIFromPrefix(java.lang.String prefix)
ExtendedContentHandler
getNamespaceURIFromPrefix
in interface ExtendedContentHandler
prefix
- a prefix of an element or attribute.ExtendedContentHandler.getNamespaceURIFromPrefix(java.lang.String)
public void setDocumentLocator(Locator arg0)
ContentHandler
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 ContentHandler 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 SAX event callbacks after
startDocument
returns and before
endDocument
is called. The
application should not attempt to use it at any other time.
setDocumentLocator
in interface ContentHandler
arg0
- an object that can return the location of
any SAX document eventContentHandler.setDocumentLocator(org.xml.sax.Locator)
public void endDocument() throws SAXException
ContentHandler
There is an apparent contradiction between the
documentation for this method and the documentation for ErrorHandler.fatalError(org.xml.sax.SAXParseException)
. Until this ambiguity is
resolved in a future major release, clients should make no
assumptions about whether endDocument() will or will not be
invoked when the parser has reported a fatalError() or thrown
an exception.
The SAX parser will invoke this method only once, and it will be the last method invoked during the parse. The parser shall not invoke this method until it has either abandoned parsing (because of an unrecoverable error) or reached the end of input.
endDocument
in interface ContentHandler
SAXException
- any SAX exception, possibly
wrapping another exceptionContentHandler.endDocument()
public void startPrefixMapping(java.lang.String arg0, java.lang.String arg1) throws SAXException
ContentHandler
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/namespaces
feature 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
event,
and all endPrefixMapping
events will occur immediately after the corresponding
endElement
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
in interface ContentHandler
arg0
- the Namespace prefix being declared.
An empty string is used for the default element namespace,
which has no prefix.arg1
- the Namespace URI the prefix is mapped toSAXException
- the client may throw
an exception during processingContentHandler.startPrefixMapping(java.lang.String, java.lang.String)
public void endPrefixMapping(java.lang.String arg0) throws SAXException
ContentHandler
See startPrefixMapping
for
details. These events will always occur immediately after the
corresponding endElement
event, but the order of
endPrefixMapping
events is not otherwise
guaranteed.
endPrefixMapping
in interface ContentHandler
arg0
- the prefix that was being mapped.
This is the empty string when a default mapping scope ends.SAXException
- the client may throw
an exception during processingContentHandler.endPrefixMapping(java.lang.String)
public void startElement(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2, Attributes arg3) throws SAXException
ContentHandler
The Parser will invoke this method at the beginning of every
element in the XML document; there will be a corresponding
endElement
event for every startElement event
(even when the element is empty). All of the element's content will be
reported, in order, before the corresponding endElement
event.
This event allows up to three name components for each element:
Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes properties:
Note that the attribute list provided will contain only
attributes with explicit values (specified or defaulted):
#IMPLIED attributes will be omitted. The attribute list
will contain attributes used for Namespace declarations
(xmlns* attributes) only if the
http://xml.org/sax/features/namespace-prefixes
property is true (it is false by default, and support for a
true value is optional).
Like characters()
, attribute values may have
characters that need more than one char
value.
startElement
in interface ContentHandler
arg0
- the Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performedarg1
- the local name (without prefix), or the
empty string if Namespace processing is not being
performedarg2
- the qualified name (with prefix), or the
empty string if qualified names are not availablearg3
- 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 undefinedSAXException
- any SAX exception, possibly
wrapping another exceptionContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
public void endElement(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2) throws SAXException
ContentHandler
The SAX parser will invoke this method at the end of every
element in the XML document; there will be a corresponding
startElement
event for every endElement
event (even when the element is empty).
For information on the names, see startElement.
endElement
in interface ContentHandler
arg0
- the Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performedarg1
- the local name (without prefix), or the
empty string if Namespace processing is not being
performedarg2
- the qualified XML name (with prefix), or the
empty string if qualified names are not availableSAXException
- any SAX exception, possibly
wrapping another exceptionContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
public void characters(char[] arg0, int arg1, int arg2) throws SAXException
ContentHandler
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
char
value. 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
method rather than this one (validating parsers must
do so).
characters
in interface ContentHandler
arg0
- the characters from the XML documentarg1
- the start position in the arrayarg2
- the number of characters to read from the arraySAXException
- any SAX exception, possibly
wrapping another exceptionContentHandler.characters(char[], int, int)
public void ignorableWhitespace(char[] arg0, int arg1, int arg2) throws SAXException
ContentHandler
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.
ignorableWhitespace
in interface ContentHandler
arg0
- the characters from the XML documentarg1
- the start position in the arrayarg2
- the number of characters to read from the arraySAXException
- any SAX exception, possibly
wrapping another exceptionContentHandler.ignorableWhitespace(char[], int, int)
public void processingInstruction(java.lang.String arg0, java.lang.String arg1) throws SAXException
ContentHandler
The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.
A SAX parser must never report an XML declaration (XML 1.0, section 2.8) or a text declaration (XML 1.0, section 4.3.1) using this method.
Like characters()
, processing instruction
data may have characters that need more than one char
value.
processingInstruction
in interface ContentHandler
arg0
- the processing instruction targetarg1
- the processing instruction data, or null if
none was supplied. The data does not include any
whitespace separating it from the targetSAXException
- any SAX exception, possibly
wrapping another exceptionContentHandler.processingInstruction(java.lang.String, java.lang.String)
public void skippedEntity(java.lang.String arg0) throws SAXException
ContentHandler
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-entities
and the
http://xml.org/sax/features/external-parameter-entities
properties.
skippedEntity
in interface ContentHandler
arg0
- the name of the skipped entity. If it is a
parameter entity, the name will begin with '%', and if
it is the external DTD subset, it will be the string
"[dtd]"SAXException
- any SAX exception, possibly
wrapping another exceptionContentHandler.skippedEntity(java.lang.String)
public void comment(java.lang.String comment) throws SAXException
ExtendedLexicalHandler
comment
in interface ExtendedLexicalHandler
comment
- the comment, but unlike the SAX comment() method this
method takes a String rather than a character array.SAXException
ExtendedLexicalHandler.comment(java.lang.String)
public void startDTD(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2) throws SAXException
LexicalHandler
This method is intended to report the beginning of the DOCTYPE declaration; if the document has no DOCTYPE declaration, this method will not be invoked.
All declarations reported through
DTDHandler
or
DeclHandler
events must appear
between the startDTD and endDTD
events.
Declarations are assumed to belong to the internal DTD subset
unless they appear between startEntity
and endEntity
events. Comments and
processing instructions from the DTD should also be reported
between the startDTD and endDTD events, in their original
order of (logical) occurrence; they are not required to
appear in their correct locations relative to DTDHandler
or DeclHandler events, however.
Note that the start/endDTD events will appear within
the start/endDocument events from ContentHandler and
before the first
startElement
event.
startDTD
in interface LexicalHandler
arg0
- The document type name.arg1
- The declared public identifier for the
external DTD subset, or null if none was declared.arg2
- 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.)SAXException
- The application may raise an
exception.LexicalHandler.startDTD(java.lang.String, java.lang.String, java.lang.String)
public void endDTD() throws SAXException
LexicalHandler
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.
endDTD
in interface LexicalHandler
SAXException
- The application may raise an exception.LexicalHandler.endDTD()
public void startEntity(java.lang.String arg0) throws SAXException
LexicalHandler
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-entities
feature 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
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:
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.
startEntity
in interface LexicalHandler
arg0
- The name of the entity. If it is a parameter
entity, the name will begin with '%', and if it is the
external DTD subset, it will be "[dtd]".SAXException
- The application may raise an exception.LexicalHandler.startEntity(java.lang.String)
public void endEntity(java.lang.String arg0) throws SAXException
LexicalHandler
endEntity
in interface LexicalHandler
arg0
- The name of the entity that is ending.SAXException
- The application may raise an exception.LexicalHandler.endEntity(java.lang.String)
public void startCDATA() throws SAXException
LexicalHandler
The contents of the CDATA section will be reported through
the regular characters
event; this event is intended only to report
the boundary.
startCDATA
in interface LexicalHandler
SAXException
- The application may raise an exception.LexicalHandler.startCDATA()
public void endCDATA() throws SAXException
LexicalHandler
endCDATA
in interface LexicalHandler
SAXException
- The application may raise an exception.LexicalHandler.endCDATA()
public void comment(char[] arg0, int arg1, int arg2) throws SAXException
LexicalHandler
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).
comment
in interface LexicalHandler
arg0
- An array holding the characters in the comment.arg1
- The starting position in the array.arg2
- The number of characters to use from the array.SAXException
- The application may raise an exception.LexicalHandler.comment(char[], int, int)
public java.lang.String getDoctypePublic()
XSLOutputAttributes.getDoctypePublic()
public java.lang.String getDoctypeSystem()
XSLOutputAttributes.getDoctypeSystem()
public java.lang.String getEncoding()
XSLOutputAttributes.getEncoding()
public boolean getIndent()
XSLOutputAttributes.getIndent()
public int getIndentAmount()
XSLOutputAttributes.getIndentAmount()
public java.lang.String getMediaType()
XSLOutputAttributes.getMediaType()
public boolean getOmitXMLDeclaration()
XSLOutputAttributes.getOmitXMLDeclaration()
public java.lang.String getStandalone()
standalone
delaration is to
be included in the output document.XSLOutputAttributes.getStandalone()
public java.lang.String getVersion()
XSLOutputAttributes.getVersion()
public void setCdataSectionElements(java.util.Hashtable h) throws java.lang.Exception
java.lang.Exception
XSLOutputAttributes.setCdataSectionElements(java.util.Vector)
public void setDoctype(java.lang.String system, java.lang.String pub)
system
- the system identifier to be used in the DOCTYPE declaration
in the output document.pub
- the public identifier to be used in the DOCTYPE declaration in
the output document.XSLOutputAttributes.setDoctype(java.lang.String, java.lang.String)
public void setDoctypePublic(java.lang.String doctype)
doctype
- the public identifier to be used in the DOCTYPE
declaration in the output document.XSLOutputAttributes.setDoctypePublic(java.lang.String)
public void setDoctypeSystem(java.lang.String doctype)
doctype
- the system identifier to be used in the DOCTYPE
declaration in the output document.XSLOutputAttributes.setDoctypeSystem(java.lang.String)
public void setEncoding(java.lang.String encoding)
encoding
- the character encodingXSLOutputAttributes.setEncoding(java.lang.String)
public void setMediaType(java.lang.String mediatype)
mediatype
- the media-type or MIME type associated with the output
document.XSLOutputAttributes.setMediaType(java.lang.String)
public void setOmitXMLDeclaration(boolean b)
b
- true if the XML declaration is to be omitted from the output
document.XSLOutputAttributes.setOmitXMLDeclaration(boolean)
public void setStandalone(java.lang.String standalone)
standalone
- a value of "yes" indicates that the
standalone
delaration is to be included in the output
document.XSLOutputAttributes.setStandalone(java.lang.String)
public void elementDecl(java.lang.String arg0, java.lang.String arg1) throws SAXException
DeclHandler
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.
elementDecl
in interface DeclHandler
arg0
- The element type name.arg1
- The content model as a normalized string.SAXException
- The application may raise an exception.DeclHandler.elementDecl(java.lang.String, java.lang.String)
public void attributeDecl(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2, java.lang.String arg3, java.lang.String arg4) throws SAXException
DeclHandler
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.
attributeDecl
in interface DeclHandler
arg0
- The name of the associated element.arg1
- The name of the attribute.arg2
- A string representing the attribute type.arg3
- A string representing the attribute defaulting mode
("#IMPLIED", "#REQUIRED", or "#FIXED") or null if
none of these applies.arg4
- A string representing the attribute's default value,
or null if there is none.SAXException
- The application may raise an exception.DeclHandler.attributeDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void internalEntityDecl(java.lang.String arg0, java.lang.String arg1) throws SAXException
DeclHandler
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.
internalEntityDecl
in interface DeclHandler
arg0
- The name of the entity. If it is a parameter
entity, the name will begin with '%'.arg1
- The replacement text of the entity.SAXException
- The application may raise an exception.DeclHandler.internalEntityDecl(java.lang.String, java.lang.String)
public void externalEntityDecl(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2) throws SAXException
DeclHandler
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.
externalEntityDecl
in interface DeclHandler
arg0
- The name of the entity. If it is a parameter
entity, the name will begin with '%'.arg1
- The entity's public identifier, or null if none
was given.arg2
- The entity's system identifier.SAXException
- The application may raise an exception.DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)
public void warning(SAXParseException arg0) throws SAXException
ErrorHandler
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.
warning
in interface ErrorHandler
arg0
- The warning information encapsulated in a
SAX parse exception.SAXException
- Any SAX exception, possibly
wrapping another exception.ErrorHandler.warning(org.xml.sax.SAXParseException)
public void error(SAXParseException arg0) throws SAXException
ErrorHandler
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.
error
in interface ErrorHandler
arg0
- The error information encapsulated in a
SAX parse exception.SAXException
- Any SAX exception, possibly
wrapping another exception.ErrorHandler.error(org.xml.sax.SAXParseException)
public void fatalError(SAXParseException arg0) throws SAXException
ErrorHandler
There is an apparent contradiction between the
documentation for this method and the documentation for ContentHandler.endDocument()
. Until this ambiguity
is resolved in a future major release, clients should make no
assumptions about whether endDocument() will or will not be
invoked when the parser has reported a fatalError() or thrown
an exception.
This corresponds to the definition of "fatal error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a parser would use this callback to report the violation of a well-formedness constraint.
The application must assume that the document is unusable after the parser has invoked this method, and should continue (if at all) only for the sake of collecting additional error messages: in fact, SAX parsers are free to stop reporting any other events once this method has been invoked.
fatalError
in interface ErrorHandler
arg0
- The error information encapsulated in a
SAX parse exception.SAXException
- Any SAX exception, possibly
wrapping another exception.ErrorHandler.fatalError(org.xml.sax.SAXParseException)
public DOMSerializer asDOMSerializer() throws java.io.IOException
Serializer
DOMSerializer
interface into this serializer.
Through the returned object the document to be serialized,
a DOM, can be provided to the serializer.
If the serializer does not support the DOMSerializer
interface, it should return null.
In principle only one of asDOMSerializer() or asContentHander() should be called.
asDOMSerializer
in interface Serializer
DOMSerializer
interface into this serializer,
or null if the serializer is not DOM capablejava.io.IOException
- An I/O exception occuredSerializer.asDOMSerializer()
public void setNamespaceMappings(NamespaceMappings mappings)
SerializationHandler
setNamespaceMappings
in interface SerializationHandler
mappings
- NamespaceMappingsSerializationHandler.setNamespaceMappings(NamespaceMappings)
public void setSourceLocator(SourceLocator locator)
ExtendedContentHandler
setSourceLocator
in interface ExtendedContentHandler
locator
- the source locatorExtendedContentHandler.setSourceLocator(javax.xml.transform.SourceLocator)
public void addUniqueAttribute(java.lang.String name, java.lang.String value, int flags) throws SAXException
ExtendedContentHandler
addUniqueAttribute
in interface ExtendedContentHandler
name
- the fully qualified attribute name.value
- the attribute valueflags
- a bitwise flagSAXException
ExtendedContentHandler.addUniqueAttribute(java.lang.String, java.lang.String, int)
public void characters(Node node) throws SAXException
ExtendedContentHandler
characters
in interface ExtendedContentHandler
node
- a DOM Node containing text.SAXException
ExtendedContentHandler.characters(org.w3c.dom.Node)
public void addXSLAttribute(java.lang.String qName, java.lang.String value, java.lang.String uri)
ExtendedContentHandler
addXSLAttribute
in interface ExtendedContentHandler
qName
- the qualified attribute name (prefix:localName)value
- the attributes valueuri
- the uri that the prefix of the qName is mapped to.ExtendedContentHandler.addXSLAttribute(java.lang.String, java.lang.String, java.lang.String)
public void addAttribute(java.lang.String uri, java.lang.String localName, java.lang.String rawName, java.lang.String type, java.lang.String value) throws SAXException
ExtendedContentHandler
addAttribute
in interface ExtendedContentHandler
uri
- the namespace URI of the attribute namelocalName
- the local name of the attribute (without prefix)rawName
- the qualified name of the attributetype
- the attribute type typically character data (CDATA)value
- the value of the attributeSAXException
ExtendedContentHandler.addAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void notationDecl(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2) throws SAXException
DTDHandler
It is up to the application to record the notation for later reference, if necessary; notations may appear as attribute values and in unparsed entity declarations, and are sometime used with processing instruction target names.
At least one of publicId and systemId must be non-null. If a system identifier is present, and it is a URL, the SAX parser must resolve it fully before passing it to the application through this event.
There is no guarantee that the notation declaration will be reported before any unparsed entities that use it.
notationDecl
in interface DTDHandler
arg0
- The notation name.arg1
- The notation's public identifier, or null if
none was given.arg2
- The notation's system identifier, or null if
none was given.SAXException
- Any SAX exception, possibly
wrapping another exception.DTDHandler.notationDecl(java.lang.String, java.lang.String, java.lang.String)
public void unparsedEntityDecl(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2, java.lang.String arg3) throws SAXException
DTDHandler
Note that the notation name corresponds to a notation
reported by the notationDecl
event.
It is up to the application to record the entity for later
reference, if necessary;
unparsed entities may appear as attribute values.
If the system identifier is a URL, the parser must resolve it fully before passing it to the application.
unparsedEntityDecl
in interface DTDHandler
arg0
- The unparsed entity's name.arg1
- The entity's public identifier, or null if none
was given.arg2
- The entity's system identifier.arg3
- The name of the associated notation.SAXException
- Any SAX exception, possibly
wrapping another exception.DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void setDTDEntityExpansion(boolean expand)
SerializationHandler
setDTDEntityExpansion
in interface SerializationHandler
expand
- true if DTD entities are to be expanded,
false if they are to be left as DTD entity references.SerializationHandler.setDTDEntityExpansion(boolean)
public java.lang.String getOutputProperty(java.lang.String name)
name
- The name of the property, which is just the local name
if it is in no namespace, but is the URI in curly braces followed by
the local name if it is in a namespace, for example:
public java.lang.String getOutputPropertyDefault(java.lang.String name)
name
- The name of the property.public void setOutputProperty(java.lang.String name, java.lang.String val)
name
- The name of the property, which is just the local name
if it is in no namespace, but is the URI in curly braces followed by
the local name if it is in a namespace, for example:
public void setOutputPropertyDefault(java.lang.String name, java.lang.String val)
name
- The name of the property, which is just the local name
if it is in no namespace, but is the URI in curly braces followed by
the local name if it is in a namespace, for example:
public java.lang.Object asDOM3Serializer() throws java.io.IOException
Serializer
DOM3Serializer
interface, it should return null.
In principle only one of asDOM3Serializer() or asContentHander() should be called.
asDOM3Serializer
in interface Serializer
java.io.IOException
- An I/O exception occuredSerializer.asDOM3Serializer()
Copyright © 2014 Apache XML Project. All Rights Reserved.