Package evo.search.io.service
Class XmlService
- java.lang.Object
-
- evo.search.io.service.XmlService
-
public class XmlService extends Object
Utility service for xml-based transformation.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.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.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.static void
readProperties(org.dom4j.Element parent, BiConsumer<String,String> consumer)
Read<property>
elements from a parent and consume their "name" and "value" attributes.static void
readProperty(org.dom4j.Element property, BiConsumer<String,String> consumer)
Get a<property>
element and consume its "name" and "value" attributes.static List<IndexEntry>
readRegister(org.dom4j.Document document)
Parse theDocument
for the global project register.static <T> org.dom4j.Element
simpleElement(String name, T content)
Create a simple element with name and content.static <T> org.dom4j.Element
writeProperty(@NonNull String name, T value, String type)
Create a<property>
element with "name", "value" and "type" attributes.static <T> org.dom4j.Element
writeProperty(String name, T value)
Create a<property>
element with "name", "value" and "type" attributes.static org.dom4j.Document
writeRegister(List<IndexEntry> projects)
Create theDocument
for the global project register.
-
-
-
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 elementsconsumer
- 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 attributesconsumer
- 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 propertyvalue
- 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 propertyvalue
- value of the propertytype
- 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 elementsparent
- parent elementaction
- consumer of the children
-
writeRegister
public static org.dom4j.Document writeRegister(List<IndexEntry> projects)
Create theDocument
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 theDocument
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 elementsparent
- parent elementaction
- 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 tolist
- list of value to map and appendaction
- 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 elementcontent
- content of the simple element to stringify- Returns:
- element with name and string content
-
-