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 DA372EBAD for ; Tue, 28 May 2013 07:52:31 +0000 (UTC) Received: (qmail 78779 invoked by uid 500); 28 May 2013 07:52:28 -0000 Delivered-To: apmail-chemistry-commits-archive@chemistry.apache.org Received: (qmail 78503 invoked by uid 500); 28 May 2013 07:52:27 -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 78286 invoked by uid 99); 28 May 2013 07:52:24 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 May 2013 07:52:24 +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:52:12 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 346EE2388C2C; Tue, 28 May 2013 07:50:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1486802 [19/22] - in /chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-jcr: ./ css/ images/ images/logos/ xref-test/ xref-test/org/ xref-test/org/apache/ xref-test/org/apache/chemistry/ xref... Date: Tue, 28 May 2013 07:50:52 -0000 To: commits@chemistry.apache.org From: gabriele@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130528075058.346EE2388C2C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-jcr/xref/org/apache/chemistry/opencmis/jcr/query/IdentifierMap.html URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-jcr/xref/org/apache/chemistry/opencmis/jcr/query/IdentifierMap.html?rev=1486802&view=auto ============================================================================== --- chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-jcr/xref/org/apache/chemistry/opencmis/jcr/query/IdentifierMap.html (added) +++ chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-jcr/xref/org/apache/chemistry/opencmis/jcr/query/IdentifierMap.html Tue May 28 07:50:50 2013 @@ -0,0 +1,79 @@ + + + + +IdentifierMap 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  
+20  package org.apache.chemistry.opencmis.jcr.query;
+21  
+22  /**
+23   * The methods of this class map CMIS identifiers to JCR identifiers. Each implementation
+24   * of this interface is bound to a specific CMIS object type. That is, it implements the
+25   * identifier maps for that object type. 
+26   */
+27  public interface IdentifierMap {
+28  
+29      /**
+30       * Map a column name in the CMIS query to the corresponding relative JCR path.
+31       * The path must be relative to the context node.
+32       *
+33       * @param name  column name
+34       * @return  relative JCR path
+35       */
+36      String jcrPathFromCol(String name);
+37  
+38      /**
+39       * JCR type name corresponding to the CMIS type bound to this instance.
+40       * @see #jcrTypeCondition()
+41       *
+42       * @return  name of the JCR type
+43       */
+44      String jcrTypeName();
+45  
+46      /**
+47       * Create and additional condition in order for the query to only return nodes
+48       * of the right type. This condition and-ed to the condition determined by the
+49       * CMIS query's where clause.
+50       * <p/>
+51       * A CMIS query for non versionable documents should for example result in the
+52       * following XPath query:
+53       * <p/>
+54       * <pre>
+55       *   element(*, nt:file)[not(@jcr:mixinTypes = 'mix:simpleVersionable')]
+56       * </pre>
+57       * Here the element test is covered by {@link #jcrTypeName()}
+58       * while the predicate is covered by this method.
+59       *
+60       * @see #jcrTypeName()
+61       *
+62       * @return  Additional condition or <code>null</code> if none.
+63       */
+64      String jcrTypeCondition();
+65  }
+
+
+ + Added: chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-jcr/xref/org/apache/chemistry/opencmis/jcr/query/IdentifierMapBase.html URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-jcr/xref/org/apache/chemistry/opencmis/jcr/query/IdentifierMapBase.html?rev=1486802&view=auto ============================================================================== --- chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-jcr/xref/org/apache/chemistry/opencmis/jcr/query/IdentifierMapBase.html (added) +++ chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-jcr/xref/org/apache/chemistry/opencmis/jcr/query/IdentifierMapBase.html Tue May 28 07:50:50 2013 @@ -0,0 +1,68 @@ + + + + +IdentifierMapBase 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.jcr.query;
+20  
+21  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+22  
+23  import java.util.HashMap;
+24  import java.util.Map;
+25  
+26  /**
+27   * This abstract base class provides support for implementing {@link IdentifierMap}.
+28   */
+29  public abstract class IdentifierMapBase implements IdentifierMap {
+30  
+31      private final String jcrTypeName;
+32      protected final Map<String, String> cmis2Jcr = new HashMap<String, String>();
+33  
+34      protected IdentifierMapBase(String jcrTypeName) {
+35          this.jcrTypeName = jcrTypeName;
+36      }
+37  
+38      public String jcrPathFromCol(String name) {
+39          String jcrPath = cmis2Jcr.get(name);
+40          if (jcrPath == null) {
+41              throw new CmisRuntimeException("Not supported: query on column " + name);
+42          } else {
+43              return jcrPath;
+44          }
+45      }
+46  
+47      public String jcrTypeName() {
+48          return jcrTypeName;
+49      }
+50  
+51      public String jcrTypeCondition() {
+52          return null;
+53      }
+54  }
+
+
+ + Added: chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-jcr/xref/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.html URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-jcr/xref/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.html?rev=1486802&view=auto ============================================================================== --- chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-jcr/xref/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.html (added) +++ chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-jcr/xref/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.html Tue May 28 07:50:50 2013 @@ -0,0 +1,342 @@ + + + + +ParseTreeWalker 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  
+20  package org.apache.chemistry.opencmis.jcr.query;
+21  
+22  import org.antlr.runtime.tree.Tree;
+23  import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+24  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+25  import org.apache.chemistry.opencmis.server.support.query.CalendarHelper;
+26  import org.apache.chemistry.opencmis.server.support.query.CmisQlStrictLexer;
+27  import org.apache.chemistry.opencmis.server.support.query.PredicateWalkerBase;
+28  import org.apache.chemistry.opencmis.server.support.query.TextSearchLexer;
+29  
+30  import java.util.ArrayList;
+31  import java.util.List;
+32  
+33  /**
+34   * This implementation of {@link PredicateWalkerBase} traverses the parse tree of a CMIS query.
+35   * It uses an {@link Evaluator} to accumulate the result of the traversal. <code>Evaluator</code>
+36   * has a corresponding method for each {@link Tree#getType() node type} in the parse tree.
+37   * <code>ParseTreeWalker</code> calls these methods while traversing the parse tree passing an
+38   * <code>Evaluator</code> for each of the corresponding operation's arguments.
+39   * </br>
+40   * The {@link #walkPredicate(Tree)} serves as entry point for traversing a parse tree. After
+41   * successful traversal, the result is obtained from the {@link #getResult()} method.
+42   *
+43   * @param <T>  type of the result determined by the <code>Evaluator</code> used.
+44   */
+45  public class ParseTreeWalker<T> implements PredicateWalkerBase {
+46  
+47      private final Evaluator<T> evaluator;
+48      private T result;
+49  
+50      /**
+51       * Create a new instance for traversing CMIS query parse trees.
+52       *
+53       * @param evaluator  <code>Evaluator</code> for evaluating the nodes of the parse tree
+54       */
+55      public ParseTreeWalker(Evaluator<T> evaluator) {
+56          this.evaluator = evaluator;
+57      }
+58  
+59      /**
+60       * Retrieve the result of a successful traversal.
+61       *
+62       * @return  result of traversal or <code>null</code> if either not yet traversed, an error occurred
+63       *      on traversal or the query has an empty where clause. 
+64       */
+65      public T getResult() {
+66          return result;
+67      }
+68  
+69      //------------------------------------------< PredicateWalkerBase >---
+70      
+71      public Boolean walkPredicate(Tree node) {
+72          result = null;
+73          result = walkPredicate(evaluator, node);
+74          return false; // Return value is ignored by caller
+75      }
+76  
+77      //------------------------------------------< protected >---
+78  
+79      /** For extensibility. */
+80      protected T walkOtherExpr(Evaluator<?> evaluator, Tree node) {
+81          throw new CmisRuntimeException("Unknown node type: " + node.getType() + " (" + node.getText() + ")");
+82      }
+83  
+84      /** For extensibility. */
+85      protected T walkOtherPredicate(Evaluator<?> evaluator, Tree node) {
+86          throw new CmisRuntimeException("Unknown node type: " + node.getType() + " (" + node.getText() + ")");
+87      }
+88  
+89      //------------------------------------------< private >---
+90  
+91      private T walkPredicate(Evaluator<T> evaluator, Tree node) {
+92          switch (node.getType()) {
+93              case CmisQlStrictLexer.NOT:
+94                  return evaluator.not(walkPredicate(evaluator.op(), node.getChild(0)));
+95              case CmisQlStrictLexer.AND:
+96                  return evaluator.and(
+97                          walkPredicate(evaluator.op(), node.getChild(0)),
+98                          walkPredicate(evaluator.op(), node.getChild(1)));
+99              case CmisQlStrictLexer.OR:
+100                 return evaluator.or(
+101                         walkPredicate(evaluator.op(), node.getChild(0)),
+102                         walkPredicate(evaluator.op(), node.getChild(1)));
+103             case CmisQlStrictLexer.EQ:
+104                 return evaluator.eq(
+105                         walkExpr(evaluator.op(), node.getChild(0)),
+106                         walkExpr(evaluator.op(), node.getChild(1)));
+107             case CmisQlStrictLexer.NEQ:
+108                 return evaluator.neq(
+109                         walkExpr(evaluator.op(), node.getChild(0)),
+110                         walkExpr(evaluator.op(), node.getChild(1)));
+111             case CmisQlStrictLexer.GT:
+112                 return evaluator.gt(
+113                         walkExpr(evaluator.op(), node.getChild(0)),
+114                         walkExpr(evaluator.op(), node.getChild(1)));
+115             case CmisQlStrictLexer.GTEQ:
+116                 return evaluator.gteq(
+117                         walkExpr(evaluator.op(), node.getChild(0)),
+118                         walkExpr(evaluator.op(), node.getChild(1)));
+119             case CmisQlStrictLexer.LT:
+120                 return evaluator.lt(
+121                         walkExpr(evaluator.op(), node.getChild(0)),
+122                         walkExpr(evaluator.op(), node.getChild(1)));
+123             case CmisQlStrictLexer.LTEQ:
+124                 return evaluator.lteq(
+125                         walkExpr(evaluator.op(), node.getChild(0)),
+126                         walkExpr(evaluator.op(), node.getChild(1)));
+127             case CmisQlStrictLexer.IN:
+128                 return evaluator.in(
+129                         walkExpr(evaluator.op(), node.getChild(0)),
+130                         walkExpr(evaluator.op(), node.getChild(1)));
+131             case CmisQlStrictLexer.NOT_IN:
+132                 return evaluator.notIn(
+133                         walkExpr(evaluator.op(), node.getChild(0)),
+134                         walkExpr(evaluator.op(), node.getChild(1)));
+135             case CmisQlStrictLexer.IN_ANY:
+136                 return evaluator.inAny(
+137                         walkExpr(evaluator.op(), node.getChild(0)),
+138                         walkExpr(evaluator.op(), node.getChild(1)));
+139             case CmisQlStrictLexer.NOT_IN_ANY:
+140                 return evaluator.notInAny(
+141                         walkExpr(evaluator.op(), node.getChild(0)),
+142                         walkExpr(evaluator.op(), node.getChild(1)));
+143             case CmisQlStrictLexer.EQ_ANY:
+144                 return evaluator.eqAny(
+145                         walkExpr(evaluator.op(), node.getChild(0)),
+146                         walkExpr(evaluator.op(), node.getChild(1)));
+147             case CmisQlStrictLexer.IS_NULL:
+148                 return evaluator.isNull(walkExpr(evaluator.op(), node.getChild(0)));
+149             case CmisQlStrictLexer.IS_NOT_NULL:
+150                 return evaluator.notIsNull(walkExpr(evaluator.op(), node.getChild(0)));
+151             case CmisQlStrictLexer.LIKE:
+152                 return evaluator.like(
+153                         walkExpr(evaluator.op(), node.getChild(0)),
+154                         walkExpr(evaluator.op(), node.getChild(1)));
+155             case CmisQlStrictLexer.NOT_LIKE:
+156                 return evaluator.notLike(
+157                         walkExpr(evaluator.op(), node.getChild(0)),
+158                         walkExpr(evaluator.op(), node.getChild(1)));
+159             case CmisQlStrictLexer.CONTAINS:
+160                 if (node.getChildCount() == 1) {
+161                     return evaluator.contains(
+162                             null,
+163                             walkExprTextSearch(evaluator.op(), node.getChild(0)));
+164                 }
+165                 else {
+166                     return evaluator.contains(
+167                             walkExpr(evaluator.op(), node.getChild(0)),
+168                             walkExpr(evaluator.op(), node.getChild(1)));
+169                 }
+170             case CmisQlStrictLexer.IN_FOLDER:
+171                 if (node.getChildCount() == 1) {
+172                     return evaluator.inFolder(
+173                             null,
+174                             walkExpr(evaluator.op(), node.getChild(0)));
+175                 }
+176                 else {
+177                     return evaluator.inFolder(
+178                             walkExpr(evaluator.op(), node.getChild(0)),
+179                             walkExpr(evaluator.op(), node.getChild(1)));
+180                 }
+181             case CmisQlStrictLexer.IN_TREE:
+182                 if (node.getChildCount() == 1) {
+183                     return evaluator.inTree(
+184                             null,
+185                             walkExpr(evaluator.op(), node.getChild(0)));
+186                 }
+187                 else {
+188                     return evaluator.inTree(
+189                             walkExpr(evaluator.op(), node.getChild(0)),
+190                             walkExpr(evaluator.op(), node.getChild(1)));
+191                 }
+192             default:
+193                 return walkOtherPredicate(evaluator, node);
+194         }
+195     }
+196 
+197     private T walkExpr(Evaluator<T> evaluator, Tree node) {
+198         switch (node.getType()) {
+199             case CmisQlStrictLexer.BOOL_LIT:
+200                 return walkBoolean(evaluator, node);
+201             case CmisQlStrictLexer.NUM_LIT:
+202                 return walkNumber(evaluator, node);
+203             case CmisQlStrictLexer.STRING_LIT:
+204                 return walkString(evaluator, node);
+205             case CmisQlStrictLexer.TIME_LIT:
+206                 return walkTimestamp(evaluator, node);
+207             case CmisQlStrictLexer.IN_LIST:
+208                 return evaluator.list(walkList(evaluator, node));
+209             case CmisQlStrictLexer.COL:
+210                 return walkCol(evaluator, node);
+211             default:
+212                 return walkOtherExpr(evaluator, node);
+213         }
+214     }
+215     
+216     private T walkExprTextSearch(Evaluator<T> evaluator, Tree node) {
+217         switch (node.getType()) {
+218             case TextSearchLexer.TEXT_AND:
+219                 return walkTextAnd(evaluator, node);
+220             case TextSearchLexer.TEXT_OR:
+221                 return walkTextOr(evaluator, node);
+222             case TextSearchLexer.TEXT_MINUS:
+223                 return walkTextMinus(evaluator, node);
+224             case TextSearchLexer.TEXT_SEARCH_WORD_LIT:
+225                 return walkTextWord(evaluator, node);
+226             case TextSearchLexer.TEXT_SEARCH_PHRASE_STRING_LIT:
+227                 return walkTextPhrase(evaluator, node);
+228             default:
+229                 return walkOtherExpr(evaluator, node);
+230         }
+231     }
+232 
+233     private List<T> walkList(Evaluator<T> evaluator, Tree node) {
+234         int n = node.getChildCount();
+235         List<T> result = new ArrayList<T>(n);
+236         for (int i = 0; i < n; i++) {
+237             result.add(walkExpr(evaluator.op(), node.getChild(i)));
+238         }
+239         return result;
+240     }
+241 
+242     private T walkBoolean(Evaluator<T> evaluator, Tree node) {
+243         String s = node.getText();
+244 
+245         if ("true".equalsIgnoreCase(s)) {
+246             return evaluator.value(true);
+247         }
+248         else if ("false".equalsIgnoreCase(s)) {
+249             return evaluator.value(false);
+250         }
+251         else {
+252             throw new CmisInvalidArgumentException("Not a boolean: " + s);
+253         }
+254     }
+255 
+256     private T walkNumber(Evaluator<T> evaluator, Tree node) {
+257         String s = node.getText();
+258         try {
+259             return s.contains(".") || s.contains("e") || s.contains("E")
+260                     ? evaluator.value(Double.valueOf(s))
+261                     : evaluator.value(Long.valueOf(s));
+262         }
+263         catch (NumberFormatException e) {
+264             throw new CmisInvalidArgumentException("Not a number: " + s);
+265         }
+266     }
+267 
+268     private T walkString(Evaluator<T> evaluator, Tree node) {
+269         String s = node.getText();
+270         s = s.substring(1, s.length() - 1);
+271         return evaluator.value(s.replace("''", "'"));  // un-escape quotes
+272     }
+273 
+274     private T walkTimestamp(Evaluator<T> evaluator, Tree node) {
+275         String s = node.getText();
+276         s = s.substring(s.indexOf('\'') + 1, s.length() - 1);
+277         try {
+278             return evaluator.value(CalendarHelper.fromString(s));
+279         }
+280         catch (IllegalArgumentException e) {
+281             throw new CmisInvalidArgumentException("Not a date time value: " + s);
+282         }
+283     }
+284 
+285     private T walkCol(Evaluator<T> evaluator, Tree node) {
+286         return evaluator.col(node.getChild(0).getText());
+287     }
+288 
+289     private T walkTextAnd(Evaluator<T> evaluator, Tree node) {
+290         List<T> terms = new ArrayList<T>();
+291         for (Tree term: getChildrenAsList(node)) {
+292             terms.add(walkExprTextSearch(evaluator, term));
+293         }
+294 
+295         return evaluator.textAnd(terms);
+296     }
+297     
+298     private T walkTextOr(Evaluator<T> evaluator, Tree node) {
+299         List<T> terms = new ArrayList<T>();
+300         for (Tree term: getChildrenAsList(node)) {
+301             terms.add(walkExprTextSearch(evaluator, term));
+302         }
+303 
+304         return evaluator.textOr(terms);
+305     }
+306     
+307     private T walkTextMinus(Evaluator<T> evaluator, Tree node) {
+308         return evaluator.textMinus(node.getChild(0).getText());
+309     }
+310     
+311     private T walkTextWord(Evaluator<T> evaluator, Tree node) {
+312         return evaluator.textWord(node.getText());
+313     }
+314     
+315     private T walkTextPhrase(Evaluator<T> evaluator, Tree node) {
+316         return evaluator.textPhrase(node.getText());
+317     }
+318 
+319     private static List<Tree> getChildrenAsList(Tree node) {
+320         List<Tree> res = new ArrayList<Tree>(node.getChildCount());
+321         for (int i=0; i<node.getChildCount(); i++) {
+322             Tree childNode =  node.getChild(i);
+323             res.add(childNode);
+324         }
+325         return res;
+326     }
+327 
+328 }
+
+
+ +