1 30 31 package com.caucho.web; 32 33 import com.caucho.util.Tree; 34 35 import java.util.ArrayList ; 36 import java.util.Iterator ; 37 38 public class NavItem { 39 Tree tree; 40 String title; 41 String link; 42 String description; 43 String brief; 44 String _product; 45 46 NavItem() 47 { 48 } 49 50 void setTree(Tree tree) 51 { 52 this.tree = tree; 53 } 54 55 58 Tree getTree() 59 { 60 return tree; 61 } 62 63 66 public NavItem getParent() 67 { 68 if (tree == null) 69 return null; 70 71 Tree parent = tree.getParent(); 72 73 return parent == null ? null : (NavItem) parent.getData(); 74 } 75 76 public Iterator children() 77 { 78 return tree.iterator(); 79 } 80 81 public String getTitle() 82 { 83 return title; 84 } 85 86 public void setTitle(String title) 87 { 88 this.title = title; 89 } 90 91 public String getProduct() 92 { 93 return _product; 94 } 95 96 public void setProduct(String product) 97 { 98 _product = product; 99 } 100 101 public String getBrief() 102 { 103 return brief; 104 } 105 106 public void setBrief(String brief) 107 { 108 this.brief = brief; 109 } 110 111 public String getLink() 112 { 113 return link; 114 } 115 116 public void setLink(String link) 117 { 118 this.link = link; 119 } 120 121 public String getDescription() 122 { 123 return description; 124 } 125 126 public void setDescription(String description) 127 { 128 this.description = description; 129 } 130 131 134 public NavItem getPrevious() 135 { 136 Tree prevTree = tree.getPrevious(); 137 138 if (prevTree == null) 139 return null; 140 else 141 return (NavItem) prevTree.getData(); 142 } 143 144 147 public NavItem getPreviousPreorder() 148 { 149 Tree prevTree = tree.getPreviousPreorder(); 150 151 if (prevTree == null) 152 return null; 153 else 154 return (NavItem) prevTree.getData(); 155 } 156 157 160 public NavItem getNext() 161 { 162 Tree nextTree = tree.getNext(); 163 164 if (nextTree == null) 165 return null; 166 else 167 return (NavItem) nextTree.getData(); 168 } 169 170 173 public NavItem getNextPreorder() 174 { 175 Tree nextTree = tree.getNextPreorder(); 176 177 if (nextTree == null) 178 return null; 179 else 180 return (NavItem) nextTree.getData(); 181 } 182 183 186 public ArrayList familyNavigation() 187 { 188 ArrayList list = new ArrayList (); 189 190 familyNavigation(tree, list); 191 192 return list; 193 } 194 195 198 private boolean familyNavigation(Tree tree, ArrayList results) 199 { 200 if (tree == null) { 201 return false; 202 } 203 204 boolean hasParent = false; 205 if (tree.getParent() != null) { 206 hasParent = familyNavigation(tree.getParent(), results); 207 } 208 209 Iterator iter = tree.iterator(); 210 211 boolean hasChild = false; 212 while (iter.hasNext()) { 213 NavItem child = (NavItem) iter.next(); 214 215 if (! hasChild && hasParent) 216 results.add(null); 217 218 hasChild = true; 219 results.add(child); 220 } 221 222 return hasChild || hasParent; 223 } 224 225 public String toString() 226 { 227 return "[NavItem title='" + title + "' link='" + link + "']"; 228 } 229 } 230 | Popular Tags |