1 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 ; 40 import java.util.Iterator ; 41 import java.util.List ; 42 import java.util.Vector ; 43 44 56 57 public class CmsSearchForm extends CmsWorkplaceDefault { 58 59 70 71 public byte[] getContent(CmsObject cms, String templateFile, String elementName, 72 Hashtable parameters, String templateSelector) throws CmsException { 73 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 75 String error = ""; 76 String reload = ""; 77 boolean luceneEnabled = false; 78 79 CmsXmlWpTemplateFile template = (CmsXmlWpTemplateFile)getOwnTemplateFile(cms, 81 templateFile, elementName, parameters, templateSelector); 82 String action = (String )parameters.get("action")!=null?(String )parameters.get("action"):""; 83 String propRestype = (String )parameters.get("proprestype"); 84 String propKey = (String )parameters.get("propkey"); 85 String propValue = (String )parameters.get("propvalue"); 86 String content = (String )parameters.get("content"); 87 String filename = (String )parameters.get("filename"); 88 89 Hashtable filters = (Hashtable )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 this.getResourceTypes(cms, template, propRestype); 132 this.getPropertyDefs(cms, template, propRestype, propKey); 133 134 filters = new Hashtable (); 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 if(!"".equals(action.trim())){ 148 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 template.setData("reload", reload); 159 template.setData("error", error); 160 template.setData("propvalue", propValue); 161 template.setData("filename", filename); 162 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 byte[] retValue = startProcessing(cms, template, elementName, parameters, templateSelector); 172 return retValue; 173 } 174 175 186 public Integer getPropertyDefs(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values, 187 Hashtable parameters) throws CmsException { 188 Integer retValue = new Integer (0); 189 190 String resourcetype = (String )parameters.get("restype"); 191 String selectedDef = (String )parameters.get("propkey"); 192 names.add("---"); 193 values.add(""); 194 195 if((resourcetype != null) && (!"".equals(resourcetype.trim()))){ 196 List propdefs = cms.readAllPropertyDefinitions(); 197 198 int i = 0; 199 Iterator 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 (i+1); 205 } 206 i++; 207 } 208 } 209 return retValue; 210 } 211 212 215 private void getPropertyDefs(CmsObject cms, CmsXmlWpTemplateFile template, String restype, String selDef) throws CmsException{ 216 StringBuffer typeOptions = new StringBuffer (); 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 propdefs = cms.readAllPropertyDefinitions(); 223 Iterator i = propdefs.iterator(); 224 while (i.hasNext()) { 225 String 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 250 public Integer getResourceTypes(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values, 251 Hashtable parameters) throws CmsException { 252 return new Integer (0); 253 } 254 255 258 private void getResourceTypes(CmsObject cms, CmsXmlWpTemplateFile template, String restype) throws CmsException{ 259 } 260 261 266 private boolean checkFilter(String action, Hashtable 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 295 296 public boolean isCacheable(CmsObject cms, String templateFile, String elementName, 297 Hashtable parameters, String templateSelector) { 298 return false; 299 } 300 } 301
| Popular Tags
|