Class SimpleXPathBasedCheck


  • public abstract class SimpleXPathBasedCheck
    extends SonarXmlCheck
    • Constructor Detail

      • SimpleXPathBasedCheck

        public SimpleXPathBasedCheck()
    • Method Detail

      • getXPathExpression

        public XPathExpression getXPathExpression​(String expression)
        Compiles an XPath 1.0 expression
        Parameters:
        expression - The expression to be compiled in XPath, as a String
        Returns:
        The compiled expression
        Throws:
        IllegalStateException - When the XPath expression can not be compiled by the XPath engine. Could occur with invalid expression, or incompatible XPath version.
      • evaluate

        @CheckForNull
        public NodeList evaluate​(XPathExpression expression,
                                 Node node)
        Evaluates a XPath expression on a given node from DOM. The only situation where null is returned is when XPath fails to evaluate the expression. This could occur with strangely built DOM. Note that in such case, the check will log extra information if the debug level is set.
        Parameters:
        expression - The XPath expression to be used, preferably compiled using getXPathExpression(String)
        node - The node to use as starting point of the XPath expression
        Returns:
        The list of nodes, possibly empty, matching the XPath expression. Note that it will return null only when XPath fails to evaluate the expression.
      • evaluateAsList

        public List<Node> evaluateAsList​(XPathExpression expression,
                                         Node node)
        Evaluates a XPath expression on a given node from DOM, returning it as a java List of Node, possibly empty.
        Parameters:
        expression - The XPath expression to be used, preferably compiled using getXPathExpression(String)
        node - The node to use as starting point of the XPath expression
        Returns:
        The list of nodes, possibly empty, matching the XPath expression.