Enum XmlUtil

java.lang.Object
java.lang.Enum<XmlUtil>
org.faktorips.runtime.internal.XmlUtil
All Implemented Interfaces:
Serializable, Comparable<XmlUtil>, java.lang.constant.Constable

public enum XmlUtil extends Enum<XmlUtil>
A collection of utility methods for XML DOM handling.
Author:
Jan Ortmann
  • Method Details

    • values

      public static XmlUtil[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static XmlUtil valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • getFirstElement

      public static final Element getFirstElement(Node parent, String tagName)
      See Also:
    • findFirstElement

      public static final Optional<Element> findFirstElement(Node parent, String tagName)
    • getFirstElement

      public static final Element getFirstElement(Node parent)
      Returns the first Element node
      See Also:
    • findFirstElement

      public static final Optional<Element> findFirstElement(Node parent)
      Returns the first Element node
    • getElement

      public static final Element getElement(Node parent, String tagName, int index)
      Returns the child element with the given tag name and index. The index is the position of the element considering all child elements with the given tag name.
      Parameters:
      parent - The parent node.
      tagName - the element tag name.
      index - The 0 based position of the child.
      Returns:
      The element at the specified index
      Throws:
      IndexOutOfBoundsException - if no element exists at the specified index.
    • getElements

      public static final List<Element> getElements(Node parent, String tagName)
      Returns all child elements with the given tag name. Considers only direct children. Use Element.getElementsByTagName(String) to search all descendants.
      Parameters:
      parent - The parent node.
      tagName - the element tag name.
      Returns:
      all child elements with the matching tag name
    • getTextNode

      public static final Text getTextNode(Node node)
      Returns the node's text child node or null if the node hasn't got a text node.
    • getFirstCDataSection

      public static final CDATASection getFirstCDataSection(Node node)
      Returns the node's first CDATA section or null if the node hasn't got one.
    • getCDATAorTextContent

      public static final String getCDATAorTextContent(Node node)
      Returns the node's first CDATA section if the node has one. If not, this returns the node's text child node or null if the node hasn't got a text node.
    • getValueFromNode

      public static final String getValueFromNode(Element elem, String nodeName)
      Returns the value of the first element with the given node name, starts searching by the given Element
      Parameters:
      elem - The first element (root or parent) element the search begins
      nodeName - The name searching for
    • getElementsFromNode

      public static final List<Element> getElementsFromNode(Element elem, String nodeName, String attributeName, String attributeValue)
      Returns a list of element's with the following criteria:
      • the node name must be equal to the given node name
      • the node must contain an attribute with the attribute name
      • the value of the attribute (with the given name) must be equal to the given value
    • writeXMLtoFile

      public static void writeXMLtoFile(File file, Document doc, String doctype, int indentWidth, String encoding) throws TransformerException
      Writes an XML document to a file.

      See also the DOMUtil.java example.

      Throws:
      TransformerException
    • writeXMLtoResult

      public static void writeXMLtoResult(Result res, Document doc, String doctype, int indentWidth, String encoding) throws TransformerException
      Writes an XML document to a DOM result object.

      See also the DOMUtil.java example.

      Throws:
      TransformerException
    • getDocumentBuilder

      public static final DocumentBuilder getDocumentBuilder()
      Returns:
      a DocumentBuilder in a thread safe manner (ThreadLocal).