Class SimpleXPathBasedCheck
- java.lang.Object
-
- org.sonarsource.analyzer.commons.xml.checks.SonarXmlCheck
-
- org.sonarsource.analyzer.commons.xml.checks.SimpleXPathBasedCheck
-
public abstract class SimpleXPathBasedCheck extends SonarXmlCheck
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.sonarsource.analyzer.commons.xml.checks.SonarXmlCheck
SonarXmlCheck.Secondary
-
-
Constructor Summary
Constructors Constructor Description SimpleXPathBasedCheck()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NodeList
evaluate(XPathExpression expression, Node node)
Evaluates a XPath expression on a given node from DOM.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.XPathExpression
getXPathExpression(String expression)
Compiles an XPath 1.0 expression-
Methods inherited from class org.sonarsource.analyzer.commons.xml.checks.SonarXmlCheck
inputFile, reportIssue, reportIssue, reportIssueOnFile, ruleKey, scanFile, scanFile
-
-
-
-
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 usinggetXPathExpression(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 usinggetXPathExpression(String)
node
- The node to use as starting point of the XPath expression- Returns:
- The list of nodes, possibly empty, matching the XPath expression.
-
-