KickJava   Java API By Example, From Geeks To Geeks.

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


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.repository.VariantKey;
20 import org.outerj.daisy.repository.RepositoryException;
21 import org.xml.sax.ContentHandler JavaDoc;
22 import org.xml.sax.SAXException JavaDoc;
23 import org.xml.sax.helpers.AttributesImpl JavaDoc;
24
25 import java.util.List JavaDoc;
26 import java.util.Map JavaDoc;
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 JavaDoc[] path, int pos, long branchId, long languageId, Node[] foundPath) throws RepositoryException {
36         delegate.searchPath(path, pos, branchId, languageId, foundPath);
37     }
38
39     public List JavaDoc searchDocument(VariantKey key) throws RepositoryException {
40         return delegate.searchDocument(key);
41     }
42
43     public void populateNodeLookupMap(Map JavaDoc map, String JavaDoc path) throws RepositoryException {
44         delegate.populateNodeLookupMap(map, path);
45     }
46
47     public boolean checkId(String JavaDoc 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 JavaDoc getExpandedChildList() throws RepositoryException {
56         return delegate.getExpandedChildList();
57     }
58
59     public void generateXml(ContentHandler JavaDoc contentHandler, int depth, String JavaDoc path, long userId, long[] roleIds) throws RepositoryException, SAXException JavaDoc {
60         generateHeader(contentHandler, null, depth == -1);
61         delegate.generateXml(contentHandler, depth, path, userId, roleIds);
62         generateFooter(contentHandler);
63     }
64
65     public void generateXml(ContentHandler JavaDoc contentHandler, Node[] activeNodePath, int pos, boolean includeOnlyActivePath,
66                             String JavaDoc path, long userId, long[] roleIds) throws RepositoryException, SAXException JavaDoc {
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 JavaDoc contentHandler, Node[] activeNodePath, boolean completeTree) throws SAXException JavaDoc, RepositoryException {
73         contentHandler.startDocument();
74         AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
75         if (activeNodePath != null) {
76             StringBuffer JavaDoc selectedPath = new StringBuffer JavaDoc(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 JavaDoc contentHandler) throws SAXException JavaDoc {
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 JavaDoc getId() {
97         throw new UnsupportedOperationException JavaDoc();
98     }
99
100     public boolean isVisible(long userId, long[] roleId, Node[] activeNodePath, int activeNodePathPos) throws NavigationException {
101         return true;
102     }
103 }
104
Popular Tags