KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/stores/org/apache/slide/index/TextContainsExpressionFactory.java,v 1.1.2.2 2004/09/13 16:52:25 unico Exp $
3  * $Revision: 1.1.2.2 $
4  * $Date: 2004/09/13 16:52:25 $
5  *
6  * ====================================================================
7  *
8  * Copyright 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 org.apache.slide.search.basic.IBasicExpressionFactory;
27 import org.apache.slide.search.basic.IBasicQuery;
28 import org.apache.slide.search.basic.IBasicExpression;
29 import org.apache.slide.search.PropertyProvider;
30 import org.apache.slide.search.BadQueryException;
31 import org.apache.slide.content.NodeProperty;
32 import org.jdom.Element;
33
34 import org.apache.lucene.analysis.Analyzer;
35
36 import java.util.Collection JavaDoc;
37
38 /**
39  * Date: Jun 24, 2004
40  * Time: 11:42:35 PM
41  */

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

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

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

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

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

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

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

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