// Job: Jay's Own Browser, a web browser written in Java by Jay Skeer // Copyright (C) 1996 Jay Skeer, Jay Prime Positive // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // /** Tokens of an HTML stream. */ public class HtmlToken { /** The HTML type of this class, see HtmlToken.BODY etc. */ int id; /** a string with the actual key for this component, eg "body" */ String id_string; /** The actual characters lexed */ String value; /** HTML is root of html document trees */ public static final int HTML= 0; /** HEAD is title (and other parts?) */ public static final int HEAD= 100; /** TITLE is title of this document */ public static final int TITLE= 101; /** BODY is main part of document */ public static final int BODY= 200; /** H1 is heading level 1 (highest level) */ public static final int H1= 201; /** H2 is heading level 2 */ public static final int H2= 202; /** H3 is heading level 3 (middle level) */ public static final int H3= 203; /** H4 is heading level 4 */ public static final int H4= 204; /** H5 is heading level 5 (lowest level) */ public static final int H5= 205; /** PRE is a kind of paragraph format (fixed width font, no fill) */ public static final int PRE= 206; /** TT is a kind of text format (fixed width font, fill ok) */ public static final int TT= 207; /** STRONG is a kind of text format (bold i believe) */ public static final int STRONG= 208; /** B is a kind of text format (bold i believe) */ public static final int B= 209; /** HR is what??? */ public static final int HR= 210; /** P is a paragraph (a sequence of TEXT */ public static final int P= 220; /** TEXT is a (sequence of) characters */ public static final int TEXT= 221; /** ANCHOR, a subtype of TEXT, is abstract super of HREF's and NAME's */ public static final int ANCHOR= 222; /** AHREF is a reference to (another) HTML doc */ public static final int AHREF= 223; /** ANAME is a name for a section (position) in an HTML doc */ public static final int ANAME= 224; /** LIST is abstract supertype of UL, DL, etc. */ public static final int LIST= 230; /** UL is a kind of list */ public static final int UL= 231; /** DL is a kind of list */ public static final int DL= 232; /** ITEM is a kind of list item marker */ public static final int ITEM= 240; /** LI is a kind of list item marker */ public static final int LI= 241; /** DD is a kind of list item marker */ public static final int DD= 242; /** DT is a kind of list item marker */ public static final int DT= 243; /** IMG is a image */ public static final int IMG= 250; /** CENTER is centered text */ public static final int CENTER= 260; /** OTHER is a html tag not recognized by this parser */ public static final int OTHER= 999; /** OPEN is a '<' token */ public static final int OPEN= 1001; /** CLOSE is a '>' token */ public static final int CLOSE= 1002; /** END is a '/' token */ public static final int END= 1003; /** EQUAL is a '=' token */ public static final int EQUAL= 1004; /** STRING is a "..." token */ public static final int STRING= 1005; /** ID is an identifyer token */ public static final int ID= 1006; /** EOF is a token rep. the end of the stream */ public static final int EOF= 1999; /** Given an id number, return an id_string */ public static String idToIdString(int id) { switch (id) { case HTML: return "html"; case HEAD: return "head"; case TITLE: return "title"; case BODY: return "body"; case H1: return "h1"; case H2: return "h2"; case H3: return "h3"; case H4: return "h4"; case H5: return "h5"; case PRE: return "pre"; case TT: return "tt"; case STRONG: return "strong"; case B: return "b"; case HR: return "hr"; case P: return "p"; case TEXT: return "text"; case ANCHOR: return "anchor"; case AHREF: return "ahref"; case ANAME: return "aname"; case LIST: return "list-abstract"; case DL: return "dl"; case UL: return "ul"; case ITEM: return "list-item-abstract"; case LI: return "li"; case DD: return "dd"; case DT: return "dt"; case IMG: return "img"; case OTHER: return "other"; case OPEN: return "<"; case CLOSE: return ">"; case END: return "/"; case EQUAL: return "="; case STRING: return "double-quote-string"; case CENTER: return "center"; case ID: return "??ID??"; case EOF: return "eof"; default: return "error"+Integer.toString(id); } } public static int idStringToId(String id) { if (id.equalsIgnoreCase("HTML")) return HTML; else if (id.equalsIgnoreCase("HEAD")) return HEAD; else if (id.equalsIgnoreCase("TITLE")) return TITLE; else if (id.equalsIgnoreCase("BODY")) return BODY; else if (id.equalsIgnoreCase("H1")) return H1; else if (id.equalsIgnoreCase("H2")) return H2; else if (id.equalsIgnoreCase("H3")) return H3; else if (id.equalsIgnoreCase("H4")) return H4; else if (id.equalsIgnoreCase("H5")) return H5; else if (id.equalsIgnoreCase("PRE")) return PRE; else if (id.equalsIgnoreCase("TT")) return TT; else if (id.equalsIgnoreCase("STRONG")) return STRONG; else if (id.equalsIgnoreCase("B")) return B; else if (id.equalsIgnoreCase("HR")) return HR; else if (id.equalsIgnoreCase("P")) return P; else if (id.equalsIgnoreCase("TEXT")) return TEXT; else if (id.equalsIgnoreCase("ANCHOR")) return ANCHOR; else if (id.equalsIgnoreCase("A")) return ANCHOR; else if (id.equalsIgnoreCase("AHREF")) return AHREF; else if (id.equalsIgnoreCase("ANAME")) return ANAME; else if (id.equalsIgnoreCase("UL")) return UL; else if (id.equalsIgnoreCase("MENU")) return UL; else if (id.equalsIgnoreCase("DL")) return DL; else if (id.equalsIgnoreCase("LI")) return LI; else if (id.equalsIgnoreCase("DD")) return DD; else if (id.equalsIgnoreCase("DT")) return DT; else if (id.equalsIgnoreCase("IMG")) return IMG; else if (id.equalsIgnoreCase("<")) return OPEN; else if (id.equalsIgnoreCase(">")) return CLOSE; else if (id.equalsIgnoreCase("/")) return END; else if (id.equalsIgnoreCase("CENTER")) return CENTER; // else if (id.equalsIgnoreCase("OTHER")) return OTHER; else return OTHER; } /** Creates a new HtmlToken with the given id, and id_string */ public HtmlToken(int nid, String nid_string) { this.id= nid; this.id_string= nid_string; } /** Creates a new HtmlToken with the given id */ public HtmlToken(int nid) { this.id= nid; this.id_string= HtmlToken.idToIdString(nid); } /** Creates a new HtmlToken with the given id_string */ public HtmlToken(String nid_string) { this.id= HtmlToken.idStringToId(nid_string); this.id_string= nid_string; } /** Returns string rep of token */ public String toString() { return "[t " + this.idToIdString(this.id) + "==\"" + this.id_string + "\"" + ", \"" + this.value + "\"]"; } }