1 28 29 30 package com.opencms.workplace; 31 32 import org.opencms.file.CmsObject; 33 import org.opencms.file.CmsProject; 34 import org.opencms.i18n.CmsEncoder; 35 import org.opencms.main.CmsException; 36 import org.opencms.util.CmsDateUtil; 37 38 import com.opencms.legacy.CmsLegacyException; 39 import com.opencms.template.A_CmsXmlContent; 40 41 import java.lang.reflect.InvocationTargetException ; 42 import java.lang.reflect.Method ; 43 import java.util.Hashtable ; 44 import java.util.Vector ; 45 46 import org.w3c.dom.Element ; 47 48 58 59 public class CmsProjectlist extends A_CmsWpElement { 60 61 62 65 private static final String C_PROJECT_LOCK = "project_lock"; 66 67 68 71 private static final String C_PROJECT_UNLOCK = "project_unlock"; 72 73 90 91 public Object handleSpecialWorkplaceTag(CmsObject cms, Element n, A_CmsXmlContent doc, Object callingObject, 92 Hashtable parameters, CmsXmlLanguageFile lang) throws CmsException { 93 94 String listMethod = n.getAttribute(CmsWorkplaceDefault.C_PROJECTLIST_METHOD); 96 97 CmsXmlWpTemplateFile listdef = getProjectlistDefinitions(cms); 99 100 Method callingMethod = null; 102 Vector list = new Vector (); 103 try { 104 callingMethod = callingObject.getClass().getMethod(listMethod, new Class [] { 105 CmsObject.class, CmsXmlLanguageFile.class 106 }); 107 list = (Vector )callingMethod.invoke(callingObject, new Object [] { 108 cms, lang 109 }); 110 } 111 catch(NoSuchMethodException exc) { 112 113 throwException("Could not find method " + listMethod + " in calling class " 115 + callingObject.getClass().getName() + " for generating projectlist content.", 116 CmsLegacyException.C_NOT_FOUND); 117 } 118 catch(InvocationTargetException targetEx) { 119 120 Throwable e = targetEx.getTargetException(); 123 if(!(e instanceof CmsException)) { 124 125 throwException("User method " + listMethod + " in calling class " 127 + callingObject.getClass().getName() + " throwed an exception. " 128 + e); 129 } 130 else { 131 132 throw (CmsException)e; 135 } 136 } 137 catch(Exception exc2) { 138 throwException("User method " + listMethod + " in calling class " 139 + callingObject.getClass().getName() + " was found but could not be invoked. " 140 + exc2, CmsLegacyException.C_XML_NO_USER_METHOD); 141 } 142 143 144 StringBuffer result = new StringBuffer (); 145 String state = CmsWorkplaceDefault.C_PROJECTLIST_STATE_UNLOCKED; 146 String snaplock = listdef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_PROJECTLIST_SNAPLOCK, callingObject, parameters); 147 for(int i = 0;i < list.size();i++) { 148 149 CmsProject project = (CmsProject)list.elementAt(i); 151 152 if(cms.countLockedResources(project.getId()) == 0) { 154 state = CmsWorkplaceDefault.C_PROJECTLIST_STATE_UNLOCKED; 155 } 156 else { 157 state = CmsWorkplaceDefault.C_PROJECTLIST_STATE_LOCKED; 158 } 159 160 setListEntryData(cms, lang, listdef, project); 162 if(state.equals(CmsWorkplaceDefault.C_PROJECTLIST_STATE_UNLOCKED)) { 163 listdef.setData(CmsWorkplaceDefault.C_PROJECTLIST_LOCKSTATE, ""); 164 listdef.setData(CmsWorkplaceDefault.C_PROJECTLIST_MENU, C_PROJECT_UNLOCK); 165 } 166 else { 167 listdef.setData(CmsWorkplaceDefault.C_PROJECTLIST_LOCKSTATE, snaplock); 168 listdef.setData(CmsWorkplaceDefault.C_PROJECTLIST_MENU, C_PROJECT_LOCK); 169 } 170 listdef.setData(CmsWorkplaceDefault.C_PROJECTLIST_IDX, new Integer (i).toString()); 171 result.append(listdef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_PROJECTLIST_DEFAULT, callingObject, 172 parameters)); 173 } 174 return result.toString(); 175 } 176 177 187 188 public boolean isCacheable(CmsObject cms, String templateFile, String elementName, 189 Hashtable parameters, String templateSelector) { 190 return false; 191 } 192 193 201 202 public static void setListEntryData(CmsObject cms, CmsXmlLanguageFile lang, 203 CmsXmlWpTemplateFile xmlFile, CmsProject project) throws CmsException { 204 String state; 205 206 if(cms.countLockedResources(project.getId()) == 0) { 208 state = CmsWorkplaceDefault.C_PROJECTLIST_STATE_UNLOCKED; 209 } 210 else { 211 state = CmsWorkplaceDefault.C_PROJECTLIST_STATE_LOCKED; 212 } 213 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_NAME, project.getName()); 214 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_NAME_ESCAPED, CmsEncoder.escape(project.getName(), 215 cms.getRequestContext().getEncoding())); 216 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_PROJECTID, project.getId() + ""); 217 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_DESCRIPTION, project.getDescription()); 218 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_STATE, lang.getLanguageValue(state)); 219 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_PROJECTMANAGER, cms.readManagerGroup(project).getName()); 220 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_PROJECTWORKER, cms.readGroup(project).getName()); 221 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_DATECREATED, CmsDateUtil.getDateTimeShort(project.getDateCreated())); 222 xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_OWNER, cms.readOwner(project).getName()); 223 } 224 } 225 | Popular Tags |