protected String parsePath( TokenStream tokens, TypeSystem typeSystem ) { return removeBracketsAndQuotes(tokens.consume(), tokens.previousPosition()); }
protected String parseName( TokenStream tokens, TypeSystem typeSystem ) { return removeBracketsAndQuotes(tokens.consume(), tokens.previousPosition()); }
protected String parsePath( TokenStream tokens, TypeSystem typeSystem ) { return removeBracketsAndQuotes(tokens.consume(), tokens.previousPosition()); }
protected String parseName( TokenStream tokens, TypeSystem typeSystem ) { return removeBracketsAndQuotes(tokens.consume(), tokens.previousPosition()); }
protected String parsePath( TokenStream tokens, TypeSystem typeSystem ) { return removeBracketsAndQuotes(tokens.consume(), tokens.previousPosition()); }
protected String parseName( TokenStream tokens, TypeSystem typeSystem ) { return removeBracketsAndQuotes(tokens.consume(), tokens.previousPosition()); }
protected String parseNCName( TokenStream tokens ) { String name = tokens.consume(); if (!XmlCharacters.isValidNcName(name)) { throw new ParsingException(tokens.previousPosition(), "Expected valid NCName but found " + name); } return name; }
protected String parseNCName( TokenStream tokens ) { String name = tokens.consume(); if (!XmlCharacters.isValidNcName(name)) { throw new ParsingException(tokens.previousPosition(), "Expected valid NCName but found " + name); } return name; }
/** * {@inheritDoc} * <p> * Parsing behavior is overridden to that JCR-SQL style (unquoted prefixed) names are allowed. This method parses the selector * name, which may be of the form "<code>unprefixedName</code>" (consisting of a single token) or "<code>prefix:name</code>" * (consisting of three tokens). * </p> * * @see org.modeshape.jcr.query.parse.BasicSqlQueryParser#parseName(org.modeshape.common.text.TokenStream, * org.modeshape.jcr.query.model.TypeSystem) */ @Override protected String parseName( TokenStream tokens, TypeSystem typeSystem ) { String token1 = tokens.consume(); token1 = removeBracketsAndQuotes(token1, tokens.previousPosition()); if (tokens.canConsume(':')) { String token2 = tokens.consume(); token2 = removeBracketsAndQuotes(token2, tokens.previousPosition()); return token1 + ':' + token2; } return token1; }
/** * {@inheritDoc} * <p> * Parsing behavior is overridden to that JCR-SQL style (unquoted prefixed) names are allowed. This method parses the selector * name, which may be of the form "<code>unprefixedName</code>" (consisting of a single token) or "<code>prefix:name</code>" * (consisting of three tokens). * </p> * * @see org.modeshape.jcr.query.parse.BasicSqlQueryParser#parseName(org.modeshape.common.text.TokenStream, * org.modeshape.jcr.query.model.TypeSystem) */ @Override protected String parseName( TokenStream tokens, TypeSystem typeSystem ) { String token1 = tokens.consume(); token1 = removeBracketsAndQuotes(token1, tokens.previousPosition()); if (tokens.canConsume(':')) { String token2 = tokens.consume(); token2 = removeBracketsAndQuotes(token2, tokens.previousPosition()); return token1 + ':' + token2; } return token1; }
@Test public void shouldFindPreviousPositionStartIndex() { makeCaseInsensitive(); // "Select all columns from this table"; tokens.consume(); tokens.consume(); // previous position should be line 1, column 8 assertThat(tokens.previousPosition().getIndexInContent(), is(7)); assertThat(tokens.previousPosition().getColumn(), is(8)); assertThat(tokens.previousPosition().getLine(), is(1)); }
protected BindVariableName parseBindVariableName( TokenStream tokens, TypeSystem typeSystem ) { // The variable name must conform to a valid prefix, which is defined as a valid NCName ... String value = tokens.consume(); if (!XmlCharacters.isValidNcName(value)) { Position pos = tokens.previousPosition(); String msg = GraphI18n.bindVariableMustConformToNcName.text(value, pos.getLine(), pos.getColumn()); throw new ParsingException(pos, msg); } return bindVariableName(value); }
protected BindVariableName parseBindVariableName( TokenStream tokens, TypeSystem typeSystem ) { // The variable name must conform to a valid prefix, which is defined as a valid NCName ... String value = tokens.consume(); if (!XmlCharacters.isValidNcName(value)) { Position pos = tokens.previousPosition(); String msg = GraphI18n.bindVariableMustConformToNcName.text(value, pos.getLine(), pos.getColumn()); throw new ParsingException(pos, msg); } return bindVariableName(value); }
/** * Parse the name that is expected to be next on the token stream. * * @param tokens the tokens containing the name; never null * @return the name; never null * @throws ParsingException if there is a problem parsing the content */ protected Name parseName( TokenStream tokens ) { String value = tokens.consume(); try { return nameFactory.create(removeQuotes(value)); } catch (ValueFormatException e) { if (e.getCause() instanceof NamespaceException) { throw (NamespaceException)e.getCause(); } throw new ParsingException(tokens.previousPosition(), CndI18n.expectedValidNameLiteral.text(value)); } }
/** * Parse the name that is expected to be next on the token stream. * * @param tokens the tokens containing the name; never null * @return the name; never null * @throws ParsingException if there is a problem parsing the content */ protected Name parseName( TokenStream tokens ) { String value = tokens.consume(); try { return nameFactory.create(removeQuotes(value)); } catch (ValueFormatException e) { if (e.getCause() instanceof NamespaceException) { throw (NamespaceException)e.getCause(); } throw new ParsingException(tokens.previousPosition(), CndI18n.expectedValidNameLiteral.text(value)); } }
protected PathExpression parsePathExpr( TokenStream tokens ) { boolean relative = true; boolean prependDependentOrSelf = false; if (tokens.canConsume('/')) { if (tokens.canConsume('/')) { if (!tokens.hasNext()) { // See http://www.w3.org/XML/2007/qt-errata/xpath20-errata.html#E3 throw new ParsingException(tokens.previousPosition(), "'//' is not a valid XPath expression"); } 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; }
protected PathExpression parsePathExpr( TokenStream tokens ) { boolean relative = true; boolean prependDependentOrSelf = false; if (tokens.canConsume('/')) { if (tokens.canConsume('/')) { if (!tokens.hasNext()) { // See http://www.w3.org/XML/2007/qt-errata/xpath20-errata.html#E3 throw new ParsingException(tokens.previousPosition(), "'//' is not a valid XPath expression"); } 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; }
/** * Parse the CND content. * * @param content the content * @throws ParsingException if there is a problem parsing the content */ protected void parse( String content ) { Tokenizer tokenizer = new CndTokenizer(false, true); TokenStream tokens = new TokenStream(content, tokenizer, false); tokens.start(); while (tokens.hasNext()) { // Keep reading while we can recognize one of the two types of statements ... if (tokens.matches("<", ANY_VALUE, "=", ANY_VALUE, ">")) { parseNamespaceMapping(tokens); } else if (tokens.matches("[", ANY_VALUE, "]")) { parseNodeTypeDefinition(tokens); } else { Position position = tokens.previousPosition(); throw new ParsingException(position, CndI18n.expectedNamespaceOrNodeDefinition.text(tokens.consume(), position.getLine(), position.getColumn())); } } }
/** * Parse the CND content. * * @param content the content * @throws ParsingException if there is a problem parsing the content */ protected void parse( String content ) { Tokenizer tokenizer = new CndTokenizer(false, true); TokenStream tokens = new TokenStream(content, tokenizer, false); tokens.start(); while (tokens.hasNext()) { // Keep reading while we can recognize one of the two types of statements ... if (tokens.matches("<", ANY_VALUE, "=", ANY_VALUE, ">")) { parseNamespaceMapping(tokens); } else if (tokens.matches("[", ANY_VALUE, "]")) { parseNodeTypeDefinition(tokens); } else { Position position = tokens.previousPosition(); throw new ParsingException(position, CndI18n.expectedNamespaceOrNodeDefinition.text(tokens.consume(), position.getLine(), position.getColumn())); } } }
protected StaticOperand parseStaticOperand( TokenStream tokens, TypeSystem typeSystem ) { if (tokens.canConsume('$')) { // The variable name must conform to a valid prefix, which is defined as a valid NCName ... String value = tokens.consume(); if (!XmlCharacters.isValidNcName(value)) { Position pos = tokens.previousPosition(); String msg = GraphI18n.bindVariableMustConformToNcName.text(value, pos.getLine(), pos.getColumn()); throw new ParsingException(pos, msg); } return bindVariableName(value); } if (tokens.canConsume('(')) { // Sometimes the subqueries are wrapped with parentheses ... StaticOperand result = parseStaticOperand(tokens, typeSystem); tokens.consume(')'); return result; } if (tokens.matches("SELECT")) { // This is a subquery. This object is stateless, so we can reuse this object ... QueryCommand subqueryExpression = parseQueryCommand(tokens, typeSystem); return subquery(subqueryExpression); } return parseLiteral(tokens, typeSystem); }