1 | package org.greenstone.gsdl3.gs3build.util;
|
---|
2 |
|
---|
3 | public class HTMLCText implements HTMLObject
|
---|
4 | { String text;
|
---|
5 | int start;
|
---|
6 | int end;
|
---|
7 |
|
---|
8 | public static final String HTML_TEXT_TYPE = "Text";
|
---|
9 |
|
---|
10 | public HTMLCText(String text, int start, int end)
|
---|
11 | { this.text = text;
|
---|
12 | this.start = start;
|
---|
13 | this.end = end;
|
---|
14 | }
|
---|
15 |
|
---|
16 | public String getHTMLType()
|
---|
17 | { return HTML_TEXT_TYPE;
|
---|
18 | }
|
---|
19 |
|
---|
20 | public int startPos()
|
---|
21 | { return this.start;
|
---|
22 | }
|
---|
23 |
|
---|
24 | public int endPos()
|
---|
25 | { return this.end;
|
---|
26 | }
|
---|
27 |
|
---|
28 | public boolean isEmpty()
|
---|
29 | { return emptyString(this.text);
|
---|
30 | }
|
---|
31 |
|
---|
32 | public static boolean emptyString(String s)
|
---|
33 | { int c;
|
---|
34 |
|
---|
35 | for (c = 0; c < s.length(); c ++)
|
---|
36 | { if (s.charAt(c) > 32)
|
---|
37 | { return false;
|
---|
38 | }
|
---|
39 | }
|
---|
40 | return true;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public static StringBuffer cleanString(StringBuffer buffer)
|
---|
44 | { int c;
|
---|
45 | int w;
|
---|
46 |
|
---|
47 | w = 0;
|
---|
48 | for (c = 0; c < buffer.length(); c ++)
|
---|
49 | { if (buffer.charAt(c) >= 32)
|
---|
50 | { if (buffer.charAt(c) == 32)
|
---|
51 | { if (w > 0 && buffer.charAt(w-1) > 32)
|
---|
52 | { buffer.setCharAt(w, buffer.charAt(c));
|
---|
53 | w ++;
|
---|
54 | }
|
---|
55 | }
|
---|
56 | else
|
---|
57 | { if (c != w)
|
---|
58 | { buffer.setCharAt(w, buffer.charAt(c));
|
---|
59 | }
|
---|
60 | w ++;
|
---|
61 | }
|
---|
62 | }
|
---|
63 | else
|
---|
64 | { if (w > 0 && buffer.charAt(w-1) > 32)
|
---|
65 | { buffer.setCharAt(w,' ');
|
---|
66 | w ++;
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 | buffer.setLength(w);
|
---|
71 | return buffer;
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * nullString; used by initialisation for checking for
|
---|
76 | * non-blank content (ie. text other than just spaces/returns)
|
---|
77 | * see constructor (ie HTMLBlockList) methods below for role of
|
---|
78 | * this in the larger plan of things
|
---|
79 | */
|
---|
80 | public boolean nullString()
|
---|
81 | { int ch;
|
---|
82 |
|
---|
83 | if (text != null)
|
---|
84 | { for (ch = 0; ch < text.length(); ch ++)
|
---|
85 | { if (text.charAt(ch) > ' ')
|
---|
86 | { return false;
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|
90 | return true;
|
---|
91 | }
|
---|
92 |
|
---|
93 | public String toString()
|
---|
94 | { return this.text;
|
---|
95 | }
|
---|
96 |
|
---|
97 | public String toString(boolean cleaned)
|
---|
98 | { if (cleaned == false)
|
---|
99 | { return toString();
|
---|
100 | }
|
---|
101 | else
|
---|
102 | { return HTMLEntity.decodeText(this.text);
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|