source: trunk/src/org/expeditee/io/oldHTMLWriter.java@ 457

Last change on this file since 457 was 376, checked in by ra33, 16 years ago
File size: 2.8 KB
Line 
1package org.expeditee.io;
2
3import java.io.IOException;
4import java.io.Writer;
5import java.util.List;
6
7import org.expeditee.gui.Frame;
8import org.expeditee.items.Item;
9import org.expeditee.items.Picture;
10import org.expeditee.items.Text;
11
12public class oldHTMLWriter extends DefaultTreeWriter {
13
14 private int _indent = 0;
15
16 private static final String INDENT = " ";
17
18 @Override
19 protected void initialise(Frame start, Writer writer) throws IOException {
20 _format = ".html";
21 super.initialise(start, writer);
22 }
23
24 @Override
25 protected void writeStartLink(Item linker) throws IOException {
26 // only output text items
27 if (!(linker instanceof Text)) {
28 _indent++;
29 return;
30 }
31
32 Text text = (Text) linker;
33 List<String> toWrite = text.getTextList();
34
35 String first = toWrite.get(0);
36 int ind = first.indexOf(":");
37
38 if (ind > 0) {
39 String tag = first.substring(0, ind);
40 String remain = first.substring(ind + 1);
41
42 if (remain.length() > 0) {
43 // indenting for comments
44 indent();
45 _writer.write("<!-- " + remain);
46
47 for (int i = 1; i < toWrite.size(); i++)
48 _writer.write(ItemWriter.NEW_LINE + toWrite.get(i));
49
50 _writer.write(" -->" + ItemWriter.NEW_LINE);
51 }
52
53 // indenting for tag
54 indent();
55 _writer.write("<" + tag + ">" + ItemWriter.NEW_LINE);
56 }
57
58 _indent++;
59 }
60
61 @Override
62 protected void writeEndLink(Item linker) throws IOException {
63 _indent--;
64
65 // only output text items
66 if (!(linker instanceof Text))
67 return;
68
69 Text text = (Text) linker;
70 List<String> toWrite = text.getTextList();
71
72 String first = toWrite.get(0);
73 int ind = first.indexOf(":");
74
75 if (ind > 0) {
76 String tag = first.substring(0, ind);
77
78 // indenting for tag
79 indent();
80 _writer.write("</" + tag + ">" + ItemWriter.NEW_LINE);
81 }
82
83 }
84
85 @Override
86 protected void writeText(Text text) throws IOException {
87 for (String s : text.getTextList()) {
88
89 indent();
90 // check if the first word is proceeded by a :
91 int firstColonIndex = s.indexOf(":");
92 int firstSpaceIndex = s.indexOf(" ");
93 if (firstColonIndex > 0 && firstColonIndex < firstSpaceIndex) {
94 _writer.write("<" + s.substring(0, firstColonIndex) + ">");
95 if (firstColonIndex < s.length())
96 _writer.write(s.substring(firstColonIndex + 1));
97 _writer.write("</" + s.substring(0, firstColonIndex) + ">");
98 } else
99 _writer.write(s);
100 _writer.write(ItemWriter.NEW_LINE);
101 }
102 }
103
104 private void indent() throws IOException {
105 for (int i = 0; i < _indent; i++)
106 _writer.write(INDENT);
107 }
108
109 @Override
110 protected void writePicture(Picture pic) throws IOException {
111 Text source = pic.getSource();
112
113 String line = source.getFirstLine();
114 line = line.substring(line.indexOf(":") + 1).trim();
115
116 indent();
117
118 _writer.write("<img src = '../images/" + line + "'>");
119 _writer.write(ItemWriter.NEW_LINE);
120 }
121}
Note: See TracBrowser for help on using the repository browser.