Package org.apache.wss4j.common.util
Class XMLUtils
java.lang.Object
org.apache.wss4j.common.util.XMLUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidelementToStream(Element element, OutputStream out) static ElementfindElement(Node startNode, String name, String namespace) Returns the first element that matchesnameandnamespace.static ElementfindElementById(Node startNode, String value, boolean checkMultipleElements) Returns the single element that contains an Id with valueuriandnamespace.findElements(Node startNode, String name, String namespace) Returns all elements that matchnameandnamespace.static ElementfindSAMLAssertionElementById(Node startNode, String value) Returns the single SAMLAssertion element that contains an AssertionID/ID that matches the supplied parameter.static ElementgetDirectChildElement(Node parentNode, String localName, String namespace) Gets a direct child with specified localname and namespace.static StringReturn the text content of an Element, or null if no such text content existsstatic StringgetIDFromReference(String ref) Turn a reference (eg "#5") into an ID (eg "5").static InputSourceUtility to get the bytes uri.static StringgetNamespace(String prefix, Node e) static StringgetPrefixNS(String uri, Node e) static Stringstatic StringsetNamespace(Element element, String namespace, String prefix) Set a namespace/prefix on an element if it is not set already.static InputSourcesourceToInputSource(Source source) Utility to get the bytes uri
-
Field Details
-
XMLNS_NS
- See Also:
-
XML_NS
- See Also:
-
WSU_NS
- See Also:
-
-
Method Details
-
getDirectChildElement
Gets a direct child with specified localname and namespace.- Parameters:
parentNode- the node where to start the searchlocalName- local name of the child to getnamespace- the namespace of the child to get- Returns:
- the node or
nullif not such node found
-
getElementText
Return the text content of an Element, or null if no such text content exists -
getNamespace
-
prettyDocumentToString
- Throws:
IOExceptionTransformerException
-
elementToStream
- Throws:
TransformerException
-
sourceToInputSource
public static InputSource sourceToInputSource(Source source) throws IOException, TransformerException Utility to get the bytes uri- Parameters:
source- the resource to get- Throws:
IOExceptionTransformerException
-
getInputSourceFromURI
Utility to get the bytes uri. Does NOT handle authenticated URLs, use getInputSourceFromURI(uri, username, password)- Parameters:
uri- the resource to get
-
setNamespace
Set a namespace/prefix on an element if it is not set already. First off, it searches for the element for the prefix associated with the specified namespace. If the prefix isn't null, then this is returned. Otherwise, it creates a new attribute using the namespace/prefix passed as parameters.- Parameters:
element-namespace-prefix-- Returns:
- the prefix associated with the set namespace
-
getPrefixNS
-
getIDFromReference
Turn a reference (eg "#5") into an ID (eg "5").- Parameters:
ref-- Returns:
- ref trimmed and with the leading "#" removed, or null if not correctly formed
-
findElementById
Returns the single element that contains an Id with valueuriandnamespace. The Id can be either a wsu:Id or an Id with no namespace. This is a replacement for a XPath Id lookup with the given namespace. It's somewhat faster than XPath, and we do not deal with prefixes, just with the real namespace URI If checkMultipleElements is true and there are multiple elements, we LOG.a warning and return null as this can be used to get around the signature checking.- Parameters:
startNode- Where to start the searchvalue- Value of the Id attributecheckMultipleElements- If true then go through the entire tree and return null if there are multiple elements with the same Id- Returns:
- The found element if there was exactly one match, or
nullotherwise
-
findElement
Returns the first element that matchesnameandnamespace. This is a replacement for a XPath lookup//namewith the given namespace. It's somewhat faster than XPath, and we do not deal with prefixes, just with the real namespace URI- Parameters:
startNode- Where to start the searchname- Local name of the elementnamespace- Namespace URI of the element- Returns:
- The found element or
null
-
findElements
Returns all elements that matchnameandnamespace. This is a replacement for a XPath lookup//namewith the given namespace. It's somewhat faster than XPath, and we do not deal with prefixes, just with the real namespace URI- Parameters:
startNode- Where to start the searchname- Local name of the elementnamespace- Namespace URI of the element- Returns:
- The found elements (or an empty list)
-
findSAMLAssertionElementById
Returns the single SAMLAssertion element that contains an AssertionID/ID that matches the supplied parameter.- Parameters:
startNode- Where to start the searchvalue- Value of the AssertionID/ID attribute- Returns:
- The found element if there was exactly one match, or
nullotherwise
-