1 16 package org.outerj.daisy.navigation.impl; 17 18 import org.outerj.daisy.repository.VariantKey; 19 import org.outerj.daisy.repository.RepositoryException; 20 import org.xml.sax.ContentHandler ; 21 import org.xml.sax.SAXException ; 22 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.ArrayList ; 26 import java.util.Map ; 27 28 public abstract class AbstractParentNode implements Node { 29 protected final List children = new ArrayList (); 30 31 public void add(Node node) { 32 children.add(node); 33 } 34 35 public void searchPath(String [] path, int pos, long branchId, long languageId, Node[] foundPath) throws RepositoryException { 36 Iterator childrenIt = getExpandedChildList().iterator(); 37 while (childrenIt.hasNext()) { 38 Node node = (Node)childrenIt.next(); 39 if (node.checkId(path[pos], branchId, languageId)) { 40 foundPath[pos] = node; 41 if (pos != path.length - 1) { 42 node.searchPath(path, pos + 1, branchId, languageId, foundPath); 43 } 44 return; 45 } 46 } 47 } 48 49 public List searchDocument(VariantKey key) throws RepositoryException { 50 Iterator childrenIt = getExpandedChildList().iterator(); 51 while (childrenIt.hasNext()) { 52 Node node = (Node)childrenIt.next(); 53 List foundNodePath = node.searchDocument(key); 54 if (foundNodePath != null) { 55 if (isIdentifiable()) 56 foundNodePath.add(this); 57 return foundNodePath; 58 } 59 } 60 return null; 61 } 62 63 public void populateNodeLookupMap(Map map, String path) throws RepositoryException { 64 Iterator childrenIt = getExpandedChildList().iterator(); 65 while (childrenIt.hasNext()) { 66 Node node = (Node)childrenIt.next(); 67 node.populateNodeLookupMap(map, path); 68 } 69 } 70 71 public void generateXml(ContentHandler contentHandler, int depth, String path, long userId, long[] roleIds) throws RepositoryException, SAXException { 72 generateXml(getExpandedChildList(), contentHandler, depth, path, userId, roleIds); 73 } 74 75 public void generateXml(List children, ContentHandler contentHandler, int depth, String path, long userId, long[] roleIds) throws RepositoryException, SAXException { 77 Iterator childrenIt = children.iterator(); 78 while (childrenIt.hasNext()) { 79 Node node = (Node)childrenIt.next(); 80 node.generateXml(contentHandler, depth, path, userId, roleIds); 81 } 82 } 83 84 public void generateXml(ContentHandler contentHandler, Node[] activeNodePath, int pos, boolean includeOnlyActivePath, 85 String path, long userId, long[] roleIds) throws RepositoryException, SAXException { 86 generateXml(getExpandedChildList(), contentHandler, activeNodePath, pos, includeOnlyActivePath, path, userId, roleIds); 87 } 88 89 public void generateXml(List children, ContentHandler contentHandler, Node[] activeNodePath, int pos, 91 boolean includeOnlyActivePath, String path, long userId, long[] roleIds) 92 throws RepositoryException, SAXException { 93 Iterator childrenIt = children.iterator(); 94 while (childrenIt.hasNext()) { 95 Node node = (Node)childrenIt.next(); 96 node.generateXml(contentHandler, activeNodePath, pos, includeOnlyActivePath, path, userId, roleIds); 97 } 98 } 99 100 public List getExpandedChildList() throws RepositoryException { 101 ArrayList list = new ArrayList (children.size()); 102 103 Iterator childIt = children.iterator(); 104 while (childIt.hasNext()) { 105 Node child = (Node)childIt.next(); 106 if (child.isExpandable()) { 107 list.addAll(child.getExpandedChildList()); 108 } else { 109 list.add(child); 110 } 111 } 112 113 return list; 114 } 115 116 public String getId() { 117 throw new UnsupportedOperationException (); 118 } 119 120 } 121 | Popular Tags |