1 18 package org.apache.batik.dom.svg; 19 20 import org.apache.batik.css.engine.CSSEngine; 21 import org.apache.batik.dom.AbstractDocument; 22 import org.apache.batik.dom.util.DOMUtilities; 23 import org.apache.batik.util.SVGConstants; 24 import org.apache.batik.util.XMLConstants; 25 import org.w3c.dom.DOMException ; 26 import org.w3c.dom.Element ; 27 import org.w3c.dom.Node ; 28 import org.w3c.dom.svg.SVGAnimatedEnumeration; 29 import org.w3c.dom.svg.SVGAnimatedInteger; 30 import org.w3c.dom.svg.SVGAnimatedLength; 31 import org.w3c.dom.svg.SVGAnimatedNumber; 32 import org.w3c.dom.svg.SVGAnimatedString; 33 import org.w3c.dom.svg.SVGElement; 34 import org.w3c.dom.svg.SVGException; 35 import org.w3c.dom.svg.SVGFitToViewBox; 36 import org.w3c.dom.svg.SVGSVGElement; 37 38 44 public abstract class SVGOMElement 45 extends AbstractElement 46 implements SVGElement, 47 SVGConstants { 48 49 52 protected transient boolean readonly; 53 54 57 protected String prefix; 58 59 62 protected transient SVGContext svgContext; 63 64 67 protected SVGOMElement() { 68 } 69 70 75 protected SVGOMElement(String prefix, AbstractDocument owner) { 76 super(prefix, owner); 77 } 78 79 82 public String getId() { 83 return getAttributeNS(null, "id"); 84 } 85 86 89 public void setId(String id) { 90 setAttributeNS(null, "id", id); 91 } 92 93 96 public String getXMLbase() { 97 return XMLBaseSupport.getXMLBase(this); 98 } 99 100 103 public void setXMLbase(String xmlbase) throws DOMException { 104 setAttributeNS(XMLConstants.XML_NAMESPACE_URI, "xml:base", xmlbase); 105 } 106 107 110 public SVGSVGElement getOwnerSVGElement() { 111 for (Element e = CSSEngine.getParentCSSStylableElement(this); 112 e != null; 113 e = CSSEngine.getParentCSSStylableElement(e)) { 114 if (e instanceof SVGSVGElement) { 115 return (SVGSVGElement)e; 116 } 117 } 118 return null; 119 } 120 121 124 public SVGElement getViewportElement() { 125 for (Element e = CSSEngine.getParentCSSStylableElement(this); 126 e != null; 127 e = CSSEngine.getParentCSSStylableElement(e)) { 128 if (e instanceof SVGFitToViewBox) { 129 return (SVGElement)e; 130 } 131 } 132 return null; 133 } 134 135 138 public String getNodeName() { 139 if (prefix == null || prefix.equals("")) { 140 return getLocalName(); 141 } 142 String ln = getLocalName(); 143 StringBuffer sb = new StringBuffer (prefix.length() + ln.length() + 1); 144 sb.append(prefix).append(':').append(ln); 145 return sb.toString(); 146 } 147 148 151 public String getNamespaceURI() { 152 return SVGDOMImplementation.SVG_NAMESPACE_URI; 153 } 154 155 158 public void setPrefix(String prefix) throws DOMException { 159 if (isReadonly()) { 160 throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, 161 "readonly.node", 162 new Object [] { new Integer (getNodeType()), 163 getNodeName() }); 164 } 165 if (prefix != null && 166 !prefix.equals("") && 167 !DOMUtilities.isValidName(prefix)) { 168 throw createDOMException(DOMException.INVALID_CHARACTER_ERR, 169 "prefix", 170 new Object [] { new Integer (getNodeType()), 171 getNodeName(), 172 prefix }); 173 } 174 this.prefix = prefix; 175 } 176 177 179 184 public void setSVGContext(SVGContext ctx) { 185 svgContext = ctx; 186 } 187 188 191 public SVGContext getSVGContext() { 192 return svgContext; 193 } 194 195 197 200 public SVGException createSVGException(short type, 201 String key, 202 Object [] args) { 203 try { 204 return new SVGOMException 205 (type, getCurrentDocument().formatMessage(key, args)); 206 } catch (Exception e) { 207 return new SVGOMException(type, key); 208 } 209 } 210 211 214 public boolean isReadonly() { 215 return readonly; 216 } 217 218 221 public void setReadonly(boolean v) { 222 readonly = v; 223 } 224 225 230 protected SVGAnimatedString getAnimatedStringAttribute(String ns, 231 String ln) { 232 SVGAnimatedString result = 233 (SVGAnimatedString)getLiveAttributeValue(ns, ln); 234 if (result == null) { 235 result = new SVGOMAnimatedString(this, ns, ln); 236 putLiveAttributeValue(ns, ln, (LiveAttributeValue)result); 237 } 238 return result; 239 } 240 241 247 protected SVGAnimatedNumber getAnimatedNumberAttribute(String ns, 248 String ln, 249 float val) { 250 SVGAnimatedNumber result = 251 (SVGAnimatedNumber)getLiveAttributeValue(ns, ln); 252 if (result == null) { 253 result = new SVGOMAnimatedNumber(this, ns, ln, val); 254 putLiveAttributeValue(ns, ln, (LiveAttributeValue)result); 255 } 256 return result; 257 } 258 259 265 protected SVGAnimatedInteger getAnimatedIntegerAttribute(String ns, 266 String ln, 267 int val) { 268 SVGAnimatedInteger result = 269 (SVGAnimatedInteger)getLiveAttributeValue(ns, ln); 270 if (result == null) { 271 result = new SVGOMAnimatedInteger(this, ns, ln, val); 272 putLiveAttributeValue(ns, ln, (LiveAttributeValue)result); 273 } 274 return result; 275 } 276 277 284 protected SVGAnimatedEnumeration 285 getAnimatedEnumerationAttribute(String ns, String ln, 286 String [] val, short def) { 287 SVGAnimatedEnumeration result = 288 (SVGAnimatedEnumeration)getLiveAttributeValue(ns, ln); 289 if (result == null) { 290 result = new SVGOMAnimatedEnumeration(this, ns, ln, val, def); 291 putLiveAttributeValue(ns, ln, (LiveAttributeValue)result); 292 } 293 return result; 294 } 295 296 303 protected SVGAnimatedLength getAnimatedLengthAttribute(String ns, 304 String ln, 305 String val, 306 short dir) { 307 SVGAnimatedLength result = 308 (SVGAnimatedLength)getLiveAttributeValue(ns, ln); 309 if (result == null) { 310 result = new SVGOMAnimatedLength(this, ns, ln, val, dir); 311 putLiveAttributeValue(ns, ln, (LiveAttributeValue)result); 312 } 313 return result; 314 } 315 316 318 321 protected Node export(Node n, AbstractDocument d) { 322 super.export(n, d); 323 SVGOMElement e = (SVGOMElement)n; 324 e.prefix = prefix; 325 return n; 326 } 327 328 331 protected Node deepExport(Node n, AbstractDocument d) { 332 super.deepExport(n, d); 333 SVGOMElement e = (SVGOMElement)n; 334 e.prefix = prefix; 335 return n; 336 } 337 338 342 protected Node copyInto(Node n) { 343 super.copyInto(n); 344 SVGOMElement e = (SVGOMElement)n; 345 e.prefix = prefix; 346 return n; 347 } 348 349 353 protected Node deepCopyInto(Node n) { 354 super.deepCopyInto(n); 355 SVGOMElement e = (SVGOMElement)n; 356 e.prefix = prefix; 357 return n; 358 } 359 } 360 | Popular Tags |