1 16 package org.outerj.daisy.navigation.impl; 17 18 import org.outerj.daisy.navigation.NavigationException; 19 import org.outerj.daisy.repository.VariantKey; 20 import org.outerj.daisy.repository.RepositoryException; 21 import org.xml.sax.ContentHandler ; 22 import org.xml.sax.SAXException ; 23 import org.xml.sax.helpers.AttributesImpl ; 24 25 import java.util.List ; 26 import java.util.Map ; 27 28 public class RootNode implements Node { 29 private Node delegate; 30 31 public RootNode(Node delegate) { 32 this.delegate = delegate; 33 } 34 35 public void searchPath(String [] path, int pos, long branchId, long languageId, Node[] foundPath) throws RepositoryException { 36 delegate.searchPath(path, pos, branchId, languageId, foundPath); 37 } 38 39 public List searchDocument(VariantKey key) throws RepositoryException { 40 return delegate.searchDocument(key); 41 } 42 43 public void populateNodeLookupMap(Map map, String path) throws RepositoryException { 44 delegate.populateNodeLookupMap(map, path); 45 } 46 47 public boolean checkId(String id, long branchId, long languageId) throws RepositoryException { 48 return delegate.checkId(id, branchId, languageId); 49 } 50 51 public boolean isExpandable() throws RepositoryException { 52 return delegate.isExpandable(); 53 } 54 55 public List getExpandedChildList() throws RepositoryException { 56 return delegate.getExpandedChildList(); 57 } 58 59 public void generateXml(ContentHandler contentHandler, int depth, String path, long userId, long[] roleIds) throws RepositoryException, SAXException { 60 generateHeader(contentHandler, null, depth == -1); 61 delegate.generateXml(contentHandler, depth, path, userId, roleIds); 62 generateFooter(contentHandler); 63 } 64 65 public void generateXml(ContentHandler contentHandler, Node[] activeNodePath, int pos, boolean includeOnlyActivePath, 66 String path, long userId, long[] roleIds) throws RepositoryException, SAXException { 67 generateHeader(contentHandler, activeNodePath, !includeOnlyActivePath); 68 delegate.generateXml(contentHandler, activeNodePath, pos, includeOnlyActivePath, path, userId, roleIds); 69 generateFooter(contentHandler); 70 } 71 72 private void generateHeader(ContentHandler contentHandler, Node[] activeNodePath, boolean completeTree) throws SAXException , RepositoryException { 73 contentHandler.startDocument(); 74 AttributesImpl attrs = new AttributesImpl (); 75 if (activeNodePath != null) { 76 StringBuffer selectedPath = new StringBuffer (activeNodePath.length * 8); 77 for (int i = 0; i < activeNodePath.length; i++) 78 selectedPath.append("/").append(activeNodePath[i].getId()); 79 attrs.addAttribute("", "selectedPath", "selectedPath", "CDATA", selectedPath.toString()); 80 } 81 attrs.addAttribute("", "completeTree", "completeTree", "CDATA", String.valueOf(completeTree)); 82 contentHandler.startPrefixMapping("", NAVIGATION_NS); 83 contentHandler.startElement(NAVIGATION_NS, "navigationTree", "navigationTree", attrs); 84 } 85 86 private void generateFooter(ContentHandler contentHandler) throws SAXException { 87 contentHandler.endElement(NAVIGATION_NS, "navigationTree", "navigationTree"); 88 contentHandler.endPrefixMapping(""); 89 contentHandler.endDocument(); 90 } 91 92 public boolean isIdentifiable() { 93 return false; 94 } 95 96 public String getId() { 97 throw new UnsupportedOperationException (); 98 } 99 100 public boolean isVisible(long userId, long[] roleId, Node[] activeNodePath, int activeNodePathPos) throws NavigationException { 101 return true; 102 } 103 } 104 | Popular Tags |