@Test( expected = ParsingException.class ) public void shouldFailToParseNonAbbreviatedParentAxis() { parser.parseAxisStep(tokenize("parent::x")); }
protected AxisStep parseAxisStep( TokenStream tokens ) { NodeTest nodeTest = null; if (tokens.canConsume('@')) { nodeTest = new AttributeNameTest(parseNameTest(tokens)); } else if (tokens.matches('*')) { nodeTest = parseNodeTest(tokens); } else if (tokens.matches("child", ":", ":") || tokens.matches("attribute", ":", ":") || tokens.matches("self", ":", ":") || tokens.matches("descendant", ":", ":") || tokens.matches("descendant-or-self", ":", ":") || tokens.matches("following-sibling", ":", ":") || tokens.matches("following", ":", ":") || tokens.matches("namespace", ":", ":")) { throw new ParsingException( tokens.nextPosition(), "XPath non-abbreviated forward steps (e.g., 'child::', 'attribute::', 'self::', 'descendant::', 'descendant-or-self::', 'following-sibling::', 'following::', or 'namespace::') are not supported"); } else if (tokens.matches("..")) { throw new ParsingException(tokens.nextPosition(), "XPath abbreviated reverse steps (e.g., '..') are not supported"); } else if (tokens.matches("parent", ":", ":") || tokens.matches("ancestor-or-self", ":", ":") || tokens.matches("preceding-sibling", ":", ":") || tokens.matches("preceding", ":", ":") || tokens.matches("ancestor", ":", ":")) { throw new ParsingException( tokens.nextPosition(), "XPath non-abbreviated reverse steps (e.g., 'parent::', 'ancestor::', 'ancestor-or-self::', 'preceding-or-sibling::', or 'preceding::') are not supported"); } else if (tokens.matches(ANY_VALUE, ":", ANY_VALUE) && tokens.matches(XPathTokenizer.NAME, XPathTokenizer.SYMBOL, XPathTokenizer.NAME)) { nodeTest = parseQName(tokens); } else if (tokens.matches(XPathTokenizer.NAME)) { nodeTest = parseNodeTest(tokens); } else { return null; } List<Component> predicates = parsePredicates(tokens); return new AxisStep(nodeTest, predicates); }
XPathParser { protected AxisStep parseAxisStep( TokenStream tokens ) { NodeTest nodeTest = null; if (tokens.canConsume('@')) { nodeTest = new AttributeNameTest(parseNameTest(tokens)); } else if (tokens.matches('*')) { nodeTest = parseNodeTest(tokens); } else if (tokens.matches("child", ":", ":") || tokens.matches("attribute", ":", ":") || tokens.matches("self", ":", ":") || tokens.matches("descendant", ":", ":") || tokens.matches("descendant-or-self", ":", ":") || tokens.matches("following-sibling", ":", ":") || tokens.matches("following", ":", ":") || tokens.matches("namespace", ":", ":")) { throw new ParsingException( tokens.nextPosition(), "XPath non-abbreviated forward steps (e.g., 'child::', 'attribute::', 'self::', 'descendant::', 'descendant-or-self::', 'following-sibling::', 'following::', or 'namespace::') are not supported"); } else if (tokens.matches("..")) { throw new ParsingException(tokens.nextPosition(), "XPath abbreviated reverse steps (e.g., '..') are not supported"); } else if (tokens.matches("parent", ":", ":") || tokens.matches("ancestor-or-self", ":", ":") || tokens.matches("preceding-sibling", ":", ":") || tokens.matches("preceding", ":", ":") || tokens.matches("ancestor", ":", ":")) { throw new ParsingException( tokens.nextPosition(), "XPath non-abbreviated reverse steps (e.g., 'parent::', 'ancestor::', 'ancestor-or-self::', 'preceding-or-sibling::', or 'preceding::') are not supported"); } else if (tokens.matches(ANY_VALUE, ":", ANY_VALUE) && tokens.matches(XPathTokenizer.NAME, XPathTokenizer.SYMBOL, XPathTokenizer.NAME)) { nodeTest = parseQName(tokens); } else if (tokens.matches(XPathTokenizer.NAME)) { nodeTest = parseNodeTest(tokens); } else { return null; } List<Component> predicates = parsePredicates(tokens); return new AxisStep(nodeTest, predicates); } }
XPathParser { protected AxisStep parseAxisStep( TokenStream tokens ) { NodeTest nodeTest = null; if (tokens.canConsume('@')) { nodeTest = new AttributeNameTest(parseNameTest(tokens)); } else if (tokens.matches('*')) { nodeTest = parseNodeTest(tokens); } else if (tokens.matches("child", ":", ":") || tokens.matches("attribute", ":", ":") || tokens.matches("self", ":", ":") || tokens.matches("descendant", ":", ":") || tokens.matches("descendant-or-self", ":", ":") || tokens.matches("following-sibling", ":", ":") || tokens.matches("following", ":", ":") || tokens.matches("namespace", ":", ":")) { throw new ParsingException( tokens.nextPosition(), "XPath non-abbreviated forward steps (e.g., 'child::', 'attribute::', 'self::', 'descendant::', 'descendant-or-self::', 'following-sibling::', 'following::', or 'namespace::') are not supported"); } else if (tokens.matches("..")) { throw new ParsingException(tokens.nextPosition(), "XPath abbreviated reverse steps (e.g., '..') are not supported"); } else if (tokens.matches("parent", ":", ":") || tokens.matches("ancestor-or-self", ":", ":") || tokens.matches("preceding-sibling", ":", ":") || tokens.matches("preceding", ":", ":") || tokens.matches("ancestor", ":", ":")) { throw new ParsingException( tokens.nextPosition(), "XPath non-abbreviated reverse steps (e.g., 'parent::', 'ancestor::', 'ancestor-or-self::', 'preceding-or-sibling::', or 'preceding::') are not supported"); } else if (tokens.matches(ANY_VALUE, ":", ANY_VALUE) && tokens.matches(XPathTokenizer.NAME, XPathTokenizer.SYMBOL, XPathTokenizer.NAME)) { nodeTest = parseQName(tokens); } else if (tokens.matches(XPathTokenizer.NAME)) { nodeTest = parseNodeTest(tokens); } else { return null; } List<Component> predicates = parsePredicates(tokens); return new AxisStep(nodeTest, predicates); } XPathParser( TypeSystem context ); }
XPathParser { protected AxisStep parseAxisStep( TokenStream tokens ) { NodeTest nodeTest = null; if (tokens.canConsume('@')) { nodeTest = new AttributeNameTest(parseNameTest(tokens)); } else if (tokens.matches('*')) { nodeTest = parseNodeTest(tokens); } else if (tokens.matches("child", ":", ":") || tokens.matches("attribute", ":", ":") || tokens.matches("self", ":", ":") || tokens.matches("descendant", ":", ":") || tokens.matches("descendant-or-self", ":", ":") || tokens.matches("following-sibling", ":", ":") || tokens.matches("following", ":", ":") || tokens.matches("namespace", ":", ":")) { throw new ParsingException( tokens.nextPosition(), "XPath non-abbreviated forward steps (e.g., 'child::', 'attribute::', 'self::', 'descendant::', 'descendant-or-self::', 'following-sibling::', 'following::', or 'namespace::') are not supported"); } else if (tokens.matches("..")) { throw new ParsingException(tokens.nextPosition(), "XPath abbreviated reverse steps (e.g., '..') are not supported"); } else if (tokens.matches("parent", ":", ":") || tokens.matches("ancestor-or-self", ":", ":") || tokens.matches("preceding-sibling", ":", ":") || tokens.matches("preceding", ":", ":") || tokens.matches("ancestor", ":", ":")) { throw new ParsingException( tokens.nextPosition(), "XPath non-abbreviated reverse steps (e.g., 'parent::', 'ancestor::', 'ancestor-or-self::', 'preceding-or-sibling::', or 'preceding::') are not supported"); } else if (tokens.matches(ANY_VALUE, ":", ANY_VALUE) && tokens.matches(XPathTokenizer.NAME, XPathTokenizer.SYMBOL, XPathTokenizer.NAME)) { nodeTest = parseQName(tokens); } else if (tokens.matches(XPathTokenizer.NAME)) { nodeTest = parseNodeTest(tokens); } else { return null; } List<Component> predicates = parsePredicates(tokens); return new AxisStep(nodeTest, predicates); } XPathParser( TypeSystem context ); Component parseXPath( String xpath ); }
XPathParser { protected AxisStep parseAxisStep( TokenStream tokens ) { NodeTest nodeTest = null; if (tokens.canConsume('@')) { nodeTest = new AttributeNameTest(parseNameTest(tokens)); } else if (tokens.matches('*')) { nodeTest = parseNodeTest(tokens); } else if (tokens.matches("child", ":", ":") || tokens.matches("attribute", ":", ":") || tokens.matches("self", ":", ":") || tokens.matches("descendant", ":", ":") || tokens.matches("descendant-or-self", ":", ":") || tokens.matches("following-sibling", ":", ":") || tokens.matches("following", ":", ":") || tokens.matches("namespace", ":", ":")) { throw new ParsingException( tokens.nextPosition(), "XPath non-abbreviated forward steps (e.g., 'child::', 'attribute::', 'self::', 'descendant::', 'descendant-or-self::', 'following-sibling::', 'following::', or 'namespace::') are not supported"); } else if (tokens.matches("..")) { throw new ParsingException(tokens.nextPosition(), "XPath abbreviated reverse steps (e.g., '..') are not supported"); } else if (tokens.matches("parent", ":", ":") || tokens.matches("ancestor-or-self", ":", ":") || tokens.matches("preceding-sibling", ":", ":") || tokens.matches("preceding", ":", ":") || tokens.matches("ancestor", ":", ":")) { throw new ParsingException( tokens.nextPosition(), "XPath non-abbreviated reverse steps (e.g., 'parent::', 'ancestor::', 'ancestor-or-self::', 'preceding-or-sibling::', or 'preceding::') are not supported"); } else if (tokens.matches(ANY_VALUE, ":", ANY_VALUE) && tokens.matches(XPathTokenizer.NAME, XPathTokenizer.SYMBOL, XPathTokenizer.NAME)) { nodeTest = parseQName(tokens); } else if (tokens.matches(XPathTokenizer.NAME)) { nodeTest = parseNodeTest(tokens); } else { return null; } List<Component> predicates = parsePredicates(tokens); return new AxisStep(nodeTest, predicates); } XPathParser( TypeSystem context ); Component parseXPath( String xpath );  }