KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > navigation > impl > BuildingNode


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.navigation.impl;
17
18 import org.outerj.daisy.navigation.NavigationException;
19 import org.outerj.daisy.navigation.NavigationVersionMode;
20 import org.outerj.daisy.repository.VariantKey;
21 import org.outerj.daisy.repository.RepositoryException;
22 import org.xml.sax.ContentHandler JavaDoc;
23 import org.xml.sax.SAXException JavaDoc;
24
25 import java.util.List JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.Stack JavaDoc;
28
29 /**
30  * A node which builds a navigation tree when first needed.
31  */

32 public class BuildingNode implements Node {
33     private final VariantKey navigationDoc;
34     private final NavigationVersionMode versionMode;
35     private final CommonNavigationManager.Context context;
36     private Node delegate;
37
38     public BuildingNode(VariantKey navigationDoc, NavigationVersionMode versionMode, CommonNavigationManager.Context context) {
39         this.navigationDoc = navigationDoc;
40         this.versionMode = versionMode;
41         this.context = context;
42     }
43
44     private synchronized void load() throws NavigationException {
45         if (delegate == null) {
46             delegate = NavigationFactory.build(navigationDoc, versionMode, context, new Counter(), new Stack JavaDoc());
47         }
48     }
49
50     private void checkAccess(long userId, long roleIds[]) throws RepositoryException {
51         // Everyone can browse navigation trees based on the live version (even if they
52
// don't have read live access to the document).
53
if (versionMode != NavigationVersionMode.LIVE) {
54             if (!context.canRead(navigationDoc, userId, roleIds))
55                 throw new NavigationException("Access to non-live versions of navigation trees is only allowed when you have read permission to them. Navigation tree: " + navigationDoc);
56         }
57     }
58
59     public void searchPath(String JavaDoc[] path, int pos, long branchId, long languageId, Node[] foundPath) throws RepositoryException {
60         load();
61         delegate.searchPath(path, pos, branchId, languageId, foundPath);
62     }
63
64     public boolean isExpandable() throws RepositoryException {
65         load();
66         return delegate.isExpandable();
67     }
68
69     public List JavaDoc getExpandedChildList() throws RepositoryException {
70         load();
71         return delegate.getExpandedChildList();
72     }
73
74     public boolean checkId(String JavaDoc id, long branchId, long languageId) throws RepositoryException {
75         load();
76         return delegate.checkId(id, branchId, languageId);
77     }
78
79     public List JavaDoc searchDocument(VariantKey key) throws RepositoryException {
80         load();
81         return delegate.searchDocument(key);
82     }
83
84     public void populateNodeLookupMap(Map JavaDoc map, String JavaDoc path) throws RepositoryException {
85         load();
86         delegate.populateNodeLookupMap(map, path);
87     }
88
89     public void generateXml(ContentHandler JavaDoc contentHandler, int depth, String JavaDoc path, long userId, long[] roleIds) throws RepositoryException, SAXException JavaDoc {
90         load();
91         checkAccess(userId, roleIds);
92         delegate.generateXml(contentHandler, depth, path, userId, roleIds);
93     }
94
95     public void generateXml(ContentHandler JavaDoc contentHandler, Node[] activeNodePath, int pos, boolean includeOnlyActivePath,
96                             String JavaDoc path, long userId, long[] roleIds) throws RepositoryException, SAXException JavaDoc {
97         load();
98         checkAccess(userId, roleIds);
99         delegate.generateXml(contentHandler, activeNodePath, pos, includeOnlyActivePath, path, userId, roleIds);
100     }
101
102     public boolean isVisible(long userId, long[] roleIds, Node[] activeNodePath, int activeNodePathPos) throws RepositoryException {
103         load();
104         return delegate.isVisible(userId, roleIds, activeNodePath, activeNodePathPos);
105     }
106
107     public boolean isIdentifiable() throws RepositoryException {
108         load();
109         return delegate.isIdentifiable();
110     }
111
112     public String JavaDoc getId() throws RepositoryException {
113         load();
114         return delegate.getId();
115     }
116 }
117
Popular Tags