public class CanonicalXMLSerializerImpl extends java.lang.Object implements CanonicalXMLSerializerInterface, ExclusiveCanonicalXMLSerializerInterface
CanonicalXMLSerializerInterface and ExclusiveCanonicalXMLSerializerInterface. See there for further information.
IMPORTANT NOTE: The algorithms implemented by this class only works correct if namespace attributes
are explicitely declared for all element they should be in scope for. This precondition is necessary due
to a difference in the tree model of XPath and DOM.| Modifier and Type | Class and Description |
|---|---|
protected class |
CanonicalXMLSerializerImpl.AttributeComparator
Implements the
Comparator interface for DOM attributes. |
protected class |
CanonicalXMLSerializerImpl.NSAttributeComparator
Implements the
Comparator interface for DOM namespace attributes. |
| Modifier and Type | Field and Description |
|---|---|
protected static int |
AFTER_DOC_ELEMENT_
Constant indicating that the document element has already been processed.
|
protected org.w3c.dom.traversal.NodeIterator |
allNodesIterator_
A node iterator for the underlying DOM document.
|
protected org.w3c.dom.NodeList |
allOutputNodesList_
All nodes to be canonicalized as a
NodeList. |
protected java.util.HashMap |
allOutputNodesMap_
All nodes to be canonicalized as a
HashMap. |
protected static int |
BEFORE_DOC_ELEMENT_
Constant indicating that the document element has not been processed.
|
static int |
C14N_
Constant indicating that the output has to be canonical XML.
|
protected int |
canonMode_
Indicates wheter the output has to be canonical XML or exclusive canonical XML.
|
static java.lang.String |
EXC_C14N_DEFAULT_NS_PREFIX_
The string used to indicate the default namespace, according to section 4 of Exclusive XML Canonicalization Version 1.0.
|
static int |
EXCLUSIVE_C14N_
Constant indicating that the output has to be exclusive canonical XML.
|
protected static int |
IN_DOC_ELEMENT_
Constant indicating that the document element is currently being processed.
|
protected java.util.HashMap |
inclusiveNamespacePrefixMap_
In case that Exclusive Canonical XML should be serialized, this member contains a list of all namespace
prefixes that should be treated as described in Canonical XML.
|
protected java.util.Map |
namespaceAndXMLAxes_
Contains in scope namespace attributes and xml:foo attributes for each element of the underlying DOM
document (see @link #computeNamespaceAndXMLAxes}.
|
protected boolean |
omitComments_
Indicates wheter to filter comment nodes or not.
|
protected int |
processingPosition_
Indicates processing position during serialization (see {link BEFORE_DOC_ELEMENT_},
IN_DOC_ELEMENT_ and AFTER_DOC_ELEMENT_). |
protected java.io.CharArrayWriter |
serializationResultSink_
Sink for serialization result.
|
FACTORY_METHOD_NAME_, INITPROPERTY_IMPL_CLASSNAME_FACTORY_METHOD_NAME_, INITPROPERTY_IMPL_CLASSNAME_| Modifier | Constructor and Description |
|---|---|
protected |
CanonicalXMLSerializerImpl(org.w3c.dom.NodeList allOutputNodesList,
int canonMode,
boolean omitComments,
java.lang.String inclusiveNamespacePrefixes)
Standard constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkForRelativeNamespaceURIs()
Report an error if there is any namespace attribute in the list of output nodes having a relative URI
as its value.
|
protected java.util.Map |
computeNamespaceAndXMLAxes(org.w3c.dom.Document document)
Computes two sets for each element node of the specified DOM document: One contains all namespace
attributes that are in scope for the element, the other one contains all xml attributes (such as
xml:space), that are in scope for the element.
|
static CanonicalXMLSerializerInterface |
getCanonicalXMLSerializer(org.w3c.dom.NodeList allOutputNodesList,
boolean omitComments)
Gets an implementation instance of interface
CanonicalXMLSerializerInterface. |
static ExclusiveCanonicalXMLSerializerInterface |
getExclusiveCanonicalXMLSerializer(org.w3c.dom.NodeList allOutputNodesList,
java.lang.String inclusiveNamespacePrefixes,
boolean omitComments)
Gets an implementation instance of interface
ExclusiveCanonicalXMLSerializerInterface. |
protected java.util.Vector |
getOutputAncestors(org.w3c.dom.Element candidate)
Gets all output ancestors of an element node.
|
protected java.util.SortedSet |
getOutputAttrs(org.w3c.dom.Element element)
Gets the list of all attributes to be serialized for the specified element node.
|
protected java.util.SortedSet |
getOutputNSAttrs(org.w3c.dom.Element element)
Gets the list of all namespace attributes to be serialized for the specified element node.
|
protected org.w3c.dom.Element |
getOutputParent(org.w3c.dom.Element candidate)
Gets the output parent of an element node.
|
protected boolean |
isDocumentElement(org.w3c.dom.Element candidate)
Tests if an element node is the document element.
|
protected boolean |
isNSAttribute(org.w3c.dom.Attr candidate)
Tests wheter an attribute node is a namespace node.
|
protected boolean |
isOrphan(org.w3c.dom.Element candidate)
Tests wheter an element node is orphan or not.
|
protected boolean |
isVisiblyUtilized(java.lang.String prefix,
org.w3c.dom.Element element)
Tests if a namespace prefix is visibly utilized by an element.
|
protected boolean |
isXMLAttribute(org.w3c.dom.Attr candidate)
Tests wheter an attribute node is an xml:foo attribute node.
|
java.io.InputStream |
serialize()
Serializes all
Node objects contained by {link #allOutputNodesList_}, according to
the rules of Canonical XML Version 1.0> or
Exclusive XML Canonicalization Version 1.0
. |
protected void |
serialize(org.w3c.dom.Node parent)
Serializes the all children of
parent which are in the output node list. |
protected void |
serializeAttribute(org.w3c.dom.Attr attr)
Serializes the specified DOM Attr node.
|
protected void |
serializeComment(org.w3c.dom.Comment comment)
Serializes the specified DOM Comment node.
|
protected void |
serializeElement(org.w3c.dom.Element element)
Serializes the specified DOM element if it is in the list of output nodes.
|
protected void |
serializeProcessingInstruction(org.w3c.dom.ProcessingInstruction pi)
Serializes the specified DOM ProcessingInstruction node.
|
protected void |
serializeText(org.w3c.dom.Node text)
Serializes the specified DOM Text node.
|
protected static final int BEFORE_DOC_ELEMENT_
protected static final int IN_DOC_ELEMENT_
protected static final int AFTER_DOC_ELEMENT_
public static final int C14N_
public static final int EXCLUSIVE_C14N_
public static final java.lang.String EXC_C14N_DEFAULT_NS_PREFIX_
protected int canonMode_
protected boolean omitComments_
protected org.w3c.dom.NodeList allOutputNodesList_
NodeList.protected java.util.HashMap allOutputNodesMap_
HashMap.protected org.w3c.dom.traversal.NodeIterator allNodesIterator_
protected java.util.Map namespaceAndXMLAxes_
protected int processingPosition_
IN_DOC_ELEMENT_ and AFTER_DOC_ELEMENT_).protected java.io.CharArrayWriter serializationResultSink_
protected java.util.HashMap inclusiveNamespacePrefixMap_
protected CanonicalXMLSerializerImpl(org.w3c.dom.NodeList allOutputNodesList,
int canonMode,
boolean omitComments,
java.lang.String inclusiveNamespacePrefixes)
allOutputNodesList - A list containg objects of type Node, which are to be
serialized. May equal null.
The following node types are allowed:
DocumentElementAttrTextCommentProcessingInstructioncanonMode - Indicates wheter the output has to be canonical XML or exclusive canonical XML (see
C14N_ and EXCLUSIVE_C14N_.inclusiveNamespacePrefixes - Contains the list of namespace prefixes to be treated as described
in Canonical XML. If canonMode equals C14N_
, this parameter must be null. Otherwise it
contains a whitespace seperated list of namespace prefixes. May be
null or an emtpy string.omitComments - Indicates wheter to filter comment nodes or not.public java.io.InputStream serialize()
throws CanonicalXMLSerializerException
Node objects contained by {link #allOutputNodesList_}, according to
the rules of Canonical XML Version 1.0> or
Exclusive XML Canonicalization Version 1.0
.serialize in interface CanonicalXMLSerializerInterfaceserialize in interface ExclusiveCanonicalXMLSerializerInterfacenull
, or if it contains no nodes, an empty octet stream will be returned.CanonicalXMLSerializerException - if there exists a namespace attribute node in the node list,
whose value is a relative URI. Relative namespace URIs are
not allowed according to Canonical XML.public static CanonicalXMLSerializerInterface getCanonicalXMLSerializer(org.w3c.dom.NodeList allOutputNodesList, boolean omitComments)
CanonicalXMLSerializerInterface. See there for
further documentation.allOutputNodesList - See CanonicalXMLSerializerInterface.omitComments - See CanonicalXMLSerializerInterface.CanonicalXMLSerializerInterface.public static ExclusiveCanonicalXMLSerializerInterface getExclusiveCanonicalXMLSerializer(org.w3c.dom.NodeList allOutputNodesList, java.lang.String inclusiveNamespacePrefixes, boolean omitComments)
ExclusiveCanonicalXMLSerializerInterface. See
there for further documentation.allOutputNodesList - See CanonicalXMLSerializerInterface.inclusiveNamespacePrefixes - See CanonicalXMLSerializerInterface.omitComments - See CanonicalXMLSerializerInterface.ExclusiveCanonicalXMLSerializerInterface.protected void serialize(org.w3c.dom.Node parent)
parent which are in the output node list.parent - The parent DOM node, which children are to be serialized. If parent equals
null, all nodes in the output node list will be serialized.protected void serializeElement(org.w3c.dom.Element element)
throws java.io.IOException
element - The DOM element to be serialized if it is in the list of output nodes.java.io.IOException - if writing to the serialization result sink fails.protected void serializeAttribute(org.w3c.dom.Attr attr)
throws java.io.IOException
attr - The DOM Attr node to be serialized.java.io.IOException - if writing to the serialization result sink fails.protected void serializeText(org.w3c.dom.Node text)
throws java.io.IOException
text - The DOM Text node to be serialized.java.io.IOException - if writing to the serialization result sink fails.protected void serializeProcessingInstruction(org.w3c.dom.ProcessingInstruction pi)
throws java.io.IOException
pi - The DOM ProcessingInstruction node to be serialized.java.io.IOException - if writing to the serialization result sink fails.protected void serializeComment(org.w3c.dom.Comment comment)
throws java.io.IOException
comment - The DOM Comment node to be serialized.java.io.IOException - if writing to the serialization result sink fails.protected java.util.SortedSet getOutputAttrs(org.w3c.dom.Element element)
element - The owner of the requested attributes.protected java.util.SortedSet getOutputNSAttrs(org.w3c.dom.Element element)
element - The owner of the requested namespace attributes.protected java.util.Map computeNamespaceAndXMLAxes(org.w3c.dom.Document document)
document - The DOM document for whose elements the sets should be computed.protected boolean isNSAttribute(org.w3c.dom.Attr candidate)
candidate - The attribute node to be tested.true if candidate is a namespace node, false otherwise.protected boolean isXMLAttribute(org.w3c.dom.Attr candidate)
candidate - The attribute node to be tested.true if candidate is an xml:foo attribute node, false otherwise.protected boolean isOrphan(org.w3c.dom.Element candidate)
candidate - The element node to be tested.true if candidate is orphan, false otherwise.protected org.w3c.dom.Element getOutputParent(org.w3c.dom.Element candidate)
candidate - The element node to be investigated.null if candiate has no output parent.protected java.util.Vector getOutputAncestors(org.w3c.dom.Element candidate)
candidate - The element node to be investigated.Vector of all output ancestors of the element node. The first element of
the Vector is the nearest ancestor. The Vector will be
empty, if there are no output ancestors.protected boolean isVisiblyUtilized(java.lang.String prefix,
org.w3c.dom.Element element)
prefix - The prefix to be tested.element - The element to be tested.true, if the element visibly utilizes the prefix, false otherwise.protected boolean isDocumentElement(org.w3c.dom.Element candidate)
candidate - The element node to be tested.true if candidate is the document element, false
otherwise.protected void checkForRelativeNamespaceURIs()
throws CanonicalXMLSerializerException
CanonicalXMLSerializerException - if there exists a namespace attribute node in the node list,
whose value is a relative URI. Relative namespace URIs are
not allowed according to Canonical XML.