1
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
42 public class EnableBackgroundManager extends LengthManager {
43
44
47 protected int orientation;
48
49
52 public boolean isInheritedProperty() {
53 return false;
54 }
55
56
59 public boolean isAnimatableProperty() {
60 return false;
61 }
62
63
66 public boolean isAdditiveProperty() {
67 return false;
68 }
69
70
73 public int getPropertyType() {
74 return SVGTypes.TYPE_ENABLE_BACKGROUND_VALUE;
75 }
76
77
80 public String getPropertyName() {
81 return CSSConstants.CSS_ENABLE_BACKGROUND_PROPERTY;
82 }
83
84
87 public Value getDefaultValue() {
88 return SVGValueConstants.ACCUMULATE_VALUE;
89 }
90
91
94 public Value createValue(LexicalUnit lu, CSSEngine engine)
95 throws DOMException {
96 switch (lu.getLexicalUnitType()) {
97 case LexicalUnit.SAC_INHERIT:
98 return SVGValueConstants.INHERIT_VALUE;
99
100 default:
101 throw createInvalidLexicalUnitDOMException
102 (lu.getLexicalUnitType());
103
104 case LexicalUnit.SAC_IDENT:
105 String id = lu.getStringValue().toLowerCase().intern();
106 if (id == CSSConstants.CSS_ACCUMULATE_VALUE) {
107 return SVGValueConstants.ACCUMULATE_VALUE;
108 }
109 if (id != CSSConstants.CSS_NEW_VALUE) {
110 throw createInvalidIdentifierDOMException(id);
111 }
112 ListValue result = new ListValue(' ');
113 result.append(SVGValueConstants.NEW_VALUE);
114 lu = lu.getNextLexicalUnit();
115 if (lu == null) {
116 return result;
117 }
118 result.append(super.createValue(lu, engine));
119 for (int i = 1; i < 4; i++) {
120 lu = lu.getNextLexicalUnit();
121 if (lu == null){
122 throw createMalformedLexicalUnitDOMException();
123 }
124 result.append(super.createValue(lu, engine));
125 }
126 return result;
127 }
128 }
129
130
134 public Value createStringValue(short type, String value,
135 CSSEngine engine) {
136 if (type != CSSPrimitiveValue.CSS_IDENT) {
137 throw createInvalidStringTypeDOMException(type);
138 }
139 if (!value.equalsIgnoreCase(CSSConstants.CSS_ACCUMULATE_VALUE)) {
140 throw createInvalidIdentifierDOMException(value);
141 }
142 return SVGValueConstants.ACCUMULATE_VALUE;
143 }
144
145
148 public Value createFloatValue(short unitType, float floatValue)
149 throws DOMException {
150 throw createDOMException();
151 }
152
153
157 public Value computeValue(CSSStylableElement elt,
158 String pseudo,
159 CSSEngine engine,
160 int idx,
161 StyleMap sm,
162 Value value) {
163 if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
164 ListValue lv = (ListValue)value;
165 if (lv.getLength() == 5) {
166 Value lv1 = lv.item(1);
167 orientation = HORIZONTAL_ORIENTATION;
168 Value v1 = super.computeValue(elt, pseudo, engine,
169 idx, sm, lv1);
170 Value lv2 = lv.item(2);
171 orientation = VERTICAL_ORIENTATION;
172 Value v2 = super.computeValue(elt, pseudo, engine,
173 idx, sm, lv2);
174 Value lv3 = lv.item(3);
175 orientation = HORIZONTAL_ORIENTATION;
176 Value v3 = super.computeValue(elt, pseudo, engine,
177 idx, sm, lv3);
178 Value lv4 = lv.item(4);
179 orientation = VERTICAL_ORIENTATION;
180 Value v4 = super.computeValue(elt, pseudo, engine,
181 idx, sm, lv4);
182
183 if (lv1 != v1 || lv2 != v2 ||
184 lv3 != v3 || lv4 != v4) {
185 ListValue result = new ListValue(' ');
186 result.append(lv.item(0));
187 result.append(v1);
188 result.append(v2);
189 result.append(v3);
190 result.append(v4);
191 return result;
192 }
193 }
194 }
195 return value;
196 }
197
198
202 protected int getOrientation() {
203 return orientation;
204 }
205
206 }
207