KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
33 import java.io.PrintWriter JavaDoc;
34
35 public abstract class Section extends ContainerNode {
36   protected FormattedTextWithAnchors _description;
37   protected String JavaDoc _name;
38   protected String JavaDoc _title;
39   protected String JavaDoc _version;
40   protected String JavaDoc _type;
41
42   private String JavaDoc _parentHref;
43
44   public Section(Document document)
45   {
46     this(document, "");
47   }
48
49     public Section(Document document, String JavaDoc parentHref)
50   {
51     super(document);
52     _parentHref = parentHref;
53   }
54
55
56   //
57
// XXX: Stubbed
58
//
59

60   public void setOccur(String JavaDoc occur)
61   {
62   }
63
64   public void setLocalTOCIndent(String JavaDoc localTOCIndent)
65   {
66   }
67
68   public void setVersion(String JavaDoc version)
69   {
70     _version = version;
71   }
72
73   public void setName(String JavaDoc name)
74   {
75     _name = name;
76   }
77
78   public void setProduct(String JavaDoc product)
79   {
80   }
81
82   public void setIndex(String JavaDoc index)
83   {
84   }
85
86   //
87
// XXX: End stubbed
88
//
89

90   public void setType(String JavaDoc type)
91   {
92     _type = type;
93   }
94
95   public void setTitle(String JavaDoc title)
96   {
97     _title = title;
98   }
99
100   public String JavaDoc getName()
101   {
102     return _name;
103   }
104
105   public String JavaDoc getTitle()
106   {
107     return _title;
108   }
109
110   public String JavaDoc getHref()
111   {
112     if (_name != null)
113       return cleanHref(_name);
114     else
115       return cleanHref(_title);
116   }
117
118   public static String JavaDoc cleanHref(String JavaDoc href)
119   {
120     if (href == null)
121       return href;
122     
123     StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
124
125     for (int i = 0; i < href.length(); i++) {
126       char ch = href.charAt(i);
127
128       switch (ch) {
129       case '<': case '>': case '(': case ')': case '?':
130     break;
131     
132       default:
133     sb.append(ch);
134     break;
135       }
136     }
137
138     return sb.toString();
139   }
140
141   public DefinitionList createDl()
142   {
143     DefinitionList list = new DefinitionList(getDocument());
144     addItem(list);
145     return list;
146   }
147
148   public FormattedTextWithAnchors createDescription()
149   {
150     _description = new FormattedTextWithAnchors(getDocument());
151     return _description;
152   }
153
154   public BlockQuote createBlockquote()
155   {
156     BlockQuote blockQuote = new BlockQuote(getDocument());
157     addItem(blockQuote);
158     return blockQuote;
159   }
160
161   public Paragraph createP()
162   {
163     Paragraph paragraph = new Paragraph(getDocument());
164     addItem(paragraph);
165     return paragraph;
166   }
167
168   public PreFormattedText createPre()
169   {
170     PreFormattedText pretext = new PreFormattedText(getDocument());
171     addItem(pretext);
172     return pretext;
173   }
174
175   public OrderedList createOl()
176   {
177     OrderedList orderedList = new OrderedList(getDocument());
178     addItem(orderedList);
179     return orderedList;
180   }
181
182   public UnorderedList createUl()
183   {
184     UnorderedList unorderedList = new UnorderedList(getDocument());
185     addItem(unorderedList);
186     return unorderedList;
187   }
188
189   public Figure createFigure()
190   {
191     Figure figure = new Figure(getDocument());
192     addItem(figure);
193     return figure;
194   }
195
196   public Example createExample()
197   {
198     Example example = new Example(getDocument());
199     addItem(example);
200     return example;
201   }
202
203   public Table createTable()
204   {
205     Table table = new Table(getDocument());
206     addItem(table);
207     return table;
208   }
209
210   public DefinitionTable createDeftable()
211   {
212     DefinitionTable definitionTable = new DefinitionTable(getDocument());
213     addItem(definitionTable);
214     return definitionTable;
215   }
216
217   public DefinitionTable createDeftableChildtags()
218   {
219     DefinitionTable definitionTable = new DefinitionTable(getDocument());
220     addItem(definitionTable);
221     return definitionTable;
222   }
223
224   public DefinitionTable createDeftableParameters()
225   {
226     DefinitionTable definitionTable = new DefinitionTable(getDocument());
227     addItem(definitionTable);
228     return definitionTable;
229   }
230
231   public Example createResults()
232   {
233     Example results = new Example(getDocument());
234     addItem(results);
235     return results;
236   }
237
238   public Def createDef()
239   {
240     Def def = new Def(getDocument());
241     addItem(def);
242     return def;
243   }
244
245   public FormattedTextWithAnchors createNote()
246   {
247     FormattedTextWithAnchors note = new FormattedTextWithAnchors(getDocument());
248     addItem(new NamedText("Note", note));
249     return note;
250   }
251
252   public FormattedTextWithAnchors createWarn()
253   {
254     FormattedTextWithAnchors warning =
255       new FormattedTextWithAnchors(getDocument());
256     addItem(new NamedText("Warning", warning));
257     return warning;
258   }
259
260   public FormattedText createParents()
261   {
262     FormattedText parents = new FormattedText(getDocument());
263     addItem(new NamedText("child of", parents));
264     return parents;
265   }
266  
267   public FormattedText createDefault()
268   {
269     FormattedText def = new FormattedText(getDocument());
270     addItem(new NamedText("default", def));
271     return def;
272   }
273
274   public Glossary createGlossary()
275   {
276     Glossary glossary = new Glossary(getDocument());
277     addItem(glossary);
278     return glossary;
279   }
280  
281   public void writeLaTeXTop(PrintWriter JavaDoc out)
282     throws IOException JavaDoc
283   {
284     writeLaTeX(out);
285   }
286
287   public void writeLaTeX(PrintWriter JavaDoc out)
288     throws IOException JavaDoc
289   {
290     String JavaDoc label = getDocument().getDocumentPath().getUserPath() + ":" + _title;
291
292     label = label.replace(" ", "-");
293
294     out.println("\\label{" + label + "}");
295     out.println("\\hypertarget{" + label + "}{}");
296
297     super.writeLaTeX(out);
298
299     if (_type != null && _type.equals("defun"))
300       out.println("\\newpage");
301   }
302
303   abstract public void writeLaTeXEnclosed(PrintWriter JavaDoc out)
304     throws IOException JavaDoc;
305 }
306
Popular Tags