OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [javax/] [swing/] [text/] [html/] [HTML.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* HTML.java -- HTML document tag constants
2
   Copyright (C) 2002 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package javax.swing.text.html;
40
 
41
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
 * HTML attribute and tag definitions.
53
 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
54
 */
55
public class HTML
56
{
57
  /**
58
   * Represents a HTML attribute.
59
   */
60
  public static class Attribute
61
    implements Serializable
62
  {
63
    /**
64
     * The action attribute
65
     */
66
    public static final Attribute ACTION = new Attribute("action");
67
 
68
    /**
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
      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
  /**
559
   * Represents a HTML tag.
560
   */
561
  public static class Tag
562
    implements Comparable, Serializable
563
  {
564
    /**
565
     * The &lt;a&gt; tag
566
     */
567
    public static final Tag A = new Tag("a");
568
 
569
    /**
570
     * The &lt;address&gt; tag
571
     */
572
    public static final Tag ADDRESS = new Tag("address");
573
 
574
    /**
575
     * The &lt;applet&gt; tag
576
     */
577
    public static final Tag APPLET = new Tag("applet");
578
 
579
    /**
580
     * The &lt;area&gt; tag
581
     */
582
    public static final Tag AREA = new Tag("area");
583
 
584
    /**
585
     * The &lt;b&gt; tag
586
     */
587
    public static final Tag B = new Tag("b");
588
 
589
    /**
590
     * The &lt;base&gt; tag
591
     */
592
    public static final Tag BASE = new Tag("base");
593
 
594
    /**
595
     * The &lt;basefont&gt; tag
596
     */
597
    public static final Tag BASEFONT = new Tag("basefont");
598
 
599
    /**
600
     * The &lt;big&gt; tag
601
     */
602
    public static final Tag BIG = new Tag("big");
603
 
604
    /**
605
     * The &lt;blockquote&gt; tag , breaks flow, block tag.
606
     */
607
    public static final Tag BLOCKQUOTE = new Tag("blockquote", BREAKS | BLOCK);
608
 
609
    /**
610
     * The &lt;body&gt; tag , breaks flow, block tag.
611
     */
612
    public static final Tag BODY = new Tag("body", BREAKS | BLOCK);
613
 
614
    /**
615
     * The &lt;br&gt; tag , breaks flow.
616
     */
617
    public static final Tag BR = new Tag("br", BREAKS);
618
 
619
    /**
620
     * The &lt;caption&gt; tag
621
     */
622
    public static final Tag CAPTION = new Tag("caption");
623
 
624
    /**
625
     * The &lt;center&gt; tag , breaks flow.
626
     */
627
    public static final Tag CENTER = new Tag("center", BREAKS);
628
 
629
    /**
630
     * The &lt;cite&gt; tag
631
     */
632
    public static final Tag CITE = new Tag("cite");
633
 
634
    /**
635
     * The &lt;code&gt; tag
636
     */
637
    public static final Tag CODE = new Tag("code");
638
 
639
    /**
640
     * The &lt;dd&gt; tag , breaks flow, block tag.
641
     */
642
    public static final Tag DD = new Tag("dd", BREAKS | BLOCK);
643
 
644
    /**
645
     * The &lt;dfn&gt; tag
646
     */
647
    public static final Tag DFN = new Tag("dfn");
648
 
649
    /**
650
     * The &lt;dir&gt; tag , breaks flow, block tag.
651
     */
652
    public static final Tag DIR = new Tag("dir", BREAKS | BLOCK);
653
 
654
    /**
655
     * The &lt;div&gt; tag , breaks flow, block tag.
656
     */
657
    public static final Tag DIV = new Tag("div", BREAKS | BLOCK);
658
 
659
    /**
660
     * The &lt;dl&gt; tag , breaks flow, block tag.
661
     */
662
    public static final Tag DL = new Tag("dl", BREAKS | BLOCK);
663
 
664
    /**
665
     * The &lt;dt&gt; tag , breaks flow, block tag.
666
     */
667
    public static final Tag DT = new Tag("dt", BREAKS | BLOCK);
668
 
669
    /**
670
     * The &lt;em&gt; tag
671
     */
672
    public static final Tag EM = new Tag("em");
673
 
674
    /**
675
     * The &lt;font&gt; tag
676
     */
677
    public static final Tag FONT = new Tag("font");
678
 
679
    /**
680
     * The &lt;form&gt; tag , breaks flow.
681
     */
682
    public static final Tag FORM = new Tag("form", BREAKS);
683
 
684
    /**
685
     * The &lt;frame&gt; tag
686
     */
687
    public static final Tag FRAME = new Tag("frame");
688
 
689
    /**
690
     * The &lt;frameset&gt; tag
691
     */
692
    public static final Tag FRAMESET = new Tag("frameset");
693
 
694
    /**
695
     * The &lt;h1&gt; tag , breaks flow, block tag.
696
     */
697
    public static final Tag H1 = new Tag("h1", BREAKS | BLOCK);
698
 
699
    /**
700
     * The &lt;h2&gt; tag , breaks flow, block tag.
701
     */
702
    public static final Tag H2 = new Tag("h2", BREAKS | BLOCK);
703
 
704
    /**
705
     * The &lt;h3&gt; tag , breaks flow, block tag.
706
     */
707
    public static final Tag H3 = new Tag("h3", BREAKS | BLOCK);
708
 
709
    /**
710
     * The &lt;h4&gt; tag , breaks flow, block tag.
711
     */
712
    public static final Tag H4 = new Tag("h4", BREAKS | BLOCK);
713
 
714
    /**
715
     * The &lt;h5&gt; tag , breaks flow, block tag.
716
     */
717
    public static final Tag H5 = new Tag("h5", BREAKS | BLOCK);
718
 
719
    /**
720
     * The &lt;h6&gt; tag , breaks flow, block tag.
721
     */
722
    public static final Tag H6 = new Tag("h6", BREAKS | BLOCK);
723
 
724
    /**
725
     * The &lt;head&gt; tag , breaks flow, block tag.
726
     */
727
    public static final Tag HEAD = new Tag("head", BREAKS | BLOCK);
728
 
729
    /**
730
     * The &lt;hr&gt; tag , breaks flow.
731
     */
732
    public static final Tag HR = new Tag("hr", BREAKS);
733
 
734
    /**
735
     * The &lt;html&gt; tag , breaks flow.
736
     */
737
    public static final Tag HTML = new Tag("html", BREAKS);
738
 
739
    /**
740
     * The &lt;i&gt; tag
741
     */
742
    public static final Tag I = new Tag("i");
743
 
744
    /**
745
     * The &lt;img&gt; tag
746
     */
747
    public static final Tag IMG = new Tag("img");
748
 
749
    /**
750
     * The &lt;input&gt; tag
751
     */
752
    public static final Tag INPUT = new Tag("input");
753
 
754
    /**
755
     * The &lt;isindex&gt; tag , breaks flow.
756
     */
757
    public static final Tag ISINDEX = new Tag("isindex", BREAKS);
758
 
759
    /**
760
     * The &lt;kbd&gt; tag
761
     */
762
    public static final Tag KBD = new Tag("kbd");
763
 
764
    /**
765
     * The &lt;li&gt; tag , breaks flow, block tag.
766
     */
767
    public static final Tag LI = new Tag("li", BREAKS | BLOCK);
768
 
769
    /**
770
     * The &lt;link&gt; tag
771
     */
772
    public static final Tag LINK = new Tag("link");
773
 
774
    /**
775
     * The &lt;map&gt; tag
776
     */
777
    public static final Tag MAP = new Tag("map");
778
 
779
    /**
780
     * The &lt;menu&gt; tag , breaks flow, block tag.
781
     */
782
    public static final Tag MENU = new Tag("menu", BREAKS | BLOCK);
783
 
784
    /**
785
     * The &lt;meta&gt; tag
786
     */
787
    public static final Tag META = new Tag("meta");
788
 
789
    /**
790
     * The &lt;nobr&gt; tag
791
     */
792
    public static final Tag NOBR = new Tag("nobr");
793
 
794
    /**
795
     * The &lt;noframes&gt; tag , breaks flow, block tag.
796
     */
797
    public static final Tag NOFRAMES = new Tag("noframes", BREAKS | BLOCK);
798
 
799
    /**
800
     * The &lt;object&gt; tag
801
     */
802
    public static final Tag OBJECT = new Tag("object");
803
 
804
    /**
805
     * The &lt;ol&gt; tag , breaks flow, block tag.
806
     */
807
    public static final Tag OL = new Tag("ol", BREAKS | BLOCK);
808
 
809
    /**
810
     * The &lt;option&gt; tag
811
     */
812
    public static final Tag OPTION = new Tag("option");
813
 
814
    /**
815
     * The &lt;p&gt; tag , breaks flow, block tag.
816
     */
817
    public static final Tag P = new Tag("p", BREAKS | BLOCK);
818
 
819
    /**
820
     * The &lt;param&gt; tag
821
     */
822
    public static final Tag PARAM = new Tag("param");
823
 
824
    /**
825
     * The &lt;pre&gt; tag , breaks flow, block tag, preformatted.
826
     */
827
    public static final Tag PRE = new Tag("pre", BREAKS | BLOCK | PREFORMATTED);
828
 
829
    /**
830
     * The &lt;s&gt; tag
831
     */
832
    public static final Tag S = new Tag("s");
833
 
834
    /**
835
     * The &lt;samp&gt; tag
836
     */
837
    public static final Tag SAMP = new Tag("samp");
838
 
839
    /**
840
     * The &lt;script&gt; tag
841
     */
842
    public static final Tag SCRIPT = new Tag("script");
843
 
844
    /**
845
     * The &lt;select&gt; tag
846
     */
847
    public static final Tag SELECT = new Tag("select");
848
 
849
    /**
850
     * The &lt;small&gt; tag
851
     */
852
    public static final Tag SMALL = new Tag("small");
853
 
854
    /**
855
     * The &lt;span&gt; tag
856
     */
857
    public static final Tag SPAN = new Tag("span");
858
 
859
    /**
860
     * The &lt;strike&gt; tag
861
     */
862
    public static final Tag STRIKE = new Tag("strike");
863
 
864
    /**
865
     * The &lt;strong&gt; tag
866
     */
867
    public static final Tag STRONG = new Tag("strong");
868
 
869
    /**
870
     * The &lt;style&gt; tag
871
     */
872
    public static final Tag STYLE = new Tag("style");
873
 
874
    /**
875
     * The &lt;sub&gt; tag
876
     */
877
    public static final Tag SUB = new Tag("sub");
878
 
879
    /**
880
     * The &lt;sup&gt; tag
881
     */
882
    public static final Tag SUP = new Tag("sup");
883
 
884
    /**
885
     * The &lt;table&gt; tag , block tag.
886
     */
887
    public static final Tag TABLE = new Tag("table", BLOCK);
888
 
889
    /**
890
     * The &lt;td&gt; tag , breaks flow, block tag.
891
     */
892
    public static final Tag TD = new Tag("td", BREAKS | BLOCK);
893
 
894
    /**
895
     * The &lt;textarea&gt; tag , preformatted.
896
     */
897
    public static final Tag TEXTAREA = new Tag("textarea", PREFORMATTED);
898
 
899
    /**
900
     * The &lt;th&gt; tag , breaks flow, block tag.
901
     */
902
    public static final Tag TH = new Tag("th", BREAKS | BLOCK);
903
 
904
    /**
905
     * The &lt;title&gt; tag , breaks flow, block tag.
906
     */
907
    public static final Tag TITLE = new Tag("title", BREAKS | BLOCK);
908
 
909
    /**
910
     * The &lt;tr&gt; tag , block tag.
911
     */
912
    public static final Tag TR = new Tag("tr", BLOCK);
913
 
914
    /**
915
     * The &lt;tt&gt; tag
916
     */
917
    public static final Tag TT = new Tag("tt");
918
 
919
    /**
920
     * The &lt;u&gt; tag
921
     */
922
    public static final Tag U = new Tag("u");
923
 
924
    /**
925
     * The &lt;ul&gt; tag , breaks flow, block tag.
926
     */
927
    public static final Tag UL = new Tag("ul", BREAKS | BLOCK);
928
 
929
    /**
930
     * The &lt;var&gt; 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", SYNTHETIC);
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", SYNTHETIC);
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 'p-implied'. HTML reader synthesizes this tag.
962
     */
963
    public static final Tag IMPLIED = new Tag("p-implied", SYNTHETIC);
964
    final String name;
965
    final int flags;
966
 
967
    /**
968
     * Create the unitialised instance of HTML.Tag.
969
     *
970
     * The {@link #breaksFlow()}, {@link #isBlock()}
971
     * and {@link #isPreformatted()} will always return false.
972
     * The {@link #toString()} will return <code>null</code>.
973
     *
974
     * @since 1.3
975
     */
976
    public Tag()
977
    {
978
      name = null;
979
      flags = 0;
980
    }
981
 
982
    /**
983
     * Creates a new Tag with the specified id, and with causesBreak
984
     * and isBlock set to false.
985
     */
986
    protected Tag(String id)
987
    {
988
      name = id;
989
      flags = 0;
990
    }
991
 
992
    /**
993
     * Creates a new Tag with the specified tag name and
994
     * causesBreak and isBlock properties.
995
     */
996
    protected Tag(String id, boolean causesBreak, boolean isBlock)
997
    {
998
      int f = 0;
999
 
1000
      if (causesBreak)
1001
        {
1002
          f |= BREAKS;
1003
        }
1004
 
1005
      if (isBlock)
1006
        {
1007
          f |= BLOCK;
1008
        }
1009
 
1010
      flags = f;
1011
      name = id;
1012
    }
1013
 
1014
    /**
1015
     * Create a tag taking flags.
1016
     */
1017
    Tag(String id, int a_flags)
1018
    {
1019
      name = id;
1020
      flags = a_flags;
1021
    }
1022
 
1023
    /**
1024
     * Returns true if this tag is a block tag, which is a tag used to
1025
     * add structure to a document.
1026
     */
1027
    public boolean isBlock()
1028
    {
1029
      return (flags & BLOCK) != 0;
1030
    }
1031
 
1032
    /**
1033
     * Returns true if this tag is pre-formatted, which is true if
1034
     * the tag is either PRE or TEXTAREA
1035
     */
1036
    public boolean isPreformatted()
1037
    {
1038
      return (flags & PREFORMATTED) != 0;
1039
    }
1040
 
1041
    /**
1042
     * Returns true if this tag causes a line break to the flow of text
1043
     */
1044
    public boolean breaksFlow()
1045
    {
1046
      return (flags & BREAKS) != 0;
1047
    }
1048
 
1049
    /**
1050
     * Calls compareTo on the tag names (Strings)
1051
     */
1052
    public int compareTo(Object other)
1053
    {
1054
      return name.compareTo(((Tag) other).name);
1055
    }
1056
 
1057
    /**
1058
     * The tags are equal if the names are equal (ignoring case).
1059
     */
1060
    public boolean equals(Object other)
1061
    {
1062
      if (other == this)
1063
        {
1064
          return true;
1065
        }
1066
 
1067
      if (!(other instanceof Tag))
1068
        {
1069
          return false;
1070
        }
1071
 
1072
      Tag that = (Tag) other;
1073
 
1074
      return that.name.equalsIgnoreCase(name);
1075
    }
1076
 
1077
    /**
1078
     * Returns the hash code which corresponds to the string for this tag.
1079
     */
1080
    public int hashCode()
1081
    {
1082
      return name == null ? 0 : name.hashCode();
1083
    }
1084
 
1085
    /**
1086
     * Returns the tag name. The names of the built-in tags are always
1087
     * returned in lowercase.
1088
     */
1089
    public String toString()
1090
    {
1091
      return name;
1092
    }
1093
 
1094
    /**
1095
     * Return an array of HTML tags, declared in HTML.Tag class.
1096
     * WARNING: This method expects that the Tags are the only
1097
     * public fields declared in the Tag class.
1098
     */
1099
    static Tag[] getAllTags()
1100
    {
1101
      Field[] f = Tag.class.getFields();
1102
      Field x;
1103
 
1104
      // The syntetic tags are not included.
1105
      Tag[] tags = new Tag[ f.length - TOTAL_SYNTHETIC_TAGS ];
1106
      int p = 0;
1107
      Tag t;
1108
 
1109
      for (int i = 0; i < f.length; i++)
1110
        {
1111
          x = f [ i ];
1112
 
1113
          if ((x.getModifiers() & Modifier.STATIC) != 0)
1114
            {
1115
              if (x.getType().equals(Tag.class))
1116
                {
1117
                  try
1118
                    {
1119
                      t = (Tag) x.get(null);
1120
 
1121
                      if (!t.isSyntetic())
1122
                        {
1123
                          tags [ p++ ] = t;
1124
                        }
1125
                    }
1126
                  catch (IllegalAccessException ex)
1127
                    {
1128
                      unexpected(ex);
1129
                    }
1130
                  catch (IllegalArgumentException ex)
1131
                    {
1132
                      unexpected(ex);
1133
                    }
1134
                }
1135
            }
1136
        }
1137
 
1138
      return tags;
1139
    }
1140
 
1141
    /**
1142
     * Returns true for tags, generated by the html reader
1143
     * (COMMENT, CONTENT and IMPLIED).
1144
     */
1145
    boolean isSyntetic()
1146
    {
1147
      return (flags & SYNTHETIC) != 0;
1148
    }
1149
 
1150
    private static void unexpected(Exception ex)
1151
                            throws Error
1152
    {
1153
      throw new Error("This should never happen, report a bug", ex);
1154
    }
1155
  }
1156
 
1157
  /**
1158
   * Represents an unknown HTML tag.
1159
   * @author Mark Wielaard (mark@klomp.org)
1160
   */
1161
  public static class UnknownTag
1162
    extends Tag
1163
    implements Serializable
1164
  {
1165
    private static final long serialVersionUID = -1534369342247250625L;
1166
 
1167
    /**
1168
     * Creates a new UnknownTag with the specified name
1169
     * @param name The tag name.
1170
     *
1171
     */
1172
    public UnknownTag(String name)
1173
    {
1174
      super(name);
1175
    }
1176
  }
1177
 
1178
  /**
1179
   * This value is returned for attributes without value that have no
1180
   * default value defined in the DTD.
1181
   */
1182
  public static final String NULL_ATTRIBUTE_VALUE = "#DEFAULT";
1183
 
1184
  /* Package level html tag flags */
1185
  static final int BREAKS = 1;
1186
  static final int BLOCK = 2;
1187
  static final int PREFORMATTED = 4;
1188
  static final int SYNTHETIC = 8;
1189
  private static Map tagMap;
1190
  private static Map attrMap;
1191
 
1192
  /**
1193
   * The public constructor (does nothing). It it seldom required to have
1194
   * an instance of this class, because all public fields and methods
1195
   * are static.
1196
   */
1197
  public HTML()
1198
  {
1199
    // Nothing to do here.
1200
  }
1201
 
1202
  /**
1203
   * Returns the set of the recognized HTML attributes.
1204
   */
1205
  public static HTML.Attribute[] getAllAttributeKeys()
1206
  {
1207
    return Attribute.getAllAttributes();
1208
  }
1209
 
1210
  /**
1211
   * Returns the set of actual HTML tags that are recognized by
1212
   * the default HTML reader. The returned array does not include the
1213
   * COMMENT, CONTENT and IMPLIED tags.
1214
   */
1215
  public static HTML.Tag[] getAllTags()
1216
  {
1217
    return Tag.getAllTags();
1218
  }
1219
 
1220
  /**
1221
   * Returns an htl attribute constant for the given attribute name.
1222
   * @param attName the attribute name, case insensitive
1223
   */
1224
  public static Attribute getAttributeKey(String attName)
1225
  {
1226
    if (attrMap == null)
1227
      {
1228
        // Create the map on demand.
1229
        attrMap = new TreeMap();
1230
 
1231
        Attribute[] attrs = getAllAttributeKeys();
1232
 
1233
        for (int i = 0; i < attrs.length; i++)
1234
          {
1235
            attrMap.put(attrs [ i ].toString(), attrs [ i ]);
1236
          }
1237
      }
1238
 
1239
    return (Attribute) attrMap.get(attName.toLowerCase());
1240
  }
1241
 
1242
  /**
1243
   * Searches the value of given attribute in the provided set.
1244
   * If the value is found (String type expected), tries to parse it as
1245
   * an integer value. If succeded, returns the obtained integer value.
1246
   *
1247
   * For example:<p><code>
1248
   * SimpleAttributeSet ase = new SimpleAttributeSet();
1249
   * ase.addAttribute(HTML.getAttributeKey("size"),"222");
1250
   * System.out.println(
1251
   *  HTML.getIntegerAttributeValue
1252
   *     (ase, HTML.getAttributeKey("size"), 333)); // prints "222"
1253
   * System.out.println(
1254
   *  HTML.getIntegerAttributeValue
1255
   *     (ase, HTML.getAttributeKey("width"), 333)); // prints "333".
1256
   * </code></p>
1257
   *
1258
   *
1259
   * @param set The attribute set to search in. If the set contains the
1260
   * given attribute, it must by a type of String.
1261
   * @param attribute The html attribute to search in
1262
   * @param defaultValue The value that is returned if the attribute is not
1263
   * found in the given set or if the NumberFormatException was thrown
1264
   * during the parsing.
1265
   */
1266
  public static int getIntegerAttributeValue(AttributeSet set,
1267
                                             HTML.Attribute attribute,
1268
                                             int defaultValue
1269
                                            )
1270
  {
1271
    Object v = set.getAttribute(attribute);
1272
 
1273
    if (v == null)
1274
      {
1275
        return defaultValue;
1276
      }
1277
 
1278
    try
1279
      {
1280
        return Integer.parseInt(v.toString().trim());
1281
      }
1282
    catch (Exception ex)
1283
      {
1284
        return defaultValue;
1285
      }
1286
  }
1287
 
1288
  /**
1289
   * Returns a HTML tag constant for the given HTML attribute name.
1290
   * If the tag is unknown, the null is returned.
1291
   * @param tagName the tag name, case insensitive
1292
   */
1293
  public static Tag getTag(String tagName)
1294
  {
1295
    if (tagMap == null)
1296
      {
1297
        // Create the mao on demand.
1298
        tagMap = new TreeMap();
1299
 
1300
        Tag[] tags = getAllTags();
1301
 
1302
        for (int i = 0; i < tags.length; i++)
1303
          {
1304
            tagMap.put(tags [ i ].toString(), tags [ i ]);
1305
          }
1306
      }
1307
 
1308
    return (Tag) tagMap.get(tagName.toLowerCase());
1309
  }
1310
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.