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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `feature_disallow_doctype_decl`
    `static String` | `feature_external_general_entities`
    `static String` | `feature_external_parameter_entities`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DocumentUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `asString(Document doc)` Get the document as a string while ignoring any exceptions
    `static boolean` | `containsNode(Document doc, Node node)` Check whether a node belongs to a document
    `static Document` | `createDocument()` Create a new document
    `static 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 its `QName`
    `static Document` | `getDocument(File file)` Get Document from a file
    `static Document` | `getDocument(InputStream is)` Get Document from an inputstream
    `static Document` | `getDocument(Reader reader)` Parse a document from a reader
    `static Document` | `getDocument(String docString)` Parse a document from the string
    `static String` | `getDocumentAsString(Document signedDoc)` Marshall a document into a String
    `static Document` | `getDocumentFromSource(Source source)`
    `static String` | `getDOMElementAsString(Element element)` Marshall a DOM Element as string
    `static Element` | `getElement(Document doc, QName elementQName)` Get an element from the document given its `QName`
    `static InputStream` | `getNodeAsStream(Node node)` Stream a DOM Node as an input stream
    `static String` | `getNodeAsString(Node node)` Stream a DOM Node as a String
    `static Node` | `getNodeFromSource(Source source)`
    `static Node` | `getNodeWithAttribute(Document document, String nsURI, String nodeName, String attributeName, String attributeValue)` Given a document, return a Node with the given node name and an attribute with a particular attribute value
    `static InputStream` | `getSourceAsStream(Source source)` Get the `Source` as an `InputStream`
    `static Source` | `getXMLSource(Document doc)` Get a `Source` given a `Document`
    `static void` | `logNodes(Document doc)` Log the nodes in the document
    `static Document` | `normalizeNamespaces(Document doc)` DOM3 method: Normalize the document with namespaces

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### feature_external_general_entities

          public static final String feature_external_general_entities

      See Also:
        Constant Field Values

    - #### feature_external_parameter_entities

          public static final String feature_external_parameter_entities

      See Also:
        Constant Field Values

    - #### feature_disallow_doctype_decl

          public static final String feature_disallow_doctype_decl

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DocumentUtil

          public DocumentUtil()

  - ### Method Detail

    - #### containsNode

          public static boolean containsNode(Document doc,
                                             Node node)

      Check whether a node belongs to a document
      Parameters:
        `doc` -
        `node` -
      Returns:

    - #### createDocument

          public static Document createDocument()
                                         throws ConfigurationException

      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`

    - #### getDOMElementAsString

          public static String getDOMElementAsString(Element element)
                                              throws ProcessingException,
                                                     ConfigurationException

      Marshall a DOM Element as string
      Parameters:
        `element` -
      Returns:
      Throws:
        `TransformerFactoryConfigurationError`
        `TransformerException`
        `ProcessingException`
        `ConfigurationException`

    - #### getElement

          public static Element getElement(Document doc,
                                           QName elementQName)

      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

          public static Element getChildElement(Element doc,
                                                QName elementQName)

      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 the `Source` as an `InputStream`
      Parameters:
        `source` -
      Returns:
      Throws:
        `ConfigurationException`
        `ProcessingException`

    - #### getNodeAsString

          public static String getNodeAsString(Node node)
                                        throws ConfigurationException,
                                               ProcessingException

      Stream a DOM Node as a String
      Parameters:
        `node` -
      Returns:
      Throws:
        `ProcessingException`
        `TransformerFactoryConfigurationError`
        `TransformerException`
        `ConfigurationException`

    - #### getNodeWithAttribute

          public static Node getNodeWithAttribute(Document document,
                                                  String nsURI,
                                                  String nodeName,
                                                  String attributeName,
                                                  String attributeValue)
                                           throws XPathException,
                                                  TransformerFactoryConfigurationError,
                                                  TransformerException

      Given a document, return a Node with the given node name and an attribute with a particular attribute value
      Parameters:
        `document` -
        `nsURI` -
        `nodeName` -
        `attributeName` -
        `attributeValue` -
      Returns:
      Throws:
        `XPathException`
        `TransformerFactoryConfigurationError`
        `TransformerException`

    - #### normalizeNamespaces

          public static Document normalizeNamespaces(Document doc)

      DOM3 method: Normalize the document with namespaces
      Parameters:
        `doc` -
      Returns:

    - #### getXMLSource

          public static Source getXMLSource(Document doc)

      Get a `Source` given a `Document`
      Parameters:
        `doc` -
      Returns:

    - #### asString

          public static String asString(Document doc)

      Get the document as a string while ignoring any exceptions
      Parameters:
        `doc` -
      Returns:

    - #### logNodes

          public static void logNodes(Document doc)

      Log the nodes in the document
      Parameters:
        `doc` -

    - #### getNodeFromSource

          public static Node getNodeFromSource(Source source)
                                        throws ProcessingException,
                                               ConfigurationException

      Throws:
        `ProcessingException`
        `ConfigurationException`

    - #### getDocumentFromSource

          public static Document getDocumentFromSource(Source source)
                                                throws ProcessingException,
                                                       ConfigurationException

      Throws:
        `ProcessingException`
        `ConfigurationException`

Copyright © 2016 JBoss by Red Hat. All rights reserved.