Package org.keycloak.saml.common.util
Class DocumentUtil
- java.lang.Object
- 
- org.keycloak.saml.common.util.DocumentUtil
 
- 
- Direct Known Subclasses:
- DocumentUtil
 
 public class DocumentUtil extends Object Utility dealing with DOM- Since:
- Jan 14, 2009
- Author:
- Anil.Saldhana@redhat.com
 
- 
- 
Field SummaryFields Modifier and Type Field Description static Stringfeature_disallow_doctype_declstatic Stringfeature_external_general_entitiesstatic Stringfeature_external_parameter_entities
 - 
Constructor SummaryConstructors Constructor Description DocumentUtil()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static StringasString(Document doc)Get the document as a string while ignoring any exceptionsstatic DocumentcreateDocument()Create a new documentstatic DocumentcreateDocumentWithBaseNamespace(String baseNamespace, String localPart)Create a document with the root element of the form <someElement xmlns="customNamespace"static ElementgetChildElement(Element doc, QName elementQName)Get an child element from the parent element given itsQNamestatic ElementgetDirectChildElement(Element parent, String targetNamespace, String targetLocalName)static DocumentgetDocument(File file)Get Document from a filestatic DocumentgetDocument(InputStream is)Get Document from an inputstreamstatic DocumentgetDocument(Reader reader)Parse a document from a readerstatic DocumentgetDocument(String docString)Parse a document from the stringstatic StringgetDocumentAsString(Document signedDoc)Marshall a document into a Stringstatic DocumentBuildergetDocumentBuilder()static ElementgetElement(Document doc, QName elementQName)Get an element from the document given itsQNamestatic InputStreamgetNodeAsStream(Node node)Stream a DOM Node as an input streamstatic StringgetNodeAsString(Node node)Marshall a DOM Node into a Stringstatic InputStreamgetSourceAsStream(Source source)Get theSourceas anInputStreamstatic SourcegetXMLSource(Document doc)
 
- 
- 
- 
Field Detail- 
feature_external_general_entitiespublic static final String feature_external_general_entities - See Also:
- Constant Field Values
 
 - 
feature_external_parameter_entitiespublic static final String feature_external_parameter_entities - See Also:
- Constant Field Values
 
 - 
feature_disallow_doctype_declpublic static final String feature_disallow_doctype_decl - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
createDocumentpublic static Document createDocument() throws ConfigurationException Create a new document- Returns:
- Throws:
- ParserConfigurationException
- ConfigurationException
 
 - 
createDocumentWithBaseNamespacepublic 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
 
 - 
getDocumentpublic 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
 
 - 
getDocumentpublic 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
 
 - 
getDocumentpublic static Document getDocument(File file) throws ConfigurationException, ProcessingException, ParsingException Get Document from a file- Parameters:
- file-
- Returns:
- Throws:
- ParserConfigurationException
- IOException
- SAXException
- ConfigurationException
- ProcessingException
- ParsingException
 
 - 
getDocumentpublic static Document getDocument(InputStream is) throws ConfigurationException, ProcessingException, ParsingException Get Document from an inputstream- Parameters:
- is-
- Returns:
- Throws:
- ParserConfigurationException
- IOException
- SAXException
- ConfigurationException
- ProcessingException
- ParsingException
 
 - 
getDocumentAsStringpublic static String getDocumentAsString(Document signedDoc) throws ProcessingException, ConfigurationException Marshall a document into a String- Parameters:
- signedDoc-
- Returns:
- Throws:
- TransformerFactoryConfigurationError
- TransformerException
- ProcessingException
- ConfigurationException
 
 - 
getNodeAsStringpublic static String getNodeAsString(Node node) throws ProcessingException, ConfigurationException Marshall a DOM Node into a String- Parameters:
- node-
- Returns:
- Throws:
- ProcessingException
- ConfigurationException
 
 - 
getElementpublic static Element getElement(Document doc, QName elementQName) Get an element from the document given its QNameFirst 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:
 
 - 
getChildElementpublic static Element getChildElement(Element doc, QName elementQName) Get an child element from the parent element given its QNameFirst 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:
 
 - 
getNodeAsStreampublic static InputStream getNodeAsStream(Node node) throws ConfigurationException, ProcessingException Stream a DOM Node as an input stream- Parameters:
- node-
- Returns:
- Throws:
- TransformerFactoryConfigurationError
- TransformerException
- ConfigurationException
- ProcessingException
 
 - 
getSourceAsStreampublic static InputStream getSourceAsStream(Source source) throws ConfigurationException, ProcessingException Get theSourceas anInputStream- Parameters:
- source-
- Returns:
- Throws:
- ConfigurationException
- ProcessingException
 
 - 
asStringpublic static String asString(Document doc) Get the document as a string while ignoring any exceptions- Parameters:
- doc-
- Returns:
 
 - 
getDocumentBuilderpublic static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException - Throws:
- ParserConfigurationException
 
 - 
getDirectChildElementpublic static Element getDirectChildElement(Element parent, String targetNamespace, String targetLocalName) - Parameters:
- parent- parent element
- targetNamespace- namespace URI
- targetLocalName- local name
- Returns:
- a child element matching the target namespace and localname, where Node.getParentNode() is the parent input parameter
 
 
- 
 
-