source: trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/util/HTMLDocLocalHeading.java@ 7306

Last change on this file since 7306 was 5800, checked in by cs025, 21 years ago

Adding gs3build

  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 KB
Line 
1package org.greenstone.gsdl3.gs3build.util;
2
3
4
5import java.util.*;
6
7
8
9public class HTMLDocLocalHeading
10
11{ String heading;
12
13 HTMLBlock block;
14
15
16
17 public HTMLDocLocalHeading(HTMLDoc doc, String local)
18
19 { HTMLBlock nextheading, lastheading, anchor;
20
21 Enumeration headings;
22
23 HTMLDocAnchorList anchors;
24
25 HTMLBlock docBlock;
26
27 int _start, _end, _pos;
28
29
30
31 // initialise (to undefined)
32
33 this.heading = null;
34
35 this.block = null;
36
37
38
39 // get anchors
40
41 anchors = new HTMLDocAnchorList(doc);
42
43 anchor = anchors.localAnchor(local);
44
45 if (anchor == null)
46
47 { return;
48
49 }
50
51
52
53 // get headings position; lastheading will be previous, nextheading will be next
54
55 headings = doc.headings();
56
57 lastheading = null;
58
59 nextheading = null;
60
61
62
63 while (headings.hasMoreElements())
64
65 { nextheading = (HTMLBlock) headings.nextElement();
66
67 if (nextheading.startPos() > anchor.startPos())
68
69 { break;
70
71 }
72
73
74
75
76
77 lastheading = nextheading;
78
79 }
80
81
82
83 // didn't get any actual headings; abort.
84
85 if (nextheading == null)
86
87 { return;
88
89 }
90
91
92
93 // got to the end
94
95 if (nextheading == lastheading)
96
97 { this.block = nextheading;
98
99 }
100
101 else
102
103 { // now see where anchor is; try to find null textual content between anchor
104
105 // and heading
106
107 docBlock = doc.getCodedContent();
108
109 _start = docBlock.find(anchor);
110
111 _end = docBlock.find(nextheading);
112
113 for (_pos = _start; _pos < _end; _pos ++)
114
115 { // HTML tag
116
117 if (docBlock.elementAt(_pos) instanceof HTMLTag)
118
119 {
120
121 }
122
123 // HTML text - if non-blank, abort
124
125 else
126
127 { if (((HTMLCText) docBlock.elementAt(_pos)).nullString() == false)
128
129 { break;
130
131 }
132
133 }
134
135 }
136
137
138
139 // assign
140
141 if (_pos != _end)
142
143 { this.block = lastheading;
144
145 }
146
147 else
148
149 { this.block = nextheading;
150
151 }
152
153 }
154
155 this.heading = this.block.toString();
156
157 }
158
159
160
161 public String toString()
162
163 { return this.heading;
164
165 }
166
167
168
169 public HTMLBlock block()
170
171 { return this.block;
172
173 }
174
175
176
177 protected void finalize() throws Throwable
178
179 { this.heading = null;
180
181 this.block = null;
182
183 super.finalize();
184
185 }
186
187}
Note: See TracBrowser for help on using the repository browser.