1 29 30 package com.caucho.xtpdoc; 31 32 import java.io.IOException ; 33 import java.io.PrintWriter ; 34 35 public abstract class Section extends ContainerNode { 36 protected FormattedTextWithAnchors _description; 37 protected String _name; 38 protected String _title; 39 protected String _version; 40 protected String _type; 41 42 private String _parentHref; 43 44 public Section(Document document) 45 { 46 this(document, ""); 47 } 48 49 public Section(Document document, String parentHref) 50 { 51 super(document); 52 _parentHref = parentHref; 53 } 54 55 56 60 public void setOccur(String occur) 61 { 62 } 63 64 public void setLocalTOCIndent(String localTOCIndent) 65 { 66 } 67 68 public void setVersion(String version) 69 { 70 _version = version; 71 } 72 73 public void setName(String name) 74 { 75 _name = name; 76 } 77 78 public void setProduct(String product) 79 { 80 } 81 82 public void setIndex(String index) 83 { 84 } 85 86 90 public void setType(String type) 91 { 92 _type = type; 93 } 94 95 public void setTitle(String title) 96 { 97 _title = title; 98 } 99 100 public String getName() 101 { 102 return _name; 103 } 104 105 public String getTitle() 106 { 107 return _title; 108 } 109 110 public String getHref() 111 { 112 if (_name != null) 113 return cleanHref(_name); 114 else 115 return cleanHref(_title); 116 } 117 118 public static String cleanHref(String href) 119 { 120 if (href == null) 121 return href; 122 123 StringBuilder sb = new StringBuilder (); 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 out) 282 throws IOException 283 { 284 writeLaTeX(out); 285 } 286 287 public void writeLaTeX(PrintWriter out) 288 throws IOException 289 { 290 String 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 out) 304 throws IOException ; 305 } 306 | Popular Tags |