1 package org.catacomb.xdoc;
2
3 import org.catacomb.interlish.structure.Page;
4 import org.catacomb.interlish.util.JUtil;
5
6 public class HTMLPage implements Page {
7
8
9 String htmlTemplate;
10
11 String htmlPageText;
12
13 String sourceText;
14
15
16 public final static int PLAIN_TEXT = 1;
17 public final static int DASSIE_TEXT = 2;
18
19 public int sourceStyle = PLAIN_TEXT;
20
21
22
23 public HTMLPage() {
24 htmlPageText = "";
25 }
26
27
28 public HTMLPage(String s) {
29 sourceText = s;
30 htmlPageText = null;
31 }
32
33 public HTMLPage(String s, int iss) {
34 sourceText = s;
35 sourceStyle = iss;
36 htmlPageText = null;
37 }
38
39
40
41 public void setSourceStyle(int iss) {
42 sourceStyle = iss;
43 }
44
45
46
47
48
49 public void loadDefault() {
50 htmlPageText = JUtil.getRelativeResource(this, "homePageHTML.txt");
51 }
52
53
54 public String getHTMLText() {
55 if (htmlPageText == null && sourceText != null) {
56 wrapText(sourceText);
57 }
58 return htmlPageText;
59 }
60
61 public void setSourceText(String s) {
62 sourceText = s;
63 htmlPageText = null;
64 }
65
66 public void setSourceDassieText(String s) {
67 sourceStyle = DASSIE_TEXT;
68 sourceText = s;
69 htmlPageText = null;
70 }
71
72
73
74
75 private String getHTMLTemplate() {
76 if (htmlTemplate == null) {
77 htmlTemplate = JUtil.getRelativeResource(this, "baseTemplateHTML.txt");
78 }
79 return htmlTemplate;
80 }
81
82
83
84 public void wrapText(String txt) {
85 String sr = null;
86 if (sourceStyle == PLAIN_TEXT) {
87 sr = wrapPlainString(txt);
88 } else {
89 sr = wrapDassieString(txt);
90 }
91 wrapHTMLText(sr);
92 }
93
94
95
96
97
98
99 private String wrapPlainString(String txtin) {
100 String txt = txtin;
101 StringBuffer textSB = new StringBuffer();
102
103 textSB.append("<p>");
104
105 txt = txt.replaceAll(" -p- ", " </p>\n<p> ");
106 txt = txt.replaceAll(" -br- ", " <br>\n ");
107
108 textSB.append(txt);
109
110 textSB.append("</p>");
111
112 return textSB.toString();
113 }
114
115
116
117 public String wrapDassieString(String txt) {
118
119 String ret = TextTagger.getTagger().tagText(txt);
120
121
122 return ret;
123 }
124
125
126
127 public void wrapHTMLText(String s) {
128 String txt = getHTMLTemplate();
129 int ibo = txt.indexOf("BODY");
130
131 htmlPageText = txt.substring(0, ibo) + s + txt.substring(ibo+4, txt.length());
132 }
133
134
135 public void loadText(String fnm) {
136 htmlPageText = JUtil.getRelativeResource(this, fnm);
137 }
138
139
140 }