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 java.io.IOException;
033: import java.io.PrintWriter;
034:
035: public abstract class Section extends ContainerNode {
036: protected FormattedTextWithAnchors _description;
037: protected String _name;
038: protected String _title;
039: protected String _version;
040: protected String _type;
041:
042: private String _parentHref;
043:
044: public Section(Document document) {
045: this (document, "");
046: }
047:
048: public Section(Document document, String parentHref) {
049: super (document);
050: _parentHref = parentHref;
051: }
052:
053: //
054: // XXX: Stubbed
055: //
056:
057: public void setOccur(String occur) {
058: }
059:
060: public void setLocalTOCIndent(String localTOCIndent) {
061: }
062:
063: public void setVersion(String version) {
064: _version = version;
065: }
066:
067: public void setName(String name) {
068: _name = name;
069: }
070:
071: public void setProduct(String product) {
072: }
073:
074: public void setIndex(String index) {
075: }
076:
077: //
078: // XXX: End stubbed
079: //
080:
081: public void setType(String type) {
082: _type = type;
083: }
084:
085: public void setTitle(String title) {
086: _title = title;
087: }
088:
089: public String getName() {
090: return _name;
091: }
092:
093: public String getTitle() {
094: return _title;
095: }
096:
097: public String getHref() {
098: if (_name != null)
099: return cleanHref(_name);
100: else
101: return cleanHref(_title);
102: }
103:
104: public static String cleanHref(String href) {
105: if (href == null)
106: return href;
107:
108: StringBuilder sb = new StringBuilder();
109:
110: for (int i = 0; i < href.length(); i++) {
111: char ch = href.charAt(i);
112:
113: switch (ch) {
114: case '<':
115: case '>':
116: case '(':
117: case ')':
118: case '?':
119: break;
120:
121: default:
122: sb.append(ch);
123: break;
124: }
125: }
126:
127: return sb.toString();
128: }
129:
130: public Defun createDefun() {
131: Defun defun = new Defun(getDocument());
132: addItem(defun);
133: return defun;
134: }
135:
136: public DefinitionList createDl() {
137: DefinitionList list = new DefinitionList(getDocument());
138: addItem(list);
139: return list;
140: }
141:
142: public FormattedTextWithAnchors createDescription() {
143: _description = new FormattedTextWithAnchors(getDocument());
144: return _description;
145: }
146:
147: public BlockQuote createBlockquote() {
148: BlockQuote blockQuote = new BlockQuote(getDocument());
149: addItem(blockQuote);
150: return blockQuote;
151: }
152:
153: public Center createCenter() {
154: Center center = new Center(getDocument());
155: addItem(center);
156: return center;
157: }
158:
159: public Paragraph createP() {
160: Paragraph paragraph = new Paragraph(getDocument());
161: addItem(paragraph);
162: return paragraph;
163: }
164:
165: public PreFormattedText createPre() {
166: PreFormattedText pretext = new PreFormattedText(getDocument());
167: addItem(pretext);
168: return pretext;
169: }
170:
171: public OrderedList createOl() {
172: OrderedList orderedList = new OrderedList(getDocument());
173: addItem(orderedList);
174: return orderedList;
175: }
176:
177: public UnorderedList createUl() {
178: UnorderedList unorderedList = new UnorderedList(getDocument());
179: addItem(unorderedList);
180: return unorderedList;
181: }
182:
183: public Figure createFigure() {
184: Figure figure = new Figure(getDocument());
185: addItem(figure);
186: return figure;
187: }
188:
189: public Example createExample() {
190: Example example = new Example(getDocument());
191: addItem(example);
192: return example;
193: }
194:
195: public Table createTable() {
196: Table table = new Table(getDocument());
197: addItem(table);
198: return table;
199: }
200:
201: public DefinitionTable createDeftable() {
202: DefinitionTable definitionTable = new DefinitionTable(
203: getDocument());
204: addItem(definitionTable);
205: return definitionTable;
206: }
207:
208: public DefinitionTable createDeftableChildtags() {
209: DefinitionTable definitionTable = new DefinitionTable(
210: getDocument());
211: addItem(definitionTable);
212: return definitionTable;
213: }
214:
215: public DefinitionTable createDeftableParameters() {
216: DefinitionTable definitionTable = new DefinitionTable(
217: getDocument());
218: addItem(definitionTable);
219: return definitionTable;
220: }
221:
222: public Example createResults() {
223: Example results = new Example(getDocument());
224: addItem(results);
225: return results;
226: }
227:
228: public Def createDef() {
229: Def def = new Def(getDocument());
230: addItem(def);
231: return def;
232: }
233:
234: public FormattedTextWithAnchors createNote() {
235: FormattedTextWithAnchors note = new FormattedTextWithAnchors(
236: getDocument());
237: addItem(new NamedText("Note", note));
238: return note;
239: }
240:
241: public FormattedTextWithAnchors createWarn() {
242: FormattedTextWithAnchors warning = new FormattedTextWithAnchors(
243: getDocument());
244: addItem(new NamedText("Warning", warning));
245: return warning;
246: }
247:
248: public FormattedText createParents() {
249: FormattedText parents = new FormattedText(getDocument());
250: addItem(new NamedText("child of", parents));
251: return parents;
252: }
253:
254: public FormattedText createDefault() {
255: FormattedText def = new FormattedText(getDocument());
256: addItem(new NamedText("default", def));
257: return def;
258: }
259:
260: public Glossary createGlossary() {
261: Glossary glossary = new Glossary(getDocument());
262: addItem(glossary);
263: return glossary;
264: }
265:
266: public void writeLaTeXTop(PrintWriter out) throws IOException {
267: writeLaTeX(out);
268: }
269:
270: public void writeLaTeX(PrintWriter out) throws IOException {
271: String label = getDocument().getDocumentPath().getUserPath()
272: + ":" + _title;
273:
274: label = label.replace(" ", "-");
275:
276: out.println("\\label{" + label + "}");
277: out.println("\\hypertarget{" + label + "}{}");
278:
279: super .writeLaTeX(out);
280:
281: if (_type != null && _type.equals("defun"))
282: out.println("\\newpage");
283: }
284:
285: abstract public void writeLaTeXEnclosed(PrintWriter out)
286: throws IOException;
287: }
|