KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/searchindex/CmsEditSearchIndexDialog.java,v $
3  * Date : $Date: 2006/10/17 09:09:23 $
4  * Version: $Revision: 1.3 $
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.file.CmsProject;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.main.CmsException;
37 import org.opencms.widgets.CmsDisplayWidget;
38 import org.opencms.widgets.CmsInputWidget;
39 import org.opencms.widgets.CmsSelectWidget;
40 import org.opencms.widgets.CmsSelectWidgetOption;
41 import org.opencms.workplace.CmsWidgetDialogParameter;
42
43 import java.util.Iterator JavaDoc;
44 import java.util.LinkedList JavaDoc;
45 import java.util.List JavaDoc;
46 import java.util.Set JavaDoc;
47 import java.util.TreeSet JavaDoc;
48
49 import javax.servlet.http.HttpServletRequest JavaDoc;
50 import javax.servlet.http.HttpServletResponse JavaDoc;
51 import javax.servlet.jsp.PageContext JavaDoc;
52
53 /**
54  *
55  * Dialog to edit new or existing search index in the administration view.<p>
56  *
57  * @author Achim Westermann
58  *
59  * @version $Revision: 1.3 $
60  *
61  * @since 6.0.0
62  */

63 public class CmsEditSearchIndexDialog extends A_CmsEditSearchIndexDialog {
64
65     /**
66      * Public constructor with JSP action element.<p>
67      *
68      * @param jsp an initialized JSP action element
69      */

70     public CmsEditSearchIndexDialog(CmsJspActionElement jsp) {
71
72         super(jsp);
73     }
74
75     /**
76      * Public constructor with JSP variables.<p>
77      *
78      * @param context the JSP page context
79      * @param req the JSP request
80      * @param res the JSP response
81      */

82     public CmsEditSearchIndexDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
83
84         this(new CmsJspActionElement(context, req, res));
85     }
86
87     /**
88      * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
89      *
90      * This overwrites the method from the super class to create a layout variation for the widgets.<p>
91      *
92      * @param dialog the dialog (page) to get the HTML for
93      * @return the dialog HTML for all defined widgets of the named dialog (page)
94      */

95     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
96
97         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
98
99         result.append(createWidgetTableStart());
100         // show error header once if there were validation errors
101
result.append(createWidgetErrorHeader());
102
103         if (dialog.equals(PAGES[0])) {
104             // create the widgets for the first dialog page
105
result.append(dialogBlockStart(key(Messages.GUI_LABEL_SEARCHINDEX_BLOCK_SETTINGS_0)));
106             result.append(createWidgetTableStart());
107             result.append(createDialogRowsHtml(0, 3));
108             result.append(createWidgetTableEnd());
109             result.append(dialogBlockEnd());
110         }
111
112         result.append(createWidgetTableEnd());
113         return result.toString();
114     }
115
116     /**
117      * Creates the list of widgets for this dialog.<p>
118      */

119     protected void defineWidgets() {
120
121         super.defineWidgets();
122
123         // widgets to display
124
if (m_index == null || m_index.getName() == null) {
125             addWidget(new CmsWidgetDialogParameter(m_index, "name", PAGES[0], new CmsInputWidget()));
126         } else {
127             addWidget(new CmsWidgetDialogParameter(m_index, "name", PAGES[0], new CmsDisplayWidget()));
128         }
129         addWidget(new CmsWidgetDialogParameter(m_index, "rebuildMode", "", PAGES[0], new CmsSelectWidget(
130             getRebuildModeWidgetConfiguration()), 0, 1));
131         addWidget(new CmsWidgetDialogParameter(m_index, "locale", "", PAGES[0], new CmsSelectWidget(
132             getLocaleWidgetConfiguration()), 0, 1));
133         addWidget(new CmsWidgetDialogParameter(m_index, "project", "", PAGES[0], new CmsSelectWidget(
134             getProjectWidgetConfiguration()), 0, 1));
135     }
136
137     private List JavaDoc getLocaleWidgetConfiguration() {
138
139         List JavaDoc result = new LinkedList JavaDoc();
140         String JavaDoc locale = m_index.getLocale();
141         // find all different locales
142
Iterator JavaDoc itAnalyzerLocales = m_searchManager.getAnalyzers().keySet().iterator();
143         Set JavaDoc distinctLocales = new TreeSet JavaDoc();
144         while (itAnalyzerLocales.hasNext()) {
145             distinctLocales.add(itAnalyzerLocales.next());
146         }
147
148         // put an option for each distinct locale
149
itAnalyzerLocales = distinctLocales.iterator();
150         String JavaDoc curLocale;
151         CmsSelectWidgetOption option;
152         while (itAnalyzerLocales.hasNext()) {
153             curLocale = (String JavaDoc)itAnalyzerLocales.next();
154             option = new CmsSelectWidgetOption(curLocale, curLocale.equals(locale));
155             result.add(option);
156         }
157         return result;
158     }
159
160     private List JavaDoc getProjectWidgetConfiguration() {
161
162         List JavaDoc result = new LinkedList JavaDoc();
163         List JavaDoc projects;
164         try {
165             projects = getCms().getAllManageableProjects();
166             //projects.addAll(getCms().getAllBackupProjects());
167
projects.add(getCms().readProject(CmsProject.ONLINE_PROJECT_ID));
168             Iterator JavaDoc itProjects = projects.iterator();
169             String JavaDoc project = m_index.getProject();
170             String JavaDoc curProject;
171             CmsSelectWidgetOption option;
172             while (itProjects.hasNext()) {
173                 curProject = ((CmsProject)itProjects.next()).getName();
174                 option = new CmsSelectWidgetOption(curProject, curProject.equals(project));
175                 result.add(option);
176             }
177         } catch (CmsException e) {
178             // should never happen
179
}
180         return result;
181     }
182
183     private List JavaDoc getRebuildModeWidgetConfiguration() {
184
185         List JavaDoc result = new LinkedList JavaDoc();
186         String JavaDoc rebuildMode = m_index.getRebuildMode();
187         CmsSelectWidgetOption option = new CmsSelectWidgetOption("auto", "auto".equals(rebuildMode));
188         result.add(option);
189         option = new CmsSelectWidgetOption("manual", "manual".equals(rebuildMode));
190         result.add(option);
191         return result;
192     }
193
194 }
Popular Tags