org.apache.xml.serializer
Class SerializerBase

java.lang.Object
  extended by org.apache.xml.serializer.SerializerBase
All Implemented Interfaces:
DOMSerializer, ExtendedContentHandler, ExtendedLexicalHandler, SerializationHandler, Serializer, SerializerConstants, XSLOutputAttributes, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.ErrorHandler, org.xml.sax.ext.DeclHandler, org.xml.sax.ext.LexicalHandler
Direct Known Subclasses:
ToSAXHandler, ToStream, ToUnknownStream

public abstract class SerializerBase
extends java.lang.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.


Field Summary
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  java.util.Hashtable m_CdataElems
           
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.
(package private)  boolean m_docIsEmpty
           
protected  java.lang.String m_doctypePublic
          The public ID for the doc type.
protected  java.lang.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  int m_indentAmount
          Amount to indent.
protected  boolean m_inEntityRef
          Tells if we're in an EntityRef event.
protected  boolean m_inExternalDTD
          This flag is set while receiving events from the external DTD
protected  java.lang.String m_mediatype
          The mediatype.
protected  boolean m_needToCallStartDocument
          true if we still need to call startDocumentInternal()
(package private)  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  java.util.HashMap m_OutputProps
          A mapping of keys to explicitly set values, for example if and has an "encoding" attribute, this map will have what that attribute maps to.
private  java.util.HashMap 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  javax.xml.transform.SourceLocator m_sourceLocator
           
private  java.lang.String m_standalone
          The standalone value for the doctype.
protected  boolean m_standaloneWasSpecified
          True if standalone was specified.
protected  java.lang.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  javax.xml.transform.Transformer m_transformer
          The transformer that was around when this output handler was created (if any).
protected  java.lang.String m_version
          Tells the XML version, for writing out to the XML decl.
protected  java.io.Writer m_writer
          The writer to send output to.
static java.lang.String PKG_NAME
          The name of the package that this class is in.
static java.lang.String PKG_PATH
          The same as the name of the package that this class is in except that '.' are replaced with '/'.
 
Fields inherited from interface org.apache.xml.serializer.ExtendedContentHandler
HTML_ATTREMPTY, HTML_ATTRURL, NO_BAD_CHARS
 
Fields inherited from interface org.apache.xml.serializer.SerializerConstants
CDATA_CONTINUE, CDATA_DELIMITER_CLOSE, CDATA_DELIMITER_OPEN, DEFAULT_SAX_SERIALIZER, EMPTYSTRING, ENTITY_AMP, ENTITY_CRLF, ENTITY_GT, ENTITY_LT, ENTITY_QUOT, XML_PREFIX, XMLNS_PREFIX, XMLNS_URI, XMLVERSION10, XMLVERSION11
 
Constructor Summary
SerializerBase()
           
 
Method Summary
 void addAttribute(java.lang.String name, java.lang.String value)
          Adds the given attribute to the set of collected attributes, but only if there is a currently open element.
 void addAttribute(java.lang.String uri, java.lang.String localName, java.lang.String rawName, java.lang.String type, java.lang.String value)
          This method adds an attribute the the current element, but should not be used for an xsl:attribute child.
 void addAttribute(java.lang.String uri, java.lang.String localName, java.lang.String rawName, java.lang.String type, java.lang.String value, boolean XSLAttribute)
          Adds the given attribute to the set of collected attributes , but only if there is a currently open element.
 boolean addAttributeAlways(java.lang.String uri, java.lang.String localName, java.lang.String rawName, java.lang.String type, java.lang.String value, boolean XSLAttribute)
          Adds the given attribute to the set of attributes, even if there is no currently open element.
 void addAttributes(org.xml.sax.Attributes atts)
          Add the given attributes to the currently collected ones.
private  void addCDATAElement(java.lang.String uri, java.lang.String localName)
           
 void addXSLAttribute(java.lang.String name, java.lang.String value, java.lang.String uri)
          Adds the given xsl:attribute to the set of collected attributes, but only if there is a currently open element.
 org.xml.sax.ContentHandler asContentHandler()
          Return a ContentHandler interface into this serializer.
 java.lang.Object asDOM3Serializer()
          Return a DOM3Serializer interface into this serializer.
 DOMSerializer asDOMSerializer()
          Return a DOMSerializer interface into this serializer.
 void characters(org.w3c.dom.Node node)
          This method gets the nodes value as a String and uses that String as if it were an input character notification.
 void close()
          Flush and close the underlying java.io.Writer.
 void comment(java.lang.String data)
          Receive notification of a comment.
 boolean documentIsEmpty()
          Return true if nothing has been sent to this result tree yet.
 void endEntity(java.lang.String name)
          Report the end of an entity.
 void entityReference(java.lang.String name)
          Entity reference event.
 void error(org.xml.sax.SAXParseException exc)
           
 void fatalError(org.xml.sax.SAXParseException exc)
           
protected  void fireCDATAEvent(char[] chars, int start, int length)
          Report the CDATA trace event
protected  void fireCharEvent(char[] chars, int start, int length)
          Report the characters trace event
protected  void fireCommentEvent(char[] chars, int start, int length)
          Report the comment trace event
protected  void fireEndDoc()
          To fire off end document trace event
protected  void fireEndElem(java.lang.String name)
          To fire off the end element trace event
 void fireEndEntity(java.lang.String name)
          To fire off end entity trace event
protected  void fireEntityReference(java.lang.String name)
          To fire off the entity reference trace event
protected  void fireEscapingEvent(java.lang.String name, java.lang.String data)
          To fire off the PI trace event
protected  void fireStartDoc()
          To fire off start document trace event
protected  void fireStartElem(java.lang.String elemName)
          Report the start element trace event.
protected  void fireStartEntity(java.lang.String 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.
 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).
private  java.lang.String getElementURI()
          Before this call m_elementContext.m_elementURI is null, which means it is not yet known.
 java.lang.String getEncoding()
          Returns the character encoding to be used in the output document.
(package private) static char getFirstCharLocName(java.lang.String name)
          Get the first char of the local name
 boolean getIndent()
           
 int getIndentAmount()
           
protected static java.lang.String getLocalName(java.lang.String qname)
          Returns the local name of a qualified name.
 java.lang.String getMediaType()
          Gets the mediatype the media-type or MIME type associated with the output document.
 NamespaceMappings getNamespaceMappings()
          Some users of the serializer may need the current namespace mappings
 java.lang.String getNamespaceURI(java.lang.String qname, boolean isElement)
          Returns the URI of an element or attribute.
 java.lang.String getNamespaceURIFromPrefix(java.lang.String prefix)
          Returns the URI of prefix (if any)
 boolean getOmitXMLDeclaration()
           
(package private)  java.util.Set getOutputPropDefaultKeys()
           
 java.lang.String getOutputProperty(java.lang.String name)
          Get the value of an output property, the explicit value, if any, otherwise the default value, if any, otherwise null.
 java.lang.String getOutputPropertyDefault(java.lang.String name)
          Get the default value of an xsl:output property, which would be null only if no default value exists for the property.
 java.lang.String getOutputPropertyNonDefault(java.lang.String name)
          Get the value of an output property, not the default value.
(package private)  java.util.Set getOutputPropKeys()
           
 java.lang.String getPrefix(java.lang.String namespaceURI)
          Returns the prefix currently pointing to the given URI (if any).
protected static java.lang.String getPrefixPart(java.lang.String qname)
          Returns the local name of a qualified name.
private  java.lang.String getProp(java.lang.String name, boolean defaultVal)
           
 java.lang.String getStandalone()
          Gets the XSL standalone attribute
 javax.xml.transform.Transformer getTransformer()
          Gets the transformer associated with this serializer
 java.lang.String getVersion()
          Gets the version of the output format.
protected  void initCDATA()
          Initialize global variables
(package private)  void initCdataElems(java.lang.String s)
           
(package private)  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.
 void namespaceAfterStartElement(java.lang.String uri, java.lang.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().
 void notationDecl(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2)
           
protected  java.lang.String patchName(java.lang.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.
 boolean reset()
          This method resets the serializer.
private  void resetSerializerBase()
          Reset all of the fields owned by SerializerBase
 void setDoctype(java.lang.String doctypeSystem, java.lang.String doctypePublic)
          Set the value coming from the xsl:output doctype-public and doctype-system stylesheet properties
 void setDoctypePublic(java.lang.String doctypePublic)
          Set the value coming from the xsl:output doctype-public stylesheet attribute.
 void setDoctypeSystem(java.lang.String doctypeSystem)
          Set the value coming from the xsl:output doctype-system stylesheet attribute.
 void setDocumentLocator(org.xml.sax.Locator locator)
          Receive an object for locating the origin of SAX document events.
 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.
 void setEncoding(java.lang.String encoding)
          Sets the character encoding coming from the xsl:output encoding stylesheet attribute.
 void setIndent(boolean doIndent)
          Sets the value coming from the xsl:output indent stylesheet attribute.
 void setIndentAmount(int m_indentAmount)
          Sets the indentation amount.
 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 setOutputProperty(java.lang.String name, java.lang.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.
 void setOutputPropertyDefault(java.lang.String name, java.lang.String val)
          Set the default value for an output property, but this does not impact any explicitly set value.
(package private)  void setProp(java.lang.String name, java.lang.String val, boolean defaultVal)
           
 void setSourceLocator(javax.xml.transform.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.
protected  void setStandaloneInternal(java.lang.String standalone)
          Sets the XSL standalone attribute, but does not remember if this is a default or explicite setting.
 void setTransformer(javax.xml.transform.Transformer t)
          Sets the transformer associated with this serializer
 void setVersion(java.lang.String version)
          Sets the value coming from the xsl:output version attribute.
 void 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 boolean subPartMatch(java.lang.String p, java.lang.String t)
          Tell if two strings are equal, without worry if the first string is null.
 void unparsedEntityDecl(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2, java.lang.String arg3)
           
 void warning(org.xml.sax.SAXParseException exc)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.xml.serializer.SerializationHandler
flushPending, serialize, setContentHandler, setEscaping
 
Methods inherited from interface org.apache.xml.serializer.ExtendedContentHandler
addUniqueAttribute, characters, endElement, startElement, startElement, startPrefixMapping
 
Methods inherited from interface org.xml.sax.ContentHandler
characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, skippedEntity, startElement, startPrefixMapping
 
Methods inherited from interface org.xml.sax.ext.LexicalHandler
comment, endCDATA, endDTD, startCDATA, startDTD, startEntity
 
Methods inherited from interface org.apache.xml.serializer.XSLOutputAttributes
setCdataSectionElements
 
Methods inherited from interface org.xml.sax.ext.DeclHandler
attributeDecl, elementDecl, externalEntityDecl, internalEntityDecl
 
Methods inherited from interface org.apache.xml.serializer.Serializer
getOutputFormat, getOutputStream, getWriter, setOutputFormat, setOutputStream, setWriter
 

Field Detail

PKG_NAME

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

Not a public API.


PKG_PATH

public static final java.lang.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.


m_needToCallStartDocument

protected boolean m_needToCallStartDocument
true if we still need to call startDocumentInternal()


m_cdataTagOpen

protected boolean m_cdataTagOpen
True if a trailing "]]>" still needs to be written to be written out. Used to merge adjacent CDATA sections


m_attributes

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.


m_inEntityRef

protected boolean m_inEntityRef
Tells if we're in an EntityRef event.


m_inExternalDTD

protected boolean m_inExternalDTD
This flag is set while receiving events from the external DTD


m_doctypeSystem

protected java.lang.String m_doctypeSystem
The System ID for the doc type.


m_doctypePublic

protected java.lang.String m_doctypePublic
The public ID for the doc type.


m_needToOutputDocTypeDecl

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.


m_shouldNotWriteXMLHeader

protected boolean m_shouldNotWriteXMLHeader
Tells if we should write the XML declaration.


m_standalone

private java.lang.String m_standalone
The standalone value for the doctype.


m_standaloneWasSpecified

protected boolean m_standaloneWasSpecified
True if standalone was specified.


m_doIndent

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


m_indentAmount

protected int m_indentAmount
Amount to indent.


m_version

protected java.lang.String m_version
Tells the XML version, for writing out to the XML decl.


m_mediatype

protected java.lang.String m_mediatype
The mediatype. Not used right now.


m_transformer

private javax.xml.transform.Transformer m_transformer
The transformer that was around when this output handler was created (if any).


m_prefixMap

protected NamespaceMappings m_prefixMap
Namespace support, that keeps track of currently defined prefix/uri mappings. As processed elements come and go, so do the associated mappings for that element.


m_tracer

protected SerializerTrace m_tracer
Handle for firing generate events. This interface may be implemented by the referenced transformer object.


m_sourceLocator

protected javax.xml.transform.SourceLocator m_sourceLocator

m_writer

protected java.io.Writer m_writer
The writer to send output to. This field is only used in the ToStream serializers, but exists here just so that the fireStartDoc() and other fire... methods can flush this writer when tracing.


m_elemContext

protected ElemContext m_elemContext
A reference to "stack frame" corresponding to the current element. Such a frame is pushed at a startElement() and popped at an endElement(). This frame contains information about the element, such as its namespace URI.


m_charsBuff

protected char[] m_charsBuff
A utility buffer for converting Strings passed to character() methods to character arrays. Reusing this buffer means not creating a new character array everytime and it runs faster.


m_attrBuff

protected char[] m_attrBuff
A utility buffer for converting Strings passed to attribute methods to character arrays. Reusing this buffer means not creating a new character array everytime and it runs faster.


m_StringOfCDATASections

protected java.lang.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. This field replaces m_cdataSectionElements Vector.


m_docIsEmpty

boolean m_docIsEmpty

m_CdataElems

protected java.util.Hashtable m_CdataElems

m_OutputProps

private java.util.HashMap m_OutputProps
A mapping of keys to explicitly set values, for example if and has an "encoding" attribute, this map will have what that attribute maps to.


m_OutputPropsDefault

private java.util.HashMap 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".

Constructor Detail

SerializerBase

SerializerBase()
Method Detail

fireEndElem

protected void fireEndElem(java.lang.String name)
                    throws org.xml.sax.SAXException
To fire off the end element trace event

Parameters:
name - Name of element
Throws:
org.xml.sax.SAXException

fireCharEvent

protected void fireCharEvent(char[] chars,
                             int start,
                             int length)
                      throws org.xml.sax.SAXException
Report the characters trace event

Parameters:
chars - content of characters
start - starting index of characters to output
length - number of characters to output
Throws:
org.xml.sax.SAXException

comment

public void comment(java.lang.String data)
             throws org.xml.sax.SAXException
Receive notification of a comment.

Specified by:
comment in interface ExtendedLexicalHandler
Parameters:
data - the comment, but unlike the SAX comment() method this method takes a String rather than a character array.
Throws:
org.xml.sax.SAXException
See Also:
ExtendedLexicalHandler.comment(String)

patchName

protected java.lang.String patchName(java.lang.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. For a qname of the form "ns?:otherprefix:name", this function patches the qname by simply ignoring "otherprefix". TODO: This method is a HACK! We do not have access to the XML file, it sometimes generates a NS prefix of the form "ns?" for an attribute.


getLocalName

protected static java.lang.String getLocalName(java.lang.String qname)
Returns the local name of a qualified name. If the name has no prefix, then it works as the identity (SAX2).

Parameters:
qname - the qualified name
Returns:
the name, but excluding any prefix and colon.

setDocumentLocator

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

Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler
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.


addAttribute

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 org.xml.sax.SAXException
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.

Specified by:
addAttribute in interface ExtendedContentHandler
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
Throws:
org.xml.sax.SAXException
See Also:
ExtendedContentHandler.addAttribute(String, String, String, String, String)

addAttributeAlways

public boolean addAttributeAlways(java.lang.String uri,
                                  java.lang.String localName,
                                  java.lang.String rawName,
                                  java.lang.String type,
                                  java.lang.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.

addAttribute

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

Specified by:
addAttribute in interface ExtendedContentHandler
Parameters:
name - the attribute's qualified name
value - the value of the attribute

addXSLAttribute

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

Specified by:
addXSLAttribute in interface ExtendedContentHandler
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

addAttributes

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

Specified by:
addAttributes in interface ExtendedContentHandler
Parameters:
atts - List of attributes to add to this list
Throws:
org.xml.sax.SAXException

asContentHandler

public org.xml.sax.ContentHandler asContentHandler()
                                            throws java.io.IOException
Return a ContentHandler interface into this serializer. If the serializer does not support the ContentHandler interface, it should return null.

Specified by:
asContentHandler in interface Serializer
Returns:
A ContentHandler interface into this serializer, or null if the serializer is not SAX 2 capable
Throws:
java.io.IOException - An I/O exception occured

endEntity

public void endEntity(java.lang.String name)
               throws org.xml.sax.SAXException
Report the end of an entity.

Specified by:
endEntity in interface org.xml.sax.ext.LexicalHandler
Parameters:
name - The name of the entity that is ending.
Throws:
org.xml.sax.SAXException - The application may raise an exception.
See Also:
LexicalHandler.startEntity(java.lang.String)

close

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

Specified by:
close in interface SerializationHandler
See Also:
ToStream

initCDATA

protected void initCDATA()
Initialize global variables


getEncoding

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

Specified by:
getEncoding in interface XSLOutputAttributes
Returns:
the character encoding to be used in the output document.

setEncoding

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

Specified by:
setEncoding in interface XSLOutputAttributes
Parameters:
m_encoding - the character encoding

setOmitXMLDeclaration

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

Specified by:
setOmitXMLDeclaration in interface XSLOutputAttributes
Parameters:
b - true if the XML declaration is to be omitted from the output document.

getOmitXMLDeclaration

public boolean getOmitXMLDeclaration()
Specified by:
getOmitXMLDeclaration in interface XSLOutputAttributes
Returns:
true if the XML declaration is to be omitted from the output document.

getDoctypePublic

public 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).

Specified by:
getDoctypePublic in interface XSLOutputAttributes
Returns:
the public identifier to be used in the DOCTYPE declaration in the output document.

setDoctypePublic

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

Specified by:
setDoctypePublic in interface XSLOutputAttributes
Parameters:
doctypePublic - the public identifier to be used in the DOCTYPE declaration in the output document.

getDoctypeSystem

public 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).

Specified by:
getDoctypeSystem in interface XSLOutputAttributes
Returns:
the system identifier to be used in the DOCTYPE declaration in the output document.

setDoctypeSystem

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

Specified by:
setDoctypeSystem in interface XSLOutputAttributes
Parameters:
doctypeSystem - the system identifier to be used in the DOCTYPE declaration in the output document.

setDoctype

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

Specified by:
setDoctype in interface XSLOutputAttributes
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.

setStandalone

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

Specified by:
setStandalone in interface XSLOutputAttributes
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.

setStandaloneInternal

protected void setStandaloneInternal(java.lang.String standalone)
Sets the XSL standalone attribute, but does not remember if this is a default or explicite setting.

Parameters:
standalone - "yes" | "no"

getStandalone

public java.lang.String getStandalone()
Gets the XSL standalone attribute

Specified by:
getStandalone in interface XSLOutputAttributes
Returns:
a value of "yes" if the standalone delaration is to be included in the output document.
See Also:
XSLOutputAttributes.getStandalone()

getIndent

public boolean getIndent()
Specified by:
getIndent in interface XSLOutputAttributes
Returns:
true if the output document should be indented to visually indicate its structure.

getMediaType

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

Specified by:
getMediaType in interface XSLOutputAttributes
Returns:
the mediatype the media-type or MIME type associated with the output document.

getVersion

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

Specified by:
getVersion in interface XSLOutputAttributes
Returns:
the version of the output format.

setVersion

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

Specified by:
setVersion in interface XSLOutputAttributes
Parameters:
version - the version of the output format.
See Also:
XSLOutputAttributes.setVersion(String)

setMediaType

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

Specified by:
setMediaType in interface XSLOutputAttributes
Parameters:
mediaType - the non-null media-type or MIME type associated with the output document.
See Also:
OutputKeys.MEDIA_TYPE, XSLOutputAttributes.setMediaType(String)

getIndentAmount

public int getIndentAmount()
Specified by:
getIndentAmount in interface XSLOutputAttributes
Returns:
the number of spaces to indent for each indentation level.

setIndentAmount

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

Specified by:
setIndentAmount in interface SerializationHandler
Parameters:
m_indentAmount - The m_indentAmount to set

setIndent

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

Specified by:
setIndent in interface XSLOutputAttributes
Parameters:
doIndent - true if the output document should be indented to visually indicate its structure.
See Also:
XSLOutputAttributes.setIndent(boolean)

namespaceAfterStartElement

public void namespaceAfterStartElement(java.lang.String uri,
                                       java.lang.String prefix)
                                throws org.xml.sax.SAXException
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.

Specified by:
namespaceAfterStartElement in interface ExtendedContentHandler
Parameters:
uri - the URI of the namespace
prefix - the prefix associated with the given URI.
Throws:
org.xml.sax.SAXException
See Also:
ExtendedContentHandler.namespaceAfterStartElement(String, String)

asDOMSerializer

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

Specified by:
asDOMSerializer in interface Serializer
Returns:
A DOMSerializer interface into this serializer, or null if the serializer is not DOM capable
Throws:
java.io.IOException - An I/O exception occured
See Also:
Serializer.asDOMSerializer()

subPartMatch

private static final boolean subPartMatch(java.lang.String p,
                                          java.lang.String t)
Tell if two strings are equal, without worry if the first string is null.

Parameters:
p - String reference, which may be null.
t - String reference, which may be null.
Returns:
true if strings are equal.

getPrefixPart

protected static final java.lang.String getPrefixPart(java.lang.String qname)
Returns the local name of a qualified name. If the name has no prefix, then it works as the identity (SAX2).

Parameters:
qname - a qualified name
Returns:
returns the prefix of the qualified name, or null if there is no prefix.

getNamespaceMappings

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

Specified by:
getNamespaceMappings in interface ExtendedContentHandler
Returns:
the current namespace mappings (prefix/uri)
See Also:
ExtendedContentHandler.getNamespaceMappings()

getPrefix

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

Specified by:
getPrefix in interface ExtendedContentHandler
Parameters:
namespaceURI - the uri of the namespace in question
Returns:
a prefix pointing to the given URI (if any).
See Also:
ExtendedContentHandler.getPrefix(String)

getNamespaceURI

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

Specified by:
getNamespaceURI in interface ExtendedContentHandler
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 java.lang.String getNamespaceURIFromPrefix(java.lang.String prefix)
Returns the URI of prefix (if any)

Specified by:
getNamespaceURIFromPrefix in interface ExtendedContentHandler
Parameters:
prefix - the prefix whose URI is searched for
Returns:
the namespace URI currently associated with the prefix, null if the prefix is undefined.

entityReference

public void entityReference(java.lang.String name)
                     throws org.xml.sax.SAXException
Entity reference event.

Specified by:
entityReference in interface ExtendedContentHandler
Parameters:
name - Name of entity
Throws:
org.xml.sax.SAXException

setTransformer

public void setTransformer(javax.xml.transform.Transformer t)
Sets the transformer associated with this serializer

Specified by:
setTransformer in interface SerializationHandler
Parameters:
t - the transformer associated with this serializer.
See Also:
SerializationHandler.setTransformer(Transformer)

getTransformer

public javax.xml.transform.Transformer getTransformer()
Gets the transformer associated with this serializer

Specified by:
getTransformer in interface SerializationHandler
Returns:
returns the transformer associated with this serializer.
See Also:
SerializationHandler.getTransformer()

characters

public void characters(org.w3c.dom.Node node)
                throws org.xml.sax.SAXException
This method gets the nodes value as a String and uses that String as if it were an input character notification.

Specified by:
characters in interface ExtendedContentHandler
Parameters:
node - the Node to serialize
Throws:
org.xml.sax.SAXException

error

public void error(org.xml.sax.SAXParseException exc)
           throws org.xml.sax.SAXException
Specified by:
error in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException
See Also:
ErrorHandler.error(SAXParseException)

fatalError

public void fatalError(org.xml.sax.SAXParseException exc)
                throws org.xml.sax.SAXException
Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException
See Also:
ErrorHandler.fatalError(SAXParseException)

warning

public void warning(org.xml.sax.SAXParseException exc)
             throws org.xml.sax.SAXException
Specified by:
warning in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException
See Also:
ErrorHandler.warning(SAXParseException)

fireStartEntity

protected void fireStartEntity(java.lang.String name)
                        throws org.xml.sax.SAXException
To fire off start entity trace event

Parameters:
name - Name of entity
Throws:
org.xml.sax.SAXException

flushMyWriter

private void flushMyWriter()
This method is only used internally when flushing the writer from the various fire...() trace events. Due to the writer being wrapped with SerializerTraceWriter it may cause the flush of these trace events: EVENTTYPE_OUTPUT_PSEUDO_CHARACTERS EVENTTYPE_OUTPUT_CHARACTERS which trace the output written to the output stream.


fireCDATAEvent

protected void fireCDATAEvent(char[] chars,
                              int start,
                              int length)
                       throws org.xml.sax.SAXException
Report the CDATA trace event

Parameters:
chars - content of CDATA
start - starting index of characters to output
length - number of characters to output
Throws:
org.xml.sax.SAXException

fireCommentEvent

protected void fireCommentEvent(char[] chars,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Report the comment trace event

Parameters:
chars - content of comment
start - starting index of comment to output
length - number of characters to output
Throws:
org.xml.sax.SAXException

fireEndEntity

public void fireEndEntity(java.lang.String name)
                   throws org.xml.sax.SAXException
To fire off end entity trace event

Parameters:
name - Name of entity
Throws:
org.xml.sax.SAXException

fireStartDoc

protected void fireStartDoc()
                     throws org.xml.sax.SAXException
To fire off start document trace event

Throws:
org.xml.sax.SAXException

fireEndDoc

protected void fireEndDoc()
                   throws org.xml.sax.SAXException
To fire off end document trace event

Throws:
org.xml.sax.SAXException

fireStartElem

protected void fireStartElem(java.lang.String elemName)
                      throws org.xml.sax.SAXException
Report the start element trace event. This trace method needs to be called just before the attributes are cleared.

Parameters:
elemName - the qualified name of the element
Throws:
org.xml.sax.SAXException

fireEscapingEvent

protected void fireEscapingEvent(java.lang.String name,
                                 java.lang.String data)
                          throws org.xml.sax.SAXException
To fire off the PI trace event

Parameters:
name - Name of PI
Throws:
org.xml.sax.SAXException

fireEntityReference

protected void fireEntityReference(java.lang.String name)
                            throws org.xml.sax.SAXException
To fire off the entity reference trace event

Parameters:
name - Name of entity reference
Throws:
org.xml.sax.SAXException

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
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).

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
org.xml.sax.SAXException

startDocumentInternal

protected void startDocumentInternal()
                              throws org.xml.sax.SAXException
This method handles what needs to be done at a startDocument() call, whether from an external caller, or internally called in the serializer. For historical reasons the serializer is flexible to startDocument() not always being called. Even if no external call is made into startDocument() this method will always be called as a self generated internal startDocument, it handles what needs to be done at a startDocument() call. This method exists just to make sure that startDocument() is only ever called from an external caller, which in principle is just a matter of style.

Throws:
org.xml.sax.SAXException

setSourceLocator

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

Specified by:
setSourceLocator in interface ExtendedContentHandler
Parameters:
locator - the source locator
See Also:
ExtendedContentHandler.setSourceLocator(javax.xml.transform.SourceLocator)

setNamespaceMappings

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

Specified by:
setNamespaceMappings in interface SerializationHandler
Parameters:
mappings - NamespaceMappings

reset

public boolean reset()
Description copied from interface: Serializer
This method resets the serializer. If this method returns true, the serializer may be used for subsequent serialization of new documents. It is possible to change the output format and output stream prior to serializing, or to reuse the existing output format and output stream or writer.

Specified by:
reset in interface Serializer
Returns:
True if serializer has been reset and can be reused

resetSerializerBase

private void resetSerializerBase()
Reset all of the fields owned by SerializerBase


inTemporaryOutputState

final boolean inTemporaryOutputState()
Returns true if the serializer is used for temporary output rather than final output. This concept is made clear in the XSLT 2.0 draft.


addAttribute

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

Specified by:
addAttribute in interface ExtendedContentHandler
Parameters:
uri - the namespace URI of the attribute name
localName - the local name of the attribute (without prefix)
rawName - the qualified name of the attribute
type - the attribute type typically character data (CDATA)
value - the value of the attribute
Throws:
org.xml.sax.SAXException
See Also:
ExtendedContentHandler.addAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)

notationDecl

public void notationDecl(java.lang.String arg0,
                         java.lang.String arg1,
                         java.lang.String arg2)
                  throws org.xml.sax.SAXException
Specified by:
notationDecl in interface org.xml.sax.DTDHandler
Throws:
org.xml.sax.SAXException
See Also:
DTDHandler.notationDecl(java.lang.String, java.lang.String, java.lang.String)

unparsedEntityDecl

public void unparsedEntityDecl(java.lang.String arg0,
                               java.lang.String arg1,
                               java.lang.String arg2,
                               java.lang.String arg3)
                        throws org.xml.sax.SAXException
Specified by:
unparsedEntityDecl in interface org.xml.sax.DTDHandler
Throws:
org.xml.sax.SAXException
See Also:
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

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.

Specified by:
setDTDEntityExpansion in interface SerializationHandler
Parameters:
expand - true if DTD entities are to be expanded, false if they are to be left as DTD entity references.

initCdataElems

void initCdataElems(java.lang.String s)

addCDATAElement

private void addCDATAElement(java.lang.String uri,
                             java.lang.String localName)

documentIsEmpty

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

This is not a public API.


isCdataSection

protected boolean isCdataSection()
Return true if the current element in m_elemContext is a CDATA section. CDATA sections are specified in the attribute cdata-section-names or in the JAXP equivalent property. In any case the format of the value of such a property is:
 "{uri1}localName1 {uri2}localName2 . . . "
 

This method is not a public API, but is only used internally by the serializer.


getElementURI

private java.lang.String getElementURI()
Before this call m_elementContext.m_elementURI is null, which means it is not yet known. After this call it is non-null, but possibly "" meaning that it is in the default namespace.

Returns:
The URI of the element, never null, but possibly "".

getOutputProperty

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

Specified by:
getOutputProperty in interface XSLOutputAttributes
Parameters:
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:
  • "encoding"
  • "method"
  • "{http://xml.apache.org/xalan}indent-amount"
  • "{http://xml.apache.org/xalan}line-separator"
Returns:
The value of the parameter

getOutputPropertyNonDefault

public java.lang.String getOutputPropertyNonDefault(java.lang.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.


asDOM3Serializer

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

Specified by:
asDOM3Serializer in interface Serializer
Returns:
A DOM3Serializer interface into this serializer, or null if the serializer is not DOM capable
Throws:
java.io.IOException - An I/O exception occured
See Also:
Serializer.asDOM3Serializer()

getOutputPropertyDefault

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

Specified by:
getOutputPropertyDefault in interface XSLOutputAttributes
Parameters:
name - The name of the property.
Returns:
The default value of the parameter, or null if there is no default value.

setOutputProperty

public void setOutputProperty(java.lang.String name,
                              java.lang.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.

Specified by:
setOutputProperty in interface XSLOutputAttributes
Parameters:
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:
  • "encoding"
  • "method"
  • "{http://xml.apache.org/xalan}indent-amount"
  • "{http://xml.apache.org/xalan}line-separator"

setOutputPropertyDefault

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

Specified by:
setOutputPropertyDefault in interface XSLOutputAttributes
Parameters:
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:
  • "encoding"
  • "method"
  • "{http://xml.apache.org/xalan}indent-amount"
  • "{http://xml.apache.org/xalan}line-separator"

getOutputPropDefaultKeys

java.util.Set getOutputPropDefaultKeys()

getOutputPropKeys

java.util.Set getOutputPropKeys()

getProp

private java.lang.String getProp(java.lang.String name,
                                 boolean defaultVal)

setProp

void setProp(java.lang.String name,
             java.lang.String val,
             boolean defaultVal)
Parameters:
name - The name of the property, e.g. "{http://myprop}indent-tabs" or "indent".
val - The value of the property, e.g. "4"
defaultVal - 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

getFirstCharLocName

static char getFirstCharLocName(java.lang.String name)
Get the first char of the local name

Parameters:
name - Either a local name, or a local name preceeded by a uri enclosed in curly braces.