Class XmlService


  • public class XmlService
    extends Object
    Utility service for xml-based transformation.
    • Method Detail

      • readProperties

        public static void readProperties​(org.dom4j.Element parent,
                                          BiConsumer<String,​String> consumer)
        Read <property> elements from a parent and consume their "name" and "value" attributes.
        Parameters:
        parent - parent element containing the property elements
        consumer - consumer of the "name" and "value" attributes values
      • readProperty

        public static void readProperty​(org.dom4j.Element property,
                                        BiConsumer<String,​String> consumer)
        Get a <property> element and consume its "name" and "value" attributes.
        Parameters:
        property - property element with name and value attributes
        consumer - consumer of the "name" and "value" attributes values
      • writeProperty

        public static <T> org.dom4j.Element writeProperty​(String name,
                                                          T value)
        Create a <property> element with "name", "value" and "type" attributes. The type is inferred through the value.
        Type Parameters:
        T - type of the property's value
        Parameters:
        name - name of the property
        value - value of the property
        Returns:
        property element with "name", "value" and "type" attributes
        See Also:
        writeProperty(String, Object, String)
      • writeProperty

        public static <T> org.dom4j.Element writeProperty​(@NonNull
                                                          @NonNull String name,
                                                          @NonNull
                                                          T value,
                                                          String type)
        Create a <property> element with "name", "value" and "type" attributes.
        Type Parameters:
        T - type of the property's value
        Parameters:
        name - name of the property
        value - value of the property
        type - type name of the property's value
        Returns:
        property element with "name", "value" and "type" attributes
      • forEach

        public static void forEach​(String name,
                                   org.dom4j.Element parent,
                                   Consumer<org.dom4j.Element> action)
        Iterate a parent element's children by their name and consume these elements.
        Parameters:
        name - name of the children elements
        parent - parent element
        action - consumer of the children
      • writeRegister

        public static org.dom4j.Document writeRegister​(List<IndexEntry> projects)
        Create the Document for the global project register.
        Parameters:
        projects - list of project index entries
        Returns:
        document containing the serialized index entries
      • readRegister

        public static List<IndexEntry> readRegister​(org.dom4j.Document document)
        Parse the Document for the global project register.
        Parameters:
        document - document to parse
        Returns:
        list of project index entries
      • readElementList

        public static <T> List<T> readElementList​(String name,
                                                  org.dom4j.Element parent,
                                                  Function<org.dom4j.Element,​T> action)
        Iterate a parent element's children by their name and map these elements to their values.
        Type Parameters:
        T - type of the element's value
        Parameters:
        name - name of the children elements
        parent - parent element
        action - mapper of the children
        Returns:
        list of the parsed elements values
      • appendElementList

        public static <T> void appendElementList​(org.dom4j.Element parent,
                                                 List<T> list,
                                                 Function<T,​org.dom4j.Element> action)
        Append a list of mapped values to a parent element.
        Type Parameters:
        T - type of the values
        Parameters:
        parent - parent element to append to
        list - list of value to map and append
        action - mapper function to create elements from the given values
      • simpleElement

        public static <T> org.dom4j.Element simpleElement​(String name,
                                                          T content)
        Create a simple element with name and content.
        Type Parameters:
        T - type of the content value
        Parameters:
        name - name of the simple element
        content - content of the simple element to stringify
        Returns:
        element with name and string content