1 23 24 package org.infoglue.cms.treeservice.ss; 25 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.Collections ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 32 import org.apache.log4j.Logger; 33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController; 34 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy; 35 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController; 36 import org.infoglue.cms.entities.content.ContentVO; 37 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO; 38 import org.infoglue.cms.exception.ConstraintException; 39 import org.infoglue.cms.exception.SystemException; 40 import org.infoglue.cms.security.InfoGluePrincipal; 41 import org.infoglue.cms.util.CmsPropertyHandler; 42 import org.infoglue.cms.util.sorters.ReflectionComparator; 43 44 import com.frovi.ss.Tree.BaseNode; 45 import com.frovi.ss.Tree.BaseNodeSupplier; 46 47 53 54 public class ContentNodeSupplier extends BaseNodeSupplier 55 { 56 private final static Logger logger = Logger.getLogger(ContentNodeSupplier.class.getName()); 57 58 private ArrayList cacheLeafs; 59 private boolean showLeafs = true; 60 private String [] allowedContentTypeIds = null; 61 private InfoGluePrincipal infogluePrincipal = null; 62 63 public ContentNodeSupplier(Integer repositoryId, InfoGluePrincipal infogluePrincipal) throws SystemException 64 { 65 ContentVO vo =null; 66 try 67 { 68 this.infogluePrincipal = infogluePrincipal; 69 70 vo = ContentControllerProxy.getController().getRootContentVO(repositoryId, infogluePrincipal.getName()); 71 BaseNode rootNode = new ContentNodeImpl(); 72 rootNode.setChildren(true); 73 rootNode.setId(vo.getId()); 74 rootNode.setTitle(vo.getName()); 75 rootNode.setContainer(vo.getIsBranch().booleanValue()); 76 77 setRootNode(rootNode); 78 } 79 catch (ConstraintException e) 80 { 81 e.printStackTrace(); 82 } 83 84 } 85 88 public boolean hasChildren() 89 { 90 if (showLeafs) 91 return false; 92 else 93 return true; 94 } 95 96 99 public Collection getChildContainerNodes(Integer parentNode) 100 { 101 ArrayList ret = new ArrayList (); 102 cacheLeafs = new ArrayList (); 103 104 List children = null; 105 try 106 { 107 children = ContentController.getContentController().getContentChildrenVOList(parentNode); 108 } 109 catch (ConstraintException e) 110 { 111 logger.warn("Error getting Content Children", e); 112 } 113 catch (SystemException e) 114 { 115 logger.warn("Error getting Content Children", e); 116 } 117 118 try 120 { 121 if(allowedContentTypeIds != null) 122 { 123 List filteredList = new ArrayList (); 124 Iterator iterator = children.iterator(); 125 while(iterator.hasNext()) 126 { 127 ContentVO contentVO = (ContentVO) iterator.next(); 128 if(contentVO.getContentTypeDefinitionId() != null && !contentVO.getIsBranch().booleanValue()) 129 { 130 ContentTypeDefinitionVO contentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(contentVO.getContentTypeDefinitionId()); 131 boolean exists = false; 132 for(int i=0; i<allowedContentTypeIds.length; i++) 133 { 134 String allowedId = allowedContentTypeIds[i]; 135 136 if(allowedId.equalsIgnoreCase(contentTypeDefinitionVO.getId().toString())) 137 { 138 exists = true; 139 break; 140 } 141 } 142 143 if(exists) 144 { 145 filteredList.add(contentVO); 146 } 147 } 148 else 149 { 150 filteredList.add(contentVO); 151 } 152 } 153 154 children = filteredList; 155 } 156 } 157 catch(Exception e) 158 { 159 logger.warn("Error filtering Content Children", e); 160 } 161 162 String sortProperty = CmsPropertyHandler.getContentTreeSort(); 164 if(sortProperty != null) 165 Collections.sort(children, new ReflectionComparator(sortProperty)); 166 167 Iterator i = children.iterator(); 168 while(i.hasNext()) 169 { 170 ContentVO vo = (ContentVO) i.next(); 171 172 if(!vo.getName().equals("Meta info folder") || this.infogluePrincipal.getIsAdministrator()) 173 { 174 BaseNode node = new ContentNodeImpl(); 175 node.setId(vo.getId()); 176 node.setTitle(vo.getName()); 177 178 if (vo.getIsBranch().booleanValue()) 179 { 180 node.setContainer(true); 181 node.setChildren((vo.getChildCount().intValue() > 0)); 182 183 ret.add(node); 184 } 185 else if(showLeafs) 186 { 187 node.setContainer(false); 188 189 cacheLeafs.add(node); 190 } 191 } 192 } 193 194 return ret; 195 } 196 197 200 public Collection getChildLeafNodes(Integer parentNode) 201 { 202 return (cacheLeafs == null ) ? new ArrayList () : cacheLeafs; 203 } 204 205 209 public void setShowLeafs(boolean showLeafs) 210 { 211 this.showLeafs = showLeafs; 212 } 213 214 public String [] getAllowedContentTypeIds() 215 { 216 return allowedContentTypeIds; 217 } 218 219 public void setAllowedContentTypeIds(String [] allowedContentTypeIds) 220 { 221 this.allowedContentTypeIds = allowedContentTypeIds; 222 } 223 } 224 | Popular Tags |