java.lang.Object
org.rrd4j.core.Util.Xml
- Enclosing class:
Util
Various DOM utility functions.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classSingletonHelper class.Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ErrorHandlerHandler reporting XML errors through the logging system.Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionstatic Node[]getChildNodes(Node parentNode) Returns every element child of the given nodestatic Node[]getChildNodes(Node parentNode, String childName) Returns the element children of the given node whose name matchesstatic StringgetChildValue(Node parentNode, String childName) Returns the trimmed text of the first child element carrying the requested namestatic StringgetChildValue(Node parentNode, String childName, boolean trim) Returns the text of the first child element carrying the requested namestatic booleangetChildValueAsBoolean(Node parentNode, String childName) Reads a child element's text as a booleanstatic doublegetChildValueAsDouble(Node parentNode, String childName) Reads a child element's text as adouble, yielding NaN when unparsablestatic intgetChildValueAsInt(Node parentNode, String childName) Reads a child element's text as anintstatic longgetChildValueAsLong(Node parentNode, String childName) Reads a child element's text as alongstatic NodegetFirstChildNode(Node parentNode, String childName) Returns the first element child carrying the requested namestatic ElementgetRootElement(File xmlFile) Parses an RRD XML file, read as UTF-8, and returns its root elementstatic ElementgetRootElement(String xmlString) Parses RRD XML held in a string and returns its root elementstatic ElementgetRootElement(InputSource inputSource) Parses an RRD XML document and returns its root elementstatic StringReturns the trimmed text of the node's first childstatic StringReturns the text of the node's first childstatic booleangetValueAsBoolean(Node node) Reads a node's text as a booleanstatic doublegetValueAsDouble(Node node) Reads a node's text as adouble, yielding NaN when unparsablestatic intgetValueAsInt(Node node) Reads a node's text as anintstatic longgetValueAsLong(Node node) Reads a node's text as alongstatic booleanhasChildNode(Node parentNode, String childName) Checks whether the given node has an element child of the requested name
Field Details
eh
Handler reporting XML errors through the logging system.
Constructor Details
Xml
private Xml()Utility class, not intended for instantiation.
Method Details
getChildNodes
getChildNodes
Returns the element children of the given node whose name matches- Parameters:
parentNode- node whose children are collectedchildName- element name to match, ornullto accept every element- Returns:
- matching element children in document order, empty if there are none
getFirstChildNode
Returns the first element child carrying the requested name- Parameters:
parentNode- node whose children are searchedchildName- element name to match- Returns:
- the first matching element child
- Throws:
IllegalArgumentException- If no child carries that name
hasChildNode
getChildValue
Returns the trimmed text of the first child element carrying the requested name- Parameters:
parentNode- node whose children are searchedchildName- element name to match- Returns:
- text of the first matching child element, trimmed
- Throws:
IllegalStateException- If no child carries that name
getChildValue
Returns the text of the first child element carrying the requested name- Parameters:
parentNode- node whose children are searchedchildName- element name to matchtrim- whether to strip leading and trailing whitespace from the text- Returns:
- text of the first matching child element, trimmed if requested
- Throws:
IllegalStateException- If no child carries that name
getValue
getValue
Returns the text of the node's first child- Parameters:
node- element whose child supplies the texttrimValue- whether to strip leading and trailing whitespace from the text- Returns:
- text of the first child, trimmed if requested, or
nullif the node has no child at all (an empty element such as<x/>)
getChildValueAsInt
Reads a child element's text as anint- Parameters:
parentNode- node whose children are searchedchildName- element name to match- Returns:
- the text parsed as an int, typically a row or step count
- Throws:
IllegalStateException- If no child carries that nameNumberFormatException- If the text is not a valid int
getValueAsInt
Reads a node's text as anint- Parameters:
node- element whose child supplies the text- Returns:
- the text parsed as an int, typically a row or step count
- Throws:
NumberFormatException- If the text is not a valid int
getChildValueAsLong
Reads a child element's text as along- Parameters:
parentNode- node whose children are searchedchildName- element name to match- Returns:
- the text parsed as a long, typically a timestamp in seconds or a heartbeat span
- Throws:
IllegalStateException- If no child carries that nameNumberFormatException- If the text is not a valid long
getValueAsLong
Reads a node's text as along- Parameters:
node- element whose child supplies the text- Returns:
- the text parsed as a long, typically a timestamp in seconds or a heartbeat span
- Throws:
NumberFormatException- If the text is not a valid long
getChildValueAsDouble
Reads a child element's text as adouble, yielding NaN when unparsable- Parameters:
parentNode- node whose children are searchedchildName- element name to match- Returns:
- the text parsed as a double, or NaN if it is not a valid double
- Throws:
IllegalStateException- If no child carries that name
getValueAsDouble
Reads a node's text as adouble, yielding NaN when unparsable- Parameters:
node- element whose child supplies the text- Returns:
- the text parsed as a double, or NaN if it is not a valid double
getChildValueAsBoolean
Reads a child element's text as a boolean- Parameters:
parentNode- node whose children are searchedchildName- element name to match- Returns:
truefor true/on/yes/y/1 (any case),falsefor anything else including a missing text- Throws:
IllegalStateException- If no child carries that name
getValueAsBoolean
Reads a node's text as a boolean- Parameters:
node- element whose child supplies the text- Returns:
truefor true/on/yes/y/1 (any case),falsefor anything else including a missing text
getRootElement
Parses an RRD XML document and returns its root element- Parameters:
inputSource- source of the XML text, for example a file or a string reader- Returns:
- the document element of the parsed document
- Throws:
IOException- Thrown if the source cannot be readRuntimeException- Thrown if the source is not well-formed XML
getRootElement
Parses RRD XML held in a string and returns its root element- Parameters:
xmlString- the XML text- Returns:
- the document element of the parsed document
- Throws:
IOException- Thrown if the string cannot be readRuntimeException- Thrown if the string is not well-formed XML
getRootElement
Parses an RRD XML file, read as UTF-8, and returns its root element- Parameters:
xmlFile- file holding the XML text- Returns:
- the document element of the parsed document
- Throws:
IOException- Thrown if the file cannot be opened or readRuntimeException- Thrown if the file is not well-formed XML