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

Last change on this file since 1510 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 3.5 KB
Line 
1/**
2 * oldHTMLWriter.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.io;
20
21import java.io.IOException;
22import java.io.Writer;
23import java.util.List;
24
25import org.expeditee.gui.Frame;
26import org.expeditee.items.Item;
27import org.expeditee.items.Picture;
28import org.expeditee.items.Text;
29
30public class oldHTMLWriter extends DefaultTreeWriter {
31
32 private int _indent = 0;
33
34 private static final String INDENT = " ";
35
36 @Override
37 protected void initialise(Frame start, Writer writer) throws IOException {
38 _format = ".html";
39 super.initialise(start, writer);
40 }
41
42 @Override
43 protected void writeStartLink(Item linker) throws IOException {
44 // only output text items
45 if (!(linker instanceof Text)) {
46 _indent++;
47 return;
48 }
49
50 Text text = (Text) linker;
51 List<String> toWrite = text.getTextList();
52
53 String first = toWrite.get(0);
54 int ind = first.indexOf(":");
55
56 if (ind > 0) {
57 String tag = first.substring(0, ind);
58 String remain = first.substring(ind + 1);
59
60 if (remain.length() > 0) {
61 // indenting for comments
62 indent();
63 _writer.write("<!-- " + remain);
64
65 for (int i = 1; i < toWrite.size(); i++)
66 _writer.write(ItemWriter.NEW_LINE + toWrite.get(i));
67
68 _writer.write(" -->" + ItemWriter.NEW_LINE);
69 }
70
71 // indenting for tag
72 indent();
73 _writer.write("<" + tag + ">" + ItemWriter.NEW_LINE);
74 }
75
76 _indent++;
77 }
78
79 @Override
80 protected void writeEndLink(Item linker) throws IOException {
81 _indent--;
82
83 // only output text items
84 if (!(linker instanceof Text))
85 return;
86
87 Text text = (Text) linker;
88 List<String> toWrite = text.getTextList();
89
90 String first = toWrite.get(0);
91 int ind = first.indexOf(":");
92
93 if (ind > 0) {
94 String tag = first.substring(0, ind);
95
96 // indenting for tag
97 indent();
98 _writer.write("</" + tag + ">" + ItemWriter.NEW_LINE);
99 }
100
101 }
102
103 @Override
104 protected void writeText(Text text) throws IOException {
105 for (String s : text.getTextList()) {
106
107 indent();
108 // check if the first word is proceeded by a :
109 int firstColonIndex = s.indexOf(":");
110 int firstSpaceIndex = s.indexOf(" ");
111 if (firstColonIndex > 0 && firstColonIndex < firstSpaceIndex) {
112 _writer.write("<" + s.substring(0, firstColonIndex) + ">");
113 if (firstColonIndex < s.length())
114 _writer.write(s.substring(firstColonIndex + 1));
115 _writer.write("</" + s.substring(0, firstColonIndex) + ">");
116 } else
117 _writer.write(s);
118 _writer.write(ItemWriter.NEW_LINE);
119 }
120 }
121
122 private void indent() throws IOException {
123 for (int i = 0; i < _indent; i++)
124 _writer.write(INDENT);
125 }
126
127 @Override
128 protected void writePicture(Picture pic) throws IOException {
129 Text source = pic.getSource();
130
131 String line = source.getFirstLine();
132 line = line.substring(line.indexOf(":") + 1).trim();
133
134 indent();
135
136 _writer.write("<img src = '../images/" + line + "'>");
137 _writer.write(ItemWriter.NEW_LINE);
138 }
139}
Note: See TracBrowser for help on using the repository browser.