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.LengthManager;
23 import org.apache.batik.css.engine.value.Value;
24 import org.apache.batik.css.engine.value.ValueManager;
25 import org.apache.batik.util.CSSConstants;
26 import org.apache.batik.util.SVGTypes;
27
28 import org.w3c.css.sac.LexicalUnit;
29 import org.w3c.dom.DOMException;
30 import org.w3c.dom.css.CSSPrimitiveValue;
31
32 /**
33 * This class provides a manager for the '*-spacing' property values.
34 *
35 * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
36 * @version $Id: SpacingManager.java 1733416 2016-03-03 07:07:13Z gadams $
37 */
38 public class SpacingManager extends LengthManager {
39
40 /**
41 * The handled property.
42 */
43 protected String property;
44
45 /**
46 * Creates a new SpacingManager.
47 */
48 public SpacingManager(String prop) {
49 property = prop;
50 }
51
52
53 /**
54 * Implements {@link ValueManager#isInheritedProperty()}.
55 */
56 public boolean isInheritedProperty() {
57 return true;
58 }
59
60 /**
61 * Implements {@link ValueManager#isAnimatableProperty()}.
62 */
63 public boolean isAnimatableProperty() {
64 return true;
65 }
66
67 /**
68 * Implements {@link ValueManager#isAdditiveProperty()}.
69 */
70 public boolean isAdditiveProperty() {
71 return true;
72 }
73
74 /**
75 * Implements {@link ValueManager#getPropertyType()}.
76 */
77 public int getPropertyType() {
78 return SVGTypes.TYPE_SPACING_VALUE;
79 }
80
81 /**
82 * Implements {@link ValueManager#getPropertyName()}.
83 */
84 public String getPropertyName() {
85 return property;
86 }
87
88 /**
89 * Implements {@link ValueManager#getDefaultValue()}.
90 */
91 public Value getDefaultValue() {
92 return SVGValueConstants.NORMAL_VALUE;
93 }
94
95 /**
96 * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
97 */
98 public Value createValue(LexicalUnit lu, CSSEngine engine)
99 throws DOMException {
100 switch (lu.getLexicalUnitType()) {
101 case LexicalUnit.SAC_INHERIT:
102 return SVGValueConstants.INHERIT_VALUE;
103
104 case LexicalUnit.SAC_IDENT:
105 if (lu.getStringValue().equalsIgnoreCase
106 (CSSConstants.CSS_NORMAL_VALUE)) {
107 return SVGValueConstants.NORMAL_VALUE;
108 }
109 throw createInvalidIdentifierDOMException(lu.getStringValue());
110 }
111 return super.createValue(lu, engine);
112 }
113
114 /**
115 * Implements {@link
116 * ValueManager#createStringValue(short,String,CSSEngine)}.
117 */
118 public Value createStringValue(short type, String value, CSSEngine engine)
119 throws DOMException {
120 if (type != CSSPrimitiveValue.CSS_IDENT) {
121 throw createInvalidStringTypeDOMException(type);
122 }
123 if (value.equalsIgnoreCase(CSSConstants.CSS_NORMAL_VALUE)) {
124 return SVGValueConstants.NORMAL_VALUE;
125 }
126 throw createInvalidIdentifierDOMException(value);
127 }
128
129 /**
130 * Indicates the orientation of the property associated with
131 * this manager.
132 */
133 protected int getOrientation() {
134 return BOTH_ORIENTATION;
135 }
136 }
137