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

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

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

51     public String getPropertyName() {
52         return CSSConstants.CSS_FILTER_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.NONE_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_URI:
93             return new URIValue(lu.getStringValue(),
94                                 resolveURI(engine.getCSSBaseURI(),
95                                            lu.getStringValue()));
96
97         case LexicalUnit.SAC_IDENT:
98             if (lu.getStringValue().equalsIgnoreCase
99                 (CSSConstants.CSS_NONE_VALUE)) {
100                 return SVGValueConstants.NONE_VALUE;
101             }
102             throw createInvalidIdentifierDOMException(lu.getStringValue());
103         }
104         throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType());
105     }
106
107     /**
108      * Implements {@link
109      * ValueManager#createStringValue(short,String,CSSEngine)}.
110      */

111     public Value createStringValue(short type, String value, CSSEngine engine)
112         throws DOMException {
113         if (type == CSSPrimitiveValue.CSS_IDENT) {
114             if (value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) {
115                 return SVGValueConstants.NONE_VALUE;
116             }
117             throw createInvalidIdentifierDOMException(value);
118         }
119         if (type == CSSPrimitiveValue.CSS_URI) {
120             return new URIValue(value, 
121                                 resolveURI(engine.getCSSBaseURI(), value));
122         }
123         throw createInvalidStringTypeDOMException(type);
124     }
125 }
126