KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > snapper > presentation > Search


1 package org.enhydra.snapper.presentation;
2
3 /**
4  * @author Milin Radivoj
5  *
6  */

7
8 import java.util.Properties JavaDoc;
9
10 import org.enhydra.snapper.presentation.html.*;
11 import org.enhydra.snapper.spec.*;
12 import org.enhydra.xml.xmlc.XMLObject;
13 import org.enhydra.snapper.Log;
14 import org.enhydra.snapper.Snapper;
15 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
16 import org.w3c.dom.*;
17 import com.lutris.appserver.server.httpPresentation.HttpPresentationOutputStream;
18
19
20 public class Search extends BasePO {
21    
22     String JavaDoc defaultXslSheme = "search";
23     String JavaDoc xslSheme;
24     String JavaDoc xslDir;
25     
26     String JavaDoc type;
27     String JavaDoc contents;
28     String JavaDoc title;
29     
30     String JavaDoc modifiedfrom;
31     String JavaDoc modifiedto;
32     
33     String JavaDoc propertiesKey;
34     String JavaDoc propertiesValue;
35     
36     String JavaDoc metaDataKey;
37     String JavaDoc metaDataValue;
38     
39     String JavaDoc contentLength;
40     String JavaDoc metaDataLength;
41     String JavaDoc wordLength;
42     
43     String JavaDoc sortType;
44
45     String JavaDoc typeOfSearch;
46
47     String JavaDoc from;
48     String JavaDoc to;
49     
50     Properties JavaDoc standardRequestParameters = new Properties JavaDoc();
51     Properties JavaDoc siteRequestParameters = new Properties JavaDoc();
52      
53    protected XMLObject getDOM() throws Exception JavaDoc {
54             
55                 
56         xslSheme=comms.request.getParameter("xsl");
57         xslDir= Snapper.getXslDirectory();
58  
59         type=comms.request.getParameter("type");
60         contents=comms.request.getParameter("contents");
61         title=comms.request.getParameter("title");
62         
63         modifiedfrom=comms.request.getParameter("modifiedfrom");
64         modifiedto=comms.request.getParameter("modifiedto");
65         
66         propertiesKey = comms.request.getParameter("propertiesKey");
67         propertiesValue = comms.request.getParameter("propertiesValue");
68         
69         metaDataKey = comms.request.getParameter("metaDataKey");
70         metaDataValue = comms.request.getParameter("metaDataValue");
71         
72         
73         contentLength = comms.request.getParameter("contentLength");
74         metaDataLength = comms.request.getParameter("metaDataLength");
75         wordLength = comms.request.getParameter("wordLength");
76         
77         sortType = comms.request.getParameter("sortType");
78         
79         from = comms.request.getParameter("from");
80         to = comms.request.getParameter("to");
81         
82         typeOfSearch = comms.request.getParameter("typeOfSearch");
83         
84         manageRequestParameters();
85         manageSiteRequestParameters();
86         
87           Builder builder = BuilderFactory.createBuilder("org.enhydra.snapper.business.BuilderImpl");
88           
89           
90           builder.setStandardRequestParameters(standardRequestParameters);
91           builder.setSiteRequestParameters(siteRequestParameters);
92         
93     
94         
95         BaseHTML page;
96         page = (BaseHTML)comms.xmlcFactory.create(BaseHTML.class);
97       
98         String JavaDoc finall;
99         
100
101      if(!xslSheme.equals("none"))
102      {
103          String JavaDoc resultXML = builder.getResult(dbTransaction);
104         
105         TransformManager manager = TransformManagerFactory.getTransformManager("org.enhydra.snapper.business.TransformManagerImpl");
106         
107         
108         finall=manager.transform(resultXML,xslDir+"/"+xslSheme+".xsl");
109            finall=filter(finall);
110      }
111      else
112      {
113         comms.response.setContentType("text/xml");
114         HttpPresentationOutputStream os =comms.response.getOutputStream();
115         builder.writeResult(dbTransaction,os);
116         comms.response.flush();
117       return null;
118      }
119        
120         
121         
122         
123         CDATASection cdata = (CDATASection)page.createCDATASection(finall);
124         
125          page.getElementResult().appendChild(cdata);
126         
127          return page;
128      }
129     
130    private void manageRequestParameters()
131      {
132     
133     if(xslSheme!=null)
134     {
135         standardRequestParameters.setProperty("xsl",xslSheme);
136     }
137     else
138     {
139         xslSheme = "search";
140     }
141     if(type!=null)
142     {
143         standardRequestParameters.setProperty("type",type);
144     }
145     if(typeOfSearch!=null)
146     {
147         standardRequestParameters.setProperty("typeOfSearch",typeOfSearch);
148       
149     }
150     if(contents!=null)
151     {
152         standardRequestParameters.setProperty("contents",contents.replaceAll("&"," "));
153       
154     }
155     if(title!=null)
156     {
157         standardRequestParameters.setProperty("title",title.replaceAll("&"," "));
158     }
159     
160     if(modifiedfrom!=null)
161     {
162         standardRequestParameters.setProperty("modifiedfrom",modifiedfrom);
163     }
164     if(modifiedto!=null)
165     {
166         standardRequestParameters.setProperty("modifiedto",modifiedto);
167     }
168     if(propertiesKey!=null)
169     {
170         standardRequestParameters.setProperty("propertiesKey",propertiesKey.replaceAll("&"," "));
171     }
172     if(propertiesValue!=null)
173     {
174         standardRequestParameters.setProperty("propertiesValue",propertiesValue.replaceAll("&"," "));
175     }
176     if(metaDataKey!=null)
177     {
178         standardRequestParameters.setProperty("metaDataKey",metaDataKey.replaceAll("&"," "));
179     }
180     if(metaDataValue!=null)
181     {
182         standardRequestParameters.setProperty("metaDataValue",metaDataValue.replaceAll("&"," "));
183     }
184     if(contentLength!=null)
185     {
186         standardRequestParameters.setProperty("contentLength",contentLength);
187     }
188     if(wordLength!=null)
189     {
190         standardRequestParameters.setProperty("wordLength",wordLength);
191     }
192     if(metaDataLength!=null)
193     {
194         standardRequestParameters.setProperty("metaDataLength",metaDataLength);
195     }
196     if(sortType!=null)
197     {
198         standardRequestParameters.setProperty("sortType",sortType);
199     }
200     if(from!=null)
201     {
202         standardRequestParameters.setProperty("from",from);
203     }
204     if(to!=null)
205     {
206         standardRequestParameters.setProperty("to",to);
207     }
208   }
209    
210  
211  private void manageSiteRequestParameters()
212      {
213         Site[] sites;
214         try {
215             SiteList sl = SiteListFactory.getSiteList("org.enhydra.snapper.business.SiteListImpl");
216             sites = sl.getList(dbTransaction);
217             
218         }catch (Exception JavaDoc e){
219                         Log.logException(e);
220                         sites = null;
221            
222         }
223          
224          for (int i = 0; i < sites.length; i++)
225         {
226             try {
227             String JavaDoc siteName = sites[i].getName();
228             String JavaDoc siteId = sites[i].getID();
229             
230             String JavaDoc site = comms.request.getParameter(siteId);
231             
232             if(site!=null&&site.equals("on"))
233               {
234                 siteRequestParameters.setProperty(siteId,"on");
235               }
236             }catch (Exception JavaDoc e){
237                 Log.logException(e);
238                 sites = null;
239    
240               }
241             
242            }
243       }
244       
245
246      public static String JavaDoc replaceAll(
247             String JavaDoc input,
248             String JavaDoc forReplace,
249             String JavaDoc replaceWith) {
250             if( input == null )
251               return null;
252             StringBuffer JavaDoc result = new StringBuffer JavaDoc();
253             boolean hasMore = true;
254             while (hasMore) {
255               int start = input.indexOf(forReplace);
256               int end = start + forReplace.length();
257               if (start != -1) {
258                 result.append(input.substring(0, start) + replaceWith);
259                 input = input.substring(end);
260               }
261               else {
262                 hasMore = false;
263                 result.append(input);
264               }
265             }
266             if (result.toString().equals(""))
267               return input; //nothing is changed
268
else
269               return result.toString();
270           }
271      
272      public String JavaDoc filter(String JavaDoc stringToFilter){
273          stringToFilter = replaceAll(stringToFilter,"&#60;B&#62;","<B>");
274          stringToFilter = replaceAll(stringToFilter,"&#60;/B&#62;","</B>");
275        return stringToFilter;
276      }
277     
278 }
279
Popular Tags