KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > engine > value > css2 > TextDecorationManager


1 /*
2
3    Copyright 2002-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.css.engine.value.css2;
19
20 import org.apache.batik.css.engine.CSSEngine;
21 import org.apache.batik.css.engine.value.AbstractValueManager;
22 import org.apache.batik.css.engine.value.ListValue;
23 import org.apache.batik.css.engine.value.StringMap;
24 import org.apache.batik.css.engine.value.Value;
25 import org.apache.batik.css.engine.value.ValueConstants;
26 import org.apache.batik.css.engine.value.ValueManager;
27 import org.apache.batik.util.CSSConstants;
28 import org.w3c.css.sac.LexicalUnit;
29 import org.w3c.dom.DOMException JavaDoc;
30 import org.w3c.dom.css.CSSPrimitiveValue;
31
32 /**
33  * This class provides a manager for the 'text-decoration' property values.
34  *
35  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
36  * @version $Id: TextDecorationManager.java,v 1.5 2005/03/27 08:58:31 cam Exp $
37  */

38 public class TextDecorationManager extends AbstractValueManager {
39     
40     /**
41      * The identifier values.
42      */

43     protected final static StringMap values = new StringMap();
44     static {
45     values.put(CSSConstants.CSS_BLINK_VALUE,
46                    ValueConstants.BLINK_VALUE);
47     values.put(CSSConstants.CSS_LINE_THROUGH_VALUE,
48                    ValueConstants.LINE_THROUGH_VALUE);
49     values.put(CSSConstants.CSS_OVERLINE_VALUE,
50                    ValueConstants.OVERLINE_VALUE);
51     values.put(CSSConstants.CSS_UNDERLINE_VALUE,
52                    ValueConstants.UNDERLINE_VALUE);
53     }
54
55     /**
56      * Implements {@link ValueManager#isInheritedProperty()}.
57      */

58     public boolean isInheritedProperty() {
59     return false;
60     }
61
62     /**
63      * Implements {@link ValueManager#getPropertyName()}.
64      */

65     public String JavaDoc getPropertyName() {
66     return CSSConstants.CSS_TEXT_DECORATION_PROPERTY;
67     }
68     
69     /**
70      * Implements {@link ValueManager#getDefaultValue()}.
71      */

72     public Value getDefaultValue() {
73         return ValueConstants.NONE_VALUE;
74     }
75
76     /**
77      * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
78      */

79     public Value createValue(LexicalUnit lu, CSSEngine engine)
80         throws DOMException JavaDoc {
81     switch (lu.getLexicalUnitType()) {
82     case LexicalUnit.SAC_INHERIT:
83         return ValueConstants.INHERIT_VALUE;
84
85     case LexicalUnit.SAC_IDENT:
86             if (lu.getStringValue().equalsIgnoreCase
87                 (CSSConstants.CSS_NONE_VALUE)) {
88                 return ValueConstants.NONE_VALUE;
89         }
90             ListValue lv = new ListValue(' ');
91             do {
92                 if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
93                     String JavaDoc s = lu.getStringValue().toLowerCase().intern();
94                     Object JavaDoc obj = values.get(s);
95                     if (obj == null) {
96                         throw createInvalidIdentifierDOMException
97                             (lu.getStringValue());
98                     }
99                     lv.append((Value)obj);
100                     lu = lu.getNextLexicalUnit();
101                 } else {
102                     throw createInvalidLexicalUnitDOMException
103                         (lu.getLexicalUnitType());
104                 }
105                 
106             } while (lu != null);
107             return lv;
108         }
109         throw createInvalidLexicalUnitDOMException
110             (lu.getLexicalUnitType());
111     }
112
113     /**
114      * Implements {@link
115      * ValueManager#createStringValue(short,String,CSSEngine)}.
116      */

117     public Value createStringValue(short type, String JavaDoc value, CSSEngine engine)
118     throws DOMException JavaDoc {
119     if (type != CSSPrimitiveValue.CSS_IDENT) {
120             throw createInvalidStringTypeDOMException(type);
121     }
122         if (!value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) {
123             throw createInvalidIdentifierDOMException(value);
124         }
125     return ValueConstants.NONE_VALUE;
126     }
127
128 }
129
Popular Tags