1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.server.support.query;
20
21 import org.antlr.runtime.ANTLRStringStream;
22 import org.antlr.runtime.CharStream;
23 import org.antlr.runtime.CommonTokenStream;
24 import org.antlr.runtime.RecognitionException;
25 import org.antlr.runtime.TokenSource;
26 import org.antlr.runtime.TokenStream;
27 import org.antlr.runtime.tree.CommonTree;
28 import org.antlr.runtime.tree.CommonTreeNodeStream;
29 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
30 import org.apache.chemistry.opencmis.server.support.TypeManager;
31 import org.apache.chemistry.opencmis.server.support.query.CmisQlStrictParser_CmisBaseGrammar.query_return;
32
33 public class QueryUtilStrict extends QueryUtilBase<CmisQueryWalker> {
34
35 private CommonTree parserTree;
36 private TokenStream tokens;
37 private boolean parseFulltext = true;
38
39 public QueryUtilStrict(String statement, TypeManager tm, PredicateWalkerBase pw) {
40 super(statement, tm, pw);
41 }
42
43 public QueryUtilStrict(String statement, TypeManager tm, PredicateWalkerBase pw, boolean parseFulltext) {
44 super(statement, tm, pw);
45 this.parseFulltext = parseFulltext;
46 }
47
48 @Override
49 public CommonTree parseStatement() throws RecognitionException {
50 CharStream input = new ANTLRStringStream(statement);
51 TokenSource lexer = new CmisQlStrictLexer(input);
52 tokens = new CommonTokenStream(lexer);
53 CmisQlStrictParser parser = new CmisQlStrictParser(tokens);
54
55 query_return parsedStatement = parser.query();
56 if (parser.hasErrors()) {
57 throw new CmisInvalidArgumentException(parser.getErrorMessages());
58 } else if (tokens.index() != tokens.size()) {
59 throw new CmisInvalidArgumentException("Query String has illegal tokens after end of statement: " + tokens.get(tokens.index()));
60 }
61
62 parserTree = (CommonTree) parsedStatement.getTree();
63 return parserTree;
64 }
65
66 @Override
67 public void walkStatement() throws RecognitionException {
68
69 if (null == parserTree)
70 throw new CmisQueryException("You must parse the query before you can walk it.");
71
72 CommonTreeNodeStream nodes = new CommonTreeNodeStream(parserTree);
73 nodes.setTokenStream(tokens);
74 walker = new CmisQueryWalker(nodes);
75 walker.setDoFullTextParse(parseFulltext);
76 walker.query(queryObj, predicateWalker);
77 walker.getWherePredicateTree();
78 }
79
80 }