summaryrefslogtreecommitdiff
path: root/javax/swing/text/html/CSS.java
blob: 77f94a608784ead1a2c834c79d566a5648f340bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
/* CSS.java -- Provides CSS attributes
   Copyright (C) 2005 Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath 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, or (at your option)
any later version.

GNU Classpath 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 GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

package javax.swing.text.html;

import gnu.javax.swing.text.html.css.BorderStyle;
import gnu.javax.swing.text.html.css.BorderWidth;
import gnu.javax.swing.text.html.css.CSSColor;
import gnu.javax.swing.text.html.css.FontSize;
import gnu.javax.swing.text.html.css.FontStyle;
import gnu.javax.swing.text.html.css.FontWeight;
import gnu.javax.swing.text.html.css.Length;

import java.io.Serializable;
import java.util.HashMap;
import java.util.StringTokenizer;

import javax.swing.text.MutableAttributeSet;

/**
 * Provides CSS attributes to be used by the HTML view classes. The constants
 * defined here are used as keys for text attributes for use in
 * {@link javax.swing.text.AttributeSet}s of {@link javax.swing.text.Element}s.
 *
 * @author Roman Kennke (kennke@aicas.com)
 */
public class CSS implements Serializable
{
  /**
   * Returns an array of all CSS attributes.
   *
   * @return All available CSS.Attribute objects.
   */
  public static CSS.Attribute[] getAllAttributeKeys()
  {
    Object[] src = Attribute.attributeMap.values().toArray();
    CSS.Attribute[] dst = new CSS.Attribute[ src.length ];
    System.arraycopy(src, 0, dst, 0, src.length);
    return dst;
  }

  /**
   * Returns an a given CSS attribute.
   *
   * @param name - The name of the attribute.
   * @return The CSS attribute with the given name, or <code>null</code> if
   * no attribute with that name exists.
   */
  public static CSS.Attribute getAttribute(String name)
  {
    return (CSS.Attribute)Attribute.attributeMap.get( name );
  }

  public static final class Attribute
  {
    /**
     * The CSS attribute 'background'.
     */
    public static final Attribute BACKGROUND =
      new Attribute("background", false, null);

    /**
     * The CSS attribute 'background-attachment'.
     */
    public static final Attribute BACKGROUND_ATTACHMENT =
      new Attribute("background-attachment", false, "scroll");

    /**
     * The CSS attribute 'background-color'.
     */
    public static final Attribute BACKGROUND_COLOR =
      new Attribute("background-color", false, "transparent");

    /**
     * The CSS attribute 'background-image'.
     */
    public static final Attribute BACKGROUND_IMAGE =
      new Attribute("background-image", false, "none");

    /**
     * The CSS attribute 'background-position'.
     */
    public static final Attribute BACKGROUND_POSITION =
      new Attribute("background-position", false, null);

    /**
     * The CSS attribute 'background-repeat'.
     */
    public static final Attribute BACKGROUND_REPEAT =
      new Attribute("background-repeat", false, "repeat");

    /**
     * The CSS attribute 'border'.
     */
    public static final Attribute BORDER = new Attribute("border", false, null);

    /**
     * The CSS attribute 'border-bottom'.
     */
    public static final Attribute BORDER_BOTTOM =
      new Attribute("border-bottom", false, null);

    /**
     * The CSS attribute 'border-bottom-width'.
     */
    public static final Attribute BORDER_BOTTOM_WIDTH =
      new Attribute("border-bottom-width", false, "medium");

    /**
     * The CSS attribute 'border-color'.
     */
    public static final Attribute BORDER_COLOR =
      new Attribute("border-color", false, "black");

    /**
     * The CSS attribute 'border-left'.
     */
    public static final Attribute BORDER_LEFT =
      new Attribute("border-left", false, null);

    /**
     * The CSS attribute 'border-left-width'.
     */
    public static final Attribute BORDER_LEFT_WIDTH =
      new Attribute("border-left-width", false, "medium");

    /**
     * The CSS attribute 'border-right'.
     */
    public static final Attribute BORDER_RIGHT =
      new Attribute("border-right", false, null);

    /**
     * The CSS attribute 'border-right-width'.
     */
    public static final Attribute BORDER_RIGHT_WIDTH =
      new Attribute("border-right-width", false, "medium");

    /**
     * The CSS attribute 'border-style'.
     */
    public static final Attribute BORDER_STYLE =
      new Attribute("border-style", false, "none");

    /**
     * The CSS attribute 'border-top'.
     */
    public static final Attribute BORDER_TOP =
      new Attribute("border-top", false, null);

    /**
     * The CSS attribute 'border-top-width'.
     */
    public static final Attribute BORDER_TOP_WIDTH =
      new Attribute("border-top-width", false, "medium");

    /**
     * The CSS attribute 'border-width'.
     */
    public static final Attribute BORDER_WIDTH =
      new Attribute("border-width", false, "medium");

    /**
     * The CSS attribute 'clear'.
     */
    public static final Attribute CLEAR = new Attribute("clear", false, "none");

    /**
     * The CSS attribute 'color'.
     */
    public static final Attribute COLOR = new Attribute("color", true, "black");

    /**
     * The CSS attribute 'display'.
     */
    public static final Attribute DISPLAY =
      new Attribute("display", false, "block");

    /**
     * The CSS attribute 'float'.
     */
    public static final Attribute FLOAT = new Attribute("float", false, "none");

    /**
     * The CSS attribute 'font'.
     */
    public static final Attribute FONT = new Attribute("font", true, null);

    /**
     * The CSS attribute 'font-family'.
     */
    public static final Attribute FONT_FAMILY =
      new Attribute("font-family", true, null);

    /**
     * The CSS attribute 'font-size'.
     */
    public static final Attribute FONT_SIZE =
      new Attribute("font-size", true, "medium");

    /**
     * The CSS attribute 'font-style'.
     */
    public static final Attribute FONT_STYLE =
      new Attribute("font-style", true, "normal");

    /**
     * The CSS attribute 'font-variant'.
     */
    public static final Attribute FONT_VARIANT =
      new Attribute("font-variant", true, "normal");

    /**
     * The CSS attribute 'font-weight'.
     */
    public static final Attribute FONT_WEIGHT =
      new Attribute("font-weight", true, "normal");

    /**
     * The CSS attribute 'height'.
     */
    public static final Attribute HEIGHT =
      new Attribute("height", false, "auto");

    /**
     * The CSS attribute 'letter-spacing'.
     */
    public static final Attribute LETTER_SPACING =
      new Attribute("letter-spacing", true, "normal");

    /**
     * The CSS attribute 'line-height'.
     */
    public static final Attribute LINE_HEIGHT =
      new Attribute("line-height", true, "normal");

    /**
     * The CSS attribute 'list-style'.
     */
    public static final Attribute LIST_STYLE =
      new Attribute("list-style", true, null);

    /**
     * The CSS attribute 'list-style-image'.
     */
    public static final Attribute LIST_STYLE_IMAGE =
      new Attribute("list-style-image", true, "none");

    /**
     * The CSS attribute 'list-style-position'.
     */
    public static final Attribute LIST_STYLE_POSITION =
      new Attribute("list-style-position", true, "outside");

    /**
     * The CSS attribute 'list-style-type'.
     */
    public static final Attribute LIST_STYLE_TYPE =
      new Attribute("list-style-type", true, "disc");

    /**
     * The CSS attribute 'margin'.
     */
    public static final Attribute MARGIN = new Attribute("margin", false, null);

    /**
     * The CSS attribute 'margin-bottom'.
     */
    public static final Attribute MARGIN_BOTTOM =
      new Attribute("margin-bottom", false, "0");

    /**
     * The CSS attribute 'margin-left'.
     */
    public static final Attribute MARGIN_LEFT =
      new Attribute("margin-left", false, "0");

    /**
     * The CSS attribute 'margin-right'.
     */
    public static final Attribute MARGIN_RIGHT =
      new Attribute("margin-right", false, "0");

    /**
     * The CSS attribute 'margin-top'.
     */
    public static final Attribute MARGIN_TOP =
      new Attribute("margin-top", false, "0");

    /**
     * The CSS attribute 'padding'.
     */
    public static final Attribute PADDING =
      new Attribute("padding", false, null);

    /**
     * The CSS attribute 'padding-bottom'.
     */
    public static final Attribute PADDING_BOTTOM =
      new Attribute("padding-bottom", false, "0");

    /**
     * The CSS attribute 'padding-left'.
     */
    public static final Attribute PADDING_LEFT =
      new Attribute("padding-left", false, "0");

    /**
     * The CSS attribute 'padding-right'.
     */
    public static final Attribute PADDING_RIGHT =
      new Attribute("padding-right", false, "0");

    /**
     * The CSS attribute 'padding-top'.
     */
    public static final Attribute PADDING_TOP =
      new Attribute("padding-top", false, "0");

    /**
     * The CSS attribute 'text-align'.
     */
    public static final Attribute TEXT_ALIGN =
      new Attribute("text-align", true, null);

    /**
     * The CSS attribute 'text-decoration'.
     */
    public static final Attribute TEXT_DECORATION =
      new Attribute("text-decoration", true, "none");

    /**
     * The CSS attribute 'text-indent'.
     */
    public static final Attribute TEXT_INDENT =
      new Attribute("text-indent", true, "0");

    /**
     * The CSS attribute 'text-transform'.
     */
    public static final Attribute TEXT_TRANSFORM =
      new Attribute("text-transform", true, "none");

    /**
     * The CSS attribute 'vertical-align'.
     */
    public static final Attribute VERTICAL_ALIGN =
      new Attribute("vertical-align", false, "baseline");

    /**
     * The CSS attribute 'white-space'.
     */
    public static final Attribute WHITE_SPACE =
      new Attribute("white-space", true, "normal");

    /**
     * The CSS attribute 'width'.
     */
    public static final Attribute WIDTH =
      new Attribute("width", false, "auto");

    /**
     * The CSS attribute 'word-spacing'.
     */
    public static final Attribute WORD_SPACING =
      new Attribute("word-spacing", true, "normal");

    // Some GNU Classpath specific extensions.
    static final Attribute BORDER_TOP_STYLE =
      new Attribute("border-top-style", false, null);
    static final Attribute BORDER_BOTTOM_STYLE =
      new Attribute("border-bottom-style", false, null);
    static final Attribute BORDER_LEFT_STYLE =
      new Attribute("border-left-style", false, null);
    static final Attribute BORDER_RIGHT_STYLE =
      new Attribute("border-right-style", false, null);
    static final Attribute BORDER_TOP_COLOR =
      new Attribute("border-top-color", false, null);
    static final Attribute BORDER_BOTTOM_COLOR =
      new Attribute("border-bottom-color", false, null);
    static final Attribute BORDER_LEFT_COLOR =
      new Attribute("border-left-color", false, null);
    static final Attribute BORDER_RIGHT_COLOR =
      new Attribute("border-right-color", false, null);
    static final Attribute BORDER_SPACING =
      new Attribute("border-spacing", false, null);
    static final Attribute POSITION =
      new Attribute("position", false, null);
    static final Attribute LEFT =
      new Attribute("left", false, null);
    static final Attribute RIGHT =
      new Attribute("right", false, null);
    static final Attribute TOP =
      new Attribute("top", false, null);
    static final Attribute BOTTOM =
      new Attribute("bottom", false, null);

    /**
     * The attribute string.
     */
    String attStr;

    /**
     * Indicates if this attribute should be inherited from it's parent or
     * not.
     */
    boolean isInherited;

    /**
     * A default value for this attribute if one exists, otherwise null.
     */
    String defaultValue;

    /**
     * A HashMap of all attributes.
     */
    static HashMap attributeMap;

    /**
     * Creates a new Attribute instance with the specified values.
     *
     * @param attr the attribute string
     * @param inherited if the attribute should be inherited or not
     * @param def a default value; may be <code>null</code> 
     */
    Attribute(String attr, boolean inherited, String def)
    {
      attStr = attr;
      isInherited = inherited;
      defaultValue = def;
      if( attributeMap == null)
	attributeMap = new HashMap();
      attributeMap.put( attr, this );
    }

    /**
     * Returns the string representation of this attribute as specified
     * in the CSS specification.
     */
    public String toString()
    {
      return attStr;
    }

    /**
     * Returns <code>true</code> if the attribute should be inherited from
     * the parent, <code>false</code> otherwise.
     *
     * @return <code>true</code> if the attribute should be inherited from
     *         the parent, <code>false</code> otherwise
     */
    public boolean isInherited()
    {
      return isInherited;
    }

    /**
     * Returns the default value of this attribute if one exists,
     * <code>null</code> otherwise.
     *
     * @return the default value of this attribute if one exists,
     *         <code>null</code> otherwise
     */
    public String getDefaultValue()
    {
      return defaultValue;
    }
  }

  /**
   * Maps attribute values (String) to some converter class, based on the
   * key.
   *
   * @param att the key
   * @param v the value
   *
   * @return the wrapped value
   */
  static Object getValue(Attribute att, String v)
  {
    Object o;
    if (att == Attribute.FONT_SIZE)
      o = new FontSize(v);
    else if (att == Attribute.FONT_WEIGHT)
      o = new FontWeight(v);
    else if (att == Attribute.FONT_STYLE)
      o = new FontStyle(v);
    else if (att == Attribute.COLOR || att == Attribute.BACKGROUND_COLOR
             || att == Attribute.BORDER_COLOR
             || att == Attribute.BORDER_TOP_COLOR
             || att == Attribute.BORDER_BOTTOM_COLOR
             || att == Attribute.BORDER_LEFT_COLOR
             || att == Attribute.BORDER_RIGHT_COLOR)
      o = new CSSColor(v);
    else if (att == Attribute.MARGIN || att == Attribute.MARGIN_BOTTOM
             || att == Attribute.MARGIN_LEFT || att == Attribute.MARGIN_RIGHT
             || att == Attribute.MARGIN_TOP || att == Attribute.WIDTH
             || att == Attribute.HEIGHT
             || att == Attribute.PADDING || att == Attribute.PADDING_BOTTOM
             || att == Attribute.PADDING_LEFT || att == Attribute.PADDING_RIGHT
             || att == Attribute.PADDING_TOP
             || att == Attribute.LEFT || att == Attribute.RIGHT
             || att == Attribute.TOP || att == Attribute.BOTTOM)
      o = new Length(v);
    else if (att == Attribute.BORDER_WIDTH || att == Attribute.BORDER_TOP_WIDTH
             || att == Attribute.BORDER_LEFT_WIDTH
             || att == Attribute.BORDER_RIGHT_WIDTH
             || att == Attribute.BORDER_BOTTOM_WIDTH)
      o = new BorderWidth(v);
    else
      o = v;
    return o;
  }

  static void addInternal(MutableAttributeSet atts, Attribute a, String v)
  {
    if (a == Attribute.BACKGROUND)
      parseBackgroundShorthand(atts, v);
    else if (a == Attribute.PADDING)
      parsePaddingShorthand(atts, v);
    else if (a == Attribute.MARGIN)
      parseMarginShorthand(atts, v);
    else if (a == Attribute.BORDER || a == Attribute.BORDER_LEFT
             || a == Attribute.BORDER_RIGHT || a == Attribute.BORDER_TOP
             || a == Attribute.BORDER_BOTTOM)
      parseBorderShorthand(atts, v, a);
  }

  /**
   * Parses the background shorthand and translates it to more specific
   * background attributes.
   *
   * @param atts the attributes
   * @param v the value
   */
  private static void parseBackgroundShorthand(MutableAttributeSet atts,
                                               String v)
  {
    StringTokenizer tokens = new StringTokenizer(v, " ");
    while (tokens.hasMoreElements())
      {
        String token = tokens.nextToken();
        if (CSSColor.isValidColor(token))
          atts.addAttribute(Attribute.BACKGROUND_COLOR,
                            new CSSColor(token));
      }
  }

  /**
   * Parses the padding shorthand and translates to the specific padding
   * values.
   *
   * @param atts the attributes
   * @param v the actual value
   */
  private static void parsePaddingShorthand(MutableAttributeSet atts, String v)
  {
    StringTokenizer tokens = new StringTokenizer(v, " ");
    int numTokens = tokens.countTokens();
    if (numTokens == 1)
      {
        Length l = new Length(tokens.nextToken());
        atts.addAttribute(Attribute.PADDING_BOTTOM, l);
        atts.addAttribute(Attribute.PADDING_LEFT, l);
        atts.addAttribute(Attribute.PADDING_RIGHT, l);
        atts.addAttribute(Attribute.PADDING_TOP, l);
      }
    else if (numTokens == 2)
      {
        Length l1 = new Length(tokens.nextToken());
        Length l2 = new Length(tokens.nextToken());
        atts.addAttribute(Attribute.PADDING_BOTTOM, l1);
        atts.addAttribute(Attribute.PADDING_TOP, l1);
        atts.addAttribute(Attribute.PADDING_LEFT, l2);
        atts.addAttribute(Attribute.PADDING_RIGHT, l2);
      }
    else if (numTokens == 3)
      {
        Length l1 = new Length(tokens.nextToken());
        Length l2 = new Length(tokens.nextToken());
        Length l3 = new Length(tokens.nextToken());
        atts.addAttribute(Attribute.PADDING_TOP, l1);
        atts.addAttribute(Attribute.PADDING_LEFT, l2);
        atts.addAttribute(Attribute.PADDING_RIGHT, l2);
        atts.addAttribute(Attribute.PADDING_BOTTOM, l3);
      }
    else
      {
        Length l1 = new Length(tokens.nextToken());
        Length l2 = new Length(tokens.nextToken());
        Length l3 = new Length(tokens.nextToken());
        Length l4 = new Length(tokens.nextToken());
        atts.addAttribute(Attribute.PADDING_TOP, l1);
        atts.addAttribute(Attribute.PADDING_RIGHT, l2);
        atts.addAttribute(Attribute.PADDING_BOTTOM, l3);
        atts.addAttribute(Attribute.PADDING_LEFT, l4);
      }
  }

  /**
   * Parses the margin shorthand and translates to the specific margin
   * values.
   *
   * @param atts the attributes
   * @param v the actual value
   */
  private static void parseMarginShorthand(MutableAttributeSet atts, String v)
  {
    StringTokenizer tokens = new StringTokenizer(v, " ");
    int numTokens = tokens.countTokens();
    if (numTokens == 1)
      {
        Length l = new Length(tokens.nextToken());
        atts.addAttribute(Attribute.MARGIN_BOTTOM, l);
        atts.addAttribute(Attribute.MARGIN_LEFT, l);
        atts.addAttribute(Attribute.MARGIN_RIGHT, l);
        atts.addAttribute(Attribute.MARGIN_TOP, l);
      }
    else if (numTokens == 2)
      {
        Length l1 = new Length(tokens.nextToken());
        Length l2 = new Length(tokens.nextToken());
        atts.addAttribute(Attribute.MARGIN_BOTTOM, l1);
        atts.addAttribute(Attribute.MARGIN_TOP, l1);
        atts.addAttribute(Attribute.MARGIN_LEFT, l2);
        atts.addAttribute(Attribute.MARGIN_RIGHT, l2);
      }
    else if (numTokens == 3)
      {
        Length l1 = new Length(tokens.nextToken());
        Length l2 = new Length(tokens.nextToken());
        Length l3 = new Length(tokens.nextToken());
        atts.addAttribute(Attribute.MARGIN_TOP, l1);
        atts.addAttribute(Attribute.MARGIN_LEFT, l2);
        atts.addAttribute(Attribute.MARGIN_RIGHT, l2);
        atts.addAttribute(Attribute.MARGIN_BOTTOM, l3);
      }
    else
      {
        Length l1 = new Length(tokens.nextToken());
        Length l2 = new Length(tokens.nextToken());
        Length l3 = new Length(tokens.nextToken());
        Length l4 = new Length(tokens.nextToken());
        atts.addAttribute(Attribute.MARGIN_TOP, l1);
        atts.addAttribute(Attribute.MARGIN_RIGHT, l2);
        atts.addAttribute(Attribute.MARGIN_BOTTOM, l3);
        atts.addAttribute(Attribute.MARGIN_LEFT, l4);
      }
  }

  /**
   * Parses the CSS border shorthand attribute and translates it to the
   * more specific border attributes.
   *
   * @param atts the attribute
   * @param value the value
   */
  private static void parseBorderShorthand(MutableAttributeSet atts,
                                           String value, Attribute cssAtt)
  {
    StringTokenizer tokens = new StringTokenizer(value, " ");
    while (tokens.hasMoreTokens())
      {
        String token = tokens.nextToken();
        if (BorderStyle.isValidStyle(token))
          {
            if (cssAtt == Attribute.BORDER_LEFT || cssAtt == Attribute.BORDER)
              atts.addAttribute(Attribute.BORDER_LEFT_STYLE, token);
            if (cssAtt == Attribute.BORDER_RIGHT || cssAtt == Attribute.BORDER)
              atts.addAttribute(Attribute.BORDER_RIGHT_STYLE, token);
            if (cssAtt == Attribute.BORDER_BOTTOM || cssAtt == Attribute.BORDER)
              atts.addAttribute(Attribute.BORDER_BOTTOM_STYLE, token);
            if (cssAtt == Attribute.BORDER_TOP || cssAtt == Attribute.BORDER)
              atts.addAttribute(Attribute.BORDER_TOP_STYLE, token);
          }
        else if (BorderWidth.isValid(token))
          {
            BorderWidth w = new BorderWidth(token);
            if (cssAtt == Attribute.BORDER_LEFT || cssAtt == Attribute.BORDER)
              atts.addAttribute(Attribute.BORDER_LEFT_WIDTH, w);
            if (cssAtt == Attribute.BORDER_RIGHT || cssAtt == Attribute.BORDER)
              atts.addAttribute(Attribute.BORDER_RIGHT_WIDTH, w);
            if (cssAtt == Attribute.BORDER_BOTTOM || cssAtt == Attribute.BORDER)
              atts.addAttribute(Attribute.BORDER_BOTTOM_WIDTH, w);
            if (cssAtt == Attribute.BORDER_TOP || cssAtt == Attribute.BORDER)
              atts.addAttribute(Attribute.BORDER_TOP_WIDTH, w);
          }
        else if (CSSColor.isValidColor(token))
          {
            CSSColor c = new CSSColor(token);
            if (cssAtt == Attribute.BORDER_LEFT || cssAtt == Attribute.BORDER)
              atts.addAttribute(Attribute.BORDER_LEFT_COLOR, c);
            if (cssAtt == Attribute.BORDER_RIGHT || cssAtt == Attribute.BORDER)
              atts.addAttribute(Attribute.BORDER_RIGHT_COLOR, c);
            if (cssAtt == Attribute.BORDER_BOTTOM || cssAtt == Attribute.BORDER)
              atts.addAttribute(Attribute.BORDER_BOTTOM_COLOR, c);
            if (cssAtt == Attribute.BORDER_TOP || cssAtt == Attribute.BORDER)
              atts.addAttribute(Attribute.BORDER_TOP_COLOR, c);
          }
      }
  }
}