001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/modules/CmsExportpointsList.java,v $
003: * Date : $Date: 2008-02-27 12:05:32 $
004: * Version: $Revision: 1.17 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools.modules;
033:
034: import org.opencms.configuration.CmsConfigurationException;
035: import org.opencms.db.CmsExportPoint;
036: import org.opencms.jsp.CmsJspActionElement;
037: import org.opencms.main.CmsRuntimeException;
038: import org.opencms.main.OpenCms;
039: import org.opencms.module.CmsModule;
040: import org.opencms.security.CmsRoleViolationException;
041: import org.opencms.workplace.list.A_CmsListDialog;
042: import org.opencms.workplace.list.CmsListColumnAlignEnum;
043: import org.opencms.workplace.list.CmsListColumnDefinition;
044: import org.opencms.workplace.list.CmsListDefaultAction;
045: import org.opencms.workplace.list.CmsListDirectAction;
046: import org.opencms.workplace.list.CmsListItem;
047: import org.opencms.workplace.list.CmsListMetadata;
048: import org.opencms.workplace.list.CmsListMultiAction;
049: import org.opencms.workplace.list.CmsListOrderEnum;
050:
051: import java.io.IOException;
052: import java.util.ArrayList;
053: import java.util.HashMap;
054: import java.util.Iterator;
055: import java.util.List;
056: import java.util.Map;
057:
058: import javax.servlet.ServletException;
059: import javax.servlet.http.HttpServletRequest;
060: import javax.servlet.http.HttpServletResponse;
061: import javax.servlet.jsp.PageContext;
062:
063: /**
064: * Module exportpoint view.<p>
065: *
066: * @author Michael Emmerich
067: *
068: * @version $Revision: 1.17 $
069: *
070: * @since 6.0.0
071: */
072: public class CmsExportpointsList extends A_CmsListDialog {
073:
074: /** List action delete. */
075: public static final String LIST_ACTION_DELETE = "ad";
076:
077: /** list action id constant. */
078: public static final String LIST_ACTION_EDIT = "ae";
079:
080: /** List column delete. */
081: public static final String LIST_COLUMN_DELETE = "cd";
082:
083: /** List column name. */
084: public static final String LIST_COLUMN_DESTINATION = "ct";
085:
086: /** List column edit. */
087: public static final String LIST_COLUMN_EDIT = "ce";
088:
089: /** List column name. */
090: public static final String LIST_COLUMN_SERVERDESTINATION = "cs";
091:
092: /** List column name. */
093: public static final String LIST_COLUMN_URI = "cu";
094:
095: /** list action id constant. */
096: public static final String LIST_DEFACTION_EDIT = "de";
097:
098: /** list id constant. */
099: public static final String LIST_ID = "lmep";
100:
101: /** List action multi delete. */
102: public static final String LIST_MACTION_DELETE = "md";
103:
104: /** Exportpoint parameter. */
105: public static final String PARAM_EXPORTPOINT = "exportpoint";
106:
107: /** Module parameter. */
108: public static final String PARAM_MODULE = "module";
109:
110: /** Path to the list buttons. */
111: public static final String PATH_BUTTONS = "tools/modules/buttons/";
112:
113: /** Modulename. */
114: private String 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 (jsp, LIST_ID, Messages.get().container(
124: Messages.GUI_EXPORTPOINTS_LIST_NAME_0),
125: LIST_COLUMN_URI, CmsListOrderEnum.ORDER_ASCENDING, null);
126: }
127:
128: /**
129: * Public constructor with JSP variables.<p>
130: *
131: * @param context the JSP page context
132: * @param req the JSP request
133: * @param res the JSP response
134: */
135: public CmsExportpointsList(PageContext context,
136: HttpServletRequest req, HttpServletResponse res) {
137:
138: this (new CmsJspActionElement(context, req, res));
139: }
140:
141: /**
142: * This method should handle every defined list multi action,
143: * by comparing <code>{@link #getParamListAction()}</code> with the id
144: * of the action to execute.<p>
145: */
146: public void executeListMultiActions() {
147:
148: if (getParamListAction().equals(LIST_MACTION_DELETE)) {
149: String moduleName = getParamModule();
150: // execute the delete multiaction
151: Iterator itItems = getSelectedItems().iterator();
152:
153: while (itItems.hasNext()) {
154: CmsModule module = (CmsModule) OpenCms
155: .getModuleManager().getModule(moduleName)
156: .clone();
157: CmsListItem listItem = (CmsListItem) itItems.next();
158: String exportpointName = listItem.getId();
159: deleteExportpoint(module, exportpointName);
160: }
161: }
162: // refresh the list
163: Map objects = (Map) getSettings().getListObject();
164: if (objects != null) {
165: objects.remove(CmsModulesList.class.getName());
166: }
167: listSave();
168:
169: }
170:
171: /**
172: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
173: */
174: public void executeListSingleActions() throws IOException,
175: ServletException {
176:
177: String moduleName = getParamModule();
178: String exportpointName = getSelectedItem().getId();
179:
180: Map params = new HashMap();
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()
187: .getModule(moduleName).clone();
188: deleteExportpoint(module, exportpointName);
189: } else if (getParamListAction().equals(LIST_ACTION_EDIT)
190: || getParamListAction().equals(LIST_DEFACTION_EDIT)) {
191: // edit an export pointfrom the list
192: params.put(PARAM_ACTION, DIALOG_INITIAL);
193: getToolManager().jspForwardTool(this ,
194: "/modules/edit/exportpoints/edit", params);
195: }
196: // refresh the list
197: Map objects = (Map) getSettings().getListObject();
198: if (objects != null) {
199: objects.remove(CmsModulesList.class.getName());
200: }
201: listSave();
202: }
203:
204: /**
205: * Gets the module parameter.<p>
206: *
207: * @return the module parameter
208: */
209: public String getParamModule() {
210:
211: return m_paramModule;
212: }
213:
214: /**
215: * Sets the module parameter.<p>
216: * @param paramModule the module parameter
217: */
218: public void setParamModule(String paramModule) {
219:
220: m_paramModule = paramModule;
221: }
222:
223: /**
224: * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
225: */
226: protected void fillDetails(String detailId) {
227:
228: // noop
229: }
230:
231: /**
232: * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
233: */
234: protected List getListItems() {
235:
236: List ret = new ArrayList();
237:
238: String moduleName = getParamModule();
239: CmsModule module = OpenCms.getModuleManager().getModule(
240: moduleName);
241: // get exportpoints
242: List exportpoints = module.getExportPoints();
243: Iterator i = exportpoints.iterator();
244: while (i.hasNext()) {
245: CmsExportPoint exportpoint = (CmsExportPoint) i.next();
246: CmsListItem item = getList().newItem(exportpoint.getUri());
247: // name
248: item.set(LIST_COLUMN_URI, exportpoint.getUri());
249: // destination
250: item.set(LIST_COLUMN_DESTINATION, exportpoint
251: .getConfiguredDestination());
252: // server
253: item.set(LIST_COLUMN_SERVERDESTINATION, exportpoint
254: .getDestinationPath());
255:
256: ret.add(item);
257: }
258: return ret;
259: }
260:
261: /**
262: * @see org.opencms.workplace.CmsWorkplace#initMessages()
263: */
264: protected void initMessages() {
265:
266: // add specific dialog resource bundle
267: addMessages(Messages.get().getBundleName());
268: // add default resource bundles
269: super .initMessages();
270: }
271:
272: /**
273: * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
274: */
275: protected void setColumns(CmsListMetadata metadata) {
276:
277: //add column for edit action
278: CmsListColumnDefinition editCol = new CmsListColumnDefinition(
279: LIST_COLUMN_EDIT);
280: editCol.setName(Messages.get().container(
281: Messages.GUI_MODULES_LIST_COLS_EDIT_0));
282: editCol.setWidth("20");
283: editCol.setSorteable(false);
284: editCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
285: // add the edit action
286: CmsListDirectAction editColAction = new CmsListDirectAction(
287: LIST_ACTION_EDIT);
288: editColAction.setName(Messages.get().container(
289: Messages.GUI_EXPORTPOINTS_LIST_ACTION_EDIT_NAME_0));
290: editColAction.setHelpText(Messages.get().container(
291: Messages.GUI_EXPORTPOINTS_LIST_ACTION_EDIT_HELP_0));
292: editColAction.setIconPath(PATH_BUTTONS
293: + "module_exportpoints.png");
294: editColAction.setEnabled(true);
295: editColAction.setConfirmationMessage(null);
296: editCol.addDirectAction(editColAction);
297: metadata.addColumn(editCol);
298:
299: // add column for delete action
300: CmsListColumnDefinition delCol = new CmsListColumnDefinition(
301: LIST_COLUMN_DELETE);
302: delCol.setName(Messages.get().container(
303: Messages.GUI_MODULES_LIST_COLS_DELETE_0));
304: delCol.setWidth("20");
305: delCol.setSorteable(false);
306: delCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
307: // direct action: delete module
308: CmsListDirectAction delDependency = new CmsListDirectAction(
309: LIST_ACTION_DELETE);
310: delDependency.setName(Messages.get().container(
311: Messages.GUI_EXPORTPOINTS_LIST_ACTION_DELETE_NAME_0));
312: delDependency.setConfirmationMessage(Messages.get().container(
313: Messages.GUI_EXPORTPOINTS_LIST_ACTION_DELETE_CONF_0));
314: delDependency.setIconPath(ICON_DELETE);
315: delDependency.setEnabled(true);
316: delDependency.setHelpText(Messages.get().container(
317: Messages.GUI_EXPORTPOINTS_LIST_ACTION_DELETE_HELP_0));
318: delCol.addDirectAction(delDependency);
319: metadata.addColumn(delCol);
320:
321: // add column for name
322: CmsListColumnDefinition nameCol = new CmsListColumnDefinition(
323: LIST_COLUMN_URI);
324: nameCol.setName(Messages.get().container(
325: Messages.GUI_EXPORTPOINTS_LIST_COLS_URI_0));
326: nameCol.setWidth("40%");
327: nameCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
328: // create default edit action for name column: edit dependency
329: CmsListDefaultAction nameColAction = new CmsListDefaultAction(
330: LIST_DEFACTION_EDIT);
331: nameColAction.setName(Messages.get().container(
332: Messages.GUI_EXPORTPOINTS_LIST_ACTION_OVERVIEW_NAME_0));
333: nameColAction.setIconPath(null);
334: nameColAction.setHelpText(Messages.get().container(
335: Messages.GUI_EXPORTPOINTS_LIST_ACTION_OVERVIEW_HELP_0));
336: nameColAction.setEnabled(true);
337: nameColAction.setConfirmationMessage(null);
338: // set action for the name column
339: nameCol.addDefaultAction(nameColAction);
340: metadata.addColumn(nameCol);
341:
342: // add column for destination
343: CmsListColumnDefinition destinationCol = new CmsListColumnDefinition(
344: LIST_COLUMN_DESTINATION);
345: destinationCol.setName(Messages.get().container(
346: Messages.GUI_EXPORTPOINTS_LIST_COLS_DESTINATION_0));
347: destinationCol.setWidth("30%");
348: destinationCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
349: metadata.addColumn(destinationCol);
350:
351: // add column for server destination
352: CmsListColumnDefinition serverDestinationCol = new CmsListColumnDefinition(
353: LIST_COLUMN_SERVERDESTINATION);
354: serverDestinationCol
355: .setName(Messages
356: .get()
357: .container(
358: Messages.GUI_EXPORTPOINTS_LIST_COLS_SERVERDESTINATION_0));
359: serverDestinationCol.setWidth("30%");
360: serverDestinationCol
361: .setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
362: metadata.addColumn(serverDestinationCol);
363:
364: }
365:
366: /**
367: * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
368: */
369: protected void setIndependentActions(CmsListMetadata metadata) {
370:
371: // noop
372: }
373:
374: /**
375: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
376: */
377: protected void setMultiActions(CmsListMetadata metadata) {
378:
379: // add the delete dependencies multi action
380: CmsListMultiAction deleteDependencies = new CmsListMultiAction(
381: LIST_MACTION_DELETE);
382: deleteDependencies.setName(Messages.get().container(
383: Messages.GUI_DEPENDENCIES_LIST_ACTION_MDELETE_NAME_0));
384: deleteDependencies
385: .setConfirmationMessage(Messages
386: .get()
387: .container(
388: Messages.GUI_DEPENDENCIES_LIST_ACTION_MDELETE_CONF_0));
389: deleteDependencies.setIconPath(ICON_MULTI_DELETE);
390: deleteDependencies.setEnabled(true);
391: deleteDependencies.setHelpText(Messages.get().container(
392: Messages.GUI_DEPENDENCIES_LIST_ACTION_MDELETE_HELP_0));
393: metadata.addMultiAction(deleteDependencies);
394: }
395:
396: /**
397: * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
398: */
399: protected void validateParamaters() throws Exception {
400:
401: if (OpenCms.getModuleManager().getModule(getParamModule()) == null) {
402: // just throw a dummy exception here since getModule does not produce an exception when a
403: // module is not found
404: throw new Exception();
405: }
406: }
407:
408: /**
409: * Deletes a module exportpoint from a module.<p>
410: *
411: * @param module the module to delete the dependency from
412: * @param exportpoint the name of the exportpoint to delete
413: */
414: private void deleteExportpoint(CmsModule module, String exportpoint) {
415:
416: List oldExportpoints = module.getExportPoints();
417: List newExportpoints = new ArrayList();
418: Iterator i = oldExportpoints.iterator();
419: while (i.hasNext()) {
420: CmsExportPoint exp = (CmsExportPoint) i.next();
421: if (!exp.getUri().equals(exportpoint)) {
422: newExportpoints.add(exp);
423: }
424: }
425: module.setExportPoints(newExportpoints);
426: // update the module information
427: try {
428: OpenCms.getModuleManager().updateModule(getCms(), module);
429: } catch (CmsConfigurationException ce) {
430: // should never happen
431: throw new CmsRuntimeException(Messages.get().container(
432: Messages.ERR_ACTION_EXPORTPOINTS_DELETE_2,
433: exportpoint, module.getName()), ce);
434:
435: } catch (CmsRoleViolationException re) {
436: throw new CmsRuntimeException(Messages.get().container(
437: Messages.ERR_ACTION_EXPORTPOINTS_DELETE_2,
438: exportpoint, module.getName()), re);
439: }
440: }
441: }
|