KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > list > CmsListSearchAction


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListSearchAction.java,v $
3  * Date : $Date: 2005/06/27 23:22:25 $
4  * Version: $Revision: 1.12 $
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.list;
33
34 import org.opencms.i18n.CmsMessageContainer;
35 import org.opencms.workplace.CmsWorkplace;
36
37 import java.util.ArrayList JavaDoc;
38 import java.util.Iterator JavaDoc;
39 import java.util.List JavaDoc;
40
41 /**
42  * Default implementation for a seach action in an html list.<p>
43  *
44  * It allows to search in several columns, including item details.<p>
45  *
46  * @author Michael Moossen
47  *
48  * @version $Revision: 1.12 $
49  *
50  * @since 6.0.0
51  */

52 public class CmsListSearchAction extends A_CmsListSearchAction implements I_CmsSearchMethod {
53
54     /** Ids of Columns to search into. */
55     private final List JavaDoc m_columns = new ArrayList JavaDoc();
56
57     /**
58      * Default Constructor.<p>
59      *
60      * @param column the column to search into
61      */

62     public CmsListSearchAction(CmsListColumnDefinition column) {
63
64         super();
65         useDefaultShowAllAction();
66         m_columns.add(column);
67     }
68
69     /**
70      * Adds a column to search into.<p>
71      *
72      * @param column the additional column to search into
73      */

74     public void addColumn(CmsListColumnDefinition column) {
75
76         m_columns.add(column);
77     }
78
79     /**
80      * @see org.opencms.workplace.list.A_CmsListSearchAction#buttonHtml(org.opencms.workplace.CmsWorkplace)
81      */

82     public String JavaDoc buttonHtml(CmsWorkplace wp) {
83
84         // delay the composition of the help text as much as possible
85
if (getHelpText() == EMPTY_MESSAGE) {
86             String JavaDoc columns = "";
87             Iterator JavaDoc it = m_columns.iterator();
88             while (it.hasNext()) {
89                 CmsListColumnDefinition col = (CmsListColumnDefinition)it.next();
90                 columns += "${key." + col.getName().getKey() + "}";
91                 if (it.hasNext()) {
92                     columns += ", ";
93                 }
94             }
95             if (columns.lastIndexOf(", ") > 0) {
96                 columns = columns.substring(0, columns.lastIndexOf(", "))
97                     + " and "
98                     + columns.substring(columns.lastIndexOf(", ") + 2);
99             }
100             setHelpText(new CmsMessageContainer(
101                 Messages.get(),
102                 Messages.GUI_LIST_ACTION_SEARCH_HELP_1,
103                 new Object JavaDoc[] {columns}));
104         }
105         return super.buttonHtml(wp);
106     }
107
108     /**
109      * @see org.opencms.workplace.list.I_CmsSearchMethod#filter(java.util.List, java.lang.String)
110      */

111     public List JavaDoc filter(List JavaDoc items, String JavaDoc filter) {
112
113         List JavaDoc res = new ArrayList JavaDoc();
114         Iterator JavaDoc itItems = items.iterator();
115         while (itItems.hasNext()) {
116             CmsListItem item = (CmsListItem)itItems.next();
117             if (res.contains(item)) {
118                 continue;
119             }
120             Iterator JavaDoc itCols = m_columns.iterator();
121             while (itCols.hasNext()) {
122                 CmsListColumnDefinition col = (CmsListColumnDefinition)itCols.next();
123                 if (item.get(col.getId()) == null) {
124                     continue;
125                 }
126                 if (item.get(col.getId()).toString().indexOf(filter) > -1) {
127                     res.add(item);
128                     break;
129                 }
130             }
131         }
132         return res;
133     }
134 }
Popular Tags