KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xtpdoc > Navigation


1 /*
2  * Copyright (c) 1998-2000 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Emil Ong
28  */

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 JavaDoc;
37 import java.io.PrintWriter JavaDoc;
38 import java.util.ArrayList JavaDoc;
39 import java.util.HashMap JavaDoc;
40 import java.util.logging.Logger JavaDoc;
41
42 public class Navigation {
43   private static final Logger JavaDoc 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 JavaDoc _uri;
52   private String JavaDoc _section;
53   private boolean _threaded;
54   private boolean _comment;
55   private ArrayList JavaDoc<NavigationItem> _items
56     = new ArrayList JavaDoc<NavigationItem>();
57
58   private NavigationItem _docItem;
59   private NavigationItem _child;
60
61   private HashMap JavaDoc<String JavaDoc,NavigationItem> _itemMap
62     = new HashMap JavaDoc<String JavaDoc,NavigationItem>();
63
64   public Navigation(Document document, String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc section)
107   {
108     _section = section;
109   }
110
111   public String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc path,
188             int depth, int styleDepth, int maxDepth)
189     throws XMLStreamException
190   {
191     /*
192     String depthString = (depth == 0) ? "top" : ("" + depth);
193     out.writeStartElement("dl");
194     out.writeAttribute("class", "atoc-toplevel atoc-toplevel-" + depthString);
195     */

196
197     for (NavigationItem item : _items)
198       item.writeHtml(out, path, depth, styleDepth, maxDepth);
199
200     //out.writeEndElement(); // dl
201
}
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 JavaDoc writer)
221     throws IOException JavaDoc
222   {
223   }
224 }
225
Popular Tags