1 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.OpenCms; 38 import org.opencms.module.CmsModule; 39 import org.opencms.security.CmsSecurityException; 40 import org.opencms.util.CmsStringUtil; 41 import org.opencms.widgets.CmsComboWidget; 42 import org.opencms.widgets.CmsDisplayWidget; 43 import org.opencms.widgets.CmsSelectWidgetOption; 44 import org.opencms.widgets.CmsVfsFileWidget; 45 import org.opencms.workplace.CmsDialog; 46 import org.opencms.workplace.CmsWidgetDialog; 47 import org.opencms.workplace.CmsWidgetDialogParameter; 48 import org.opencms.workplace.CmsWorkplaceSettings; 49 50 import java.util.ArrayList ; 51 import java.util.Iterator ; 52 import java.util.List ; 53 import java.util.Map ; 54 55 import javax.servlet.http.HttpServletRequest ; 56 import javax.servlet.http.HttpServletResponse ; 57 import javax.servlet.jsp.PageContext ; 58 59 68 public class CmsExportpointsEdit extends CmsWidgetDialog { 69 70 71 public static final String DIALOG_TYPE = "ExportpointsOverview"; 72 73 74 public static final String [] PAGES = {"page1"}; 75 76 77 private CmsExportPoint m_exportpoint; 78 79 80 private String m_paramExportpoint; 81 82 83 private String m_paramModule; 84 85 90 public CmsExportpointsEdit(CmsJspActionElement jsp) { 91 92 super(jsp); 93 } 94 95 102 public CmsExportpointsEdit(PageContext context, HttpServletRequest req, HttpServletResponse res) { 103 104 this(new CmsJspActionElement(context, req, res)); 105 } 106 107 110 public void actionCommit() { 111 112 List errors = new ArrayList (); 113 114 try { 115 String moduleName = getParamModule(); 117 CmsModule module = (CmsModule)OpenCms.getModuleManager().getModule(moduleName).clone(); 118 List oldExportpoints = module.getExportPoints(); 120 List newExportpoints = new ArrayList (); 122 Iterator i = oldExportpoints.iterator(); 123 while (i.hasNext()) { 124 CmsExportPoint exp = (CmsExportPoint)i.next(); 125 if (!exp.getUri().equals(m_exportpoint.getUri())) { 126 newExportpoints.add(exp); 127 } 128 } 129 newExportpoints.add(m_exportpoint); 131 module.setExportPoints(newExportpoints); 132 OpenCms.getModuleManager().updateModule(getCms(), module); 134 Map objects = (Map )getSettings().getListObject(); 136 if (objects != null) { 137 objects.remove(CmsModulesList.class.getName()); 138 objects.remove(CmsExportpointsList.class.getName()); 139 } 140 } catch (CmsConfigurationException ce) { 141 errors.add(ce); 142 } catch (CmsSecurityException se) { 143 errors.add(se); 144 } 145 146 setCommitErrors(errors); 148 } 149 150 155 public String buildDialogForm() { 156 157 StringBuffer result = new StringBuffer (1024); 158 159 try { 160 161 result.append(createDialogHtml(getParamPage())); 163 164 } catch (Throwable t) { 165 } 167 return result.toString(); 168 } 169 170 173 public String getCancelAction() { 174 175 setParamPage((String )getPages().get(0)); 177 178 return DIALOG_SET; 179 } 180 181 186 public String getParamExportpoint() { 187 188 return m_paramExportpoint; 189 } 190 191 196 public String getParamModule() { 197 198 return m_paramModule; 199 } 200 201 205 public void setParamExportpoint(String paramExportpoint) { 206 207 m_paramExportpoint = paramExportpoint; 208 } 209 210 214 public void setParamModule(String paramModule) { 215 216 m_paramModule = paramModule; 217 } 218 219 225 protected String createDialogHtml(String dialog) { 226 227 StringBuffer result = new StringBuffer (1024); 228 229 result.append(createWidgetTableStart()); 231 232 result.append(createWidgetErrorHeader()); 234 235 if (dialog.equals(PAGES[0])) { 236 result.append(dialogBlockStart(key("label.exportpointinformation"))); 237 result.append(createWidgetTableStart()); 238 result.append(createDialogRowsHtml(0, 2)); 239 result.append(createWidgetTableEnd()); 240 result.append(dialogBlockEnd()); 241 } 242 243 result.append(createWidgetTableEnd()); 245 246 return result.toString(); 247 } 248 249 252 protected void defineWidgets() { 253 254 initModule(); 255 256 List destinations = getDestinations(); 257 258 addWidget(new CmsWidgetDialogParameter(m_exportpoint, "uri", PAGES[0], new CmsVfsFileWidget())); 259 addWidget(new CmsWidgetDialogParameter(m_exportpoint, "configuredDestination", PAGES[0], new CmsComboWidget( 260 destinations))); 261 addWidget(new CmsWidgetDialogParameter(m_exportpoint, "destinationPath", PAGES[0], new CmsDisplayWidget())); 262 263 } 264 265 268 protected String [] getPageArray() { 269 270 return PAGES; 271 } 272 273 276 protected void initMessages() { 277 278 addMessages(Messages.get().getBundleName()); 280 super.initMessages(); 282 } 283 284 287 protected void initModule() { 288 289 Object o; 290 CmsModule module; 291 292 if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) { 293 if (CmsStringUtil.isNotEmpty(m_paramModule)) { 295 o = OpenCms.getModuleManager().getModule(m_paramModule); 297 } else { 298 o = null; 300 } 301 } else { 302 o = getDialogObject(); 304 } 305 306 if (!(o instanceof CmsModule)) { 307 module = new CmsModule(); 309 310 } else { 311 module = (CmsModule)((CmsModule)o).clone(); 313 } 314 315 List exportpoints = module.getExportPoints(); 316 m_exportpoint = new CmsExportPoint(); 317 if (exportpoints != null && exportpoints.size() > 0) { 318 Iterator i = exportpoints.iterator(); 319 while (i.hasNext()) { 320 CmsExportPoint exportpoint = (CmsExportPoint)i.next(); 321 if (exportpoint.getUri().equals(m_paramExportpoint)) { 322 m_exportpoint = exportpoint; 323 } 324 } 325 } 326 327 } 328 329 332 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 333 334 setParamDialogtype(DIALOG_TYPE); 336 337 super.initWorkplaceRequestValues(settings, request); 338 339 setDialogObject(m_exportpoint); 341 342 } 343 344 347 protected void validateParamaters() throws Exception { 348 349 String moduleName = getParamModule(); 350 CmsModule module = OpenCms.getModuleManager().getModule(moduleName); 352 if (module == null) { 353 throw new Exception (); 354 } 355 if (!isNewExportPoint()) { 357 Iterator it = module.getExportPoints().iterator(); 358 while (it.hasNext()) { 359 CmsExportPoint ep = (CmsExportPoint)it.next(); 360 if (ep.getUri().equals(getParamExportpoint())) { 361 return; 363 } 364 } 365 throw new Exception (); 366 } 367 } 368 369 376 private List getDestinations() { 377 378 List result = new ArrayList (); 379 result.add(new CmsSelectWidgetOption("WEB-INF/classes/")); 380 result.add(new CmsSelectWidgetOption("WEB-INF/lib/")); 381 return result; 382 } 383 384 389 private boolean isNewExportPoint() { 390 391 return getCurrentToolPath().equals("/modules/edit/exportpoints/new"); 392 } 393 } | Popular Tags |