001: /*
002:
003: ============================================================================
004: The Apache Software License, Version 1.1
005: ============================================================================
006:
007: Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
008:
009: Redistribution and use in source and binary forms, with or without modifica-
010: tion, are permitted provided that the following conditions are met:
011:
012: 1. Redistributions of source code must retain the above copyright notice,
013: this list of conditions and the following disclaimer.
014:
015: 2. Redistributions in binary form must reproduce the above copyright notice,
016: this list of conditions and the following disclaimer in the documentation
017: and/or other materials provided with the distribution.
018:
019: 3. The end-user documentation included with the redistribution, if any, must
020: include the following acknowledgment: "This product includes software
021: developed by the Apache Software Foundation (http://www.apache.org/)."
022: Alternately, this acknowledgment may appear in the software itself, if
023: and wherever such third-party acknowledgments normally appear.
024:
025: 4. The names "Batik" and "Apache Software Foundation" must not be
026: used to endorse or promote products derived from this software without
027: prior written permission. For written permission, please contact
028: apache@apache.org.
029:
030: 5. Products derived from this software may not be called "Apache", nor may
031: "Apache" appear in their name, without prior written permission of the
032: Apache Software Foundation.
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
035: INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
036: FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
037: APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
038: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
039: DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
040: OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
041: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
042: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
043: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
044:
045: This software consists of voluntary contributions made by many individuals
046: on behalf of the Apache Software Foundation. For more information on the
047: Apache Software Foundation, please see <http://www.apache.org/>.
048:
049: */
050:
051: package org.apache.batik.css.engine.value.css2;
052:
053: import org.apache.batik.css.engine.CSSEngine;
054: import org.apache.batik.css.engine.CSSStylableElement;
055: import org.apache.batik.css.engine.StyleMap;
056: import org.apache.batik.css.engine.value.AbstractValueManager;
057: import org.apache.batik.css.engine.value.ListValue;
058: import org.apache.batik.css.engine.value.StringMap;
059: import org.apache.batik.css.engine.value.URIValue;
060: import org.apache.batik.css.engine.value.Value;
061: import org.apache.batik.css.engine.value.ValueConstants;
062: import org.apache.batik.util.CSSConstants;
063: import org.w3c.css.sac.LexicalUnit;
064: import org.w3c.dom.DOMException;
065: import org.w3c.dom.css.CSSPrimitiveValue;
066: import org.w3c.dom.css.CSSValue;
067:
068: /**
069: * This class provides a manager for the 'cursor' property values.
070: *
071: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
072: * @version $Id$
073: */
074: public class CursorManager extends AbstractValueManager {
075:
076: /**
077: * The identifier values.
078: */
079: protected final static StringMap values = new StringMap();
080: static {
081: values.put(CSSConstants.CSS_AUTO_VALUE,
082: ValueConstants.AUTO_VALUE);
083: values.put(CSSConstants.CSS_CROSSHAIR_VALUE,
084: ValueConstants.CROSSHAIR_VALUE);
085: values.put(CSSConstants.CSS_DEFAULT_VALUE,
086: ValueConstants.DEFAULT_VALUE);
087: values.put(CSSConstants.CSS_E_RESIZE_VALUE,
088: ValueConstants.E_RESIZE_VALUE);
089: values.put(CSSConstants.CSS_HELP_VALUE,
090: ValueConstants.HELP_VALUE);
091: values.put(CSSConstants.CSS_MOVE_VALUE,
092: ValueConstants.MOVE_VALUE);
093: values.put(CSSConstants.CSS_N_RESIZE_VALUE,
094: ValueConstants.N_RESIZE_VALUE);
095: values.put(CSSConstants.CSS_NE_RESIZE_VALUE,
096: ValueConstants.NE_RESIZE_VALUE);
097: values.put(CSSConstants.CSS_NW_RESIZE_VALUE,
098: ValueConstants.NW_RESIZE_VALUE);
099: values.put(CSSConstants.CSS_POINTER_VALUE,
100: ValueConstants.POINTER_VALUE);
101: values.put(CSSConstants.CSS_S_RESIZE_VALUE,
102: ValueConstants.S_RESIZE_VALUE);
103: values.put(CSSConstants.CSS_SE_RESIZE_VALUE,
104: ValueConstants.SE_RESIZE_VALUE);
105: values.put(CSSConstants.CSS_SW_RESIZE_VALUE,
106: ValueConstants.SW_RESIZE_VALUE);
107: values.put(CSSConstants.CSS_TEXT_VALUE,
108: ValueConstants.TEXT_VALUE);
109: values.put(CSSConstants.CSS_W_RESIZE_VALUE,
110: ValueConstants.W_RESIZE_VALUE);
111: values.put(CSSConstants.CSS_WAIT_VALUE,
112: ValueConstants.WAIT_VALUE);
113: }
114:
115: /**
116: * Implements {@link ValueManager#isInheritedProperty()}.
117: */
118: public boolean isInheritedProperty() {
119: return true;
120: }
121:
122: /**
123: * Implements {@link ValueManager#getPropertyName()}.
124: */
125: public String getPropertyName() {
126: return CSSConstants.CSS_CURSOR_PROPERTY;
127: }
128:
129: /**
130: * Implements {@link ValueManager#getDefaultValue()}.
131: */
132: public Value getDefaultValue() {
133: return ValueConstants.AUTO_VALUE;
134: }
135:
136: /**
137: * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
138: */
139: public Value createValue(LexicalUnit lu, CSSEngine engine)
140: throws DOMException {
141: ListValue result = new ListValue();
142: switch (lu.getLexicalUnitType()) {
143: case LexicalUnit.SAC_INHERIT:
144: return ValueConstants.INHERIT_VALUE;
145:
146: case LexicalUnit.SAC_URI:
147: do {
148: result.append(new URIValue(lu.getStringValue(),
149: resolveURI(engine.getCSSBaseURI(), lu
150: .getStringValue())));
151: lu = lu.getNextLexicalUnit();
152: if (lu == null) {
153: throw createMalformedLexicalUnitDOMException(engine);
154: }
155: if (lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) {
156: throw createInvalidLexicalUnitDOMException(lu
157: .getLexicalUnitType(), engine);
158: }
159: lu = lu.getNextLexicalUnit();
160: if (lu == null) {
161: throw createMalformedLexicalUnitDOMException(engine);
162: }
163: } while (lu.getLexicalUnitType() == LexicalUnit.SAC_URI);
164: if (lu.getLexicalUnitType() != LexicalUnit.SAC_IDENT) {
165: throw createInvalidLexicalUnitDOMException(lu
166: .getLexicalUnitType(), engine);
167: }
168: // Fall through...
169:
170: case LexicalUnit.SAC_IDENT:
171: String s = lu.getStringValue().toLowerCase().intern();
172: Object v = values.get(s);
173: if (v == null) {
174: throw createInvalidIdentifierDOMException(lu
175: .getStringValue(), engine);
176: }
177: result.append((Value) v);
178: lu = lu.getNextLexicalUnit();
179: }
180: if (lu != null) {
181: throw createInvalidLexicalUnitDOMException(lu
182: .getLexicalUnitType(), engine);
183: }
184: return result;
185: }
186:
187: /**
188: * Implements {@link
189: * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
190: */
191: public Value computeValue(CSSStylableElement elt, String pseudo,
192: CSSEngine engine, int idx, StyleMap sm, Value value) {
193: if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
194: ListValue lv = (ListValue) value;
195: int len = lv.getLength();
196: ListValue result = new ListValue(' ');
197: for (int i = 0; i < len; i++) {
198: Value v = lv.item(0);
199: if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
200: // Reveal the absolute value as the cssText now.
201: result.append(new URIValue(v.getStringValue(), v
202: .getStringValue()));
203: } else {
204: result.append(v);
205: }
206: }
207: return result;
208: }
209: return super.computeValue(elt, pseudo, engine, idx, sm, value);
210: }
211:
212: }
|