1 23 24 package org.infoglue.cms.controllers.kernel.impl.simple; 25 26 import java.util.ArrayList ; 27 import java.util.Collections ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 32 import org.apache.log4j.Logger; 33 import org.exolab.castor.jdo.Database; 34 import org.infoglue.cms.entities.content.ContentVO; 35 import org.infoglue.cms.entities.content.ContentVersion; 36 import org.infoglue.cms.entities.kernel.BaseEntityVO; 37 import org.infoglue.cms.entities.management.Language; 38 import org.infoglue.cms.exception.Bug; 39 import org.infoglue.cms.exception.SystemException; 40 import org.infoglue.cms.util.sorters.ContentComparator; 41 import org.infoglue.deliver.util.CacheController; 42 43 48 49 public class ComponentController extends BaseController 50 { 51 private final static Logger logger = Logger.getLogger(ComponentController.class.getName()); 52 53 56 57 public static ComponentController getController() 58 { 59 return new ComponentController(); 60 } 61 62 69 70 public List getComponentVOList(String sortAttribute, String direction, String [] allowedComponentNames) throws SystemException, Bug, Exception 71 { 72 List componentVOList = null; 73 74 Database db = CastorDatabaseService.getDatabase(); 75 try 76 { 77 beginTransaction(db); 78 79 componentVOList = getComponentVOList(sortAttribute, direction, allowedComponentNames, db); 80 81 commitTransaction(db); 82 } 83 catch ( Exception e ) 84 { 85 e.printStackTrace(); 86 rollbackTransaction(db); 87 throw new SystemException("An error occurred when we tried to fetch a list of users in this group. Reason:" + e.getMessage(), e); 88 } 89 90 return componentVOList; 91 } 92 93 100 101 private static List cachedComponents = null; 102 103 public List getComponentVOList(String sortAttribute, String direction, String [] allowedComponentNames, Database db) throws SystemException, Bug, Exception 104 { 105 String allowedComponentNamesString = ""; 106 if(allowedComponentNames != null) 107 { 108 for(int i=0; i<allowedComponentNames.length; i++) 109 allowedComponentNamesString = allowedComponentNames[i] + ":"; 110 } 111 112 String componentsKey = "components_" + sortAttribute + "_" + direction + "_" + allowedComponentNamesString; 113 List components = (List )CacheController.getCachedObject("componentContentsCache", componentsKey); 114 if(components != null) 115 { 116 logger.info("There was cached components:" + components.size()); 117 } 118 else 119 { 120 components = getComponents(allowedComponentNames); 121 Iterator componentsIterator = components.iterator(); 122 while(componentsIterator.hasNext()) 123 { 124 ContentVO contentVO = (ContentVO)componentsIterator.next(); 125 126 Language masterLanguage = LanguageController.getController().getMasterLanguage(db, contentVO.getRepositoryId()); 127 ContentVersion contentVersion = ContentVersionController.getContentVersionController().getLatestActiveContentVersion(contentVO.getId(), masterLanguage.getId(), db); 128 129 String groupName = "Unknown"; 130 131 if(contentVersion != null) 132 { 133 groupName = ContentVersionController.getContentVersionController().getAttributeValue(contentVersion.getValueObject(), "GroupName", false); 134 } 135 136 contentVO.getExtraProperties().put("GroupName", groupName); 137 } 138 139 CacheController.cacheObject("componentContentsCache", componentsKey, components); 140 } 141 142 ContentComparator comparator = new ContentComparator(sortAttribute, direction, null); 143 Collections.sort(components, comparator); 144 145 return components; 146 } 147 148 149 152 153 public List getComponents(String [] allowedComponentNames) throws Exception 154 { 155 HashMap arguments = new HashMap (); 156 arguments.put("method", "selectListOnContentTypeName"); 157 158 List argumentList = new ArrayList (); 159 HashMap argument = new HashMap (); 160 argument.put("contentTypeDefinitionName", "HTMLTemplate"); 161 argumentList.add(argument); 162 arguments.put("arguments", argumentList); 163 164 List results = ContentController.getContentController().getContentVOList(arguments); 165 166 if(allowedComponentNames != null && allowedComponentNames.length > 0) 167 { 168 Iterator resultsIterator = results.iterator(); 169 while(resultsIterator.hasNext()) 170 { 171 ContentVO contentVO = (ContentVO)resultsIterator.next(); 172 boolean isAllowed = false; 173 for(int i=0; i<allowedComponentNames.length; i++) 174 { 175 if(contentVO.getName().equals(allowedComponentNames[i])) 176 isAllowed = true; 177 } 178 179 if(!isAllowed) 180 resultsIterator.remove(); 181 } 182 } 183 184 return results; 185 } 186 187 190 public BaseEntityVO getNewVO() 191 { 192 return null; 193 } 194 195 196 } 197 | Popular Tags |