Class XmlNavigator

java.lang.Object
org.cip4.lib.xjdf.xml.internal.XmlNavigator
Direct Known Subclasses:
XJdfNavigator

public class XmlNavigator extends Object
Navigator class which simplify XPath handling using XML Documents.
  • Field Details

  • Constructor Details

  • Method Details

    • getXmlDocument

      public Document getXmlDocument()
      Getter for xmlDocument attribute.
      Returns:
      the xmlDocument
    • addNamespace

      public void addNamespace(String prefix, String uri)
      Add XML Namespace if navigator works namespace aware.
      Parameters:
      prefix - Prefix of Namespace.
      uri - Namespace URI.
    • readAttribute

      public String readAttribute(String xPath) throws XPathExpressionException
      Read attribute from XML Document using XPath.
      Parameters:
      xPath - XPath expression of attribute to read.
      Returns:
      Value of attribute as String.
      Throws:
      XPathExpressionException - Is being thrown in case an exception occurs.
    • readAttribute

      public Object readAttribute(String xPath, Class xJdfType) throws XPathExpressionException, ReflectiveOperationException
      Read attribute from XML Document using XPath and convert to JDF Datatype.
      Parameters:
      xPath - XPath expression to evaluate.
      xJdfType - Target JDF Data Type of attribute.
      Returns:
      Value as JDF Data Type.
      Throws:
      XPathExpressionException - Is thrown in case an XPath Exception occurs.
      ReflectiveOperationException - Is thrown in case reflection fails.
    • evaluateDouble

      public double evaluateDouble(String xPath) throws XPathExpressionException
      Evaluates an XPath expression on XML Document and returns a Double object as result.
      Parameters:
      xPath - XPath expression to execute to.
      Returns:
      Expression result as double.
      Throws:
      XPathExpressionException - Is thrown in case an XPath Exception occurs.
    • evaluateInt

      public Integer evaluateInt(String xPath) throws XPathExpressionException
      Evaluates an XPath expression on XML Document and returns an Integer value as result.
      Parameters:
      xPath - XPath expression to execute to.
      Returns:
      Expression result as integer.
      Throws:
      XPathExpressionException - Is thrown in case an XPath Exception occurs.
    • evaluateLong

      public Long evaluateLong(String xPath) throws XPathExpressionException
      Evaluates an XPath expression on XML Document and returns an Long value as result.
      Parameters:
      xPath - XPath expression to execute to.
      Returns:
      Expression result as long.
      Throws:
      XPathExpressionException - Is thrown in case an XPath Exception occurs.
    • evaluateString

      public String evaluateString(String xPath) throws XPathExpressionException
      Evaluates an XPath expression on XML Document and returns a String object as result.
      Parameters:
      xPath - XPath expression to execute to.
      Returns:
      Expression result as string.
      Throws:
      XPathExpressionException - Is thrown in case an XPath Exception occurs.
    • evaluateNode

      public Node evaluateNode(String xPath) throws XPathExpressionException
      Evaluates an XPath expression on XML Document and returns a Node object as result.
      Parameters:
      xPath - XPath expression to execute to.
      Returns:
      Expression result as node.
      Throws:
      XPathExpressionException - Is thrown in case an XPath Exception occurs.
    • evaluateNodeList

      public NodeList evaluateNodeList(String xPath) throws XPathExpressionException
      Evaluates an XPath expression on XML Document and returns a NodeList object as result.
      Parameters:
      xPath - XPath expression to execute to.
      Returns:
      Expression result as node list.
      Throws:
      XPathExpressionException - Is thrown in case an XPath Exception occurs.
    • evaluate

      public final <T extends AbstractXJdfType> T evaluate(String xPath, Class<T> xJdfType) throws XPathExpressionException, ReflectiveOperationException
      Evaluates an XPath expression on XML Document and returns the result as XJDF DataType.
      Type Parameters:
      T - Type of the desired value object.
      Parameters:
      xPath - XPath expression to execute to.
      xJdfType - The desired result data type.
      Returns:
      Result as desired data type.
      Throws:
      XPathExpressionException - Is thrown in case an XPath Exception occurs.
      ReflectiveOperationException - Is thrown in case reflection fails.
    • extractNode

      protected Object extractNode(String xPath, AbstractXmlParser parser) throws XPathExpressionException, javax.xml.bind.JAXBException
      Extract an XML Node from XML Document and return parsed result.
      !! WORKS ONLY IF NAVIGATOR IS NAMESPACE AWARE !!
      Parameters:
      xPath - XPath expression in order to locate the node.
      Returns:
      Expression result as parsed XML Node object.
      Throws:
      XPathExpressionException - Is thrown in case an XPath Exception occurs.
      javax.xml.bind.JAXBException
    • removeNode

      public void removeNode(String xPath) throws XPathExpressionException
      Remove a node from XML Document locaed by the XPath expression.
      Parameters:
      xPath - Location of the node to be removed.
      Throws:
      XPathExpressionException
    • replaceNode

      protected void replaceNode(String xPath, Object replacement, AbstractXmlParser parser) throws XPathExpressionException, javax.xml.bind.JAXBException, ParserConfigurationException
      Replace a node in XML Document located by the XPath expression.
      !! WORKS ONLY IF NAVIGATOR IS NAMESPACE AWARE !!
      Parameters:
      xPath - Location of the node to be replaced.
      replacement - The new node.
      parser - XML Parser.
      Throws:
      XPathExpressionException
      javax.xml.bind.JAXBException
      ParserConfigurationException
    • evaluateBoolean

      public boolean evaluateBoolean(String xPath) throws XPathExpressionException
      Evaluate an XPath expression on XML Document and returns an Boolean value as result.
      Parameters:
      xPath - XPath expression to execute to.
      Returns:
      Expression result as boolean value.
      Throws:
      XPathExpressionException - Is thrown in case an XPath Exception occurs.
    • updateAttribute

      public void updateAttribute(String xPath, AbstractXJdfType value) throws XPathExpressionException
      Update attribute in XML Document.
      Parameters:
      xPath - XPath expression of attribute to read.
      value - New value of attribute defined by xPath.
      Throws:
      XPathExpressionException - Is thrown in case an XPath Exception occurs.
    • updateAttribute

      public void updateAttribute(String xPath, String value) throws XPathExpressionException
      Update attribute in XML Document.
      Parameters:
      xPath - XPath expression of attribute to read.
      value - New value of attribute defined by xPath.
      Throws:
      XPathExpressionException - Is thrown in case an XPath Exception occurs.
    • getXmlStream

      public InputStream getXmlStream() throws TransformerException, IOException
      Return the XML Document as input stream.
      Returns:
      XML document as input stream.
      Throws:
      TransformerException - If this document could not be transformed.
      IOException - If any IO errors occur.
    • getXmlBytes

      public byte[] getXmlBytes() throws TransformerException, IOException
      Return the XML Document as Byte Array.
      Returns:
      XML Document as Byte Array.
      Throws:
      TransformerException - If this document could not be transformed.
      IOException - - If any IO errors occur.