KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > visitors > HtmlPage


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Somik Raha
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/visitors/HtmlPage.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/05/24 00:38:19 $
10
// $Revision: 1.43 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.visitors;
28
29 import org.htmlparser.Parser;
30 import org.htmlparser.tags.BodyTag;
31 import org.htmlparser.tags.TableTag;
32 import org.htmlparser.Tag;
33 import org.htmlparser.tags.TitleTag;
34 import org.htmlparser.util.NodeList;
35
36 public class HtmlPage extends NodeVisitor {
37     private String JavaDoc title;
38     private NodeList nodesInBody;
39     private NodeList tables;
40
41     public HtmlPage(Parser parser) {
42         super(true);
43         title = "";
44         nodesInBody = new NodeList();
45         tables = new NodeList();
46     }
47
48     public String JavaDoc getTitle() {
49         return title;
50     }
51
52     public void setTitle(String JavaDoc title) {
53         this.title = title;
54     }
55
56     public void visitTag(Tag tag)
57     {
58         if (isTable(tag))
59             tables.add(tag);
60         else if (isBodyTag(tag))
61             nodesInBody = tag.getChildren ();
62         else if (isTitleTag(tag))
63             title = ((TitleTag)tag).getTitle();
64     }
65
66     private boolean isTable(Tag tag)
67     {
68         return (tag instanceof TableTag);
69     }
70
71     private boolean isBodyTag(Tag tag)
72     {
73         return (tag instanceof BodyTag);
74     }
75
76     private boolean isTitleTag(Tag tag)
77     {
78         return (tag instanceof TitleTag);
79     }
80
81     public NodeList getBody() {
82         return nodesInBody;
83     }
84
85     public TableTag [] getTables()
86     {
87         TableTag [] tableArr = new TableTag[tables.size()];
88         tables.copyToNodeArray (tableArr);
89         return tableArr;
90     }
91 }
92
Popular Tags