1 31 32 package org.opencms.workplace.tools.modules; 33 34 import org.opencms.db.CmsExportPoint; 35 import org.opencms.file.types.CmsResourceTypeFolder; 36 import org.opencms.jsp.CmsJspActionElement; 37 import org.opencms.main.CmsException; 38 import org.opencms.main.OpenCms; 39 import org.opencms.module.CmsModule; 40 import org.opencms.util.CmsStringUtil; 41 import org.opencms.workplace.CmsDialog; 42 import org.opencms.workplace.CmsWidgetDialog; 43 import org.opencms.workplace.CmsWorkplace; 44 import org.opencms.workplace.CmsWorkplaceSettings; 45 46 import java.util.List ; 47 import java.util.Map ; 48 import java.util.Set ; 49 import java.util.StringTokenizer ; 50 51 import javax.servlet.http.HttpServletRequest ; 52 import javax.servlet.http.HttpServletResponse ; 53 import javax.servlet.jsp.PageContext ; 54 55 64 public class CmsModulesEditBase extends CmsWidgetDialog { 65 66 67 public static final String DIALOG_TYPE = "ModulesEdit"; 68 69 70 public static final String [] PAGES = {"page1"}; 71 72 73 public static final String PATH_CLASSES = "classes/"; 74 75 76 public static final String PATH_ELEMENTS = "elements/"; 77 78 79 public static final String PATH_LIB = "lib/"; 80 81 82 public static final String PATH_RESOURCES = "resources/"; 83 84 85 public static final String PATH_TEMPLATES = "templates/"; 86 87 88 protected CmsModule m_module; 89 90 91 protected String m_paramModule; 92 93 98 public CmsModulesEditBase(CmsJspActionElement jsp) { 99 100 super(jsp); 101 } 102 103 110 public CmsModulesEditBase(PageContext context, HttpServletRequest req, HttpServletResponse res) { 111 112 this(new CmsJspActionElement(context, req, res)); 113 } 114 115 118 public void actionCommit() { 119 120 if (!hasCommitErrors()) { 121 Set moduleNames = OpenCms.getModuleManager().getModuleNames(); 123 if (moduleNames.contains(m_module.getName())) { 124 try { 126 OpenCms.getModuleManager().updateModule(getCms(), m_module); 127 } catch (CmsException e) { 128 addCommitError(e); 129 } 130 } else { 131 try { 132 m_module = createModuleFolders((CmsModule)m_module.clone()); 133 OpenCms.getModuleManager().addModule(getCms(), m_module); 134 } catch (CmsException e) { 135 addCommitError(e); 136 } 137 } 138 } 139 140 if (!hasCommitErrors()) { 141 Map objects = (Map )getSettings().getListObject(); 143 if (objects != null) { 144 objects.remove(CmsModulesList.class.getName()); 145 } 146 } 147 } 148 149 152 public String getCancelAction() { 153 154 setParamPage((String )getPages().get(0)); 156 157 return DIALOG_SET; 158 } 159 160 165 public String getParamModule() { 166 167 return m_paramModule; 168 } 169 170 174 public void setParamModule(String paramModule) { 175 176 m_paramModule = paramModule; 177 } 178 179 182 protected void defineWidgets() { 183 184 } 186 187 190 protected String [] getPageArray() { 191 192 return PAGES; 193 } 194 195 198 protected void initMessages() { 199 200 addMessages(Messages.get().getBundleName()); 202 super.initMessages(); 204 } 205 206 209 protected void initModule() { 210 211 Object o; 212 213 if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) { 214 if (CmsStringUtil.isNotEmpty(m_paramModule)) { 216 o = OpenCms.getModuleManager().getModule(m_paramModule); 218 } else { 219 o = null; 221 } 222 } else { 223 o = getDialogObject(); 225 } 226 227 if (!(o instanceof CmsModule)) { 228 m_module = new CmsModule(); 230 231 } else { 232 m_module = (CmsModule)((CmsModule)o).clone(); 234 } 235 } 236 237 240 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 241 242 setParamDialogtype(DIALOG_TYPE); 244 245 super.initWorkplaceRequestValues(settings, request); 246 247 setDialogObject(m_module); 249 } 250 251 254 protected void validateParamaters() throws Exception { 255 256 String moduleName = getParamModule(); 257 if (!isNewModule()) { 259 CmsModule module = OpenCms.getModuleManager().getModule(moduleName); 260 if (module == null) { 261 throw new Exception (); 262 } 263 } 264 } 265 266 270 private CmsModule createModuleFolders(CmsModule module) throws CmsException { 271 272 String modulePath = CmsWorkplace.VFS_PATH_MODULES + module.getName() + "/"; 273 List exportPoints = module.getExportPoints(); 274 List resources = module.getResources(); 275 276 if (module.isCreateClassesFolder() 278 || module.isCreateElementsFolder() 279 || module.isCreateLibFolder() 280 || module.isCreateResourcesFolder() 281 || module.isCreateTemplateFolder()) { 282 module.setCreateModuleFolder(true); 283 } 284 285 if (module.isCreateModuleFolder()) { 287 getCms().createResource(modulePath, CmsResourceTypeFolder.getStaticTypeId()); 288 resources.add(modulePath); 290 module.setResources(resources); 291 } 292 293 if (module.isCreateTemplateFolder()) { 295 String path = modulePath + PATH_TEMPLATES; 296 getCms().createResource(path, CmsResourceTypeFolder.getStaticTypeId()); 297 } 298 299 if (module.isCreateElementsFolder()) { 301 String path = modulePath + PATH_ELEMENTS; 302 getCms().createResource(path, CmsResourceTypeFolder.getStaticTypeId()); 303 } 304 305 if (module.isCreateTemplateFolder()) { 307 String path = modulePath + PATH_RESOURCES; 308 getCms().createResource(path, CmsResourceTypeFolder.getStaticTypeId()); 309 } 310 311 if (module.isCreateLibFolder()) { 313 String path = modulePath + PATH_LIB; 314 getCms().createResource(path, CmsResourceTypeFolder.getStaticTypeId()); 315 CmsExportPoint exp = new CmsExportPoint(path, "WEB-INF/lib/"); 316 exportPoints.add(exp); 317 module.setExportPoints(exportPoints); 318 } 319 320 if (module.isCreateClassesFolder()) { 322 String path = modulePath + PATH_CLASSES; 323 getCms().createResource(path, CmsResourceTypeFolder.getStaticTypeId()); 324 CmsExportPoint exp = new CmsExportPoint(path, "WEB-INF/classes/"); 325 exportPoints.add(exp); 326 module.setExportPoints(exportPoints); 327 328 StringTokenizer tok = new StringTokenizer (m_module.getName(), "."); 330 while (tok.hasMoreTokens()) { 331 String folder = tok.nextToken(); 332 path += folder + "/"; 333 getCms().createResource(path, CmsResourceTypeFolder.getStaticTypeId()); 334 } 335 } 336 return module; 337 } 338 339 344 private boolean isNewModule() { 345 346 return getCurrentToolPath().equals("/modules/modules_new"); 347 } 348 } | Popular Tags |