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

19 package org.apache.batik.css.engine.value.css2;
20
21 import org.apache.batik.css.engine.CSSEngine;
22 import org.apache.batik.css.engine.value.AbstractValueManager;
23 import org.apache.batik.css.engine.value.ListValue;
24 import org.apache.batik.css.engine.value.StringMap;
25 import org.apache.batik.css.engine.value.Value;
26 import org.apache.batik.css.engine.value.ValueConstants;
27 import org.apache.batik.css.engine.value.ValueManager;
28 import org.apache.batik.util.CSSConstants;
29 import org.apache.batik.util.SVGTypes;
30 import org.w3c.css.sac.LexicalUnit;
31 import org.w3c.dom.DOMException;
32 import org.w3c.dom.css.CSSPrimitiveValue;
33
34 /**
35  * This class provides a manager for the 'text-decoration' property values.
36  *
37  * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
38  * @version $Id: TextDecorationManager.java 1733416 2016-03-03 07:07:13Z gadams $
39  */

40 public class TextDecorationManager extends AbstractValueManager {
41
42     /**
43      * The identifier values.
44      */

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

60     public boolean isInheritedProperty() {
61         return false;
62     }
63
64     /**
65      * Implements {@link ValueManager#isAnimatableProperty()}.
66      */

67     public boolean isAnimatableProperty() {
68         return true;
69     }
70
71     /**
72      * Implements {@link ValueManager#isAdditiveProperty()}.
73      */

74     public boolean isAdditiveProperty() {
75         return false;
76     }
77
78     /**
79      * Implements {@link ValueManager#getPropertyType()}.
80      */

81     public int getPropertyType() {
82         return SVGTypes.TYPE_IDENT_LIST;
83     }
84
85     /**
86      * Implements {@link ValueManager#getPropertyName()}.
87      */

88     public String getPropertyName() {
89         return CSSConstants.CSS_TEXT_DECORATION_PROPERTY;
90     }
91
92     /**
93      * Implements {@link ValueManager#getDefaultValue()}.
94      */

95     public Value getDefaultValue() {
96         return ValueConstants.NONE_VALUE;
97     }
98
99     /**
100      * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
101      */

102     public Value createValue(LexicalUnit lu, CSSEngine engine)
103         throws DOMException {
104         switch (lu.getLexicalUnitType()) {
105         case LexicalUnit.SAC_INHERIT:
106             return ValueConstants.INHERIT_VALUE;
107
108         case LexicalUnit.SAC_IDENT:
109             if (lu.getStringValue().equalsIgnoreCase
110                 (CSSConstants.CSS_NONE_VALUE)) {
111                 return ValueConstants.NONE_VALUE;
112             }
113             ListValue lv = new ListValue(' ');
114             do {
115                 if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
116                     String s = lu.getStringValue().toLowerCase().intern();
117                     Object obj = values.get(s);
118                     if (obj == null) {
119                         throw createInvalidIdentifierDOMException
120                             (lu.getStringValue());
121                     }
122                     lv.append((Value)obj);
123                     lu = lu.getNextLexicalUnit();
124                 } else {
125                     throw createInvalidLexicalUnitDOMException
126                         (lu.getLexicalUnitType());
127                 }
128
129             } while (lu != null);
130             return lv;
131         }
132         throw createInvalidLexicalUnitDOMException
133             (lu.getLexicalUnitType());
134     }
135
136     /**
137      * Implements {@link
138      * ValueManager#createStringValue(short,String,CSSEngine)}.
139      */

140     public Value createStringValue(short type, String value, CSSEngine engine)
141         throws DOMException {
142         if (type != CSSPrimitiveValue.CSS_IDENT) {
143             throw createInvalidStringTypeDOMException(type);
144         }
145         if (!value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) {
146             throw createInvalidIdentifierDOMException(value);
147         }
148         return ValueConstants.NONE_VALUE;
149     }
150
151 }
152