org.apache.xml.serializer.dom3
Class LSSerializerImpl

java.lang.Object
  extended by org.apache.xml.serializer.dom3.LSSerializerImpl
All Implemented Interfaces:
org.w3c.dom.DOMConfiguration, org.w3c.dom.ls.LSSerializer

public final class LSSerializerImpl
extends java.lang.Object
implements org.w3c.dom.DOMConfiguration, org.w3c.dom.ls.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.

See Also:
org.w3c.dom.ls.LSSerializer, org.w3c.dom.DOMConfiguration

Nested Class Summary
(package private) static class LSSerializerImpl.ThrowableMethods
          Holder of methods from java.lang.Throwable.
 
Field Summary
private static int CANONICAL
           
private static int CDATA
           
private static int CHARNORMALIZE
           
private static int COMMENTS
           
private static java.lang.String DEFAULT_END_OF_LINE
           
private static int DISCARDDEFAULT
           
private static int DTNORMALIZE
           
private static int ELEM_CONTENT_WHITESPACE
           
private static int ENTITIES
           
private  java.util.Properties fDOMConfigProperties
           
private  org.w3c.dom.DOMErrorHandler fDOMErrorHandler
           
private  DOM3Serializer fDOMSerializer
           
private  java.lang.String fEncoding
           
private  java.lang.String fEndOfLine
           
protected  int fFeatures
           
private  java.lang.String[] fRecognizedParameters
           
private  org.w3c.dom.ls.LSSerializerFilter fSerializerFilter
           
private  org.w3c.dom.Node fVisitedNode
           
private  Serializer fXMLSerializer
          private data members
private static int IGNORE_CHAR_DENORMALIZE
           
private static int INFOSET
           
private static int NAMESPACEDECLS
           
private static int NAMESPACES
           
private static int NORMALIZECHARS
           
private static int PRETTY_PRINT
           
private static int SCHEMAVALIDATE
           
private static int SPLITCDATA
           
private static int VALIDATE
           
private static int WELLFORMED
           
private static int XMLDECL
           
 
Constructor Summary
LSSerializerImpl()
          Constructor: Creates a LSSerializerImpl object.
 
Method Summary
 boolean canSetParameter(java.lang.String name, java.lang.Object value)
          Checks if setting a parameter to a specific value is supported.
private static org.w3c.dom.ls.LSException createLSException(short code, java.lang.Throwable cause)
          Creates an LSException.
 org.w3c.dom.DOMConfiguration getDomConfig()
          Returns the DOMConfiguration of the LSSerializer.
 org.w3c.dom.DOMErrorHandler getErrorHandler()
          This method returns the LSSerializer's error handler.
 org.w3c.dom.ls.LSSerializerFilter getFilter()
          Returns the DOMConfiguration of the LSSerializer.
protected  java.lang.String getInputEncoding(org.w3c.dom.Node nodeArg)
          Determines the Input Encoding of the Document Node to serialize.
 java.lang.String getNewLine()
          Returns the End-Of-Line sequence of characters to be used in the XML being serialized.
 java.lang.Object getParameter(java.lang.String name)
          This method returns the value of a parameter if known.
 org.w3c.dom.DOMStringList 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
private static java.lang.String getPathWithoutEscapes(java.lang.String origPath)
          Replaces all escape sequences in the given path with their literal characters.
protected  java.lang.String getXMLEncoding(org.w3c.dom.Node nodeArg)
          Determines the XML Encoding of the Document Node to serialize.
protected  java.lang.String getXMLVersion(org.w3c.dom.Node nodeArg)
          Determines the XML Version of the Document Node to serialize.
 void initializeSerializerProps()
          Initializes the underlying serializer's configuration depending on the default DOMConfiguration parameters.
private static boolean isHexDigit(char c)
          Returns true if the given character is a valid hex character.
 void setFilter(org.w3c.dom.ls.LSSerializerFilter filter)
          Set a LSSerilizerFilter on the LSSerializer.
 void setNewLine(java.lang.String newLine)
          Sets the End-Of-Line sequence of characters to be used in the XML being serialized.
 void setParameter(java.lang.String name, java.lang.Object value)
          This method sets the value of the named parameter.
 boolean write(org.w3c.dom.Node nodeArg, org.w3c.dom.ls.LSOutput destination)
          Serializes the specified node to the specified LSOutput and returns true if the Node was successfully serialized.
 java.lang.String writeToString(org.w3c.dom.Node nodeArg)
          Serializes the specified node and returns a String with the serialized data to the caller.
 boolean writeToURI(org.w3c.dom.Node nodeArg, java.lang.String uri)
          Serializes the specified node to the specified URI and returns true if the Node was successfully serialized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_END_OF_LINE

private static final java.lang.String DEFAULT_END_OF_LINE

fXMLSerializer

private Serializer fXMLSerializer
private data members


fFeatures

protected int fFeatures

fDOMSerializer

private DOM3Serializer fDOMSerializer

fSerializerFilter

private org.w3c.dom.ls.LSSerializerFilter fSerializerFilter

fVisitedNode

private org.w3c.dom.Node fVisitedNode

fEndOfLine

private java.lang.String fEndOfLine

fDOMErrorHandler

private org.w3c.dom.DOMErrorHandler fDOMErrorHandler

fDOMConfigProperties

private java.util.Properties fDOMConfigProperties

fEncoding

private java.lang.String fEncoding

CANONICAL

private static final int CANONICAL
See Also:
Constant Field Values

CDATA

private static final int CDATA
See Also:
Constant Field Values

CHARNORMALIZE

private static final int CHARNORMALIZE
See Also:
Constant Field Values

COMMENTS

private static final int COMMENTS
See Also:
Constant Field Values

DTNORMALIZE

private static final int DTNORMALIZE
See Also:
Constant Field Values

ELEM_CONTENT_WHITESPACE

private static final int ELEM_CONTENT_WHITESPACE
See Also:
Constant Field Values

ENTITIES

private static final int ENTITIES
See Also:
Constant Field Values

INFOSET

private static final int INFOSET
See Also:
Constant Field Values

NAMESPACES

private static final int NAMESPACES
See Also:
Constant Field Values

NAMESPACEDECLS

private static final int NAMESPACEDECLS
See Also:
Constant Field Values

NORMALIZECHARS

private static final int NORMALIZECHARS
See Also:
Constant Field Values

SPLITCDATA

private static final int SPLITCDATA
See Also:
Constant Field Values

VALIDATE

private static final int VALIDATE
See Also:
Constant Field Values

SCHEMAVALIDATE

private static final int SCHEMAVALIDATE
See Also:
Constant Field Values

WELLFORMED

private static final int WELLFORMED
See Also:
Constant Field Values

DISCARDDEFAULT

private static final int DISCARDDEFAULT
See Also:
Constant Field Values

PRETTY_PRINT

private static final int PRETTY_PRINT
See Also:
Constant Field Values

IGNORE_CHAR_DENORMALIZE

private static final int IGNORE_CHAR_DENORMALIZE
See Also:
Constant Field Values

XMLDECL

private static final int XMLDECL
See Also:
Constant Field Values

fRecognizedParameters

private java.lang.String[] fRecognizedParameters
Constructor Detail

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 Detail

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

public boolean canSetParameter(java.lang.String name,
                               java.lang.Object value)
Checks if setting a parameter to a specific value is supported.

Specified by:
canSetParameter in interface org.w3c.dom.DOMConfiguration
Parameters:
name - A String containing the DOMConfiguration parameter name.
value - An Object specifying the value of the corresponding parameter.
Since:
DOM Level 3
See Also:
DOMConfiguration.canSetParameter(java.lang.String, java.lang.Object)

getParameter

public java.lang.Object getParameter(java.lang.String name)
                              throws org.w3c.dom.DOMException
This method returns the value of a parameter if known.

Specified by:
getParameter in interface org.w3c.dom.DOMConfiguration
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:
org.w3c.dom.DOMException
See Also:
DOMConfiguration.getParameter(java.lang.String)

getParameterNames

public org.w3c.dom.DOMStringList 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:
getParameterNames in interface org.w3c.dom.DOMConfiguration
Returns:
DOMStringList A list of DOMConfiguration parameters recognized by the serializer
See Also:
DOMConfiguration.getParameterNames()

setParameter

public void setParameter(java.lang.String name,
                         java.lang.Object value)
                  throws org.w3c.dom.DOMException
This method sets the value of the named parameter.

Specified by:
setParameter in interface org.w3c.dom.DOMConfiguration
Parameters:
name - A String containing the DOMConfiguration parameter name.
value - An Object contaiing the parameters value to set.
Throws:
org.w3c.dom.DOMException
See Also:
DOMConfiguration.setParameter(java.lang.String, java.lang.Object)

getDomConfig

public org.w3c.dom.DOMConfiguration getDomConfig()
Returns the DOMConfiguration of the LSSerializer.

Specified by:
getDomConfig in interface org.w3c.dom.ls.LSSerializer
Returns:
A DOMConfiguration object.
Since:
DOM Level 3
See Also:
LSSerializer.getDomConfig()

getFilter

public org.w3c.dom.ls.LSSerializerFilter getFilter()
Returns the DOMConfiguration of the LSSerializer.

Specified by:
getFilter in interface org.w3c.dom.ls.LSSerializer
Returns:
A LSSerializerFilter object.
Since:
DOM Level 3
See Also:
LSSerializer.getFilter()

getNewLine

public java.lang.String 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:
getNewLine in interface org.w3c.dom.ls.LSSerializer
Returns:
A String containing the end-of-line character sequence used in serialization.
Since:
DOM Level 3
See Also:
LSSerializer.getNewLine()

setFilter

public void setFilter(org.w3c.dom.ls.LSSerializerFilter filter)
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:
setFilter in interface org.w3c.dom.ls.LSSerializer
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

public void setNewLine(java.lang.String newLine)
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:
setNewLine in interface org.w3c.dom.ls.LSSerializer
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

public boolean write(org.w3c.dom.Node nodeArg,
                     org.w3c.dom.ls.LSOutput destination)
              throws org.w3c.dom.ls.LSException
Serializes the specified node to the specified LSOutput and returns true if the Node was successfully serialized.

Specified by:
write in interface org.w3c.dom.ls.LSSerializer
Parameters:
nodeArg - The Node to serialize.
Throws:
org.w3c.dom.ls.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

public java.lang.String writeToString(org.w3c.dom.Node nodeArg)
                               throws org.w3c.dom.DOMException,
                                      org.w3c.dom.ls.LSException
Serializes the specified node and returns a String with the serialized data to the caller.

Specified by:
writeToString in interface org.w3c.dom.ls.LSSerializer
Parameters:
nodeArg - The Node to serialize.
Throws:
org.w3c.dom.ls.LSException - SERIALIZE_ERR: Raised if the LSSerializer was unable to serialize the node.
org.w3c.dom.DOMException
Since:
DOM Level 3
See Also:
LSSerializer.writeToString(org.w3c.dom.Node)

writeToURI

public boolean writeToURI(org.w3c.dom.Node nodeArg,
                          java.lang.String uri)
                   throws org.w3c.dom.ls.LSException
Serializes the specified node to the specified URI and returns true if the Node was successfully serialized.

Specified by:
writeToURI in interface org.w3c.dom.ls.LSSerializer
Parameters:
nodeArg - The Node to serialize.
Throws:
org.w3c.dom.ls.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

protected java.lang.String getXMLVersion(org.w3c.dom.Node nodeArg)
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:
java.lang.Throwable - if the DOM implementation does not implement Document.getXmlVersion()

getXMLEncoding

protected java.lang.String getXMLEncoding(org.w3c.dom.Node nodeArg)
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:
java.lang.Throwable - if the DOM implementation does not implement Document.getXmlEncoding()

getInputEncoding

protected java.lang.String getInputEncoding(org.w3c.dom.Node nodeArg)
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

public org.w3c.dom.DOMErrorHandler getErrorHandler()
This method returns the LSSerializer's error handler.

Returns:
Returns the fDOMErrorHandler.

getPathWithoutEscapes

private static java.lang.String getPathWithoutEscapes(java.lang.String origPath)
Replaces all escape sequences in the given path with their literal characters.


isHexDigit

private static boolean isHexDigit(char c)
Returns true if the given character is a valid hex character.


createLSException

private static org.w3c.dom.ls.LSException createLSException(short code,
                                                            java.lang.Throwable cause)
Creates an LSException. On J2SE 1.4 and above the cause for the exception will be set.