1 18 package org.apache.batik.css.engine.value.css2; 19 20 import org.apache.batik.css.engine.CSSEngine; 21 import org.apache.batik.css.engine.CSSStylableElement; 22 import org.apache.batik.css.engine.StyleMap; 23 import org.apache.batik.css.engine.value.AbstractValueManager; 24 import org.apache.batik.css.engine.value.ListValue; 25 import org.apache.batik.css.engine.value.StringMap; 26 import org.apache.batik.css.engine.value.URIValue; 27 import org.apache.batik.css.engine.value.Value; 28 import org.apache.batik.css.engine.value.ValueConstants; 29 import org.apache.batik.css.engine.value.ValueManager; 30 import org.apache.batik.util.CSSConstants; 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 CursorManager extends AbstractValueManager { 43 44 47 protected final static StringMap values = new StringMap(); 48 static { 49 values.put(CSSConstants.CSS_AUTO_VALUE, 50 ValueConstants.AUTO_VALUE); 51 values.put(CSSConstants.CSS_CROSSHAIR_VALUE, 52 ValueConstants.CROSSHAIR_VALUE); 53 values.put(CSSConstants.CSS_DEFAULT_VALUE, 54 ValueConstants.DEFAULT_VALUE); 55 values.put(CSSConstants.CSS_E_RESIZE_VALUE, 56 ValueConstants.E_RESIZE_VALUE); 57 values.put(CSSConstants.CSS_HELP_VALUE, 58 ValueConstants.HELP_VALUE); 59 values.put(CSSConstants.CSS_MOVE_VALUE, 60 ValueConstants.MOVE_VALUE); 61 values.put(CSSConstants.CSS_N_RESIZE_VALUE, 62 ValueConstants.N_RESIZE_VALUE); 63 values.put(CSSConstants.CSS_NE_RESIZE_VALUE, 64 ValueConstants.NE_RESIZE_VALUE); 65 values.put(CSSConstants.CSS_NW_RESIZE_VALUE, 66 ValueConstants.NW_RESIZE_VALUE); 67 values.put(CSSConstants.CSS_POINTER_VALUE, 68 ValueConstants.POINTER_VALUE); 69 values.put(CSSConstants.CSS_S_RESIZE_VALUE, 70 ValueConstants.S_RESIZE_VALUE); 71 values.put(CSSConstants.CSS_SE_RESIZE_VALUE, 72 ValueConstants.SE_RESIZE_VALUE); 73 values.put(CSSConstants.CSS_SW_RESIZE_VALUE, 74 ValueConstants.SW_RESIZE_VALUE); 75 values.put(CSSConstants.CSS_TEXT_VALUE, 76 ValueConstants.TEXT_VALUE); 77 values.put(CSSConstants.CSS_W_RESIZE_VALUE, 78 ValueConstants.W_RESIZE_VALUE); 79 values.put(CSSConstants.CSS_WAIT_VALUE, 80 ValueConstants.WAIT_VALUE); 81 } 82 83 86 public boolean isInheritedProperty() { 87 return true; 88 } 89 90 93 public String getPropertyName() { 94 return CSSConstants.CSS_CURSOR_PROPERTY; 95 } 96 97 100 public Value getDefaultValue() { 101 return ValueConstants.AUTO_VALUE; 102 } 103 104 107 public Value createValue(LexicalUnit lu, CSSEngine engine) 108 throws DOMException { 109 ListValue result = new ListValue(); 110 switch (lu.getLexicalUnitType()) { 111 case LexicalUnit.SAC_INHERIT: 112 return ValueConstants.INHERIT_VALUE; 113 114 case LexicalUnit.SAC_URI: 115 do { 116 result.append(new URIValue(lu.getStringValue(), 117 resolveURI(engine.getCSSBaseURI(), 118 lu.getStringValue()))); 119 lu = lu.getNextLexicalUnit(); 120 if (lu == null) { 121 throw createMalformedLexicalUnitDOMException(); 122 } 123 if (lu.getLexicalUnitType() != 124 LexicalUnit.SAC_OPERATOR_COMMA) { 125 throw createInvalidLexicalUnitDOMException 126 (lu.getLexicalUnitType()); 127 } 128 lu = lu.getNextLexicalUnit(); 129 if (lu == null) { 130 throw createMalformedLexicalUnitDOMException(); 131 } 132 } while (lu.getLexicalUnitType() == LexicalUnit.SAC_URI); 133 if (lu.getLexicalUnitType() != LexicalUnit.SAC_IDENT) { 134 throw createInvalidLexicalUnitDOMException 135 (lu.getLexicalUnitType()); 136 } 137 139 case LexicalUnit.SAC_IDENT: 140 String s = lu.getStringValue().toLowerCase().intern(); 141 Object v = values.get(s); 142 if (v == null) { 143 throw createInvalidIdentifierDOMException(lu.getStringValue()); 144 } 145 result.append((Value)v); 146 lu = lu.getNextLexicalUnit(); 147 } 148 if (lu != null) { 149 throw createInvalidLexicalUnitDOMException 150 (lu.getLexicalUnitType()); 151 } 152 return result; 153 } 154 155 159 public Value computeValue(CSSStylableElement elt, 160 String pseudo, 161 CSSEngine engine, 162 int idx, 163 StyleMap sm, 164 Value value) { 165 if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { 166 ListValue lv = (ListValue)value; 167 int len = lv.getLength(); 168 ListValue result = new ListValue(' '); 169 for (int i=0; i<len; i++) { 170 Value v = lv.item(0); 171 if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_URI) { 172 result.append(new URIValue(v.getStringValue(), 174 v.getStringValue())); 175 } else { 176 result.append(v); 177 } 178 } 179 return result; 180 } 181 return super.computeValue(elt, pseudo, engine, idx, sm, value); 182 } 183 184 } 185 | Popular Tags |