KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > controllers > kernel > impl > simple > ExtendedSearchCriterias


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23 package org.infoglue.cms.controllers.kernel.impl.simple;
24
25 import java.sql.Timestamp JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Date JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.infoglue.cms.entities.content.ContentVersionVO;
31 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO;
32 import org.infoglue.cms.entities.management.LanguageVO;
33
34 /**
35  * Criterias for the <code>ExtendedSearchController</code>.
36  */

37 public class ExtendedSearchCriterias
38 {
39     /**
40      * Indicates that no date criteria should be used.
41      */

42     public static final int NO_DATE_CRITERIA_TYPE = 0;
43
44     /**
45      * Indicates that the from date criteria should be used.
46      */

47     public static final int FROM_DATE_CRITERIA_TYPE = 1;
48
49     /**
50      * Indicates that the to date criteria should be used.
51      */

52     public static final int TO_DATE_CRITERIA_TYPE = 2;
53
54     /**
55      * Indicates that the between date criteria should be used.
56      */

57     public static final int BOTH_DATE_CRITERIA_TYPE = 3;
58
59     /**
60      * Only fetch content versions having at least the present state.
61      */

62     private Integer JavaDoc stateId;
63     
64     /**
65      * If present, only fetch content version that has at least one attribute fulfilling:
66      * (a) the attribute is present in the <code>xmlAttributes</code> list.
67      * (b) the value of the attribute contains the freetext value.
68      */

69     private String JavaDoc freetext;
70     
71     /**
72      * The list of content version attributes to search in the freetext search.
73      */

74     private List JavaDoc xmlAttributes; // type: <String>
75

76     /**
77      * If present, only fetch content versions with this language.
78      */

79     private LanguageVO languageVO;
80     
81     /**
82      * If present, only fetch contents whose type is present in the list.
83      */

84     private List JavaDoc contentTypeDefinitionVOs; // type: <ContentTypeDefinitionVO>
85

86     /**
87      * If present, only fetch content versions fulfilling the category condition.
88      */

89     private CategoryConditions categories;
90     
91     /**
92      * If present, only fetch contents published after this date.
93      */

94     private Timestamp JavaDoc fromDate;
95     
96     /**
97      * If present, only fetch contents published before this date.
98      */

99     private Timestamp JavaDoc toDate;
100
101     /**
102      * Constructs a criteria object with the state critera set to <code>ContentVersionVO.WORKING_STATE</code>.
103      */

104     public ExtendedSearchCriterias()
105     {
106         this(ContentVersionVO.WORKING_STATE.intValue());
107     }
108     
109     /**
110      * Constructs a criteria object with the specified state critera.
111      *
112      * @param stateId the stateId to use.
113      */

114     public ExtendedSearchCriterias(final int stateId)
115     {
116         super();
117         this.stateId = new Integer JavaDoc(stateId);
118     }
119     
120     /**
121      * Sets the freetext critera.
122      * Note that at least one attribute must be specified to enabled freetext search.
123      *
124      * @param freetext the freetext to use.
125      * @param xmlAttributes the list of attribute names to use.
126      */

127     public void setFreetext(final String JavaDoc freetext, final List JavaDoc xmlAttributes)
128     {
129         this.freetext = freetext;
130         if(xmlAttributes != null)
131         {
132             this.xmlAttributes = new ArrayList JavaDoc(xmlAttributes);
133         }
134     }
135     
136     /**
137      * Sets the language criteria.
138      *
139      * @param languageVO the language to use.
140      */

141     public void setLanguage(final LanguageVO languageVO)
142     {
143         this.languageVO = languageVO;
144     }
145     
146     /**
147      * Sets the content type definition critiera.
148      *
149      * @param contentTypeDefinitionVO the content type definition to use.
150      */

151     public void setContentTypeDefinitions(final ContentTypeDefinitionVO contentTypeDefinitionVO)
152     {
153         if(contentTypeDefinitionVO != null)
154         {
155             contentTypeDefinitionVOs = new ArrayList JavaDoc();
156             contentTypeDefinitionVOs.add(contentTypeDefinitionVO);
157         }
158     }
159     
160     /**
161      * Sets the content type definition critiera.
162      *
163      * @param contentTypeDefinitionVOs the list of <code>ContentTypeDefinitionVO</code> to use.
164      */

165     public void setContentTypeDefinitions(final List JavaDoc contentTypeDefinitionVOs)
166     {
167         if(contentTypeDefinitionVOs != null)
168         {
169             this.contentTypeDefinitionVOs = new ArrayList JavaDoc(contentTypeDefinitionVOs);
170         }
171     }
172     
173     /**
174      * Sets the category criteria.
175      *
176      * @param categories the category condition to use.
177      */

178     public void setCategoryConditions(final CategoryConditions categories)
179     {
180         this.categories = categories;
181     }
182     
183     /**
184      * Sets the date critiera.
185      *
186      * @param from the from date to use (null is used to indicate an open end).
187      * @param to the to date to use (null is used to indicate an open end).
188      */

189     public void setDates(final Date JavaDoc from, final Date JavaDoc to)
190     {
191         this.fromDate = (from == null) ? null : new Timestamp JavaDoc(from.getTime());
192         this.toDate = (to == null) ? null : new Timestamp JavaDoc(to.getTime());
193     }
194     
195     /**
196      * Returns true if the freetext criteria should be used; false otherwise.
197      *
198      * @return true if the criteria should be used; false otherwise.
199      */

200     public boolean hasFreetextCritera()
201     {
202         return freetext != null && freetext.length() > 0 && xmlAttributes != null && !xmlAttributes.isEmpty();
203     }
204
205     /**
206      * Returns true if the language criteria should be used; false otherwise.
207      *
208      * @return true if the criteria should be used; false otherwise.
209      */

210     public boolean hasLanguageCriteria()
211     {
212         return languageVO != null;
213     }
214     
215     /**
216      * Returns true if the content type definition criteria should be used; false otherwise.
217      *
218      * @return true if the criteria should be used; false otherwise.
219      */

220     public boolean hasContentTypeDefinitionVOsCriteria()
221     {
222         return contentTypeDefinitionVOs != null && !contentTypeDefinitionVOs.isEmpty();
223     }
224     
225     /**
226      * Returns true if the category criteria should be used; false otherwise.
227      *
228      * @return true if the criteria should be used; false otherwise.
229      */

230     public boolean hasCategoryConditions()
231     {
232         return categories != null && categories.hasCondition();
233     }
234     
235     /**
236      * Returns the type of date critiera to use.
237      *
238      * @return the type of date criteria to use.
239      */

240     public int getDateCriteriaType()
241     {
242         if(toDate == null && fromDate == null)
243         {
244             return NO_DATE_CRITERIA_TYPE;
245         }
246         if(toDate != null && fromDate == null)
247         {
248             return NO_DATE_CRITERIA_TYPE;
249         }
250         if(toDate == null && fromDate != null)
251         {
252             return FROM_DATE_CRITERIA_TYPE;
253         }
254         return BOTH_DATE_CRITERIA_TYPE;
255     }
256     
257     /**
258      * Returns the state to use in the state criteria.
259      *
260      * @return the state.
261      */

262     public Integer JavaDoc getStateId()
263     {
264         return this.stateId;
265     }
266     
267     /**
268      * Returns the freetext to use in the freetext criteria.
269      *
270      * @return the freetext.
271      */

272     public String JavaDoc getFreetext()
273     {
274         return this.freetext;
275     }
276
277     /**
278      * Returns the attributes to use in the freetext criteria.
279      *
280      * @return the list of attribute names.
281      */

282     public List JavaDoc getXmlAttributes()
283     {
284         return this.xmlAttributes;
285     }
286
287     /**
288      * Returns the language to use in the language criteria.
289      *
290      * @return the language.
291      */

292     public LanguageVO getLanguage()
293     {
294         return this.languageVO;
295     }
296     
297     /**
298      * Returns the content type definitions to use in the content type definition criteria.
299      *
300      * @return the list of <code>ContentTypeDefinitionVO</code>:s.
301      */

302     public List JavaDoc getContentTypeDefinitions()
303     {
304         return this.contentTypeDefinitionVOs;
305     }
306
307     /**
308      * Returns the category condition to use in the category condition criteria.
309      *
310      * @return the category condition.
311      */

312     public CategoryConditions getCategories()
313     {
314         return this.categories;
315     }
316
317     /**
318      * Returns the from date to use in the date criteria.
319      *
320      * @return the from date.
321      */

322     public Timestamp JavaDoc getFromDate()
323     {
324         return this.fromDate;
325     }
326
327     /**
328      * Returns the to date to use in the date criteria.
329      *
330      * @return the to date.
331      */

332     public Timestamp JavaDoc getToDate()
333     {
334         return this.toDate;
335     }
336 }
337
Popular Tags