KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > index > BasicExpressionFactoryTxtContainsSample


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/stores/org/apache/slide/index/BasicExpressionFactoryTxtContainsSample.java,v 1.2 2004/07/11 10:12:50 unico Exp $
3  * $Revision: 1.2 $
4  * $Date: 2004/07/11 10:12:50 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.index;
25
26 import java.util.Collection JavaDoc;
27
28 import org.apache.slide.content.NodeProperty.NamespaceCache;
29 import org.apache.slide.search.BadQueryException;
30 import org.apache.slide.search.PropertyProvider;
31 import org.apache.slide.search.basic.IBasicExpression;
32 import org.apache.slide.search.basic.IBasicExpressionFactory;
33 import org.apache.slide.search.basic.IBasicQuery;
34 import org.jdom.Element;
35
36 /**
37  * This factory creates executable BasicExpressions. An instance is created for
38  * each SEARCH request.
39  * */

40 public class BasicExpressionFactoryTxtContainsSample implements IBasicExpressionFactory
41 {
42     
43     
44     private IBasicQuery query;
45     protected PropertyProvider propertyProvider;
46     
47     private String JavaDoc rootPath;
48     
49     /**
50      * Constructor
51      *
52      * @param rootPath path to the content files
53      *
54      */

55     public BasicExpressionFactoryTxtContainsSample (String JavaDoc rootPath)
56     {
57         this.rootPath = rootPath;
58     }
59     
60     /**
61      * called for merge expressions (or, and). Not defined here
62      *
63      * @param mergeOperator and, or
64      * @param namespace the namespace of this expression
65      * @param expressionsToMerge all expressions, that shall be merged
66      *
67      * @return an IBasicExpression
68      *
69      * @throws BadQueryException
70      *
71      */

72     public IBasicExpression createMergeExpression (String JavaDoc mergeOperator,
73                                                    String JavaDoc namespace,
74                                                    Collection JavaDoc expressionsToMerge)
75         throws BadQueryException
76     {
77         return null;
78     }
79     
80     /**
81      * Called by the expression compiler for each leave expression.
82      *
83      * @param element an Element discribing the expression
84      *
85      * @return an IBasicExpression
86      *
87      * @throws BadQueryException
88      *
89      */

90     public IBasicExpression createExpression (Element element)
91         throws BadQueryException
92     {
93         BasicExpressionTxtContainsSample result = null;
94         
95         if (element == null)
96         {
97             throw new BadQueryException ("expected a where criteria");
98         }
99         else
100         {
101             String JavaDoc namespace = element.getNamespace().getURI();
102             if (namespace.equals (NamespaceCache.DEFAULT_URI))
103                 result = createDAVExpression (element);
104             
105             // allow store specific extensions
106
// else if (namespace.equals (MyNamespace))
107
// result = createMyExpression (element);
108
}
109         result.setFactory(this);
110         return result;
111     }
112     
113     
114     /**
115      * Called, when the expression is in the default (DAV:) namespace.
116      *
117      *
118      * @param e an Element
119      *
120      * @return a BasicExpressionTemplate
121      *
122      */

123     private BasicExpressionTxtContainsSample createDAVExpression (Element e)
124     {
125         String JavaDoc name = e.getName();
126         BasicExpressionTxtContainsSample result = null;
127         
128         if (name.equals ("contains"))
129         {
130             String JavaDoc searchedText = e.getTextTrim();
131             result = new BasicExpressionTxtContainsSample (searchedText, rootPath);
132         }
133         
134         return result;
135     }
136     
137     /**
138      * called by BasicExpressionCompiler after construction.
139      *
140      * @param query the associated BasicQuery
141      * @param propertyProvider the PropertyProvider for this expression.
142      *
143      * @throws BadQueryException
144      *
145      */

146     public void init(IBasicQuery query, PropertyProvider propertyProvider)
147         throws BadQueryException
148     {
149         this.query = (IBasicQuery) query;
150         this.propertyProvider = propertyProvider;
151     }
152     
153     /**
154      * Method getPropertyProvider
155      *
156      * @return the PropertyProvider
157      *
158      */

159     public PropertyProvider getPropertyProvider()
160     {
161         return propertyProvider;
162     }
163     
164     /**
165      * Method getQuery
166      *
167      * @return the IBasicQuery
168      *
169      */

170     public IBasicQuery getQuery()
171     {
172         return query;
173     }
174
175 }
176
177
Popular Tags