KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.xml.stream.XMLStreamException;
33 import javax.xml.stream.XMLStreamWriter;
34 import java.io.IOException JavaDoc;
35 import java.io.PrintWriter JavaDoc;
36
37 public class Localtoc implements ContentItem {
38   Document _document;
39   
40   Localtoc(Document doc)
41   {
42     _document = doc;
43   }
44   
45   public void writeHtml(XMLStreamWriter out)
46     throws XMLStreamException
47   {
48     ContainerNode container = _document.getBody();
49
50     writeContainer(out, container);
51   }
52   
53   private void writeContainer(XMLStreamWriter out, ContainerNode container)
54     throws XMLStreamException
55   {
56     if (container == null)
57       return;
58     
59     out.writeStartElement("div");
60     out.writeAttribute("class", "toc");
61     out.writeStartElement("ol");
62
63     for (ContentItem item : container.getItems()) {
64       if (item instanceof Section) {
65     Section section = (Section) item;
66
67     if (section.getTitle() != null
68         && ! "".equals(section.getTitle())) {
69       out.writeStartElement("li");
70       out.writeStartElement("a");
71       out.writeAttribute("href", "#" + section.getHref());
72       out.writeCharacters(section.getTitle());
73       out.writeEndElement();
74       out.writeEndElement();
75     
76       writeContainer(out, section);
77     }
78       }
79     }
80     out.writeEndElement(); // </ul>
81
out.writeEndElement(); //
82
}
83
84   public void writeLaTeX(PrintWriter JavaDoc writer)
85     throws IOException JavaDoc
86   {
87   }
88
89   public void writeLaTeXTop(PrintWriter JavaDoc out)
90     throws IOException JavaDoc
91   {
92   }
93
94   public void writeLaTeXEnclosed(PrintWriter JavaDoc out)
95     throws IOException JavaDoc
96   {
97   }
98 }
99
Popular Tags