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.CSSStylableElement;
23 import org.apache.batik.css.engine.StyleMap;
24 import org.apache.batik.css.engine.value.LengthManager;
25 import org.apache.batik.css.engine.value.ListValue;
26 import org.apache.batik.css.engine.value.Value;
27 import org.apache.batik.css.engine.value.ValueManager;
28 import org.apache.batik.util.CSSConstants;
29 import org.apache.batik.util.SVGTypes;
30
31 import org.w3c.css.sac.LexicalUnit;
32 import org.w3c.dom.DOMException;
33 import org.w3c.dom.css.CSSPrimitiveValue;
34 import org.w3c.dom.css.CSSValue;
35
36 /**
37 * This class provides a factory for the 'stroke-dasharray' property values.
38 *
39 * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
40 * @version $Id: StrokeDasharrayManager.java 1733416 2016-03-03 07:07:13Z gadams $
41 */
42 public class StrokeDasharrayManager extends LengthManager {
43
44 /**
45 * Implements {@link ValueManager#isInheritedProperty()}.
46 */
47 public boolean isInheritedProperty() {
48 return true;
49 }
50
51 /**
52 * Implements {@link ValueManager#isAnimatableProperty()}.
53 */
54 public boolean isAnimatableProperty() {
55 return true;
56 }
57
58 /**
59 * Implements {@link ValueManager#isAdditiveProperty()}.
60 */
61 public boolean isAdditiveProperty() {
62 return false;
63 }
64
65 /**
66 * Implements {@link ValueManager#getPropertyType()}.
67 */
68 public int getPropertyType() {
69 return SVGTypes.TYPE_LENGTH_LIST_OR_IDENT;
70 }
71
72 /**
73 * Implements {@link ValueManager#getPropertyName()}.
74 */
75 public String getPropertyName() {
76 return CSSConstants.CSS_STROKE_DASHARRAY_PROPERTY;
77 }
78
79 /**
80 * Implements {@link ValueManager#getDefaultValue()}.
81 */
82 public Value getDefaultValue() {
83 return SVGValueConstants.NONE_VALUE;
84 }
85
86 /**
87 * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
88 */
89 public Value createValue(LexicalUnit lu, CSSEngine engine)
90 throws DOMException {
91 switch (lu.getLexicalUnitType()) {
92 case LexicalUnit.SAC_INHERIT:
93 return SVGValueConstants.INHERIT_VALUE;
94
95 case LexicalUnit.SAC_IDENT:
96 if (lu.getStringValue().equalsIgnoreCase
97 (CSSConstants.CSS_NONE_VALUE)) {
98 return SVGValueConstants.NONE_VALUE;
99 }
100 throw createInvalidIdentifierDOMException(lu.getStringValue());
101
102 default:
103 ListValue lv = new ListValue(' ');
104 do {
105 Value v = super.createValue(lu, engine);
106 lv.append(v);
107 lu = lu.getNextLexicalUnit();
108 if (lu != null &&
109 lu.getLexicalUnitType() ==
110 LexicalUnit.SAC_OPERATOR_COMMA) {
111 lu = lu.getNextLexicalUnit();
112 }
113 } while (lu != null);
114 return lv;
115 }
116 }
117
118 /**
119 * Implements {@link
120 * ValueManager#createStringValue(short,String,CSSEngine)}.
121 */
122 public Value createStringValue(short type, String value, CSSEngine engine)
123 throws DOMException {
124 if (type != CSSPrimitiveValue.CSS_IDENT) {
125 throw createInvalidStringTypeDOMException(type);
126 }
127 if (value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) {
128 return SVGValueConstants.NONE_VALUE;
129 }
130 throw createInvalidIdentifierDOMException(value);
131 }
132
133 /**
134 * Implements {@link
135 * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
136 */
137 public Value computeValue(CSSStylableElement elt,
138 String pseudo,
139 CSSEngine engine,
140 int idx,
141 StyleMap sm,
142 Value value) {
143 switch (value.getCssValueType()) {
144 case CSSValue.CSS_PRIMITIVE_VALUE:
145 return value;
146 }
147
148 ListValue lv = (ListValue)value;
149 ListValue result = new ListValue(' ');
150 for (int i = 0; i < lv.getLength(); i++) {
151 result.append(super.computeValue(elt, pseudo, engine, idx, sm,
152 lv.item(i)));
153 }
154 return result;
155 }
156
157 /**
158 * Indicates the orientation of the property associated with
159 * this manager.
160 */
161 protected int getOrientation() {
162 return BOTH_ORIENTATION;
163 }
164 }
165