001: /*
002: * Copyright (c) 1998-2000 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.xtpdoc;
031:
032: import com.caucho.vfs.Path;
033:
034: import javax.xml.stream.XMLStreamException;
035: import javax.xml.stream.XMLStreamWriter;
036: import java.io.IOException;
037: import java.io.PrintWriter;
038: import java.util.ArrayList;
039: import java.util.HashMap;
040: import java.util.logging.Logger;
041:
042: public class Navigation {
043: private static final Logger log = Logger.getLogger(Navigation.class
044: .getName());
045:
046: private Document _document;
047: private Navigation _parent;
048:
049: private int _depth;
050: private Path _rootPath;
051: private String _uri;
052: private String _section;
053: private boolean _threaded;
054: private boolean _comment;
055: private ArrayList<NavigationItem> _items = new ArrayList<NavigationItem>();
056:
057: private NavigationItem _docItem;
058: private NavigationItem _child;
059:
060: private HashMap<String, NavigationItem> _itemMap = new HashMap<String, NavigationItem>();
061:
062: public Navigation(Document document, String uri, Path path,
063: int depth) {
064: _document = document;
065: _rootPath = path;
066: _uri = uri;
067: _depth = depth;
068: }
069:
070: public Navigation(Navigation parent, String uri, Path path,
071: int depth) {
072: _parent = parent;
073: _document = parent.getDocument();
074: _rootPath = path;
075: _uri = uri;
076: _depth = depth;
077: }
078:
079: public Path getRootPath() {
080: return _rootPath;
081: }
082:
083: public void setChild(NavigationItem child) {
084: _child = child;
085: }
086:
087: public String getUri() {
088: return _uri;
089: }
090:
091: public Document getDocument() {
092: return _document;
093: }
094:
095: public Navigation getParent() {
096: return _parent;
097: }
098:
099: public void setSection(String section) {
100: _section = section;
101: }
102:
103: public String getSection() {
104: return _section;
105: }
106:
107: public void setComment(boolean comment) {
108: _comment = comment;
109: }
110:
111: public void setThreaded(boolean threaded) {
112: _threaded = threaded;
113: }
114:
115: public NavigationItem getRoot() {
116: if (_items.size() > 0)
117: return _items.get(0);
118: else
119: return null;
120: }
121:
122: public NavigationItem createItem() {
123: return new NavigationItem(this , null, _depth);
124: }
125:
126: public void addItem(NavigationItem item) {
127: _items.add(item);
128: }
129:
130: public void putItem(String uri, NavigationItem item) {
131: if (_child != null && _child.getUri().equals(uri)) {
132: if (item.getParent() != null)
133: _child.setParent(item.getParent());
134: _itemMap.put(uri, _child);
135:
136: if (_parent != null)
137: _parent.putItem(uri, item);
138: } else {
139: _itemMap.put(uri, item);
140:
141: if (_parent != null)
142: _parent.putItem(uri, item);
143: }
144: }
145:
146: public NavigationItem getItem(String uri) {
147: return _itemMap.get(uri);
148: }
149:
150: public NavigationItem getRootItem() {
151: if (_items.size() > 0)
152: return _items.get(0);
153: else
154: return null;
155: }
156:
157: public void writeHtml(XMLStreamWriter out)
158: throws XMLStreamException {
159: writeHtml(out, "", 1, 0, 4);
160: }
161:
162: public void writeHtml(XMLStreamWriter out, int styleDepth)
163: throws XMLStreamException {
164: writeHtml(out, "", 1, styleDepth, 4);
165: }
166:
167: public void writeHtml(XMLStreamWriter out, String path, int depth,
168: int styleDepth, int maxDepth) throws XMLStreamException {
169: /*
170: String depthString = (depth == 0) ? "top" : ("" + depth);
171: out.writeStartElement("dl");
172: out.writeAttribute("class", "atoc-toplevel atoc-toplevel-" + depthString);
173: */
174:
175: for (NavigationItem item : _items)
176: item.writeHtml(out, path, depth, styleDepth, maxDepth);
177:
178: //out.writeEndElement(); // dl
179: }
180:
181: protected void initSummary() {
182: for (NavigationItem item : _items)
183: item.initSummary();
184: }
185:
186: public void writeLeftNav(XMLStreamWriter out)
187: throws XMLStreamException {
188: if (_items.size() > 0) {
189: NavigationItem topItem = _items.get(0);
190: }
191:
192: for (NavigationItem item : _items)
193: item.writeLeftNav(out);
194: }
195:
196: public void writeLaTeX(PrintWriter writer) throws IOException {
197: }
198: }
|