public final class XMLUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
WSU_NS |
static String |
XML_NS |
static String |
XMLNS_NS |
Modifier and Type | Method and Description |
---|---|
static void |
ElementToStream(Element element,
OutputStream out) |
static Element |
findElement(Node startNode,
String name,
String namespace)
Returns the first element that matches
name and
namespace . |
static Element |
findElementById(Node startNode,
String value,
boolean checkMultipleElements)
Returns the single element that contains an Id with value
uri and namespace . |
static List<Element> |
findElements(Node startNode,
String name,
String namespace)
Returns all elements that match
name and namespace . |
static Element |
findSAMLAssertionElementById(Node startNode,
String value)
Returns the single SAMLAssertion element that contains an AssertionID/ID that
matches the supplied parameter.
|
static Element |
getDirectChildElement(Node parentNode,
String localName,
String namespace)
Gets a direct child with specified localname and namespace.
|
static String |
getElementText(Element e)
Return the text content of an Element, or null if no such text content exists
|
static String |
getIDFromReference(String ref)
Turn a reference (eg "#5") into an ID (eg "5").
|
static InputSource |
getInputSourceFromURI(String uri)
Utility to get the bytes uri.
|
static String |
getNamespace(String prefix,
Node e) |
static String |
getPrefixNS(String uri,
Node e) |
static String |
PrettyDocumentToString(Document doc) |
static String |
setNamespace(Element element,
String namespace,
String prefix)
Set a namespace/prefix on an element if it is not set already.
|
static InputSource |
sourceToInputSource(Source source)
Utility to get the bytes uri
|
public static final String XMLNS_NS
public static final String XML_NS
public static final String WSU_NS
public static Element getDirectChildElement(Node parentNode, String localName, String namespace)
parentNode
- the node where to start the searchlocalName
- local name of the child to getnamespace
- the namespace of the child to getnull
if not such node foundpublic static String getElementText(Element e)
public static String PrettyDocumentToString(Document doc) throws IOException, TransformerException
IOException
TransformerException
public static void ElementToStream(Element element, OutputStream out) throws TransformerException
TransformerException
public static InputSource sourceToInputSource(Source source) throws IOException, TransformerException
source
- the resource to getIOException
TransformerException
public static InputSource getInputSourceFromURI(String uri)
uri
- the resource to getpublic static String setNamespace(Element element, String namespace, String prefix)
element
- namespace
- prefix
- public static String getIDFromReference(String ref)
ref
- public static Element findElementById(Node startNode, String value, boolean checkMultipleElements)
uri
and namespace
. 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.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 Idnull
otherwisepublic static Element findElement(Node startNode, String name, String namespace)
name
and
namespace
. This is a replacement for a XPath lookup
//name
with the given namespace. It's somewhat faster than
XPath, and we do not deal with prefixes, just with the real namespace URIstartNode
- Where to start the searchname
- Local name of the elementnamespace
- Namespace URI of the elementnull
public static List<Element> findElements(Node startNode, String name, String namespace)
name
and namespace
.
This is a replacement for a XPath lookup
//name
with the given namespace. It's somewhat faster than
XPath, and we do not deal with prefixes, just with the real namespace URIstartNode
- Where to start the searchname
- Local name of the elementnamespace
- Namespace URI of the elementpublic static Element findSAMLAssertionElementById(Node startNode, String value)
startNode
- Where to start the searchvalue
- Value of the AssertionID/ID attributenull
otherwiseCopyright © 2016 JBoss by Red Hat. All rights reserved.