Class CFNode


  • public class CFNode
    extends Object
    A node in a configuration. Note that if there is inheritance, this will be backed by mutliple Nodes, otherwise just a single one.
    • Constructor Detail

      • CFNode

        public CFNode()
      • CFNode

        public CFNode​(Node node)
      • CFNode

        public CFNode​(List<Node> nodes)
    • Method Detail

      • size

        public int size()
      • getNodes

        public List<Node> getNodes()
      • setNodes

        public void setNodes​(List<Node> nodes)
      • hasNodes

        public boolean hasNodes()
      • getName

        public String getName()
      • getFirstAttribute

        public String getFirstAttribute​(String name)
        Get the very first attribute with the given name found in the nodes. A null is returned if there is no such value.
        Parameters:
        name -
        Returns:
      • getFirstAttribute

        public String getFirstAttribute​(String name,
                                        String defaultValue)
      • getAttributes

        public List<String> getAttributes​(String name)
        Returns all attributes as strings.
        Parameters:
        name -
        Returns:
      • getAttributes

        public Map<String,​String> getAttributes()
        Return all the attributes as a map. You must convert these to whatever they are supposed to be. Note that this does resolve overrides.
        Returns:
      • getLongAttributes

        public List<Long> getLongAttributes​(String name)
        Returns all the long values for the attribute. This does not flag errors, it just skips them.
        Parameters:
        name -
        Returns:
      • getBooleanAttributes

        public List<Boolean> getBooleanAttributes​(String name)
        returns the boolean values for the attribute. It does not flag bad ones, it just skips them.
        Parameters:
        name -
        Returns:
      • getFirstNode

        public CFNode getFirstNode​(String name)
        Return the first named child configuration node of the given node or null if there is no such named child. Very useful if your specification only allows for a single child node.
        Parameters:
        name -
        Returns:
      • getChildren

        public List<CFNode> getChildren​(String name)
        The contract is that this will return all the named children nodes of the given node in order So if the argument is [node0,node1,...] Then result is all the children of node0, followed by all the children of node1,... Note that you can feed the result of this list back in to get the next level of children.
        Returns:
      • getChildren

        public List<CFNode> getChildren()
        Get non-text (so type is text or comment) child nodes.
        Returns:
      • getChildren

        public List<CFNode> getChildren​(boolean nonTextOnly)
        Return children with possible filtering for text nodes. In most applications you do not want just whitespace.
        Parameters:
        nonTextOnly -
        Returns:
      • getParent

        public CFNode getParent()
      • getFirstChild

        public CFNode getFirstChild​(String name)
        Convenience method to get the zero-th node or null if there is none. In many cases you know there is exactly a single node and you just want that.
        Parameters:
        name -
        Returns:
      • getNodes

        public CFNode getNodes​(String name)
        Use this to get all the named nodes off the list. Rather than overrides, this returns the kitchen sink. This is the equivalent of glomming together all of the like-named nodes into one big virtual node. This also gets other nodes in the configuration too so if there are multiple ones in any configuration, they are added in as well.

        Sometimes this is necessary.

        Parameters:
        name -
        Returns:
      • getNodeContents

        public String getNodeContents​(String name,
                                      String defaultValue)
        Convenience method for getting the value of a single named child node, i.e. the contents, so

        <foo>value</foo>

        would have name equal to 'foo' and return the string 'value'. Returns the default value if no such value is found.
        Parameters:
        name -
        defaultValue -
        Returns:
      • getNodeContents

        public String getNodeContents()
        Get the contents of the current node.
        Returns:
      • getNodeContents

        public String getNodeContents​(String name)
        Convenience method for getting the value of a single node, i.e. the contents, so

        <foo>value</foo>

        would have name equal to 'foo' and return the string 'value'. Returns a null if no such value is found. This is also clever enough to pull things out of CDATA nodes.
        Parameters:
        name -
        Returns:
      • getFirstBooleanValue

        public boolean getFirstBooleanValue​(String attrib,
                                            boolean defaultValue)
        Finds the first attribute with the given name and then converts to boolean. If the conversion fails, the default is returned. This supports values of true, false, on, off.
        Parameters:
        attrib -
        defaultValue -
        Returns:
      • getFirstBooleanValue

        public Boolean getFirstBooleanValue​(String attrib)
        Get the first attribute and return a boolean. Note that this supports values of StringUtils.LOGICAL_TRUES and StringUtils.LOGICAL_FALSES. If no such value is found, an error is raised, since use of this method asserts the value is a boolean.
        Parameters:
        attrib -
        Returns:
      • getFirstLongAttribute

        public Long getFirstLongAttribute​(String attrib)
        Return the value as a long Long. If no such value, a null is returned. If the value fails to parse as a long, an illegal argument exception is raised
        Parameters:
        attrib -
        Returns:
      • getFirstLongAttribute

        public long getFirstLongAttribute​(String attrib,
                                          long defaultValue)
        Get the first attribute that is a long. If no such attribute, return the default value.
        Parameters:
        attrib -
        defaultValue -
        Returns:
      • getAttributeInNode

        public String getAttributeInNode​(String nodeName,
                                         String attributeName)
        Looks for the given node and returns the first attribute. This is the method that lets you override a single attribute in a tag.
        Parameters:
        nodeName -
        attributeName -
        Returns: