Class DomUtils


  • public final class DomUtils
    extends Object
    Helper class providing convenience methods for dealing with Dom trees.
    Author:
    Oliver Wolff
    • Field Detail

      • ROOT_TEMPLATE

        public static final String ROOT_TEMPLATE
        The root element for creating Documents. This ensures correct structure regarding xml only having one root-element
        See Also:
        Constant Field Values
    • Method Detail

      • htmlStringToDocument

        public static org.jdom2.Document htmlStringToDocument​(String htmlString)
        Creates an instance of Document for the given htmlString. It always uses ROOT_TEMPLATE as the root element.
        Parameters:
        htmlString - must not be null
        Returns:
        the created Document with ROOT_TEMPLATE as the root element.
      • filterForAttribute

        public static List<org.jdom2.Attribute> filterForAttribute​(org.jdom2.Element element,
                                                                   String attributeName)
        Extracts all attributes with the given name. The method will recursively check all children as well.
        Parameters:
        element - to be checked, must not be null.
        attributeName - to be looked for, must not be null nor empty.
        Returns:
        a List with the found attributes, never null but may be empty.
      • filterForAttributeContainingValue

        public static List<org.jdom2.Attribute> filterForAttributeContainingValue​(org.jdom2.Element element,
                                                                                  String attributeName,
                                                                                  String attributeValuePart)
        Extracts all attributes with the given name and the attribute-value containing the given String. The method will recursively check all children as well.
        Parameters:
        element - to be checked, must not be null.
        attributeName - to be looked for, must not be null nor empty.
        attributeValuePart - the string of the attribute value to be filtered for.
        Returns:
        a List with the found attributes, never null but may be empty.