KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > modules > CmsExportpointsList


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/modules/CmsExportpointsList.java,v $
3  * Date : $Date: 2006/03/27 14:52:53 $
4  * Version: $Revision: 1.14 $
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.modules;
33
34 import org.opencms.configuration.CmsConfigurationException;
35 import org.opencms.db.CmsExportPoint;
36 import org.opencms.jsp.CmsJspActionElement;
37 import org.opencms.main.CmsRuntimeException;
38 import org.opencms.main.OpenCms;
39 import org.opencms.module.CmsModule;
40 import org.opencms.security.CmsRoleViolationException;
41 import org.opencms.workplace.list.A_CmsListDialog;
42 import org.opencms.workplace.list.CmsListColumnAlignEnum;
43 import org.opencms.workplace.list.CmsListColumnDefinition;
44 import org.opencms.workplace.list.CmsListDefaultAction;
45 import org.opencms.workplace.list.CmsListDirectAction;
46 import org.opencms.workplace.list.CmsListItem;
47 import org.opencms.workplace.list.CmsListMetadata;
48 import org.opencms.workplace.list.CmsListMultiAction;
49 import org.opencms.workplace.list.CmsListOrderEnum;
50
51 import java.io.IOException JavaDoc;
52 import java.util.ArrayList JavaDoc;
53 import java.util.HashMap JavaDoc;
54 import java.util.Iterator JavaDoc;
55 import java.util.List JavaDoc;
56 import java.util.Map JavaDoc;
57
58 import javax.servlet.ServletException JavaDoc;
59 import javax.servlet.http.HttpServletRequest JavaDoc;
60 import javax.servlet.http.HttpServletResponse JavaDoc;
61 import javax.servlet.jsp.PageContext JavaDoc;
62
63 /**
64  * Module exportpoint view.<p>
65  *
66  * @author Michael Emmerich
67  *
68  * @version $Revision: 1.14 $
69  *
70  * @since 6.0.0
71  */

72 public class CmsExportpointsList extends A_CmsListDialog {
73
74     /** List action delete. */
75     public static final String JavaDoc LIST_ACTION_DELETE = "ad";
76
77     /** list action id constant. */
78     public static final String JavaDoc LIST_ACTION_EDIT = "ae";
79
80     /** List column delete. */
81     public static final String JavaDoc LIST_COLUMN_DELETE = "cd";
82
83     /** List column name. */
84     public static final String JavaDoc LIST_COLUMN_DESTINATION = "ct";
85
86     /** List column edit. */
87     public static final String JavaDoc LIST_COLUMN_EDIT = "ce";
88
89     /** List column name. */
90     public static final String JavaDoc LIST_COLUMN_SERVERDESTINATION = "cs";
91
92     /** List column name. */
93     public static final String JavaDoc LIST_COLUMN_URI = "cu";
94
95     /** list action id constant. */
96     public static final String JavaDoc LIST_DEFACTION_EDIT = "de";
97
98     /** list id constant. */
99     public static final String JavaDoc LIST_ID = "lmep";
100
101     /** List action multi delete. */
102     public static final String JavaDoc LIST_MACTION_DELETE = "md";
103
104     /** Exportpoint parameter. */
105     public static final String JavaDoc PARAM_EXPORTPOINT = "exportpoint";
106
107     /** Module parameter. */
108     public static final String JavaDoc PARAM_MODULE = "module";
109
110     /** Path to the list buttons. */
111     public static final String JavaDoc PATH_BUTTONS = "tools/modules/buttons/";
112
113     /** Modulename. */
114     private String JavaDoc m_paramModule;
115
116     /**
117      * Public constructor.<p>
118      *
119      * @param jsp an initialized JSP action element
120      */

121     public CmsExportpointsList(CmsJspActionElement jsp) {
122
123         super(
124             jsp,
125             LIST_ID,
126             Messages.get().container(Messages.GUI_EXPORTPOINTS_LIST_NAME_0),
127             LIST_COLUMN_URI,
128             CmsListOrderEnum.ORDER_ASCENDING,
129             null);
130     }
131
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 CmsExportpointsList(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
140
141         this(new CmsJspActionElement(context, req, res));
142     }
143
144     /**
145      * This method should handle every defined list multi action,
146      * by comparing <code>{@link #getParamListAction()}</code> with the id
147      * of the action to execute.<p>
148      */

149     public void executeListMultiActions() {
150
151         if (getParamListAction().equals(LIST_MACTION_DELETE)) {
152             String JavaDoc moduleName = getParamModule();
153             // execute the delete multiaction
154
Iterator JavaDoc itItems = getSelectedItems().iterator();
155
156             while (itItems.hasNext()) {
157                 CmsModule module = (CmsModule)OpenCms.getModuleManager().getModule(moduleName).clone();
158                 CmsListItem listItem = (CmsListItem)itItems.next();
159                 String JavaDoc exportpointName = listItem.getId();
160                 deleteExportpoint(module, exportpointName);
161             }
162         }
163         // refresh the list
164
Map JavaDoc objects = (Map JavaDoc)getSettings().getListObject();
165         if (objects != null) {
166             objects.remove(CmsModulesList.class.getName());
167         }
168         listSave();
169
170     }
171
172     /**
173      * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
174      */

175     public void executeListSingleActions() throws IOException JavaDoc, ServletException JavaDoc {
176
177         String JavaDoc moduleName = getParamModule();
178         String JavaDoc exportpointName = getSelectedItem().getId();
179
180         Map JavaDoc params = new HashMap JavaDoc();
181         params.put(PARAM_MODULE, moduleName);
182         params.put(PARAM_EXPORTPOINT, exportpointName);
183
184         if (getParamListAction().equals(LIST_ACTION_DELETE)) {
185             // delete a dependency
186
CmsModule module = (CmsModule)OpenCms.getModuleManager().getModule(moduleName).clone();
187             deleteExportpoint(module, exportpointName);
188         } else if (getParamListAction().equals(LIST_ACTION_EDIT) || getParamListAction().equals(LIST_DEFACTION_EDIT)) {
189             // edit an export pointfrom the list
190
params.put(PARAM_ACTION, DIALOG_INITIAL);
191             getToolManager().jspForwardTool(this, "/modules/edit/exportpoints/edit", params);
192         }
193         // refresh the list
194
Map JavaDoc objects = (Map JavaDoc)getSettings().getListObject();
195         if (objects != null) {
196             objects.remove(CmsModulesList.class.getName());
197         }
198         listSave();
199     }
200
201     /**
202      * Gets the module parameter.<p>
203      *
204      * @return the module parameter
205      */

206     public String JavaDoc getParamModule() {
207
208         return m_paramModule;
209     }
210
211     /**
212      * Sets the module parameter.<p>
213      * @param paramModule the module parameter
214      */

215     public void setParamModule(String JavaDoc paramModule) {
216
217         m_paramModule = paramModule;
218     }
219
220     /**
221      * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
222      */

223     protected void fillDetails(String JavaDoc detailId) {
224
225         // noop
226
}
227
228     /**
229      * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
230      */

231     protected List JavaDoc getListItems() {
232
233         List JavaDoc ret = new ArrayList JavaDoc();
234
235         String JavaDoc moduleName = getParamModule();
236         CmsModule module = OpenCms.getModuleManager().getModule(moduleName);
237         // get exportpoints
238
List JavaDoc exportpoints = module.getExportPoints();
239         Iterator JavaDoc i = exportpoints.iterator();
240         while (i.hasNext()) {
241             CmsExportPoint exportpoint = (CmsExportPoint)i.next();
242             CmsListItem item = getList().newItem(exportpoint.getUri());
243             // name
244
item.set(LIST_COLUMN_URI, exportpoint.getUri());
245             // destination
246
item.set(LIST_COLUMN_DESTINATION, exportpoint.getConfiguredDestination());
247             // server
248
item.set(LIST_COLUMN_SERVERDESTINATION, exportpoint.getDestinationPath());
249
250             ret.add(item);
251         }
252         return ret;
253     }
254
255     /**
256      * @see org.opencms.workplace.CmsWorkplace#initMessages()
257      */

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

269     protected void setColumns(CmsListMetadata metadata) {
270
271         //add column for edit action
272
CmsListColumnDefinition editCol = new CmsListColumnDefinition(LIST_COLUMN_EDIT);
273         editCol.setName(Messages.get().container(Messages.GUI_MODULES_LIST_COLS_EDIT_0));
274         editCol.setWidth("20");
275         editCol.setSorteable(false);
276         editCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
277         // add the edit action
278
CmsListDirectAction editColAction = new CmsListDirectAction(LIST_ACTION_EDIT);
279         editColAction.setName(Messages.get().container(Messages.GUI_EXPORTPOINTS_LIST_ACTION_EDIT_NAME_0));
280         editColAction.setHelpText(Messages.get().container(Messages.GUI_EXPORTPOINTS_LIST_ACTION_EDIT_HELP_0));
281         editColAction.setIconPath(PATH_BUTTONS + "module_exportpoints.png");
282         editColAction.setEnabled(true);
283         editColAction.setConfirmationMessage(null);
284         editCol.addDirectAction(editColAction);
285         metadata.addColumn(editCol);
286
287         // add column for delete action
288
CmsListColumnDefinition delCol = new CmsListColumnDefinition(LIST_COLUMN_DELETE);
289         delCol.setName(Messages.get().container(Messages.GUI_MODULES_LIST_COLS_DELETE_0));
290         delCol.setWidth("20");
291         delCol.setSorteable(false);
292         delCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
293         // direct action: delete module
294
CmsListDirectAction delDependency = new CmsListDirectAction(LIST_ACTION_DELETE);
295         delDependency.setName(Messages.get().container(Messages.GUI_EXPORTPOINTS_LIST_ACTION_DELETE_NAME_0));
296         delDependency.setConfirmationMessage(Messages.get().container(
297             Messages.GUI_EXPORTPOINTS_LIST_ACTION_DELETE_CONF_0));
298         delDependency.setIconPath(ICON_DELETE);
299         delDependency.setEnabled(true);
300         delDependency.setHelpText(Messages.get().container(Messages.GUI_EXPORTPOINTS_LIST_ACTION_DELETE_HELP_0));
301         delCol.addDirectAction(delDependency);
302         metadata.addColumn(delCol);
303
304         // add column for name
305
CmsListColumnDefinition nameCol = new CmsListColumnDefinition(LIST_COLUMN_URI);
306         nameCol.setName(Messages.get().container(Messages.GUI_EXPORTPOINTS_LIST_COLS_URI_0));
307         nameCol.setWidth("40%");
308         nameCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
309         // create default edit action for name column: edit dependency
310
CmsListDefaultAction nameColAction = new CmsListDefaultAction(LIST_DEFACTION_EDIT);
311         nameColAction.setName(Messages.get().container(Messages.GUI_EXPORTPOINTS_LIST_ACTION_OVERVIEW_NAME_0));
312         nameColAction.setIconPath(null);
313         nameColAction.setHelpText(Messages.get().container(Messages.GUI_EXPORTPOINTS_LIST_ACTION_OVERVIEW_HELP_0));
314         nameColAction.setEnabled(true);
315         nameColAction.setConfirmationMessage(null);
316         // set action for the name column
317
nameCol.addDefaultAction(nameColAction);
318         metadata.addColumn(nameCol);
319
320         // add column for destination
321
CmsListColumnDefinition destinationCol = new CmsListColumnDefinition(LIST_COLUMN_DESTINATION);
322         destinationCol.setName(Messages.get().container(Messages.GUI_EXPORTPOINTS_LIST_COLS_DESTINATION_0));
323         destinationCol.setWidth("30%");
324         destinationCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
325         metadata.addColumn(destinationCol);
326
327         // add column for server destination
328
CmsListColumnDefinition serverDestinationCol = new CmsListColumnDefinition(LIST_COLUMN_SERVERDESTINATION);
329         serverDestinationCol.setName(Messages.get().container(Messages.GUI_EXPORTPOINTS_LIST_COLS_SERVERDESTINATION_0));
330         serverDestinationCol.setWidth("30%");
331         serverDestinationCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
332         metadata.addColumn(serverDestinationCol);
333
334     }
335
336     /**
337      * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
338      */

339     protected void setIndependentActions(CmsListMetadata metadata) {
340
341         // noop
342
}
343
344     /**
345      * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
346      */

347     protected void setMultiActions(CmsListMetadata metadata) {
348
349         // add the delete dependencies multi action
350
CmsListMultiAction deleteDependencies = new CmsListMultiAction(LIST_MACTION_DELETE);
351         deleteDependencies.setName(Messages.get().container(Messages.GUI_DEPENDENCIES_LIST_ACTION_MDELETE_NAME_0));
352         deleteDependencies.setConfirmationMessage(Messages.get().container(
353             Messages.GUI_DEPENDENCIES_LIST_ACTION_MDELETE_CONF_0));
354         deleteDependencies.setIconPath(ICON_MULTI_DELETE);
355         deleteDependencies.setEnabled(true);
356         deleteDependencies.setHelpText(Messages.get().container(Messages.GUI_DEPENDENCIES_LIST_ACTION_MDELETE_HELP_0));
357         metadata.addMultiAction(deleteDependencies);
358     }
359
360     /**
361      * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
362      */

363     protected void validateParamaters() throws Exception JavaDoc {
364
365         if (OpenCms.getModuleManager().getModule(getParamModule()) == null) {
366             // just throw a dummy exception here since getModule does not produce an exception when a
367
// module is not found
368
throw new Exception JavaDoc();
369         }
370     }
371
372     /**
373      * Deletes a module exportpoint from a module.<p>
374      *
375      * @param module the module to delete the dependency from
376      * @param exportpoint the name of the exportpoint to delete
377      */

378     private void deleteExportpoint(CmsModule module, String JavaDoc exportpoint) {
379
380         List JavaDoc oldExportpoints = module.getExportPoints();
381         List JavaDoc newExportpoints = new ArrayList JavaDoc();
382         Iterator JavaDoc i = oldExportpoints.iterator();
383         while (i.hasNext()) {
384             CmsExportPoint exp = (CmsExportPoint)i.next();
385             if (!exp.getUri().equals(exportpoint)) {
386                 newExportpoints.add(exp);
387             }
388         }
389         module.setExportPoints(newExportpoints);
390         // update the module information
391
try {
392             OpenCms.getModuleManager().updateModule(getCms(), module);
393         } catch (CmsConfigurationException ce) {
394             // should never happen
395
throw new CmsRuntimeException(Messages.get().container(
396                 Messages.ERR_ACTION_EXPORTPOINTS_DELETE_2,
397                 exportpoint,
398                 module.getName()), ce);
399
400         } catch (CmsRoleViolationException re) {
401             throw new CmsRuntimeException(Messages.get().container(
402                 Messages.ERR_ACTION_EXPORTPOINTS_DELETE_2,
403                 exportpoint,
404                 module.getName()), re);
405         }
406         getList().removeItem(exportpoint, getLocale());
407     }
408 }
Popular Tags