org.rrd4j.core

## Class XmlTemplate

- java.lang.Object
- - org.rrd4j.core.XmlTemplate

- Direct Known Subclasses:
    RrdDefTemplate

      public abstract class XmlTemplate
      extends Object

  Class used as a base class for various XML template related classes. Class provides methods for XML source parsing and XML tree traversing. XML source may have unlimited number of placeholders (variables) in the format `${variable_name}`. Methods are provided to specify variable values at runtime. Note that this class has limited functionality: XML source gets parsed, and variable values are collected. You have to extend this class to do something more useful.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Element` | `root`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `XmlTemplate(File xmlFile)` Constructor for XmlTemplate.
    `protected` | `XmlTemplate(InputSource xmlSource)` Constructor for XmlTemplate.
    `protected` | `XmlTemplate(String xmlString)` Constructor for XmlTemplate.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clearValues()` Removes all placeholder-value mappings.
    `protected static Node[]` | `getChildNodes(Node parentNode)` getChildNodes.
    `protected static Node[]` | `getChildNodes(Node parentNode, String childName)` getChildNodes.
    `protected String` | `getChildValue(Node parentNode, String childName)` getChildValue.
    `protected String` | `getChildValue(Node parentNode, String childName, boolean trim)` getChildValue.
    `protected boolean` | `getChildValueAsBoolean(Node parentNode, String childName)` getChildValueAsBoolean.
    `protected double` | `getChildValueAsDouble(Node parentNode, String childName)` getChildValueAsDouble.
    `protected int` | `getChildValueAsInt(Node parentNode, String childName)` getChildValueAsInt.
    `protected long` | `getChildValueAsLong(Node parentNode, String childName)` getChildValueAsLong.
    `protected static Node` | `getFirstChildNode(Node parentNode, String childName)` getFirstChildNode.
    `protected String` | `getValue(Node parentNode)` getValue.
    `protected String` | `getValue(Node parentNode, boolean trim)` getValue.
    `protected boolean` | `getValueAsBoolean(Node parentNode)` getValueAsBoolean.
    `protected Paint` | `getValueAsColor(Node parentNode)` getValueAsColor.
    `protected double` | `getValueAsDouble(Node parentNode)` getValueAsDouble.
    `protected int` | `getValueAsInt(Node parentNode)` getValueAsInt.
    `protected long` | `getValueAsLong(Node parentNode)` getValueAsLong.
    `String[]` | `getVariables()` Returns the list of variables that should be set in this template.
    `protected boolean` | `hasChildNode(Node parentNode, String childName)` hasChildNode.
    `boolean` | `hasVariables()` Searches the XML template to see if there are variables in there that will need to be set.
    `protected boolean` | `isEmptyNode(Node node)` isEmptyNode.
    `void` | `setVariable(String name, boolean value)` Sets value for a single XML template variable.
    `void` | `setVariable(String name, Calendar value)` Sets value for a single XML template variable.
    `void` | `setVariable(String name, Color value)` Sets value for a single XML template variable.
    `void` | `setVariable(String name, Date value)` Sets value for a single XML template variable.
    `void` | `setVariable(String name, double value)` Sets value for a single XML template variable.
    `void` | `setVariable(String name, int value)` Sets value for a single XML template variable.
    `void` | `setVariable(String name, long value)` Sets value for a single XML template variable.
    `void` | `setVariable(String name, String value)` Sets value for a single XML template variable.
    `protected void` | `validateTagsOnlyOnce(Node parentNode, String[] allowedChildNames)` validateTagsOnlyOnce.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### root

          protected Element root

  - ### Constructor Detail

    - #### XmlTemplate

          protected XmlTemplate(File xmlFile)
                         throws IOException

      Constructor for XmlTemplate.
      Parameters:
        `xmlFile` - a `File` object.
      Throws:
        `IOException` - if any.

    - #### XmlTemplate

          protected XmlTemplate(InputSource xmlSource)
                         throws IOException

      Constructor for XmlTemplate.
      Parameters:
        `xmlSource` - a `InputSource` object.
      Throws:
        `IOException` - if any.

    - #### XmlTemplate

          protected XmlTemplate(String xmlString)
                         throws IOException

      Constructor for XmlTemplate.
      Parameters:
        `xmlString` - a `String` object.
      Throws:
        `IOException` - if any.

  - ### Method Detail

    - #### clearValues

          public void clearValues()

      Removes all placeholder-value mappings.

    - #### getChildNodes

          protected static Node[] getChildNodes(Node parentNode)

      getChildNodes.
      Parameters:
        `parentNode` - a `Node` object.
      Returns:
        an array of `Node` objects.

    - #### getChildNodes

          protected static Node[] getChildNodes(Node parentNode,
                                                String childName)

      getChildNodes.
      Parameters:
        `parentNode` - a `Node` object.
        `childName` - a `String` object.
      Returns:
        an array of `Node` objects.

    - #### getChildValue

          protected String getChildValue(Node parentNode,
                                         String childName)

      getChildValue.
      Parameters:
        `parentNode` - a `Node` object.
        `childName` - a `String` object.
      Returns:
        a `String` object.

    - #### getChildValue

          protected String getChildValue(Node parentNode,
                                         String childName,
                                         boolean trim)

      getChildValue.
      Parameters:
        `parentNode` - a `Node` object.
        `childName` - a `String` object.
        `trim` - a boolean.
      Returns:
        a `String` object.

    - #### getChildValueAsBoolean

          protected boolean getChildValueAsBoolean(Node parentNode,
                                                   String childName)

      getChildValueAsBoolean.
      Parameters:
        `parentNode` - a `Node` object.
        `childName` - a `String` object.
      Returns:
        a boolean.

    - #### getChildValueAsDouble

          protected double getChildValueAsDouble(Node parentNode,
                                                 String childName)

      getChildValueAsDouble.
      Parameters:
        `parentNode` - a `Node` object.
        `childName` - a `String` object.
      Returns:
        a double.

    - #### getChildValueAsInt

          protected int getChildValueAsInt(Node parentNode,
                                           String childName)

      getChildValueAsInt.
      Parameters:
        `parentNode` - a `Node` object.
        `childName` - a `String` object.
      Returns:
        a int.

    - #### getChildValueAsLong

          protected long getChildValueAsLong(Node parentNode,
                                             String childName)

      getChildValueAsLong.
      Parameters:
        `parentNode` - a `Node` object.
        `childName` - a `String` object.
      Returns:
        a long.

    - #### getFirstChildNode

          protected static Node getFirstChildNode(Node parentNode,
                                                  String childName)

      getFirstChildNode.
      Parameters:
        `parentNode` - a `Node` object.
        `childName` - a `String` object.
      Returns:
        a `Node` object.

    - #### getValue

          protected String getValue(Node parentNode)

      getValue.
      Parameters:
        `parentNode` - a `Node` object.
      Returns:
        a `String` object.

    - #### getValue

          protected String getValue(Node parentNode,
                                    boolean trim)

      getValue.
      Parameters:
        `parentNode` - a `Node` object.
        `trim` - a boolean.
      Returns:
        a `String` object.

    - #### getValueAsBoolean

          protected boolean getValueAsBoolean(Node parentNode)

      getValueAsBoolean.
      Parameters:
        `parentNode` - a `Node` object.
      Returns:
        a boolean.

    - #### getValueAsColor

          protected Paint getValueAsColor(Node parentNode)

      getValueAsColor.
      Parameters:
        `parentNode` - a `Node` object.
      Returns:
        a `Paint` object.

    - #### getValueAsDouble

          protected double getValueAsDouble(Node parentNode)

      getValueAsDouble.
      Parameters:
        `parentNode` - a `Node` object.
      Returns:
        a double.

    - #### getValueAsInt

          protected int getValueAsInt(Node parentNode)

      getValueAsInt.
      Parameters:
        `parentNode` - a `Node` object.
      Returns:
        a int.

    - #### getValueAsLong

          protected long getValueAsLong(Node parentNode)

      getValueAsLong.
      Parameters:
        `parentNode` - a `Node` object.
      Returns:
        a long.

    - #### getVariables

          public String[] getVariables()

      Returns the list of variables that should be set in this template.
      Returns:
        Array of variable names as an array of strings.

    - #### hasChildNode

          protected boolean hasChildNode(Node parentNode,
                                         String childName)

      hasChildNode.
      Parameters:
        `parentNode` - a `Node` object.
        `childName` - a `String` object.
      Returns:
        a boolean.

    - #### hasVariables

          public boolean hasVariables()

      Searches the XML template to see if there are variables in there that will need to be set.
      Returns:
        True if variables were detected, false if not.

    - #### isEmptyNode

          protected boolean isEmptyNode(Node node)

      isEmptyNode.
      Parameters:
        `node` - a `Node` object.
      Returns:
        a boolean.

    - #### setVariable

          public void setVariable(String name,
                                  boolean value)

      Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder `${start}`, specify `start` for the `name` parameter.
      Parameters:
        `name` - variable name
        `value` - value to be set in the XML template

    - #### setVariable

          public void setVariable(String name,
                                  Calendar value)

      Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder `${start}`, specify `start` for the `name` parameter.
      Parameters:
        `name` - variable name
        `value` - value to be set in the XML template

    - #### setVariable

          public void setVariable(String name,
                                  Color value)

      Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder `${start}`, specify `start` for the `name` parameter.
      Parameters:
        `name` - variable name
        `value` - value to be set in the XML template

    - #### setVariable

          public void setVariable(String name,
                                  Date value)

      Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder `${start}`, specify `start` for the `name` parameter.
      Parameters:
        `name` - variable name
        `value` - value to be set in the XML template

    - #### setVariable

          public void setVariable(String name,
                                  double value)

      Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder `${start}`, specify `start` for the `name` parameter.
      Parameters:
        `name` - variable name
        `value` - value to be set in the XML template

    - #### setVariable

          public void setVariable(String name,
                                  int value)

      Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder `${start}`, specify `start` for the `name` parameter.
      Parameters:
        `name` - variable name
        `value` - value to be set in the XML template

    - #### setVariable

          public void setVariable(String name,
                                  long value)

      Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder `${start}`, specify `start` for the `name` parameter.
      Parameters:
        `name` - variable name
        `value` - value to be set in the XML template

    - #### setVariable

          public void setVariable(String name,
                                  String value)

      Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder `${start}`, specify `start` for the `name` parameter.
      Parameters:
        `name` - variable name
        `value` - value to be set in the XML template

    - #### validateTagsOnlyOnce

          protected void validateTagsOnlyOnce(Node parentNode,
                                              String[] allowedChildNames)

      validateTagsOnlyOnce.
      Parameters:
        `parentNode` - a `Node` object.
        `allowedChildNames` - an array of `String` objects.