Package org.apache.xml.serializer.dom3
Class LSSerializerImpl
java.lang.Object
org.apache.xml.serializer.dom3.LSSerializerImpl
- All Implemented Interfaces:
DOMConfiguration,LSSerializer
public final class LSSerializerImpl extends Object implements DOMConfiguration, LSSerializer
Implemenatation of DOM Level 3 org.w3c.ls.LSSerializer and
org.w3c.dom.ls.DOMConfiguration. Serialization is achieved by delegating
serialization calls to
org.apache.xml.serializer.ToStream or
one of its derived classes depending on the serialization method, while walking
the DOM in DOM3TreeWalker.- Version:
- $Id:
- See Also:
- org.w3c.dom.ls.LSSerializer, org.w3c.dom.DOMConfiguration
-
Field Summary
Fields Modifier and Type Field Description protected intfFeatures -
Constructor Summary
Constructors Constructor Description LSSerializerImpl()Constructor: Creates a LSSerializerImpl object. -
Method Summary
Modifier and Type Method Description booleancanSetParameter(String name, Object value)Checks if setting a parameter to a specific value is supported.DOMConfigurationgetDomConfig()Returns the DOMConfiguration of the LSSerializer.DOMErrorHandlergetErrorHandler()This method returns the LSSerializer's error handler.LSSerializerFiltergetFilter()Returns the DOMConfiguration of the LSSerializer.protected StringgetInputEncoding(Node nodeArg)Determines the Input Encoding of the Document Node to serialize.StringgetNewLine()Returns the End-Of-Line sequence of characters to be used in the XML being serialized.ObjectgetParameter(String name)This method returns the value of a parameter if known.DOMStringListgetParameterNames()This method returns a of the parameters supported by this DOMConfiguration object and for which at least one value can be set by the applicationprotected StringgetXMLEncoding(Node nodeArg)Determines the XML Encoding of the Document Node to serialize.protected StringgetXMLVersion(Node nodeArg)Determines the XML Version of the Document Node to serialize.voidinitializeSerializerProps()Initializes the underlying serializer's configuration depending on the default DOMConfiguration parameters.voidsetFilter(LSSerializerFilter filter)Set a LSSerilizerFilter on the LSSerializer.voidsetNewLine(String newLine)Sets the End-Of-Line sequence of characters to be used in the XML being serialized.voidsetParameter(String name, Object value)This method sets the value of the named parameter.booleanwrite(Node nodeArg, LSOutput destination)Serializes the specified node to the specified LSOutput and returns true if the Node was successfully serialized.StringwriteToString(Node nodeArg)Serializes the specified node and returns a String with the serialized data to the caller.booleanwriteToURI(Node nodeArg, String uri)Serializes the specified node to the specified URI and returns true if the Node was successfully serialized.
-
Field Details
-
fFeatures
protected int fFeatures
-
-
Constructor Details
-
LSSerializerImpl
public LSSerializerImpl()Constructor: Creates a LSSerializerImpl object. The underlying XML 1.0 or XML 1.1 org.apache.xml.serializer.Serializer object is created and initialized the first time any of the write methods are invoked to serialize the Node. Subsequent write methods on the same LSSerializerImpl object will use the previously created Serializer object.
-
-
Method Details
-
initializeSerializerProps
public void initializeSerializerProps()Initializes the underlying serializer's configuration depending on the default DOMConfiguration parameters. This method must be called before a node is to be serialized. -
canSetParameter
Checks if setting a parameter to a specific value is supported.- Specified by:
canSetParameterin interfaceDOMConfiguration- Parameters:
name- A String containing the DOMConfiguration parameter name.value- An Object specifying the value of the corresponding parameter.- Returns:
trueif the parameter could be successfully set to the specified value, orfalseif the parameter is not recognized or the requested value is not supported. This does not change the current value of the parameter itself.- Since:
- DOM Level 3
- See Also:
DOMConfiguration.canSetParameter(java.lang.String, java.lang.Object)
-
getParameter
This method returns the value of a parameter if known.- Specified by:
getParameterin interfaceDOMConfiguration- Parameters:
name- A String containing the DOMConfiguration parameter name whose value is to be returned.- Returns:
- Object The value of the parameter if known.
- Throws:
DOMException- NOT_FOUND_ERR: Raised when the parameter name is not recognized.- See Also:
DOMConfiguration.getParameter(java.lang.String)
-
getParameterNames
This method returns a of the parameters supported by this DOMConfiguration object and for which at least one value can be set by the application- Specified by:
getParameterNamesin interfaceDOMConfiguration- Returns:
- DOMStringList A list of DOMConfiguration parameters recognized by the serializer
- See Also:
DOMConfiguration.getParameterNames()
-
setParameter
This method sets the value of the named parameter.- Specified by:
setParameterin interfaceDOMConfiguration- Parameters:
name- A String containing the DOMConfiguration parameter name.value- An Object contaiing the parameters value to set.- Throws:
DOMException- NOT_FOUND_ERR: Raised when the parameter name is not recognized.
NOT_SUPPORTED_ERR: Raised when the parameter name is recognized but the requested value cannot be set.
TYPE_MISMATCH_ERR: Raised if the value type for this parameter name is incompatible with the expected value type.- See Also:
DOMConfiguration.setParameter(java.lang.String, java.lang.Object)
-
getDomConfig
Returns the DOMConfiguration of the LSSerializer.- Specified by:
getDomConfigin interfaceLSSerializer- Returns:
- A DOMConfiguration object.
- Since:
- DOM Level 3
- See Also:
LSSerializer.getDomConfig()
-
getFilter
Returns the DOMConfiguration of the LSSerializer.- Specified by:
getFilterin interfaceLSSerializer- Returns:
- A LSSerializerFilter object.
- Since:
- DOM Level 3
- See Also:
LSSerializer.getFilter()
-
getNewLine
Returns the End-Of-Line sequence of characters to be used in the XML being serialized. If none is set a default "\n" is returned.- Specified by:
getNewLinein interfaceLSSerializer- Returns:
- A String containing the end-of-line character sequence used in serialization.
- Since:
- DOM Level 3
- See Also:
LSSerializer.getNewLine()
-
setFilter
Set a LSSerilizerFilter on the LSSerializer. When set, the filter is called before each node is serialized which depending on its implemention determines if the node is to be serialized or not.- Specified by:
setFilterin interfaceLSSerializer- Parameters:
filter- A LSSerializerFilter to be applied to the stream to serialize.- Since:
- DOM Level 3
- See Also:
LSSerializer.setFilter(org.w3c.dom.ls.LSSerializerFilter)
-
setNewLine
Sets the End-Of-Line sequence of characters to be used in the XML being serialized. Setting this attribute to null will reset its value to the default value i.e. "\n".- Specified by:
setNewLinein interfaceLSSerializer- Parameters:
newLine- a String that is the end-of-line character sequence to be used in serialization.- Since:
- DOM Level 3
- See Also:
LSSerializer.setNewLine(java.lang.String)
-
write
Serializes the specified node to the specified LSOutput and returns true if the Node was successfully serialized.- Specified by:
writein interfaceLSSerializer- Parameters:
nodeArg- The Node to serialize.destination- The destination for the serialized DOM.- Returns:
- Returns
trueifnodewas successfully serialized. Returnfalsein case the normal processing stopped but the implementation kept serializing the document; the result of the serialization being implementation dependent then. - Throws:
LSException- SERIALIZE_ERR: Raised if the LSSerializer was unable to serialize the node.- Since:
- DOM Level 3
- See Also:
LSSerializer.write(org.w3c.dom.Node, org.w3c.dom.ls.LSOutput)
-
writeToString
Serializes the specified node and returns a String with the serialized data to the caller.- Specified by:
writeToStringin interfaceLSSerializer- Parameters:
nodeArg- The Node to serialize.- Returns:
- Returns the serialized data.
- Throws:
LSException- SERIALIZE_ERR: Raised if the LSSerializer was unable to serialize the node.DOMException- DOMSTRING_SIZE_ERR: Raised if the resulting string is too long to fit in aDOMString.- Since:
- DOM Level 3
- See Also:
LSSerializer.writeToString(org.w3c.dom.Node)
-
writeToURI
Serializes the specified node to the specified URI and returns true if the Node was successfully serialized.- Specified by:
writeToURIin interfaceLSSerializer- Parameters:
nodeArg- The Node to serialize.uri- The URI to write to.- Returns:
- Returns
trueifnodewas successfully serialized. Returnfalsein case the normal processing stopped but the implementation kept serializing the document; the result of the serialization being implementation dependent then. - Throws:
LSException- SERIALIZE_ERR: Raised if the LSSerializer was unable to serialize the node.- Since:
- DOM Level 3
- See Also:
LSSerializer.writeToURI(org.w3c.dom.Node, String)
-
getXMLVersion
Determines the XML Version of the Document Node to serialize. If the Document Node is not a DOM Level 3 Node, then the default version returned is 1.0.- Parameters:
nodeArg- The Node to serialize- Returns:
- A String containing the version pseudo-attribute of the XMLDecl.
- Throws:
Throwable- if the DOM implementation does not implement Document.getXmlVersion()
-
getXMLEncoding
Determines the XML Encoding of the Document Node to serialize. If the Document Node is not a DOM Level 3 Node, then the default encoding "UTF-8" is returned.- Parameters:
nodeArg- The Node to serialize- Returns:
- A String containing the encoding pseudo-attribute of the XMLDecl.
- Throws:
Throwable- if the DOM implementation does not implement Document.getXmlEncoding()
-
getInputEncoding
Determines the Input Encoding of the Document Node to serialize. If the Document Node is not a DOM Level 3 Node, then null is returned.- Parameters:
nodeArg- The Node to serialize- Returns:
- A String containing the input encoding.
-
getErrorHandler
This method returns the LSSerializer's error handler.- Returns:
- Returns the fDOMErrorHandler.
-