Package cz.martlin.xspf.util
Class XMLDocumentUtilityHelper
- java.lang.Object
-
- cz.martlin.xspf.util.XMLDocumentUtilityHelper
-
public class XMLDocumentUtilityHelper extends Object
The xml document utility helper, the actual implementor of the DOM manipulation on the low-level.- Author:
- martin
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceXMLDocumentUtilityHelper.NonNullTextToValueMapper<T>An mapping of the text (never null) obtained from the XML file to some particular java type.static interfaceXMLDocumentUtilityHelper.NonNullValueToTextMapper<T>An mapping of the particular java object (never null) to text to fill into the XML file.static interfaceXMLDocumentUtilityHelper.NullableTextToValueMapper<T>An mapping of the text (or null) obtained from the XML file to some particular java type.static interfaceXMLDocumentUtilityHelper.NullableValueToTextMapper<T>An mapping of the particular java object (or null) to text to fill into the XML file.
-
Constructor Summary
Constructors Constructor Description XMLDocumentUtilityHelper(String nsName, String nsURL)Creates instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(Node owner, Element child)Adds the given child element.Elementclone(Element elem)Clones the given elment.ElementcreateChild(Node owner, String elemName)Creates (and appends) child element of the given owner.ElementcreateNew(Node context, String elemName)Creates new element of the given name in the given context (any node or the whole document).StringgetAttrValue(Element elem, String attrName)Returns the value of the given element's attribute.StringgetAttrValueOrNull(Element elem, String attrName)Returns the value of the given element's attribute.StringgetElementValue(Element elem)Returns the value of the given element's content.StringgetElementValueOrNull(Element elem)Returns the value of the given element's content.ElementgetChildOrNull(Node owner, String elemName)Returns the child element of the given owner.java.util.stream.Stream<Element>getChildren(Node owner, String elemName)Returns the child elements of the given owner (having given name).ElementgetOrCreateChild(Node owner, String elemName)Returns the child element of the given owner.booleanhasChildren(Node owner, String elemName)Returns true whether the given owner has any child elements having the given name.voidremoveChild(Node owner, Element child)Removes the given child element.voidsetAttrValue(Element elem, String attrName, String value)Sets the value of the given element's attribute.voidsetElementValue(Element elem, String value)Sets the value of the given element's content.voidspecifyNSattribute(Element elem)Sets the namespace declaration attribute to the given element.<T> TtextToValue(String text, XMLDocumentUtilityHelper.NullableTextToValueMapper<T> mapper)Converts the given text to value of particular type by the given mapper.<T> StringvalueToText(T value, XMLDocumentUtilityHelper.NullableValueToTextMapper<T> mapper)Converts the given value of particular type to text by the given mapper.
-
-
-
Method Detail
-
specifyNSattribute
public void specifyNSattribute(Element elem) throws XSPFException
Sets the namespace declaration attribute to the given element.- Parameters:
elem-- Throws:
XSPFException
-
createNew
public Element createNew(Node context, String elemName) throws XSPFException
Creates new element of the given name in the given context (any node or the whole document).- Parameters:
context-elemName-- Returns:
- Throws:
XSPFException
-
createChild
public Element createChild(Node owner, String elemName) throws XSPFException
Creates (and appends) child element of the given owner.- Parameters:
owner-elemName-- Returns:
- Throws:
XSPFException
-
getChildOrNull
public Element getChildOrNull(Node owner, String elemName) throws XSPFException
Returns the child element of the given owner. Returns null if no such, fails if more.- Parameters:
owner-elemName-- Returns:
- Throws:
XSPFException
-
getOrCreateChild
public Element getOrCreateChild(Node owner, String elemName) throws XSPFException
Returns the child element of the given owner. Creates and appends if no such, fails if more.- Parameters:
owner-elemName-- Returns:
- Throws:
XSPFException
-
getChildren
public java.util.stream.Stream<Element> getChildren(Node owner, String elemName) throws XSPFException
Returns the child elements of the given owner (having given name).- Parameters:
owner-elemName-- Returns:
- Throws:
XSPFException
-
hasChildren
public boolean hasChildren(Node owner, String elemName) throws XSPFException
Returns true whether the given owner has any child elements having the given name.- Parameters:
owner-elemName-- Returns:
- Throws:
XSPFException
-
addChild
public void addChild(Node owner, Element child) throws XSPFException
Adds the given child element.- Parameters:
owner-child-- Throws:
XSPFException
-
removeChild
public void removeChild(Node owner, Element child) throws XSPFException
Removes the given child element.- Parameters:
owner-child-- Throws:
XSPFException
-
getElementValue
public String getElementValue(Element elem) throws XSPFException
Returns the value of the given element's content. Fails if no such.- Parameters:
elem-- Returns:
- Throws:
XSPFException
-
getElementValueOrNull
public String getElementValueOrNull(Element elem) throws XSPFException
Returns the value of the given element's content. Returns null if no such.- Parameters:
elem-- Returns:
- Throws:
XSPFException
-
setElementValue
public void setElementValue(Element elem, String value)
Sets the value of the given element's content.- Parameters:
elem-value-
-
getAttrValue
public String getAttrValue(Element elem, String attrName) throws XSPFException
Returns the value of the given element's attribute. Fails if no such.- Parameters:
elem-attrName-- Returns:
- Throws:
XSPFException
-
getAttrValueOrNull
public String getAttrValueOrNull(Element elem, String attrName) throws XSPFException
Returns the value of the given element's attribute. Returns null if no such.- Parameters:
elem-attrName-- Returns:
- Throws:
XSPFException
-
setAttrValue
public void setAttrValue(Element elem, String attrName, String value)
Sets the value of the given element's attribute.- Parameters:
elem-attrName-value-
-
textToValue
public <T> T textToValue(String text, XMLDocumentUtilityHelper.NullableTextToValueMapper<T> mapper) throws XSPFException
Converts the given text to value of particular type by the given mapper.- Type Parameters:
T-- Parameters:
text-mapper-- Returns:
- Throws:
XSPFException
-
valueToText
public <T> String valueToText(T value, XMLDocumentUtilityHelper.NullableValueToTextMapper<T> mapper) throws XSPFException
Converts the given value of particular type to text by the given mapper.- Type Parameters:
T-- Parameters:
value-mapper-- Returns:
- Throws:
XSPFException
-
-