Package org.keycloak.saml.common.util
Class DocumentUtil
java.lang.Object
org.keycloak.saml.common.util.DocumentUtil
- Direct Known Subclasses:
DocumentUtil
Utility dealing with DOM
- Since:
- Jan 14, 2009
- Author:
- Anil.Saldhana@redhat.com
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Get the document as a string while ignoring any exceptionsstatic Document
Create a new documentstatic Document
createDocumentWithBaseNamespace
(String baseNamespace, String localPart) Create a document with the root element of the form <someElement xmlns="customNamespace"static Element
getChildElement
(Element doc, QName elementQName) Get an child element from the parent element given itsQName
static Element
getDirectChildElement
(Element parent, String targetNamespace, String targetLocalName) static Document
getDocument
(File file) Get Document from a filestatic Document
Get Document from an inputstreamstatic Document
getDocument
(Reader reader) Parse a document from a readerstatic Document
getDocument
(String docString) Parse a document from the stringstatic String
getDocumentAsString
(Document signedDoc) Marshall a document into a Stringstatic DocumentBuilder
static Element
getElement
(Document doc, QName elementQName) Get an element from the document given itsQName
static InputStream
getNodeAsStream
(Node node) Stream a DOM Node as an input streamstatic String
getNodeAsString
(Node node) Marshall a DOM Node into a Stringstatic InputStream
getSourceAsStream
(Source source) Get theSource
as anInputStream
static Source
getXMLSource
(Document doc)
-
Field Details
-
feature_external_general_entities
- See Also:
-
feature_external_parameter_entities
- See Also:
-
feature_disallow_doctype_decl
- See Also:
-
-
Constructor Details
-
DocumentUtil
public DocumentUtil()
-
-
Method Details
-
createDocument
Create a new document- Returns:
- Throws:
ParserConfigurationException
ConfigurationException
-
createDocumentWithBaseNamespace
public static Document createDocumentWithBaseNamespace(String baseNamespace, String localPart) throws ProcessingException Create a document with the root element of the form <someElement xmlns="customNamespace"- Parameters:
baseNamespace
-- Returns:
- Throws:
ProcessingException
-
getDocument
public static Document getDocument(String docString) throws ConfigurationException, ParsingException, ProcessingException Parse a document from the string- Parameters:
docString
-- Returns:
- Throws:
IOException
SAXException
ParserConfigurationException
ConfigurationException
ParsingException
ProcessingException
-
getDocument
public static Document getDocument(Reader reader) throws ConfigurationException, ProcessingException, ParsingException Parse a document from a reader- Parameters:
reader
-- Returns:
- Throws:
ParsingException
ParserConfigurationException
IOException
SAXException
ConfigurationException
ProcessingException
-
getDocument
public static Document getDocument(File file) throws ConfigurationException, ProcessingException, ParsingException Get Document from a file- Parameters:
file
-- Returns:
- Throws:
ParserConfigurationException
IOException
SAXException
ConfigurationException
ProcessingException
ParsingException
-
getDocument
public static Document getDocument(InputStream is) throws ConfigurationException, ProcessingException, ParsingException Get Document from an inputstream- Parameters:
is
-- Returns:
- Throws:
ParserConfigurationException
IOException
SAXException
ConfigurationException
ProcessingException
ParsingException
-
getDocumentAsString
public static String getDocumentAsString(Document signedDoc) throws ProcessingException, ConfigurationException Marshall a document into a String- Parameters:
signedDoc
-- Returns:
- Throws:
TransformerFactoryConfigurationError
TransformerException
ProcessingException
ConfigurationException
-
getNodeAsString
Marshall a DOM Node into a String- Parameters:
node
-- Returns:
- Throws:
ProcessingException
ConfigurationException
-
getElement
Get an element from the document given its
QName
First an attempt to get the element based on its namespace is made, failing which an element with the localpart ignoring any namespace is returned.
- Parameters:
doc
-elementQName
-- Returns:
-
getChildElement
Get an child element from the parent element given its
QName
First an attempt to get the element based on its namespace is made, failing which an element with the localpart ignoring any namespace is returned.
- Parameters:
doc
-elementQName
-- Returns:
-
getNodeAsStream
public static InputStream getNodeAsStream(Node node) throws ConfigurationException, ProcessingException Stream a DOM Node as an input stream- Parameters:
node
-- Returns:
- Throws:
TransformerFactoryConfigurationError
TransformerException
ConfigurationException
ProcessingException
-
getSourceAsStream
public static InputStream getSourceAsStream(Source source) throws ConfigurationException, ProcessingException Get theSource
as anInputStream
- Parameters:
source
-- Returns:
- Throws:
ConfigurationException
ProcessingException
-
getXMLSource
- Parameters:
doc
-- Returns:
-
asString
Get the document as a string while ignoring any exceptions- Parameters:
doc
-- Returns:
-
getDocumentBuilder
- Throws:
ParserConfigurationException
-
getDirectChildElement
public static Element getDirectChildElement(Element parent, String targetNamespace, String targetLocalName) - Parameters:
parent
- parent elementtargetNamespace
- namespace URItargetLocalName
- local name- Returns:
- a child element matching the target namespace and localname, where Node.getParentNode() is the parent input parameter
-