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 |
static int |
HTML_ATTREMPTY |
static int |
HTML_ATTRURL |
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 Vector |
m_cdataSectionElements
Pairs of local names and corresponding URIs of CDATA sections.
|
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 boolean |
m_doIndent
Flag to tell if indenting (pretty-printing) is on.
|
protected jdk7u.jaxp.org.apache.xml.external.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 boolean |
m_isStandalone
Determine if the output is a standalone.
|
protected boolean |
m_needToCallSetDocumentInfo |
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 SourceLocator |
m_sourceLocator |
protected boolean |
m_standaloneWasSpecified
True if standalone was specified.
|
protected SerializerTrace |
m_tracer
Handle for firing generate events.
|
protected Writer |
m_writer
The writer to send output to.
|
static int |
NO_BAD_CHARS |
static String |
XML_PREFIX |
static String |
XMLNS_PREFIX |
static String |
XMLNS_URI |
static String |
XMLVERSION10 |
static String |
XMLVERSION11
Define the XML version.
|
| Constructor and Description |
|---|
SerializerBase() |
| 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 |
addUniqueAttribute(String qName,
String value,
int flags)
Add a unique attribute to the current element.
|
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. |
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 |
characters(String chars)
This method is used to notify of a character event, but passing the data
as a character String rather than the standard character array.
|
void |
close()
Flush and close the underlying java.io.Writer.
|
void |
comment(String data)
Receive notification of a comment.
|
void |
endElement(String elemName)
This method is used to notify that an element has ended.
|
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 |
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()
Push a boolean state based on if the name of the current element
is found in the list of qnames.
|
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.
|
protected void |
setDocumentInfo() |
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 m_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 |
setIsStandalone(boolean isStandalone)
Sets the isStandalone property
|
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 |
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 |
startElement(String qName)
This method is used to notify of the start of an element
|
void |
startElement(String uri,
String localName,
String qName)
This method is used to notify that an element is starting.
|
boolean |
startPrefixMapping(String prefix,
String uri,
boolean shouldFlush)
This method is used to notify that a prefix maping is to start, which can
be for the current element, or for the one to come.
|
void |
unparsedEntityDecl(String arg0,
String arg1,
String arg2,
String arg3) |
void |
warning(SAXParseException exc) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitflushPending, serialize, setContentHandler, setEscapingcharacters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, skippedEntity, startElement, startPrefixMappingcomment, endCDATA, endDTD, startCDATA, startDTD, startEntityattributeDecl, elementDecl, externalEntityDecl, internalEntityDeclgetOutputFormat, getOutputStream, getWriter, setOutputFormat, setOutputStream, setWriterprotected boolean m_needToCallStartDocument
protected boolean m_cdataTagOpen
protected AttributesImplSerializer m_attributes
protected boolean m_inEntityRef
protected boolean m_inExternalDTD
protected boolean m_standaloneWasSpecified
protected boolean m_isStandalone
protected boolean m_doIndent
protected int m_indentAmount
protected Vector m_cdataSectionElements
protected NamespaceMappings m_prefixMap
protected SerializerTrace m_tracer
protected SourceLocator m_sourceLocator
protected Writer m_writer
protected jdk7u.jaxp.org.apache.xml.external.serializer.ElemContext m_elemContext
protected char[] m_charsBuff
protected char[] m_attrBuff
protected boolean m_needToCallSetDocumentInfo
public static final int NO_BAD_CHARS
public static final int HTML_ATTREMPTY
public static final int HTML_ATTRURL
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 elementSAXExceptionprotected void fireCharEvent(char[] chars,
int start,
int length)
throws SAXException
chars - content of charactersstart - starting index of characters to outputlength - number of characters to outputSAXExceptionpublic void comment(String data) throws SAXException
data - the comment, but unlike the SAX comment() method this
method takes a String rather than a character array.SAXExceptionExtendedLexicalHandler.comment(String)protected String patchName(String qname)
protected static String getLocalName(String qname)
qname - the qualified namepublic void setDocumentLocator(Locator locator)
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
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 elementSAXExceptionExtendedContentHandler.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)
name - the attribute's qualified namevalue - the value of the attributepublic void addXSLAttribute(String name, String value, String uri)
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
atts - List of attributes to add to this listSAXExceptionpublic 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 SerializerContentHandler 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
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 SerializationHandlerToStreamprotected void initCDATA()
public String getEncoding()
public void setEncoding(String m_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 SerializationHandlerm_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 setIsStandalone(boolean isStandalone)
setIsStandalone in interface SerializationHandlerisStandalone - true if the ORACLE_IS_STANDALONE is set to yesORACLE_IS_STANDALONEpublic void namespaceAfterStartElement(String uri, String prefix) throws SAXException
uri - the URI of the namespaceprefix - the prefix associated with the given URI.SAXExceptionExtendedContentHandler.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 SerializerDOMSerializer interface into this serializer, or null
if the serializer is not DOM capableIOException - An I/O exception occuredSerializer.asDOMSerializer()protected boolean isCdataSection()
Hidden parameters are the vector of qualified elements specified in cdata-section-names attribute, and the m_cdataSectionStates stack onto which whether the current element is in the list is pushed (true or false). Other hidden parameters are the current elements namespaceURI, localName and qName
protected static final String getPrefixPart(String qname)
qname - a qualified namepublic NamespaceMappings getNamespaceMappings()
ExtendedContentHandler.getNamespaceMappings()public String getPrefix(String namespaceURI)
namespaceURI - the uri of the namespace in questionExtendedContentHandler.getPrefix(String)public String getNamespaceURI(String qname, boolean isElement)
qname - a qualified nameisElement - true if the qualified name is the name of
an element.public String getNamespaceURIFromPrefix(String prefix)
prefix - the prefix whose URI is searched forpublic void entityReference(String name) throws SAXException
name - Name of entitySAXExceptionpublic void setTransformer(Transformer t)
setTransformer in interface SerializationHandlert - the transformer associated with this serializer.SerializationHandler.setTransformer(Transformer)public Transformer getTransformer()
getTransformer in interface SerializationHandlerSerializationHandler.getTransformer()public void characters(Node node) throws SAXException
node - the Node to serializeSAXExceptionpublic void error(SAXParseException exc) throws SAXException
error in interface ErrorHandlerSAXExceptionErrorHandler.error(SAXParseException)public void fatalError(SAXParseException exc) throws SAXException
fatalError in interface ErrorHandlerSAXExceptionErrorHandler.fatalError(SAXParseException)public void warning(SAXParseException exc) throws SAXException
warning in interface ErrorHandlerSAXExceptionErrorHandler.warning(SAXParseException)protected void fireStartEntity(String name) throws SAXException
name - Name of entitySAXExceptionprotected void fireCDATAEvent(char[] chars,
int start,
int length)
throws SAXException
chars - content of CDATAstart - starting index of characters to outputlength - number of characters to outputSAXExceptionprotected void fireCommentEvent(char[] chars,
int start,
int length)
throws SAXException
chars - content of commentstart - starting index of comment to outputlength - number of characters to outputSAXExceptionpublic void fireEndEntity(String name) throws SAXException
name - Name of entitySAXExceptionprotected void fireStartDoc()
throws SAXException
SAXExceptionprotected void fireEndDoc()
throws SAXException
SAXExceptionprotected void fireStartElem(String elemName) throws SAXException
elemName - the qualified name of the elementSAXExceptionprotected void fireEscapingEvent(String name, String data) throws SAXException
name - Name of PISAXExceptionprotected void fireEntityReference(String name) throws SAXException
name - Name of entity referenceSAXExceptionpublic 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).
SAXException - Any SAX exception, possibly
wrapping another exception.SAXExceptionprotected void startDocumentInternal()
throws SAXException
SAXExceptionprotected void setDocumentInfo()
public void setSourceLocator(SourceLocator locator)
locator - the source locatorExtendedContentHandler.setSourceLocator(javax.xml.transform.SourceLocator)public void setNamespaceMappings(NamespaceMappings mappings)
setNamespaceMappings in interface SerializationHandlermappings - NamespaceMappingspublic boolean reset()
Serializerreset in interface Serializerpublic void addAttribute(String uri, String localName, String rawName, String type, String value) throws SAXException
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 attributeSAXExceptionExtendedContentHandler.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 DTDHandlerSAXExceptionDTDHandler.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 DTDHandlerSAXExceptionDTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)public void setDTDEntityExpansion(boolean expand)
setDTDEntityExpansion in interface SerializationHandlerexpand - true if DTD entities are to be expanded,
false if they are to be left as DTD entity references.public void characters(String chars) throws SAXException
chars - the character dataSAXExceptionpublic void endElement(String elemName) throws SAXException
endElement(namespaceURI,localName,qName)only the last parameter is passed. If needed the serializer can derive the localName from the qualified name and derive the namespaceURI from its implementation.
elemName - the fully qualified element name.SAXExceptionpublic void startElement(String uri, String localName, String qName) throws SAXException
startElement(uri,localName,qname,atts)but without the attributes.
uri - the namespace URI of the elementlocalName - the local name (without prefix) of the elementqName - the qualified name of the elementSAXExceptionpublic void startElement(String qName) throws SAXException
qName - the fully qualified name of the elementSAXExceptionpublic boolean startPrefixMapping(String prefix, String uri, boolean shouldFlush) throws SAXException
prefix - the prefix that maps to the given URIuri - the namespace URI of the given prefixshouldFlush - if true this call is like the SAX
startPrefixMapping(prefix,uri) call and the mapping applies to the
element to come. If false the mapping applies to the current element.SAXExceptionpublic void addUniqueAttribute(String qName, String value, int flags) throws SAXException
qName - the fully qualified attribute name.value - the attribute valueflags - a bitwise flagSAXExceptionpublic 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–2021 mhoffrogge. All rights reserved.