1 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 ; 23 import org.xml.sax.SAXException ; 24 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.Stack ; 28 29 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 ()); 47 } 48 } 49 50 private void checkAccess(long userId, long roleIds[]) throws RepositoryException { 51 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 [] 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 getExpandedChildList() throws RepositoryException { 70 load(); 71 return delegate.getExpandedChildList(); 72 } 73 74 public boolean checkId(String id, long branchId, long languageId) throws RepositoryException { 75 load(); 76 return delegate.checkId(id, branchId, languageId); 77 } 78 79 public List searchDocument(VariantKey key) throws RepositoryException { 80 load(); 81 return delegate.searchDocument(key); 82 } 83 84 public void populateNodeLookupMap(Map map, String path) throws RepositoryException { 85 load(); 86 delegate.populateNodeLookupMap(map, path); 87 } 88 89 public void generateXml(ContentHandler contentHandler, int depth, String path, long userId, long[] roleIds) throws RepositoryException, SAXException { 90 load(); 91 checkAccess(userId, roleIds); 92 delegate.generateXml(contentHandler, depth, path, userId, roleIds); 93 } 94 95 public void generateXml(ContentHandler contentHandler, Node[] activeNodePath, int pos, boolean includeOnlyActivePath, 96 String path, long userId, long[] roleIds) throws RepositoryException, SAXException { 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 getId() throws RepositoryException { 113 load(); 114 return delegate.getId(); 115 } 116 } 117 | Popular Tags |