Class MicroHelper


  • @Immutable
    public final class MicroHelper
    extends Object
    Some utility methods on micro nodes.
    Author:
    Philip Helger
    • Method Detail

      • 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 be null.
        sSep - The separator to be put between each level. For XPath e.g. use "/"
        Returns:
        A non-null string. If the passed node is null, 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 be null.
        Returns:
        null if the passed document was null or if no document element is present. The tag name otherwise.
      • 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 be null.
        sChildElementName - The name of the child element who's text content is to be extracted.
        Returns:
        null if 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 be null.
        sChildElementName - The name of the child element who's text content is to be extracted.
        Returns:
        null if 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 the TypeConverter to the desired destination type.
        Type Parameters:
        DSTTYPE - Destination type
        Parameters:
        eParentElement - The parent element to use. May not be null.
        sChildElementName - The name of the child element who's text content is to be extracted.
        aDstClass - The destination class. May not be null.
        Returns:
        null if 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 be null.
        sNamespaceURI - The expected namespace URI of the element.
        sChildElementName - The name of the child element who's text content is to be extracted.
        Returns:
        null if 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 be null.
        sNamespaceURI - The expected namespace URI of the element.
        sChildElementName - The name of the child element who's text content is to be extracted.
        Returns:
        null if 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 the TypeConverter to the desired destination type.
        Type Parameters:
        DSTTYPE - Destination type
        Parameters:
        eParentElement - The parent element to use. May not be null.
        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 be null.
        Returns:
        null if 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 be null.
        Returns:
        The micro container and never null but 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 be null.
        Returns:
        The micro container and never null but maybe empty.