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.svg;
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.StringValue;
24 import org.apache.batik.css.engine.value.URIValue;
25 import org.apache.batik.css.engine.value.Value;
26 import org.apache.batik.css.engine.value.ValueManager;
27 import org.apache.batik.util.CSSConstants;
28 import org.apache.batik.util.SVGTypes;
29 import org.w3c.css.sac.LexicalUnit;
30 import org.w3c.dom.DOMException;
31 import org.w3c.dom.css.CSSPrimitiveValue;
32
33 /**
34  * This class provides a manager for the 'color-interpolation' property values.
35  *
36  * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
37  * @version $Id: ColorProfileManager.java 1733416 2016-03-03 07:07:13Z gadams $
38  */

39 public class ColorProfileManager extends AbstractValueManager {
40     
41     /**
42      * Implements {@link ValueManager#isInheritedProperty()}.
43      */

44     public boolean isInheritedProperty() {
45         return true;
46     }
47
48     /**
49      * Implements {@link ValueManager#getPropertyName()}.
50      */

51     public String getPropertyName() {
52         return CSSConstants.CSS_COLOR_PROFILE_PROPERTY;
53     }
54     
55     /**
56      * Implements {@link ValueManager#isAnimatableProperty()}.
57      */

58     public boolean isAnimatableProperty() {
59         return true;
60     }
61
62     /**
63      * Implements {@link ValueManager#isAdditiveProperty()}.
64      */

65     public boolean isAdditiveProperty() {
66         return false;
67     }
68
69     /**
70      * Implements {@link ValueManager#getPropertyType()}.
71      */

72     public int getPropertyType() {
73         return SVGTypes.TYPE_URI_OR_IDENT;
74     }
75
76     /**
77      * Implements {@link ValueManager#getDefaultValue()}.
78      */

79     public Value getDefaultValue() {
80         return SVGValueConstants.AUTO_VALUE;
81     }
82
83     /**
84      * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
85      */

86     public Value createValue(LexicalUnit lu, CSSEngine engine)
87         throws DOMException {
88         switch (lu.getLexicalUnitType()) {
89         case LexicalUnit.SAC_INHERIT:
90             return SVGValueConstants.INHERIT_VALUE;
91
92         case LexicalUnit.SAC_IDENT:
93             String s = lu.getStringValue().toLowerCase();
94             if (s.equals(CSSConstants.CSS_AUTO_VALUE)) {
95                 return SVGValueConstants.AUTO_VALUE;
96             }
97             if (s.equals(CSSConstants.CSS_SRGB_VALUE)) {
98                 return SVGValueConstants.SRGB_VALUE;
99             }
100             return new StringValue(CSSPrimitiveValue.CSS_IDENT, s);
101             
102         case LexicalUnit.SAC_URI:
103             return new URIValue(lu.getStringValue(),
104                                 resolveURI(engine.getCSSBaseURI(),
105                                            lu.getStringValue()));
106         }
107         throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType());
108     }
109
110     /**
111      * Implements {@link
112      * ValueManager#createStringValue(short,String,CSSEngine)}.
113      */

114     public Value createStringValue(short type, String value, CSSEngine engine)
115         throws DOMException {
116         switch (type) {
117         case CSSPrimitiveValue.CSS_IDENT:
118             String s = value.toLowerCase();
119             if (s.equals(CSSConstants.CSS_AUTO_VALUE)) {
120                 return SVGValueConstants.AUTO_VALUE;
121             }
122             if (s.equals(CSSConstants.CSS_SRGB_VALUE)) {
123                 return SVGValueConstants.SRGB_VALUE;
124             }
125             return new StringValue(CSSPrimitiveValue.CSS_IDENT, s);
126
127         case CSSPrimitiveValue.CSS_URI:
128             return new URIValue(value,
129                                 resolveURI(engine.getCSSBaseURI(), value));
130         }
131         throw createInvalidStringTypeDOMException(type);
132     }
133 }
134