|
Oracle Security Developer Tools XML Security Java API Reference 10g Release 2 (10.1.2.0.2) B15571-01 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
oracle.security.xmlsec.util.XMLUtils
Class containing static utility methods for XML and XML-DSIG.
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 |
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.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() Returns a new javax.xml.transform.Transformer instance ('identity' trasformer). |
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 org.w3c.dom.Element |
getElementById(org.w3c.dom.Document doc, java.lang.String id) Resolves an ID attribute value to an element. |
static java.util.Vector |
getIdAttributes(java.lang.String namespaceURI) Returns the list of attributes defined as type ID for the given namespace. |
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 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 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.util.Enumeration |
idAttributeNamespaces() Returns a list of namespace URIs for which ID attributes have been mapped. |
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.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 |
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 |
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.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(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 . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public XMLUtils()
Method Detail |
public static javax.xml.parsers.DocumentBuilder createDocBuilder()
javax.xml.parsers.DocumentBuilder
instance with the NamespaceAware property set to true
.public static org.w3c.dom.Document createDocument()
org.w3c.dom.Document
instance.public static javax.xml.transform.Transformer createTransformer()
javax.xml.transform.Transformer
instance ('identity' trasformer).public static java.lang.String getNodeTypeName(short type)
public static java.lang.String getNodeTypeName(org.w3c.dom.Node node)
public static org.w3c.dom.Document getOwnerDocument(org.w3c.dom.Node node)
Document
node.public static java.lang.String toStringNode(org.w3c.dom.Node node)
public static java.lang.String toStringNodes(java.util.Collection c)
public static java.lang.String toStringXML(XMLNode xmlNode, boolean indent, boolean xmlDecl) throws javax.xml.transform.TransformerException
oracle.security.xmlsec.XMLNode
.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.javax.xml.transform.TransformerException
- If the DOM subtree rooted in this XMLNode
cannot be serialized to a character stream.public static java.lang.String toStringXML(org.w3c.dom.Node node, boolean indent, boolean xmlDecl) throws javax.xml.transform.TransformerException
org.w3c.dom.Node
.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.javax.xml.transform.TransformerException
- If the DOM subtree rooted in this Node
cannot be serialized to a character stream.public static byte[] toBytesXML(XMLNode xmlNode, boolean indent, boolean xmlDecl) throws javax.xml.transform.TransformerException
oracle.security.xmlsec.XMLNode
.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.javax.xml.transform.TransformerException
- If the DOM subtree rooted in the given XMLNode
cannot be serialized to a byte stream.public static byte[] toBytesXML(org.w3c.dom.Node node, boolean indent, boolean xmlDecl) throws javax.xml.transform.TransformerException
org.w3c.dom.Node
.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.javax.xml.transform.TransformerException
- If the DOM subtree rooted in the given Node
cannot be serialized to a byte stream.public static void toStreamXML(java.io.OutputStream os, XMLNode xmlNode, boolean indent, boolean xmlDecl) throws javax.xml.transform.TransformerException, java.io.IOException
oracle.security.xmlsec.XMLNode
to the given stream.os
- The OutputStream
to which the XML will be written.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.javax.xml.transform.TransformerException
- If the DOM subtree rooted in the given XMLNode
cannot be serialized to a byte stream.java.io.IOException
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
org.w3c.dom.Node
to the given stream.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.javax.xml.transform.TransformerException
- If the DOM subtree rooted in the given XMLNode
cannot be serialized to a byte stream.java.io.IOException
public static java.lang.String readString(java.io.Reader reader) throws java.io.IOException
java.io.Reader
as a string.java.io.IOException
public static byte[] readBytes(java.io.InputStream is) throws java.io.IOException
InputStream
and returns a newly allocated byte array.java.io.IOException
public static byte[] readBytes(java.net.URL url) throws java.io.IOException
java.io.IOException
public static java.lang.String stripWS(java.lang.String s)
public static java.util.List toDocumentOrderList(java.util.Collection nodes)
DocOrderComparator
public static XMLElement getInstance(org.w3c.dom.NodeList nodes, java.lang.String tag, java.lang.String ns)
nodes
- The NodeList
containing the element to be wrapped.tag
- The tag name to look for.ns
- The namespace in which tag
is defined.XMLElement
, or null
if a corresponding implementation class cannot be identified or instantiated.public static XMLElement getInstance(java.util.Collection nodes, java.lang.String tag, java.lang.String ns)
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.XMLElement
, or null
if a corresponding implementation class cannot be identified or instantiated.public static XMLElement getInstance(org.w3c.dom.Element element, java.lang.String tag, java.lang.String ns)
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.XMLElement
, or null
if a corresponding implementation class cannot be identified or instantiated.public static XMLElement getInstance(org.w3c.dom.Element element, java.lang.String tag)
element
- The element to be wrapped.tag
- The tag name to look for; if null
, the tag will be taken from the element.XMLElement
, or null
if a corresponding implementation class cannot be identified or instantiated.public static XMLElement getInstance(org.w3c.dom.Element element)
element
- The element to be wrapped.XMLElement
, or null
if a corresponding implementation class cannot be identified or instantiated.public static void copyNSPrefix(org.w3c.dom.Element source, org.w3c.dom.Element target) throws org.w3c.dom.DOMException
source
- The Element from which the namespace prefix will be taken.target
- The Element to which the source's namespace prefix will be given.org.w3c.dom.DOMException
public static java.lang.String canonicalize(org.w3c.dom.Node input, boolean withComments) throws CanonicalizationException
Node
.input
- The root Node
of the sub-tree to be canonicalized.withComments
- If true
, comments will be preserved, otherwise they will be removed.CanonicalizationException
public static java.lang.String canonicalize(org.w3c.dom.NodeList input, boolean withComments) throws CanonicalizationException
NodeList
.input
- The NodeList
to be canonicalized.withComments
- If true
, comments will be preserved, otherwise they will be removed.NodeList
.CanonicalizationException
public static java.lang.String canonicalize(java.util.Collection nodeSet, boolean withComments) throws CanonicalizationException
nodeSet
- The node-set to be canonicalized.withComments
- If true
, comments will be preserved, otherwise they will be removed.NodeSet
.CanonicalizationException
public static java.lang.String randomName()
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.
public static java.lang.String fixURL(java.lang.String urlStr, java.lang.String systemId)
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.urlStr
, based on systemId
. If urlStr
is already expanded, or if it or systemId
is invalid, urlStr
is returned unaltered.public static java.lang.String fixURL(java.lang.String urlStr)
urlStr
- A URL string.urlStr
is invalid, then urlStr
is returned unaltered.public static java.lang.String getIdFromURI(java.lang.String uri)
uri
- The URI string containing the ID.null
if none could be found.public static org.w3c.dom.Element getElementById(org.w3c.dom.Document doc, java.lang.String id)
doc
- The Document
to search.id
- The ID attribute value to resolve.Element
with the ID attribute value given by id
, or null
if none could be located in doc
.public static void addIdAttribute(java.lang.String namespaceURI, java.lang.String attrName)
namespaceURI
- The URI identifying the namespace in which the attribute is defined with ID type.attrName
- The local name of the ID attribute.getIdAttributes(java.lang.String)
public static java.util.Enumeration idAttributeNamespaces()
public static java.util.Vector getIdAttributes(java.lang.String namespaceURI)
namespaceURI
- The URI identifying the namespace in which the attributes are defined with ID type.java.util.Vector
containing any attribute names defined to be of type ID in the given namespace.addIdAttribute(java.lang.String, java.lang.String)
public static java.lang.String formatDate(java.util.Date date)
date
- The Date
to parse.public static java.lang.String formatTime(java.util.Date date)
public static java.lang.String formatDateTime(java.util.Date date)
public static java.util.Date parseDateTime(java.lang.String s)
s
- The String to parse.Date
object.public static java.lang.String collectText(org.w3c.dom.Node node)
node
- The node whose text-node children are to be concatenated.node
's text-node children's values.public static java.lang.String resolveNSPrefix(java.lang.String prefix, org.w3c.dom.Node context)
prefix
- The namespace prefix to be resolved.context
- The node to be used to determine the scope.null
if none could be found for the given inputs.public static java.lang.String getNamespaceURI(org.w3c.dom.Node node)
node
- The node for which a namespace is to be resolved.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
.public static org.jaxen.NamespaceContext createNamespaceContext(org.w3c.dom.Node nsContextNode) throws XPathException
nsContextNode
- A node containing the namespace prefix definitions to be used for the XPath namespace context.org.jaxen.NamespaceContext
with the prefix mappings in scope for nsContextNode
.XPathException
public static void removeChildren(org.w3c.dom.Element parent, java.lang.String ns, java.lang.String tag)
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.public static void insertChild(XMLElement parent, XMLElement child, java.lang.String[] ns, java.lang.String[] tag, int pos) throws org.w3c.dom.DOMException
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.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
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
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.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
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
parent
- The element to which a child will be appended.child
- The child element to insert.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.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
public static void insertChild(XMLElement parent, XMLElement child, java.lang.String[] namespaces, java.lang.String[] localNames) throws org.w3c.dom.DOMException
parent
- The element to which a child will be appended.child
- The child element to insert.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.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
|
Oracle Security Developer Tools XML Security Java API Reference 10g Release 2 (10.1.2.0.2) B15571-01 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |