source: trunk/greenstone3-extensions/gs3build/src/org/greenstone/gsdl3/gs3build/util/HTMLDocTitle.java@ 12188

Last change on this file since 12188 was 12188, checked in by kjdon, 18 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1package org.greenstone.gsdl3.gs3build.util;
2
3import java.util.*;
4
5public 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}
Note: See TracBrowser for help on using the repository browser.