public abstract class SerializerBase extends Object implements SerializationHandler
Modifier and Type | Field and Description |
---|---|
static String |
CDATA_CONTINUE
To insert ]]> in a CDATA section by ending the last CDATA section with
]] and starting the next CDATA section with >
|
static String |
CDATA_DELIMITER_CLOSE
The constant "]]>"
|
static String |
CDATA_DELIMITER_OPEN |
static String |
DEFAULT_SAX_SERIALIZER |
static String |
EMPTYSTRING |
static String |
ENTITY_AMP |
static String |
ENTITY_CRLF |
static String |
ENTITY_GT |
static String |
ENTITY_LT |
static String |
ENTITY_QUOT |
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 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.
|
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 org.apache.xml.serializer.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 String |
m_mediatype
The mediatype.
|
protected boolean |
m_needToCallStartDocument
true if we still need to call startDocumentInternal()
|
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 |
m_sourceLocator |
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.
|
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.
|
static String |
PKG_NAME
The name of the package that this class is in.
|
static String |
PKG_PATH
The same as the name of the package that this class is in
except that '.' are replaced with '/'.
|
static String |
XML_PREFIX |
static String |
XMLNS_PREFIX |
static String |
XMLNS_URI |
static String |
XMLVERSION10 |
static String |
XMLVERSION11
Define the XML version.
|
HTML_ATTREMPTY, HTML_ATTRURL, NO_BAD_CHARS
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
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.
|
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.
|
void |
addAttributes(Attributes atts)
Add the given attributes to the currently collected ones.
|
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.
|
ContentHandler |
asContentHandler()
Return a
ContentHandler interface into this serializer. |
Object |
asDOM3Serializer()
Return a
DOM3Serializer interface into this serializer. |
DOMSerializer |
asDOMSerializer()
Return a
DOMSerializer interface into this serializer. |
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.
|
void |
close()
Flush and close the underlying java.io.Writer.
|
void |
comment(String data)
Receive notification of a comment.
|
boolean |
documentIsEmpty()
Return true if nothing has been sent to this result tree yet.
|
void |
endEntity(String name)
Report the end of an entity.
|
void |
entityReference(String name)
Entity reference event.
|
void |
error(SAXParseException exc) |
void |
fatalError(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(String name)
To fire off the end element trace event
|
void |
fireEndEntity(String name)
To fire off end entity trace event
|
protected void |
fireEntityReference(String name)
To fire off the entity reference trace event
|
protected void |
fireEscapingEvent(String name,
String data)
To fire off the PI trace event
|
protected void |
fireStartDoc()
To fire off start document trace event
|
protected void |
fireStartElem(String elemName)
Report the start element trace event.
|
protected void |
fireStartEntity(String name)
To fire off start entity trace event
|
String |
getDoctypePublic()
Returns the previously set value of the value to be used as the public
identifier in the document type declaration (DTD).
|
String |
getDoctypeSystem()
Returns the previously set value of the value to be used
as the system identifier in the document type declaration (DTD).
|
String |
getEncoding()
Returns the character encoding to be used in the output document.
|
boolean |
getIndent() |
int |
getIndentAmount() |
protected static String |
getLocalName(String qname)
Returns the local name of a qualified name.
|
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
|
String |
getNamespaceURI(String qname,
boolean isElement)
Returns the URI of an element or attribute.
|
String |
getNamespaceURIFromPrefix(String prefix)
Returns the URI of prefix (if any)
|
boolean |
getOmitXMLDeclaration() |
String |
getOutputProperty(String name)
Get the value of an output property,
the explicit value, if any, otherwise the
default value, if any, otherwise null.
|
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.
|
String |
getOutputPropertyNonDefault(String name)
Get the value of an output property,
not the default value.
|
String |
getPrefix(String namespaceURI)
Returns the prefix currently pointing to the given URI (if any).
|
protected static String |
getPrefixPart(String qname)
Returns the local name of a qualified name.
|
String |
getStandalone()
Gets the XSL standalone attribute
|
Transformer |
getTransformer()
Gets the transformer associated with this serializer
|
String |
getVersion()
Gets the version of the output format.
|
protected void |
initCDATA()
Initialize global variables
|
protected boolean |
isCdataSection()
Return true if the current element in m_elemContext
is a CDATA section.
|
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().
|
void |
notationDecl(String arg0,
String arg1,
String arg2) |
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.
|
boolean |
reset()
This method resets the serializer.
|
void |
setCdataSectionElements(Vector URI_and_localNames)
Sets the value coming from the xsl:output cdata-section-elements
stylesheet property.
|
void |
setDoctype(String doctypeSystem,
String doctypePublic)
Set the value coming from the xsl:output doctype-public and doctype-system stylesheet properties
|
void |
setDoctypePublic(String doctypePublic)
Set the value coming from the xsl:output doctype-public stylesheet attribute.
|
void |
setDoctypeSystem(String doctypeSystem)
Set the value coming from the xsl:output doctype-system stylesheet attribute.
|
void |
setDocumentLocator(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(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(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(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.
|
void |
setOutputPropertyDefault(String name,
String val)
Set the default value for an output property, but this does
not impact any explicitly set value.
|
void |
setSourceLocator(SourceLocator locator)
This method is used to set the source locator, which might be used to
generated an error message.
|
void |
setStandalone(String standalone)
Sets the value coming from the xsl:output standalone stylesheet attribute.
|
protected void |
setStandaloneInternal(String standalone)
Sets the XSL standalone attribute, but does not remember if this is a
default or explicite setting.
|
void |
setTransformer(Transformer t)
Sets the transformer associated with this serializer
|
void |
setVersion(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.
|
void |
unparsedEntityDecl(String arg0,
String arg1,
String arg2,
String arg3) |
void |
warning(SAXParseException exc) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
flushPending, serialize, setContentHandler, setEscaping
addUniqueAttribute, characters, endElement, startElement, startElement, startPrefixMapping
characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, skippedEntity, startElement, startPrefixMapping
comment, endCDATA, endDTD, startCDATA, startDTD, startEntity
attributeDecl, elementDecl, externalEntityDecl, internalEntityDecl
getOutputFormat, getOutputStream, getWriter, setOutputFormat, setOutputStream, setWriter
public static final String PKG_NAME
Not a public API.
public static final String PKG_PATH
Not a public API.
protected boolean m_needToCallStartDocument
protected boolean m_cdataTagOpen
protected AttributesImplSerializer m_attributes
protected boolean m_inEntityRef
protected boolean m_inExternalDTD
protected String m_doctypeSystem
protected String m_doctypePublic
protected boolean m_shouldNotWriteXMLHeader
protected boolean m_standaloneWasSpecified
protected boolean m_doIndent
protected int m_indentAmount
protected String m_version
protected String m_mediatype
protected NamespaceMappings m_prefixMap
protected SerializerTrace m_tracer
protected SourceLocator m_sourceLocator
protected Writer m_writer
protected org.apache.xml.serializer.ElemContext m_elemContext
protected char[] m_charsBuff
protected char[] m_attrBuff
protected String m_StringOfCDATASections
protected Hashtable m_CdataElems
public static final String CDATA_CONTINUE
public static final String CDATA_DELIMITER_CLOSE
public static final String CDATA_DELIMITER_OPEN
public static final String EMPTYSTRING
public static final String ENTITY_AMP
public static final String ENTITY_CRLF
public static final String ENTITY_GT
public static final String ENTITY_LT
public static final String ENTITY_QUOT
public static final String XML_PREFIX
public static final String XMLNS_PREFIX
public static final String XMLNS_URI
public static final String DEFAULT_SAX_SERIALIZER
public static final String XMLVERSION11
public static final String XMLVERSION10
protected void fireEndElem(String name) throws SAXException
name
- Name of elementSAXException
protected void fireCharEvent(char[] chars, int start, int length) throws SAXException
chars
- content of charactersstart
- starting index of characters to outputlength
- number of characters to outputSAXException
public void comment(String data) throws SAXException
comment
in interface ExtendedLexicalHandler
data
- the comment, but unlike the SAX comment() method this
method takes a String rather than a character array.SAXException
ExtendedLexicalHandler.comment(String)
protected String patchName(String qname)
protected static String getLocalName(String qname)
qname
- the qualified namepublic void setDocumentLocator(Locator locator)
setDocumentLocator
in interface ContentHandler
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.
public void addAttribute(String uri, String localName, String rawName, String type, String value, boolean XSLAttribute) throws SAXException
addAttribute
in interface ExtendedContentHandler
uri
- the URI of the attributelocalName
- the local name of the attributerawName
- the qualified name of the attributetype
- the type of the attribute (probably CDATA)value
- the value of the attributeXSLAttribute
- true if this attribute is coming from an xsl:attriute elementSAXException
ExtendedContentHandler.addAttribute(String, String, String, String, String)
public boolean addAttributeAlways(String uri, String localName, String rawName, String type, String value, boolean XSLAttribute)
uri
- the URI of the attributelocalName
- the local name of the attributerawName
- the qualified name of the attributetype
- the type of the attribute (probably CDATA)value
- the value of the attributeXSLAttribute
- true if this attribute is coming from an xsl:attribute elementpublic void addAttribute(String name, String value)
addAttribute
in interface ExtendedContentHandler
name
- the attribute's qualified namevalue
- the value of the attributepublic void addXSLAttribute(String name, String value, String uri)
addXSLAttribute
in interface ExtendedContentHandler
name
- the attribute's qualified name (prefix:localName)value
- the value of the attributeuri
- the URI that the prefix of the name points topublic void addAttributes(Attributes atts) throws SAXException
addAttributes
in interface ExtendedContentHandler
atts
- List of attributes to add to this listSAXException
public ContentHandler asContentHandler() throws IOException
ContentHandler
interface into this serializer.
If the serializer does not support the ContentHandler
interface, it should return null.asContentHandler
in interface Serializer
ContentHandler
interface into this serializer,
or null if the serializer is not SAX 2 capableIOException
- An I/O exception occuredpublic void endEntity(String name) throws SAXException
endEntity
in interface LexicalHandler
name
- The name of the entity that is ending.SAXException
- The application may raise an exception.LexicalHandler.startEntity(java.lang.String)
public void close()
close
in interface SerializationHandler
ToStream
protected void initCDATA()
public String getEncoding()
public void setEncoding(String encoding)
m_encoding
- the character encodingpublic void setOmitXMLDeclaration(boolean b)
b
- true if the XML declaration is to be omitted from the output
document.public boolean getOmitXMLDeclaration()
public String getDoctypePublic()
public void setDoctypePublic(String doctypePublic)
doctypePublic
- the public identifier to be used in the DOCTYPE
declaration in the output document.public String getDoctypeSystem()
public void setDoctypeSystem(String doctypeSystem)
doctypeSystem
- the system identifier to be used in the DOCTYPE
declaration in the output document.public void setDoctype(String doctypeSystem, String doctypePublic)
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.public void setStandalone(String standalone)
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.protected void setStandaloneInternal(String standalone)
standalone
- "yes" | "no"public String getStandalone()
standalone
delaration is to
be included in the output document.XSLOutputAttributes.getStandalone()
public boolean getIndent()
public String getMediaType()
public String getVersion()
public void setVersion(String version)
version
- the version of the output format.XSLOutputAttributes.setVersion(String)
public void setMediaType(String mediaType)
mediaType
- the non-null media-type or MIME type associated with the
output document.OutputKeys.MEDIA_TYPE
,
XSLOutputAttributes.setMediaType(String)
public int getIndentAmount()
public void setIndentAmount(int m_indentAmount)
setIndentAmount
in interface SerializationHandler
m_indentAmount
- The m_indentAmount to setpublic void setIndent(boolean doIndent)
doIndent
- true if the output document should be indented to
visually indicate its structure.XSLOutputAttributes.setIndent(boolean)
public void namespaceAfterStartElement(String uri, String prefix) throws SAXException
namespaceAfterStartElement
in interface ExtendedContentHandler
uri
- the URI of the namespaceprefix
- the prefix associated with the given URI.SAXException
ExtendedContentHandler.namespaceAfterStartElement(String, String)
public DOMSerializer asDOMSerializer() throws IOException
DOMSerializer
interface into this serializer. If the
serializer does not support the DOMSerializer
interface, it should
return null.asDOMSerializer
in interface Serializer
DOMSerializer
interface into this serializer, or null
if the serializer is not DOM capableIOException
- An I/O exception occuredSerializer.asDOMSerializer()
protected static final String getPrefixPart(String qname)
qname
- a qualified namepublic NamespaceMappings getNamespaceMappings()
getNamespaceMappings
in interface ExtendedContentHandler
ExtendedContentHandler.getNamespaceMappings()
public String getPrefix(String namespaceURI)
getPrefix
in interface ExtendedContentHandler
namespaceURI
- the uri of the namespace in questionExtendedContentHandler.getPrefix(String)
public String getNamespaceURI(String qname, boolean isElement)
getNamespaceURI
in interface ExtendedContentHandler
qname
- a qualified nameisElement
- true if the qualified name is the name of
an element.public String getNamespaceURIFromPrefix(String prefix)
getNamespaceURIFromPrefix
in interface ExtendedContentHandler
prefix
- the prefix whose URI is searched forpublic void entityReference(String name) throws SAXException
entityReference
in interface ExtendedContentHandler
name
- Name of entitySAXException
public void setTransformer(Transformer t)
setTransformer
in interface SerializationHandler
t
- the transformer associated with this serializer.SerializationHandler.setTransformer(Transformer)
public Transformer getTransformer()
getTransformer
in interface SerializationHandler
SerializationHandler.getTransformer()
public void characters(Node node) throws SAXException
characters
in interface ExtendedContentHandler
node
- the Node to serializeSAXException
public void error(SAXParseException exc) throws SAXException
error
in interface ErrorHandler
SAXException
ErrorHandler.error(SAXParseException)
public void fatalError(SAXParseException exc) throws SAXException
fatalError
in interface ErrorHandler
SAXException
ErrorHandler.fatalError(SAXParseException)
public void warning(SAXParseException exc) throws SAXException
warning
in interface ErrorHandler
SAXException
ErrorHandler.warning(SAXParseException)
protected void fireStartEntity(String name) throws SAXException
name
- Name of entitySAXException
protected void fireCDATAEvent(char[] chars, int start, int length) throws SAXException
chars
- content of CDATAstart
- starting index of characters to outputlength
- number of characters to outputSAXException
protected void fireCommentEvent(char[] chars, int start, int length) throws SAXException
chars
- content of commentstart
- starting index of comment to outputlength
- number of characters to outputSAXException
public void fireEndEntity(String name) throws SAXException
name
- Name of entitySAXException
protected void fireStartDoc() throws SAXException
SAXException
protected void fireEndDoc() throws SAXException
SAXException
protected void fireStartElem(String elemName) throws SAXException
elemName
- the qualified name of the elementSAXException
protected void fireEscapingEvent(String name, String data) throws SAXException
name
- Name of PISAXException
protected void fireEntityReference(String name) throws SAXException
name
- Name of entity referenceSAXException
public void startDocument() throws SAXException
The SAX parser will invoke this method only once, before any other methods in this interface or in DTDHandler (except for setDocumentLocator).
startDocument
in interface ContentHandler
SAXException
- Any SAX exception, possibly
wrapping another exception.SAXException
protected void startDocumentInternal() throws SAXException
SAXException
public void setSourceLocator(SourceLocator locator)
setSourceLocator
in interface ExtendedContentHandler
locator
- the source locatorExtendedContentHandler.setSourceLocator(javax.xml.transform.SourceLocator)
public void setNamespaceMappings(NamespaceMappings mappings)
setNamespaceMappings
in interface SerializationHandler
mappings
- NamespaceMappingspublic boolean reset()
Serializer
reset
in interface Serializer
public void addAttribute(String uri, String localName, String rawName, String type, String value) throws SAXException
addAttribute
in interface ExtendedContentHandler
uri
- the namespace URI of the attribute namelocalName
- the local name of the attribute (without prefix)rawName
- the qualified name of the attributetype
- the attribute type typically character data (CDATA)value
- the value of the attributeSAXException
ExtendedContentHandler.addAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void notationDecl(String arg0, String arg1, String arg2) throws SAXException
notationDecl
in interface DTDHandler
SAXException
DTDHandler.notationDecl(java.lang.String, java.lang.String, java.lang.String)
public void unparsedEntityDecl(String arg0, String arg1, String arg2, String arg3) throws SAXException
unparsedEntityDecl
in interface DTDHandler
SAXException
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void setDTDEntityExpansion(boolean expand)
setDTDEntityExpansion
in interface SerializationHandler
expand
- true if DTD entities are to be expanded,
false if they are to be left as DTD entity references.public boolean documentIsEmpty()
This is not a public API.
protected boolean isCdataSection()
"{uri1}localName1 {uri2}localName2 . . . "
This method is not a public API, but is only used internally by the serializer.
public String getOutputProperty(String name)
name
- The name of the property, which is just the local name
if it is in no namespace, but is the URI in curly braces followed by
the local name if it is in a namespace, for example:
public String getOutputPropertyNonDefault(String name)
public Object asDOM3Serializer() throws IOException
DOM3Serializer
interface into this serializer. If the
serializer does not support the DOM3Serializer
interface, it should
return null.asDOM3Serializer
in interface Serializer
DOM3Serializer
interface into this serializer, or null
if the serializer is not DOM capableIOException
- An I/O exception occuredSerializer.asDOM3Serializer()
public String getOutputPropertyDefault(String name)
name
- The name of the property.public void setOutputProperty(String name, String val)
name
- The name of the property, which is just the local name
if it is in no namespace, but is the URI in curly braces followed by
the local name if it is in a namespace, for example:
public void setOutputPropertyDefault(String name, String val)
name
- The name of the property, which is just the local name
if it is in no namespace, but is the URI in curly braces followed by
the local name if it is in a namespace, for example:
public void setCdataSectionElements(Vector URI_and_localNames)
URI_and_localNames
- pairs of namespace URI and local names that
identify elements whose text elements are to be output as CDATA sections.
The namespace of the local element must be the given URI to match. The
qName is not given because the prefix does not matter, only the namespace
URI to which that prefix would map matters, so the prefix itself is not
relevant in specifying which elements have their text to be output as
CDATA sections.Copyright © 2018 JBoss by Red Hat. All rights reserved.