1 28 29 30 package com.opencms.workplace; 31 32 import org.opencms.file.CmsBackupProject; 33 import org.opencms.file.CmsObject; 34 import org.opencms.i18n.CmsEncoder; 35 import org.opencms.main.CmsException; 36 import org.opencms.util.CmsDateUtil; 37 import org.opencms.workplace.CmsWorkplace; 38 39 import com.opencms.legacy.CmsLegacyException; 40 import com.opencms.template.A_CmsXmlContent; 41 42 import java.lang.reflect.InvocationTargetException ; 43 import java.lang.reflect.Method ; 44 import java.util.ArrayList ; 45 import java.util.Hashtable ; 46 import java.util.List ; 47 48 import org.w3c.dom.Element ; 49 50 60 61 public class CmsProjecthistory extends A_CmsWpElement { 62 63 66 private static final String C_PROJECT_UNLOCK = "project_unlock"; 67 68 85 86 public Object handleSpecialWorkplaceTag(CmsObject cms, Element n, A_CmsXmlContent doc, Object callingObject, 87 Hashtable parameters, CmsXmlLanguageFile lang) throws CmsException { 88 89 String listMethod = n.getAttribute(CmsWorkplaceDefault.C_PROJECTLIST_METHOD); 91 92 CmsXmlWpTemplateFile listdef = getProjectlistDefinitions(cms); 94 95 Method callingMethod = null; 97 List list = new ArrayList (); 98 try { 99 callingMethod = callingObject.getClass().getMethod(listMethod, new Class [] { 100 CmsObject.class, CmsXmlLanguageFile.class 101 }); 102 list = (List )callingMethod.invoke(callingObject, new Object [] { 103 cms, lang 104 }); 105 } 106 catch(NoSuchMethodException exc) { 107 108 throwException("Could not find method " + listMethod + " in calling class " 110 + callingObject.getClass().getName() + " for generating projectlist content.", 111 CmsLegacyException.C_NOT_FOUND); 112 } 113 catch(InvocationTargetException targetEx) { 114 115 Throwable e = targetEx.getTargetException(); 118 if(!(e instanceof CmsException)) { 119 120 throwException("User method " + listMethod + " in calling class " 122 + callingObject.getClass().getName() + " throwed an exception. " 123 + e); 124 } 125 else { 126 127 throw (CmsException)e; 130 } 131 } 132 catch(Exception exc2) { 133 throwException("User method " + listMethod + " in calling class " 134 + callingObject.getClass().getName() + " was found but could not be invoked. " 135 + exc2, CmsLegacyException.C_XML_NO_USER_METHOD); 136 } 137 138 139 StringBuffer result = new StringBuffer (); 140 listdef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_PROJECTLIST_SNAPLOCK, callingObject, parameters); 141 for(int i = 0;i < list.size();i++) { 142 143 CmsBackupProject project = (CmsBackupProject)list.get(i); 145 146 setListEntryData(cms, lang, listdef, project); 148 listdef.setData(CmsWorkplaceDefault.C_PROJECTLIST_LOCKSTATE, ""); 149 listdef.setData(CmsWorkplaceDefault.C_PROJECTLIST_MENU, C_PROJECT_UNLOCK); 150 151 listdef.setData(CmsWorkplaceDefault.C_PROJECTLIST_IDX, new Integer (i).toString()); 152 result.append(listdef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_PROJECTLIST_DEFAULT, callingObject, 153 parameters)); 154 } 155 return result.toString(); 156 } 157 158 168 169 public boolean isCacheable(CmsObject cms, String templateFile, String elementName, 170 Hashtable parameters, String templateSelector) { 171 return false; 172 } 173 174 182 183 public static void setListEntryData(CmsObject cms, CmsXmlLanguageFile lang, 184 CmsXmlWpTemplateFile xmlFile, CmsBackupProject project) throws CmsException { 185 186 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_NAME, project.getName()); 187 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_DESCRIPTION, project.getDescription()); 188 List resources = project.getProjectResources(); 190 String reslist = new String (); 191 for(int i=0; i < resources.size(); i++){ 192 reslist = reslist+(String )resources.get(i); 193 if(i < (resources.size()-1)){ 194 reslist = reslist+"<br>"; 195 } 196 } 197 xmlFile.setData("resources", reslist); 198 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_PROJECTWORKER, project.getGroupName()); 199 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_PROJECTMANAGER, project.getManagerGroupName()); 200 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_DATECREATED, CmsDateUtil.getDateTimeShort(project.getDateCreated())); 201 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_OWNER, project.getOwnerName()); 202 xmlFile.setData("publishdate", CmsDateUtil.getDateTimeShort(project.getPublishingDate())); 203 xmlFile.setData("publishedby", project.getPublishedByName()); 204 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_NAME_ESCAPED, CmsEncoder.escape(project.getName(), 205 cms.getRequestContext().getEncoding())); 206 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_PROJECTID, project.getId() + ""); 207 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_STATE, lang.getLanguageValue(CmsWorkplaceDefault.C_PROJECTLIST_STATE_UNLOCKED)); 208 } 209 210 216 217 public CmsXmlWpTemplateFile getProjectlistDefinitions(CmsObject cms) throws CmsException { 218 String templatePath = CmsWorkplace.VFS_PATH_WORKPLACE + "administration/project/historyprojects/"; 219 m_projectlistdef = new CmsXmlWpTemplateFile(cms, templatePath+"projectlist"); 220 return m_projectlistdef; 221 } 222 } 223
| Popular Tags
|