KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > frontoffice > objectSelector > SearchPublications


1 /*
2  * ĻON content management system.
3  * Copyright (C) 2002 Guillaume Bort(gbort@msn.com). All rights reserved.
4  *
5  * Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
6  * Copyright 2000-2002 (C) Intalio Inc. All Rights Reserved.
7  *
8  * ĻON is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * ĻON core framework, ĻON content server, ĻON backoffice, ĻON frontoffice
14  * and ĻON admin application are parts of ĻON and are distributed under
15  * same terms of licence.
16  *
17  *
18  * ĻON includes software developed by the Apache Software Foundation (http://www.apache.org/)
19  * and software developed by the Exolab Project (http://www.exolab.org).
20  *
21  * ĻON is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  */

26
27 package org.nextime.ion.frontoffice.objectSelector;
28
29 import java.util.Collection JavaDoc;
30 import java.util.Hashtable JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35
36 import org.nextime.ion.common.IsOnline;
37 import org.nextime.ion.framework.helper.SearchResult;
38 import org.nextime.ion.framework.helper.Searcher;
39 import org.nextime.ion.framework.helper.Viewer;
40 import org.nextime.ion.framework.logger.Logger;
41
42 public class SearchPublications implements ObjectSelector {
43
44     public Collection JavaDoc selectObjects(
45         Hashtable JavaDoc params,
46         HttpServletRequest JavaDoc request,
47         HttpServletResponse JavaDoc response)
48         throws SelectException {
49
50         try {
51             String JavaDoc queryString = (String JavaDoc) params.get("queryString");
52             String JavaDoc view = (String JavaDoc) params.get("view");
53             String JavaDoc index = (String JavaDoc) params.get("index");
54
55             String JavaDoc currentLocale =
56                 request.getSession().getAttribute("currentLocale") + "";
57
58             Vector JavaDoc returnResults = new Vector JavaDoc();
59             if (queryString.equals("") || index.equals(""))
60                 return returnResults;
61             Vector JavaDoc results = Searcher.search(queryString, index);
62
63             int count = 0;
64             for (int i = 0; i < results.size(); i++) {
65                 SearchResult result = (SearchResult) results.get(i);
66
67                 // est ce la version actuellement publiée ???
68
if (result.getVersion()
69                     == IsOnline.getMostRecentVersion(result.getPublication())) {
70
71                     String JavaDoc viewResult = "";
72                     if (!view.equals("")) {
73                         viewResult =
74                             new String JavaDoc(
75                                 Viewer.getView(
76                                     result.getPublication(),
77                                     result.getVersion(),
78                                     view,
79                                     currentLocale));
80                     }
81
82                     SearchPublicationResult spr = new SearchPublicationResult();
83                     PublicationResult pr = new PublicationResult();
84                     pr.setPublication(result.getPublication());
85                     pr.setVersion(result.getVersion());
86                     pr.setView(viewResult);
87                     spr.setPublicationResult(pr);
88                     spr.setSearchResult(result);
89
90                     returnResults.add(spr);
91                 }
92             }
93             return returnResults;
94         } catch (Exception JavaDoc e) {
95             Logger.getInstance().error("Erreur du SelectObject", this, e);
96             throw new SelectException(e.getMessage());
97         }
98     }
99
100 }
Popular Tags