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.ValueConstants;
26 import org.apache.batik.css.engine.value.ValueManager;
27 import org.apache.batik.util.CSSConstants;
28 import org.apache.batik.util.SVGTypes;
29
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 'clip-path' property values.
36  *
37  * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
38  * @version $Id: ClipPathManager.java 1733416 2016-03-03 07:07:13Z gadams $
39  */

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

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

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

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

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

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

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

87     public Value createValue(LexicalUnit lu, CSSEngine engine)
88         throws DOMException {
89         switch (lu.getLexicalUnitType()) {
90         case LexicalUnit.SAC_INHERIT:
91             return ValueConstants.INHERIT_VALUE;
92
93         case LexicalUnit.SAC_URI:
94             return new URIValue(lu.getStringValue(),
95                                 resolveURI(engine.getCSSBaseURI(),
96                                            lu.getStringValue()));
97
98         case LexicalUnit.SAC_IDENT:
99             if (lu.getStringValue().equalsIgnoreCase
100                 (CSSConstants.CSS_NONE_VALUE)) {
101                 return ValueConstants.NONE_VALUE;
102             }
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         switch (type) {
114         case CSSPrimitiveValue.CSS_IDENT:
115             if (value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) {
116                 return ValueConstants.NONE_VALUE;
117             }
118             break;
119
120         case CSSPrimitiveValue.CSS_URI:
121             return new URIValue(value, 
122                                 resolveURI(engine.getCSSBaseURI(), value));
123         }
124         throw createInvalidStringTypeDOMException(type);
125     }
126 }
127