1 18 package org.apache.batik.css.engine.value.svg; 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.LengthManager; 24 import org.apache.batik.css.engine.value.ListValue; 25 import org.apache.batik.css.engine.value.Value; 26 import org.apache.batik.css.engine.value.ValueManager; 27 import org.apache.batik.util.CSSConstants; 28 import org.w3c.css.sac.LexicalUnit; 29 import org.w3c.dom.DOMException ; 30 import org.w3c.dom.css.CSSPrimitiveValue; 31 import org.w3c.dom.css.CSSValue; 32 33 39 public class EnableBackgroundManager extends LengthManager { 40 41 44 protected int orientation; 45 46 49 public boolean isInheritedProperty() { 50 return false; 51 } 52 53 56 public String getPropertyName() { 57 return CSSConstants.CSS_ENABLE_BACKGROUND_PROPERTY; 58 } 59 60 63 public Value getDefaultValue() { 64 return SVGValueConstants.ACCUMULATE_VALUE; 65 } 66 67 70 public Value createValue(LexicalUnit lu, CSSEngine engine) 71 throws DOMException { 72 switch (lu.getLexicalUnitType()) { 73 case LexicalUnit.SAC_INHERIT: 74 return SVGValueConstants.INHERIT_VALUE; 75 76 default: 77 throw createInvalidLexicalUnitDOMException 78 (lu.getLexicalUnitType()); 79 80 case LexicalUnit.SAC_IDENT: 81 String id = lu.getStringValue().toLowerCase().intern(); 82 if (id == CSSConstants.CSS_ACCUMULATE_VALUE) { 83 return SVGValueConstants.ACCUMULATE_VALUE; 84 } 85 if (id != CSSConstants.CSS_NEW_VALUE) { 86 throw createInvalidIdentifierDOMException(id); 87 } 88 ListValue result = new ListValue(' '); 89 result.append(SVGValueConstants.NEW_VALUE); 90 lu = lu.getNextLexicalUnit(); 91 if (lu == null) { 92 return result; 93 } 94 result.append(super.createValue(lu, engine)); 95 for (int i = 1; i < 4; i++) { 96 lu = lu.getNextLexicalUnit(); 97 if (lu == null){ 98 throw createMalformedLexicalUnitDOMException(); 99 } 100 result.append(super.createValue(lu, engine)); 101 } 102 return result; 103 } 104 } 105 106 110 public Value createStringValue(short type, String value, 111 CSSEngine engine) { 112 if (type != CSSPrimitiveValue.CSS_IDENT) { 113 throw createInvalidStringTypeDOMException(type); 114 } 115 if (!value.equalsIgnoreCase(CSSConstants.CSS_ACCUMULATE_VALUE)) { 116 throw createInvalidIdentifierDOMException(value); 117 } 118 return SVGValueConstants.ACCUMULATE_VALUE; 119 } 120 121 124 public Value createFloatValue(short unitType, float floatValue) 125 throws DOMException { 126 throw createDOMException(); 127 } 128 129 133 public Value computeValue(CSSStylableElement elt, 134 String pseudo, 135 CSSEngine engine, 136 int idx, 137 StyleMap sm, 138 Value value) { 139 if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { 140 ListValue lv = (ListValue)value; 141 if (lv.getLength() == 5) { 142 Value lv1 = lv.item(1); 143 orientation = HORIZONTAL_ORIENTATION; 144 Value v1 = super.computeValue(elt, pseudo, engine, 145 idx, sm, lv1); 146 Value lv2 = lv.item(2); 147 orientation = VERTICAL_ORIENTATION; 148 Value v2 = super.computeValue(elt, pseudo, engine, 149 idx, sm, lv2); 150 Value lv3 = lv.item(3); 151 orientation = HORIZONTAL_ORIENTATION; 152 Value v3 = super.computeValue(elt, pseudo, engine, 153 idx, sm, lv3); 154 Value lv4 = lv.item(4); 155 orientation = VERTICAL_ORIENTATION; 156 Value v4 = super.computeValue(elt, pseudo, engine, 157 idx, sm, lv4); 158 159 if (lv1 != v1 || lv2 != v2 || 160 lv3 != v3 || lv4 != v4) { 161 ListValue result = new ListValue(' '); 162 result.append(lv.item(0)); 163 result.append(v1); 164 result.append(v2); 165 result.append(v3); 166 result.append(v4); 167 return result; 168 } 169 } 170 } 171 return value; 172 } 173 174 178 protected int getOrientation() { 179 return orientation; 180 } 181 182 } 183 | Popular Tags |