edu.northwestern.at.utils.xml

## Class JDOMUtils

- java.lang.Object
- - edu.northwestern.at.utils.xml.JDOMUtils

-     public class JDOMUtils
      extends java.lang.Object

  XML JDOM utilities.

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `JDOMUtils()` Allow overrides but not instantiation.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `applyElementFilter(org.jdom2.Document document, org.jdom2.filter.Filter<org.jdom2.Element> filter, ElementProcessor processor)` Process elements selected by an element filter.
    `static org.jdom2.Attribute` | `getAttribute(org.jdom2.Element element, java.lang.String attributeName, boolean ignoreCase)` Get attribute.
    `static java.lang.String` | `getAttributeValue(org.jdom2.Element element, java.lang.String attributeName, boolean ignoreCase)` Get attribute value.
    `static java.lang.String` | `getAttributeValueIgnoreCase(org.jdom2.Element element, java.lang.String attributeName)` Get attribute value ignoring case.
    `static java.util.Map<java.lang.String,java.lang.String>` | `getAttributeValues(org.jdom2.Element element)` Get mapped attributes for an element.
    `static org.jdom2.Document` | `parse(java.io.File file)` Parses an XML file.
    `static org.jdom2.Document` | `parse(java.lang.String path)` Parses an XML file.
    `static org.jdom2.Document` | `parse(java.net.URL url)` Parses XML document from URL.
    `static org.jdom2.Document` | `parseText(java.lang.String text)` Parses XML document from a string.
    `static void` | `removeAttribute(org.jdom2.Element element, java.lang.String attributeName)` Remove attribute.
    `static void` | `save(org.jdom2.Document document, java.lang.String path, org.jdom2.output.Format format)` Saves a JDOM document to an XML file in utf-8.
    `static void` | `savePretty(org.jdom2.Document document, java.lang.String path)` Saves a JDOM document to an XML file in utf-8.
    `static void` | `saveRaw(org.jdom2.Document document, java.lang.String path)` Saves a JDOM document to an XML file in utf-8.
    `static void` | `saveRawCompressed(org.jdom2.Document document, java.lang.String path)` Saves a JDOM document to a compressed XML file in utf-8.
    `static java.lang.String` | `saveToString(org.jdom2.Document document, org.jdom2.output.Format format)` Saves a JDOM document to a String.
    `static void` | `setAttributeValue(org.jdom2.Element element, java.lang.String attributeName, java.lang.String attributeValue)` Set attribute value.
    `static java.util.List<ValidationError>` | `validateDocument(org.jdom2.Document document, Schema schema)` Validate a JDOM document against a schema.
    `static java.util.List<ValidationError>` | `validateDocument(org.jdom2.Document document, java.lang.String schemaURI)` Validate a JDOM document against a schema.

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

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

- - ### Constructor Detail

    - #### JDOMUtils

          protected JDOMUtils()

      Allow overrides but not instantiation.

  - ### Method Detail

    - #### parse

          public static org.jdom2.Document parse(java.io.File file)
                                          throws java.io.IOException,
                                                 org.jdom2.JDOMException,
                                                 org.xml.sax.SAXException

      Parses an XML file.
      Parameters:
        `file` - File.
      Returns:
        JDOM document.
      Throws:
        `java.lang.Exception`
        `java.io.IOException`
        `org.jdom2.JDOMException`
        `org.xml.sax.SAXException`

    - #### parse

          public static org.jdom2.Document parse(java.lang.String path)
                                          throws java.io.IOException,
                                                 org.jdom2.JDOMException,
                                                 org.xml.sax.SAXException

      Parses an XML file.
      Parameters:
        `path` - File path.
      Returns:
        JDOM document.
      Throws:
        `java.lang.Exception`
        `java.io.IOException`
        `org.jdom2.JDOMException`
        `org.xml.sax.SAXException`

    - #### parse

          public static org.jdom2.Document parse(java.net.URL url)
                                          throws java.io.IOException,
                                                 org.jdom2.JDOMException,
                                                 org.xml.sax.SAXException

      Parses XML document from URL.
      Parameters:
        `url` - URL.
      Returns:
        JDOM document.
      Throws:
        `java.lang.Exception`
        `java.io.IOException`
        `org.jdom2.JDOMException`
        `org.xml.sax.SAXException`

    - #### parseText

          public static org.jdom2.Document parseText(java.lang.String text)
                                              throws java.io.IOException,
                                                     org.jdom2.JDOMException,
                                                     org.xml.sax.SAXException

      Parses XML document from a string.
      Parameters:
        `text` - Document text string.
      Returns:
        JDOM document.
      Throws:
        `java.lang.Exception`
        `java.io.IOException`
        `org.jdom2.JDOMException`
        `org.xml.sax.SAXException`

    - #### getAttribute

          public static org.jdom2.Attribute getAttribute(org.jdom2.Element element,
                                         java.lang.String attributeName,
                                         boolean ignoreCase)

      Get attribute.
      Parameters:
        `element` - The JDOM element.
        `attributeName` - The attribute name whose value we want.
        `ignoreCase` - true to ignore attribute name case.
      Returns:
        The attribute or null if not found.

    - #### getAttributeValue

          public static java.lang.String getAttributeValue(org.jdom2.Element element,
                                           java.lang.String attributeName,
                                           boolean ignoreCase)

      Get attribute value.
      Parameters:
        `element` - The JDOM element.
        `attributeName` - The attribute name whose value we want.
        `ignoreCase` - true to ignore attribute name case.
      Returns:
        The attribute value or null if not found.

    - #### getAttributeValueIgnoreCase

          public static java.lang.String getAttributeValueIgnoreCase(org.jdom2.Element element,
                                                     java.lang.String attributeName)

      Get attribute value ignoring case.
      Parameters:
        `element` - The JDOM element.
        `attributeName` - The attribute name whose value we want.
      Returns:
        The attribute value or null if not found.

    - #### getAttributeValues

          public static java.util.Map<java.lang.String,java.lang.String> getAttributeValues(org.jdom2.Element element)

      Get mapped attributes for an element.
      Parameters:
        `element` - The JDOM element whose attributes are desired.
      Returns:
        Map with attribute name as key and attribute value as value.

    - #### setAttributeValue

          public static void setAttributeValue(org.jdom2.Element element,
                               java.lang.String attributeName,
                               java.lang.String attributeValue)

      Set attribute value.
      Parameters:
        `element` - The JDOM element.
        `attributeName` - The attribute name whose value should be set.
        `attributeValue` - The attribute value.

    - #### removeAttribute

          public static void removeAttribute(org.jdom2.Element element,
                             java.lang.String attributeName)

      Remove attribute.
      Parameters:
        `element` - The JDOM element.
        `attributeName` - The attribute name to remove.

    - #### applyElementFilter

          public static void applyElementFilter(org.jdom2.Document document,
                                org.jdom2.filter.Filter<org.jdom2.Element> filter,
                                ElementProcessor processor)

      Process elements selected by an element filter.
      Parameters:
        `document` - The document to which to apply the filter.
        `filter` - The filter.
        `processor` - The element processor.

    - #### save

          public static void save(org.jdom2.Document document,
                  java.lang.String path,
                  org.jdom2.output.Format format)
                           throws java.io.FileNotFoundException,
                                  java.io.IOException

      Saves a JDOM document to an XML file in utf-8.
      Parameters:
        `document` - JDOM document.
        `path` - Output file path.
        `format` - The JDOM output format.
      Throws:
        `FileNotFoundException,` - IOException
        `java.io.FileNotFoundException`
        `java.io.IOException`

    - #### saveToString

          public static java.lang.String saveToString(org.jdom2.Document document,
                                      org.jdom2.output.Format format)
                                               throws java.io.FileNotFoundException,
                                                      java.io.IOException

      Saves a JDOM document to a String.
      Parameters:
        `document` - JDOM document.
        `format` - The JDOM output format.
      Returns:
        String containing saved document.
      Throws:
        `FileNotFoundException,` - IOException
        `java.io.FileNotFoundException`
        `java.io.IOException`

    - #### savePretty

          public static void savePretty(org.jdom2.Document document,
                        java.lang.String path)
                                 throws java.io.FileNotFoundException,
                                        java.io.IOException

      Saves a JDOM document to an XML file in utf-8.
      Parameters:
        `document` - JDOM document.
        `path` - Output file path.
      Throws:
        `java.io.IOException` -

        The document is "pretty printed."

        `java.io.FileNotFoundException`

    - #### saveRaw

          public static void saveRaw(org.jdom2.Document document,
                     java.lang.String path)
                              throws java.io.FileNotFoundException,
                                     java.io.IOException

      Saves a JDOM document to an XML file in utf-8.
      Parameters:
        `document` - JDOM document.
        `path` - Output file path.
      Throws:
        `java.io.IOException` -

        The document is output raw, without "pretty printing."

        `java.io.FileNotFoundException`

    - #### saveRawCompressed

          public static void saveRawCompressed(org.jdom2.Document document,
                               java.lang.String path)
                                        throws java.io.FileNotFoundException,
                                               java.io.IOException

      Saves a JDOM document to a compressed XML file in utf-8.
      Parameters:
        `document` - JDOM document.
        `path` - Output file path.
      Throws:
        `java.io.IOException` -

        The document is output raw, without "pretty printing."

        `java.io.FileNotFoundException`

    - #### validateDocument

          public static java.util.List<ValidationError> validateDocument(org.jdom2.Document document,
                                                         java.lang.String schemaURI)
                                                                  throws org.jdom2.JDOMException,
                                                                         java.io.IOException

      Validate a JDOM document against a schema.
      Parameters:
        `document` - The parsed JDOM document to validate.
        `schemaURI` - The schema URI.
      Returns:
        List of validation errors. Null if no errors.
      Throws:
        `java.io.IOException` - if the schema URI cannot be read.
        `org.jdom2.JDOMException` - if the schema is invalid or validation fails.

    - #### validateDocument

          public static java.util.List<ValidationError> validateDocument(org.jdom2.Document document,
                                                         Schema schema)
                                                                  throws org.jdom2.JDOMException,
                                                                         java.io.IOException

      Validate a JDOM document against a schema.
      Parameters:
        `document` - The parsed JDOM document to validate.
        `schema` - A parsed schema.
      Returns:
        List of validation errors. Null if no errors.
      Throws:
        `java.io.IOException` - if the schema URI cannot be read.
        `org.jdom2.JDOMException` - if the schema is invalid or validation fails.

        Simply returns without error if validation succeeds.