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 'marker-*' property values.
36  *
37  * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
38  * @version $Id: MarkerManager.java 1733416 2016-03-03 07:07:13Z gadams $
39  */

40 public class MarkerManager extends AbstractValueManager {
41     
42     /**
43      * The handled property.
44      */

45     protected String property;
46
47     /**
48      * Creates a new MarkerManager.
49      */

50     public MarkerManager(String prop) {
51         property = prop;
52     }
53
54     /**
55      * Implements {@link ValueManager#isInheritedProperty()}.
56      */

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

64     public boolean isAnimatableProperty() {
65         return true;
66     }
67
68     /**
69      * Implements {@link ValueManager#isAdditiveProperty()}.
70      */

71     public boolean isAdditiveProperty() {
72         return false;
73     }
74
75     /**
76      * Implements {@link ValueManager#getPropertyType()}.
77      */

78     public int getPropertyType() {
79         return SVGTypes.TYPE_URI_OR_IDENT;
80     }
81
82     /**
83      * Implements {@link ValueManager#getPropertyName()}.
84      */

85     public String getPropertyName() {
86         return property;
87     }
88     
89     /**
90      * Implements {@link ValueManager#getDefaultValue()}.
91      */

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

99     public Value createValue(LexicalUnit lu, CSSEngine engine)
100         throws DOMException {
101         switch (lu.getLexicalUnitType()) {
102         case LexicalUnit.SAC_INHERIT:
103             return ValueConstants.INHERIT_VALUE;
104
105         case LexicalUnit.SAC_URI:
106             return new URIValue(lu.getStringValue(),
107                                 resolveURI(engine.getCSSBaseURI(),
108                                            lu.getStringValue()));
109
110         case LexicalUnit.SAC_IDENT:
111             if (lu.getStringValue().equalsIgnoreCase
112                 (CSSConstants.CSS_NONE_VALUE)) {
113                 return ValueConstants.NONE_VALUE;
114             }
115         }
116         throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType());
117     }
118
119     /**
120      * Implements {@link
121      * ValueManager#createStringValue(short,String,CSSEngine)}.
122      */

123     public Value createStringValue(short type, String value, CSSEngine engine)
124         throws DOMException {
125         switch (type) {
126         case CSSPrimitiveValue.CSS_IDENT:
127             if (value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) {
128                 return ValueConstants.NONE_VALUE;
129             }
130             break;
131
132         case CSSPrimitiveValue.CSS_URI:
133             return new URIValue(value,
134                                 resolveURI(engine.getCSSBaseURI(), value));
135         }
136         throw createInvalidStringTypeDOMException(type);
137     }
138 }
139