KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/searchindex/CmsHookListSearchCategory.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.search.CmsSearchParameters;
35
36 import java.util.Collection JavaDoc;
37 import java.util.LinkedList JavaDoc;
38 import java.util.List JavaDoc;
39
40 /**
41  * A hook on the list of categories of the <code>CmsSearchParameters</code>
42  * (see <code>{@link org.opencms.search.CmsSearchParameters#setCategories(List)}</code>)
43  * that will set the page to display of the search parameters to start (1) whenever
44  * a change in the amount of categories takes place. <p>
45  *
46  * This hook monitors the actions of the <code>{@link org.opencms.workplace.CmsWidgetDialog}</code>:
47  * During a request - response cycle it clears the list (prepareCommit)
48  * of categories and adds all request parameters (actionCommitValue) to the list. <pü>
49  *
50  * The strategy here is to save all categories in a backup at "onClear" - time
51  * and then wait until all add operations are finished. This is when the iterator()
52  * method is triggered by the running search (<code>{@link org.opencms.search.CmsSearch#getSearchResult()}</code>).
53  * At that time it is detected wether we have "lost" categories. If this is the
54  * case, the search page will be reset to start. <p>
55  *
56  * <h3>Warning</h3>
57  * This procedure is highly unstable as coupled to the behaviour of CmsWidgetDialog. It
58  * will only be successful if the request parameter "action" has a value in
59  * <ol>
60  * <li>
61  * <code>{@link org.opencms.workplace.CmsWidgetDialog#DIALOG_SAVE}</code>
62  * </li>
63  * <li>
64  * <code>{@link org.opencms.workplace.CmsWidgetDialog#DIALOG_BACK}</code>
65  * </li>
66  * <li>
67  * <code>{@link org.opencms.workplace.CmsWidgetDialog#DIALOG_CONTINUE}</code>
68  * </li>
69  * </ol>
70  *
71  * Search page links (<code>{@link org.opencms.search.CmsSearch#getPageLinks()}</code>)
72  * contain a parameter "action" with value "search" which has to be rewritten to one
73  * of those values or the order of operations on widget - managed collections does not
74  * work together with the detection strategy for category changes used here. <p>
75  *
76  * @author Achim Westermann
77  *
78  * @version $Revision: 1.2 $
79  *
80  * @since 6.0.0
81  */

82 public class CmsHookListSearchCategory extends CmsHookList {
83
84     private static final long serialVersionUID = 145986432425221213L;
85
86     /** The snapshot (clone) of this list at "clear()" time. **/
87     private List JavaDoc m_backupCategories;
88
89     /**
90      * @param peer the search parameters to modify upon category modifications.
91      */

92     public CmsHookListSearchCategory(CmsSearchParameters peer) {
93
94         super(peer);
95     }
96
97     /**
98      * @param peer the search parameters to modify upon category modifications
99      *
100      * @param c a collection with all values for this list
101      */

102     public CmsHookListSearchCategory(CmsSearchParameters peer, Collection JavaDoc c) {
103
104         super(peer, c);
105
106     }
107
108     /**
109      * A category has been added: do nothing. <p>
110      *
111      * @see org.opencms.workplace.tools.searchindex.CmsHookList#onAdded(java.lang.Object, int, java.lang.Object)
112      */

113     protected void onAdded(Object JavaDoc peer, int index, Object JavaDoc element) {
114
115         // nop
116
}
117
118     /**
119      * @see org.opencms.workplace.tools.searchindex.CmsHookList#onAdded(java.lang.Object, java.lang.Object)
120      */

121     protected void onAdded(Object JavaDoc peer, Object JavaDoc added) {
122
123         // nop
124
}
125
126     /**
127      * Takes a copy of the current categories contained to a backup list as this
128      * operation is triggered by
129      * <code>{@link org.opencms.workplace.CmsWidgetDialog#ACTION_SAVE}</code>.<p>
130      *
131      * @see org.opencms.workplace.tools.searchindex.CmsHookList#onClear(java.lang.Object)
132      */

133     protected void onClear(Object JavaDoc peer) {
134
135         m_backupCategories = new LinkedList JavaDoc(this);
136     }
137
138     /**
139      *
140      * @see org.opencms.workplace.tools.searchindex.CmsHookList#onCleared(java.lang.Object)
141      */

142     protected void onCleared(Object JavaDoc peer) {
143
144         // nop
145
}
146
147     /**
148      * Set the search page of the peer Object
149      * (<code>{@link org.opencms.search.CmsSearch#setSearchPage(int)}</code>)
150      * to zero if the internal backup list of categories (taken at clear time which
151      * is triggered by <code>{@link org.opencms.workplace.CmsWidgetDialog#ACTION_SAVE}</code>)
152      * was empty (no restriction) and now categories are contained or if the new
153      * backup list of categories is no subset of the current categories any
154      * more (more restrictive search than before). <p>
155      *
156      * @see org.opencms.workplace.tools.searchindex.CmsHookList#onGetCall(java.lang.Object, int)
157      */

158     protected void onGetCall(Object JavaDoc peer, int index) {
159
160         // zero categories are all (first condition)
161
if ((m_backupCategories.size() == 0 && size() != 0) || !(containsAll(m_backupCategories))) {
162             ((CmsSearchParameters)peer).setSearchPage(1);
163         }
164     }
165
166     /**
167      * @see org.opencms.workplace.tools.searchindex.CmsHookList#onIteratorCall(java.lang.Object)
168      */

169     protected void onIteratorCall(Object JavaDoc peer) {
170
171         // nop
172
}
173
174     /**
175      * A category has been removed: set search page to start page as
176      * new results may / will be smaller. <p>
177      *
178      *
179      * @see org.opencms.workplace.tools.searchindex.CmsHookList#onRemoved(java.lang.Object, int)
180      */

181     protected void onRemoved(Object JavaDoc peer, int index) {
182
183         ((CmsSearchParameters)peer).setSearchPage(1);
184     }
185 }
186
Popular Tags