KickJava   Java API By Example, From Geeks To Geeks.

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


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.RepositoryException;
20 import org.xml.sax.ContentHandler JavaDoc;
21 import org.xml.sax.SAXException JavaDoc;
22 import org.xml.sax.helpers.AttributesImpl JavaDoc;
23
24 import java.util.Map JavaDoc;
25
26 /**
27  * Link to an (external) URL.
28  */

29 public class LinkNode extends AbstractParentNode {
30     private String JavaDoc url;
31     private String JavaDoc label;
32     private String JavaDoc id;
33
34     public LinkNode(String JavaDoc id, String JavaDoc url, String JavaDoc label) {
35         this.id = id;
36         this.url = url;
37         this.label = label;
38     }
39
40     public boolean checkId(String JavaDoc id, long branchId, long languageId) {
41         return this.id.equals(id);
42     }
43
44     public boolean isExpandable() throws NavigationException {
45         return false;
46     }
47
48     public void populateNodeLookupMap(Map JavaDoc map, String JavaDoc path) throws RepositoryException {
49         path = path + "/" + id;
50         super.populateNodeLookupMap(map, path);
51     }
52
53     public void generateXml(ContentHandler JavaDoc contentHandler, int depth, String JavaDoc path, long userId, long[] roleIds) throws RepositoryException, SAXException JavaDoc {
54         path = path + "/" + id;
55         AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
56         attrs.addAttribute("", "label", "label", "CDATA", label);
57         attrs.addAttribute("", "path", "path", "CDATA", path);
58         attrs.addAttribute("", "url", "url", "CDATA", url);
59         contentHandler.startElement(NAVIGATION_NS, "link", "link", attrs);
60         if (depth != -1 && depth - 1 > 0)
61             super.generateXml(contentHandler, depth - 1, path, userId, roleIds);
62         else if (depth == -1)
63             super.generateXml(contentHandler, -1, path, userId, roleIds);
64         contentHandler.endElement(NAVIGATION_NS, "link", "link");
65     }
66
67     public void generateXml(ContentHandler JavaDoc contentHandler, Node[] activeNodePath, int pos, boolean includeOnlyActivePath,
68             String JavaDoc path, long userId, long[] roleIds) throws RepositoryException, SAXException JavaDoc {
69         path = path + "/" + id;
70         AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
71         attrs.addAttribute("", "label", "label", "CDATA", label);
72         attrs.addAttribute("", "id", "id", "CDATA", id);
73         attrs.addAttribute("", "path", "path", "CDATA", path);
74         attrs.addAttribute("", "url", "url", "CDATA", url);
75         if (pos < activeNodePath.length && activeNodePath[pos] == this)
76             attrs.addAttribute("", "selected", "selected", "CDATA", "true");
77         if (pos == activeNodePath.length - 1 && activeNodePath[pos] == this)
78             attrs.addAttribute("", "active", "active", "CDATA", "true");
79         contentHandler.startElement(NAVIGATION_NS, "link", "link", attrs);
80         if ((includeOnlyActivePath && pos < activeNodePath.length && activeNodePath[pos] == this) || (!includeOnlyActivePath))
81             super.generateXml(contentHandler, activeNodePath, pos + 1, includeOnlyActivePath, path, userId, roleIds);
82         contentHandler.endElement(NAVIGATION_NS, "link", "link");
83     }
84
85     public boolean isIdentifiable() {
86         return true;
87     }
88
89     public String JavaDoc getId() {
90         return id;
91     }
92
93     public boolean isVisible(long userId, long[] roleId, Node[] activeNodePath, int activeNodePathPos) throws NavigationException {
94         return true;
95     }
96 }
97
Popular Tags