KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > repo > component > UISpaceSelector


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.ui.repo.component;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.List JavaDoc;
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 /**
39  * @author Kevin Roast
40  */

41 public class UISpaceSelector extends AbstractItemSelector
42 {
43    // ------------------------------------------------------------------------------
44
// Component Impl
45

46    /**
47     * @see javax.faces.component.UIComponent#getFamily()
48     */

49    public String JavaDoc getFamily()
50    {
51       return "org.alfresco.faces.SpaceSelector";
52    }
53
54    /**
55     *
56     * @see org.alfresco.web.ui.repo.component.AbstractItemSelector#getDefaultLabel()
57     */

58    public String JavaDoc getDefaultLabel()
59    {
60       return Application.getMessage(FacesContext.getCurrentInstance(), "select_space_prompt");
61    }
62    
63    /**
64     * Returns the parent id of the current space or null if the parent space is an immediate child
65     * of the repository root node or the parent is inaccessable due to permissions.
66     *
67     * @see org.alfresco.web.ui.repo.component.AbstractItemSelector#getParentNodeId(javax.faces.context.FacesContext)
68     */

69    public String JavaDoc getParentNodeId(FacesContext context)
70    {
71       String JavaDoc 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             // cannot navigate to parent id will be null
84
}
85       }
86       
87       return id;
88    }
89    
90    /**
91     * @see org.alfresco.web.ui.repo.component.AbstractItemSelector#parentAccessable()
92     */

93    /*public boolean parentAccessable(FacesContext context)
94    {
95       boolean accessable = false;
96       try
97       {
98          ChildAssociationRef parentRef = getNodeService(context).getPrimaryParent(
99                new NodeRef(Repository.getStoreRef(), this.navigationId));
100          parentRef.getParentRef().getId();
101          accessable = true;
102       }
103       catch (AccessDeniedException accessErr)
104       {
105          // cannot navigate to parent id - not accessable
106       }
107       return accessable;
108    }*/

109
110    /**
111     * Returns the child spaces of the current space
112     *
113     * @see org.alfresco.web.ui.repo.component.AbstractItemSelector#getChildrenForNode(javax.faces.context.FacesContext)
114     */

115    public Collection JavaDoc<NodeRef> getChildrenForNode(FacesContext context)
116    {
117       NodeRef nodeRef = new NodeRef(Repository.getStoreRef(), this.navigationId);
118       List JavaDoc<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       // filter out those children that are not spaces
124
List JavaDoc<NodeRef> spaceKids = new ArrayList JavaDoc<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    /**
138     * Returns the children of the initial root space
139     *
140     * @see org.alfresco.web.ui.repo.component.AbstractItemSelector#getRootChildren(javax.faces.context.FacesContext)
141     */

142    public Collection JavaDoc<NodeRef> getRootChildren(FacesContext context)
143    {
144       NodeRef rootRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId());
145       
146       // get a child association reference back from the parent node to satisfy
147
// the generic API we have in the abstract super class
148
PermissionService ps = Repository.getServiceRegistry(context).getPermissionService();
149       if (ps.hasPermission(rootRef, PermissionService.READ) != AccessStatus.ALLOWED)
150       {
151          // get the root space from the current user home instead
152
String JavaDoc homeId = Application.getCurrentUser(context).getHomeSpaceId();
153          rootRef = new NodeRef(Repository.getStoreRef(), homeId);
154       }
155       List JavaDoc<NodeRef> roots = new ArrayList JavaDoc<NodeRef>(1);
156       roots.add(rootRef);
157       
158       return roots;
159    }
160
161    /**
162     * @see org.alfresco.web.ui.repo.component.AbstractItemSelector#getItemIcon()
163     */

164    public String JavaDoc getItemIcon()
165    {
166       return WebResources.IMAGE_SPACE;
167    }
168 }
169
Popular Tags