public class DOMUtilsImpl extends java.lang.Object implements DOMUtilsInterface
DOMUtilsInterface, which is shipped with the IXSIL toolkit.
This implemenation is based on Apache Xerces 2.4.0.| Modifier and Type | Class and Description |
|---|---|
protected class |
DOMUtilsImpl.DOMUtilsSAXErrorHandler
Implements an
ErrorHandler, adapted for employment in the createDocumentFromXMLInstance(java.io.InputStream, iaik.ixsil.util.URI, int, java.lang.String, java.lang.String) method of the DOM utilities. |
protected class |
DOMUtilsImpl.DOMUtilsXMLErrorHandler
Implements an
XMLErrorHandler, adapted for employment with the XML
signature parser grammarPreparser_ used in method schemaValidateSignatureElement(org.w3c.dom.Element, java.lang.String, java.lang.String). |
protected class |
DOMUtilsImpl.NodeListImpl
Simple implementation for the DOM
NodeList interface. |
| Modifier and Type | Field and Description |
|---|---|
protected static int |
BIG_PRIME_
Used for intiializing the symbol table of various parsers.
|
protected static java.lang.String |
FEATURE_CONTINUE_AFTER_FATALERROR_
Name of the Xerces feature specifying wheter or not continuing after a fatal error has occured.
|
protected static java.lang.String |
FEATURE_CREATE_ENTITY_REF_NODES_
Name of the Xerces feature specifying wheter or not to create entity reference nodes.
|
protected static java.lang.String |
FEATURE_DEFER_NODE_EXPANSION_
Name of the Xerces feature specifying wheter or not to use late node expansion.
|
protected static java.lang.String |
FEATURE_DYNAMIC_VALIDATION_
Name of the Xerces feature specifying dynamic validation depending on the presence of a grammar
specification.
|
protected static java.lang.String |
FEATURE_INCLUDE_IGNORABLE_WHITESPACE_
Name of the Xerces feature specifying wheter or not to include ignorable whitespace text nodes.
|
protected static java.lang.String |
FEATURE_INCLUDE_PSVI_NODES_
Name of the Xerces feature specifying wheter or not to augment Post-Schema-Validation-Infoset.
|
protected static java.lang.String |
FEATURE_SCHEMA_NORMALIZED_VALUES_
Name of the Xerces feature specifying whether Xerces schema-normalizes element and attribute values in
case of validating parsing.
|
protected static java.lang.String |
FEATURE_SCHEMA_VALIDATION_
Name of the Xerces feature specifying explicite validation against an XML Schema, if such a Schema is
present.
|
protected org.apache.xerces.util.XMLGrammarPoolImpl |
grammarPool_
The grammar pool used by grammarPreparser.
|
protected org.apache.xerces.parsers.XMLGrammarPreparser |
grammarPreparser_
The grammar parser used to preparse the XML schemas necessary for validating an XML signature
(see
schemaValidateSignatureElement(org.w3c.dom.Element, java.lang.String, java.lang.String)). |
protected static java.lang.String |
PROPERTY_EXTERNAL_NONAMESPACESCHEMALOCATION_
Name of the property telling the parser the location of the schemas to be used for validation.
|
protected static java.lang.String |
PROPERTY_EXTERNAL_SCHEMALOCATION_
Name of the property telling the parser the location of the no-namespace schema to be used for
validation.
|
protected static java.lang.String |
SAXFEATURE_NAMESPACE_PROCESSING_
Name of the Xerces feature specifying wheter or not to do namespace processing.
|
protected static java.lang.String |
SAXFEATURE_VALIDATION_
Name of the Xerces feature specifying explicite validation against a DTD.
|
| Constructor and Description |
|---|
DOMUtilsImpl()
Standard constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected java.util.List |
addInScopeNSDecls(org.w3c.dom.Element elem)
Checks which namespace declarations are in scope for the specified element and adds a namespace node
for each declaration if the namespace node is not already present in the specified element.
|
boolean |
checkExpandedElementName(org.w3c.dom.Element element,
java.lang.String namespaceURI,
java.lang.String localName)
Checks if the expanded name of the specified element corresponds with the specified namespace URI and
local name.
|
org.w3c.dom.Document |
createDocumentFromScratch()
Creates a new, empty DOM document.
|
org.w3c.dom.Document |
createDocumentFromXMLInstance(java.io.InputStream xmlDocStream,
URI xmlDocBaseURI,
int validate,
java.lang.String noNamespaceSchemaLocation,
java.lang.String schemaLocations)
The DOM parser is configured not to report any Warnings, Errors or FatalErrors.
|
java.lang.String |
getCharacterData(org.w3c.dom.Element parent)
Returns a concatenation of all text children of the specified parent element.
|
org.w3c.dom.Element |
getChildElementByTagNameNS(org.w3c.dom.Element parent,
java.lang.String namespaceURI,
java.lang.String localName,
int instance)
Returns the child element of the specified parent element, which matches the specified namespace URI
and the specified local name.
|
org.w3c.dom.traversal.DocumentTraversal |
getDocumentTraversal(org.w3c.dom.Document doc)
Gets a DOM level 2
DocumentTraversal interface, which allows the creation
of DOM level 2 NodeIterator and TreeWalker
interfaces, for the specified DOM document. |
protected java.util.List |
getInScopeNSDecls(org.w3c.dom.Element elem)
Gets all namespace declarations which are in scope for the specified element.
|
protected java.lang.String |
getNamespaceOfElement(org.w3c.dom.Element element)
Gets the namespace URI which is in scope for the specified element.
|
protected void |
initXMLSigSchemaValidator()
Instantiate and initialize XML signature schema validator.
|
protected boolean |
isValidSchemaLocationsArgument(java.lang.String schemaLocations)
Test if the specified parameter is a valid argument containing schema locations.
|
org.w3c.dom.NodeList |
listToNodeList(java.util.List list)
Converts a
List object into a NodeList object. |
void |
registerID(org.w3c.dom.Document owningDoc,
org.w3c.dom.Element candidate,
java.lang.String idValue)
Registers a candidate DOM element with the value of its ID attribute at its owning DOM document.
|
protected void |
removeAddedNSDecls(org.w3c.dom.Element elem,
java.util.List addedNSDecls)
Removes all namespace nodes part of the specified list (list entries must be of type
Attr) from the specified element. |
void |
replaceSignatureElement(org.w3c.dom.Element oldSigElem,
org.w3c.dom.Element newSigElem)
Replaces an old signature element, which is part of document A, with a new signature element, which
is part of document B.
|
org.w3c.dom.Element |
schemaValidateSignatureElement(org.w3c.dom.Element signatureDOMElem,
java.lang.String additionalNoNamespaceSchemaLocation,
java.lang.String additionalSchemaLocations)
This method uses a parser with a preloaded schema for XML signatures for efficiency reasons.
|
void |
serializeDocument(org.w3c.dom.Document doc,
java.io.OutputStream documentSurface)
Serializes the specified DOM document to the specified output stream.
|
void |
serializeDocument(org.w3c.dom.Document doc,
java.io.OutputStream documentSurface,
java.lang.String xmlEncoding)
Serializes the specified DOM document to the specified output stream using the specified
character encoding.
|
void |
serializeElement(org.w3c.dom.Element elem,
java.io.OutputStream elementSurface)
Serializes the specified DOM element to the specified output stream.
|
void |
setAttribute(org.w3c.dom.Element element,
java.lang.String namespaceURI,
java.lang.String namespacePrefix,
java.lang.String localName,
java.lang.String value)
Creates a DOM attribute from the specified parameters and adds it to the specified DOM element.
|
void |
unregisterID(org.w3c.dom.Document owningDoc,
java.lang.String idValue)
Unregisters a candidate DOM element, which has been registerred with method
DOMUtilsInterface.registerID(org.w3c.dom.Document, org.w3c.dom.Element, java.lang.String) before,
at its owning DOM document. |
protected static final java.lang.String SAXFEATURE_VALIDATION_
protected static final java.lang.String SAXFEATURE_NAMESPACE_PROCESSING_
protected static final java.lang.String FEATURE_SCHEMA_VALIDATION_
protected static final java.lang.String FEATURE_DYNAMIC_VALIDATION_
protected static final java.lang.String FEATURE_SCHEMA_NORMALIZED_VALUES_
protected static final java.lang.String FEATURE_CONTINUE_AFTER_FATALERROR_
protected static final java.lang.String FEATURE_INCLUDE_IGNORABLE_WHITESPACE_
protected static final java.lang.String FEATURE_CREATE_ENTITY_REF_NODES_
protected static final java.lang.String FEATURE_DEFER_NODE_EXPANSION_
protected static final java.lang.String FEATURE_INCLUDE_PSVI_NODES_
protected static final java.lang.String PROPERTY_EXTERNAL_SCHEMALOCATION_
protected static final java.lang.String PROPERTY_EXTERNAL_NONAMESPACESCHEMALOCATION_
protected static final int BIG_PRIME_
protected org.apache.xerces.parsers.XMLGrammarPreparser grammarPreparser_
schemaValidateSignatureElement(org.w3c.dom.Element, java.lang.String, java.lang.String)).protected org.apache.xerces.util.XMLGrammarPoolImpl grammarPool_
public DOMUtilsImpl()
throws DOMUtilsException
DOMUtilsException - if initializing the XML signature schema validator fails.protected void initXMLSigSchemaValidator()
throws DOMUtilsException
schemaValidateSignatureElement(org.w3c.dom.Element, java.lang.String, java.lang.String).DOMUtilsException - If initializing the schema validator fails for any reason.public void serializeDocument(org.w3c.dom.Document doc,
java.io.OutputStream documentSurface)
throws DOMUtilsException
UTF-8.
This method is not part of the DOMUtilsInterface. It is provided for convenience of the
application.
serializeDocument in interface DOMUtilsInterfacedoc - The DOM document to be serialized. Must not be null.documentSurface - The output stream where the serialization result is printed to. Must not be
null.DOMUtilsException - if serialization fails for any reason.public void serializeDocument(org.w3c.dom.Document doc,
java.io.OutputStream documentSurface,
java.lang.String xmlEncoding)
throws DOMUtilsException
This method is not part of the DOMUtilsInterface. It is provided for convenience of the
application.
serializeDocument in interface DOMUtilsInterfacedoc - The DOM document to be serialized. Must not be null.documentSurface - The output stream where the serialization result is printed. Must not be
null.encoding - The character encoding to be used in the serialization.
Must not be null. *DOMUtilsExceptionpublic void serializeElement(org.w3c.dom.Element elem,
java.io.OutputStream elementSurface)
throws DOMUtilsException
UTF-8.
This method is not part of the DOMUtilsInterface. It is provided for convenience of the
application.
serializeElement in interface DOMUtilsInterfaceelem - The DOM element to be serialized. Must not be null.elementSurface - The output stream where the serialization result is printed to. Must not be
null.DOMUtilsException - if serialization fails for any reason.public org.w3c.dom.Element schemaValidateSignatureElement(org.w3c.dom.Element signatureDOMElem,
java.lang.String additionalNoNamespaceSchemaLocation,
java.lang.String additionalSchemaLocations)
throws DOMUtilsException
schemaValidateSignatureElement in interface DOMUtilsInterfacesignatureDOMElem - The signature DOM element to be schema validated. Must not be null
.additionalNoNamespaceSchemaLocation - Provides an additional schema apart from the XMLDSIG schema
for elements in the no-namespace. Such a schema can be pro-
vided for the content of Object or
SignatureProperty elements. The parameter contains
the location URI for such a schema. May be null
.additionalSchemaLocations - Provides additional schemas apart from the XMLDSIG schema to be used
for validation. Such schemas can be provided for the content of
Object or SignatureProperty elements. Must either
be null or conform to the following rules:
additionalSchemas ::= additionalSchema (space additionalSchema)*
additionalSchema ::= schemaNamespaceURI space schemaLocationURI
For example,
"http://foo.org/mySchema http://repository.foo.org/mySchema.xsd".DOMUtilsException - if the validation fails for some reason.DOMUtilsInterface.schemaValidateSignatureElement(org.w3c.dom.Element, java.lang.String, java.lang.String)protected boolean isValidSchemaLocationsArgument(java.lang.String schemaLocations)
schemaLocations - The argument to be tested.true if the argument is valid, false otherwise.public void replaceSignatureElement(org.w3c.dom.Element oldSigElem,
org.w3c.dom.Element newSigElem)
throws DOMUtilsException
DOMUtilsInterfacereplaceSignatureElement in interface DOMUtilsInterfaceoldSigElem - The old Signature DOM element which should be replaced. Must not be null
.newSigElem - The new Signature DOM element which should replace the old one. Must not be
null.DOMUtilsException - if the transfer fails for some reason.DOMUtilsInterface.replaceSignatureElement(org.w3c.dom.Element, org.w3c.dom.Element)public org.w3c.dom.Document createDocumentFromScratch()
DOMUtilsInterfacecreateDocumentFromScratch in interface DOMUtilsInterfaceDOMUtilsInterface.createDocumentFromScratch()public org.w3c.dom.traversal.DocumentTraversal getDocumentTraversal(org.w3c.dom.Document doc)
DOMUtilsInterfaceDocumentTraversal interface, which allows the creation
of DOM level 2 NodeIterator and TreeWalker
interfaces, for the specified DOM document.getDocumentTraversal in interface DOMUtilsInterfacedoc - The DOM document, for which a DocumentTraversal should be
returned. Must be an instance of DocumentImpl.DOMUtilsInterface.getDocumentTraversal(org.w3c.dom.Document)public org.w3c.dom.Document createDocumentFromXMLInstance(java.io.InputStream xmlDocStream,
URI xmlDocBaseURI,
int validate,
java.lang.String noNamespaceSchemaLocation,
java.lang.String schemaLocations)
throws DOMUtilsException
createDocumentFromXMLInstance in interface DOMUtilsInterfacexmlDocStream - The stream representation of the XML document.xmlDocBaseURI - Holds the base URI for the XML document used to resolve relative URIs.validate - Determines wheter the document should be validated or not. Please see the constants
DOMUtils.VALIDATION_YES_, DOMUtils.VALIDATION_NO_, DOMUtils.VALIDATION_DYNAMIC_ for further information.noNamespaceSchemaLocation - This URI string can be used to provide a Schema for the no-namespace
in cases where the DOM document should be created by a validating
parser (see also parameter validate). May be null
. Valid example: "http://repository.foo.org/mySchema.xsd".schemaLocations - This parameter can be used to provide schemas for various namespaces in cases
where the DOM document should be created by a validating parser (see also
parameter validate). Must either be null or conform
to the following rules:
additionalSchemas ::= additionalSchema (space additionalSchema)*
additionalSchema ::= schemaNamespaceURI space schemaLocationURI
For example, "http://foo.org/mySchema http://repository.foo.org/mySchema.xsd".DOMUtilsException - if creating the DOM document failed for any reason.DOMUtilsInterface.createDocumentFromXMLInstance(java.io.InputStream, iaik.ixsil.util.URI, int, java.lang.String, java.lang.String)public org.w3c.dom.Element getChildElementByTagNameNS(org.w3c.dom.Element parent,
java.lang.String namespaceURI,
java.lang.String localName,
int instance)
DOMUtilsInterfacegetChildElementByTagNameNS in interface DOMUtilsInterfaceparent - The parent element bearing the requested child element. Must not be null.namespaceURI - The namespace URI of the requested child element. May be null to
indicate that the attribute should be in no namespace.localName - The local name of the requested child element. Must not be null.instance - A value of i will return the (i)th occurence of the requested element in the parent
element. Must be greater than or equal to 1.null if there is no such child element.DOMUtilsInterface.getChildElementByTagNameNS(Element, String, String, int)public java.lang.String getCharacterData(org.w3c.dom.Element parent)
DOMUtilsInterfacegetCharacterData in interface DOMUtilsInterfaceparent - The parent element.null, if
the element does not contain any text children or if all text children represent text with zero
length.DOMUtilsInterface.getCharacterData(org.w3c.dom.Element)public boolean checkExpandedElementName(org.w3c.dom.Element element,
java.lang.String namespaceURI,
java.lang.String localName)
DOMUtilsInterfacecheckExpandedElementName in interface DOMUtilsInterfaceelement - The candidate element. Must not be null.namespaceURI - The namespace URI part of the expanded name. May be null if the
candidate element should be in no namespace.localName - The local name part of the expanded name. Must not be null.true, if the expanded name of the specified element corresponds with the
specified namespace URI and local name; false otherwise.DOMUtilsInterface.checkExpandedElementName(Element, String, String)public void setAttribute(org.w3c.dom.Element element,
java.lang.String namespaceURI,
java.lang.String namespacePrefix,
java.lang.String localName,
java.lang.String value)
DOMUtilsInterfacevalue parameter
equals null, the possibly existing DOM attribute will be removed from the DOM element.setAttribute in interface DOMUtilsInterfaceelement - The DOM element, which will become the owner of the new DOM attribute. Must not be
null.namespaceURI - The namespace URI for the attribute. May be null to indicate that the
attribute should be in no namespace.namespacePrefix - The namespace prefix for the attribute (including the final colon). Must not be
null. Use an empty string to indicate that no namespace prefix
should be used.localName - The local name for the attribute. Must not be null.value - The value for the attribute. May be null to indicate that the specified
DOM attribute should be removed from the specified DOM element.DOMUtilsInterface.setAttribute(Element, String, String, String, String)public org.w3c.dom.NodeList listToNodeList(java.util.List list)
DOMUtilsInterfaceList object into a NodeList object.listToNodeList in interface DOMUtilsInterfacelist - A List object constisting purely of Node objects.NodeList containing the specified nodes as member, or an empty NodeList if the specified List equals null.DOMUtilsInterface.listToNodeList(java.util.List)public void registerID(org.w3c.dom.Document owningDoc,
org.w3c.dom.Element candidate,
java.lang.String idValue)
throws DOMUtilsException
DOMUtilsInterfaceDocument.getElementById(java.lang.String). If a DOM element is already registerred under the
specified ID value, this method will have no effect.registerID in interface DOMUtilsInterfaceowningDoc - The DOM document which owns the candidate DOM element. Must not be null.candidate - The candidate DOM element to be registerred. Must not be null.idValue - The value of the candidate's ID attribute. Must not be null.DOMUtilsException - if registration fails for any reason.DOMUtilsInterface.registerID(org.w3c.dom.Document, org.w3c.dom.Element, java.lang.String)public void unregisterID(org.w3c.dom.Document owningDoc,
java.lang.String idValue)
throws DOMUtilsException
DOMUtilsInterfaceDOMUtilsInterface.registerID(org.w3c.dom.Document, org.w3c.dom.Element, java.lang.String) before,
at its owning DOM document. If no DOM element is registerred under the specified ID value at the DOM
document, this method will have no effect.unregisterID in interface DOMUtilsInterfaceowningDoc - The DOM document which owns the candidate DOM element. Must not be null.idValue - The value of the candidate's ID attribute. Must not be null.DOMUtilsException - if undoing the registration fails for any reason.DOMUtilsInterface.unregisterID(org.w3c.dom.Document, java.lang.String)protected java.lang.String getNamespaceOfElement(org.w3c.dom.Element element)
element - The element for which the namespace URI should be detected. Must not be null
.null, if no namespace attribute has been found, or if a
namespace attribute has been found, but its value is an empty string.protected java.util.List addInScopeNSDecls(org.w3c.dom.Element elem)
elem - The element to be checked.Attr).protected void removeAddedNSDecls(org.w3c.dom.Element elem,
java.util.List addedNSDecls)
Attr) from the specified element. If the list contains a node which is not in the
element, it will be ignored.elem - The element to be checked.addedNSDecls - The list of namespace nodes to be removed from the element.protected java.util.List getInScopeNSDecls(org.w3c.dom.Element elem)
elem - The element to be checked.Attr.