Return-Path: X-Original-To: apmail-chemistry-commits-archive@www.apache.org Delivered-To: apmail-chemistry-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E0EF7D5CC for ; Tue, 28 May 2013 07:13:51 +0000 (UTC) Received: (qmail 52981 invoked by uid 500); 28 May 2013 07:13:51 -0000 Delivered-To: apmail-chemistry-commits-archive@chemistry.apache.org Received: (qmail 52873 invoked by uid 500); 28 May 2013 07:13:51 -0000 Mailing-List: contact commits-help@chemistry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@chemistry.apache.org Delivered-To: mailing list commits@chemistry.apache.org Received: (qmail 52026 invoked by uid 99); 28 May 2013 07:13:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 May 2013 07:13:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 May 2013 07:13:44 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 322212388CBF for ; Tue, 28 May 2013 07:12:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r863408 [24/27] - in /websites/staging/chemistry/trunk/content: ./ java/0.9.0/maven/chemistry-opencmis-server/ java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-support/ java/0.9.0/maven/chemistry-opencmis-server/chemistr... Date: Tue, 28 May 2013 07:12:28 -0000 To: commits@chemistry.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130528071234.322212388CBF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-support/xref/org/apache/chemistry/opencmis/server/support/query/QueryUtil.html ============================================================================== --- websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-support/xref/org/apache/chemistry/opencmis/server/support/query/QueryUtil.html (added) +++ websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-support/xref/org/apache/chemistry/opencmis/server/support/query/QueryUtil.html Tue May 28 07:12:25 2013 @@ -0,0 +1,146 @@ + + + + +QueryUtil xref + + + +
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one
+3    * or more contributor license agreements.  See the NOTICE file
+4    * distributed with this work for additional information
+5    * regarding copyright ownership.  The ASF licenses this file
+6    * to you under the Apache License, Version 2.0 (the
+7    * "License"); you may not use this file except in compliance
+8    * with the License.  You may obtain a copy of the License at
+9    *
+10   * http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   * Unless required by applicable law or agreed to in writing,
+13   * software distributed under the License is distributed on an
+14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   * KIND, either express or implied.  See the License for the
+16   * specific language governing permissions and limitations
+17   * under the License.
+18   */
+19  package org.apache.chemistry.opencmis.server.support.query;
+20  
+21  import java.io.IOException;
+22  import java.io.UnsupportedEncodingException;
+23  
+24  import org.antlr.runtime.ANTLRStringStream;
+25  import org.antlr.runtime.CharStream;
+26  import org.antlr.runtime.CommonTokenStream;
+27  import org.antlr.runtime.RecognitionException;
+28  import org.antlr.runtime.TokenSource;
+29  import org.antlr.runtime.TokenStream;
+30  import org.antlr.runtime.tree.CommonTree;
+31  import org.antlr.runtime.tree.CommonTreeNodeStream;
+32  import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
+33  import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+34  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+35  import org.apache.chemistry.opencmis.server.support.query.CmisQlStrictParser_CmisBaseGrammar.query_return;
+36  
+37  /**
+38   * Support class to assist in parsing and processing CMIS queries.
+39   * This class inherits from QueryUtilBase to use the error handling
+40   * methods. It does not follow its design and is only maintained for
+41   * backwards compatibility.
+42   * 
+43   * @deprecated 
+44   *
+45   */
+46  public class QueryUtil extends QueryUtilBase<CmisQueryWalker> {
+47      
+48      public QueryUtil() {
+49          super(null, null, null);
+50      }
+51      
+52      @Override
+53      public CommonTree parseStatement() throws RecognitionException {
+54          throw new CmisRuntimeException("Not supported, use getWalker to parse a query using this legacy class.");        
+55      }
+56  
+57      @Override
+58      public void walkStatement() throws CmisQueryException, RecognitionException {
+59          throw new CmisRuntimeException("Not supported, use getWalker to parse a query using this legacy class.");
+60      }
+61  
+62      /**
+63       * Parse a CMISQL statement and return a tree that can be walked to evaluate the expression
+64       * of the query (usually not used directly but through traverseStatement)
+65       * 
+66       * @param statement
+67       *      CMISQL statement
+68       * @return
+69       *      an AntLR tree grammar that can be traversed to evaluate the query
+70       *      
+71       * @throws RecognitionException
+72       */
+73      public static CmisQueryWalker getWalker(String statement) throws RecognitionException {
+74          CharStream input = new ANTLRStringStream(statement);
+75          TokenSource lexer = new CmisQlStrictLexer(input);
+76          TokenStream tokens = new CommonTokenStream(lexer);
+77          CmisQlStrictParser parser = new CmisQlStrictParser(tokens);
+78          CommonTree parserTree; // the ANTLR tree after parsing phase
+79  
+80          query_return parsedStatement = parser.query();
+81          if (parser.hasErrors()) {
+82              throw new CmisInvalidArgumentException(parser.getErrorMessages());
+83          } else if ( tokens.index()!=tokens.size() ) {
+84              throw new  CmisInvalidArgumentException("Query String has illegal tokens after end of statement: " + tokens.get(tokens.index()));
+85          }
+86          
+87          parserTree = (CommonTree) parsedStatement.getTree();
+88  
+89          CommonTreeNodeStream nodes = new CommonTreeNodeStream(parserTree);
+90          nodes.setTokenStream(tokens);
+91          CmisQueryWalker walker = new CmisQueryWalker(nodes);
+92          return walker;               
+93      }
+94      
+95      /**
+96       * Parse and process a CMISQL statement using the higher level support classes
+97       * 
+98       * @param statement
+99       *      CMISQL statement
+100      * @param queryObj
+101      *      CMIS query object filled with information what data need to be retrieved
+102      * @param pw
+103      *      predicate walker that evaluates the where clause
+104      * @return
+105      *      AntLR tree grammar created by this statement
+106      *      
+107      * @throws UnsupportedEncodingException
+108      * @throws IOException
+109      * @throws RecognitionException
+110      */
+111     public CmisQueryWalker traverseStatement(String statement, QueryObject queryObj, PredicateWalkerBase pw)
+112             throws UnsupportedEncodingException, IOException, RecognitionException {
+113         walker = getWalker(statement);
+114         walker.query(queryObj, pw);
+115         walker.getWherePredicateTree();
+116         return walker;        
+117     }
+118 
+119     public CmisQueryWalker traverseStatementAndCatchExc(String statement, QueryObject queryObj, PredicateWalkerBase pw) {
+120         try {
+121             return traverseStatement(statement, queryObj, pw);
+122         } catch (RecognitionException e) {
+123             String errorMsg = queryObj.getErrorMessage();
+124             throw new CmisInvalidArgumentException("Walking of statement failed with RecognitionException error: \n   " + errorMsg, e);
+125         } catch (CmisBaseException e) {
+126             throw e;
+127         } catch (Exception e) {
+128             throw new CmisInvalidArgumentException("Walking of statement failed with exception: \n   ", e);
+129         }
+130     }
+131 
+132 }
+
+
+ + Added: websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-support/xref/org/apache/chemistry/opencmis/server/support/query/QueryUtilBase.html ============================================================================== --- websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-support/xref/org/apache/chemistry/opencmis/server/support/query/QueryUtilBase.html (added) +++ websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-support/xref/org/apache/chemistry/opencmis/server/support/query/QueryUtilBase.html Tue May 28 07:12:25 2013 @@ -0,0 +1,153 @@ + + + + +QueryUtilBase xref + + + +
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one
+3    * or more contributor license agreements.  See the NOTICE file
+4    * distributed with this work for additional information
+5    * regarding copyright ownership.  The ASF licenses this file
+6    * to you under the Apache License, Version 2.0 (the
+7    * "License"); you may not use this file except in compliance
+8    * with the License.  You may obtain a copy of the License at
+9    *
+10   * http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   * Unless required by applicable law or agreed to in writing,
+13   * software distributed under the License is distributed on an
+14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   * KIND, either express or implied.  See the License for the
+16   * specific language governing permissions and limitations
+17   * under the License.
+18   */
+19  package org.apache.chemistry.opencmis.server.support.query;
+20  
+21  import org.antlr.runtime.BaseRecognizer;
+22  import org.antlr.runtime.RecognitionException;
+23  import org.antlr.runtime.TokenStream;
+24  import org.antlr.runtime.tree.CommonTree;
+25  import org.antlr.runtime.tree.TreeParser;
+26  import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
+27  import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+28  import org.apache.chemistry.opencmis.server.support.TypeManager;
+29  
+30  /**
+31   * Utility class to help parsing and processing a query statement using the AntLR parser
+32   * Subclasses have to implement methods that setup parser and query walker and 
+33   * parse and process a query. This class provides common methods for error handling
+34   * and for storing the necessary opencmis objects for query support
+35   *
+36   * @param <T>
+37   *      AntLR tree grammar, will usually be a CmisQueryWalker but can be custom class for
+38   *       customized (extended) parsers
+39   */
+40  public abstract class QueryUtilBase<T extends TreeParser> {
+41  
+42      protected T walker;
+43      protected QueryObject queryObj;
+44      protected PredicateWalkerBase predicateWalker;
+45      protected String statement;
+46   
+47      protected CommonTree parserTree; // the ANTLR tree after parsing phase
+48      protected TokenStream tokens;    // the ANTLR token stream
+49  
+50      /**
+51       * Perform the first phase of query processing. Setup lexer and parser, 
+52       * parse the statement, check for syntax errors and create an AST
+53       * 
+54       * @return
+55       *      the abstract syntax tree of the parsed statement
+56       *      
+57       * @throws RecognitionException
+58       */
+59      public abstract CommonTree parseStatement() throws RecognitionException;
+60      
+61      /**
+62       * Perform the second phase of  query processing, analyzes the select 
+63       * part, check for semantic errors, fill the query object. Usually a 
+64       * walker will be CmisQueryWalker (or subclass) if the supporting 
+65       * OpenCMIS query classes are used. 
+66       * 
+67       * @throws RecognitionException
+68       */    
+69      public abstract void walkStatement() throws RecognitionException;;
+70  
+71      /**
+72       * Fully process a query by parsing and walking it and setting up the
+73       * supporting objects
+74       * 
+75       * @throws RecognitionException
+76       */
+77      public void processStatement() throws RecognitionException {
+78          parseStatement();
+79          walkStatement();
+80       }
+81  
+82      protected QueryUtilBase(String statement, TypeManager tm, PredicateWalkerBase pw) {
+83          walker = null;
+84          queryObj = new QueryObject(tm);
+85          predicateWalker = pw; 
+86          this.statement = statement;
+87      }
+88      
+89      public T getWalker() {
+90          return walker;
+91      }
+92      
+93      public PredicateWalkerBase getPredicateWalker() {
+94          return predicateWalker;
+95      }
+96      
+97      public QueryObject getQueryObject() {
+98          return queryObj;
+99      }
+100     
+101     public String getStatement() {
+102         return statement;
+103     }
+104         
+105     /**
+106      * Same as traverseStatement but throws only CMIS Exceptions
+107      * 
+108      * @param statement
+109      *      CMISQL statement to parse
+110      * @return
+111      */
+112     public void  processStatementUsingCmisExceptions() {
+113         try {
+114             processStatement();
+115         } catch (RecognitionException e) {
+116             String errorMsg = queryObj.getErrorMessage();
+117             throw new CmisInvalidArgumentException("Walking of statement failed with RecognitionException error: \n   " + errorMsg, e);
+118         } catch (CmisBaseException e) {
+119             throw e;
+120         } catch (Exception e) {
+121             throw new CmisInvalidArgumentException("Walking of statement failed with exception: \n   ", e);
+122         }
+123     }
+124 
+125     public String getErrorMessage(RecognitionException e) {
+126         if (null == walker)
+127             return e.toString();
+128         else
+129             return getErrorMessage(walker, e);
+130     }
+131     
+132     private static String getErrorMessage(BaseRecognizer recognizer, RecognitionException e) {
+133         String[] tokenNames = recognizer.getTokenNames();
+134         String hdr = "Line "+e.line+":"+e.charPositionInLine;
+135         String msg = recognizer.getErrorMessage(e, tokenNames);
+136         return hdr + " " + msg;
+137     }
+138 
+139 }
+
+
+ + Added: websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-support/xref/org/apache/chemistry/opencmis/server/support/query/QueryUtilStrict.html ============================================================================== --- websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-support/xref/org/apache/chemistry/opencmis/server/support/query/QueryUtilStrict.html (added) +++ websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-support/xref/org/apache/chemistry/opencmis/server/support/query/QueryUtilStrict.html Tue May 28 07:12:25 2013 @@ -0,0 +1,94 @@ + + + + +QueryUtilStrict xref + + + +
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one
+3    * or more contributor license agreements.  See the NOTICE file
+4    * distributed with this work for additional information
+5    * regarding copyright ownership.  The ASF licenses this file
+6    * to you under the Apache License, Version 2.0 (the
+7    * "License"); you may not use this file except in compliance
+8    * with the License.  You may obtain a copy of the License at
+9    *
+10   * http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   * Unless required by applicable law or agreed to in writing,
+13   * software distributed under the License is distributed on an
+14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   * KIND, either express or implied.  See the License for the
+16   * specific language governing permissions and limitations
+17   * under the License.
+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; // the ANTLR tree after parsing phase
+36      private TokenStream tokens;    // the ANTLR token stream
+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  }
+
+
+ + Added: websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-support/xref/org/apache/chemistry/opencmis/server/support/query/StringUtil.html ============================================================================== --- websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-support/xref/org/apache/chemistry/opencmis/server/support/query/StringUtil.html (added) +++ websites/staging/chemistry/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-support/xref/org/apache/chemistry/opencmis/server/support/query/StringUtil.html Tue May 28 07:12:25 2013 @@ -0,0 +1,94 @@ + + + + +StringUtil xref + + + +
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one
+3    * or more contributor license agreements.  See the NOTICE file
+4    * distributed with this work for additional information
+5    * regarding copyright ownership.  The ASF licenses this file
+6    * to you under the Apache License, Version 2.0 (the
+7    * "License"); you may not use this file except in compliance
+8    * with the License.  You may obtain a copy of the License at
+9    *
+10   * http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   * Unless required by applicable law or agreed to in writing,
+13   * software distributed under the License is distributed on an
+14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   * KIND, either express or implied.  See the License for the
+16   * specific language governing permissions and limitations
+17   * under the License.
+18   */
+19  package org.apache.chemistry.opencmis.server.support.query;
+20  
+21  
+22  public class StringUtil {
+23      
+24      /**
+25       * remove all escape sequences in a string and return unescaped string
+26       * escape character is backslash \, so \\ --> \, \' --> ' additional
+27       * escaped characters can be allowed in escapedChars
+28       * @param literal
+29       *      String to unescape
+30       * @param escapedChars
+31       *      set of allowed characters to be escaped with a backslash, if set to
+32       *      null then ' (quote) and \ (backslash) are allowed to be escaped
+33       * @return
+34       *      unescaped literal or null if the literal is illegal
+35       */
+36      public static String unescape(String literal, String escapedChars) {
+37          char c ='?';
+38          int i=0;
+39          StringBuffer sb = new StringBuffer();
+40          
+41          if (null == escapedChars) 
+42              escapedChars = "\\'";
+43          
+44          if (null == literal)
+45              return null;
+46          
+47          int len = literal.length();
+48          
+49          if (len == 1 && literal.charAt(0) == '\\')
+50              return null;
+51  
+52          if (len > 1 && literal.charAt(len-2) != '\\' && literal.charAt(len-1) == '\\') 
+53              return null;
+54  
+55          for (i=0; i<len; i++) {
+56              c = literal.charAt(i);
+57              if ( c == '\\') {
+58                  char escChar = literal.charAt(i+1);
+59                  boolean matched = false;
+60                  for (int j = 0; j< escapedChars.length(); j++) {
+61                      if (escChar == escapedChars.charAt(j)) {
+62                          sb.append(escChar);
+63                          ++i;
+64                          matched = true;
+65                          break;
+66                      }
+67                  }
+68                  
+69                  if (!matched)
+70                      return null;
+71                  
+72              } else {
+73                  sb.append(literal.charAt(i));
+74              }
+75          }
+76          
+77          return sb.toString();
+78      }
+79  
+80  }
+
+
+ +