001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.css.engine.value.svg;
020:
021: import org.apache.batik.css.engine.CSSEngine;
022: import org.apache.batik.css.engine.CSSStylableElement;
023: import org.apache.batik.css.engine.StyleMap;
024: import org.apache.batik.css.engine.value.LengthManager;
025: import org.apache.batik.css.engine.value.ListValue;
026: import org.apache.batik.css.engine.value.Value;
027: import org.apache.batik.css.engine.value.ValueManager;
028: import org.apache.batik.util.CSSConstants;
029: import org.apache.batik.util.SVGTypes;
030:
031: import org.w3c.css.sac.LexicalUnit;
032: import org.w3c.dom.DOMException;
033: import org.w3c.dom.css.CSSPrimitiveValue;
034: import org.w3c.dom.css.CSSValue;
035:
036: /**
037: * This class provides a manager for the 'enable-background' property values.
038: *
039: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
040: * @version $Id: EnableBackgroundManager.java 475685 2006-11-16 11:16:05Z cam $
041: */
042: public class EnableBackgroundManager extends LengthManager {
043:
044: /**
045: * The length orientation.
046: */
047: protected int orientation;
048:
049: /**
050: * Implements {@link ValueManager#isInheritedProperty()}.
051: */
052: public boolean isInheritedProperty() {
053: return false;
054: }
055:
056: /**
057: * Implements {@link ValueManager#isAnimatableProperty()}.
058: */
059: public boolean isAnimatableProperty() {
060: return false;
061: }
062:
063: /**
064: * Implements {@link ValueManager#isAdditiveProperty()}.
065: */
066: public boolean isAdditiveProperty() {
067: return false;
068: }
069:
070: /**
071: * Implements {@link ValueManager#getPropertyType()}.
072: */
073: public int getPropertyType() {
074: return SVGTypes.TYPE_ENABLE_BACKGROUND_VALUE;
075: }
076:
077: /**
078: * Implements {@link ValueManager#getPropertyName()}.
079: */
080: public String getPropertyName() {
081: return CSSConstants.CSS_ENABLE_BACKGROUND_PROPERTY;
082: }
083:
084: /**
085: * Implements {@link ValueManager#getDefaultValue()}.
086: */
087: public Value getDefaultValue() {
088: return SVGValueConstants.ACCUMULATE_VALUE;
089: }
090:
091: /**
092: * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
093: */
094: public Value createValue(LexicalUnit lu, CSSEngine engine)
095: throws DOMException {
096: switch (lu.getLexicalUnitType()) {
097: case LexicalUnit.SAC_INHERIT:
098: return SVGValueConstants.INHERIT_VALUE;
099:
100: default:
101: throw createInvalidLexicalUnitDOMException(lu
102: .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: /**
131: * Implements {@link
132: * ValueManager#createStringValue(short,String,CSSEngine)}.
133: */
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: /**
146: * Implements {@link ValueManager#createFloatValue(short,float)}.
147: */
148: public Value createFloatValue(short unitType, float floatValue)
149: throws DOMException {
150: throw createDOMException();
151: }
152:
153: /**
154: * Implements {@link
155: * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
156: */
157: public Value computeValue(CSSStylableElement elt, String pseudo,
158: CSSEngine engine, int idx, StyleMap sm, Value value) {
159: if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
160: ListValue lv = (ListValue) value;
161: if (lv.getLength() == 5) {
162: Value lv1 = lv.item(1);
163: orientation = HORIZONTAL_ORIENTATION;
164: Value v1 = super .computeValue(elt, pseudo, engine, idx,
165: sm, lv1);
166: Value lv2 = lv.item(2);
167: orientation = VERTICAL_ORIENTATION;
168: Value v2 = super .computeValue(elt, pseudo, engine, idx,
169: sm, lv2);
170: Value lv3 = lv.item(3);
171: orientation = HORIZONTAL_ORIENTATION;
172: Value v3 = super .computeValue(elt, pseudo, engine, idx,
173: sm, lv3);
174: Value lv4 = lv.item(4);
175: orientation = VERTICAL_ORIENTATION;
176: Value v4 = super .computeValue(elt, pseudo, engine, idx,
177: sm, lv4);
178:
179: if (lv1 != v1 || lv2 != v2 || lv3 != v3 || lv4 != v4) {
180: ListValue result = new ListValue(' ');
181: result.append(lv.item(0));
182: result.append(v1);
183: result.append(v2);
184: result.append(v3);
185: result.append(v4);
186: return result;
187: }
188: }
189: }
190: return value;
191: }
192:
193: /**
194: * Indicates the orientation of the property associated with
195: * this manager.
196: */
197: protected int getOrientation() {
198: return orientation;
199: }
200:
201: }
|