Class SerializerBase
- All Implemented Interfaces:
DOMSerializer,ExtendedContentHandler,ExtendedLexicalHandler,SerializationHandler,Serializer,ContentHandler,DTDHandler,ErrorHandler,DeclHandler,LexicalHandler
- Direct Known Subclasses:
ToSAXHandler,ToStream,ToUnknownStream
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringTo insert ]]> in a CDATA section by ending the last CDATA section with ]] and starting the next CDATA section with >static final StringThe constant "]]>"static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringThe name of the package that this class is in.static final StringThe same as the name of the package that this class is in except that '.' are replaced with '/'.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringDefine the XML version.Fields inherited from interface org.apache.xml.serializer.ExtendedContentHandler
HTML_ATTREMPTY, HTML_ATTRURL, NO_BAD_CHARS -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttribute(String name, String value) Adds the given attribute to the set of collected attributes, but only if there is a currently open element.voidThis method adds an attribute the the current element, but should not be used for an xsl:attribute child.voidaddAttribute(String uri, String localName, String rawName, String type, String value, boolean XSLAttribute) Adds the given attribute to the set of collected attributes , but only if there is a currently open element.booleanaddAttributeAlways(String uri, String localName, String rawName, String type, String value, boolean XSLAttribute) Adds the given attribute to the set of attributes, even if there is no currently open element.voidaddAttributes(Attributes atts) Add the given attributes to the currently collected ones.voidaddXSLAttribute(String name, String value, String uri) Adds the given xsl:attribute to the set of collected attributes, but only if there is a currently open element.Return aContentHandlerinterface into this serializer.Return aDOM3Serializerinterface into this serializer.Return aDOMSerializerinterface into this serializer.voidcharacters(Node node) This method gets the nodes value as a String and uses that String as if it were an input character notification.voidclose()Flush and close the underlying java.io.Writer.voidReceive notification of a comment.booleanReturn true if nothing has been sent to this result tree yet.voidReport the end of an entity.voidentityReference(String name) Entity reference event.voiderror(SAXParseException exc) voidvoidfireEndEntity(String name) To fire off end entity trace eventReturns the previously set value of the value to be used as the public identifier in the document type declaration (DTD).Returns the previously set value of the value to be used as the system identifier in the document type declaration (DTD).Returns the character encoding to be used in the output document.booleanintGets the mediatype the media-type or MIME type associated with the output document.Some users of the serializer may need the current namespace mappingsgetNamespaceURI(String qname, boolean isElement) Returns the URI of an element or attribute.getNamespaceURIFromPrefix(String prefix) Returns the URI of prefix (if any)booleangetOutputProperty(String name) Get the value of an output property, the explicit value, if any, otherwise the default value, if any, otherwise null.Get the default value of an xsl:output property, which would be null only if no default value exists for the property.Get the value of an output property, not the default value.Returns the prefix currently pointing to the given URI (if any).Gets the XSL standalone attributeGets the transformer associated with this serializerGets the version of the output format.voidnamespaceAfterStartElement(String uri, String prefix) This method is used when a prefix/uri namespace mapping is indicated after the element was started with a startElement() and before and endElement().voidnotationDecl(String arg0, String arg1, String arg2) booleanreset()This method resets the serializer.voidsetCdataSectionElements(Vector URI_and_localNames) Sets the value coming from the xsl:output cdata-section-elements stylesheet property.voidsetDoctype(String doctypeSystem, String doctypePublic) Set the value coming from the xsl:output doctype-public and doctype-system stylesheet propertiesvoidsetDoctypePublic(String doctypePublic) Set the value coming from the xsl:output doctype-public stylesheet attribute.voidsetDoctypeSystem(String doctypeSystem) Set the value coming from the xsl:output doctype-system stylesheet attribute.voidsetDocumentLocator(Locator locator) Receive an object for locating the origin of SAX document events.voidsetDTDEntityExpansion(boolean expand) If set to false the serializer does not expand DTD entities, but leaves them as is, the default value is true.voidsetEncoding(String encoding) Sets the character encoding coming from the xsl:output encoding stylesheet attribute.voidsetIndent(boolean doIndent) Sets the value coming from the xsl:output indent stylesheet attribute.voidsetIndentAmount(int m_indentAmount) Sets the indentation amount.voidsetMediaType(String mediaType) Sets the value coming from the xsl:output media-type stylesheet attribute.voidsetNamespaceMappings(NamespaceMappings mappings) Used only by TransformerSnapshotImpl to restore the serialization to a previous state.voidsetOmitXMLDeclaration(boolean b) Sets the value coming from the xsl:output omit-xml-declaration stylesheet attributevoidsetOutputProperty(String name, String val) Set the value for the output property, typically from an xsl:output element, but this does not change what the default value is.voidsetOutputPropertyDefault(String name, String val) Set the default value for an output property, but this does not impact any explicitly set value.voidsetSourceLocator(SourceLocator locator) This method is used to set the source locator, which might be used to generated an error message.voidsetStandalone(String standalone) Sets the value coming from the xsl:output standalone stylesheet attribute.voidSets the transformer associated with this serializervoidsetVersion(String version) Sets the value coming from the xsl:output version attribute.voidReceive notification of the beginning of a document.voidunparsedEntityDecl(String arg0, String arg1, String arg2, String arg3) voidwarning(SAXParseException exc) Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.xml.sax.ContentHandler
characters, declaration, endDocument, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, skippedEntity, startElement, startPrefixMappingMethods inherited from interface org.xml.sax.ext.DeclHandler
attributeDecl, elementDecl, externalEntityDecl, internalEntityDeclMethods inherited from interface org.apache.xml.serializer.ExtendedContentHandler
addUniqueAttribute, characters, endElement, startElement, startElement, startPrefixMappingMethods inherited from interface org.xml.sax.ext.LexicalHandler
comment, endCDATA, endDTD, startCDATA, startDTD, startEntityMethods inherited from interface org.apache.xml.serializer.SerializationHandler
flushPending, serialize, setContentHandler, setEscapingMethods inherited from interface org.apache.xml.serializer.Serializer
getOutputFormat, getOutputStream, getWriter, setOutputFormat, setOutputStream, setWriter
-
Field Details
-
PKG_NAME
The name of the package that this class is in.Not a public API.
-
PKG_PATH
The same as the name of the package that this class is in except that '.' are replaced with '/'.Not a public API.
-
CDATA_CONTINUE
To insert ]]> in a CDATA section by ending the last CDATA section with ]] and starting the next CDATA section with >- See Also:
-
CDATA_DELIMITER_CLOSE
The constant "]]>"- See Also:
-
CDATA_DELIMITER_OPEN
- See Also:
-
EMPTYSTRING
- See Also:
-
ENTITY_AMP
- See Also:
-
ENTITY_CRLF
- See Also:
-
ENTITY_GT
- See Also:
-
ENTITY_LT
- See Also:
-
ENTITY_QUOT
- See Also:
-
XML_PREFIX
- See Also:
-
XMLNS_PREFIX
- See Also:
-
XMLNS_URI
- See Also:
-
DEFAULT_SAX_SERIALIZER
-
XMLVERSION11
Define the XML version.- See Also:
-
XMLVERSION10
- See Also:
-
-
Method Details
-
comment
Receive notification of a comment.- Specified by:
commentin interfaceExtendedLexicalHandler- Parameters:
data- the comment, but unlike the SAX comment() method this method takes a String rather than a character array.- Throws:
SAXException- See Also:
-
setDocumentLocator
Receive an object for locating the origin of SAX document events.- Specified by:
setDocumentLocatorin interfaceContentHandler- 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(String uri, String localName, String rawName, String type, String value, boolean XSLAttribute) throws 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:
addAttributein interfaceExtendedContentHandler- Parameters:
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 element- Throws:
SAXException- See Also:
-
addAttributeAlways
public boolean addAttributeAlways(String uri, String localName, String rawName, String type, String value, boolean XSLAttribute) Adds the given attribute to the set of attributes, even if there is no currently open element. This is useful if a SAX startPrefixMapping() should need to add an attribute before the element name is seen.- Parameters:
uri- the URI of the 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 element- Returns:
- true if the attribute was added, false if an existing value was replaced.
-
addAttribute
Adds the given attribute to the set of collected attributes, but only if there is a currently open element.- Specified by:
addAttributein interfaceExtendedContentHandler- Parameters:
name- the attribute's qualified namevalue- the value of the attribute
-
addXSLAttribute
Adds the given xsl:attribute to the set of collected attributes, but only if there is a currently open element.- Specified by:
addXSLAttributein interfaceExtendedContentHandler- Parameters:
name- the attribute's qualified name (prefix:localName)value- the value of the attributeuri- the URI that the prefix of the name points to
-
addAttributes
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:
addAttributesin interfaceExtendedContentHandler- Parameters:
atts- List of attributes to add to this list- Throws:
SAXException
-
asContentHandler
Return aContentHandlerinterface into this serializer. If the serializer does not support theContentHandlerinterface, it should return null.- Specified by:
asContentHandlerin interfaceSerializer- Returns:
- A
ContentHandlerinterface into this serializer, or null if the serializer is not SAX 2 capable - Throws:
IOException- An I/O exception occured
-
endEntity
Report the end of an entity.- Specified by:
endEntityin interfaceLexicalHandler- Parameters:
name- The name of the entity that is ending.- Throws:
SAXException- The application may raise an exception.- See Also:
-
close
public void close()Flush and close the underlying java.io.Writer. This method applies to ToStream serializers, not ToSAXHandler serializers.- Specified by:
closein interfaceSerializationHandler- See Also:
-
getEncoding
Returns the character encoding to be used in the output document.- Returns:
- the character encoding to be used in the output document.
-
setEncoding
Sets the character encoding coming from the xsl:output encoding stylesheet attribute.- 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- Parameters:
b- true if the XML declaration is to be omitted from the output document.
-
getOmitXMLDeclaration
public boolean getOmitXMLDeclaration()- Returns:
- true if the XML declaration is to be omitted from the output document.
-
getDoctypePublic
Returns the previously set value of the value to be used as the public identifier in the document type declaration (DTD).- Returns:
- the public identifier to be used in the DOCTYPE declaration in the output document.
-
setDoctypePublic
Set the value coming from the xsl:output doctype-public stylesheet attribute.- Parameters:
doctypePublic- the public identifier to be used in the DOCTYPE declaration in the output document.
-
getDoctypeSystem
Returns the previously set value of the value to be used as the system identifier in the document type declaration (DTD).- Returns:
- the system identifier to be used in the DOCTYPE declaration in the output document.
-
setDoctypeSystem
Set the value coming from the xsl:output doctype-system stylesheet attribute.- Parameters:
doctypeSystem- the system identifier to be used in the DOCTYPE declaration in the output document.
-
setDoctype
Set the value coming from the xsl:output doctype-public and doctype-system stylesheet properties- Parameters:
doctypeSystem- the system identifier to be used in the DOCTYPE declaration in the output document.doctypePublic- the public identifier to be used in the DOCTYPE declaration in the output document.
-
setStandalone
Sets the value coming from the xsl:output standalone stylesheet attribute.- Parameters:
standalone- a value of "yes" indicates that thestandalonedelaration 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.
-
getStandalone
Gets the XSL standalone attribute- Returns:
- a value of "yes" if the
standalonedelaration is to be included in the output document. - See Also:
-
XSLOutputAttributes.getStandalone()
-
getIndent
public boolean getIndent()- Returns:
- true if the output document should be indented to visually indicate its structure.
-
getMediaType
Gets the mediatype the media-type or MIME type associated with the output document.- Returns:
- the mediatype the media-type or MIME type associated with the output document.
-
getVersion
Gets the version of the output format.- Returns:
- the version of the output format.
-
setVersion
Sets the value coming from the xsl:output version attribute.- Parameters:
version- the version of the output format.- See Also:
-
XSLOutputAttributes.setVersion(String)
-
setMediaType
Sets the value coming from the xsl:output media-type stylesheet attribute.- Parameters:
mediaType- the non-null media-type or MIME type associated with the output document.- See Also:
-
OutputKeys.MEDIA_TYPEXSLOutputAttributes.setMediaType(String)
-
getIndentAmount
public int getIndentAmount()- Returns:
- the number of spaces to indent for each indentation level.
-
setIndentAmount
public void setIndentAmount(int m_indentAmount) Sets the indentation amount.- Specified by:
setIndentAmountin interfaceSerializationHandler- 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.- Parameters:
doIndent- true if the output document should be indented to visually indicate its structure.- See Also:
-
XSLOutputAttributes.setIndent(boolean)
-
namespaceAfterStartElement
This method is used when a prefix/uri namespace mapping is indicated after the element was started with a startElement() and before and endElement(). startPrefixMapping(prefix,uri) would be used before the startElement() call.- Specified by:
namespaceAfterStartElementin interfaceExtendedContentHandler- Parameters:
uri- the URI of the namespaceprefix- the prefix associated with the given URI.- Throws:
SAXException- See Also:
-
asDOMSerializer
Return aDOMSerializerinterface into this serializer. If the serializer does not support theDOMSerializerinterface, it should return null.- Specified by:
asDOMSerializerin interfaceSerializer- Returns:
- A
DOMSerializerinterface into this serializer, or null if the serializer is not DOM capable - Throws:
IOException- An I/O exception occured- See Also:
-
getNamespaceMappings
Some users of the serializer may need the current namespace mappings- Specified by:
getNamespaceMappingsin interfaceExtendedContentHandler- Returns:
- the current namespace mappings (prefix/uri)
- See Also:
-
getPrefix
Returns the prefix currently pointing to the given URI (if any).- Specified by:
getPrefixin interfaceExtendedContentHandler- Parameters:
namespaceURI- the uri of the namespace in question- Returns:
- a prefix pointing to the given URI (if any).
- See Also:
-
getNamespaceURI
Returns the URI of an element or attribute. Note that default namespaces do not apply directly to attributes.- Specified by:
getNamespaceURIin interfaceExtendedContentHandler- Parameters:
qname- a qualified nameisElement- true if the qualified name is the name of an element.- Returns:
- returns the namespace URI associated with the qualified name.
-
getNamespaceURIFromPrefix
Returns the URI of prefix (if any)- Specified by:
getNamespaceURIFromPrefixin interfaceExtendedContentHandler- 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
Entity reference event.- Specified by:
entityReferencein interfaceExtendedContentHandler- Parameters:
name- Name of entity- Throws:
SAXException
-
setTransformer
Sets the transformer associated with this serializer- Specified by:
setTransformerin interfaceSerializationHandler- Parameters:
t- the transformer associated with this serializer.- See Also:
-
getTransformer
Gets the transformer associated with this serializer- Specified by:
getTransformerin interfaceSerializationHandler- Returns:
- returns the transformer associated with this serializer.
- See Also:
-
characters
This method gets the nodes value as a String and uses that String as if it were an input character notification.- Specified by:
charactersin interfaceExtendedContentHandler- Parameters:
node- the Node to serialize- Throws:
SAXException
-
error
- Specified by:
errorin interfaceErrorHandler- Throws:
SAXException- See Also:
-
fatalError
- Specified by:
fatalErrorin interfaceErrorHandler- Throws:
SAXException- See Also:
-
warning
- Specified by:
warningin interfaceErrorHandler- Throws:
SAXException- See Also:
-
fireEndEntity
To fire off end entity trace event- Parameters:
name- Name of entity- Throws:
SAXException
-
startDocument
Receive notification of the beginning of a document. This method is never a self generated call, but only called externally.The SAX parser will invoke this method only once, before any other methods in this interface or in DTDHandler (except for setDocumentLocator).
- Specified by:
startDocumentin interfaceContentHandler- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.SAXException
-
setSourceLocator
This method is used to set the source locator, which might be used to generated an error message.- Specified by:
setSourceLocatorin interfaceExtendedContentHandler- Parameters:
locator- the source locator- See Also:
-
setNamespaceMappings
Used only by TransformerSnapshotImpl to restore the serialization to a previous state.- Specified by:
setNamespaceMappingsin interfaceSerializationHandler- Parameters:
mappings- NamespaceMappings
-
reset
public boolean reset()Description copied from interface:SerializerThis 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:
resetin interfaceSerializer- Returns:
- True if serializer has been reset and can be reused
-
addAttribute
public void addAttribute(String uri, String localName, String rawName, String type, String value) throws SAXException This method adds an attribute the the current element, but should not be used for an xsl:attribute child.- Specified by:
addAttributein interfaceExtendedContentHandler- Parameters:
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 attribute- Throws:
SAXException- See Also:
-
notationDecl
- Specified by:
notationDeclin interfaceDTDHandler- Throws:
SAXException- See Also:
-
unparsedEntityDecl
public void unparsedEntityDecl(String arg0, String arg1, String arg2, String arg3) throws SAXException - Specified by:
unparsedEntityDeclin interfaceDTDHandler- Throws:
SAXException- See Also:
-
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:
setDTDEntityExpansionin interfaceSerializationHandler- Parameters:
expand- true if DTD entities are to be expanded, false if they are to be left as DTD entity references.
-
documentIsEmpty
public boolean documentIsEmpty()Return true if nothing has been sent to this result tree yet.This is not a public API.
-
getOutputProperty
Get the value of an output property, the explicit value, if any, otherwise the default value, if any, otherwise null. -
getOutputPropertyNonDefault
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
Return aDOM3Serializerinterface into this serializer. If the serializer does not support theDOM3Serializerinterface, it should return null.- Specified by:
asDOM3Serializerin interfaceSerializer- Returns:
- A
DOM3Serializerinterface into this serializer, or null if the serializer is not DOM capable - Throws:
IOException- An I/O exception occured- See Also:
-
getOutputPropertyDefault
Get the default value of an xsl:output property, which would be null only if no default value exists for the property. -
setOutputProperty
Set the value for the output property, typically from an xsl:output element, but this does not change what the default value is. -
setOutputPropertyDefault
Set the default value for an output property, but this does not impact any explicitly set value. -
setCdataSectionElements
Sets the value coming from the xsl:output cdata-section-elements stylesheet property. This sets the elements whose text elements are to be output as CDATA sections.- Parameters:
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.
-