KickJava   Java API By Example, From Geeks To Geeks.

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


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.repository.VariantKey;
19 import org.outerj.daisy.repository.RepositoryException;
20 import org.xml.sax.ContentHandler JavaDoc;
21 import org.xml.sax.SAXException JavaDoc;
22
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Map JavaDoc;
27
28 public abstract class AbstractParentNode implements Node {
29     protected final List JavaDoc children = new ArrayList JavaDoc();
30
31     public void add(Node node) {
32         children.add(node);
33     }
34
35     public void searchPath(String JavaDoc[] path, int pos, long branchId, long languageId, Node[] foundPath) throws RepositoryException {
36         Iterator JavaDoc 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 JavaDoc searchDocument(VariantKey key) throws RepositoryException {
50         Iterator JavaDoc childrenIt = getExpandedChildList().iterator();
51         while (childrenIt.hasNext()) {
52             Node node = (Node)childrenIt.next();
53             List JavaDoc 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 JavaDoc map, String JavaDoc path) throws RepositoryException {
64         Iterator JavaDoc 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 JavaDoc contentHandler, int depth, String JavaDoc path, long userId, long[] roleIds) throws RepositoryException, SAXException JavaDoc {
72         generateXml(getExpandedChildList(), contentHandler, depth, path, userId, roleIds);
73     }
74
75     // This method can be used if you already have retrieved the getExpandedChildList()
76
public void generateXml(List JavaDoc children, ContentHandler JavaDoc contentHandler, int depth, String JavaDoc path, long userId, long[] roleIds) throws RepositoryException, SAXException JavaDoc {
77         Iterator JavaDoc 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 JavaDoc contentHandler, Node[] activeNodePath, int pos, boolean includeOnlyActivePath,
85             String JavaDoc path, long userId, long[] roleIds) throws RepositoryException, SAXException JavaDoc {
86         generateXml(getExpandedChildList(), contentHandler, activeNodePath, pos, includeOnlyActivePath, path, userId, roleIds);
87     }
88
89     // This method can be used if you already have retrieved the getExpandedChildList()
90
public void generateXml(List JavaDoc children, ContentHandler JavaDoc contentHandler, Node[] activeNodePath, int pos,
91             boolean includeOnlyActivePath, String JavaDoc path, long userId, long[] roleIds)
92             throws RepositoryException, SAXException JavaDoc {
93         Iterator JavaDoc 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 JavaDoc getExpandedChildList() throws RepositoryException {
101         ArrayList JavaDoc list = new ArrayList JavaDoc(children.size());
102
103         Iterator JavaDoc 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 JavaDoc getId() {
117         throw new UnsupportedOperationException JavaDoc();
118     }
119
120 }
121
Popular Tags