1 | package org.greenstone.gsdl3.gs3build.util;
|
---|
2 |
|
---|
3 | import java.util.*;
|
---|
4 |
|
---|
5 | public class HTMLDocTitle
|
---|
6 | { StringBuffer title;
|
---|
7 | private static HTMLTagVector titleStartTags;
|
---|
8 | private static HTMLTagVector titleEndTags;
|
---|
9 | private static HTMLTagVector titleOptEndTags;
|
---|
10 |
|
---|
11 | static
|
---|
12 | { titleStartTags = new HTMLTagVector("title,h1,h2,h3,h4,h5,h6");
|
---|
13 | titleEndTags = new HTMLTagVector("title,h1,h2,h3,h4,h5,h6,body,head,table,hr,p,ul,ol,dl,dt,dd,li,tr,td,th,map");
|
---|
14 | titleOptEndTags = new HTMLTagVector("div,center,form");
|
---|
15 | }
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Constructor: generates a title for the supplied <code>HTMLDoc</code>.
|
---|
19 | */
|
---|
20 | public HTMLDocTitle(HTMLDoc doc)
|
---|
21 | { boolean intitle;
|
---|
22 | boolean incontent;
|
---|
23 | HTMLCText text;
|
---|
24 | HTMLTag tag;
|
---|
25 | HTMLBlock parser;
|
---|
26 | Enumeration elements;
|
---|
27 | Object element;
|
---|
28 |
|
---|
29 | this.title = null;
|
---|
30 | intitle = false;
|
---|
31 | incontent = false;
|
---|
32 |
|
---|
33 | parser = doc.getCodedContent();
|
---|
34 | if (parser == null)
|
---|
35 | { return;
|
---|
36 | }
|
---|
37 | elements = parser.elements();
|
---|
38 |
|
---|
39 | while (elements.hasMoreElements())
|
---|
40 | { //System.out.println(read + ":" + read.charAt(0));
|
---|
41 | element = elements.nextElement();
|
---|
42 |
|
---|
43 | if (element instanceof HTMLTag)
|
---|
44 | { tag = (HTMLTag) element;
|
---|
45 |
|
---|
46 | if (intitle)
|
---|
47 | { if (titleEndTags.matches(tag, false) ||
|
---|
48 | (incontent && titleOptEndTags.matches(tag, false))) // if closing
|
---|
49 | { intitle = false;
|
---|
50 | break;
|
---|
51 | }
|
---|
52 | else // else ignore it
|
---|
53 | {
|
---|
54 | }
|
---|
55 | }
|
---|
56 | else
|
---|
57 | { if (titleStartTags.matches(tag, true) == true)
|
---|
58 | { intitle = true;
|
---|
59 | incontent = false;
|
---|
60 | this.title = new StringBuffer();
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 | else
|
---|
65 | { text = (HTMLCText) element;
|
---|
66 |
|
---|
67 | if (intitle == true)
|
---|
68 | { this.title.append(text.toString());
|
---|
69 | if (!text.nullString())
|
---|
70 | { incontent = true;
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | if (this.title != null)
|
---|
76 | { this.title = HTMLCText.cleanString(this.title);
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * @return the Title as a <code>String</code>.
|
---|
82 | */
|
---|
83 | public String Title()
|
---|
84 | { if (this.title == null)
|
---|
85 | { return null;
|
---|
86 | }
|
---|
87 | return this.title.toString();
|
---|
88 | }
|
---|
89 | } |
---|