1 29 30 package com.caucho.xtpdoc; 31 32 import com.caucho.vfs.Path; 33 34 import javax.xml.stream.XMLStreamException; 35 import javax.xml.stream.XMLStreamWriter; 36 import java.io.IOException ; 37 import java.io.PrintWriter ; 38 import java.util.ArrayList ; 39 import java.util.HashMap ; 40 import java.util.logging.Logger ; 41 42 public class Navigation { 43 private static final Logger log 44 = Logger.getLogger(Navigation.class.getName()); 45 46 private Document _document; 47 private Navigation _parent; 48 49 private int _depth; 50 private Path _rootPath; 51 private String _uri; 52 private String _section; 53 private boolean _threaded; 54 private boolean _comment; 55 private ArrayList <NavigationItem> _items 56 = new ArrayList <NavigationItem>(); 57 58 private NavigationItem _docItem; 59 private NavigationItem _child; 60 61 private HashMap <String ,NavigationItem> _itemMap 62 = new HashMap <String ,NavigationItem>(); 63 64 public Navigation(Document document, String uri, Path path, int depth) 65 { 66 _document = document; 67 _rootPath = path; 68 _uri = uri; 69 _depth = depth; 70 } 71 72 public Navigation(Navigation parent, String uri, Path path, int depth) 73 { 74 _parent = parent; 75 _document = parent.getDocument(); 76 _rootPath = path; 77 _uri = uri; 78 _depth = depth; 79 } 80 81 public Path getRootPath() 82 { 83 return _rootPath; 84 } 85 86 public void setChild(NavigationItem child) 87 { 88 _child = child; 89 } 90 91 public String getUri() 92 { 93 return _uri; 94 } 95 96 public Document getDocument() 97 { 98 return _document; 99 } 100 101 public Navigation getParent() 102 { 103 return _parent; 104 } 105 106 public void setSection(String section) 107 { 108 _section = section; 109 } 110 111 public String getSection() 112 { 113 return _section; 114 } 115 116 public void setComment(boolean comment) 117 { 118 _comment = comment; 119 } 120 121 public void setThreaded(boolean threaded) 122 { 123 _threaded = threaded; 124 } 125 126 public NavigationItem getRoot() 127 { 128 if (_items.size() > 0) 129 return _items.get(0); 130 else 131 return null; 132 } 133 134 public NavigationItem createItem() 135 { 136 return new NavigationItem(this, null, _depth); 137 } 138 139 public void addItem(NavigationItem item) 140 { 141 _items.add(item); 142 } 143 144 public void putItem(String uri, NavigationItem item) 145 { 146 if (_child != null && _child.getUri().equals(uri)) { 147 if (item.getParent() != null) 148 _child.setParent(item.getParent()); 149 _itemMap.put(uri, _child); 150 151 if (_parent != null) 152 _parent.putItem(uri, item); 153 } 154 else { 155 _itemMap.put(uri, item); 156 157 if (_parent != null) 158 _parent.putItem(uri, item); 159 } 160 } 161 162 public NavigationItem getItem(String uri) 163 { 164 return _itemMap.get(uri); 165 } 166 167 public NavigationItem getRootItem() 168 { 169 if (_items.size() > 0) 170 return _items.get(0); 171 else 172 return null; 173 } 174 175 public void writeHtml(XMLStreamWriter out) 176 throws XMLStreamException 177 { 178 writeHtml(out, "", 1, 0, 4); 179 } 180 181 public void writeHtml(XMLStreamWriter out, int styleDepth) 182 throws XMLStreamException 183 { 184 writeHtml(out, "", 1, styleDepth, 4); 185 } 186 187 public void writeHtml(XMLStreamWriter out, String path, 188 int depth, int styleDepth, int maxDepth) 189 throws XMLStreamException 190 { 191 196 197 for (NavigationItem item : _items) 198 item.writeHtml(out, path, depth, styleDepth, maxDepth); 199 200 } 202 203 protected void initSummary() 204 { 205 for (NavigationItem item : _items) 206 item.initSummary(); 207 } 208 209 public void writeLeftNav(XMLStreamWriter out) 210 throws XMLStreamException 211 { 212 if (_items.size() > 0) { 213 NavigationItem topItem = _items.get(0); 214 } 215 216 for (NavigationItem item : _items) 217 item.writeLeftNav(out); 218 } 219 220 public void writeLaTeX(PrintWriter writer) 221 throws IOException 222 { 223 } 224 } 225 | Popular Tags |