1 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 ; 21 import org.xml.sax.SAXException ; 22 import org.xml.sax.helpers.AttributesImpl ; 23 24 import java.util.Map ; 25 26 29 public class LinkNode extends AbstractParentNode { 30 private String url; 31 private String label; 32 private String id; 33 34 public LinkNode(String id, String url, String label) { 35 this.id = id; 36 this.url = url; 37 this.label = label; 38 } 39 40 public boolean checkId(String 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 map, String path) throws RepositoryException { 49 path = path + "/" + id; 50 super.populateNodeLookupMap(map, path); 51 } 52 53 public void generateXml(ContentHandler contentHandler, int depth, String path, long userId, long[] roleIds) throws RepositoryException, SAXException { 54 path = path + "/" + id; 55 AttributesImpl attrs = new AttributesImpl (); 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 contentHandler, Node[] activeNodePath, int pos, boolean includeOnlyActivePath, 68 String path, long userId, long[] roleIds) throws RepositoryException, SAXException { 69 path = path + "/" + id; 70 AttributesImpl attrs = new AttributesImpl (); 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 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 |