org.apache.xml.serializer

Class SerializerBase

public abstract class SerializerBase extends Object implements SerializationHandler, SerializerConstants

This class acts as a base class for the XML "serializers" and the stream serializers. It contains a number of common fields and methods.

UNKNOWN: internal

Field Summary
static StringPKG_NAME
The name of the package that this class is in.
static StringPKG_PATH
The same as the name of the package that this class is in except that '.' are replaced with '/'.
Method Summary
voidaddAttribute(String uri, String localName, String rawName, String type, String value, boolean XSLAttribute)
Adds the given attribute to the set of collected attributes , but only if there is a currently open element.
voidaddAttribute(String name, String value)
Adds the given attribute to the set of collected attributes, but only if there is a currently open element.
voidaddAttribute(String uri, String localName, String rawName, String type, String value)
This method adds an attribute the the current element, but should not be used for an xsl:attribute child.
booleanaddAttributeAlways(String uri, String localName, String rawName, String type, String value, boolean XSLAttribute)
Adds the given attribute to the set of attributes, even if there is no currently open element.
voidaddAttributes(Attributes atts)
Add the given attributes to the currently collected ones.
voidaddXSLAttribute(String name, String value, String uri)
Adds the given xsl:attribute to the set of collected attributes, but only if there is a currently open element.
ContentHandlerasContentHandler()
Return a ContentHandler interface into this serializer.
ObjectasDOM3Serializer()
Return a DOM3Serializer interface into this serializer.
DOMSerializerasDOMSerializer()
Return a DOMSerializer interface into this serializer.
voidcharacters(Node node)
This method gets the nodes value as a String and uses that String as if it were an input character notification.
voidclose()
Flush and close the underlying java.io.Writer.
voidcomment(String data)
Receive notification of a comment.
booleandocumentIsEmpty()
Return true if nothing has been sent to this result tree yet.
voidendEntity(String name)
Report the end of an entity.
voidentityReference(String name)
Entity reference event.
voiderror(SAXParseException exc)
voidfatalError(SAXParseException exc)
voidfireEndEntity(String name)
To fire off end entity trace event
StringgetDoctypePublic()
Returns the previously set value of the value to be used as the public identifier in the document type declaration (DTD).
StringgetDoctypeSystem()
Returns the previously set value of the value to be used as the system identifier in the document type declaration (DTD).
StringgetEncoding()
Returns the character encoding to be used in the output document.
booleangetIndent()
intgetIndentAmount()
StringgetMediaType()
Gets the mediatype the media-type or MIME type associated with the output document.
NamespaceMappingsgetNamespaceMappings()
Some users of the serializer may need the current namespace mappings
StringgetNamespaceURI(String qname, boolean isElement)
Returns the URI of an element or attribute.
StringgetNamespaceURIFromPrefix(String prefix)
Returns the URI of prefix (if any)
booleangetOmitXMLDeclaration()
StringgetOutputProperty(String name)
Get the value of an output property, the explicit value, if any, otherwise the default value, if any, otherwise null.
StringgetOutputPropertyDefault(String name)
Get the default value of an xsl:output property, which would be null only if no default value exists for the property.
StringgetOutputPropertyNonDefault(String name)
Get the value of an output property, not the default value.
StringgetPrefix(String namespaceURI)
Returns the prefix currently pointing to the given URI (if any).
StringgetStandalone()
Gets the XSL standalone attribute
TransformergetTransformer()
Gets the transformer associated with this serializer
StringgetVersion()
Gets the version of the output format.
voidnamespaceAfterStartElement(String uri, String prefix)
This method is used when a prefix/uri namespace mapping is indicated after the element was started with a startElement() and before and endElement(). startPrefixMapping(prefix,uri) would be used before the startElement() call.
voidnotationDecl(String arg0, String arg1, String arg2)
booleanreset()
voidsetDoctype(String doctypeSystem, String doctypePublic)
Set the value coming from the xsl:output doctype-public and doctype-system stylesheet properties
voidsetDoctypePublic(String doctypePublic)
Set the value coming from the xsl:output doctype-public stylesheet attribute.
voidsetDoctypeSystem(String doctypeSystem)
Set the value coming from the xsl:output doctype-system stylesheet attribute.
voidsetDocumentLocator(Locator locator)
Receive an object for locating the origin of SAX document events.
voidsetDTDEntityExpansion(boolean expand)
If set to false the serializer does not expand DTD entities, but leaves them as is, the default value is true.
voidsetEncoding(String encoding)
Sets the character encoding coming from the xsl:output encoding stylesheet attribute.
voidsetIndent(boolean doIndent)
Sets the value coming from the xsl:output indent stylesheet attribute.
voidsetIndentAmount(int m_indentAmount)
Sets the indentation amount.
voidsetMediaType(String mediaType)
Sets the value coming from the xsl:output media-type stylesheet attribute.
voidsetNamespaceMappings(NamespaceMappings mappings)
Used only by TransformerSnapshotImpl to restore the serialization to a previous state.
voidsetOmitXMLDeclaration(boolean b)
Sets the value coming from the xsl:output omit-xml-declaration stylesheet attribute
voidsetOutputProperty(String name, String val)
Set the value for the output property, typically from an xsl:output element, but this does not change what the default value is.
voidsetOutputPropertyDefault(String name, String val)
Set the default value for an output property, but this does not impact any explicitly set value.
voidsetSourceLocator(SourceLocator locator)
This method is used to set the source locator, which might be used to generated an error message.
voidsetStandalone(String standalone)
Sets the value coming from the xsl:output standalone stylesheet attribute.
voidsetTransformer(Transformer t)
Sets the transformer associated with this serializer
voidsetVersion(String version)
Sets the value coming from the xsl:output version attribute.
voidstartDocument()
Receive notification of the beginning of a document.
voidunparsedEntityDecl(String arg0, String arg1, String arg2, String arg3)
voidwarning(SAXParseException exc)

Field Detail

PKG_NAME

public static final String PKG_NAME
The name of the package that this class is in.

Not a public API.

PKG_PATH

public static final String PKG_PATH
The same as the name of the package that this class is in except that '.' are replaced with '/'.

Not a public API.

Method Detail

addAttribute

public void addAttribute(String uri, String localName, String rawName, String type, String value, boolean XSLAttribute)
Adds the given attribute to the set of collected attributes , but only if there is a currently open element. An element is currently open if a startElement() notification has occured but the start of the element has not yet been written to the output. In the stream case this means that we have not yet been forced to close the elements opening tag by another notification, such as a character notification.

Parameters: uri the URI of the attribute localName the local name of the attribute rawName the qualified name of the attribute type the type of the attribute (probably CDATA) value the value of the attribute XSLAttribute true if this attribute is coming from an xsl:attriute element

See Also: ExtendedContentHandler

addAttribute

public void addAttribute(String name, String value)
Adds the given attribute to the set of collected attributes, but only if there is a currently open element.

Parameters: name the attribute's qualified name value the value of the attribute

addAttribute

public void addAttribute(String uri, String localName, String rawName, String type, String value)
This method adds an attribute the the current element, but should not be used for an xsl:attribute child.

See Also: ExtendedContentHandler

addAttributeAlways

public boolean addAttributeAlways(String uri, String localName, String rawName, String type, String value, boolean XSLAttribute)
Adds the given attribute to the set of attributes, even if there is no currently open element. This is useful if a SAX startPrefixMapping() should need to add an attribute before the element name is seen.

Parameters: uri the URI of the attribute localName the local name of the attribute rawName the qualified name of the attribute type the type of the attribute (probably CDATA) value the value of the attribute XSLAttribute true if this attribute is coming from an xsl:attribute element

Returns: true if the attribute was added, false if an existing value was replaced.

addAttributes

public void addAttributes(Attributes atts)
Add the given attributes to the currently collected ones. These attributes are always added, regardless of whether on not an element is currently open.

Parameters: atts List of attributes to add to this list

addXSLAttribute

public void addXSLAttribute(String name, String value, String uri)
Adds the given xsl:attribute to the set of collected attributes, but only if there is a currently open element.

Parameters: name the attribute's qualified name (prefix:localName) value the value of the attribute uri the URI that the prefix of the name points to

asContentHandler

public ContentHandler asContentHandler()
Return a ContentHandler interface into this serializer. If the serializer does not support the ContentHandler interface, it should return null.

Returns: A ContentHandler interface into this serializer, or null if the serializer is not SAX 2 capable

Throws: IOException An I/O exception occured

asDOM3Serializer

public Object asDOM3Serializer()
Return a DOM3Serializer interface into this serializer. If the serializer does not support the DOM3Serializer interface, it should return null.

Returns: A DOM3Serializer interface into this serializer, or null if the serializer is not DOM capable

Throws: IOException An I/O exception occured

See Also: asDOM3Serializer

asDOMSerializer

public DOMSerializer asDOMSerializer()
Return a DOMSerializer interface into this serializer. If the serializer does not support the DOMSerializer interface, it should return null.

Returns: A DOMSerializer interface into this serializer, or null if the serializer is not DOM capable

Throws: IOException An I/O exception occured

See Also: asDOMSerializer

characters

public void characters(Node node)
This method gets the nodes value as a String and uses that String as if it were an input character notification.

Parameters: node the Node to serialize

Throws: org.xml.sax.SAXException

close

public void close()
Flush and close the underlying java.io.Writer. This method applies to ToStream serializers, not ToSAXHandler serializers.

See Also: ToStream

comment

public void comment(String data)
Receive notification of a comment.

See Also: comment

documentIsEmpty

public boolean documentIsEmpty()
Return true if nothing has been sent to this result tree yet.

This is not a public API.

UNKNOWN: internal

endEntity

public void endEntity(String name)
Report the end of an entity.

Parameters: name The name of the entity that is ending.

Throws: org.xml.sax.SAXException The application may raise an exception.

See Also: SerializerBase

entityReference

public void entityReference(String name)
Entity reference event.

Parameters: name Name of entity

Throws: org.xml.sax.SAXException

error

public void error(SAXParseException exc)

See Also: org.xml.sax.ErrorHandler#error(SAXParseException)

fatalError

public void fatalError(SAXParseException exc)

See Also: org.xml.sax.ErrorHandler#fatalError(SAXParseException)

fireEndEntity

public void fireEndEntity(String name)
To fire off end entity trace event

Parameters: name Name of entity

getDoctypePublic

public String getDoctypePublic()
Returns the previously set value of the value to be used as the public identifier in the document type declaration (DTD).

Returns: the public identifier to be used in the DOCTYPE declaration in the output document.

getDoctypeSystem

public String getDoctypeSystem()
Returns the previously set value of the value to be used as the system identifier in the document type declaration (DTD).

Returns: the system identifier to be used in the DOCTYPE declaration in the output document.

getEncoding

public String getEncoding()
Returns the character encoding to be used in the output document.

Returns: the character encoding to be used in the output document.

getIndent

public boolean getIndent()

Returns: true if the output document should be indented to visually indicate its structure.

getIndentAmount

public int getIndentAmount()

Returns: the number of spaces to indent for each indentation level.

getMediaType

public String getMediaType()
Gets the mediatype the media-type or MIME type associated with the output document.

Returns: the mediatype the media-type or MIME type associated with the output document.

getNamespaceMappings

public NamespaceMappings getNamespaceMappings()
Some users of the serializer may need the current namespace mappings

Returns: the current namespace mappings (prefix/uri)

See Also: getNamespaceMappings

getNamespaceURI

public String getNamespaceURI(String qname, boolean isElement)
Returns the URI of an element or attribute. Note that default namespaces do not apply directly to attributes.

Parameters: qname a qualified name isElement true if the qualified name is the name of an element.

Returns: returns the namespace URI associated with the qualified name.

getNamespaceURIFromPrefix

public String getNamespaceURIFromPrefix(String prefix)
Returns the URI of prefix (if any)

Parameters: prefix the prefix whose URI is searched for

Returns: the namespace URI currently associated with the prefix, null if the prefix is undefined.

getOmitXMLDeclaration

public boolean getOmitXMLDeclaration()

Returns: true if the XML declaration is to be omitted from the output document.

getOutputProperty

public String getOutputProperty(String name)
Get the value of an output property, the explicit value, if any, otherwise the default value, if any, otherwise null.

getOutputPropertyDefault

public String getOutputPropertyDefault(String name)
Get the default value of an xsl:output property, which would be null only if no default value exists for the property.

getOutputPropertyNonDefault

public String getOutputPropertyNonDefault(String name)
Get the value of an output property, not the default value. If there is a default value, but no non-default value this method will return null.

getPrefix

public String getPrefix(String namespaceURI)
Returns the prefix currently pointing to the given URI (if any).

Parameters: namespaceURI the uri of the namespace in question

Returns: a prefix pointing to the given URI (if any).

See Also: getPrefix

getStandalone

public String getStandalone()
Gets the XSL standalone attribute

Returns: a value of "yes" if the standalone delaration is to be included in the output document.

See Also: getStandalone

getTransformer

public Transformer getTransformer()
Gets the transformer associated with this serializer

Returns: returns the transformer associated with this serializer.

See Also: getTransformer

getVersion

public String getVersion()
Gets the version of the output format.

Returns: the version of the output format.

namespaceAfterStartElement

public void namespaceAfterStartElement(String uri, String prefix)
This method is used when a prefix/uri namespace mapping is indicated after the element was started with a startElement() and before and endElement(). startPrefixMapping(prefix,uri) would be used before the startElement() call.

Parameters: uri the URI of the namespace prefix the prefix associated with the given URI.

See Also: ExtendedContentHandler

notationDecl

public void notationDecl(String arg0, String arg1, String arg2)

See Also: org.xml.sax.DTDHandler#notationDecl(java.lang.String, java.lang.String, java.lang.String)

reset

public boolean reset()

setDoctype

public void setDoctype(String doctypeSystem, String doctypePublic)
Set the value coming from the xsl:output doctype-public and doctype-system stylesheet properties

Parameters: doctypeSystem the system identifier to be used in the DOCTYPE declaration in the output document. doctypePublic the public identifier to be used in the DOCTYPE declaration in the output document.

setDoctypePublic

public void setDoctypePublic(String doctypePublic)
Set the value coming from the xsl:output doctype-public stylesheet attribute.

Parameters: doctypePublic the public identifier to be used in the DOCTYPE declaration in the output document.

setDoctypeSystem

public void setDoctypeSystem(String doctypeSystem)
Set the value coming from the xsl:output doctype-system stylesheet attribute.

Parameters: doctypeSystem the system identifier to be used in the DOCTYPE declaration in the output document.

setDocumentLocator

public void setDocumentLocator(Locator locator)
Receive an object for locating the origin of SAX document events.

Parameters: locator An object that can return the location of any SAX document event. Receive an object for locating the origin of SAX document events.

SAX parsers are strongly encouraged (though not absolutely required) to supply a locator: if it does so, it must supply the locator to the application by invoking this method before invoking any of the other methods in the DocumentHandler interface.

The locator allows the application to determine the end position of any document-related event, even if the parser is not reporting an error. Typically, the application will use this information for reporting its own errors (such as character content that does not match an application's business rules). The information returned by the locator is probably not sufficient for use with a search engine.

Note that the locator will return correct information only during the invocation of the events in this interface. The application should not attempt to use it at any other time.

setDTDEntityExpansion

public void setDTDEntityExpansion(boolean expand)
If set to false the serializer does not expand DTD entities, but leaves them as is, the default value is true.

setEncoding

public void setEncoding(String encoding)
Sets the character encoding coming from the xsl:output encoding stylesheet attribute.

Parameters: m_encoding the character encoding

setIndent

public void setIndent(boolean doIndent)
Sets the value coming from the xsl:output indent stylesheet attribute.

Parameters: doIndent true if the output document should be indented to visually indicate its structure.

See Also: XSLOutputAttributes

setIndentAmount

public void setIndentAmount(int m_indentAmount)
Sets the indentation amount.

Parameters: m_indentAmount The m_indentAmount to set

setMediaType

public void setMediaType(String mediaType)
Sets the value coming from the xsl:output media-type stylesheet attribute.

Parameters: mediaType the non-null media-type or MIME type associated with the output document.

See Also: javax.xml.transform.OutputKeys#MEDIA_TYPE SerializationHandler

setNamespaceMappings

public void setNamespaceMappings(NamespaceMappings mappings)
Used only by TransformerSnapshotImpl to restore the serialization to a previous state.

Parameters: mappings NamespaceMappings

setOmitXMLDeclaration

public void setOmitXMLDeclaration(boolean b)
Sets the value coming from the xsl:output omit-xml-declaration stylesheet attribute

Parameters: b true if the XML declaration is to be omitted from the output document.

setOutputProperty

public void setOutputProperty(String name, String val)
Set the value for the output property, typically from an xsl:output element, but this does not change what the default value is.

setOutputPropertyDefault

public void setOutputPropertyDefault(String name, String val)
Set the default value for an output property, but this does not impact any explicitly set value.

setSourceLocator

public void setSourceLocator(SourceLocator locator)
This method is used to set the source locator, which might be used to generated an error message.

Parameters: locator the source locator

See Also: setSourceLocator

setStandalone

public void setStandalone(String standalone)
Sets the value coming from the xsl:output standalone stylesheet attribute.

Parameters: standalone a value of "yes" indicates that the standalone delaration is to be included in the output document. This method remembers if the value was explicitly set using this method, verses if the value is the default value.

setTransformer

public void setTransformer(Transformer t)
Sets the transformer associated with this serializer

Parameters: t the transformer associated with this serializer.

See Also: setTransformer

setVersion

public void setVersion(String version)
Sets the value coming from the xsl:output version attribute.

Parameters: version the version of the output format.

See Also: SerializationHandler

startDocument

public void startDocument()
Receive notification of the beginning of a document. This method is never a self generated call, but only called externally.

The SAX parser will invoke this method only once, before any other methods in this interface or in DTDHandler (except for setDocumentLocator).

Throws: org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. org.xml.sax.SAXException

unparsedEntityDecl

public void unparsedEntityDecl(String arg0, String arg1, String arg2, String arg3)

See Also: org.xml.sax.DTDHandler#unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

warning

public void warning(SAXParseException exc)

See Also: org.xml.sax.ErrorHandler#warning(SAXParseException)

Copyright B) 2006 Apache XML Project. All Rights Reserved.