1 18 package org.apache.batik.css.dom; 19 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 import org.apache.batik.css.engine.CSSEngine; 24 import org.apache.batik.css.engine.CSSStylableElement; 25 import org.apache.batik.css.engine.value.Value; 26 import org.w3c.dom.DOMException ; 27 import org.w3c.dom.css.CSSRule; 28 import org.w3c.dom.css.CSSStyleDeclaration; 29 import org.w3c.dom.css.CSSValue; 30 31 37 public class CSSOMComputedStyle implements CSSStyleDeclaration { 38 39 42 protected CSSEngine cssEngine; 43 44 47 protected CSSStylableElement element; 48 49 52 protected String pseudoElement; 53 54 57 protected Map values = new HashMap (); 58 59 62 public CSSOMComputedStyle(CSSEngine e, 63 CSSStylableElement elt, 64 String pseudoElt) { 65 cssEngine = e; 66 element = elt; 67 pseudoElement = pseudoElt; 68 } 69 70 74 public String getCssText() { 75 StringBuffer sb = new StringBuffer (); 76 for (int i = 0; i < cssEngine.getNumberOfProperties(); i++) { 77 sb.append(cssEngine.getPropertyName(i)); 78 sb.append(": "); 79 sb.append(cssEngine.getComputedStyle(element, pseudoElement, 80 i).getCssText()); 81 sb.append(";\n"); 82 } 83 return sb.toString(); 84 } 85 86 91 public void setCssText(String cssText) throws DOMException { 92 throw new DOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 93 } 94 95 99 public String getPropertyValue(String propertyName) { 100 int idx = cssEngine.getPropertyIndex(propertyName); 101 if (idx == -1) { 102 return ""; 103 } 104 Value v = cssEngine.getComputedStyle(element, pseudoElement, idx); 105 return v.getCssText(); 106 } 107 108 112 public CSSValue getPropertyCSSValue(String propertyName) { 113 CSSValue result = (CSSValue)values.get(propertyName); 114 if (result == null) { 115 int idx = cssEngine.getPropertyIndex(propertyName); 116 if (idx != -1) { 117 result = createCSSValue(idx); 118 values.put(propertyName, result); 119 } 120 } 121 return result; 122 } 123 124 128 public String removeProperty(String propertyName) throws DOMException { 129 throw new DOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 130 } 131 132 136 public String getPropertyPriority(String propertyName) { 137 return ""; 138 } 139 140 144 public void setProperty(String propertyName, String value, String prio) 145 throws DOMException { 146 throw new DOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 147 } 148 149 153 public int getLength() { 154 return cssEngine.getNumberOfProperties(); 155 } 156 157 161 public String item(int index) { 162 if (index < 0 || index >= cssEngine.getNumberOfProperties()) { 163 return ""; 164 } 165 return cssEngine.getPropertyName(index); 166 } 167 168 173 public CSSRule getParentRule() { 174 return null; 175 } 176 177 180 protected CSSValue createCSSValue(int idx) { 181 return new ComputedCSSValue(idx); 182 } 183 184 187 public class ComputedCSSValue 188 extends CSSOMValue 189 implements CSSOMValue.ValueProvider { 190 191 194 protected int index; 195 196 199 public ComputedCSSValue(int idx) { 200 super(null); 201 valueProvider = this; 202 index = idx; 203 } 204 205 208 public Value getValue() { 209 return cssEngine.getComputedStyle(element, pseudoElement, index); 210 } 211 } 212 } 213 | Popular Tags |