35 |
obligated to do so. If you do not wish to do so, delete this |
obligated to do so. If you do not wish to do so, delete this |
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
38 |
|
|
39 |
package javax.swing.text.html; |
package javax.swing.text.html; |
40 |
|
|
41 |
import java.io.Serializable; |
import java.io.Serializable; |
42 |
|
|
43 |
|
import java.lang.reflect.Field; |
44 |
|
import java.lang.reflect.Modifier; |
45 |
|
|
46 |
|
import java.util.Map; |
47 |
|
import java.util.TreeMap; |
48 |
|
|
49 |
|
import javax.swing.text.AttributeSet; |
50 |
|
|
51 |
/** |
/** |
52 |
* Stub implementation. |
* HTML attribute and tag definitions. |
53 |
* Just enough to get gjdoc working. |
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
|
* |
|
|
* @author Mark Wielaard (mark@klomp.org) |
|
54 |
*/ |
*/ |
55 |
public class HTML |
public class HTML |
56 |
{ |
{ |
57 |
public static class Tag |
/** |
58 |
|
* Represents a HTML attribute. |
59 |
|
*/ |
60 |
|
public static class Attribute |
61 |
|
implements Serializable |
62 |
{ |
{ |
63 |
private final String id; |
/** |
64 |
|
* The action attribute |
65 |
|
*/ |
66 |
|
public static final Attribute ACTION = new Attribute("action"); |
67 |
|
|
68 |
protected Tag(String id) |
/** |
69 |
|
* The align attribute |
70 |
|
*/ |
71 |
|
public static final Attribute ALIGN = new Attribute("align"); |
72 |
|
|
73 |
|
/** |
74 |
|
* The alink attribute |
75 |
|
*/ |
76 |
|
public static final Attribute ALINK = new Attribute("alink"); |
77 |
|
|
78 |
|
/** |
79 |
|
* The alt attribute |
80 |
|
*/ |
81 |
|
public static final Attribute ALT = new Attribute("alt"); |
82 |
|
|
83 |
|
/** |
84 |
|
* The archive attribute |
85 |
|
*/ |
86 |
|
public static final Attribute ARCHIVE = new Attribute("archive"); |
87 |
|
|
88 |
|
/** |
89 |
|
* The background attribute |
90 |
|
*/ |
91 |
|
public static final Attribute BACKGROUND = new Attribute("background"); |
92 |
|
|
93 |
|
/** |
94 |
|
* The bgcolor attribute |
95 |
|
*/ |
96 |
|
public static final Attribute BGCOLOR = new Attribute("bgcolor"); |
97 |
|
|
98 |
|
/** |
99 |
|
* The border attribute |
100 |
|
*/ |
101 |
|
public static final Attribute BORDER = new Attribute("border"); |
102 |
|
|
103 |
|
/** |
104 |
|
* The cellpadding attribute |
105 |
|
*/ |
106 |
|
public static final Attribute CELLPADDING = new Attribute("cellpadding"); |
107 |
|
|
108 |
|
/** |
109 |
|
* The cellspacing attribute |
110 |
|
*/ |
111 |
|
public static final Attribute CELLSPACING = new Attribute("cellspacing"); |
112 |
|
|
113 |
|
/** |
114 |
|
* The checked attribute |
115 |
|
*/ |
116 |
|
public static final Attribute CHECKED = new Attribute("checked"); |
117 |
|
|
118 |
|
/** |
119 |
|
* The class attribute |
120 |
|
*/ |
121 |
|
public static final Attribute CLASS = new Attribute("class"); |
122 |
|
|
123 |
|
/** |
124 |
|
* The classid attribute |
125 |
|
*/ |
126 |
|
public static final Attribute CLASSID = new Attribute("classid"); |
127 |
|
|
128 |
|
/** |
129 |
|
* The clear attribute |
130 |
|
*/ |
131 |
|
public static final Attribute CLEAR = new Attribute("clear"); |
132 |
|
|
133 |
|
/** |
134 |
|
* The code attribute |
135 |
|
*/ |
136 |
|
public static final Attribute CODE = new Attribute("code"); |
137 |
|
|
138 |
|
/** |
139 |
|
* The codebase attribute |
140 |
|
*/ |
141 |
|
public static final Attribute CODEBASE = new Attribute("codebase"); |
142 |
|
|
143 |
|
/** |
144 |
|
* The codetype attribute |
145 |
|
*/ |
146 |
|
public static final Attribute CODETYPE = new Attribute("codetype"); |
147 |
|
|
148 |
|
/** |
149 |
|
* The color attribute |
150 |
|
*/ |
151 |
|
public static final Attribute COLOR = new Attribute("color"); |
152 |
|
|
153 |
|
/** |
154 |
|
* The cols attribute |
155 |
|
*/ |
156 |
|
public static final Attribute COLS = new Attribute("cols"); |
157 |
|
|
158 |
|
/** |
159 |
|
* The colspan attribute |
160 |
|
*/ |
161 |
|
public static final Attribute COLSPAN = new Attribute("colspan"); |
162 |
|
|
163 |
|
/** |
164 |
|
* The comment attribute |
165 |
|
*/ |
166 |
|
public static final Attribute COMMENT = new Attribute("comment"); |
167 |
|
|
168 |
|
/** |
169 |
|
* The compact attribute |
170 |
|
*/ |
171 |
|
public static final Attribute COMPACT = new Attribute("compact"); |
172 |
|
|
173 |
|
/** |
174 |
|
* The content attribute |
175 |
|
*/ |
176 |
|
public static final Attribute CONTENT = new Attribute("content"); |
177 |
|
|
178 |
|
/** |
179 |
|
* The coords attribute |
180 |
|
*/ |
181 |
|
public static final Attribute COORDS = new Attribute("coords"); |
182 |
|
|
183 |
|
/** |
184 |
|
* The data attribute |
185 |
|
*/ |
186 |
|
public static final Attribute DATA = new Attribute("data"); |
187 |
|
|
188 |
|
/** |
189 |
|
* The declare attribute |
190 |
|
*/ |
191 |
|
public static final Attribute DECLARE = new Attribute("declare"); |
192 |
|
|
193 |
|
/** |
194 |
|
* The dir attribute |
195 |
|
*/ |
196 |
|
public static final Attribute DIR = new Attribute("dir"); |
197 |
|
|
198 |
|
/** |
199 |
|
* The dummy attribute |
200 |
|
*/ |
201 |
|
public static final Attribute DUMMY = new Attribute("dummy"); |
202 |
|
|
203 |
|
/** |
204 |
|
* The enctype attribute |
205 |
|
*/ |
206 |
|
public static final Attribute ENCTYPE = new Attribute("enctype"); |
207 |
|
|
208 |
|
/** |
209 |
|
* The endtag attribute |
210 |
|
*/ |
211 |
|
public static final Attribute ENDTAG = new Attribute("endtag"); |
212 |
|
|
213 |
|
/** |
214 |
|
* The face attribute |
215 |
|
*/ |
216 |
|
public static final Attribute FACE = new Attribute("face"); |
217 |
|
|
218 |
|
/** |
219 |
|
* The frameborder attribute |
220 |
|
*/ |
221 |
|
public static final Attribute FRAMEBORDER = new Attribute("frameborder"); |
222 |
|
|
223 |
|
/** |
224 |
|
* The halign attribute |
225 |
|
*/ |
226 |
|
public static final Attribute HALIGN = new Attribute("halign"); |
227 |
|
|
228 |
|
/** |
229 |
|
* The height attribute |
230 |
|
*/ |
231 |
|
public static final Attribute HEIGHT = new Attribute("height"); |
232 |
|
|
233 |
|
/** |
234 |
|
* The href attribute |
235 |
|
*/ |
236 |
|
public static final Attribute HREF = new Attribute("href"); |
237 |
|
|
238 |
|
/** |
239 |
|
* The hspace attribute |
240 |
|
*/ |
241 |
|
public static final Attribute HSPACE = new Attribute("hspace"); |
242 |
|
|
243 |
|
/** |
244 |
|
* The http-equiv attribute |
245 |
|
*/ |
246 |
|
public static final Attribute HTTPEQUIV = new Attribute("http-equiv"); |
247 |
|
|
248 |
|
/** |
249 |
|
* The id attribute |
250 |
|
*/ |
251 |
|
public static final Attribute ID = new Attribute("id"); |
252 |
|
|
253 |
|
/** |
254 |
|
* The ismap attribute |
255 |
|
*/ |
256 |
|
public static final Attribute ISMAP = new Attribute("ismap"); |
257 |
|
|
258 |
|
/** |
259 |
|
* The lang attribute |
260 |
|
*/ |
261 |
|
public static final Attribute LANG = new Attribute("lang"); |
262 |
|
|
263 |
|
/** |
264 |
|
* The language attribute |
265 |
|
*/ |
266 |
|
public static final Attribute LANGUAGE = new Attribute("language"); |
267 |
|
|
268 |
|
/** |
269 |
|
* The link attribute |
270 |
|
*/ |
271 |
|
public static final Attribute LINK = new Attribute("link"); |
272 |
|
|
273 |
|
/** |
274 |
|
* The lowsrc attribute |
275 |
|
*/ |
276 |
|
public static final Attribute LOWSRC = new Attribute("lowsrc"); |
277 |
|
|
278 |
|
/** |
279 |
|
* The marginheight attribute |
280 |
|
*/ |
281 |
|
public static final Attribute MARGINHEIGHT = new Attribute("marginheight"); |
282 |
|
|
283 |
|
/** |
284 |
|
* The marginwidth attribute |
285 |
|
*/ |
286 |
|
public static final Attribute MARGINWIDTH = new Attribute("marginwidth"); |
287 |
|
|
288 |
|
/** |
289 |
|
* The maxlength attribute |
290 |
|
*/ |
291 |
|
public static final Attribute MAXLENGTH = new Attribute("maxlength"); |
292 |
|
|
293 |
|
/** |
294 |
|
* The media attribute |
295 |
|
*/ |
296 |
|
public static final Attribute MEDIA = new Attribute("media"); |
297 |
|
|
298 |
|
/** |
299 |
|
* The method attribute |
300 |
|
*/ |
301 |
|
public static final Attribute METHOD = new Attribute("method"); |
302 |
|
|
303 |
|
/** |
304 |
|
* The multiple attribute |
305 |
|
*/ |
306 |
|
public static final Attribute MULTIPLE = new Attribute("multiple"); |
307 |
|
|
308 |
|
/** |
309 |
|
* The n attribute |
310 |
|
*/ |
311 |
|
public static final Attribute N = new Attribute("n"); |
312 |
|
|
313 |
|
/** |
314 |
|
* The name attribute |
315 |
|
*/ |
316 |
|
public static final Attribute NAME = new Attribute("name"); |
317 |
|
|
318 |
|
/** |
319 |
|
* The nohref attribute |
320 |
|
*/ |
321 |
|
public static final Attribute NOHREF = new Attribute("nohref"); |
322 |
|
|
323 |
|
/** |
324 |
|
* The noresize attribute |
325 |
|
*/ |
326 |
|
public static final Attribute NORESIZE = new Attribute("noresize"); |
327 |
|
|
328 |
|
/** |
329 |
|
* The noshade attribute |
330 |
|
*/ |
331 |
|
public static final Attribute NOSHADE = new Attribute("noshade"); |
332 |
|
|
333 |
|
/** |
334 |
|
* The nowrap attribute |
335 |
|
*/ |
336 |
|
public static final Attribute NOWRAP = new Attribute("nowrap"); |
337 |
|
|
338 |
|
/** |
339 |
|
* The prompt attribute |
340 |
|
*/ |
341 |
|
public static final Attribute PROMPT = new Attribute("prompt"); |
342 |
|
|
343 |
|
/** |
344 |
|
* The rel attribute |
345 |
|
*/ |
346 |
|
public static final Attribute REL = new Attribute("rel"); |
347 |
|
|
348 |
|
/** |
349 |
|
* The rev attribute |
350 |
|
*/ |
351 |
|
public static final Attribute REV = new Attribute("rev"); |
352 |
|
|
353 |
|
/** |
354 |
|
* The rows attribute |
355 |
|
*/ |
356 |
|
public static final Attribute ROWS = new Attribute("rows"); |
357 |
|
|
358 |
|
/** |
359 |
|
* The rowspan attribute |
360 |
|
*/ |
361 |
|
public static final Attribute ROWSPAN = new Attribute("rowspan"); |
362 |
|
|
363 |
|
/** |
364 |
|
* The scrolling attribute |
365 |
|
*/ |
366 |
|
public static final Attribute SCROLLING = new Attribute("scrolling"); |
367 |
|
|
368 |
|
/** |
369 |
|
* The selected attribute |
370 |
|
*/ |
371 |
|
public static final Attribute SELECTED = new Attribute("selected"); |
372 |
|
|
373 |
|
/** |
374 |
|
* The shape attribute |
375 |
|
*/ |
376 |
|
public static final Attribute SHAPE = new Attribute("shape"); |
377 |
|
|
378 |
|
/** |
379 |
|
* The shapes attribute |
380 |
|
*/ |
381 |
|
public static final Attribute SHAPES = new Attribute("shapes"); |
382 |
|
|
383 |
|
/** |
384 |
|
* The size attribute |
385 |
|
*/ |
386 |
|
public static final Attribute SIZE = new Attribute("size"); |
387 |
|
|
388 |
|
/** |
389 |
|
* The src attribute |
390 |
|
*/ |
391 |
|
public static final Attribute SRC = new Attribute("src"); |
392 |
|
|
393 |
|
/** |
394 |
|
* The standby attribute |
395 |
|
*/ |
396 |
|
public static final Attribute STANDBY = new Attribute("standby"); |
397 |
|
|
398 |
|
/** |
399 |
|
* The start attribute |
400 |
|
*/ |
401 |
|
public static final Attribute START = new Attribute("start"); |
402 |
|
|
403 |
|
/** |
404 |
|
* The style attribute |
405 |
|
*/ |
406 |
|
public static final Attribute STYLE = new Attribute("style"); |
407 |
|
|
408 |
|
/** |
409 |
|
* The target attribute |
410 |
|
*/ |
411 |
|
public static final Attribute TARGET = new Attribute("target"); |
412 |
|
|
413 |
|
/** |
414 |
|
* The text attribute |
415 |
|
*/ |
416 |
|
public static final Attribute TEXT = new Attribute("text"); |
417 |
|
|
418 |
|
/** |
419 |
|
* The title attribute |
420 |
|
*/ |
421 |
|
public static final Attribute TITLE = new Attribute("title"); |
422 |
|
|
423 |
|
/** |
424 |
|
* The type attribute |
425 |
|
*/ |
426 |
|
public static final Attribute TYPE = new Attribute("type"); |
427 |
|
|
428 |
|
/** |
429 |
|
* The usemap attribute |
430 |
|
*/ |
431 |
|
public static final Attribute USEMAP = new Attribute("usemap"); |
432 |
|
|
433 |
|
/** |
434 |
|
* The valign attribute |
435 |
|
*/ |
436 |
|
public static final Attribute VALIGN = new Attribute("valign"); |
437 |
|
|
438 |
|
/** |
439 |
|
* The value attribute |
440 |
|
*/ |
441 |
|
public static final Attribute VALUE = new Attribute("value"); |
442 |
|
|
443 |
|
/** |
444 |
|
* The valuetype attribute |
445 |
|
*/ |
446 |
|
public static final Attribute VALUETYPE = new Attribute("valuetype"); |
447 |
|
|
448 |
|
/** |
449 |
|
* The version attribute |
450 |
|
*/ |
451 |
|
public static final Attribute VERSION = new Attribute("version"); |
452 |
|
|
453 |
|
/** |
454 |
|
* The vlink attribute |
455 |
|
*/ |
456 |
|
public static final Attribute VLINK = new Attribute("vlink"); |
457 |
|
|
458 |
|
/** |
459 |
|
* The vspace attribute |
460 |
|
*/ |
461 |
|
public static final Attribute VSPACE = new Attribute("vspace"); |
462 |
|
|
463 |
|
/** |
464 |
|
* The width attribute |
465 |
|
*/ |
466 |
|
public static final Attribute WIDTH = new Attribute("width"); |
467 |
|
private final String name; |
468 |
|
|
469 |
|
/** |
470 |
|
* Creates the attribute with the given name. |
471 |
|
*/ |
472 |
|
protected Attribute(String a_name) |
473 |
|
{ |
474 |
|
name = a_name; |
475 |
|
} |
476 |
|
|
477 |
|
/** |
478 |
|
* Calls compareTo on the tag names (Strings) |
479 |
|
*/ |
480 |
|
public int compareTo(Object other) |
481 |
|
{ |
482 |
|
return name.compareTo(((Attribute) other).name); |
483 |
|
} |
484 |
|
|
485 |
|
/** |
486 |
|
* The attributes are equal if the names are equal |
487 |
|
* (ignoring case) |
488 |
|
*/ |
489 |
|
public boolean equals(Object other) |
490 |
|
{ |
491 |
|
if (other == this) |
492 |
|
return true; |
493 |
|
|
494 |
|
if (!(other instanceof Attribute)) |
495 |
|
return false; |
496 |
|
|
497 |
|
Attribute that = (Attribute) other; |
498 |
|
|
499 |
|
return that.name.equalsIgnoreCase(name); |
500 |
|
} |
501 |
|
|
502 |
|
/** |
503 |
|
* Returns the hash code which corresponds to the string for this tag. |
504 |
|
*/ |
505 |
|
public int hashCode() |
506 |
|
{ |
507 |
|
return name == null ? 0 : name.hashCode(); |
508 |
|
} |
509 |
|
|
510 |
|
/** |
511 |
|
* Returns the attribute name. The names of the built-in attributes |
512 |
|
* are always returned in lowercase. |
513 |
|
*/ |
514 |
|
public String toString() |
515 |
{ |
{ |
516 |
this.id = id; |
return name; |
517 |
|
} |
518 |
|
|
519 |
|
/** |
520 |
|
* Return an array of all attributes, declared in the HTML.Attribute |
521 |
|
* class. WARNING: attributes are the only public fields, |
522 |
|
* expected in this class. |
523 |
|
*/ |
524 |
|
static Attribute[] getAllAttributes() |
525 |
|
{ |
526 |
|
Field[] f = Attribute.class.getFields(); |
527 |
|
Attribute[] attrs = new Attribute[ f.length ]; |
528 |
|
Field x; |
529 |
|
int p = 0; |
530 |
|
Attribute a; |
531 |
|
|
532 |
|
for (int i = 0; i < f.length; i++) |
533 |
|
{ |
534 |
|
x = f [ i ]; |
535 |
|
|
536 |
|
if ((x.getModifiers() & Modifier.STATIC) != 0) |
537 |
|
{ |
538 |
|
if (x.getType().equals(Attribute.class)) |
539 |
|
{ |
540 |
|
try |
541 |
|
{ |
542 |
|
a = (Attribute) x.get(null); |
543 |
|
attrs [ p++ ] = a; |
544 |
|
} |
545 |
|
catch (Exception ex) |
546 |
|
{ |
547 |
|
ex.printStackTrace(System.err); |
548 |
|
throw new Error("This should never happen, report a bug"); |
549 |
|
} |
550 |
|
} |
551 |
|
} |
552 |
|
} |
553 |
|
|
554 |
|
return attrs; |
555 |
} |
} |
556 |
} |
} |
557 |
|
|
558 |
public static class UnknownTag extends Tag implements Serializable |
/** |
559 |
|
* Represents a HTML tag. |
560 |
|
*/ |
561 |
|
public static class Tag |
562 |
|
implements Comparable, Serializable |
563 |
{ |
{ |
564 |
/** |
/** |
565 |
* For compatability with Sun's JDK 1.4.2 rev. 5 |
* The <a> tag |
566 |
|
*/ |
567 |
|
public static final Tag A = new Tag("a"); |
568 |
|
|
569 |
|
/** |
570 |
|
* The <address> tag |
571 |
|
*/ |
572 |
|
public static final Tag ADDRESS = new Tag("address"); |
573 |
|
|
574 |
|
/** |
575 |
|
* The <applet> tag |
576 |
|
*/ |
577 |
|
public static final Tag APPLET = new Tag("applet"); |
578 |
|
|
579 |
|
/** |
580 |
|
* The <area> tag |
581 |
|
*/ |
582 |
|
public static final Tag AREA = new Tag("area"); |
583 |
|
|
584 |
|
/** |
585 |
|
* The <b> tag |
586 |
|
*/ |
587 |
|
public static final Tag B = new Tag("b"); |
588 |
|
|
589 |
|
/** |
590 |
|
* The <base> tag |
591 |
|
*/ |
592 |
|
public static final Tag BASE = new Tag("base"); |
593 |
|
|
594 |
|
/** |
595 |
|
* The <basefont> tag |
596 |
|
*/ |
597 |
|
public static final Tag BASEFONT = new Tag("basefont"); |
598 |
|
|
599 |
|
/** |
600 |
|
* The <big> tag |
601 |
|
*/ |
602 |
|
public static final Tag BIG = new Tag("big"); |
603 |
|
|
604 |
|
/** |
605 |
|
* The <blockquote> tag , breaks flow, block tag. |
606 |
|
*/ |
607 |
|
public static final Tag BLOCKQUOTE = new Tag("blockquote", BREAKS | BLOCK); |
608 |
|
|
609 |
|
/** |
610 |
|
* The <body> tag , breaks flow, block tag. |
611 |
|
*/ |
612 |
|
public static final Tag BODY = new Tag("body", BREAKS | BLOCK); |
613 |
|
|
614 |
|
/** |
615 |
|
* The <br> tag , breaks flow. |
616 |
|
*/ |
617 |
|
public static final Tag BR = new Tag("br", BREAKS); |
618 |
|
|
619 |
|
/** |
620 |
|
* The <caption> tag |
621 |
|
*/ |
622 |
|
public static final Tag CAPTION = new Tag("caption"); |
623 |
|
|
624 |
|
/** |
625 |
|
* The <center> tag , breaks flow. |
626 |
|
*/ |
627 |
|
public static final Tag CENTER = new Tag("center", BREAKS); |
628 |
|
|
629 |
|
/** |
630 |
|
* The <cite> tag |
631 |
|
*/ |
632 |
|
public static final Tag CITE = new Tag("cite"); |
633 |
|
|
634 |
|
/** |
635 |
|
* The <code> tag |
636 |
|
*/ |
637 |
|
public static final Tag CODE = new Tag("code"); |
638 |
|
|
639 |
|
/** |
640 |
|
* The <dd> tag , breaks flow, block tag. |
641 |
|
*/ |
642 |
|
public static final Tag DD = new Tag("dd", BREAKS | BLOCK); |
643 |
|
|
644 |
|
/** |
645 |
|
* The <dfn> tag |
646 |
|
*/ |
647 |
|
public static final Tag DFN = new Tag("dfn"); |
648 |
|
|
649 |
|
/** |
650 |
|
* The <dir> tag , breaks flow, block tag. |
651 |
|
*/ |
652 |
|
public static final Tag DIR = new Tag("dir", BREAKS | BLOCK); |
653 |
|
|
654 |
|
/** |
655 |
|
* The <div> tag , breaks flow, block tag. |
656 |
|
*/ |
657 |
|
public static final Tag DIV = new Tag("div", BREAKS | BLOCK); |
658 |
|
|
659 |
|
/** |
660 |
|
* The <dl> tag , breaks flow, block tag. |
661 |
|
*/ |
662 |
|
public static final Tag DL = new Tag("dl", BREAKS | BLOCK); |
663 |
|
|
664 |
|
/** |
665 |
|
* The <dt> tag , breaks flow, block tag. |
666 |
|
*/ |
667 |
|
public static final Tag DT = new Tag("dt", BREAKS | BLOCK); |
668 |
|
|
669 |
|
/** |
670 |
|
* The <em> tag |
671 |
|
*/ |
672 |
|
public static final Tag EM = new Tag("em"); |
673 |
|
|
674 |
|
/** |
675 |
|
* The <font> tag |
676 |
|
*/ |
677 |
|
public static final Tag FONT = new Tag("font"); |
678 |
|
|
679 |
|
/** |
680 |
|
* The <form> tag , breaks flow. |
681 |
|
*/ |
682 |
|
public static final Tag FORM = new Tag("form", BREAKS); |
683 |
|
|
684 |
|
/** |
685 |
|
* The <frame> tag |
686 |
|
*/ |
687 |
|
public static final Tag FRAME = new Tag("frame"); |
688 |
|
|
689 |
|
/** |
690 |
|
* The <frameset> tag |
691 |
|
*/ |
692 |
|
public static final Tag FRAMESET = new Tag("frameset"); |
693 |
|
|
694 |
|
/** |
695 |
|
* The <h1> tag , breaks flow, block tag. |
696 |
|
*/ |
697 |
|
public static final Tag H1 = new Tag("h1", BREAKS | BLOCK); |
698 |
|
|
699 |
|
/** |
700 |
|
* The <h2> tag , breaks flow, block tag. |
701 |
|
*/ |
702 |
|
public static final Tag H2 = new Tag("h2", BREAKS | BLOCK); |
703 |
|
|
704 |
|
/** |
705 |
|
* The <h3> tag , breaks flow, block tag. |
706 |
|
*/ |
707 |
|
public static final Tag H3 = new Tag("h3", BREAKS | BLOCK); |
708 |
|
|
709 |
|
/** |
710 |
|
* The <h4> tag , breaks flow, block tag. |
711 |
|
*/ |
712 |
|
public static final Tag H4 = new Tag("h4", BREAKS | BLOCK); |
713 |
|
|
714 |
|
/** |
715 |
|
* The <h5> tag , breaks flow, block tag. |
716 |
|
*/ |
717 |
|
public static final Tag H5 = new Tag("h5", BREAKS | BLOCK); |
718 |
|
|
719 |
|
/** |
720 |
|
* The <h6> tag , breaks flow, block tag. |
721 |
|
*/ |
722 |
|
public static final Tag H6 = new Tag("h6", BREAKS | BLOCK); |
723 |
|
|
724 |
|
/** |
725 |
|
* The <head> tag , breaks flow, block tag. |
726 |
|
*/ |
727 |
|
public static final Tag HEAD = new Tag("head", BREAKS | BLOCK); |
728 |
|
|
729 |
|
/** |
730 |
|
* The <hr> tag , breaks flow. |
731 |
|
*/ |
732 |
|
public static final Tag HR = new Tag("hr", BREAKS); |
733 |
|
|
734 |
|
/** |
735 |
|
* The <html> tag , breaks flow. |
736 |
|
*/ |
737 |
|
public static final Tag HTML = new Tag("html", BREAKS); |
738 |
|
|
739 |
|
/** |
740 |
|
* The <i> tag |
741 |
|
*/ |
742 |
|
public static final Tag I = new Tag("i"); |
743 |
|
|
744 |
|
/** |
745 |
|
* The <img> tag |
746 |
|
*/ |
747 |
|
public static final Tag IMG = new Tag("img"); |
748 |
|
|
749 |
|
/** |
750 |
|
* The <input> tag |
751 |
|
*/ |
752 |
|
public static final Tag INPUT = new Tag("input"); |
753 |
|
|
754 |
|
/** |
755 |
|
* The <isindex> tag , breaks flow. |
756 |
|
*/ |
757 |
|
public static final Tag ISINDEX = new Tag("isindex", BREAKS); |
758 |
|
|
759 |
|
/** |
760 |
|
* The <kbd> tag |
761 |
|
*/ |
762 |
|
public static final Tag KBD = new Tag("kbd"); |
763 |
|
|
764 |
|
/** |
765 |
|
* The <li> tag , breaks flow, block tag. |
766 |
|
*/ |
767 |
|
public static final Tag LI = new Tag("li", BREAKS | BLOCK); |
768 |
|
|
769 |
|
/** |
770 |
|
* The <link> tag |
771 |
|
*/ |
772 |
|
public static final Tag LINK = new Tag("link"); |
773 |
|
|
774 |
|
/** |
775 |
|
* The <map> tag |
776 |
|
*/ |
777 |
|
public static final Tag MAP = new Tag("map"); |
778 |
|
|
779 |
|
/** |
780 |
|
* The <menu> tag , breaks flow, block tag. |
781 |
|
*/ |
782 |
|
public static final Tag MENU = new Tag("menu", BREAKS | BLOCK); |
783 |
|
|
784 |
|
/** |
785 |
|
* The <meta> tag |
786 |
|
*/ |
787 |
|
public static final Tag META = new Tag("meta"); |
788 |
|
|
789 |
|
/** |
790 |
|
* The <nobr> tag |
791 |
|
*/ |
792 |
|
public static final Tag NOBR = new Tag("nobr"); |
793 |
|
|
794 |
|
/** |
795 |
|
* The <noframes> tag , breaks flow, block tag. |
796 |
|
*/ |
797 |
|
public static final Tag NOFRAMES = new Tag("noframes", BREAKS | BLOCK); |
798 |
|
|
799 |
|
/** |
800 |
|
* The <object> tag |
801 |
|
*/ |
802 |
|
public static final Tag OBJECT = new Tag("object"); |
803 |
|
|
804 |
|
/** |
805 |
|
* The <ol> tag , breaks flow, block tag. |
806 |
|
*/ |
807 |
|
public static final Tag OL = new Tag("ol", BREAKS | BLOCK); |
808 |
|
|
809 |
|
/** |
810 |
|
* The <option> tag |
811 |
|
*/ |
812 |
|
public static final Tag OPTION = new Tag("option"); |
813 |
|
|
814 |
|
/** |
815 |
|
* The <p> tag , breaks flow, block tag. |
816 |
|
*/ |
817 |
|
public static final Tag P = new Tag("p", BREAKS | BLOCK); |
818 |
|
|
819 |
|
/** |
820 |
|
* The <param> tag |
821 |
|
*/ |
822 |
|
public static final Tag PARAM = new Tag("param"); |
823 |
|
|
824 |
|
/** |
825 |
|
* The <pre> tag , breaks flow, block tag, preformatted. |
826 |
*/ |
*/ |
827 |
|
public static final Tag PRE = new Tag("pre", BREAKS | BLOCK | PREFORMATTED); |
828 |
|
|
829 |
|
/** |
830 |
|
* The <s> tag |
831 |
|
*/ |
832 |
|
public static final Tag S = new Tag("s"); |
833 |
|
|
834 |
|
/** |
835 |
|
* The <samp> tag |
836 |
|
*/ |
837 |
|
public static final Tag SAMP = new Tag("samp"); |
838 |
|
|
839 |
|
/** |
840 |
|
* The <script> tag |
841 |
|
*/ |
842 |
|
public static final Tag SCRIPT = new Tag("script"); |
843 |
|
|
844 |
|
/** |
845 |
|
* The <select> tag |
846 |
|
*/ |
847 |
|
public static final Tag SELECT = new Tag("select"); |
848 |
|
|
849 |
|
/** |
850 |
|
* The <small> tag |
851 |
|
*/ |
852 |
|
public static final Tag SMALL = new Tag("small"); |
853 |
|
|
854 |
|
/** |
855 |
|
* The <span> tag |
856 |
|
*/ |
857 |
|
public static final Tag SPAN = new Tag("span"); |
858 |
|
|
859 |
|
/** |
860 |
|
* The <strike> tag |
861 |
|
*/ |
862 |
|
public static final Tag STRIKE = new Tag("strike"); |
863 |
|
|
864 |
|
/** |
865 |
|
* The <strong> tag |
866 |
|
*/ |
867 |
|
public static final Tag STRONG = new Tag("strong"); |
868 |
|
|
869 |
|
/** |
870 |
|
* The <style> tag |
871 |
|
*/ |
872 |
|
public static final Tag STYLE = new Tag("style"); |
873 |
|
|
874 |
|
/** |
875 |
|
* The <sub> tag |
876 |
|
*/ |
877 |
|
public static final Tag SUB = new Tag("sub"); |
878 |
|
|
879 |
|
/** |
880 |
|
* The <sup> tag |
881 |
|
*/ |
882 |
|
public static final Tag SUP = new Tag("sup"); |
883 |
|
|
884 |
|
/** |
885 |
|
* The <table> tag , block tag. |
886 |
|
*/ |
887 |
|
public static final Tag TABLE = new Tag("table", BLOCK); |
888 |
|
|
889 |
|
/** |
890 |
|
* The <td> tag , breaks flow, block tag. |
891 |
|
*/ |
892 |
|
public static final Tag TD = new Tag("td", BREAKS | BLOCK); |
893 |
|
|
894 |
|
/** |
895 |
|
* The <textarea> tag , preformatted. |
896 |
|
*/ |
897 |
|
public static final Tag TEXTAREA = new Tag("textarea", PREFORMATTED); |
898 |
|
|
899 |
|
/** |
900 |
|
* The <th> tag , breaks flow, block tag. |
901 |
|
*/ |
902 |
|
public static final Tag TH = new Tag("th", BREAKS | BLOCK); |
903 |
|
|
904 |
|
/** |
905 |
|
* The <title> tag , breaks flow, block tag. |
906 |
|
*/ |
907 |
|
public static final Tag TITLE = new Tag("title", BREAKS | BLOCK); |
908 |
|
|
909 |
|
/** |
910 |
|
* The <tr> tag , block tag. |
911 |
|
*/ |
912 |
|
public static final Tag TR = new Tag("tr", BLOCK); |
913 |
|
|
914 |
|
/** |
915 |
|
* The <tt> tag |
916 |
|
*/ |
917 |
|
public static final Tag TT = new Tag("tt"); |
918 |
|
|
919 |
|
/** |
920 |
|
* The <u> tag |
921 |
|
*/ |
922 |
|
public static final Tag U = new Tag("u"); |
923 |
|
|
924 |
|
/** |
925 |
|
* The <ul> tag , breaks flow, block tag. |
926 |
|
*/ |
927 |
|
public static final Tag UL = new Tag("ul", BREAKS | BLOCK); |
928 |
|
|
929 |
|
/** |
930 |
|
* The <var> tag |
931 |
|
*/ |
932 |
|
public static final Tag VAR = new Tag("var"); |
933 |
|
|
934 |
|
/* Special tags */ |
935 |
|
|
936 |
|
/** |
937 |
|
* Total number of syntetic tags, delared in the Tag class. |
938 |
|
* This must be adjusted if the new synthetic tags are declared. |
939 |
|
* Otherwise the HTML.getAllTags() will not work as expected. |
940 |
|
*/ |
941 |
|
private static final int TOTAL_SYNTHETIC_TAGS = 3; |
942 |
|
|
943 |
|
/** |
944 |
|
* All comments are labeled with this tag. |
945 |
|
* This tag is not included into the array, returned by getAllTags(). |
946 |
|
* toString() returns 'comment'. HTML reader synthesizes this tag. |
947 |
|
*/ |
948 |
|
public static final Tag COMMENT = new Tag("comment", SYNTETIC); |
949 |
|
|
950 |
|
/** |
951 |
|
* All text content is labeled with this tag. |
952 |
|
* This tag is not included into the array, returned by getAllTags(). |
953 |
|
* toString() returns 'content'. HTML reader synthesizes this tag. |
954 |
|
*/ |
955 |
|
public static final Tag CONTENT = new Tag("content", SYNTETIC); |
956 |
|
|
957 |
|
/** |
958 |
|
* All text content must be in a paragraph element. |
959 |
|
* If a paragraph didn't exist when content was encountered, |
960 |
|
* a paragraph is manufactured. |
961 |
|
* toString() returns 'implied'. HTML reader synthesizes this tag. |
962 |
|
*/ |
963 |
|
public static final Tag IMPLIED = new Tag("implied", SYNTETIC); |
964 |
|
final String name; |
965 |
|
final int flags; |
966 |
|
|
967 |
|
/** |
968 |
|
* Creates a new Tag with the specified id, and with causesBreak |
969 |
|
* and isBlock set to false. |
970 |
|
*/ |
971 |
|
protected Tag(String id) |
972 |
|
{ |
973 |
|
name = id; |
974 |
|
flags = 0; |
975 |
|
} |
976 |
|
|
977 |
|
/** |
978 |
|
* Creates a new Tag with the specified tag name and |
979 |
|
* causesBreak and isBlock properties. |
980 |
|
*/ |
981 |
|
protected Tag(String id, boolean causesBreak, boolean isBlock) |
982 |
|
{ |
983 |
|
int f = 0; |
984 |
|
|
985 |
|
if (causesBreak) |
986 |
|
{ |
987 |
|
f |= BREAKS; |
988 |
|
} |
989 |
|
|
990 |
|
if (isBlock) |
991 |
|
{ |
992 |
|
f |= BLOCK; |
993 |
|
} |
994 |
|
|
995 |
|
flags = f; |
996 |
|
name = id; |
997 |
|
} |
998 |
|
|
999 |
|
/** |
1000 |
|
* Create a tag taking flags. |
1001 |
|
*/ |
1002 |
|
Tag(String id, int a_flags) |
1003 |
|
{ |
1004 |
|
name = id; |
1005 |
|
flags = a_flags; |
1006 |
|
} |
1007 |
|
|
1008 |
|
/** |
1009 |
|
* Returns true if this tag is a block tag, which is a tag used to |
1010 |
|
* add structure to a document. |
1011 |
|
*/ |
1012 |
|
public boolean isBlock() |
1013 |
|
{ |
1014 |
|
return (flags & BLOCK) != 0; |
1015 |
|
} |
1016 |
|
|
1017 |
|
/** |
1018 |
|
* Returns true if this tag is pre-formatted, which is true if |
1019 |
|
* the tag is either PRE or TEXTAREA |
1020 |
|
*/ |
1021 |
|
public boolean isPreformatted() |
1022 |
|
{ |
1023 |
|
return (flags & PREFORMATTED) != 0; |
1024 |
|
} |
1025 |
|
|
1026 |
|
/** |
1027 |
|
* Returns true if this tag causes a line break to the flow of text |
1028 |
|
*/ |
1029 |
|
public boolean breaksFlow() |
1030 |
|
{ |
1031 |
|
return (flags & BREAKS) != 0; |
1032 |
|
} |
1033 |
|
|
1034 |
|
/** |
1035 |
|
* Calls compareTo on the tag names (Strings) |
1036 |
|
*/ |
1037 |
|
public int compareTo(Object other) |
1038 |
|
{ |
1039 |
|
return name.compareTo(((Tag) other).name); |
1040 |
|
} |
1041 |
|
|
1042 |
|
/** |
1043 |
|
* The tags are equal if the names are equal (ignoring case). |
1044 |
|
*/ |
1045 |
|
public boolean equals(Object other) |
1046 |
|
{ |
1047 |
|
if (other == this) |
1048 |
|
{ |
1049 |
|
return true; |
1050 |
|
} |
1051 |
|
|
1052 |
|
if (!(other instanceof Tag)) |
1053 |
|
{ |
1054 |
|
return false; |
1055 |
|
} |
1056 |
|
|
1057 |
|
Tag that = (Tag) other; |
1058 |
|
|
1059 |
|
return that.name.equalsIgnoreCase(name); |
1060 |
|
} |
1061 |
|
|
1062 |
|
/** |
1063 |
|
* Returns the hash code which corresponds to the string for this tag. |
1064 |
|
*/ |
1065 |
|
public int hashCode() |
1066 |
|
{ |
1067 |
|
return name == null ? 0 : name.hashCode(); |
1068 |
|
} |
1069 |
|
|
1070 |
|
/** |
1071 |
|
* Returns the tag name. The names of the built-in tags are always |
1072 |
|
* returned in lowercase. |
1073 |
|
*/ |
1074 |
|
public String toString() |
1075 |
|
{ |
1076 |
|
return name; |
1077 |
|
} |
1078 |
|
|
1079 |
|
/** |
1080 |
|
* Return an array of HTML tags, declared in HTML.Tag class. |
1081 |
|
* WARNING: This method expects that the Tags are the only |
1082 |
|
* public fields declared in the Tag class. |
1083 |
|
*/ |
1084 |
|
static Tag[] getAllTags() |
1085 |
|
{ |
1086 |
|
Field[] f = Tag.class.getFields(); |
1087 |
|
Field x; |
1088 |
|
|
1089 |
|
// The syntetic tags are not included. |
1090 |
|
Tag[] tags = new Tag[ f.length - TOTAL_SYNTHETIC_TAGS ]; |
1091 |
|
int p = 0; |
1092 |
|
Tag t; |
1093 |
|
|
1094 |
|
for (int i = 0; i < f.length; i++) |
1095 |
|
{ |
1096 |
|
x = f [ i ]; |
1097 |
|
|
1098 |
|
if ((x.getModifiers() & Modifier.STATIC) != 0) |
1099 |
|
{ |
1100 |
|
if (x.getType().equals(Tag.class)) |
1101 |
|
{ |
1102 |
|
try |
1103 |
|
{ |
1104 |
|
t = (Tag) x.get(null); |
1105 |
|
|
1106 |
|
if (!t.isSyntetic()) |
1107 |
|
{ |
1108 |
|
tags [ p++ ] = t; |
1109 |
|
} |
1110 |
|
} |
1111 |
|
catch (IllegalAccessException ex) |
1112 |
|
{ |
1113 |
|
unexpected(ex); |
1114 |
|
} |
1115 |
|
catch (IllegalArgumentException ex) |
1116 |
|
{ |
1117 |
|
unexpected(ex); |
1118 |
|
} |
1119 |
|
} |
1120 |
|
} |
1121 |
|
} |
1122 |
|
|
1123 |
|
return tags; |
1124 |
|
} |
1125 |
|
|
1126 |
|
/** |
1127 |
|
* Returns true for tags, generated by the html reader |
1128 |
|
* (COMMENT, CONTENT and IMPLIED). |
1129 |
|
*/ |
1130 |
|
boolean isSyntetic() |
1131 |
|
{ |
1132 |
|
return (flags & SYNTETIC) != 0; |
1133 |
|
} |
1134 |
|
|
1135 |
|
private static void unexpected(Exception ex) |
1136 |
|
throws Error |
1137 |
|
{ |
1138 |
|
throw new Error("This should never happen, report a bug", ex); |
1139 |
|
} |
1140 |
|
} |
1141 |
|
|
1142 |
|
/** |
1143 |
|
* Represents an unknown HTML tag. |
1144 |
|
* @author Mark Wielaard (mark@klomp.org) |
1145 |
|
*/ |
1146 |
|
public static class UnknownTag |
1147 |
|
extends Tag |
1148 |
|
implements Serializable |
1149 |
|
{ |
1150 |
private static final long serialVersionUID = -1534369342247250625L; |
private static final long serialVersionUID = -1534369342247250625L; |
1151 |
|
|
1152 |
public UnknownTag(String id) |
/** |
1153 |
|
* Creates a new UnknownTag with the specified name |
1154 |
|
* @param name The tag name. |
1155 |
|
* |
1156 |
|
*/ |
1157 |
|
public UnknownTag(String name) |
1158 |
{ |
{ |
1159 |
super(id); |
super(name); |
1160 |
} |
} |
1161 |
} |
} |
1162 |
|
|
1163 |
|
/** |
1164 |
|
* This value is returned for attributes without value that have no |
1165 |
|
* default value defined in the DTD. |
1166 |
|
*/ |
1167 |
|
public static final String NULL_ATTRIBUTE_VALUE = "#DEFAULT"; |
1168 |
|
|
1169 |
|
/* Package level html tag flags */ |
1170 |
|
static final int BREAKS = 1; |
1171 |
|
static final int BLOCK = 2; |
1172 |
|
static final int PREFORMATTED = 4; |
1173 |
|
static final int SYNTETIC = 8; |
1174 |
|
private static Map tagMap; |
1175 |
|
private static Map attrMap; |
1176 |
|
|
1177 |
|
/** |
1178 |
|
* The public constructor (does nothing). It it seldom required to have |
1179 |
|
* an instance of this class, because all public fields and methods |
1180 |
|
* are static. |
1181 |
|
*/ |
1182 |
|
public HTML() |
1183 |
|
{ |
1184 |
|
} |
1185 |
|
|
1186 |
|
/** |
1187 |
|
* Returns the set of the recognized HTML attributes. |
1188 |
|
*/ |
1189 |
|
public static HTML.Attribute[] getAllAttributeKeys() |
1190 |
|
{ |
1191 |
|
return Attribute.getAllAttributes(); |
1192 |
|
} |
1193 |
|
|
1194 |
|
/** |
1195 |
|
* Returns the set of actual HTML tags that are recognized by |
1196 |
|
* the default HTML reader. The returned array does not include the |
1197 |
|
* COMMENT, CONTENT and IMPLIED tags. |
1198 |
|
*/ |
1199 |
|
public static HTML.Tag[] getAllTags() |
1200 |
|
{ |
1201 |
|
return Tag.getAllTags(); |
1202 |
|
} |
1203 |
|
|
1204 |
|
/** |
1205 |
|
* Returns an htl attribute constant for the given attribute name. |
1206 |
|
* @param attName the attribute name, case insensitive |
1207 |
|
*/ |
1208 |
|
public static Attribute getAttributeKey(String attName) |
1209 |
|
{ |
1210 |
|
if (attrMap == null) |
1211 |
|
{ |
1212 |
|
// Create the map on demand. |
1213 |
|
attrMap = new TreeMap(); |
1214 |
|
|
1215 |
|
Attribute[] attrs = getAllAttributeKeys(); |
1216 |
|
|
1217 |
|
for (int i = 0; i < attrs.length; i++) |
1218 |
|
{ |
1219 |
|
attrMap.put(attrs [ i ].toString(), attrs [ i ]); |
1220 |
|
} |
1221 |
|
} |
1222 |
|
|
1223 |
|
return (Attribute) attrMap.get(attName.toLowerCase()); |
1224 |
|
} |
1225 |
|
|
1226 |
|
/** |
1227 |
|
* Searches the value of given attribute in the provided set. |
1228 |
|
* If the value is found (String type expected), tries to parse it as |
1229 |
|
* an integer value. If succeded, returns the obtained integer value. |
1230 |
|
* |
1231 |
|
* For example:<p><code> |
1232 |
|
* SimpleAttributeSet ase = new SimpleAttributeSet(); |
1233 |
|
* ase.addAttribute(HTML.getAttributeKey("size"),"222"); |
1234 |
|
* System.out.println( |
1235 |
|
* HTML.getIntegerAttributeValue |
1236 |
|
* (ase, HTML.getAttributeKey("size"), 333)); // prints "222" |
1237 |
|
* System.out.println( |
1238 |
|
* HTML.getIntegerAttributeValue |
1239 |
|
* (ase, HTML.getAttributeKey("width"), 333)); // prints "333". |
1240 |
|
* </code></p> |
1241 |
|
* |
1242 |
|
* |
1243 |
|
* @param set The attribute set to search in. If the set contains the |
1244 |
|
* given attribute, it must by a type of String. |
1245 |
|
* @param attribute The html attribute to search in |
1246 |
|
* @param defaultValue The value that is returned if the attribute is not |
1247 |
|
* found in the given set or if the NumberFormatException was thrown |
1248 |
|
* during the parsing. |
1249 |
|
*/ |
1250 |
|
public static int getIntegerAttributeValue(AttributeSet set, |
1251 |
|
HTML.Attribute attribute, |
1252 |
|
int defaultValue |
1253 |
|
) |
1254 |
|
{ |
1255 |
|
Object v = set.getAttribute(attribute); |
1256 |
|
|
1257 |
|
if (v == null) |
1258 |
|
{ |
1259 |
|
return defaultValue; |
1260 |
|
} |
1261 |
|
|
1262 |
|
try |
1263 |
|
{ |
1264 |
|
return Integer.parseInt(v.toString().trim()); |
1265 |
|
} |
1266 |
|
catch (Exception ex) |
1267 |
|
{ |
1268 |
|
return defaultValue; |
1269 |
|
} |
1270 |
|
} |
1271 |
|
|
1272 |
|
/** |
1273 |
|
* Returns a HTML tag constant for the given HTML attribute name. |
1274 |
|
* If the tag is unknown, the null is returned. |
1275 |
|
* @param tagName the tag name, case insensitive |
1276 |
|
*/ |
1277 |
|
public static Tag getTag(String tagName) |
1278 |
|
{ |
1279 |
|
if (tagMap == null) |
1280 |
|
{ |
1281 |
|
// Create the mao on demand. |
1282 |
|
tagMap = new TreeMap(); |
1283 |
|
|
1284 |
|
Tag[] tags = getAllTags(); |
1285 |
|
|
1286 |
|
for (int i = 0; i < tags.length; i++) |
1287 |
|
{ |
1288 |
|
tagMap.put(tags [ i ].toString(), tags [ i ]); |
1289 |
|
} |
1290 |
|
} |
1291 |
|
|
1292 |
|
return (Tag) tagMap.get(tagName.toLowerCase()); |
1293 |
|
} |
1294 |
} |
} |