OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [tools/] [gnu/] [classpath/] [tools/] [doclets/] [htmldoclet/] [HtmlPage.java] - Blame information for rev 779

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 779 jeremybenn
/* gnu.classpath.tools.doclets.htmldoclet.HtmlPage
2
   Copyright (C) 2004 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19
02111-1307 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
package gnu.classpath.tools.doclets.htmldoclet;
39
 
40
import gnu.classpath.tools.IOToolkit;
41
 
42
import java.io.BufferedWriter;
43
import java.io.File;
44
import java.io.FileOutputStream;
45
import java.io.FileWriter;
46
import java.io.InputStream;
47
import java.io.IOException;
48
import java.io.OutputStream;
49
import java.io.OutputStreamWriter;
50
import java.io.PrintWriter;
51
import java.io.Reader;
52
import java.io.Writer;
53
 
54
import java.util.Collection;
55
import java.util.Collections;
56
import java.util.HashMap;
57
import java.util.Iterator;
58
import java.util.Map;
59
 
60
import com.sun.javadoc.Tag;
61
 
62
/**
63
 *  Allows outputting an HTML document without having to build the
64
 *  document tree in-memory.
65
 */
66
public class HtmlPage
67
{
68
   private File file;
69
   private PrintWriter out;
70
   private String pathToRoot;
71
   private String docType;
72
   private String baseUrl;
73
   private File rootDir;
74
 
75
   public static final String DOCTYPE_FRAMESET = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">";
76
 
77
   public HtmlPage(File file, String pathToRoot, String encoding, String baseUrl, File rootDir)
78
      throws IOException
79
   {
80
      this(file, pathToRoot, encoding, baseUrl, rootDir, "<!DOCTYPE html PUBLIC \"-//gnu.org///DTD XHTML 1.1 plus Target 1.0//EN\" \"" + pathToRoot + "/resources/xhtml11-target10.dtd\">");
81
   }
82
 
83
   public HtmlPage(File file, String pathToRoot, String encoding, String baseUrl, File rootDir, String docType)
84
      throws IOException
85
   {
86
      this.file = file;
87
      OutputStream fileOut = new FileOutputStream(file);
88
      Writer writer;
89
      if (null != encoding) {
90
         writer = new OutputStreamWriter(fileOut,
91
                                         encoding);
92
      }
93
      else {
94
         writer = new OutputStreamWriter(fileOut);
95
      }
96
      this.out = new PrintWriter(new BufferedWriter(writer));
97
      this.pathToRoot = pathToRoot;
98
      this.docType = docType;
99
      this.baseUrl = baseUrl;
100
      this.rootDir = rootDir;
101
   }
102
 
103
   public void beginElement(String elementName)
104
   {
105
      print('<');
106
      print(elementName);
107
      print('>');
108
   }
109
 
110
   public void beginElement(String elementName, String attributeName, String attributeValue)
111
   {
112
      print('<');
113
      print(elementName);
114
      print(' ');
115
      print(attributeName);
116
      print('=');
117
      print('\"');
118
      print(attributeValue);
119
      print('\"');
120
      print('>');
121
   }
122
 
123
   public void beginElement(String elementName, String[] attributeNames, String[] attributeValues)
124
   {
125
      print('<');
126
      print(elementName);
127
      for (int i=0; i<attributeNames.length; ++i) {
128
         if (null != attributeValues[i]) {
129
            print(' ');
130
            print(attributeNames[i]);
131
            print('=');
132
            print('\"');
133
            print(attributeValues[i]);
134
            print('\"');
135
         }
136
      }
137
      print('>');
138
   }
139
 
140
   public void beginElement(String elementName, String attributeName, String attributeValue, String[] attributeNames, String[] attributeValues)
141
   {
142
      print('<');
143
      print(elementName);
144
      print(' ');
145
      print(attributeName);
146
      print('=');
147
      print('\"');
148
      print(attributeValue);
149
      print('\"');
150
      if (null != attributeNames) {
151
         for (int i=0; i<attributeNames.length; ++i) {
152
            if (null != attributeValues[i]) {
153
               print(' ');
154
               print(attributeNames[i]);
155
               print('=');
156
               print('\"');
157
               print(attributeValues[i]);
158
               print('\"');
159
            }
160
         }
161
      }
162
      print('>');
163
   }
164
 
165
   public void atomicElement(String elementName)
166
   {
167
      print('<');
168
      print(elementName);
169
      print("/>");
170
   }
171
 
172
   public void atomicElement(String elementName, String attributeName, String attributeValue)
173
   {
174
      print('<');
175
      print(elementName);
176
      print(' ');
177
      print(attributeName);
178
      print('=');
179
      print('\"');
180
      print(attributeValue);
181
      print('\"');
182
      print("/>");
183
   }
184
 
185
   public void atomicElement(String elementName, String[] attributeNames, String[] attributeValues)
186
   {
187
      print('<');
188
      print(elementName);
189
      for (int i=0; i<attributeNames.length; ++i) {
190
         if (null != attributeValues[i]) {
191
            print(' ');
192
            print(attributeNames[i]);
193
            print('=');
194
            print('\"');
195
            print(attributeValues[i]);
196
            print('\"');
197
         }
198
      }
199
      print("/>");
200
   }
201
 
202
 
203
   public void endElement(String elementName)
204
   {
205
      print("</");
206
      print(elementName);
207
      print('>');
208
   }
209
 
210
 
211
   public void beginDiv(CssClass cssClass)
212
   {
213
      String[] divAttributeNames = cssClass.getAttributeNames();
214
      String[] divAttributeValues = cssClass.getAttributeValues();
215
      if (null == divAttributeNames) {
216
         divAttributeNames = new String[0];
217
      }
218
      if (null == divAttributeValues) {
219
         divAttributeValues = new String[0];
220
      }
221
 
222
      String[] attributeNames = new String[1 + divAttributeNames.length];
223
      String[] attributeValues = new String[1 + divAttributeValues.length];
224
 
225
      System.arraycopy(divAttributeNames, 0, attributeNames, 1, divAttributeNames.length);
226
      System.arraycopy(divAttributeValues, 0, attributeValues, 1, divAttributeNames.length);
227
 
228
      attributeNames[0] = "class";
229
      attributeValues[0] = cssClass.getName();
230
 
231
      beginElement(cssClass.getDivElementName(), attributeNames, attributeValues);
232
      if (null != cssClass.getInnerElementName()) {
233
         beginElement(cssClass.getInnerElementName());
234
      }
235
   }
236
 
237
   public void endDiv(CssClass cssClass)
238
   {
239
      if (null != cssClass.getInnerElementName()) {
240
         endElement(cssClass.getInnerElementName());
241
      }
242
      endElement(cssClass.getDivElementName());
243
   }
244
 
245
   public void beginSpan(CssClass cssClass)
246
   {
247
      beginElement(cssClass.getSpanElementName(), "class", cssClass.getName());
248
   }
249
 
250
   public void endSpan(CssClass cssClass)
251
   {
252
      endElement(cssClass.getSpanElementName());
253
   }
254
 
255
   public void hr()
256
   {
257
      atomicElement("hr");
258
   }
259
 
260
   public void br()
261
   {
262
      atomicElement("br");
263
   }
264
 
265
   public void print(String text)
266
   {
267
      out.print(text);
268
   }
269
 
270
   public void print(char c)
271
   {
272
      out.print(c);
273
   }
274
 
275
   public void div(CssClass cssClass, String contents)
276
   {
277
      beginDiv(cssClass);
278
      print(contents);
279
      endDiv(cssClass);
280
   }
281
 
282
   public void span(CssClass cssClass, String contents)
283
   {
284
      beginSpan(cssClass);
285
      print(contents);
286
      endSpan(cssClass);
287
   }
288
 
289
   public void beginPage(String title, String charset, Map stylesheets)
290
      throws IOException
291
   {
292
      beginPage(title, charset, Collections.EMPTY_SET, stylesheets);
293
   }
294
 
295
   public void beginPage(String title, String charset,
296
                         Collection keywords, Map stylesheets)
297
      throws IOException
298
   {
299
      print("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\n");
300
      print(docType);
301
      print("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">");
302
      beginElement("head");
303
      beginElement("title");
304
      print(title);
305
      endElement("title");
306
      if (null != baseUrl && baseUrl.length() > 0) {
307
         StringBuffer url = new StringBuffer();
308
         url.append(baseUrl);
309
         if ('/' == url.charAt(url.length() - 1)) {
310
            url.delete(url.length() - 1, url.length());
311
         }
312
         url.append(file.getCanonicalPath().substring(rootDir.getCanonicalPath().length()));
313
         atomicElement("base",
314
                       new String[] { "href" },
315
                       new String[] { url.toString() });
316
      }
317
      beginElement("script",
318
                    new String[] { "src", "type" },
319
                    new String[] { pathToRoot + "/resources/gjdoc.js", "text/javascript" });
320
      print("<!-- this comment required for konqueror 3.2.2 -->");
321
      endElement("script");
322
      atomicElement("meta",
323
                    new String[] { "http-equiv", "content" },
324
                    new String[] { "Content-Type", "text/html; charset=" + charset });
325
      atomicElement("meta",
326
                    new String[] { "name", "content" },
327
                    new String[] { "generator", "GNU Gjdoc Standard Doclet" });
328
      Iterator keywordIt = keywords.iterator();
329
      while (keywordIt.hasNext()) {
330
         String keyword = (String)keywordIt.next();
331
         atomicElement("meta",
332
                       new String[] { "name", "content" },
333
                       new String[] { "keywords", keyword });
334
      }
335
 
336
      Iterator cssIt = stylesheets.keySet().iterator();
337
      while (cssIt.hasNext()) {
338
         String sheetName = (String)cssIt.next();
339
         String[] sheetFiles = (String[])stylesheets.get(sheetName);
340
 
341
         for (int i=0; i<sheetFiles.length; ++i) {
342
            String sheetFile = sheetFiles[i];
343
            atomicElement("link",
344
                          new String[] { "rel", "type", "href", "title" },
345
                          new String[] { "stylesheet", "text/css",
346
                                         pathToRoot + "/" + sheetFile, sheetName });
347
         }
348
      }
349
 
350
      endElement("head");
351
   }
352
 
353
   public void endPage()
354
   {
355
      endElement("html");
356
   }
357
 
358
   public void close()
359
   {
360
      out.close();
361
   }
362
 
363
   public void beginTable(CssClass cssClass)
364
   {
365
      beginElement("table", "class", cssClass.getName());
366
   }
367
 
368
   public void beginTable(CssClass cssClass, String[] attributeNames, String[] attributeValues)
369
   {
370
      beginElement("table", "class", cssClass.getName(), attributeNames, attributeValues);
371
   }
372
 
373
   public void beginRow()
374
   {
375
      beginElement("tr");
376
   }
377
 
378
   public void beginRow(CssClass cssClass)
379
   {
380
      beginElement("tr", "class", cssClass.getName(), cssClass.getAttributeNames(), cssClass.getAttributeValues());
381
   }
382
 
383
   public void beginRow(String attribute, String value)
384
   {
385
      beginElement("tr", attribute, value);
386
   }
387
 
388
   public void beginCell()
389
   {
390
      beginElement("td");
391
   }
392
 
393
   public void beginCell(String attribute, String value)
394
   {
395
      beginElement("td", attribute, value);
396
   }
397
 
398
   public void beginCell(CssClass cssClass)
399
   {
400
      beginElement("td", "class", cssClass.getName(), cssClass.getAttributeNames(), cssClass.getAttributeValues());
401
   }
402
 
403
   public void endCell()
404
   {
405
      endElement("td");
406
   }
407
 
408
   public void cell(CssClass cssClass, String contents)
409
   {
410
      beginCell(cssClass);
411
      print(contents);
412
      endCell();
413
   }
414
 
415
   public void endRow()
416
   {
417
      endElement("tr");
418
   }
419
 
420
   public void rowDiv(CssClass cssClass, String contents)
421
   {
422
      beginRow(cssClass);
423
      beginCell("colspan", "2");
424
      beginDiv(cssClass);
425
      print(contents);
426
      endDiv(cssClass);
427
      endCell();
428
      endRow();
429
   }
430
 
431
   public void endTable()
432
   {
433
      endElement("table");
434
   }
435
 
436
   public void beginAnchor(String href)
437
   {
438
      beginElement("a", "href", href);
439
   }
440
 
441
   public void beginAnchor(String href, String title)
442
   {
443
      beginElement("a",
444
                   new String[] { "href", "title" },
445
                   new String[] { href, title });
446
   }
447
 
448
   public void beginAnchor(String href, String title, String target)
449
   {
450
      beginElement("a",
451
                   new String[] { "href", "title", "target" },
452
                   new String[] { href, title, target });
453
   }
454
 
455
   public void endAnchor()
456
   {
457
      endElement("a");
458
   }
459
 
460
   public void anchor(String href, String label)
461
   {
462
      beginAnchor(href);
463
      print(label);
464
      endAnchor();
465
   }
466
 
467
   public void anchorName(String name)
468
   {
469
      atomicElement("a", new String[] { "name", "id" }, new String[] { name, name });
470
   }
471
 
472
   public String getPathToRoot()
473
   {
474
      return pathToRoot;
475
   }
476
 
477
   public void beginBody(CssClass cssClass)
478
   {
479
      beginBody(cssClass, true);
480
   }
481
 
482
   public void beginBody(CssClass cssClass, boolean setTitle)
483
   {
484
      if (setTitle) {
485
         beginElement("body",
486
                      new String[] { "class", "onload" },
487
                      new String[] { cssClass.getName(), "if(parent.contentPageLoaded)parent.contentPageLoaded(document.title)" }
488
                      );
489
      }
490
      else {
491
         beginElement("body",
492
                      new String[] { "class", "onload" },
493
                      new String[] { cssClass.getName(), "if(parent.contentPageLoaded)parent.contentPageLoaded()" }
494
                      );
495
      }
496
   }
497
 
498
   public void endBody()
499
   {
500
      endElement("body");
501
   }
502
 
503
   public void insert(Reader in)
504
      throws IOException
505
   {
506
      IOToolkit.copyStream(in, out);
507
   }
508
 
509
   public String createHrefString(String url, String content)
510
   {
511
      return createHrefString(url, content, null);
512
   }
513
 
514
   public String createHrefString(String url, String content, String title)
515
   {
516
      StringBuffer result = new StringBuffer();
517
      result.append("<a href=\"");
518
      result.append(url);
519
      result.append("\"");
520
      if (null != title) {
521
         result.append(" title=\"");
522
         result.append(title);
523
         result.append("\"");
524
      }
525
      result.append(">");
526
      result.append(content);
527
      result.append("</a>");
528
      return result.toString();
529
   }
530
 
531
   public File getFile()
532
   {
533
      return this.file;
534
   }
535
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.