1 28 29 30 package com.opencms.workplace; 31 32 import org.opencms.file.CmsGroup; 33 import org.opencms.file.CmsObject; 34 import org.opencms.file.CmsProject; 35 import org.opencms.file.CmsRequestContext; 36 import org.opencms.file.CmsResource; 37 import org.opencms.main.CmsException; 38 import org.opencms.main.CmsLog; 39 import org.opencms.main.OpenCms; 40 import org.opencms.workplace.CmsWorkplace; 41 42 import com.opencms.core.I_CmsSession; 43 import com.opencms.legacy.CmsXmlTemplateLoader; 44 import com.opencms.template.CmsXmlTemplateFile; 45 46 import java.util.Collections ; 47 import java.util.Hashtable ; 48 import java.util.List ; 49 import java.util.StringTokenizer ; 50 import java.util.Vector ; 51 52 64 65 public class CmsAdminProjectNew extends CmsWorkplaceDefault { 66 67 68 69 private static String C_NEWNAME = "new_project_name"; 70 71 72 73 private static String C_NEWDESCRIPTION = "new_project_description"; 74 75 76 77 private static String C_NEWGROUP = "new_project_group"; 78 79 80 81 private static String C_NEWMANAGERGROUP = "new_project_managergroup"; 82 83 84 private static String C_NEWFOLDER = "new_project_folder"; 85 86 87 88 private static String C_NEWTYPE = "projecttype"; 89 90 91 private static String C_NEWRESOURCES = "ALLRES"; 92 93 94 private static String C_NEWCHANNELS = "ALLCHAN"; 95 96 102 103 private void checkRedundancies(Vector resources) { 104 int i, j; 105 if(resources == null) { 106 return ; 107 } 108 Vector redundant = new Vector (); 109 int n = resources.size(); 110 if(n < 2) { 111 112 return ; 115 } 116 for(i = 0;i < n;i++) { 117 redundant.addElement(new Boolean (false)); 118 } 119 for(i = 0;i < n - 1;i++) { 120 for(j = i + 1;j < n;j++) { 121 if(((String )resources.elementAt(i)).length() < 122 ((String )resources.elementAt(j)).length()) { 123 if(((String )resources.elementAt(j)).startsWith((String )resources.elementAt(i))) { 124 redundant.setElementAt(new Boolean (true), j); 125 } 126 } 127 else { 128 if(((String )resources.elementAt(i)).startsWith((String )resources.elementAt(j))) { 129 redundant.setElementAt(new Boolean (true), i); 130 } 131 } 132 } 133 } 134 for(i = n - 1;i >= 0;i--) { 135 if(((Boolean )redundant.elementAt(i)).booleanValue()) { 136 resources.removeElementAt(i); 137 } 138 } 139 } 140 141 152 public byte[] getContent(CmsObject cms, String templateFile, String elementName, 153 Hashtable parameters, String templateSelector) throws CmsException { 154 if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) { 155 CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName)); 156 CmsLog.getLog(this).debug("Template file is: " + templateFile); 157 CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector)); 158 } 159 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 160 CmsRequestContext reqCont = cms.getRequestContext(); 161 CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms); 162 String initial = (String )parameters.get(CmsWorkplaceDefault.C_PARA_INITIAL); 164 if(initial != null) { 165 166 session.removeValue(C_NEWNAME); 168 session.removeValue(C_NEWGROUP); 169 session.removeValue(C_NEWDESCRIPTION); 170 session.removeValue(C_NEWMANAGERGROUP); 171 session.removeValue(C_NEWFOLDER); 172 session.removeValue(C_NEWRESOURCES); 173 session.removeValue(C_NEWCHANNELS); 174 session.removeValue(C_NEWTYPE); 175 session.removeValue("lasturl"); 176 session.removeValue("newProjectCallingFrom"); 177 reqCont.setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID)); 178 } 179 String newName, newGroup, newDescription, newManagerGroup; 180 int projectType = 0; 181 String newType = new String (); 182 String action = new String (); 183 action = (String )parameters.get("action"); 184 CmsXmlTemplateFile xmlTemplateDocument = getOwnTemplateFile(cms, templateFile, 185 elementName, parameters, templateSelector); 186 187 String fileToGo = (String )parameters.get(CmsWorkplaceDefault.C_PARA_RESOURCE); 189 if (fileToGo == null){ 190 fileToGo = (String )session.getValue("newProjectCallingFrom"); 191 } else { 192 CmsResource resource = cms.readResource(fileToGo); 193 if (resource.isFolder() && !resource.getRootPath().endsWith("/")) { 194 fileToGo += "/"; 195 } 196 } 197 String lasturl = (String )parameters.get("lasturl"); 198 if (lasturl == null){ 199 lasturl = (String )session.getValue("lasturl"); 200 } 201 newName = (String )parameters.get(CmsWorkplaceDefault.C_PROJECTNEW_NAME); 202 if(newName == null) { 203 newName = (String )session.getValue(C_NEWNAME); 204 } 205 String errorTemplateAddOn = ""; 206 if (fileToGo != null){ 207 if(!cms.isManagerOfProject()){ 209 return startProcessing(cms, xmlTemplateDocument, elementName,parameters, "norigths"); 211 } 212 errorTemplateAddOn = "explorer"; 213 session.putValue("newProjectCallingFrom", fileToGo); 214 xmlTemplateDocument.setData("pathCorrection",""); 215 xmlTemplateDocument.setData("backButton",lasturl); 216 xmlTemplateDocument.setData("myUrl","resource_to_project.html"); 217 xmlTemplateDocument.setData("dontDoIt", " //"); 218 xmlTemplateDocument.setData("doThis","addFolder(document.PROJECTNEW.new_ressources,'"+fileToGo+"');"); 220 if (newName == null){ 221 newName = getProjectName(cms,fileToGo); 222 } 223 }else{ 224 xmlTemplateDocument.setData("pathCorrection","../../"); 226 xmlTemplateDocument.setData("backButton","../../../action/administration_content_top.html?sender=" + CmsWorkplace.VFS_PATH_WORKPLACE + "administration/project/"); 227 xmlTemplateDocument.setData("myUrl","index.html"); 228 xmlTemplateDocument.setData("dontDoIt", ""); 229 xmlTemplateDocument.setData("doThis",""); 230 } 231 232 xmlTemplateDocument.setData("onlineId", "" + CmsProject.ONLINE_PROJECT_ID); 233 234 newGroup = (String )parameters.get(CmsWorkplaceDefault.C_PROJECTNEW_GROUP); 235 newDescription = (String )parameters.get(CmsWorkplaceDefault.C_PROJECTNEW_DESCRIPTION); 236 newManagerGroup = (String )parameters.get(CmsWorkplaceDefault.C_PROJECTNEW_MANAGERGROUP); 237 String allResources = (String )parameters.get(C_NEWRESOURCES); 238 String allChannels = (String )parameters.get(C_NEWCHANNELS); 239 newType = (String )parameters.get(C_NEWTYPE); 240 241 if(newGroup == null) { 243 newGroup = (String )session.getValue(C_NEWGROUP); 244 } 245 if(newDescription == null) { 246 newDescription = (String )session.getValue(C_NEWDESCRIPTION); 247 } 248 if(newManagerGroup == null) { 249 newManagerGroup = (String )session.getValue(C_NEWMANAGERGROUP); 250 } 251 if(allResources == null) { 252 allResources = (String )session.getValue(C_NEWRESOURCES); 253 } 254 if(allChannels == null) { 255 allChannels = (String )session.getValue(C_NEWCHANNELS); 256 } 257 if(newType == null) { 258 newType = (String )session.getValue(C_NEWTYPE); 259 } 260 if(newName == null) { 261 newName = ""; 262 } 263 if(newGroup == null) { 264 newGroup = ""; 265 } 266 if(newDescription == null) { 267 newDescription = ""; 268 } 269 if(newManagerGroup == null) { 270 newManagerGroup = ""; 271 } 272 if(allResources == null) { 273 allResources = ""; 274 } 275 if(allChannels == null) { 276 allChannels = ""; 277 } 278 if(newType == null || "".equals(newType)) { 279 projectType = CmsProject.PROJECT_TYPE_NORMAL; 280 newType = ""; 281 } else { 282 projectType = CmsProject.PROJECT_TYPE_TEMPORARY; 283 } 284 285 if(parameters.get("submitform") != null) { 286 session.putValue(C_NEWNAME, newName); 288 session.putValue(C_NEWGROUP, newGroup); 289 session.putValue(C_NEWDESCRIPTION, newDescription); 290 session.putValue(C_NEWMANAGERGROUP, newManagerGroup); 291 session.putValue(C_NEWTYPE, newType); 292 session.putValue(C_NEWCHANNELS, allChannels); 293 if(newName.equals("") || newGroup.equals("") || newManagerGroup.equals("") 294 || (allResources.equals("") && allChannels.equals(""))) { 295 templateSelector = "datamissing"+errorTemplateAddOn; 296 } 297 else { 298 session.putValue(C_NEWRESOURCES, allResources); 299 templateSelector = "wait"; 301 action = "start"; 302 } 303 } 304 305 if("working".equals(action)) { 307 try { 309 String picspath = getConfigFile(cms).getPicGalleryPath(); 311 String downloadpath = getConfigFile(cms).getDownGalleryPath(); 312 String linkpath = getConfigFile(cms).getLinkGalleryPath(); 313 String htmlPath = getConfigFile(cms).getHtmlGalleryPath(); 314 allResources = allResources + ";" + picspath + ";" 315 + downloadpath + ";" + linkpath + ";" + htmlPath; 316 Vector folders = parseResources(allResources); 319 int numRes = folders.size(); 320 for(int i = 0;i < numRes;i++) { 321 if(lang.getLanguageValue("title.rootfolder").equals(folders.elementAt(i))) { 324 folders.setElementAt("/", i); 325 } 326 } 327 checkRedundancies(folders); 328 numRes = folders.size(); Vector channels = parseResources(allChannels); 331 int numChan = channels.size(); 332 for(int j = 0;j < numChan;j++) { 333 if(lang.getLanguageValue("title.rootfolder").equals(channels.elementAt(j))) { 336 channels.setElementAt("/", j); 337 } 338 } 339 checkRedundancies(channels); 340 numChan = channels.size(); 341 CmsProject project = cms.createProject(newName, newDescription, newGroup, 343 newManagerGroup, projectType); 344 reqCont.setCurrentProject(project); 346 try { 348 for(int i = 0;i < folders.size();i++) { 349 cms.copyResourceToProject((String )folders.elementAt(i)); 350 } 351 cms.getRequestContext().saveSiteRoot(); 353 cms.getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS); 354 for(int j = 0; j < channels.size(); j++){ 355 cms.copyResourceToProject((String )channels.elementAt(j)); 356 } 357 cms.getRequestContext().restoreSiteRoot(); 358 } catch(CmsException e) { 359 cms.getRequestContext().restoreSiteRoot(); 360 List projectResources = cms.readProjectResources(project); 362 if(projectResources == null || projectResources == Collections.EMPTY_LIST || projectResources.size() == 0){ 363 cms.deleteProject(project.getId()); 364 reqCont.setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID)); 365 } 366 if(CmsLog.getLog(this).isWarnEnabled() ) { 367 CmsLog.getLog(this).warn(e.getMessage(), e); 368 } 369 throw e; 370 } 371 session.removeValue(C_NEWNAME); 373 session.removeValue(C_NEWGROUP); 374 session.removeValue(C_NEWDESCRIPTION); 375 session.removeValue(C_NEWMANAGERGROUP); 376 session.removeValue(C_NEWFOLDER); 377 session.removeValue(C_NEWTYPE); 378 session.removeValue(C_NEWRESOURCES); 379 session.removeValue(C_NEWCHANNELS); 380 session.removeValue("lasturl"); 381 session.removeValue("newProjectCallingFrom"); 382 return startProcessing(cms, xmlTemplateDocument, elementName, parameters, "done"); 383 } catch(CmsException exc) { 384 xmlTemplateDocument.setData("details", CmsException.getStackTraceAsString(exc)); 385 templateSelector = "errornewproject"+errorTemplateAddOn; 386 } 387 } 388 xmlTemplateDocument.setData(C_NEWNAME, newName); 390 xmlTemplateDocument.setData(C_NEWDESCRIPTION, newDescription); 391 xmlTemplateDocument.setData(C_NEWTYPE, newType); 392 393 return startProcessing(cms, xmlTemplateDocument, elementName, parameters, 395 templateSelector); 396 } 397 398 412 413 public Integer getGroups(CmsObject cms, CmsXmlLanguageFile lang, Vector names, 414 Vector values, Hashtable parameters) throws CmsException { 415 416 List groups = cms.getGroups(); 418 int retValue = -1; 419 String defaultGroup = OpenCms.getDefaultUsers().getGroupUsers(); 420 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 421 String enteredGroup = (String )session.getValue(C_NEWGROUP); 422 if(enteredGroup != null && !enteredGroup.equals("")) { 423 424 defaultGroup = enteredGroup; 426 } 427 428 int n = 0; 430 for(int z = 0;z < groups.size();z++) { 431 if(((CmsGroup)groups.get(z)).getProjectCoWorker()) { 432 String name = ((CmsGroup)groups.get(z)).getName(); 433 if(defaultGroup.equals(name)) { 434 retValue = n; 435 } 436 names.addElement(name); 437 values.addElement(name); 438 n++; } 440 } 441 return new Integer (retValue); 442 } 443 444 458 459 public Integer getManagerGroups(CmsObject cms, CmsXmlLanguageFile lang, Vector names, 460 Vector values, Hashtable parameters) throws CmsException { 461 462 List groups = cms.getGroups(); 464 int retValue = -1; 465 String defaultGroup = OpenCms.getDefaultUsers().getGroupProjectmanagers(); 466 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 467 String enteredGroup = (String )session.getValue(C_NEWMANAGERGROUP); 468 if(enteredGroup != null && !enteredGroup.equals("")) { 469 470 defaultGroup = enteredGroup; 472 } 473 474 int n = 0; 476 for(int z = 0;z < groups.size();z++) { 477 if(((CmsGroup)groups.get(z)).getProjectManager()) { 478 String name = ((CmsGroup)groups.get(z)).getName(); 479 if(defaultGroup.equals(name)) { 480 retValue = n; 481 } 482 names.addElement(name); 483 values.addElement(name); 484 n++; } 486 } 487 return new Integer (retValue); 488 } 489 490 public Integer getSelectedResources(CmsObject cms, CmsXmlLanguageFile lang, Vector names, 491 Vector values, Hashtable parameters) throws CmsException { 492 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 493 String [] newProjectResources = (String [])session.getValue(C_NEWRESOURCES); 494 if(newProjectResources != null) { 495 for(int i = 0;i < newProjectResources.length;i++) { 496 names.addElement(newProjectResources[i]); 497 values.addElement(newProjectResources[i]); 498 } 499 } 500 501 return new Integer (-1); 503 } 504 505 515 516 public boolean isCacheable(CmsObject cms, String templateFile, String elementName, 517 Hashtable parameters, String templateSelector) { 518 return false; 519 } 520 521 526 527 private Vector parseResources(String resources) { 528 Vector ret = new Vector (); 529 if(resources != null) { 530 StringTokenizer resTokenizer = new StringTokenizer (resources, ";"); 531 while(resTokenizer.hasMoreElements()) { 532 String path = (String )resTokenizer.nextElement(); 533 ret.addElement(path); 534 } 535 } 536 return ret; 537 } 538 539 545 546 private String getProjectName(CmsObject cms, String resource) { 547 String ret = resource; 548 if (ret.endsWith("/")){ 549 ret = ret.substring(0, ret.length()-1); 550 } 551 ret = ret.substring(ret.lastIndexOf('/')+1); 552 if (ret.length() > 14){ 553 ret = ret.substring(0,13); 554 } 555 try{ 556 Vector allProjects = new Vector (cms.getAllAccessibleProjects()); 557 Vector theNames = new Vector (); 558 int count = 0; 560 for (int i = 0; i < allProjects.size(); i++){ 561 String currProject = ((CmsProject)allProjects.elementAt(i)).getName(); 562 if (currProject.startsWith(ret)){ 563 count++; 564 theNames.addElement(currProject); 565 } 566 } 567 if ((count > 0) && (count < 99)){ 568 int version = 1; 570 for (int i = 0; i<theNames.size(); i++){ 571 int currVersion = 0; 572 try{ 573 currVersion = Integer.parseInt(((String )theNames.elementAt(i)).substring(ret.length()+1)); 574 }catch(Exception e){ 575 } 576 if ((currVersion > version)&& (currVersion < 100)){ 577 version = currVersion; 578 } 579 } 580 if (version < 99){ 581 ret = ret + "_" + (version + 1); 582 } 583 } 584 }catch(CmsException e){ 585 } 586 return ret; 587 } 588 } 589
| Popular Tags
|