01 /*
02 * [Adapted from BSD licence] Copyright (c) 2002 Terence Parr All rights
03 * reserved.
04 *
05 * Redistribution and use in source and binary forms, with or without
06 * modification, are permitted provided that the following conditions are met:
07 * 1. Redistributions of source code must retain the above copyright notice,
08 * this list of conditions and the following disclaimer. 2. Redistributions in
09 * binary form must reproduce the above copyright notice, this list of
10 * conditions and the following disclaimer in the documentation and/or other
11 * materials provided with the distribution. 3. The name of the author may not
12 * be used to endorse or promote products derived from this software without
13 * specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 package gate.wiki.antlr;
27
28 import java.io.*;
29
30 /**
31 * This class implements translation to HTML with WikiLinks and without headers.
32 * This is beneficial when making a segmented page, with different files being
33 * brought together, you might not want header and title information.
34 *
35 * @author tamara
36 *
37 */
38 public class WikiHTMLTarget extends HTMLTarget {
39
40
41 /**
42 * Keeps track of the heading numbering
43 */
44
45
46 public WikiHTMLTarget(){
47 this(new BufferedWriter(new OutputStreamWriter(System.out)));
48 }
49 public WikiHTMLTarget(Writer out){
50 this.out = out;
51 }
52 public String getTargetLanguage(){
53 return Tool.WIKI;
54 }
55
56
57
58 /** insert head.html if found */
59 public void begin(){
60 write("<!-- AUTOGENERATED ALL CHANGES WILL BE LOST -->\n");
61 fileContents = new StringBuffer("");
62 }
63 /** insert tail.html if found */
64 public void end(){
65 if(inContents){
66 inContents = false;
67 write(tableOfContents.toString());
68 write(fileContents.toString());
69 resetContents();
70 }
71
72 try{
73 out.flush();
74 }catch(IOException ioe){
75 System.err.println("Problem writing HTML output");
76 ioe.printStackTrace(System.err);
77 }
78 }
79
80
81
82 /**
83 * wikilinks should be implemented here. Support for checking for
84 * existing pages should also be implemented here.
85 */
86 public void wikilink(String url, String title) {
87 if(title == null){
88 title = url;
89 }
90 title = angleBracketsEscape(title);
91 write("<a href=\"" + url + "\">" + title + " WikiLink "+ "</a>");
92 }
93
94 public void title(String title){
95 writeln("<h1>" + title + "</h1>");
96 headingCount[1] = 1;
97 }
98
99 }
|