KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bplatt > spider > SimpleHTMLToken


1 package bplatt.spider;
2
3 /**
4  * SimpleHTMLToken - an HTML Token
5  * Copyright 2002, Robert L. Platt, All rights reserved
6  * @author Robert L. Platt
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  */

22
23 import java.io.*;
24
25 public class SimpleHTMLToken {
26     public static final int TAG = 0;
27     public static final int ENDTAG = 1;
28     public static final int CONTENT = 2;
29     private static final int UNDEFINED = -1;
30
31     private int type;
32     private String JavaDoc content;
33     
34     /**
35      * Constructor for SimpleHTMLToken.
36      */

37     public SimpleHTMLToken() {
38         type = UNDEFINED;
39         content = null;
40     }
41     
42     /**
43      * Constructor for SimpleHTMLToken.
44      */

45     public SimpleHTMLToken(int type, String JavaDoc content) {
46         this.type = type;
47         this.content = content;
48     }
49     
50     /**
51      * Returns the content.
52      * @return String
53      */

54     public String JavaDoc getContent() {
55         return content;
56     }
57
58     /**
59      * Returns the type.
60      * @return int
61      */

62     public int getType() {
63         return type;
64     }
65
66     /**
67      * Sets the content.
68      * @param content The content to set
69      */

70     public void setContent(String JavaDoc content) {
71         this.content = content;
72     }
73
74     /**
75      * Sets the type.
76      * @param type The type to set
77      */

78     public void setType(int type) {
79         this.type = type;
80     }
81     
82     /**
83      * dump - used for debugging
84      */

85     public void dump(PrintStream out)
86     {
87         switch(type) {
88             case UNDEFINED: out.println("Error!");
89                                 break;
90             case TAG: out.println("<" + content + ">");
91                                 break;
92             case ENDTAG: out.println("</"+ content + ">");
93                                 break;
94             case CONTENT: out.println("\"" + content + "\"");
95                                 break;
96             default: out.println("Error!");
97                                 break;
98         }
99     
100     }
101 }
102
Popular Tags