1 28 29 30 package com.opencms.workplace; 31 32 import org.opencms.file.CmsFile; 33 import org.opencms.file.CmsFolder; 34 import org.opencms.file.CmsObject; 35 import org.opencms.file.CmsPropertyDefinition; 36 import org.opencms.file.CmsResource; 37 import org.opencms.file.CmsVfsResourceNotFoundException; 38 import org.opencms.main.CmsException; 39 import org.opencms.main.CmsLog; 40 import org.opencms.security.CmsPermissionSet; 41 import org.opencms.security.CmsSecurityException; 42 import org.opencms.workplace.CmsWorkplace; 43 44 import com.opencms.core.I_CmsSession; 45 import com.opencms.legacy.CmsLegacyException; 46 import com.opencms.legacy.CmsXmlTemplateLoader; 47 import com.opencms.template.CmsTemplateClassManager; 48 import com.opencms.template.CmsXmlTemplateFile; 49 50 import java.lang.reflect.InvocationTargetException ; 51 import java.lang.reflect.Method ; 52 import java.util.ArrayList ; 53 import java.util.Hashtable ; 54 import java.util.List ; 55 import java.util.Map ; 56 57 66 67 public class CmsAdministration extends CmsWorkplaceDefault { 68 69 82 83 private String generateIcon(CmsObject cms, CmsXmlTemplateFile templateDocument, Hashtable parameters, 84 CmsXmlLanguageFile lang, String picName, String sender, String languageKey, 85 String iconActiveMethod, String iconVisibleMethod, String accessVisible) throws CmsException { 86 87 boolean hasAccessVisible = (new Boolean (accessVisible)).booleanValue(); 88 String iconPicPath = (String )resourcesUri(cms, "", null, null); 89 if(sender.startsWith(CmsWorkplace.VFS_PATH_SYSTEM + "modules")) { 91 if (picName.startsWith("/")) { 92 iconPicPath = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getServletUrl() + sender.substring(0, sender.indexOf("/administration/")); 93 } 94 else { 95 iconPicPath = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getServletUrl() + sender.substring(0, sender.indexOf("administration/")) + "pics/"; 96 } 97 } 98 99 boolean activate = true; 101 if(iconActiveMethod != null && !"".equals(iconActiveMethod)) { 102 String className = iconActiveMethod.substring(0, iconActiveMethod.lastIndexOf(".")); 103 iconActiveMethod = iconActiveMethod.substring(iconActiveMethod.lastIndexOf(".") + 1); 104 Method groupsMethod = null; 105 try { 106 Object o = CmsTemplateClassManager.getClassInstance(className); 107 groupsMethod = o.getClass().getMethod(iconActiveMethod, new Class [] { 108 CmsObject.class, CmsXmlLanguageFile.class, Hashtable .class 109 }); 110 activate = ((Boolean )groupsMethod.invoke(o, new Object [] { 111 cms, lang, parameters 112 })).booleanValue(); 113 114 } 115 catch(NoSuchMethodException exc) { 116 117 throwException("Could not find icon activation method " + iconActiveMethod 119 + " in calling class " + className + " for generating icon.", CmsLegacyException.C_NOT_FOUND); 120 } 121 catch(InvocationTargetException targetEx) { 122 123 Throwable e = targetEx.getTargetException(); 126 if(!(e instanceof CmsException)) { 127 128 throwException("Icon activation method " + iconActiveMethod + " in calling class " 129 + className + " throwed an exception. " + e, CmsLegacyException.C_UNKNOWN_EXCEPTION); 130 } 131 else { 132 133 throw (CmsException)e; 136 } 137 } 138 catch(Exception exc2) { 139 throwException("Icon activation method " + iconActiveMethod + " in calling class " 140 + className + " was found but could not be invoked. " + exc2, CmsLegacyException.C_UNKNOWN_EXCEPTION); 141 } 142 } 143 144 boolean visible = true; 146 if(iconVisibleMethod != null && !"".equals(iconVisibleMethod)) { 147 String className = iconVisibleMethod.substring(0, iconVisibleMethod.lastIndexOf(".")); 148 iconVisibleMethod = iconVisibleMethod.substring(iconVisibleMethod.lastIndexOf(".") + 1); 149 Method groupsMethod = null; 150 try { 151 Object o = CmsTemplateClassManager.getClassInstance(className); 152 groupsMethod = o.getClass().getMethod(iconVisibleMethod, new Class [] { 153 CmsObject.class, CmsXmlLanguageFile.class, Hashtable .class 154 }); 155 visible = ((Boolean )groupsMethod.invoke(o, new Object [] { 156 cms, lang, parameters 157 })).booleanValue(); 158 } 159 catch(NoSuchMethodException exc) { 160 161 throwException("Could not find icon activation method " + iconVisibleMethod 163 + " in calling class " + className + " for generating icon.", CmsLegacyException.C_NOT_FOUND); 164 } 165 catch(InvocationTargetException targetEx) { 166 167 169 Throwable e = targetEx.getTargetException(); 171 if(!(e instanceof CmsException)) { 172 173 throwException("Icon activation method " + iconVisibleMethod + " in calling class " 174 + className + " throwed an exception. " + e); 175 } 176 else { 177 178 180 throw (CmsException)e; 182 } 183 } 184 catch(Exception exc2) { 185 throwException("Icon activation method " + iconVisibleMethod + " in calling class " 186 + className + " was found but could not be invoked. " + exc2); 187 } 188 } 189 templateDocument.setData("linkTo", CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getServletUrl() + CmsWorkplace.VFS_PATH_WORKPLACE 190 + "action/administration_content_top.html?sender=" + sender); 191 StringBuffer iconLabelBuffer = new StringBuffer (lang.getLanguageValue(languageKey)); 192 193 if(iconLabelBuffer.toString().indexOf("- ") != -1) { 195 iconLabelBuffer.insert(iconLabelBuffer.toString().indexOf("- ") + 1, "<BR>"); 196 } 197 templateDocument.setData("linkName", iconLabelBuffer.toString()); 198 if(visible && hasAccessVisible) { 199 if(activate) { 200 templateDocument.setData("picture", iconPicPath + picName + ".gif"); 201 return templateDocument.getProcessedDataValue("defaulticon"); 202 } 203 else { 204 templateDocument.setData("picture", iconPicPath + picName + "_in.gif"); 205 return templateDocument.getProcessedDataValue("deactivatedicon"); 206 } 207 } 208 else { 209 return templateDocument.getProcessedDataValue("noicon"); 210 } 211 } 213 224 225 public byte[] getContent(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 226 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 227 CmsXmlWpTemplateFile templateDocument = new CmsXmlWpTemplateFile(cms, templateFile); 228 CmsXmlLanguageFile lang = templateDocument.getLanguageFile(); 229 String navPos = (String )session.getValue(com.opencms.core.I_CmsConstants.C_SESSION_ADMIN_POS); 230 templateDocument.setData("emptyPic", (String )resourcesUri(cms, "empty.gif", null, null)); 231 CmsXmlWpConfigFile confFile = new CmsXmlWpConfigFile(cms); 232 String sentBy = (String )parameters.get("sender"); 233 234 if(sentBy == null) { 235 if(navPos == null) { 236 sentBy = confFile.getWorkplaceAdministrationPath(); 237 } 238 else { 239 if(!navPos.endsWith("/")) { 240 navPos = navPos.substring(0, navPos.indexOf("/") + 1); 241 } 242 sentBy = navPos; 243 } 244 } 245 246 if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) { 247 CmsLog.getLog(this).debug("Getting content of element " 248 + ((elementName == null) ? "<root>" : elementName)); 249 CmsLog.getLog(this).debug("Template file is: " + templateFile); 250 CmsLog.getLog(this).debug("Selected template section is: " 251 + ((templateSelector == null) ? "<default>" : templateSelector)); 252 CmsLog.getLog(this).debug("SentBy: " + sentBy ); 253 } 254 255 List iconVector = (List ) new ArrayList (); 256 if(sentBy.endsWith("/administration/")) { 257 258 sentBy = confFile.getWorkplaceAdministrationPath(); 260 iconVector = cms.getSubFolders(sentBy); 261 List modules = (List ) new ArrayList (); 262 263 modules = cms.getSubFolders(CmsWorkplace.VFS_PATH_MODULES); 264 265 for(int i = 0;i < modules.size();i++) { 266 List moduleAdminPoints = (List ) new ArrayList (); 267 String dummy = cms.getSitePath((CmsFolder)modules.get(i)); 268 dummy += "administration/"; 269 try { 270 moduleAdminPoints = cms.getSubFolders(dummy); 271 } catch (CmsVfsResourceNotFoundException e) { 272 continue; 274 } catch (CmsSecurityException e1) { 275 } 277 for(int j = 0;j < moduleAdminPoints.size();j++) { 278 CmsFolder currentModuleAdminFolder = (CmsFolder) moduleAdminPoints.get(j); 279 iconVector.add(currentModuleAdminFolder); 280 } 282 } 283 } 284 else { 285 iconVector = cms.getSubFolders(sentBy); 286 } 287 session.putValue(com.opencms.core.I_CmsConstants.C_SESSION_ADMIN_POS, sentBy); 288 List iconVector2 = cms.getFilesInFolder(sentBy); 289 int numFolders = iconVector.size(); 290 if(numFolders > 0) { 291 String iconNames[] = new String [numFolders]; 292 int index[] = new int[numFolders]; 293 String folderTitles[] = new String [numFolders]; 294 String folderLangKeys[] = new String [numFolders]; 295 String folderPos[] = new String [numFolders]; 296 String folderVisible[] = new String [numFolders]; 297 String folderActiv[] = new String [numFolders]; 298 String accessVisible[] = new String [numFolders]; 299 for(int i = 0;i < numFolders;i++) { 300 CmsResource aktIcon = (CmsResource)iconVector.get(i); 301 try { 302 Map propertyinfos = cms.readProperties(cms.getSitePath(aktIcon)); 303 iconNames[i] = cms.getSitePath(aktIcon); 304 index[i] = i; 305 folderLangKeys[i] = getStringValue((String )propertyinfos.get(CmsPropertyDefinition.PROPERTY_NAVTEXT)); 306 folderTitles[i] = getStringValue((String )propertyinfos.get(CmsPropertyDefinition.PROPERTY_TITLE)); 307 folderPos[i] = getStringValue((String )propertyinfos.get(CmsPropertyDefinition.PROPERTY_NAVPOS)); 308 if(folderPos[i].equals("")) { 309 folderPos[i] = "101"; 310 } 311 folderVisible[i] = getStringValue((String )propertyinfos.get(org.opencms.file.CmsPropertyDefinition.PROPERTY_VISIBLE)); 312 folderActiv[i] = getStringValue((String )propertyinfos.get(org.opencms.file.CmsPropertyDefinition.PROPERTY_ACTIV)); 313 accessVisible[i] = new Boolean (checkVisible(cms, aktIcon)).toString(); 314 } catch(CmsSecurityException e) { 315 } catch(CmsException e) { 317 throw e; 318 } catch(Throwable t) { 319 throw new CmsLegacyException("[" + this.getClass().getName() + "] " 320 + t.getMessage(), CmsLegacyException.C_SQL_ERROR, t); 321 } 322 } sort(iconNames, index, folderPos, numFolders); 324 String completeTable = ""; 325 int element = 0; 326 int zeile = 0; 327 while(element < numFolders) { 328 String completeRow = ""; 329 while((element < numFolders)) { 331 int pos = index[element]; 332 if(iconNames[element] != null){ 333 completeRow += generateIcon(cms, templateDocument, parameters, lang, folderTitles[pos], 334 iconNames[element], folderLangKeys[pos], folderActiv[pos], folderVisible[pos], 335 accessVisible[pos]); 336 } 337 element++; 338 } 339 templateDocument.setData("entrys", completeRow); 340 completeTable += templateDocument.getProcessedDataValue("list_row"); 341 zeile++; 342 } templateDocument.setData("iconTable", completeTable); 344 } 345 else { 346 347 try { 349 CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendCmsRedirect(sentBy 350 + "index.html?initial=true"); 351 } 352 catch(Exception e) { 353 throw new CmsLegacyException("Redirect fails :" + cms.getSitePath((CmsFile)iconVector2.get(0)), 354 CmsLegacyException.C_UNKNOWN_EXCEPTION, e); 355 } 356 return null; 357 } 358 return startProcessing(cms, templateDocument, elementName, parameters, templateSelector); 359 } 360 361 367 368 private String getStringValue(String param) { 369 if(param == null) { 370 return ""; 371 } 372 return param; 373 } 374 375 385 386 public boolean isCacheable(CmsObject cms, String templateFile, String elementName, 387 Hashtable parameters, String templateSelector) { 388 return false; 389 } 390 391 398 399 private void sort(String [] filenames, int[] index, String [] positions, int max) { 400 401 try { 405 for(int i = max - 1;i > 0;i--) { 406 for(int j = 0;j < i;j++) { 407 float a = new Float (positions[j]).floatValue(); 408 float b = new Float (positions[j + 1]).floatValue(); 409 if(a > b) { 410 String tempfilename = filenames[j]; 411 int tempindex = index[j]; 412 String tempposition = positions[j]; 413 filenames[j] = filenames[j + 1]; 414 index[j] = index[j + 1]; 415 positions[j] = positions[j + 1]; 416 filenames[j + 1] = tempfilename; 417 index[j + 1] = tempindex; 418 positions[j + 1] = tempposition; 419 } 420 } 421 } 422 } 423 catch(Exception e) { 424 if(CmsLog.getLog(this).isWarnEnabled()){ 425 CmsLog.getLog(this).warn("Adminpoints unsorted cause I cant get a valid float value", e); 426 } 427 } 428 } 430 437 438 private boolean checkVisible(CmsObject cms, CmsResource resource) throws CmsException { 439 return cms.hasPermissions(resource, CmsPermissionSet.ACCESS_VIEW); 440 } 441 } 442
| Popular Tags
|