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 factory for the 'stroke-dasharray' property values.
038: *
039: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
040: * @version $Id: StrokeDasharrayManager.java 475685 2006-11-16 11:16:05Z cam $
041: */
042: public class StrokeDasharrayManager extends LengthManager {
043:
044: /**
045: * Implements {@link ValueManager#isInheritedProperty()}.
046: */
047: public boolean isInheritedProperty() {
048: return true;
049: }
050:
051: /**
052: * Implements {@link ValueManager#isAnimatableProperty()}.
053: */
054: public boolean isAnimatableProperty() {
055: return true;
056: }
057:
058: /**
059: * Implements {@link ValueManager#isAdditiveProperty()}.
060: */
061: public boolean isAdditiveProperty() {
062: return false;
063: }
064:
065: /**
066: * Implements {@link ValueManager#getPropertyType()}.
067: */
068: public int getPropertyType() {
069: return SVGTypes.TYPE_LENGTH_LIST_OR_IDENT;
070: }
071:
072: /**
073: * Implements {@link ValueManager#getPropertyName()}.
074: */
075: public String getPropertyName() {
076: return CSSConstants.CSS_STROKE_DASHARRAY_PROPERTY;
077: }
078:
079: /**
080: * Implements {@link ValueManager#getDefaultValue()}.
081: */
082: public Value getDefaultValue() {
083: return SVGValueConstants.NONE_VALUE;
084: }
085:
086: /**
087: * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
088: */
089: public Value createValue(LexicalUnit lu, CSSEngine engine)
090: throws DOMException {
091: switch (lu.getLexicalUnitType()) {
092: case LexicalUnit.SAC_INHERIT:
093: return SVGValueConstants.INHERIT_VALUE;
094:
095: case LexicalUnit.SAC_IDENT:
096: if (lu.getStringValue().equalsIgnoreCase(
097: CSSConstants.CSS_NONE_VALUE)) {
098: return SVGValueConstants.NONE_VALUE;
099: }
100: throw createInvalidIdentifierDOMException(lu
101: .getStringValue());
102:
103: default:
104: ListValue lv = new ListValue(' ');
105: do {
106: Value v = super .createValue(lu, engine);
107: lv.append(v);
108: lu = lu.getNextLexicalUnit();
109: if (lu != null
110: && lu.getLexicalUnitType() == 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,
123: CSSEngine engine) 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, String pseudo,
138: CSSEngine engine, int idx, StyleMap sm, Value value) {
139: switch (value.getCssValueType()) {
140: case CSSValue.CSS_PRIMITIVE_VALUE:
141: return value;
142: }
143:
144: ListValue lv = (ListValue) value;
145: ListValue result = new ListValue(' ');
146: for (int i = 0; i < lv.getLength(); i++) {
147: result.append(super .computeValue(elt, pseudo, engine, idx,
148: sm, lv.item(i)));
149: }
150: return result;
151: }
152:
153: /**
154: * Indicates the orientation of the property associated with
155: * this manager.
156: */
157: protected int getOrientation() {
158: return BOTH_ORIENTATION;
159: }
160: }
|