1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45:
46: import ;
47: import ;
48:
49: import ;
50:
51:
55: public class HTML
56: {
57:
60: public static final class Attribute
61: {
62:
65: public static final Attribute ACTION = new Attribute("action");
66:
67:
70: public static final Attribute ALIGN = new Attribute("align");
71:
72:
75: public static final Attribute ALINK = new Attribute("alink");
76:
77:
80: public static final Attribute ALT = new Attribute("alt");
81:
82:
85: public static final Attribute ARCHIVE = new Attribute("archive");
86:
87:
90: public static final Attribute BACKGROUND = new Attribute("background");
91:
92:
95: public static final Attribute BGCOLOR = new Attribute("bgcolor");
96:
97:
100: public static final Attribute BORDER = new Attribute("border");
101:
102:
105: public static final Attribute CELLPADDING = new Attribute("cellpadding");
106:
107:
110: public static final Attribute CELLSPACING = new Attribute("cellspacing");
111:
112:
115: public static final Attribute CHECKED = new Attribute("checked");
116:
117:
120: public static final Attribute CLASS = new Attribute("class");
121:
122:
125: public static final Attribute CLASSID = new Attribute("classid");
126:
127:
130: public static final Attribute CLEAR = new Attribute("clear");
131:
132:
135: public static final Attribute CODE = new Attribute("code");
136:
137:
140: public static final Attribute CODEBASE = new Attribute("codebase");
141:
142:
145: public static final Attribute CODETYPE = new Attribute("codetype");
146:
147:
150: public static final Attribute COLOR = new Attribute("color");
151:
152:
155: public static final Attribute COLS = new Attribute("cols");
156:
157:
160: public static final Attribute COLSPAN = new Attribute("colspan");
161:
162:
165: public static final Attribute COMMENT = new Attribute("comment");
166:
167:
170: public static final Attribute COMPACT = new Attribute("compact");
171:
172:
175: public static final Attribute CONTENT = new Attribute("content");
176:
177:
180: public static final Attribute COORDS = new Attribute("coords");
181:
182:
185: public static final Attribute DATA = new Attribute("data");
186:
187:
190: public static final Attribute DECLARE = new Attribute("declare");
191:
192:
195: public static final Attribute DIR = new Attribute("dir");
196:
197:
200: public static final Attribute DUMMY = new Attribute("dummy");
201:
202:
205: public static final Attribute ENCTYPE = new Attribute("enctype");
206:
207:
210: public static final Attribute ENDTAG = new Attribute("endtag");
211:
212:
215: public static final Attribute FACE = new Attribute("face");
216:
217:
220: public static final Attribute FRAMEBORDER = new Attribute("frameborder");
221:
222:
225: public static final Attribute HALIGN = new Attribute("halign");
226:
227:
230: public static final Attribute HEIGHT = new Attribute("height");
231:
232:
235: public static final Attribute HREF = new Attribute("href");
236:
237:
240: public static final Attribute HSPACE = new Attribute("hspace");
241:
242:
245: public static final Attribute HTTPEQUIV = new Attribute("http-equiv");
246:
247:
250: public static final Attribute ID = new Attribute("id");
251:
252:
255: public static final Attribute ISMAP = new Attribute("ismap");
256:
257:
260: public static final Attribute LANG = new Attribute("lang");
261:
262:
265: public static final Attribute LANGUAGE = new Attribute("language");
266:
267:
270: public static final Attribute LINK = new Attribute("link");
271:
272:
275: public static final Attribute LOWSRC = new Attribute("lowsrc");
276:
277:
280: public static final Attribute MARGINHEIGHT = new Attribute("marginheight");
281:
282:
285: public static final Attribute MARGINWIDTH = new Attribute("marginwidth");
286:
287:
290: public static final Attribute MAXLENGTH = new Attribute("maxlength");
291:
292:
295: static final Attribute MEDIA = new Attribute("media");
296:
297:
300: public static final Attribute METHOD = new Attribute("method");
301:
302:
305: public static final Attribute MULTIPLE = new Attribute("multiple");
306:
307:
310: public static final Attribute N = new Attribute("n");
311:
312:
315: public static final Attribute NAME = new Attribute("name");
316:
317:
320: public static final Attribute NOHREF = new Attribute("nohref");
321:
322:
325: public static final Attribute NORESIZE = new Attribute("noresize");
326:
327:
330: public static final Attribute NOSHADE = new Attribute("noshade");
331:
332:
335: public static final Attribute NOWRAP = new Attribute("nowrap");
336:
337:
340: public static final Attribute PROMPT = new Attribute("prompt");
341:
342:
345: public static final Attribute REL = new Attribute("rel");
346:
347:
350: public static final Attribute REV = new Attribute("rev");
351:
352:
355: public static final Attribute ROWS = new Attribute("rows");
356:
357:
360: public static final Attribute ROWSPAN = new Attribute("rowspan");
361:
362:
365: public static final Attribute SCROLLING = new Attribute("scrolling");
366:
367:
370: public static final Attribute SELECTED = new Attribute("selected");
371:
372:
375: public static final Attribute SHAPE = new Attribute("shape");
376:
377:
380: public static final Attribute SHAPES = new Attribute("shapes");
381:
382:
385: public static final Attribute SIZE = new Attribute("size");
386:
387:
390: public static final Attribute SRC = new Attribute("src");
391:
392:
395: public static final Attribute STANDBY = new Attribute("standby");
396:
397:
400: public static final Attribute START = new Attribute("start");
401:
402:
405: public static final Attribute STYLE = new Attribute("style");
406:
407:
410: public static final Attribute TARGET = new Attribute("target");
411:
412:
415: public static final Attribute TEXT = new Attribute("text");
416:
417:
420: public static final Attribute TITLE = new Attribute("title");
421:
422:
425: public static final Attribute TYPE = new Attribute("type");
426:
427:
430: public static final Attribute USEMAP = new Attribute("usemap");
431:
432:
435: public static final Attribute VALIGN = new Attribute("valign");
436:
437:
440: public static final Attribute VALUE = new Attribute("value");
441:
442:
445: public static final Attribute VALUETYPE = new Attribute("valuetype");
446:
447:
450: public static final Attribute VERSION = new Attribute("version");
451:
452:
455: public static final Attribute VLINK = new Attribute("vlink");
456:
457:
460: public static final Attribute VSPACE = new Attribute("vspace");
461:
462:
465: public static final Attribute WIDTH = new Attribute("width");
466:
467:
470: private final String name;
471:
472:
475: private Attribute(String a_name)
476: {
477: name = a_name;
478: }
479:
480:
484: public String toString()
485: {
486: return name;
487: }
488:
489:
494: static Attribute[] getAllAttributes()
495: {
496: Field[] f = Attribute.class.getFields();
497: Attribute[] attrs = new Attribute[ f.length ];
498: Field x;
499: int p = 0;
500: Attribute a;
501:
502: for (int i = 0; i < f.length; i++)
503: {
504: x = f [ i ];
505:
506: if ((x.getModifiers() & Modifier.STATIC) != 0)
507: {
508: if (x.getType().equals(Attribute.class))
509: {
510: try
511: {
512: a = (Attribute) x.get(null);
513: attrs [ p++ ] = a;
514: }
515: catch (Exception ex)
516: {
517: ex.printStackTrace(System.err);
518: throw new Error("This should never happen, report a bug");
519: }
520: }
521: }
522: }
523:
524: return attrs;
525: }
526: }
527:
528:
531: public static class Tag
532: {
533:
536: public static final Tag A = new Tag("a");
537:
538:
541: public static final Tag ADDRESS = new Tag("address");
542:
543:
546: public static final Tag APPLET = new Tag("applet");
547:
548:
551: public static final Tag AREA = new Tag("area");
552:
553:
556: public static final Tag B = new Tag("b");
557:
558:
561: public static final Tag BASE = new Tag("base");
562:
563:
566: public static final Tag BASEFONT = new Tag("basefont");
567:
568:
571: public static final Tag BIG = new Tag("big");
572:
573:
576: public static final Tag BLOCKQUOTE = new Tag("blockquote", BREAKS | BLOCK);
577:
578:
581: public static final Tag BODY = new Tag("body", BREAKS | BLOCK);
582:
583:
586: public static final Tag BR = new Tag("br", BREAKS);
587:
588:
591: public static final Tag CAPTION = new Tag("caption");
592:
593:
596: public static final Tag CENTER = new Tag("center", BREAKS);
597:
598:
601: public static final Tag CITE = new Tag("cite");
602:
603:
606: public static final Tag CODE = new Tag("code");
607:
608:
611: public static final Tag DD = new Tag("dd", BREAKS | BLOCK);
612:
613:
616: public static final Tag DFN = new Tag("dfn");
617:
618:
621: public static final Tag DIR = new Tag("dir", BREAKS | BLOCK);
622:
623:
626: public static final Tag DIV = new Tag("div", BREAKS | BLOCK);
627:
628:
631: public static final Tag DL = new Tag("dl", BREAKS | BLOCK);
632:
633:
636: public static final Tag DT = new Tag("dt", BREAKS | BLOCK);
637:
638:
641: public static final Tag EM = new Tag("em");
642:
643:
646: public static final Tag FONT = new Tag("font");
647:
648:
651: public static final Tag FORM = new Tag("form", BREAKS);
652:
653:
656: public static final Tag FRAME = new Tag("frame");
657:
658:
661: public static final Tag FRAMESET = new Tag("frameset");
662:
663:
666: public static final Tag H1 = new Tag("h1", BREAKS | BLOCK);
667:
668:
671: public static final Tag H2 = new Tag("h2", BREAKS | BLOCK);
672:
673:
676: public static final Tag H3 = new Tag("h3", BREAKS | BLOCK);
677:
678:
681: public static final Tag H4 = new Tag("h4", BREAKS | BLOCK);
682:
683:
686: public static final Tag H5 = new Tag("h5", BREAKS | BLOCK);
687:
688:
691: public static final Tag H6 = new Tag("h6", BREAKS | BLOCK);
692:
693:
696: public static final Tag HEAD = new Tag("head", BREAKS | BLOCK);
697:
698:
701: public static final Tag HR = new Tag("hr", BREAKS);
702:
703:
706: public static final Tag HTML = new Tag("html", BREAKS);
707:
708:
711: public static final Tag I = new Tag("i");
712:
713:
716: public static final Tag IMG = new Tag("img");
717:
718:
721: public static final Tag INPUT = new Tag("input");
722:
723:
726: public static final Tag ISINDEX = new Tag("isindex", BREAKS);
727:
728:
731: public static final Tag KBD = new Tag("kbd");
732:
733:
736: public static final Tag LI = new Tag("li", BREAKS | BLOCK);
737:
738:
741: public static final Tag LINK = new Tag("link");
742:
743:
746: public static final Tag MAP = new Tag("map");
747:
748:
751: public static final Tag MENU = new Tag("menu", BREAKS | BLOCK);
752:
753:
756: public static final Tag META = new Tag("meta");
757:
758:
761: static final Tag NOBR = new Tag("nobr");
762:
763:
766: public static final Tag NOFRAMES = new Tag("noframes", BREAKS | BLOCK);
767:
768:
771: public static final Tag OBJECT = new Tag("object");
772:
773:
776: public static final Tag OL = new Tag("ol", BREAKS | BLOCK);
777:
778:
781: public static final Tag OPTION = new Tag("option");
782:
783:
786: public static final Tag P = new Tag("p", BREAKS | BLOCK);
787:
788:
791: public static final Tag PARAM = new Tag("param");
792:
793:
796: public static final Tag PRE = new Tag("pre", BREAKS | BLOCK | PREFORMATTED);
797:
798:
801: public static final Tag S = new Tag("s");
802:
803:
806: public static final Tag SAMP = new Tag("samp");
807:
808:
811: public static final Tag SCRIPT = new Tag("script");
812:
813:
816: public static final Tag SELECT = new Tag("select");
817:
818:
821: public static final Tag SMALL = new Tag("small");
822:
823:
826: public static final Tag SPAN = new Tag("span");
827:
828:
831: public static final Tag STRIKE = new Tag("strike");
832:
833:
836: public static final Tag STRONG = new Tag("strong");
837:
838:
841: public static final Tag STYLE = new Tag("style");
842:
843:
846: public static final Tag SUB = new Tag("sub");
847:
848:
851: public static final Tag SUP = new Tag("sup");
852:
853:
856: public static final Tag TABLE = new Tag("table", BLOCK);
857:
858:
861: public static final Tag TD = new Tag("td", BREAKS | BLOCK);
862:
863:
866: public static final Tag TEXTAREA = new Tag("textarea", PREFORMATTED);
867:
868:
871: public static final Tag TH = new Tag("th", BREAKS | BLOCK);
872:
873:
876: public static final Tag TITLE = new Tag("title", BREAKS | BLOCK);
877:
878:
881: public static final Tag TR = new Tag("tr", BLOCK);
882:
883:
886: public static final Tag TT = new Tag("tt");
887:
888:
891: public static final Tag U = new Tag("u");
892:
893:
896: public static final Tag UL = new Tag("ul", BREAKS | BLOCK);
897:
898:
901: public static final Tag VAR = new Tag("var");
902:
903:
904:
905:
910: private static final int TOTAL_SYNTHETIC_TAGS = 3;
911:
912:
917: public static final Tag COMMENT = new Tag("comment", SYNTHETIC);
918:
919:
924: public static final Tag CONTENT = new Tag("content", SYNTHETIC);
925:
926:
932: public static final Tag IMPLIED = new Tag("p-implied", SYNTHETIC);
933: final String name;
934: final int flags;
935:
936:
945: public Tag()
946: {
947: name = null;
948: flags = 0;
949: }
950:
951:
955: protected Tag(String id)
956: {
957: name = id;
958: flags = 0;
959: }
960:
961:
965: protected Tag(String id, boolean causesBreak, boolean isBlock)
966: {
967: int f = 0;
968:
969: if (causesBreak)
970: {
971: f |= BREAKS;
972: }
973:
974: if (isBlock)
975: {
976: f |= BLOCK;
977: }
978:
979: flags = f;
980: name = id;
981: }
982:
983:
986: Tag(String id, int a_flags)
987: {
988: name = id;
989: flags = a_flags;
990: }
991:
992:
996: public boolean isBlock()
997: {
998: return (flags & BLOCK) != 0;
999: }
1000:
1001:
1005: public boolean isPreformatted()
1006: {
1007: return (flags & PREFORMATTED) != 0;
1008: }
1009:
1010:
1013: public boolean breaksFlow()
1014: {
1015: return (flags & BREAKS) != 0;
1016: }
1017:
1018:
1022: public String toString()
1023: {
1024: return name;
1025: }
1026:
1027:
1032: static Tag[] getAllTags()
1033: {
1034: Field[] f = Tag.class.getFields();
1035: Field x;
1036:
1037:
1038: Tag[] tags = new Tag[ f.length - TOTAL_SYNTHETIC_TAGS ];
1039: int p = 0;
1040: Tag t;
1041:
1042: for (int i = 0; i < f.length; i++)
1043: {
1044: x = f [ i ];
1045:
1046: if ((x.getModifiers() & Modifier.STATIC) != 0)
1047: {
1048: if (x.getType().equals(Tag.class))
1049: {
1050: try
1051: {
1052: t = (Tag) x.get(null);
1053:
1054: if (!t.isSyntetic())
1055: {
1056: tags [ p++ ] = t;
1057: }
1058: }
1059: catch (IllegalAccessException ex)
1060: {
1061: unexpected(ex);
1062: }
1063: catch (IllegalArgumentException ex)
1064: {
1065: unexpected(ex);
1066: }
1067: }
1068: }
1069: }
1070:
1071: return tags;
1072: }
1073:
1074:
1078: boolean isSyntetic()
1079: {
1080: return (flags & SYNTHETIC) != 0;
1081: }
1082:
1083: private static void unexpected(Exception ex)
1084: throws Error
1085: {
1086: throw new Error("This should never happen, report a bug", ex);
1087: }
1088: }
1089:
1090:
1094: public static class UnknownTag
1095: extends Tag
1096: implements Serializable
1097: {
1098: private static final long serialVersionUID = -1534369342247250625L;
1099:
1100:
1105: public UnknownTag(String name)
1106: {
1107: super(name);
1108: }
1109: }
1110:
1111:
1115: public static final String NULL_ATTRIBUTE_VALUE = "#DEFAULT";
1116:
1117:
1118: static final int BREAKS = 1;
1119: static final int BLOCK = 2;
1120: static final int PREFORMATTED = 4;
1121: static final int SYNTHETIC = 8;
1122: private static Map tagMap;
1123: private static Map attrMap;
1124:
1125:
1130: public HTML()
1131: {
1132:
1133: }
1134:
1135:
1138: public static HTML.Attribute[] getAllAttributeKeys()
1139: {
1140: return Attribute.getAllAttributes();
1141: }
1142:
1143:
1148: public static HTML.Tag[] getAllTags()
1149: {
1150: return Tag.getAllTags();
1151: }
1152:
1153:
1157: public static Attribute getAttributeKey(String attName)
1158: {
1159: if (attrMap == null)
1160: {
1161:
1162: attrMap = new TreeMap();
1163:
1164: Attribute[] attrs = getAllAttributeKeys();
1165:
1166: for (int i = 0; i < attrs.length; i++)
1167: {
1168: attrMap.put(attrs [ i ].toString(), attrs [ i ]);
1169: }
1170: }
1171:
1172: return (Attribute) attrMap.get(attName.toLowerCase());
1173: }
1174:
1175:
1199: public static int getIntegerAttributeValue(AttributeSet set,
1200: HTML.Attribute attribute,
1201: int defaultValue
1202: )
1203: {
1204: Object v = set.getAttribute(attribute);
1205:
1206: if (v == null)
1207: {
1208: return defaultValue;
1209: }
1210:
1211: try
1212: {
1213: return Integer.parseInt(v.toString().trim());
1214: }
1215: catch (Exception ex)
1216: {
1217: return defaultValue;
1218: }
1219: }
1220:
1221:
1226: public static Tag getTag(String tagName)
1227: {
1228: if (tagMap == null)
1229: {
1230:
1231: tagMap = new TreeMap();
1232:
1233: Tag[] tags = getAllTags();
1234:
1235: for (int i = 0; i < tags.length; i++)
1236: {
1237: tagMap.put(tags [ i ].toString(), tags [ i ]);
1238: }
1239: }
1240:
1241: return (Tag) tagMap.get(tagName.toLowerCase());
1242: }
1243: }