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

public abstract Class SerializerBase

extends Object
implements SerializationHandler, SerializerConstants
Class Inheritance
All Implemented Interfaces
com.sun.org.apache.xml.internal.serializer.SerializerConstants, com.sun.org.apache.xml.internal.serializer.SerializationHandler, com.sun.org.apache.xml.internal.serializer.Serializer, com.sun.org.apache.xml.internal.serializer.DOMSerializer, org.xml.sax.ErrorHandler, org.xml.sax.DTDHandler, org.xml.sax.ext.DeclHandler, com.sun.org.apache.xml.internal.serializer.XSLOutputAttributes, com.sun.org.apache.xml.internal.serializer.ExtendedLexicalHandler, org.xml.sax.ext.LexicalHandler, com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler, org.xml.sax.ContentHandler
Known Direct Subclasses
com.sun.org.apache.xml.internal.serializer.ToSAXHandler, com.sun.org.apache.xml.internal.serializer.ToStream, com.sun.org.apache.xml.internal.serializer.ToUnknownStream
Imports
com.sun.org.apache.xml.internal.serializer.utils.MsgKey, .Utils, java.io.IOException, java.util.HashMap, .Set, javax.xml.transform.ErrorListener, .OutputKeys, .SourceLocator, .Transformer, org.xml.sax.Attributes, .ContentHandler, .Locator, .SAXException, .SAXParseException, org.xml.sax.ext.Locator2

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

Field Summary

Modifier and TypeField and Description
protected char[]
m_attrBuff

A utility buffer for converting Strings passed to attribute methods to character arrays.

protected AttributesImplSerializer
m_attributes

All the attributes of the current element, collected from startPrefixMapping() calls, or addAddtribute() calls, or from the SAX attributes in a startElement() call.

protected HashMap<String, HashMap<String, String>>
protected boolean
m_cdataTagOpen

True if a trailing "]]>" still needs to be written to be written out.

protected char[]
m_charsBuff

A utility buffer for converting Strings passed to character() methods to character arrays.

pack-priv boolean
protected String
m_doctypePublic

The public ID for the doc type.

protected String
m_doctypeSystem

The System ID for the doc type.

protected boolean
m_doIndent

Flag to tell if indenting (pretty-printing) is on.

protected ElemContext
m_elemContext

A reference to "stack frame" corresponding to the current element.

protected ErrorListener
protected int
m_indentAmount

Amount to indent.

protected int
m_inEntityRef

Tells if we're in an EntityRef event, true if it's greater than 0.

protected boolean
m_inExternalDTD

This flag is set while receiving events from the external DTD

protected boolean
m_isStandalone

Determine if the output is a standalone.

private Locator
protected String
m_mediatype

The mediatype.

protected boolean
protected boolean
m_needToCallStartDocument

true if we still need to call startDocumentInternal()

pack-priv boolean
m_needToOutputDocTypeDecl

Flag to tell that we need to add the doctype decl, which we can't do until the first element is encountered.

private HashMap<String, String>
m_OutputProps

A mapping of keys to explicitly set values, for example if and <xsl:output/> has an "encoding" attribute, this map will have what that attribute maps to.

private HashMap<String, String>
m_OutputPropsDefault

A mapping of keys to default values, for example if the default value of the encoding is "UTF-8" then this map will have that "encoding" maps to "UTF-8".

protected NamespaceMappings
m_prefixMap

Namespace support, that keeps track of currently defined prefix/uri mappings.

protected boolean
m_shouldNotWriteXMLHeader

Tells if we should write the XML declaration.

protected SourceLocator
private String
m_standalone

The standalone value for the doctype.

protected boolean
m_standaloneWasSpecified

True if standalone was specified.

protected String
m_StringOfCDATASections

The CDATA section names stored in a whitespace separateed list with each element being a word of the form "{uri}localName" This list comes from the cdata-section-elements attribute.

protected SerializerTrace
m_tracer

Handle for firing generate events.

private Transformer
m_transformer

The transformer that was around when this output handler was created (if any).

protected String
m_version

Tells the XML version, for writing out to the XML decl.

protected Writer
m_writer

The writer to send output to.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addAttribute(String
the URI of the attribute
uri
,
String
the local name of the attribute
localName
,
String
the qualified name of the attribute
rawName
,
String
the type of the attribute (probably CDATA)
type
,
String
the value of the attribute
value
,
boolean
true if this attribute is coming from an xsl:attriute element
XSLAttribute
)

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

Adds the given attribute to the set of collected attributes , but only if there is a currently open element.

public void
addAttribute(String
the attribute's qualified name
name
,
final String
the value of the attribute
value
)

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

Adds the given attribute to the set of collected attributes, but only if there is a currently open element.

public void
addAttribute(String
the namespace URI of the attribute name
uri
,
String
the local name of the attribute (without prefix)
localName
,
String
the qualified name of the attribute
rawName
,
String
the attribute type typically character data (CDATA)
type
,
String
the value of the attribute
value
)

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

This method adds an attribute the the current element, but should not be used for an xsl:attribute child.

public boolean

Returns:

true if the attribute was added, false if an existing value was replaced.
addAttributeAlways
(String
the URI of the attribute
uri
,
String
the local name of the attribute
localName
,
String
the qualified name of the attribute
rawName
,
String
the type of the attribute (probably CDATA)
type
,
String
the value of the attribute
value
,
boolean
true if this attribute is coming from an xsl:attribute element
XSLAttribute
)

Adds the given attribute to the set of attributes, even if there is no currently open element.

public void
addAttributes(Attributes
List of attributes to add to this list
atts
)

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

Add the given attributes to the currently collected ones.

private void
addCDATAElement(String uri, String localName)

public void
addXSLAttribute(String
the attribute's qualified name (prefix:localName)
name
,
final String
the value of the attribute
value
,
final String
the URI that the prefix of the name points to
uri
)

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

Adds the given xsl:attribute to the set of collected attributes, but only if there is a currently open element.

public ContentHandler

Returns:

A ContentHandler interface into this serializer, or null if the serializer is not SAX 2 capable
asContentHandler
()

Implements com.sun.org.apache.xml.internal.serializer.Serializer.asContentHandler.

Return a ContentHandler interface into this serializer.

public Object

Returns:

A DOM3Serializer interface into this serializer, or null if the serializer is not DOM capable
asDOM3Serializer
()

Implements com.sun.org.apache.xml.internal.serializer.Serializer.asDOM3Serializer.

Return a DOM3Serializer interface into this serializer.

public DOMSerializer

Returns:

A DOMSerializer interface into this serializer, or null if the serializer is not DOM capable
asDOMSerializer
()

Implements com.sun.org.apache.xml.internal.serializer.Serializer.asDOMSerializer.

Return a DOMSerializer interface into this serializer.

public void
characters(Node
the Node to serialize
node
)

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

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

public void
close()

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

Flush and close the underlying java.io.Writer.

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

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

Receive notification of a comment.

public boolean
documentIsEmpty()

Return true if nothing has been sent to this result tree yet.

public void
endEntity(String
The name of the entity that is ending.
name
)

Implements org.xml.sax.ext.LexicalHandler.endEntity.

Report the end of an entity.

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

Implements org.xml.sax.ErrorHandler.error.

Receive notification of a recoverable error.

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

Implements org.xml.sax.ErrorHandler.fatalError.

Receive notification of a non-recoverable, fatal error.

protected void
fireCDATAEvent(char[]
content of CDATA
chars
,
int
starting index of characters to output
start
,
int
number of characters to output
length
)

Report the CDATA trace event

protected void
fireCharEvent(char[]
content of characters
chars
,
int
starting index of characters to output
start
,
int
number of characters to output
length
)

Report the characters trace event

protected void
fireCommentEvent(char[]
content of comment
chars
,
int
starting index of comment to output
start
,
int
number of characters to output
length
)

Report the comment trace event

protected void
fireEndDoc()

To fire off end document trace event

protected void
fireEndElem(String
Name of element
name
)

To fire off the end element trace event

public void
fireEndEntity(String
Name of entity
name
)

To fire off end entity trace event

protected void
fireEntityReference(String
Name of entity reference
name
)

To fire off the entity reference trace event

protected void
fireEscapingEvent(String
Name of PI
name
,
String data)

To fire off the PI trace event

protected void
fireStartDoc()

To fire off start document trace event

protected void
fireStartElem(String
the qualified name of the element
elemName
)

Report the start element trace event.

protected void
fireStartEntity(String
Name of entity
name
)

To fire off start entity trace event

private void
flushMyWriter()

This method is only used internally when flushing the writer from the various fire...() trace events.

public String

Returns:

the public identifier to be used in the DOCTYPE declaration in the output document.
getDoctypePublic
()

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

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

public String

Returns:

the system identifier to be used in the DOCTYPE declaration in the output document.
getDoctypeSystem
()

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

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

private String

Returns:

The URI of the element, never null, but possibly "".
getElementURI
()

Before this call m_elementContext.m_elementURI is null, which means it is not yet known.

public String

Returns:

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

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

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

pack-priv static char
getFirstCharLocName(String
Either a local name, or a local name preceeded by a uri enclosed in curly braces.
name
)

Get the first char of the local name

public boolean

Returns:

true if the output document should be indented to visually indicate its structure.
getIndent
()

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

public int

Returns:

the number of spaces to indent for each indentation level.
getIndentAmount
()

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

protected static String

Returns:

the name, but excluding any prefix and colon.
getLocalName
(String
the qualified name
qname
)

Returns the local name of a qualified name.

public String

Returns:

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

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

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

public NamespaceMappings

Returns:

the current namespace mappings (prefix/uri)
getNamespaceMappings
()

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

Some users of the serializer may need the current namespace mappings

public String

Returns:

returns the namespace URI associated with the qualified name.
getNamespaceURI
(String
a qualified name
qname
,
boolean
true if the qualified name is the name of an element.
isElement
)

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

Returns the URI of an element or attribute.

public String

Returns:

the namespace URI currently associated with the prefix, null if the prefix is undefined.
getNamespaceURIFromPrefix
(String
the prefix whose URI is searched for
prefix
)

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

Returns the URI of prefix (if any)

public boolean

Returns:

true if the XML declaration is to be omitted from the output document.
getOmitXMLDeclaration
()

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

pack-priv Set<String>
public String
getOutputProperty(String
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:
  • "encoding"
  • "method"
  • "{http://xml.apache.org/xalan}indent-amount"
  • "{http://xml.apache.org/xalan}line-separator"
name
)

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

Get the value of an output property, the explicit value, if any, otherwise the default value, if any, otherwise null.

public String
getOutputPropertyDefault(String
The name of the property.
name
)

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

Get the default value of an xsl:output property, which would be null only if no default value exists for the property.

public String
getOutputPropertyNonDefault(String name)

Get the value of an output property, not the default value.

pack-priv Set<String>
public String

Returns:

a prefix pointing to the given URI (if any).
getPrefix
(String
the uri of the namespace in question
namespaceURI
)

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

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

protected static final String

Returns:

returns the prefix of the qualified name, or null if there is no prefix.
getPrefixPart
(String
a qualified name
qname
)

Returns the local name of a qualified name.

private String
getProp(String name, boolean defaultVal)

public String

Returns:

a value of "yes" if the standalone delaration is to be included in the output document.
getStandalone
()

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

Gets the XSL standalone attribute

public Transformer

Returns:

returns the transformer associated with this serializer.
getTransformer
()

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

Gets the transformer associated with this serializer

public String

Returns:

the version of the output format.
getVersion
()

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

Gets the version of the output format.

protected void
initCDATA()

Initialize global variables

pack-priv void
pack-priv final boolean
inTemporaryOutputState()

Returns true if the serializer is used for temporary output rather than final output.

protected boolean
isCdataSection()

Return true if the current element in m_elemContext is a CDATA section.

protected boolean

Returns:

True if current node is in entity reference.
isInEntityRef
()

This method checks if current node is in entity reference.

public void
namespaceAfterStartElement(String
the URI of the namespace
uri
,
String
the prefix associated with the given URI.
prefix
)

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

This method is used when a prefix/uri namespace mapping is indicated after the element was started with a startElement() and before and endElement().

public void
notationDecl(String
The notation name.
arg0
,
String
The notation's public identifier, or null if none was given.
arg1
,
String
The notation's system identifier, or null if none was given.
arg2
)

Implements org.xml.sax.DTDHandler.notationDecl.

Receive notification of a notation declaration event.

protected String
patchName(String qname)

If at runtime, when the qname of the attribute is known, another prefix is specified for the attribute, then we can patch or hack the name with this method.

public boolean
reset()

Implements com.sun.org.apache.xml.internal.serializer.Serializer.reset.

This method resets the serializer.

private void
resetSerializerBase()

Reset all of the fields owned by SerializerBase

public void
setDoctype(String
the system identifier to be used in the DOCTYPE declaration in the output document.
doctypeSystem
,
String
the public identifier to be used in the DOCTYPE declaration in the output document.
doctypePublic
)

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

Set the value coming from the xsl:output doctype-public and doctype-system stylesheet properties

public void
setDoctypePublic(String
the public identifier to be used in the DOCTYPE declaration in the output document.
doctypePublic
)

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

Set the value coming from the xsl:output doctype-public stylesheet attribute.

public void
setDoctypeSystem(String
the system identifier to be used in the DOCTYPE declaration in the output document.
doctypeSystem
)

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

Set the value coming from the xsl:output doctype-system stylesheet attribute.

protected void
public void
setDocumentLocator(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.

locator
)

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Receive an object for locating the origin of SAX document events.

public void
setDTDEntityExpansion(boolean
true if DTD entities are to be expanded, false if they are to be left as DTD entity references.
expand
)

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

If set to false the serializer does not expand DTD entities, but leaves them as is, the default value is true.

public void
setEncoding(String
the character encoding
encoding
)

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

Sets the character encoding coming from the xsl:output encoding stylesheet attribute.

public void
setIndent(boolean
true if the output document should be indented to visually indicate its structure.
doIndent
)

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

Sets the value coming from the xsl:output indent stylesheet attribute.

public void
setIndentAmount(int
The m_indentAmount to set
m_indentAmount
)

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

Sets the indentation amount.

public void
setIsStandalone(boolean
the value of the property
isStandalone
)

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

Sets the implementation specific property "isStandalone".

public void
setMediaType(String
the non-null media-type or MIME type associated with the output document.
mediaType
)

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

Sets the value coming from the xsl:output media-type stylesheet attribute.

public void
setNamespaceMappings(NamespaceMappings
NamespaceMappings
mappings
)

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

Used only by TransformerSnapshotImpl to restore the serialization to a previous state.

public void
setOmitXMLDeclaration(boolean
true if the XML declaration is to be omitted from the output document.
b
)

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

Sets the value coming from the xsl:output omit-xml-declaration stylesheet attribute

public void
setOutputProperty(String
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:
  • "encoding"
  • "method"
  • "{http://xml.apache.org/xalan}indent-amount"
  • "{http://xml.apache.org/xalan}line-separator"
name
,
String
The non-default value of the parameter
val
)

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

Set the value for the output property, typically from an xsl:output element, but this does not change what the default value is.

public void
setOutputPropertyDefault(String
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:
  • "encoding"
  • "method"
  • "{http://xml.apache.org/xalan}indent-amount"
  • "{http://xml.apache.org/xalan}line-separator"
name
,
String
The default value of the parameter
val
)

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

Set the default value for an output property, but this does not impact any explicitly set value.

pack-priv void
setProp(String
The name of the property, e.g. "{http://myprop}indent-tabs" or "indent".
name
,
String
The value of the property, e.g. "4"
val
,
boolean
true if this is a default value being set for the property as opposed to a user define on, set say explicitly in the stylesheet or via JAXP
defaultVal
)

public void
setSourceLocator(SourceLocator
the source locator
locator
)

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

This method is used to set the source locator, which might be used to generated an error message.

public void
setStandalone(String
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.
standalone
)

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

Sets the value coming from the xsl:output standalone stylesheet attribute.

protected void
setStandaloneInternal(String
"yes" | "no"
standalone
)

Sets the XSL standalone attribute, but does not remember if this is a default or explicite setting.

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

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

Sets the transformer associated with this serializer

public void
setVersion(String
the version of the output format.
version
)

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

Sets the value coming from the xsl:output version attribute.

public void
startDocument()

Implements org.xml.sax.ContentHandler.startDocument.

Receive notification of the beginning of a document.

protected void
startDocumentInternal()

This method handles what needs to be done at a startDocument() call, whether from an external caller, or internally called in the serializer.

private static final boolean

Returns:

true if strings are equal.
subPartMatch
(String
String reference, which may be null.
p
,
String
String reference, which may be null.
t
)

Tell if two strings are equal, without worry if the first string is null.

public void
unparsedEntityDecl(String
The unparsed entity's name.
arg0
,
String
The entity's public identifier, or null if none was given.
arg1
,
String
The entity's system identifier.
arg2
,
String
The name of the associated notation.
arg3
)

Implements org.xml.sax.DTDHandler.unparsedEntityDecl.

Receive notification of an unparsed entity declaration event.

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

Implements org.xml.sax.ErrorHandler.warning.

Receive notification of a warning.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait