KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > workplace > CmsSearchForm


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsSearchForm.java,v $
3 * Date : $Date: 2005/05/17 13:47:28 $
4 * Version: $Revision: 1.1 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * For further information about OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */

28
29
30 package com.opencms.workplace;
31
32 import org.opencms.file.CmsObject;
33 import org.opencms.file.CmsPropertyDefinition;
34 import org.opencms.main.CmsException;
35
36 import com.opencms.core.I_CmsSession;
37 import com.opencms.legacy.CmsXmlTemplateLoader;
38
39 import java.util.Hashtable JavaDoc;
40 import java.util.Iterator JavaDoc;
41 import java.util.List JavaDoc;
42 import java.util.Vector JavaDoc;
43
44 /**
45  * News administration template class
46  * <p>
47  * Used both for displaying news administration overviews and
48  * editing news.
49  *
50  * @author Edna Falkenhan
51  * @version $Revision: 1.1 $ $Date: 2005/05/17 13:47:28 $
52  * @see com.opencms.workplace.CmsXmlWpTemplateFile
53  *
54  * @deprecated Will not be supported past the OpenCms 6 release.
55  */

56
57 public class CmsSearchForm extends CmsWorkplaceDefault {
58
59     /**
60      * Gets the content of a defined section in a given template file and its subtemplates
61      * with the given parameters.
62      *
63      * @see #getContent(CmsObject, String, String, Hashtable, String)
64      * @param cms CmsObject Object for accessing system resources.
65      * @param templateFile Filename of the template file.
66      * @param elementName Element name of this template in our parent template.
67      * @param parameters Hashtable with all template class parameters.
68      * @param templateSelector template section that should be processed.
69      */

70
71     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
72             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
73         // get the session
74
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
75         String JavaDoc error = "";
76         String JavaDoc reload = "";
77         boolean luceneEnabled = false;
78
79         // load the template file
80
CmsXmlWpTemplateFile template = (CmsXmlWpTemplateFile)getOwnTemplateFile(cms,
81                 templateFile, elementName, parameters, templateSelector);
82         String JavaDoc action = (String JavaDoc)parameters.get("action")!=null?(String JavaDoc)parameters.get("action"):"";
83         String JavaDoc propRestype = (String JavaDoc)parameters.get("proprestype");
84         String JavaDoc propKey = (String JavaDoc)parameters.get("propkey");
85         String JavaDoc propValue = (String JavaDoc)parameters.get("propvalue");
86         String JavaDoc content = (String JavaDoc)parameters.get("content");
87         String JavaDoc filename = (String JavaDoc)parameters.get("filename");
88
89         // try to get values for the searchform from the session
90
Hashtable JavaDoc filters = (Hashtable JavaDoc)session.getValue("ocms_search.allfilter");
91         CmsSearchFormObject propFilter = null;
92         CmsSearchFormObject filenameFilter = null;
93         CmsSearchFormObject contentFilter = null;
94         if(filters != null){
95             propFilter = (CmsSearchFormObject)filters.get("property");
96             filenameFilter = (CmsSearchFormObject)filters.get("filename");
97             contentFilter = (CmsSearchFormObject)filters.get("content");
98         }
99
100         if(propFilter != null){
101             if(propRestype == null){
102                 propRestype = propFilter.getValue01()!=null?propFilter.getValue01():"";
103             }
104             if(propKey == null){
105                 propKey = propFilter.getValue02()!=null?propFilter.getValue02():"";
106             }
107             if(propValue == null){
108                 propValue = propFilter.getValue03()!=null?propFilter.getValue03():"";
109             }
110         }
111
112         if(filenameFilter != null){
113             if(filename == null){
114                 filename = filenameFilter.getValue01()!=null?filenameFilter.getValue01():"";
115             }
116         }
117
118         if(contentFilter != null){
119             if(content == null){
120                 content = contentFilter.getValue01()!=null?contentFilter.getValue01():"";
121             }
122         }
123
124         propRestype = propRestype!=null?propRestype:"";
125         propKey = propKey!=null?propKey:"";
126         propValue = propValue!=null?propValue:"";
127         content = content!=null?content:"";
128         filename = filename!=null?filename:"";
129
130         // set the selectboxes
131
this.getResourceTypes(cms, template, propRestype);
132         this.getPropertyDefs(cms, template, propRestype, propKey);
133
134         // create one CmsSearchFormObject for each search filter
135
filters = new Hashtable JavaDoc();
136         propFilter = new CmsSearchFormObject("property", propRestype, propKey, propValue);
137         filters.put("property", propFilter);
138         filenameFilter = new CmsSearchFormObject("filename", filename, "", "");
139         filters.put("filename", filenameFilter);
140         if(luceneEnabled){
141             contentFilter = new CmsSearchFormObject("content", content, "", "");
142             filters.put("content", contentFilter);
143         }
144         session.putValue("ocms_search.allfilter", filters);
145
146         // put the search filter into the session
147
if(!"".equals(action.trim())){
148             // check if all filter values are set
149
if (checkFilter(action, filters)){
150                 reload = "true";
151                 session.putValue("ocms_search.currentfilter", action);
152             } else {
153                 error = template.getProcessedDataValue("errormessage");
154             }
155         }
156
157         // set the values of the template
158
template.setData("reload", reload);
159         template.setData("error", error);
160         template.setData("propvalue", propValue);
161         template.setData("filename", filename);
162         // set the formular elements depending on lucene
163
if(luceneEnabled){
164             template.setData("content", content);
165             template.setData("searchform",template.getProcessedDataValue("luceneon"));
166         } else {
167             template.setData("searchform",template.getProcessedDataValue("luceneoff"));
168         }
169
170         // Finally start the processing
171
byte[] retValue = startProcessing(cms, template, elementName, parameters, templateSelector);
172         return retValue;
173     }
174
175     /**
176      * Create the entries for selectbox for propertydefinitions
177      *
178      * @param cms The current CmsObject
179      * @param lang The current language file
180      * @param names The vector for the selectbox names
181      * @param values The vector for the selectbox values
182      * @param parameters The hashtable that contains the parameters from the request
183      *
184      * @return int The id of the selected entry
185      */

186     public Integer JavaDoc getPropertyDefs(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names, Vector JavaDoc values,
187             Hashtable JavaDoc parameters) throws CmsException {
188         Integer JavaDoc retValue = new Integer JavaDoc(0);
189
190         String JavaDoc resourcetype = (String JavaDoc)parameters.get("restype");
191         String JavaDoc selectedDef = (String JavaDoc)parameters.get("propkey");
192         names.add("---");
193         values.add("");
194
195         if((resourcetype != null) && (!"".equals(resourcetype.trim()))){
196             List JavaDoc propdefs = cms.readAllPropertyDefinitions();
197
198             int i = 0;
199             Iterator JavaDoc j = propdefs.iterator();
200             while (j.hasNext()) {
201                 names.add(((CmsPropertyDefinition)j.next()).getName());
202                 values.add(((CmsPropertyDefinition)j.next()).getName());
203                 if((((CmsPropertyDefinition)j.next()).getName()).equals(selectedDef)){
204                     retValue = new Integer JavaDoc(i+1);
205                 }
206                 i++;
207             }
208         }
209         return retValue;
210     }
211
212     /**
213      *
214      */

215     private void getPropertyDefs(CmsObject cms, CmsXmlWpTemplateFile template, String JavaDoc restype, String JavaDoc selDef) throws CmsException{
216         StringBuffer JavaDoc typeOptions = new StringBuffer JavaDoc();
217         template.setData("name","---");
218         template.setData("value","");
219         template.setData("check","");
220         typeOptions.append(template.getProcessedDataValue("selectoption",this));
221         if((restype != null) && (!"".equals(restype.trim()))){
222             List JavaDoc propdefs = cms.readAllPropertyDefinitions();
223             Iterator JavaDoc i = propdefs.iterator();
224             while (i.hasNext()) {
225                 String JavaDoc propdef = ((CmsPropertyDefinition)i.next()).getName();
226                 template.setData("name",propdef);
227                 template.setData("value",propdef);
228                 if(propdef.equals(selDef!=null?selDef:"")){
229                     template.setData("check","selected");
230                 }else{
231                     template.setData("check","");
232                 }
233                 typeOptions.append(template.getProcessedDataValue("selectoption",this));
234             }
235         }
236         template.setData("propdefs",typeOptions.toString());
237     }
238
239     /**
240      * Create the entries for selectbox for resourcetypes
241      *
242      * @param cms The current CmsObject
243      * @param lang The current language file
244      * @param names The vector for the selectbox names
245      * @param values The vector for the selectbox values
246      * @param parameters The hashtable that contains the parameters from the request
247      *
248      * @return int The id of the selected entry
249      */

250     public Integer JavaDoc getResourceTypes(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names, Vector JavaDoc values,
251             Hashtable JavaDoc parameters) throws CmsException {
252         return new Integer JavaDoc(0);
253     }
254
255     /**
256      *
257      */

258     private void getResourceTypes(CmsObject cms, CmsXmlWpTemplateFile template, String JavaDoc restype) throws CmsException{
259     }
260
261     /**
262      * Checks if all necessary filtervalues are set
263      * @param action The current filter
264      * @param filters The hashtable that contains the CmsSearchFormObject's
265      */

266      private boolean checkFilter(String JavaDoc action, Hashtable JavaDoc filters){
267         CmsSearchFormObject searchFilter = (CmsSearchFormObject)filters.get(action);
268         if(searchFilter == null){
269             return false;
270         }
271         if("".equals(searchFilter.getValue01())){
272             return false;
273         }
274         if("property".equals(action)){
275             if("".equals(searchFilter.getValue02())){
276                 return false;
277             }
278             if("".equals(searchFilter.getValue03())){
279                 return false;
280             }
281         }
282         return true;
283      }
284
285     /**
286      * Indicates if the results of this class are cacheable.
287      *
288      * @param cms CmsObject Object for accessing system resources
289      * @param templateFile Filename of the template file
290      * @param elementName Element name of this template in our parent template.
291      * @param parameters Hashtable with all template class parameters.
292      * @param templateSelector template section that should be processed.
293      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
294      */

295
296     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
297             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
298         return false;
299     }
300 }
301
Popular Tags