View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  /*
17   * $Header: /home/cvs/jakarta-slide/src/stores/org/apache/slide/index/BasicExpressionFactoryTxtContainsSample.java,v 1.2 2004/07/11 10:12:50 unico Exp $
18   * $Revision: 1.2 $
19   * $Date: 2004/07/11 10:12:50 $
20   *
21   * ====================================================================
22   *
23   * Copyright 1999-2004 The Apache Software Foundation
24   *
25   * Licensed under the Apache License, Version 2.0 (the "License");
26   * you may not use this file except in compliance with the License.
27   * You may obtain a copy of the License at
28   *
29   *     http://www.apache.org/licenses/LICENSE-2.0
30   *
31   * Unless required by applicable law or agreed to in writing, software
32   * distributed under the License is distributed on an "AS IS" BASIS,
33   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34   * See the License for the specific language governing permissions and
35   * limitations under the License.
36   *
37   */
38  
39  package com.isenshi.util.extlib;
40  
41  import java.util.Collection;
42  
43  import org.apache.slide.content.NodeProperty.NamespaceCache;
44  import org.apache.slide.search.BadQueryException;
45  import org.apache.slide.search.PropertyProvider;
46  import org.apache.slide.search.basic.IBasicExpression;
47  import org.apache.slide.search.basic.IBasicExpressionFactory;
48  import org.apache.slide.search.basic.IBasicQuery;
49  import org.jdom.Element;
50  
51  /***
52   * This factory creates executable BasicExpressions. An instance is created for
53   * each SEARCH request.
54   * */
55  public class BasicExpressionFactoryTxtContainsCJK implements IBasicExpressionFactory
56  {
57      
58      
59      private IBasicQuery query;
60      protected PropertyProvider propertyProvider;
61      
62      private String rootPath;
63      
64      /***
65       * Constructor
66       *
67       * @param    rootPath           path to the content files
68       *
69       */
70      public BasicExpressionFactoryTxtContainsCJK (String rootPath)
71      {
72          this.rootPath = rootPath;
73      }
74      
75      /***
76       * called for merge expressions (or, and). Not defined here
77       *
78       * @param    mergeOperator       and, or
79       * @param    namespace           the namespace of this expression
80       * @param    expressionsToMerge  all expressions, that shall be merged
81       *
82       * @return   an IBasicExpression
83       *
84       * @throws   BadQueryException
85       *
86       */
87      public IBasicExpression createMergeExpression (String mergeOperator,
88                                                     String namespace,
89                                                     Collection expressionsToMerge)
90          throws BadQueryException
91      {
92          return null;
93      }
94      
95      /***
96       * Called by the expression compiler for each leave expression.
97       *
98       * @param    element             an Element discribing the expression
99       *
100      * @return   an IBasicExpression
101      *
102      * @throws   BadQueryException
103      *
104      */
105     public IBasicExpression createExpression (Element element)
106         throws BadQueryException
107     {
108         BasicExpressionTxtContainsCJK result = null;
109         
110         if (element == null)
111         {
112             throw new BadQueryException ("expected a where criteria");
113         }
114         else
115         {
116             String namespace = element.getNamespace().getURI();
117             if (namespace.equals (NamespaceCache.DEFAULT_URI))
118                 result = createDAVExpression (element);
119             
120             // allow store specific extensions
121             //  else if (namespace.equals (MyNamespace))
122             //      result = createMyExpression (element);
123         }
124         result.setFactory(this);
125         return result;
126     }
127     
128     
129     /***
130      * Called, when the expression is in the default (DAV:) namespace.
131      *
132      *
133      * @param    e                   an Element
134      *
135      * @return   a BasicExpressionTemplate
136      *
137      */
138     private BasicExpressionTxtContainsCJK createDAVExpression (Element e)
139     {
140         String name = e.getName();
141         BasicExpressionTxtContainsCJK result = null;
142         
143         if (name.equals ("contains"))
144         {
145             String searchedText = e.getTextTrim();
146             result = new BasicExpressionTxtContainsCJK (searchedText, rootPath);
147         }
148         
149         return result;
150     }
151     
152     /***
153      * called by BasicExpressionCompiler after construction.
154      *
155      * @param    query               the associated BasicQuery
156      * @param    propertyProvider    the PropertyProvider for this expression.
157      *
158      * @throws   BadQueryException
159      *
160      */
161     public void init(IBasicQuery query, PropertyProvider propertyProvider)
162         throws BadQueryException
163     {
164         this.query = (IBasicQuery) query;
165         this.propertyProvider = propertyProvider;
166     }
167     
168     /***
169      * Method getPropertyProvider
170      *
171      * @return   the PropertyProvider
172      *
173      */
174     public PropertyProvider getPropertyProvider()
175     {
176         return propertyProvider;
177     }
178     
179     /***
180      * Method getQuery
181      *
182      * @return   the IBasicQuery
183      *
184      */
185     public IBasicQuery getQuery()
186     {
187         return query;
188     }
189 
190 }
191