Package org.apache.wss4j.common.util
Class XMLUtils
- java.lang.Object
-
- org.apache.wss4j.common.util.XMLUtils
-
public final class XMLUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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.static List<Element>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 StringgetElementText(Element e)Return 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 InputSourcegetInputSourceFromURI(String uri)Utility to get the bytes uri.static StringgetNamespace(String prefix, Node e)static StringgetPrefixNS(String uri, Node e)static StringprettyDocumentToString(Document doc)static 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 Detail
-
XMLNS_NS
public static final String XMLNS_NS
- See Also:
- Constant Field Values
-
XML_NS
public static final String XML_NS
- See Also:
- Constant Field Values
-
WSU_NS
public static final String WSU_NS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getDirectChildElement
public static Element getDirectChildElement(Node parentNode, String localName, String namespace)
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
public static String getElementText(Element e)
Return the text content of an Element, or null if no such text content exists
-
prettyDocumentToString
public static String prettyDocumentToString(Document doc) throws IOException, TransformerException
- Throws:
IOExceptionTransformerException
-
elementToStream
public static void elementToStream(Element element, OutputStream out) throws TransformerException
- 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
public static InputSource getInputSourceFromURI(String uri)
Utility to get the bytes uri. Does NOT handle authenticated URLs, use getInputSourceFromURI(uri, username, password)- Parameters:
uri- the resource to get
-
setNamespace
public static String setNamespace(Element element, String namespace, String prefix)
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
-
getIDFromReference
public static String getIDFromReference(String ref)
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
public static Element findElementById(Node startNode, String value, boolean checkMultipleElements)
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
public static Element findElement(Node startNode, String name, String namespace)
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
public static List<Element> findElements(Node startNode, String name, String namespace)
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
public static Element findSAMLAssertionElementById(Node startNode, String value)
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
-
-