Search in sources :

Example 6 with BaseXPath

use of org.jaxen.BaseXPath in project pmd by pmd.

the class DocumentNavigatorTest method testXPath.

@Test
public void testXPath() throws JaxenException {
    BaseXPath xPath = new BaseXPath(".//*", new DocumentNavigator());
    List<?> matches = xPath.selectNodes(rule.statement);
    assertEquals(6, matches.size());
}
Also used : BaseXPath(org.jaxen.BaseXPath) DocumentNavigator(net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator) Test(org.junit.Test)

Example 7 with BaseXPath

use of org.jaxen.BaseXPath in project mycore by MyCoRe-Org.

the class MCRRepeatBinding method getElementNameWithPredicates.

@SuppressWarnings("unchecked")
public String getElementNameWithPredicates() throws JaxenException {
    BaseXPath baseXPath = new BaseXPath(xPath, new DocumentNavigator());
    Expr rootExpr = baseXPath.getRootExpr();
    LocationPath locationPath = (LocationPath) rootExpr;
    List<Step> steps = locationPath.getSteps();
    Step lastStep = steps.get(steps.size() - 1);
    return MCRNodeBuilder.simplify(lastStep.getText());
}
Also used : Expr(org.jaxen.expr.Expr) LocationPath(org.jaxen.expr.LocationPath) BaseXPath(org.jaxen.BaseXPath) Step(org.jaxen.expr.Step) DocumentNavigator(org.jaxen.dom.DocumentNavigator)

Example 8 with BaseXPath

use of org.jaxen.BaseXPath in project mycore by MyCoRe-Org.

the class MCRXEditorTransformer method createRootElement.

private Element createRootElement(String xPath) throws JaxenException {
    BaseXPath baseXPath = new BaseXPath(xPath, new DocumentNavigator());
    LocationPath lp = (LocationPath) (baseXPath.getRootExpr());
    NameStep nameStep = (NameStep) (lp.getSteps().get(0));
    String prefix = nameStep.getPrefix();
    Namespace ns = prefix.isEmpty() ? Namespace.NO_NAMESPACE : MCRConstants.getStandardNamespace(prefix);
    return new Element(nameStep.getLocalName(), ns);
}
Also used : LocationPath(org.jaxen.expr.LocationPath) BaseXPath(org.jaxen.BaseXPath) Element(org.jdom2.Element) NameStep(org.jaxen.expr.NameStep) DocumentNavigator(org.jaxen.dom.DocumentNavigator) Namespace(org.jdom2.Namespace)

Aggregations

BaseXPath (org.jaxen.BaseXPath)8 DocumentNavigator (net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator)3 LocationPath (org.jaxen.expr.LocationPath)3 JaxenException (org.jaxen.JaxenException)2 DocumentNavigator (org.jaxen.dom.DocumentNavigator)2 Expr (org.jaxen.expr.Expr)2 NameStep (org.jaxen.expr.NameStep)2 Step (org.jaxen.expr.Step)2 Test (org.junit.Test)2 TemplateModelException (freemarker.template.TemplateModelException)1 UndeclaredThrowableException (freemarker.template.utility.UndeclaredThrowableException)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ParseException (net.sourceforge.pmd.lang.ast.ParseException)1 PropertyDescriptor (net.sourceforge.pmd.properties.PropertyDescriptor)1 SimpleVariableContext (org.jaxen.SimpleVariableContext)1 XPath (org.jaxen.XPath)1