KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > searchindex > CmsSearchResourcesList


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/searchindex/CmsSearchResourcesList.java,v $
3  * Date : $Date: 2006/03/27 14:52:21 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
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 Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.tools.searchindex;
33
34 import org.opencms.configuration.CmsSearchConfiguration;
35 import org.opencms.i18n.CmsMessageContainer;
36 import org.opencms.jsp.CmsJspActionElement;
37 import org.opencms.main.CmsIllegalStateException;
38 import org.opencms.main.OpenCms;
39 import org.opencms.search.CmsSearchIndexSource;
40 import org.opencms.search.CmsSearchManager;
41 import org.opencms.workplace.list.CmsListColumnAlignEnum;
42 import org.opencms.workplace.list.CmsListColumnDefinition;
43 import org.opencms.workplace.list.CmsListDirectAction;
44 import org.opencms.workplace.list.CmsListItem;
45 import org.opencms.workplace.list.CmsListMetadata;
46 import org.opencms.workplace.list.CmsListOrderEnum;
47
48 import java.util.ArrayList JavaDoc;
49 import java.util.Iterator JavaDoc;
50 import java.util.List JavaDoc;
51
52 import javax.servlet.http.HttpServletRequest JavaDoc;
53 import javax.servlet.http.HttpServletResponse JavaDoc;
54 import javax.servlet.jsp.PageContext JavaDoc;
55
56 /**
57  * A list that displays the search resources of a request parameter given
58  * <code>{@link org.opencms.search.CmsSearchIndexSource}</code> ("indexsource").
59  *
60  * This list is no stand-alone page but has to be embedded in another dialog
61  * (see <code> {@link org.opencms.workplace.tools.searchindex.A_CmsEmbeddedListDialog}</code>. <p>
62  *
63  * @author Achim Westermann
64  *
65  * @version $Revision: 1.2 $
66  *
67  * @since 6.0.0
68  */

69 public class CmsSearchResourcesList extends A_CmsEmbeddedListDialog {
70
71     /** list action dummy id constant. */
72     public static final String JavaDoc LIST_ACTION_NONE = "an";
73
74     /** list column id constant. */
75     public static final String JavaDoc LIST_COLUMN_ICON = "ci";
76
77     /** list column id constant. */
78     public static final String JavaDoc LIST_COLUMN_PATH = "cp";
79
80     /** list id constant. */
81     public static final String JavaDoc LIST_ID = "lssr";
82
83     /** Stores the value of the request parameter for the search index source name. */
84     private String JavaDoc m_paramIndexsource;
85
86     /**
87      * Public constructor.<p>
88      *
89      * @param jsp an initialized JSP action element
90      */

91     public CmsSearchResourcesList(CmsJspActionElement jsp) {
92
93         this(jsp, LIST_ID, Messages.get().container(Messages.GUI_LIST_SEARCHRESOURCES_NAME_0));
94     }
95
96     /**
97      * Public constructor.<p>
98      *
99      * @param jsp an initialized JSP action element
100      * @param listId the id of the list
101      * @param listName the list name
102      */

103     public CmsSearchResourcesList(CmsJspActionElement jsp, String JavaDoc listId, CmsMessageContainer listName) {
104
105         this(jsp, listId, listName, LIST_COLUMN_PATH, CmsListOrderEnum.ORDER_ASCENDING, null);
106     }
107
108     /**
109      * Public constructor.<p>
110      *
111      * @param jsp an initialized JSP action element
112      * @param listId the id of the displayed list
113      * @param listName the name of the list
114      * @param sortedColId the a priory sorted column
115      * @param sortOrder the order of the sorted column
116      * @param searchableColId the column to search into
117      */

118     public CmsSearchResourcesList(
119         CmsJspActionElement jsp,
120         String JavaDoc listId,
121         CmsMessageContainer listName,
122         String JavaDoc sortedColId,
123         CmsListOrderEnum sortOrder,
124         String JavaDoc searchableColId) {
125
126         super(jsp, listId, listName, sortedColId, sortOrder, searchableColId);
127
128     }
129
130     /**
131      * Public constructor.<p>
132      *
133      * Public constructor with JSP variables.<p>
134      *
135      * @param context the JSP page context
136      * @param req the JSP request
137      * @param res the JSP response
138      */

139     public CmsSearchResourcesList(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
140
141         this(new CmsJspActionElement(context, req, res));
142     }
143
144     /**
145      * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
146      */

147     public void executeListMultiActions() {
148
149         // view only
150
}
151
152     /**
153      * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
154      */

155     public void executeListSingleActions() {
156
157         // view only
158
}
159
160     /**
161      * Returns the request parameter "indexsource".<p>
162      *
163      * @return the request parameter "indexsource"
164      */

165     public String JavaDoc getParamIndexsource() {
166
167         return m_paramIndexsource;
168     }
169
170     /**
171      * Sets the request parameter "indexsource". <p>
172      *
173      * Method intended for workplace-properietary automatic filling of
174      * request parameter values to dialogs, not for manual invocation. <p>
175      *
176      * @param indexsource the request parameter "indexsource" to set
177      */

178     public void setParamIndexsource(String JavaDoc indexsource) {
179
180         m_paramIndexsource = indexsource;
181     }
182
183     /**
184      * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
185      */

186     protected void fillDetails(String JavaDoc detailId) {
187
188         // no details by now
189
}
190
191     /**
192      * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
193      */

194     protected List JavaDoc getListItems() {
195
196         List JavaDoc result = new ArrayList JavaDoc();
197         // get content
198
List JavaDoc resources = resources();
199         Iterator JavaDoc itResources = resources.iterator();
200         String JavaDoc path;
201         while (itResources.hasNext()) {
202             path = (String JavaDoc)itResources.next();
203             CmsListItem item = getList().newItem(path);
204             item.set(LIST_COLUMN_PATH, path);
205             result.add(item);
206         }
207         return result;
208     }
209
210     /**
211      * @see org.opencms.workplace.CmsWorkplace#initMessages()
212      */

213     protected void initMessages() {
214
215         // add specific dialog resource bundle
216
addMessages(Messages.get().getBundleName());
217         // add default resource bundles
218
super.initMessages();
219     }
220
221     /**
222      * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
223      */

224     protected void setColumns(CmsListMetadata metadata) {
225
226         // create dummy column for corporate design reasons
227
CmsListColumnDefinition dummyCol = new CmsListColumnDefinition(LIST_COLUMN_ICON);
228         dummyCol.setName(Messages.get().container(Messages.GUI_LIST_RESOURCES_NAME_0));
229         dummyCol.setHelpText(Messages.get().container(Messages.GUI_LIST_RESOURCES_NAME_HELP_0));
230         dummyCol.setWidth("20");
231         dummyCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
232         dummyCol.setSorteable(false);
233         // add dummy icon
234
CmsListDirectAction dummyAction = new CmsListDirectAction(LIST_ACTION_NONE);
235         dummyAction.setName(Messages.get().container(Messages.GUI_LIST_INDEXSOURCE_COL_ICON_NAME_0));
236         dummyAction.setHelpText(Messages.get().container(Messages.GUI_LIST_INDEXSOURCE_COL_ICON_NAME_HELP_0));
237         dummyAction.setIconPath(CmsSearchIndexSourceControlList.ICON_FOLDER);
238         dummyCol.addDirectAction(dummyAction);
239         // add it to the list definition
240
metadata.addColumn(dummyCol);
241
242         // add column for name
243
CmsListColumnDefinition pathCol = new CmsListColumnDefinition(LIST_COLUMN_PATH);
244         pathCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
245         pathCol.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_NAME_0));
246         pathCol.setWidth("100%");
247         metadata.addColumn(pathCol);
248
249     }
250
251     /**
252      * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
253      */

254     protected void setIndependentActions(CmsListMetadata metadata) {
255
256         // no detail actions
257

258     }
259
260     /**
261      * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
262      */

263     protected void setMultiActions(CmsListMetadata metadata) {
264
265         // view only
266
}
267
268     /**
269      * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
270      */

271     protected void validateParamaters() throws Exception JavaDoc {
272
273         // test the needed parameters
274
if (getParamIndexsource() == null) {
275             throw new CmsIllegalStateException(Messages.get().container(
276                 Messages.ERR_SEARCHINDEX_EDIT_MISSING_PARAM_1,
277                 A_CmsEditIndexSourceDialog.PARAM_INDEXSOURCE));
278         }
279     }
280
281     /**
282      * Writes the updated search configuration back to the XML
283      * configuration file and refreshes the complete list.<p>
284      *
285      * @param refresh if true, the list items are refreshed
286      */

287     protected void writeConfiguration(boolean refresh) {
288
289         // update the XML configuration
290
OpenCms.writeConfiguration(CmsSearchConfiguration.class);
291         if (refresh) {
292             refreshList();
293         }
294     }
295
296     /**
297      * Returns the configured resources of the current indexsource.
298      *
299      * @return the configured resources of the current indexsource
300      */

301     private List JavaDoc resources() {
302
303         CmsSearchManager manager = OpenCms.getSearchManager();
304         CmsSearchIndexSource indexsource = manager.getIndexSource(getParamIndexsource());
305         List JavaDoc result = indexsource.getResourcesNames();
306         return result;
307     }
308
309 }
310
Popular Tags