Package com.helger.xml.microdom.util
Class MicroHelper
- java.lang.Object
-
- com.helger.xml.microdom.util.MicroHelper
-
@Immutable public final class MicroHelper extends Object
Some utility methods on micro nodes.- Author:
- Philip Helger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static IMicroNodeappend(IMicroNode aSrcNode, Object aChild)static IMicroNodeconvertToMicroNode(Node aNode)static IMicroContainergetAllChildrenAsContainer(IMicroNode aParent)Create a micro container with all children of the passed node.static IMicroContainergetAllOriginalChildrenAsContainer(IMicroNode aParent)Create a micro container with all children of the passed node.static StringgetChildTextContent(IMicroElement eParentElement, String sChildElementName)Helper method to extract the text content of the child element denoted by the parameter sChildElementName of the passed parent element.static StringgetChildTextContent(IMicroElement eParentElement, String sNamespaceURI, String sChildElementName)Helper method to extract the text content of the child element denoted by the parameters sNamespaceURI and sChildElementName of the passed parent element.static StringgetChildTextContentTrimmed(IMicroElement eParentElement, String sChildElementName)Helper method to extract the text content of the child element denoted by the parameter sChildElementName of the passed parent element.static StringgetChildTextContentTrimmed(IMicroElement eParentElement, String sNamespaceURI, String sChildElementName)Helper method to extract the text content of the child element denoted by the parameters sNamespaceURI and sChildElementName of the passed parent element.static <DSTTYPE> DSTTYPEgetChildTextContentWithConversion(IMicroElement eParentElement, String sChildElementName, Class<DSTTYPE> aDstClass)Helper method to extract the text content of the child element denoted by the parameter sChildElementName of the passed parent element.static <DSTTYPE> DSTTYPEgetChildTextContentWithConversion(IMicroElement eParentElement, String sNamespaceURI, String sChildElementName, Class<DSTTYPE> aDstClass)Helper method to extract the text content of the child element denoted by the parameters sNamespaceURI and sChildElementName of the passed parent element.static StringgetDocumentRootElementTagName(IMicroDocument aDoc)Get the tag name of the passed documents root element.static StringgetPath(IMicroNode aNode, String sSep)Get the path of the given node, up to the root element.
-
-
-
Method Detail
-
append
@Nonnull public static IMicroNode append(@Nonnull IMicroNode aSrcNode, @Nullable Object aChild)
-
getPath
@Nonnull public static String getPath(@Nullable IMicroNode aNode, @Nonnull String sSep)
Get the path of the given node, up to the root element.- Parameters:
aNode- The node to get the path from. May benull.sSep- The separator to be put between each level. For XPath e.g. use "/"- Returns:
- A non-
nullstring. If the passed node isnull, the return value is an empty string.
-
getDocumentRootElementTagName
@Nullable public static String getDocumentRootElementTagName(@Nullable IMicroDocument aDoc)
Get the tag name of the passed documents root element.- Parameters:
aDoc- The document to be evaluated. May benull.- Returns:
nullif the passed document wasnullor if no document element is present. The tag name otherwise.
-
convertToMicroNode
@Nonnull public static IMicroNode convertToMicroNode(@Nonnull Node aNode)
-
getChildTextContent
@Nullable public static String getChildTextContent(@Nonnull IMicroElement eParentElement, @Nonnull String sChildElementName)
Helper method to extract the text content of the child element denoted by the parameter sChildElementName of the passed parent element.- Parameters:
eParentElement- The parent element to use. May not benull.sChildElementName- The name of the child element who's text content is to be extracted.- Returns:
nullif the child element does not exist or the child element does not contain any text.
-
getChildTextContentTrimmed
@Nullable public static String getChildTextContentTrimmed(@Nonnull IMicroElement eParentElement, @Nonnull String sChildElementName)
Helper method to extract the text content of the child element denoted by the parameter sChildElementName of the passed parent element. After concatenation, all leading and trailing spaces are removed.- Parameters:
eParentElement- The parent element to use. May not benull.sChildElementName- The name of the child element who's text content is to be extracted.- Returns:
nullif the child element does not exist or the child element does not contain any text.
-
getChildTextContentWithConversion
@Nullable public static <DSTTYPE> DSTTYPE getChildTextContentWithConversion(@Nonnull IMicroElement eParentElement, @Nonnull String sChildElementName, @Nonnull Class<DSTTYPE> aDstClass)
Helper method to extract the text content of the child element denoted by the parameter sChildElementName of the passed parent element. The read text content is converted via theTypeConverterto the desired destination type.- Type Parameters:
DSTTYPE- Destination type- Parameters:
eParentElement- The parent element to use. May not benull.sChildElementName- The name of the child element who's text content is to be extracted.aDstClass- The destination class. May not benull.- Returns:
nullif the child element does not exist or the child element does not contain any text.
-
getChildTextContent
@Nullable public static String getChildTextContent(@Nonnull IMicroElement eParentElement, @Nonnull String sNamespaceURI, @Nonnull String sChildElementName)
Helper method to extract the text content of the child element denoted by the parameters sNamespaceURI and sChildElementName of the passed parent element.- Parameters:
eParentElement- The parent element to use. May not benull.sNamespaceURI- The expected namespace URI of the element.sChildElementName- The name of the child element who's text content is to be extracted.- Returns:
nullif the child element does not exist or the child element does not contain any text.
-
getChildTextContentTrimmed
@Nullable public static String getChildTextContentTrimmed(@Nonnull IMicroElement eParentElement, @Nonnull String sNamespaceURI, @Nonnull String sChildElementName)
Helper method to extract the text content of the child element denoted by the parameters sNamespaceURI and sChildElementName of the passed parent element. After concatenation, all leading and trailing spaces are removed.- Parameters:
eParentElement- The parent element to use. May not benull.sNamespaceURI- The expected namespace URI of the element.sChildElementName- The name of the child element who's text content is to be extracted.- Returns:
nullif the child element does not exist or the child element does not contain any text.
-
getChildTextContentWithConversion
@Nullable public static <DSTTYPE> DSTTYPE getChildTextContentWithConversion(@Nonnull IMicroElement eParentElement, @Nonnull String sNamespaceURI, @Nonnull String sChildElementName, @Nonnull Class<DSTTYPE> aDstClass)
Helper method to extract the text content of the child element denoted by the parameters sNamespaceURI and sChildElementName of the passed parent element. The read text content is converted via theTypeConverterto the desired destination type.- Type Parameters:
DSTTYPE- Destination type- Parameters:
eParentElement- The parent element to use. May not benull.sNamespaceURI- The expected namespace URI of the element.sChildElementName- The name of the child element who's text content is to be extracted.aDstClass- The destination class. May not benull.- Returns:
nullif the child element does not exist or the child element does not contain any text.
-
getAllChildrenAsContainer
@Nonnull @ReturnsMutableCopy public static IMicroContainer getAllChildrenAsContainer(@Nonnull IMicroNode aParent)
Create a micro container with all children of the passed node. If the passed node has no children, an empty object is returned. The resulting container contains a clone of each child node so that the original objects is not modified.- Parameters:
aParent- The parent node to get the children from. May not benull.- Returns:
- The micro container and never
nullbut maybe empty.
-
getAllOriginalChildrenAsContainer
@Nonnull @ReturnsMutableCopy public static IMicroContainer getAllOriginalChildrenAsContainer(@Nonnull IMicroNode aParent)
Create a micro container with all children of the passed node. If the passed node has no children, an empty object is returned. The resulting container contains the original child nodes so that they no longer belong to the original object. THis implies that the original object is modified!- Parameters:
aParent- The parent node to get the children from. May not benull.- Returns:
- The micro container and never
nullbut maybe empty.
-
-