KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/searchindex/CmsDocumentTypeList.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.CmsLog;
39 import org.opencms.main.OpenCms;
40 import org.opencms.search.CmsSearchDocumentType;
41 import org.opencms.search.CmsSearchIndexSource;
42 import org.opencms.search.CmsSearchManager;
43 import org.opencms.workplace.list.CmsListColumnAlignEnum;
44 import org.opencms.workplace.list.CmsListColumnDefinition;
45 import org.opencms.workplace.list.CmsListDirectAction;
46 import org.opencms.workplace.list.CmsListItem;
47 import org.opencms.workplace.list.CmsListItemDetails;
48 import org.opencms.workplace.list.CmsListItemDetailsFormatter;
49 import org.opencms.workplace.list.CmsListMetadata;
50 import org.opencms.workplace.list.CmsListOrderEnum;
51
52 import java.util.ArrayList JavaDoc;
53 import java.util.Iterator JavaDoc;
54 import java.util.List JavaDoc;
55
56 import javax.servlet.http.HttpServletRequest JavaDoc;
57 import javax.servlet.http.HttpServletResponse JavaDoc;
58 import javax.servlet.jsp.PageContext JavaDoc;
59
60 import org.apache.commons.logging.Log;
61
62 /**
63  * A list that displays the document types of a request parameter given
64  * <code>{@link org.opencms.search.CmsSearchIndexSource}</code> ("indexsource").
65  *
66  * This list is no stand-alone page but has to be embedded in another dialog
67  * (see <code> {@link org.opencms.workplace.tools.searchindex.A_CmsEmbeddedListDialog}</code>. <p>
68  *
69  * @author Achim Westermann
70  *
71  * @version $Revision: 1.2 $
72  *
73  * @since 6.0.0
74  */

75 public class CmsDocumentTypeList extends A_CmsEmbeddedListDialog {
76
77     /** list action dummy id constant. */
78     public static final String JavaDoc LIST_ACTION_NONE = "an";
79
80     /** list column id constant. */
81     public static final String JavaDoc LIST_COLUMN_DOCCLASS = "cdc";
82
83     /** list column id constant. */
84     public static final String JavaDoc LIST_COLUMN_ICON = "ci";
85
86     /** list column id constant. */
87     public static final String JavaDoc LIST_COLUMN_NAME = "cn";
88
89     /** list item detail id constant. */
90     public static final String JavaDoc LIST_DETAIL_MIMETYPES = "dmt";
91
92     /** list item detail id constant. */
93     public static final String JavaDoc LIST_DETAIL_RESOURCETYPES = "drt";
94
95     /** list id constant. */
96     public static final String JavaDoc LIST_ID = "lssisdt";
97
98     /** The list icon for a folder resource. **/
99     protected static final String JavaDoc ICON_DOCTYPE = "tools/searchindex/icons/small/indexsource-doctype.png";
100
101     /** The log object for this class. */
102     private static final Log LOG = CmsLog.getLog(CmsDocumentTypeList.class);
103
104     /** Stores the value of the request parameter for the search index source name. */
105     private String JavaDoc m_paramIndexsource;
106
107     /**
108      * Public constructor.<p>
109      *
110      * @param jsp an initialized JSP action element
111      */

112     public CmsDocumentTypeList(CmsJspActionElement jsp) {
113
114         this(jsp, LIST_ID, Messages.get().container(Messages.GUI_LIST_DOCUMENTTYPES_NAME_0));
115     }
116
117     /**
118      * Public constructor.<p>
119      *
120      * @param jsp an initialized JSP action element
121      * @param listId the id of the list
122      * @param listName the list name
123      */

124     public CmsDocumentTypeList(CmsJspActionElement jsp, String JavaDoc listId, CmsMessageContainer listName) {
125
126         this(jsp, listId, listName, LIST_COLUMN_NAME, CmsListOrderEnum.ORDER_ASCENDING, null);
127     }
128
129     /**
130      * Public constructor.<p>
131      *
132      * @param jsp an initialized JSP action element
133      * @param listId the id of the displayed list
134      * @param listName the name of the list
135      * @param sortedColId the a priory sorted column
136      * @param sortOrder the order of the sorted column
137      * @param searchableColId the column to search into
138      */

139     public CmsDocumentTypeList(
140         CmsJspActionElement jsp,
141         String JavaDoc listId,
142         CmsMessageContainer listName,
143         String JavaDoc sortedColId,
144         CmsListOrderEnum sortOrder,
145         String JavaDoc searchableColId) {
146
147         super(jsp, listId, listName, sortedColId, sortOrder, searchableColId);
148
149     }
150
151     /**
152      * Public constructor.<p>
153      *
154      * Public constructor with JSP variables.<p>
155      *
156      * @param context the JSP page context
157      * @param req the JSP request
158      * @param res the JSP response
159      */

160     public CmsDocumentTypeList(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
161
162         this(new CmsJspActionElement(context, req, res));
163     }
164
165     /**
166      * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
167      */

168     public void executeListMultiActions() {
169
170         // view only
171
}
172
173     /**
174      * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
175      */

176     public void executeListSingleActions() {
177
178         // view only
179
}
180
181     /**
182      * Returns the request parameter "indexsource".<p>
183      *
184      * @return the request parameter "indexsource"
185      */

186     public String JavaDoc getParamIndexsource() {
187
188         return m_paramIndexsource;
189     }
190
191     /**
192      * Sets the request parameter "indexsource". <p>
193      *
194      * Method intended for workplace-properietary automatic filling of
195      * request parameter values to dialogs, not for manual invocation. <p>
196      *
197      * @param indexsource the request parameter "indexsource" to set
198      */

199     public void setParamIndexsource(String JavaDoc indexsource) {
200
201         m_paramIndexsource = indexsource;
202     }
203
204     /**
205      * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
206      */

207     protected void fillDetails(String JavaDoc detailId) {
208
209         // get content
210
List JavaDoc items = getList().getAllContent();
211         Iterator JavaDoc itItems = items.iterator();
212         CmsListItem item;
213         if (detailId.equals(LIST_DETAIL_MIMETYPES)) {
214             while (itItems.hasNext()) {
215                 item = (CmsListItem)itItems.next();
216                 fillDetailMimetypes(item, detailId);
217
218             }
219         }
220         if (detailId.equals(LIST_DETAIL_RESOURCETYPES)) {
221             while (itItems.hasNext()) {
222                 item = (CmsListItem)itItems.next();
223                 fillDetailResourceTypes(item, detailId);
224
225             }
226
227         }
228
229     }
230
231     /**
232      * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
233      */

234     protected List JavaDoc getListItems() {
235
236         List JavaDoc result = new ArrayList JavaDoc();
237         // get content
238
List JavaDoc doctypes = documentTypes();
239         Iterator JavaDoc itDoctypes = doctypes.iterator();
240         CmsSearchDocumentType doctype;
241         while (itDoctypes.hasNext()) {
242             doctype = (CmsSearchDocumentType)itDoctypes.next();
243             CmsListItem item = getList().newItem(doctype.getName());
244             item.set(LIST_COLUMN_NAME, doctype.getName());
245             item.set(LIST_COLUMN_DOCCLASS, doctype.getClassName());
246             result.add(item);
247         }
248         return result;
249     }
250
251     /**
252      * @see org.opencms.workplace.CmsWorkplace#initMessages()
253      */

254     protected void initMessages() {
255
256         // add specific dialog resource bundle
257
addMessages(Messages.get().getBundleName());
258         // add default resource bundles
259
super.initMessages();
260     }
261
262     /**
263      * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
264      */

265     protected void setColumns(CmsListMetadata metadata) {
266
267         // create dummy column for corporate design reasons
268
CmsListColumnDefinition dummyCol = new CmsListColumnDefinition(LIST_COLUMN_ICON);
269         dummyCol.setName(Messages.get().container(Messages.GUI_LIST_DOCUMENTTYPE_NAME_0));
270         dummyCol.setHelpText(Messages.get().container(Messages.GUI_LIST_DOCUMENTTYPE_NAME_HELP_0));
271         dummyCol.setWidth("20");
272         dummyCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
273         dummyCol.setSorteable(false);
274         // add dummy icon
275
CmsListDirectAction dummyAction = new CmsListDirectAction(LIST_ACTION_NONE);
276         dummyAction.setName(Messages.get().container(Messages.GUI_LIST_INDEXSOURCE_COL_ICON_NAME_0));
277         dummyAction.setHelpText(Messages.get().container(Messages.GUI_LIST_INDEXSOURCE_COL_ICON_NAME_HELP_0));
278         dummyAction.setIconPath(CmsDocumentTypeList.ICON_DOCTYPE);
279         // disable!
280
dummyAction.setEnabled(false);
281         dummyCol.addDirectAction(dummyAction);
282         // add it to the list definition
283
metadata.addColumn(dummyCol);
284
285         // add column for name
286
CmsListColumnDefinition nameCol = new CmsListColumnDefinition(LIST_COLUMN_NAME);
287         nameCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
288         nameCol.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_NAME_0));
289         nameCol.setWidth("50%");
290         metadata.addColumn(nameCol);
291
292         // add column for document implementation class
293
CmsListColumnDefinition docclassCol = new CmsListColumnDefinition(LIST_COLUMN_DOCCLASS);
294         docclassCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
295         docclassCol.setName(Messages.get().container(Messages.GUI_LIST_DOCTYPE_COL_DOCCLASS_0));
296         docclassCol.setWidth("50%");
297         metadata.addColumn(docclassCol);
298
299     }
300
301     /**
302      * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
303      */

304     protected void setIndependentActions(CmsListMetadata metadata) {
305
306         // add document types of index source detail help
307
CmsListItemDetails mimetypeDetails = new CmsListItemDetails(LIST_DETAIL_MIMETYPES);
308         mimetypeDetails.setAtColumn(LIST_COLUMN_NAME);
309         mimetypeDetails.setVisible(false);
310         mimetypeDetails.setShowActionName(Messages.get().container(Messages.GUI_LIST_DOCTYPE_DETAIL_MIMETYPES_SHOW_0));
311         mimetypeDetails.setShowActionHelpText(Messages.get().container(
312             Messages.GUI_LIST_DOCTYPE_DETAIL_MIMETYPES_SHOW_HELP_0));
313         mimetypeDetails.setHideActionName(Messages.get().container(Messages.GUI_LIST_DOCTYPE_DETAIL_MIMETYPES_HIDE_0));
314         mimetypeDetails.setHideActionHelpText(Messages.get().container(
315             Messages.GUI_LIST_DOCTYPE_DETAIL_MIMETYPES_HIDE_HELP_0));
316         mimetypeDetails.setName(Messages.get().container(Messages.GUI_LIST_DOCTYPE_DETAIL_MIMETYPES_NAME_0));
317         mimetypeDetails.setFormatter(new CmsListItemDetailsFormatter(Messages.get().container(
318             Messages.GUI_LIST_DOCTYPE_DETAIL_MIMETYPES_NAME_0)));
319         metadata.addItemDetails(mimetypeDetails);
320
321         // add resources of index source detail help
322
CmsListItemDetails resourceDetails = new CmsListItemDetails(LIST_DETAIL_RESOURCETYPES);
323         resourceDetails.setAtColumn(LIST_COLUMN_NAME);
324         resourceDetails.setVisible(false);
325         resourceDetails.setShowActionName(Messages.get().container(
326             Messages.GUI_LIST_DOCTYPE_DETAIL_RESOURCETYPES_SHOW_0));
327         resourceDetails.setShowActionHelpText(Messages.get().container(
328             Messages.GUI_LIST_DOCTYPE_DETAIL_RESOURCETYPES_SHOW_HELP_0));
329         resourceDetails.setHideActionName(Messages.get().container(
330             Messages.GUI_LIST_DOCTYPE_DETAIL_RESOURCETYPES_HIDE_0));
331         resourceDetails.setHideActionHelpText(Messages.get().container(
332             Messages.GUI_LIST_DOCTYPE_DETAIL_RESOURCETYPES_HIDE_HELP_0));
333         resourceDetails.setName(Messages.get().container(Messages.GUI_LIST_DOCTYPE_DETAIL_RESOURCETYPES_NAME_0));
334         resourceDetails.setFormatter(new CmsListItemDetailsFormatter(Messages.get().container(
335             Messages.GUI_LIST_DOCTYPE_DETAIL_RESOURCETYPES_NAME_0)));
336         metadata.addItemDetails(resourceDetails);
337
338     }
339
340     /**
341      * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
342      */

343     protected void setMultiActions(CmsListMetadata metadata) {
344
345         // view only
346
}
347
348     /**
349      * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
350      */

351     protected void validateParamaters() throws Exception JavaDoc {
352
353         // test the needed parameters
354
if (getParamIndexsource() == null) {
355             throw new CmsIllegalStateException(Messages.get().container(
356                 Messages.ERR_SEARCHINDEX_EDIT_MISSING_PARAM_1,
357                 A_CmsEditIndexSourceDialog.PARAM_INDEXSOURCE));
358         }
359     }
360
361     /**
362      * Writes the updated search configuration back to the XML
363      * configuration file and refreshes the complete list.<p>
364      *
365      * @param refresh if true, the list items are refreshed
366      */

367     protected void writeConfiguration(boolean refresh) {
368
369         // update the XML configuration
370
OpenCms.writeConfiguration(CmsSearchConfiguration.class);
371         if (refresh) {
372             refreshList();
373         }
374     }
375
376     /**
377      * Returns the configured document types of the current indexsource.
378      *
379      * @return the configured document types of the current indexsource
380      */

381     private List JavaDoc documentTypes() {
382
383         CmsSearchManager manager = OpenCms.getSearchManager();
384         CmsSearchIndexSource indexsource = manager.getIndexSource(getParamIndexsource());
385         List JavaDoc result;
386         if (indexsource != null) {
387             List JavaDoc doctypes = indexsource.getDocumentTypes();
388             // transform these mere names to real document types...
389
result = new ArrayList JavaDoc(doctypes.size());
390             Iterator JavaDoc it = doctypes.iterator();
391             String JavaDoc doctypename = "";
392             CmsSearchDocumentType doctype;
393             while (it.hasNext()) {
394                 doctypename = (String JavaDoc)it.next();
395                 if (doctypename != null) {
396                     doctype = manager.getDocumentTypeConfig(doctypename);
397                     if (doctype != null) {
398                         result.add(doctype);
399                     }
400                 }
401             }
402         } else {
403             result = new ArrayList JavaDoc(0);
404             if (LOG.isErrorEnabled()) {
405                 LOG.error(Messages.get().getBundle().key(
406                     Messages.ERR_SEARCHINDEX_EDIT_MISSING_PARAM_1,
407                     A_CmsEditIndexSourceDialog.PARAM_INDEXSOURCE));
408             }
409         }
410         return result;
411     }
412
413     /**
414      * Fills details about configured mime types of the document type into the given item. <p>
415      *
416      * @param item the list item to fill
417      * @param detailId the id for the detail to fill
418      *
419      */

420     private void fillDetailMimetypes(CmsListItem item, String JavaDoc detailId) {
421
422         CmsSearchManager searchManager = OpenCms.getSearchManager();
423         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
424
425         String JavaDoc doctypeName = (String JavaDoc)item.get(LIST_COLUMN_NAME);
426         CmsSearchDocumentType docType = searchManager.getDocumentTypeConfig(doctypeName);
427
428         // output of mime types
429
Iterator JavaDoc itMimetypes = docType.getMimeTypes().iterator();
430         html.append("<ul>\n");
431         while (itMimetypes.hasNext()) {
432             html.append(" <li>\n").append(" ").append(itMimetypes.next()).append("\n");
433             html.append(" </li>");
434         }
435
436         html.append("</ul>\n");
437         item.set(detailId, html.toString());
438     }
439
440     /**
441      * Fills details about resource types of the document type into the given item. <p>
442      *
443      * @param item the list item to fill
444      * @param detailId the id for the detail to fill
445      *
446      */

447     private void fillDetailResourceTypes(CmsListItem item, String JavaDoc detailId) {
448
449         CmsSearchManager searchManager = OpenCms.getSearchManager();
450         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
451
452         String JavaDoc doctypeName = (String JavaDoc)item.get(LIST_COLUMN_NAME);
453         CmsSearchDocumentType docType = searchManager.getDocumentTypeConfig(doctypeName);
454
455         // output of resource types
456
Iterator JavaDoc itResourcetypes = docType.getResourceTypes().iterator();
457         html.append("<ul>\n");
458         while (itResourcetypes.hasNext()) {
459             html.append(" <li>\n").append(" ").append(itResourcetypes.next()).append("\n");
460             html.append(" </li>");
461         }
462
463         html.append("</ul>\n");
464         item.set(detailId, html.toString());
465     }
466 }
Popular Tags