XPathParser { protected PathExpression parsePathExpr( TokenStream tokens ) { boolean relative = true; boolean prependDependentOrSelf = false; if (tokens.canConsume('/')) { if (tokens.canConsume('/')) { if (!tokens.hasNext()) { throw new ParsingException(tokens.previousPosition(), "' } prependDependentOrSelf = true; } relative = false; } PathExpression relativeExpr = parseRelativePathExpr(tokens); PathExpression result = new PathExpression(relative, relativeExpr.getSteps(), relativeExpr.getOrderBy()); if (prependDependentOrSelf) { result.getSteps().add(0, new DescendantOrSelf()); } return result; } XPathParser( TypeSystem context ); Component parseXPath( String xpath );  }
@Test public void shouldParsePathExpressionWithSpaceInPath() { assertThat(parser.parsePathExpr(tokenize("/a/b/c_x0020_d")), is(pathExpr(axisStep(nameTest("a")), axisStep(nameTest("b")), axisStep(nameTest("c d"))))); }
@Test public void shouldParsePathExpressionWithAbbreviatedDescendantOrSelfWithNameTestAfter() { assertThat(parser.parsePathExpr(tokenize(" }
@Test public void shouldParsePathExpressionWithAbbreviatedDescendantOrSelfWithRelativeNamePathPredicate() { assertThat(parser.parsePathExpr(tokenize(" is(pathExpr(descendantOrSelf(), filterStep(contextItem(), nameTest("c"))))); }
@Test public void shouldParsePathExpressionWithAbbreviatedDescendantOrSelfWithRelativeNumericLiteralPredicate() { assertThat(parser.parsePathExpr(tokenize(" is(pathExpr(descendantOrSelf(), filterStep(contextItem(), literal("3"))))); }
@Test public void shouldParsePathExpressionWithNameTestsAndWildcard() { assertThat(parser.parsePathExpr(tokenize("/jcr:root/a/b/*")), is(pathExpr(axisStep(nameTest("jcr", "root")), axisStep(nameTest("a")), axisStep(nameTest("b")), axisStep(wildcard())))); }
@Test public void shouldParsePathExpressionWithNameTestsAndWildcardAndPropertyExistence() { assertThat(parser.parsePathExpr(tokenize("/jcr:root/a/b/*[@prop]")), is(pathExpr(axisStep(nameTest("jcr", "root")), axisStep(nameTest("a")), axisStep(nameTest("b")), axisStep(wildcard(), attributeNameTest(nameTest("prop")))))); }