1 17 package org.alfresco.web.ui.repo.component; 18 19 import java.util.ArrayList ; 20 import java.util.Collection ; 21 import java.util.List ; 22 23 import javax.faces.context.FacesContext; 24 25 import org.alfresco.model.ContentModel; 26 import org.alfresco.repo.security.permissions.AccessDeniedException; 27 import org.alfresco.service.cmr.dictionary.DictionaryService; 28 import org.alfresco.service.cmr.repository.ChildAssociationRef; 29 import org.alfresco.service.cmr.repository.NodeRef; 30 import org.alfresco.service.cmr.repository.NodeService; 31 import org.alfresco.service.cmr.security.AccessStatus; 32 import org.alfresco.service.cmr.security.PermissionService; 33 import org.alfresco.service.namespace.RegexQNamePattern; 34 import org.alfresco.web.app.Application; 35 import org.alfresco.web.bean.repository.Repository; 36 import org.alfresco.web.ui.repo.WebResources; 37 38 41 public class UISpaceSelector extends AbstractItemSelector 42 { 43 46 49 public String getFamily() 50 { 51 return "org.alfresco.faces.SpaceSelector"; 52 } 53 54 58 public String getDefaultLabel() 59 { 60 return Application.getMessage(FacesContext.getCurrentInstance(), "select_space_prompt"); 61 } 62 63 69 public String getParentNodeId(FacesContext context) 70 { 71 String id = null; 72 73 if (this.navigationId != null && this.navigationId.equals(Application.getCompanyRootId()) == false) 74 { 75 try 76 { 77 ChildAssociationRef parentRef = getNodeService(context).getPrimaryParent( 78 new NodeRef(Repository.getStoreRef(), this.navigationId)); 79 id = parentRef.getParentRef().getId(); 80 } 81 catch (AccessDeniedException accessErr) 82 { 83 } 85 } 86 87 return id; 88 } 89 90 93 109 110 115 public Collection <NodeRef> getChildrenForNode(FacesContext context) 116 { 117 NodeRef nodeRef = new NodeRef(Repository.getStoreRef(), this.navigationId); 118 List <ChildAssociationRef> allKids = getNodeService(context).getChildAssocs(nodeRef, 119 ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL); 120 DictionaryService dd = getDictionaryService(context); 121 NodeService service = getNodeService(context); 122 123 List <NodeRef> spaceKids = new ArrayList <NodeRef>(); 125 for (ChildAssociationRef ref : allKids) 126 { 127 if (dd.isSubClass(service.getType(ref.getChildRef()), ContentModel.TYPE_FOLDER) && 128 dd.isSubClass(service.getType(ref.getChildRef()), ContentModel.TYPE_SYSTEM_FOLDER) == false) 129 { 130 spaceKids.add(ref.getChildRef()); 131 } 132 } 133 134 return spaceKids; 135 } 136 137 142 public Collection <NodeRef> getRootChildren(FacesContext context) 143 { 144 NodeRef rootRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId()); 145 146 PermissionService ps = Repository.getServiceRegistry(context).getPermissionService(); 149 if (ps.hasPermission(rootRef, PermissionService.READ) != AccessStatus.ALLOWED) 150 { 151 String homeId = Application.getCurrentUser(context).getHomeSpaceId(); 153 rootRef = new NodeRef(Repository.getStoreRef(), homeId); 154 } 155 List <NodeRef> roots = new ArrayList <NodeRef>(1); 156 roots.add(rootRef); 157 158 return roots; 159 } 160 161 164 public String getItemIcon() 165 { 166 return WebResources.IMAGE_SPACE; 167 } 168 } 169 | Popular Tags |