Skip navigation links

Oracle Fusion Middleware XML Security Java API Reference for Oracle Security Developer Tools
11g Release 1 (11.1.1)

E10680-04


oracle.security.xmlsec.util
Class XMLUtils

java.lang.Object
  extended by oracle.security.xmlsec.util.XMLUtils


public class XMLUtils
extends java.lang.Object

Class containing static utility methods for XML and XML-DSIG.


Field Summary
static java.lang.String PROPERTY_ALLOW_ALL
           
static java.lang.String PROPERTY_ALLOW_EXTERNAL_REF
           
static java.lang.String PROPERTY_ALLOW_RETRIEVAL_METHOD
           
static java.lang.String PROPERTY_ALLOW_UNVALIDATED_CERT
           
static java.lang.String PROPERTY_ALLOW_XSLT_TRANSFORM
           
static java.lang.String PROPERTY_C14N_NS_FILTERED_OUT
           
static java.lang.String PROPERTY_C14N_PARSER
           
static java.lang.String PROPERTY_C14N_SPARSE_THRESHOLD
           
static java.lang.String PROPERTY_DEBUG_VERIFY
           
static java.lang.String PROPERTY_DISABLE_ID_CACHING
           
static java.lang.String PROPERTY_MAX_TRANSFORMS
           
static java.lang.String PROPERTY_USE_EXPLICIT_C14N11
           
static java.lang.String PROPERTY_USE_JSR105
           
static java.lang.String PROPERTY_USE_JSR106
           
static java.lang.String PROPERTY_USE_MTOM
           
static java.lang.String PROPERTY_USE_OLD_C14N
           

 

Constructor Summary
XMLUtils()
           

 

Method Summary
static void addIdAttribute(java.lang.String namespaceURI, java.lang.String attrName)
          Sets the namespace in which a given attribute is defined as being of type ID.
static java.lang.String canonicalize(java.util.Collection nodeSet, boolean withComments)
          Applies Canonical XML to the input node-set.
static java.lang.String canonicalize(org.w3c.dom.Node input, boolean withComments)
          Applies Canonical XML to the input sub-tree rooted in the given Node.
static java.lang.String canonicalize(org.w3c.dom.NodeList input, boolean withComments)
          Applies Canonical XML to the input NodeList.
static java.lang.String collectText(org.w3c.dom.Node node)
          Collects all of a node's text-node children into a single string.
static void computeAncestors(org.w3c.dom.Node node, java.util.ArrayList lastNodeAncestors)
          Efficiently computes the ancestors of a given Node.
static void copyNSPrefix(org.w3c.dom.Element source, org.w3c.dom.Element target)
          Propagates the given source element tag name's namespace prefix to the given target element, if both elements have the same namespace URI and the source prefix is not null or empty.
static javax.xml.parsers.DocumentBuilder createDocBuilder()
          Returns a new javax.xml.parsers.DocumentBuilder instance with the NamespaceAware property set to true.
static org.w3c.dom.Document createDocument()
          Returns a new org.w3c.dom.Document instance.
static org.w3c.dom.Element createElement(org.w3c.dom.Document doc, java.lang.String tag, java.lang.String nsURI, java.lang.String prefix)
           
static org.jaxen.NamespaceContext createNamespaceContext(org.w3c.dom.Node nsContextNode)
          Creates a jaxen XPath namespace context containing the prefix mappings in scope for the given node.
static javax.xml.transform.Transformer createTransformer()
          Deprecated. Use createTransformer(Node)
static javax.xml.transform.Transformer createTransformer(org.w3c.dom.Node n)
          Return a new identity transformer which can transform nodes of type n
static javax.xml.transform.Transformer createTransformer(org.w3c.dom.Node n, javax.xml.transform.Source s)
          Create a transformer for stylesheet s which has to transform nodes of type n
static javax.xml.transform.Transformer createTransformer(javax.xml.transform.Source s)
          Create a transformer for stylesheet s
static byte[] decodeDEROctets(byte[] der)
           
static java.lang.String escapeTextNode(java.lang.String text)
          Escapes XML text characters - &, < > \r
static java.lang.String fixURL(java.lang.String urlStr)
          Expands a relative URL to an absolute URL using the "file" protocol and the file-system current directory path.
static java.lang.String fixURL(java.lang.String urlStr, java.lang.String systemId)
          Expands a relative URL to an absolute URL using the given document base URL.
static java.lang.String formatDate(java.util.Date date)
          Formats a date as a String in UTC format.
static java.lang.String formatDateTime(java.util.Date date)
          Formats a date and time as a String in UTC format.
static java.lang.String formatTime(java.util.Date date)
          Formats a time as a String in UTC format.
static boolean getAllowAllFlag()
           
static boolean getAllowRetrievalMethodFlag()
           
static boolean getAllowUnvalidatedCertFlag()
           
static java.util.Map<java.lang.String,java.lang.String> getAncestorNamespaces(org.w3c.dom.Element elem)
          get the namespace of all the ancestor elements, includes namespaces of current element too
static java.lang.String getAttributeValue(org.w3c.dom.Element elem, java.lang.String name)
           
static org.jaxen.dom.DocumentNavigator getDocumentNavigator()
           
static org.w3c.dom.Element getElementById(org.w3c.dom.Document doc, java.lang.String id)
          Resolves an ID attribute value to an element.
static boolean getExternalRefFlag()
           
static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node)
           
static java.util.ArrayList getIdAttributes(java.lang.String namespaceURI)
          Returns the list of attributes defined as type ID for the given namespace.
static java.util.Map getIdAttributesMap()
          return a map namespaceURI to IdAttributes list
static java.lang.String getIdFromURI(java.lang.String uri)
          Extracts the ID from a same-document URI.
static XMLElement getInstance(java.util.Collection nodes, java.lang.String tag, java.lang.String ns)
          Creates a new instance of the implementation class for the given tag name, and uses it to wrap the first Element in the input node set with that tag.
static XMLElement getInstance(org.w3c.dom.Element element)
          Creates a new instance of the implementation class for the given Element.
static XMLElement getInstance(org.w3c.dom.Element element, java.lang.String tag)
          Creates a new instance of the implementation class for the given tag name, and uses it to wrap the Element.
static XMLElement getInstance(org.w3c.dom.Element element, java.lang.String tag, java.lang.String ns)
          Creates a new instance of the implementation class for the given tag name, and uses it to wrap the Element.
static XMLElement getInstance(org.w3c.dom.NodeList nodes, java.lang.String tag, java.lang.String ns)
          Creates a new instance of the implementation class for the given tag name, and uses it to wrap the first Element in the input node list with that tag.
static int getMaxTrans()
           
static java.lang.String getNamespaceURI(org.w3c.dom.Node node)
          Returns the namespace URI that is in scope for the given node's namespace prefix, as per the XPath data model.
static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node node)
           
static java.lang.String getNodeTypeName(org.w3c.dom.Node node)
          Returns a string describing the given DOM node's type.
static java.lang.String getNodeTypeName(short type)
          Returns a string describing the given DOM node type.
static org.w3c.dom.Document getOwnerDocument(org.w3c.dom.Node node)
          Returns the given node's owner document, even if the node is a Document node.
static java.lang.String getProperty(java.lang.String name)
          Get various properties that affects XMLSEC behaviour.
static byte[] getSKI(java.security.cert.X509Certificate cert)
           
static org.w3c.dom.Node getXPathParentNode(org.w3c.dom.Node node)
          return the Parent node according to XPath model.
static boolean getXSLTFlag()
           
static java.util.Enumeration idAttributeNamespaces()
          Returns a list of namespace URIs for which ID attributes have been mapped.
static void indent(org.w3c.dom.Element elem, java.lang.String indent)
          Insert text nodes in between elements to indent a DOM node
static void insertChild(org.w3c.dom.Element parent, org.w3c.dom.Element child, java.lang.String[] namespaces, java.lang.String[] localNames)
          Inserts a child element in the correct position relative to the given lists of child element types.
static void insertChild(org.w3c.dom.Element parent, org.w3c.dom.Element child, java.lang.String[] ns, java.lang.String[] tag, int pos)
          Inserts a child element in the correct position relative to the given lists of child element types.
static void insertChild(XMLElement parent, XMLElement child, java.lang.String[] namespaces, java.lang.String[] localNames)
          Inserts a child element in the correct position relative to the given lists of child element types.
static void insertChild(XMLElement parent, XMLElement child, java.lang.String[] ns, java.lang.String[] tag, int pos)
          Inserts a child element in the correct position relative to the given lists of child element types.
static java.lang.String joinXmlBaseURI(java.util.ArrayList xmlBaseUriList)
          FOR INTERNAL USE ONLY.
static java.util.Date parseDateTime(java.lang.String s)
          Parses a date String.
static java.lang.String randomName()
          Generates a random string, suitable for use as a namespace prefix or other XML name where accidental collisions are to be avoided.
static byte[] readBytes(java.io.InputStream is)
          Reads the contents of the given InputStream and returns a newly allocated byte array.
static byte[] readBytes(java.net.URL url)
          Reads the bytes from the given URL.
static java.lang.String readString(java.io.Reader reader)
          Returns the contents of the given java.io.Reader as a string.
static void removeAllChildren(org.w3c.dom.Node node)
           
static void removeChildren(org.w3c.dom.Element parent, java.lang.String ns, java.lang.String tag)
          Removes any child elements with the given tag and namespace.
static java.lang.String removeDotSegments(java.lang.String inp)
          FOR INTERNAL USE ONLY.
static java.lang.String removeWhiteSpaces(java.lang.String str)
           
static java.lang.String resolveNSPrefix(java.lang.String prefix, org.w3c.dom.Node context)
          Returns the namespace URI that is in scope for the given namespace prefix and context node.
static java.lang.Object resolveReference(ObjectReference ref)
          Find out what the reference is pointing to by performing all transforms, except the canonicalization ones.
static java.util.List resolveReferences(XSSignature sig)
          Calls @link #resolveReference(ObjectReference) for each references in a signature and puts them into a list
static void setProperty(java.lang.String name, java.lang.String value)
          Set various properties that affects XMLSEC behaviour.
static java.lang.String stripWS(java.lang.String s)
          Strips whitespace from the given string.
static byte[] toBytesXML(org.w3c.dom.Node node, boolean indent, boolean xmlDecl)
          Returns a byte array containing the XML for the given org.w3c.dom.Node.
static byte[] toBytesXML(XMLNode xmlNode, boolean indent, boolean xmlDecl)
          Returns a byte array containing the XML for the given oracle.security.xmlsec.XMLNode.
static java.util.List toDocumentOrderList(java.util.Collection nodes)
          Returns a new list containing the given nodes sorted into document order.
static void toStreamXML(java.io.OutputStream os, org.w3c.dom.Node node, boolean indent, boolean xmlDecl)
          Writes the bytes of the XML for the given org.w3c.dom.Node to the given stream.
static void toStreamXML(java.io.OutputStream os, XMLNode xmlNode, boolean indent, boolean xmlDecl)
          Writes the bytes of the XML for the given oracle.security.xmlsec.XMLNode to the given stream.
static java.lang.String toStringNode(org.w3c.dom.Node node)
          Returns a string representation of the given DOM node (not XML).
static java.lang.String toStringNodes(java.util.Collection c)
           
static java.lang.String toStringXML(java.util.Collection c, boolean generateDummyRoot)
          Returns a string containing the XML for a Collection of Nodes.
static java.lang.String toStringXML(org.w3c.dom.Node node, boolean indent, boolean xmlDecl)
          Returns a string containing the XML for the given org.w3c.dom.Node.
static java.lang.String toStringXML(XMLNode xmlNode, boolean indent, boolean xmlDecl)
          Returns a string containing the XML for the given oracle.security.xmlsec.XMLNode.
static java.net.URI transformReference(java.net.URI Base, java.net.URI R)
          FOR INTERNAL USE ONLY.

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Field Detail

PROPERTY_USE_JSR105

public static final java.lang.String PROPERTY_USE_JSR105
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_USE_JSR106

public static final java.lang.String PROPERTY_USE_JSR106
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_USE_OLD_C14N

public static final java.lang.String PROPERTY_USE_OLD_C14N
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_C14N_NS_FILTERED_OUT

public static final java.lang.String PROPERTY_C14N_NS_FILTERED_OUT
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_C14N_PARSER

public static final java.lang.String PROPERTY_C14N_PARSER
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_C14N_SPARSE_THRESHOLD

public static final java.lang.String PROPERTY_C14N_SPARSE_THRESHOLD
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_USE_MTOM

public static final java.lang.String PROPERTY_USE_MTOM
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_DEBUG_VERIFY

public static final java.lang.String PROPERTY_DEBUG_VERIFY
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_USE_EXPLICIT_C14N11

public static final java.lang.String PROPERTY_USE_EXPLICIT_C14N11
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_MAX_TRANSFORMS

public static final java.lang.String PROPERTY_MAX_TRANSFORMS
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_ALLOW_EXTERNAL_REF

public static final java.lang.String PROPERTY_ALLOW_EXTERNAL_REF
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_ALLOW_XSLT_TRANSFORM

public static final java.lang.String PROPERTY_ALLOW_XSLT_TRANSFORM
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_ALLOW_ALL

public static final java.lang.String PROPERTY_ALLOW_ALL
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_ALLOW_UNVALIDATED_CERT

public static final java.lang.String PROPERTY_ALLOW_UNVALIDATED_CERT
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_ALLOW_RETRIEVAL_METHOD

public static final java.lang.String PROPERTY_ALLOW_RETRIEVAL_METHOD
See Also:
setProperty(String, String), Constant Field Values

PROPERTY_DISABLE_ID_CACHING

public static final java.lang.String PROPERTY_DISABLE_ID_CACHING
See Also:
setProperty(String, String), Constant Field Values

Constructor Detail

XMLUtils

public XMLUtils()

Method Detail

getMaxTrans

public static int getMaxTrans()

getXSLTFlag

public static boolean getXSLTFlag()

getExternalRefFlag

public static boolean getExternalRefFlag()

getAllowUnvalidatedCertFlag

public static boolean getAllowUnvalidatedCertFlag()

getAllowRetrievalMethodFlag

public static boolean getAllowRetrievalMethodFlag()

getAllowAllFlag

public static boolean getAllowAllFlag()

createDocBuilder

public static javax.xml.parsers.DocumentBuilder createDocBuilder()
Returns a new javax.xml.parsers.DocumentBuilder instance with the NamespaceAware property set to true.

createDocument

public static org.w3c.dom.Document createDocument()
Returns a new org.w3c.dom.Document instance.

createTransformer

public static javax.xml.transform.Transformer createTransformer(org.w3c.dom.Node n)
Return a new identity transformer which can transform nodes of type n
Parameters:
n - a sample node which this transformer will be asked to transform
Returns:

createTransformer

public static javax.xml.transform.Transformer createTransformer()
Deprecated. Use createTransformer(Node)
Returns a new javax.xml.transform.Transformer instance ('identity' transformer).

createTransformer

public static javax.xml.transform.Transformer createTransformer(javax.xml.transform.Source s)
Create a transformer for stylesheet s
Parameters:
s -
Returns:

createTransformer

public static javax.xml.transform.Transformer createTransformer(org.w3c.dom.Node n,
                                                                javax.xml.transform.Source s)
Create a transformer for stylesheet s which has to transform nodes of type n
Parameters:
n -
s -
Returns:

getNodeTypeName

public static java.lang.String getNodeTypeName(short type)
Returns a string describing the given DOM node type.

getNodeTypeName

public static java.lang.String getNodeTypeName(org.w3c.dom.Node node)
Returns a string describing the given DOM node's type.

getOwnerDocument

public static org.w3c.dom.Document getOwnerDocument(org.w3c.dom.Node node)
Returns the given node's owner document, even if the node is a Document node.
Since:
2.0

toStringNode

public static java.lang.String toStringNode(org.w3c.dom.Node node)
Returns a string representation of the given DOM node (not XML).
Since:
2.0

toStringNodes

public static java.lang.String toStringNodes(java.util.Collection c)

getXPathParentNode

public static org.w3c.dom.Node getXPathParentNode(org.w3c.dom.Node node)
return the Parent node according to XPath model. Unlike DOM, in XPath an Attribute's parent is its owner element
Parameters:
node -
Returns:

computeAncestors

public static void computeAncestors(org.w3c.dom.Node node,
                                    java.util.ArrayList lastNodeAncestors)
Efficiently computes the ancestors of a given Node. Uses the ancestors of the last node, so if this node is in the same level or one level above/below the last node, it doesn't have to walk up the whole ancestor hierarchy.
Parameters:
node -
lastNodeAncestors - The last node and all its ancestors in document order. i.e. lastNodeAncestors[i] is the parent of lastNodeAncestors[i+1]

toStringXML

public static java.lang.String toStringXML(java.util.Collection c,
                                           boolean generateDummyRoot)
                                    throws javax.xml.transform.TransformerException
Returns a string containing the XML for a Collection of Nodes. The Collection's iterator must return nodes in "document order"
Parameters:
c - Collection of Nodes in document order
generateDummyRoot - set this to true if there is more than one tree, a dummy root element will be generated to contain these subtrees
Returns:
Throws:
javax.xml.transform.TransformerException

toStringXML

public static java.lang.String toStringXML(XMLNode xmlNode,
                                           boolean indent,
                                           boolean xmlDecl)
                                    throws javax.xml.transform.TransformerException
Returns a string containing the XML for the given oracle.security.xmlsec.XMLNode.
Parameters:
node - The XMLNode to serialize to a string.
indent - If true, element tags will begin on new lines in the output.
xmlDecl - If true, an XML declaration will be prepended to the output.
Throws:
javax.xml.transform.TransformerException - If the DOM subtree rooted in this XMLNode cannot be serialized to a character stream.

toStringXML

public static java.lang.String toStringXML(org.w3c.dom.Node node,
                                           boolean indent,
                                           boolean xmlDecl)
                                    throws javax.xml.transform.TransformerException
Returns a string containing the XML for the given org.w3c.dom.Node.
Parameters:
node - The Node to serialize to a string.
indent - If true, element tags will begin on new lines in the output.
xmlDecl - If true, an XML declaration will be prepended to the output.
Throws:
javax.xml.transform.TransformerException - If the DOM subtree rooted in this Node cannot be serialized to a character stream.

toBytesXML

public static byte[] toBytesXML(XMLNode xmlNode,
                                boolean indent,
                                boolean xmlDecl)
                         throws javax.xml.transform.TransformerException
Returns a byte array containing the XML for the given oracle.security.xmlsec.XMLNode.
Parameters:
node - The XMLNode to serialize to a byte array.
indent - If true, element tags will begin on new lines in the output.
xmlDecl - If true, an XML declaration will be prepended to the output.
Throws:
javax.xml.transform.TransformerException - If the DOM subtree rooted in the given XMLNode cannot be serialized to a byte stream.

toBytesXML

public static byte[] toBytesXML(org.w3c.dom.Node node,
                                boolean indent,
                                boolean xmlDecl)
                         throws javax.xml.transform.TransformerException
Returns a byte array containing the XML for the given org.w3c.dom.Node.
Parameters:
node - The Node to serialize to a byte array.
indent - If true, element tags will begin on new lines in the output.
xmlDecl - If true, an XML declaration will be prepended to the output.
Throws:
javax.xml.transform.TransformerException - If the DOM subtree rooted in the given Node cannot be serialized to a byte stream.

toStreamXML

public static void toStreamXML(java.io.OutputStream os,
                               XMLNode xmlNode,
                               boolean indent,
                               boolean xmlDecl)
                        throws javax.xml.transform.TransformerException,
                               java.io.IOException
Writes the bytes of the XML for the given oracle.security.xmlsec.XMLNode to the given stream.
Parameters:
os - The OutputStream to which the XML will be written.
node - The XMLNode to serialize to the stream.
indent - If true, element tags will begin on new lines in the output.
xmlDecl - If true, an XML declaration will be prepended to the output.
Throws:
javax.xml.transform.TransformerException - If the DOM subtree rooted in the given XMLNode cannot be serialized to a byte stream.
java.io.IOException
Since:
2.2

toStreamXML

public static void toStreamXML(java.io.OutputStream os,
                               org.w3c.dom.Node node,
                               boolean indent,
                               boolean xmlDecl)
                        throws javax.xml.transform.TransformerException,
                               java.io.IOException
Writes the bytes of the XML for the given org.w3c.dom.Node to the given stream.
Parameters:
os - The OutputStream to which the XML will be written.
node - The Node to serialize to the stream.
indent - If true, element tags will begin on new lines in the output.
xmlDecl - If true, an XML declaration will be prepended to the output.
Throws:
javax.xml.transform.TransformerException - If the DOM subtree rooted in the given XMLNode cannot be serialized to a byte stream.
java.io.IOException
Since:
2.1 Build C

readString

public static java.lang.String readString(java.io.Reader reader)
                                   throws java.io.IOException
Returns the contents of the given java.io.Reader as a string.
Throws:
java.io.IOException

readBytes

public static byte[] readBytes(java.io.InputStream is)
                        throws java.io.IOException
Reads the contents of the given InputStream and returns a newly allocated byte array.
Throws:
java.io.IOException

readBytes

public static byte[] readBytes(java.net.URL url)
                        throws java.io.IOException
Reads the bytes from the given URL. An protocol stream handler appropriate to the URL must be available to the JVM.
Throws:
java.io.IOException

stripWS

public static java.lang.String stripWS(java.lang.String s)
Strips whitespace from the given string.

toDocumentOrderList

public static java.util.List toDocumentOrderList(java.util.Collection nodes)
Returns a new list containing the given nodes sorted into document order.
See Also:
DocOrderComparator

getInstance

public static XMLElement getInstance(org.w3c.dom.NodeList nodes,
                                     java.lang.String tag,
                                     java.lang.String ns)
Creates a new instance of the implementation class for the given tag name, and uses it to wrap the first Element in the input node list with that tag.
Parameters:
nodes - The NodeList containing the element to be wrapped.
tag - The tag name to look for.
ns - The namespace in which tag is defined.
Returns:
An instance of a subclass of XMLElement, or null if a corresponding implementation class cannot be identified or instantiated.
Since:
1.3

getInstance

public static XMLElement getInstance(java.util.Collection nodes,
                                     java.lang.String tag,
                                     java.lang.String ns)
Creates a new instance of the implementation class for the given tag name, and uses it to wrap the first Element in the input node set with that tag.
Parameters:
nodes - The java.util.Collection containing the element to be wrapped.
tag - The tag name to look for.
ns - The namespace in which tag is defined.
Returns:
An instance of a subclass of XMLElement, or null if a corresponding implementation class cannot be identified or instantiated.
Since:
2.0

getInstance

public static XMLElement getInstance(org.w3c.dom.Element element,
                                     java.lang.String tag,
                                     java.lang.String ns)
Creates a new instance of the implementation class for the given tag name, and uses it to wrap the Element. The namespace is taken from the given Element.
Parameters:
element - The element to be wrapped.
tag - The tag name to look for; if null, the tag will be taken from the element (or its xsi:type attribute).
ns - The namespace in which tag is defined; if null, the namespace will be taken from the element.
Returns:
An instance of a subclass of XMLElement, or null if a corresponding implementation class cannot be identified or instantiated.
Since:
1.3

getInstance

public static XMLElement getInstance(org.w3c.dom.Element element,
                                     java.lang.String tag)
Creates a new instance of the implementation class for the given tag name, and uses it to wrap the Element. The namespace is taken from the given Element.
Parameters:
element - The element to be wrapped.
tag - The tag name to look for; if null, the tag will be taken from the element.
Returns:
An instance of a subclass of XMLElement, or null if a corresponding implementation class cannot be identified or instantiated.

getInstance

public static XMLElement getInstance(org.w3c.dom.Element element)
Creates a new instance of the implementation class for the given Element. The tag name and namespace are taken from the Element (or its xsi:type attribute).
Parameters:
element - The element to be wrapped.
Returns:
An instance of a subclass of XMLElement, or null if a corresponding implementation class cannot be identified or instantiated.
Since:
2.1

copyNSPrefix

public static void copyNSPrefix(org.w3c.dom.Element source,
                                org.w3c.dom.Element target)
                         throws org.w3c.dom.DOMException
Propagates the given source element tag name's namespace prefix to the given target element, if both elements have the same namespace URI and the source prefix is not null or empty.
Parameters:
source - The Element from which the namespace prefix will be taken.
target - The Element to which the source's namespace prefix will be given.
Throws:
org.w3c.dom.DOMException

canonicalize

public static java.lang.String canonicalize(org.w3c.dom.Node input,
                                            boolean withComments)
                                     throws CanonicalizationException
Applies Canonical XML to the input sub-tree rooted in the given Node.
Parameters:
input - The root Node of the sub-tree to be canonicalized.
withComments - If true, comments will be preserved, otherwise they will be removed.
Returns:
The XML string obtained by canonicalizing the input sub-tree.
Throws:
CanonicalizationException

canonicalize

public static java.lang.String canonicalize(org.w3c.dom.NodeList input,
                                            boolean withComments)
                                     throws CanonicalizationException
Applies Canonical XML to the input NodeList.
Parameters:
input - The NodeList to be canonicalized.
withComments - If true, comments will be preserved, otherwise they will be removed.
Returns:
The XML string obtained by canonicalizing the input NodeList.
Throws:
CanonicalizationException

canonicalize

public static java.lang.String canonicalize(java.util.Collection nodeSet,
                                            boolean withComments)
                                     throws CanonicalizationException
Applies Canonical XML to the input node-set.
Parameters:
nodeSet - The node-set to be canonicalized.
withComments - If true, comments will be preserved, otherwise they will be removed.
Returns:
The XML string obtained by canonicalizing the input NodeSet.
Throws:
CanonicalizationException
Since:
2.0

randomName

public static java.lang.String randomName()
Generates a random string, suitable for use as a namespace prefix or other XML name where accidental collisions are to be avoided.

Note: The source of randomness used for this method is not cryptographically secure, so the results should not be used as key or seed material for any cryptographic operation.

Returns:
A random name string, specifically: 16 random bytes, base 64-encoded, with '+', '/' and '=' replaced with '1', '2', and '3', respectively.

fixURL

public static java.lang.String fixURL(java.lang.String urlStr,
                                      java.lang.String systemId)
Expands a relative URL to an absolute URL using the given document base URL.
Parameters:
urlStr - A relative URL string.
systemId - The base URL for the given relative URL. If systemId is null, the absolute URL will use the "file" protocol and the file-system current directory path.
Returns:
An absolute URL string for urlStr, based on systemId. If urlStr is already expanded, or if it or systemId is invalid, urlStr is returned unaltered.
Since:
2.0

fixURL

public static java.lang.String fixURL(java.lang.String urlStr)
Expands a relative URL to an absolute URL using the "file" protocol and the file-system current directory path.
Parameters:
urlStr - A URL string.
Returns:
The URL string with "file://" and the file-system current directory path prepended if the input URL is missing the protocol scheme. If the current directory cannot be obtained, or urlStr is invalid, then urlStr is returned unaltered.
Since:
1.2

getIdFromURI

public static java.lang.String getIdFromURI(java.lang.String uri)
Extracts the ID from a same-document URI.
Parameters:
uri - The URI string containing the ID.
Returns:
The ID string contained in the URI, or null if none could be found.
Since:
1.2

getElementById

public static org.w3c.dom.Element getElementById(org.w3c.dom.Document doc,
                                                 java.lang.String id)
Resolves an ID attribute value to an element.
Parameters:
doc - The Document to search.
id - The ID attribute value to resolve.
Returns:
The Element with the ID attribute value given by id, or null if none could be located in doc.
Since:
1.2

addIdAttribute

public static void addIdAttribute(java.lang.String namespaceURI,
                                  java.lang.String attrName)
Sets the namespace in which a given attribute is defined as being of type ID.
Parameters:
namespaceURI - The URI identifying the namespace in which the attribute is defined with ID type.
attrName - The local name of the ID attribute.
Since:
1.2
See Also:
getIdAttributes(java.lang.String)

idAttributeNamespaces

public static java.util.Enumeration idAttributeNamespaces()
Returns a list of namespace URIs for which ID attributes have been mapped.
Since:
1.2

getIdAttributes

public static java.util.ArrayList getIdAttributes(java.lang.String namespaceURI)
Returns the list of attributes defined as type ID for the given namespace.
Parameters:
namespaceURI - The URI identifying the namespace in which the attributes are defined with ID type.
Returns:
A java.util.ArrayList containing any attribute names defined to be of type ID in the given namespace.
Since:
1.2
See Also:
addIdAttribute(java.lang.String, java.lang.String)

getIdAttributesMap

public static java.util.Map getIdAttributesMap()
return a map namespaceURI to IdAttributes list
Returns:
Map<String, ArrayList<String>>

formatDate

public static java.lang.String formatDate(java.util.Date date)
Formats a date as a String in UTC format.
Parameters:
date - The Date to parse.
Returns:
A String representation of the UTC date.
Since:
1.3

formatTime

public static java.lang.String formatTime(java.util.Date date)
Formats a time as a String in UTC format.
Parameters:
time - The Date to parse.
Returns:
A String representation of the UTC time.
Since:
1.3

formatDateTime

public static java.lang.String formatDateTime(java.util.Date date)
Formats a date and time as a String in UTC format.
Parameters:
time - The Date to parse.
Returns:
A String representation of the UTC date and time.
Since:
1.3

parseDateTime

public static java.util.Date parseDateTime(java.lang.String s)
Parses a date String.
Parameters:
s - The String to parse.
Returns:
A Date object.
Since:
1.3

collectText

public static java.lang.String collectText(org.w3c.dom.Node node)
Collects all of a node's text-node children into a single string.
Parameters:
node - The node whose text-node children are to be concatenated.
Returns:
The concatenation of all of node's text-node children's values.
Since:
1.3

resolveNSPrefix

public static java.lang.String resolveNSPrefix(java.lang.String prefix,
                                               org.w3c.dom.Node context)
Returns the namespace URI that is in scope for the given namespace prefix and context node.
Parameters:
prefix - The namespace prefix to be resolved.
context - The node to be used to determine the scope.
Returns:
A namespace URI string, or null if none could be found for the given inputs.
Since:
2.0

getNamespaceURI

public static java.lang.String getNamespaceURI(org.w3c.dom.Node node)
Returns the namespace URI that is in scope for the given node's namespace prefix, as per the XPath data model.
Parameters:
node - The node for which a namespace is to be resolved.
Returns:
A namespace URI string, or null if none could be determined. If node is an Element without a namespace prefix, the default namespace in scope, if any, will be returned. If node is an Attr without a namespace prefix, null will be returned. For all other nodes, the namespace URI will be null.
Since:
2.0

createNamespaceContext

public static org.jaxen.NamespaceContext createNamespaceContext(org.w3c.dom.Node nsContextNode)
                                                         throws XPathException
Creates a jaxen XPath namespace context containing the prefix mappings in scope for the given node.
Parameters:
nsContextNode - A node containing the namespace prefix definitions to be used for the XPath namespace context.
Returns:
An org.jaxen.NamespaceContext with the prefix mappings in scope for nsContextNode.
Throws:
XPathException
Since:
2.0

getAncestorNamespaces

public static java.util.Map<java.lang.String,java.lang.String> getAncestorNamespaces(org.w3c.dom.Element elem)
get the namespace of all the ancestor elements, includes namespaces of current element too
Parameters:
elem -
Returns:
a map of nsPrefix to nsValue

removeChildren

public static void removeChildren(org.w3c.dom.Element parent,
                                  java.lang.String ns,
                                  java.lang.String tag)
Removes any child elements with the given tag and namespace.
Parameters:
parent - The element whose children will be removed.
ns - The namespace URI of the element(s) to remove.
tag - The tag name of the child element(s) to remove.
Since:
2.0

insertChild

public static void insertChild(XMLElement parent,
                               XMLElement child,
                               java.lang.String[] ns,
                               java.lang.String[] tag,
                               int pos)
                        throws org.w3c.dom.DOMException
Inserts a child element in the correct position relative to the given lists of child element types.
Parameters:
parent - The element to which a child will be appended.
child - The child element to insert.
ns - An array of namespace URIs corresponding to the tag names in the tag array.
tag - An array of element tag names, including the one corresponding to the child element to be inserted. The tags must be presented in the order in which they appear in the parent element's schema.
pos - The position in the ns and tag arrays at which the element to be inserted appears.
Throws:
java.lang.IllegalArgumentException - If either of the tag or ns array is missing or if they do not correspond in length.
org.w3c.dom.DOMException
Since:
2.0

insertChild

public static void insertChild(org.w3c.dom.Element parent,
                               org.w3c.dom.Element child,
                               java.lang.String[] ns,
                               java.lang.String[] tag,
                               int pos)
                        throws org.w3c.dom.DOMException
Inserts a child element in the correct position relative to the given lists of child element types.
Parameters:
parent - The element to which a child will be appended.
child - The child element to insert.
ns - An array of namespace URIs corresponding to the tag names in the tag array.
tag - An array of element tag names, including the one corresponding to the child element to be inserted. The tags must be presented in the order in which they appear in the parent element's schema.
pos - The position in the ns and tag arrays at which the element to be inserted appears.
Throws:
java.lang.IllegalArgumentException - If either of the tag or ns array is missing or if they do not correspond in length.
org.w3c.dom.DOMException
Since:
2.0

insertChild

public static void insertChild(org.w3c.dom.Element parent,
                               org.w3c.dom.Element child,
                               java.lang.String[] namespaces,
                               java.lang.String[] localNames)
                        throws org.w3c.dom.DOMException
Inserts a child element in the correct position relative to the given lists of child element types. The position is determined by locating the child element's type in the namespace and local name lists.
Parameters:
parent - The element to which a child will be appended.
child - The child element to insert.
namepaces - An array of namespace URIs corresponding to the tag names in the localNames array.
localNames - An array of element local tag names, including the one corresponding to the child element to be inserted. The tags must be presented in the order in which they appear in the parent element's schema.
Throws:
java.lang.IllegalArgumentException - If either of the namespaces or localNames array is missing or if they do not correspond in length.
org.w3c.dom.DOMException
Since:
2.1

insertChild

public static void insertChild(XMLElement parent,
                               XMLElement child,
                               java.lang.String[] namespaces,
                               java.lang.String[] localNames)
                        throws org.w3c.dom.DOMException
Inserts a child element in the correct position relative to the given lists of child element types. The position is determined by locating the child element's type in the namespace and local name lists.
Parameters:
parent - The element to which a child will be appended.
child - The child element to insert.
namepaces - An array of namespace URIs corresponding to the tag names in the localNames array.
localNames - An array of element local tag names, including the one corresponding to the child element to be inserted. The tags must be presented in the order in which they appear in the parent element's schema.
Throws:
java.lang.IllegalArgumentException - If either of the namespaces or localNames array is missing or if they do not correspond in length.
org.w3c.dom.DOMException
Since:
2.1

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node)

createElement

public static org.w3c.dom.Element createElement(org.w3c.dom.Document doc,
                                                java.lang.String tag,
                                                java.lang.String nsURI,
                                                java.lang.String prefix)

getAttributeValue

public static java.lang.String getAttributeValue(org.w3c.dom.Element elem,
                                                 java.lang.String name)

getNextSiblingElement

public static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node node)

removeAllChildren

public static void removeAllChildren(org.w3c.dom.Node node)

removeWhiteSpaces

public static java.lang.String removeWhiteSpaces(java.lang.String str)

decodeDEROctets

public static byte[] decodeDEROctets(byte[] der)

getSKI

public static byte[] getSKI(java.security.cert.X509Certificate cert)

indent

public static void indent(org.w3c.dom.Element elem,
                          java.lang.String indent)
Insert text nodes in between elements to indent a DOM node
Parameters:
elem -
indent - set it to "\n" or "\n "

setProperty

public static void setProperty(java.lang.String name,
                               java.lang.String value)
Set various properties that affects XMLSEC behaviour. Exactly same as calling System.setProperty(java.lang.String, java.lang.String) or setting VM arguments. Note these properties are not thread safe, set them only during initialization, when you are sure other threads are not using any xmlsec functions Note for the boolean properties, the code only checks if the property is defined, not the actual value of the property
Parameters:
name -
value -

getProperty

public static java.lang.String getProperty(java.lang.String name)
Get various properties that affects XMLSEC behaviour. Exactly same as System.getProperty(java.lang.String)
Parameters:
name -
Returns:

transformReference

public static java.net.URI transformReference(java.net.URI Base,
                                              java.net.URI R)
                                       throws java.net.URISyntaxException
FOR INTERNAL USE ONLY. Combine two URIs for C14N 1.1 xml:base processing
Parameters:
Base -
R -
Returns:
Throws:
java.net.URISyntaxException

joinXmlBaseURI

public static java.lang.String joinXmlBaseURI(java.util.ArrayList xmlBaseUriList)
                                       throws java.net.URISyntaxException
FOR INTERNAL USE ONLY. Combine two URIs for C14N 1.1 xml:base processing
Parameters:
xmlBaseUriList -
Returns:
Throws:
java.net.URISyntaxException

removeDotSegments

public static java.lang.String removeDotSegments(java.lang.String inp)
FOR INTERNAL USE ONLY. Exactly implements Appendix A of Canonical XML 1.1. http://www.w3.org/TR/xml-c14n11/ which is a modification RFC 3986 Section "5.2.4. Remove Dot Segments"
Parameters:
inp -
Returns:

escapeTextNode

public static java.lang.String escapeTextNode(java.lang.String text)
Escapes XML text characters - &, < > \r
Parameters:
text -
Returns:

resolveReference

public static java.lang.Object resolveReference(ObjectReference ref)
                                         throws ReferenceException,
                                                oracle.security.crypto.core.AlgorithmIdentifierException,
                                                TransformationException
Find out what the reference is pointing to by performing all transforms, except the canonicalization ones.

Transforms

Parameters:
ref - the reference to be resolved
Returns:
  • A byte[] is there a Base64Decode transform
  • A String if this is an external reference (simply returns the URI)
  • A Node if this is an internal reference to single complete subtree.
    This happens when a) ID based referencing is used or b) an XPath filter 2.0 with only one intersect filter that selects a single node is used.
  • A Set containing Nodes , if it an internal reference to anything other than a single complete subtree, i.e. either a single incomplete subtree or multiple subtrees whether complete or incomplete.
    E.g. an XPath Filter 2.0 of type subtract can make a subtree incomplete, and so can an EnvelopedSignatureTransform
Throws:
ReferenceException - if a reference cannot be resolved, of if the transform has invalid syntax, or if there is
oracle.security.crypto.core.AlgorithmIdentifierException - if there is a unrecognized transform
or if there is any Base64 or XSLT transform,
or if there is any transform following a C14N or STR transform
TransformationException

resolveReferences

public static java.util.List resolveReferences(XSSignature sig)
                                        throws ReferenceException,
                                               oracle.security.crypto.core.AlgorithmIdentifierException,
                                               TransformationException
Calls @link #resolveReference(ObjectReference) for each references in a signature and puts them into a list
Parameters:
sig -
Returns:
a list of objects
Throws:
ReferenceException
oracle.security.crypto.core.AlgorithmIdentifierException
TransformationException

getDocumentNavigator

public static org.jaxen.dom.DocumentNavigator getDocumentNavigator()

Skip navigation links

Oracle Fusion Middleware XML Security Java API Reference for Oracle Security Developer Tools
11g Release 1 (11.1.1)

E10680-04


Copyright © 2005, 2011 , Oracle. All rights reserved.