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