1 | package org.expeditee.io;
|
---|
2 |
|
---|
3 | import java.io.IOException;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import org.expeditee.gui.Frame;
|
---|
7 | import org.expeditee.items.Item;
|
---|
8 | import org.expeditee.items.Picture;
|
---|
9 | import org.expeditee.items.Text;
|
---|
10 |
|
---|
11 | public class HTMLBWriter extends DefaultTreeWriter {
|
---|
12 |
|
---|
13 | private int _indent = 0;
|
---|
14 |
|
---|
15 | private static final String INDENT = " ";
|
---|
16 |
|
---|
17 | @Override
|
---|
18 | protected void initialise(Frame start) throws IOException {
|
---|
19 | _format = ".html";
|
---|
20 | super.initialise(start);
|
---|
21 |
|
---|
22 | _writer.write("<HTML>" + ItemWriter.NEW_LINE);
|
---|
23 | _writer.write("<HEAD>" + ItemWriter.NEW_LINE);
|
---|
24 | _writer.write("</HEAD>" + ItemWriter.NEW_LINE);
|
---|
25 | _writer.write("<BODY>" + ItemWriter.NEW_LINE);
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | protected String finaliseTree() throws IOException {
|
---|
30 | _writer.write("</BODY>" + ItemWriter.NEW_LINE);
|
---|
31 | return super.finaliseTree();
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | protected void writeStartLink(Item linker) throws IOException {
|
---|
36 | _indent++;
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Override
|
---|
40 | protected void writeEndLink(Item linker) throws IOException {
|
---|
41 | _indent--;
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Override
|
---|
45 | protected void writeTitle(Text toWrite, List<Item> items)
|
---|
46 | throws IOException {
|
---|
47 | String heading = toWrite.getTextNoList();
|
---|
48 | String tag = "H" + (_indent + 1);
|
---|
49 | // indenting for tag
|
---|
50 | indent();
|
---|
51 | _writer.write("<" + tag + ">" + heading + "</" + tag + ">"
|
---|
52 | + ItemWriter.NEW_LINE);
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Override
|
---|
56 | protected void writeText(Text text) throws IOException {
|
---|
57 | indent();
|
---|
58 | _writer.write("<p>");
|
---|
59 | _writer.write(text.getTextNoList().replace('\n', ' '));
|
---|
60 | _writer.write("</p>" + ItemWriter.NEW_LINE);
|
---|
61 | }
|
---|
62 |
|
---|
63 | private void indent() throws IOException {
|
---|
64 | for (int i = 0; i < _indent; i++)
|
---|
65 | _writer.write(INDENT);
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Override
|
---|
69 | protected void writePicture(Picture pic) throws IOException {
|
---|
70 | Text source = pic.getText();
|
---|
71 |
|
---|
72 | String line = source.getFirstLine();
|
---|
73 | line = line.substring(line.indexOf(":") + 1).trim();
|
---|
74 |
|
---|
75 | indent();
|
---|
76 |
|
---|
77 | _writer.write("<img src = '../images/" + line + "'>");
|
---|
78 | _writer.write(ItemWriter.NEW_LINE);
|
---|
79 | }
|
---|
80 | }
|
---|