source: trunk/src/org/expeditee/io/AbstractHTMLWriter.java@ 80

Last change on this file since 80 was 80, checked in by ra33, 16 years ago

Added some more unit tests
Did a bunch of refactoring
AND added a few new features... @b @v were the most significant

File size: 1.8 KB
Line 
1package org.expeditee.io;
2
3import java.io.File;
4import java.io.IOException;
5
6import org.expeditee.gui.Frame;
7import org.expeditee.gui.FrameGraphics;
8import org.expeditee.items.Item;
9
10public abstract class AbstractHTMLWriter extends DefaultTreeWriter {
11 private int _indent = 0;
12
13 private static final String INDENT = " ";
14
15 private static final String FILE_FOLDER_SUFFIX = "_files";
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("<title>" + start.getTitle());
25 _writer.write("</title>" + ItemWriter.NEW_LINE);
26 _writer.write("</head>" + ItemWriter.NEW_LINE);
27 _writer.write("<body>" + ItemWriter.NEW_LINE);
28 }
29
30 private String _filesFolderName = null;
31
32 protected String getFilesFolder() {
33 if (_filesFolderName == null) {
34 _filesFolderName = _filename.substring(0, _filename.lastIndexOf('.')) + FILE_FOLDER_SUFFIX;
35 File dir = new File (_filesFolderName);
36 _filesFolderName = dir.getName();
37 if (!dir.exists()) {
38 try {
39 dir.mkdirs();
40 } catch (Exception e) {
41 FrameGraphics.ErrorMessage("Could not create folder: "
42 + dir.getName());
43 _filesFolderName = null;
44 return "";
45 }
46 }
47 }
48
49 return _filesFolderName + File.separator;
50 }
51
52 @Override
53 protected String finaliseTree() throws IOException {
54 _writer.write("</body>" + ItemWriter.NEW_LINE);
55 return super.finaliseTree();
56 }
57
58 @Override
59 protected void writeStartLink(Item linker) throws IOException {
60 _indent++;
61 }
62
63 @Override
64 protected void writeEndLink(Item linker) throws IOException {
65 _indent--;
66 }
67
68 protected void indent() throws IOException {
69 for (int i = 0; i < _indent; i++)
70 _writer.write(INDENT);
71 }
72
73 protected int getIndent() {
74 return _indent;
75 }
76}
Note: See TracBrowser for help on using the repository browser.