1 | package org.expeditee.io;
|
---|
2 |
|
---|
3 | import java.io.IOException;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import org.expeditee.items.Dot;
|
---|
7 | import org.expeditee.items.Item;
|
---|
8 | import org.expeditee.items.Line;
|
---|
9 | import org.expeditee.items.Picture;
|
---|
10 | import org.expeditee.items.Text;
|
---|
11 |
|
---|
12 | public abstract class ItemWriter {
|
---|
13 |
|
---|
14 | public static final String NEW_LINE = System.getProperty("line.separator");
|
---|
15 |
|
---|
16 | protected void writeTitle(Text toWrite, List<Item> items)
|
---|
17 | throws IOException {
|
---|
18 | }
|
---|
19 |
|
---|
20 | protected void writeAnnotationTitle(Text toWrite) throws IOException {
|
---|
21 | }
|
---|
22 |
|
---|
23 | protected void writeItem(Item toWrite) throws IOException {
|
---|
24 | if (toWrite.isAnnotation()) {
|
---|
25 | writeAnnotationItem(toWrite);
|
---|
26 | return;
|
---|
27 | }
|
---|
28 |
|
---|
29 | if (toWrite instanceof Text)
|
---|
30 | writeText((Text) toWrite);
|
---|
31 |
|
---|
32 | if (toWrite instanceof Picture)
|
---|
33 | writePicture((Picture) toWrite);
|
---|
34 |
|
---|
35 | if (toWrite instanceof Line)
|
---|
36 | writeLine((Line) toWrite);
|
---|
37 |
|
---|
38 | if (toWrite instanceof Dot)
|
---|
39 | writeDot((Dot) toWrite);
|
---|
40 | }
|
---|
41 |
|
---|
42 | protected void writeAnnotationItem(Item toWrite) throws IOException {
|
---|
43 | if (toWrite instanceof Text)
|
---|
44 | writeAnnotationText((Text) toWrite);
|
---|
45 |
|
---|
46 | if (toWrite instanceof Picture)
|
---|
47 | writeAnnotationPicture((Picture) toWrite);
|
---|
48 |
|
---|
49 | if (toWrite instanceof Line)
|
---|
50 | writeAnnotationLine((Line) toWrite);
|
---|
51 |
|
---|
52 | if (toWrite instanceof Dot)
|
---|
53 | writeAnnotationDot((Dot) toWrite);
|
---|
54 | }
|
---|
55 |
|
---|
56 | protected void writeAnnotationText(Text toWrite) throws IOException {
|
---|
57 | }
|
---|
58 |
|
---|
59 | protected void writeAnnotationPicture(Picture toWrite) throws IOException {
|
---|
60 | }
|
---|
61 |
|
---|
62 | protected void writeAnnotationLine(Line toWrite) throws IOException {
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected void writeAnnotationDot(Dot toWrite) throws IOException {
|
---|
66 | }
|
---|
67 |
|
---|
68 | protected void writeText(Text toWrite) throws IOException {
|
---|
69 | }
|
---|
70 |
|
---|
71 | protected void writePicture(Picture toWrite) throws IOException {
|
---|
72 | }
|
---|
73 |
|
---|
74 | protected void writeLine(Line toWrite) throws IOException {
|
---|
75 | }
|
---|
76 |
|
---|
77 | protected void writeDot(Dot toWrite) throws IOException {
|
---|
78 | }
|
---|
79 |
|
---|
80 | /*
|
---|
81 | * public static final String NEW_LINE =
|
---|
82 | * System.getProperty("line.separator");
|
---|
83 | *
|
---|
84 | * protected BufferedWriter _writer = null;
|
---|
85 | *
|
---|
86 | * public FrameWriter(String format){}
|
---|
87 | *
|
---|
88 | * public String initialise(String path, String filename) throws
|
---|
89 | * IOException{ if(path.charAt(path.length() - 1) != File.separatorChar)
|
---|
90 | * path += File.separator;
|
---|
91 | *
|
---|
92 | * _writer = new BufferedWriter(new FileWriter(path.toLowerCase() +
|
---|
93 | * filename.toLowerCase()));
|
---|
94 | *
|
---|
95 | * return filename; }
|
---|
96 | *
|
---|
97 | * public void initialise(Frame toWrite) throws IOException{ String name =
|
---|
98 | * toWrite.getFrameset().toLowerCase(); if(name.endsWith(".")) name =
|
---|
99 | * name.substring(0, name.length() - 1);
|
---|
100 | *
|
---|
101 | * String filepath = toWrite.path + name;
|
---|
102 | *
|
---|
103 | * String filename = name + "." + toWrite.getFrameNumber();
|
---|
104 | *
|
---|
105 | * initialise(filepath, filename); }
|
---|
106 | *
|
---|
107 | * public void write(Frame toWrite) throws IOException{ initialise(toWrite);
|
---|
108 | *
|
---|
109 | * writeFrame(toWrite);
|
---|
110 | *
|
---|
111 | * finalise(); }
|
---|
112 | *
|
---|
113 | * public void writeFrame(Frame toWrite) throws IOException{ for(Item i :
|
---|
114 | * toWrite.getItems()) writeItem(i, 0); }
|
---|
115 | *
|
---|
116 | * public void writeItem(Item item, int indent) throws IOException{ if(item
|
---|
117 | * instanceof Text) writeText((Text) item, indent);
|
---|
118 | *
|
---|
119 | * if(item instanceof Dot) writeDot((Dot) item);
|
---|
120 | *
|
---|
121 | * if(item instanceof Line) writeLine((Line) item);
|
---|
122 | *
|
---|
123 | * if(item instanceof Picture) writePicture((Picture) item); }
|
---|
124 | *
|
---|
125 | * public void writeStartLinkItem(Item item, int indent) throws IOException{ }
|
---|
126 | *
|
---|
127 | * public void writeEndLinkItem(Item item, int indent) throws IOException{ }
|
---|
128 | *
|
---|
129 | * protected void writeText(Text text, int indent) throws IOException{}
|
---|
130 | *
|
---|
131 | * protected void writeDot(Dot dot) throws IOException{}
|
---|
132 | *
|
---|
133 | * protected void writeLine(Line line) throws IOException{}
|
---|
134 | *
|
---|
135 | * protected void writePicture(Picture pic) throws IOException{}
|
---|
136 | *
|
---|
137 | * public abstract void insertLine() throws IOException;
|
---|
138 | *
|
---|
139 | * public abstract void indent() throws IOException;
|
---|
140 | *
|
---|
141 | * public void finalise() throws IOException{ _writer.flush();
|
---|
142 | * _writer.close(); _writer = null; }
|
---|
143 | */
|
---|
144 | }
|
---|