1 18 package org.apache.batik.dom.svg; 19 20 import java.net.MalformedURLException ; 21 import java.net.URL ; 22 23 import org.apache.batik.css.engine.CSSEngine; 24 import org.apache.batik.css.engine.CSSStyleSheetNode; 25 import org.apache.batik.css.engine.StyleSheet; 26 import org.apache.batik.dom.AbstractDocument; 27 import org.apache.batik.dom.StyleSheetFactory; 28 import org.apache.batik.dom.StyleSheetProcessingInstruction; 29 import org.apache.batik.dom.util.HashTable; 30 import org.w3c.dom.DOMException ; 31 import org.w3c.dom.Node ; 32 33 40 public class SVGStyleSheetProcessingInstruction 41 extends StyleSheetProcessingInstruction 42 implements CSSStyleSheetNode { 43 44 47 protected StyleSheet styleSheet; 48 49 52 protected SVGStyleSheetProcessingInstruction() { 53 } 54 55 58 public SVGStyleSheetProcessingInstruction(String data, 59 AbstractDocument owner, 60 StyleSheetFactory f) { 61 super(data, owner, f); 62 } 63 64 67 public String getStyleSheetURI() { 68 SVGOMDocument svgDoc; 69 svgDoc = (SVGOMDocument)getOwnerDocument(); 70 URL url = svgDoc.getURLObject(); 71 String href = (String )getPseudoAttributes().get("href"); 72 if (url != null) { 73 try { 74 return new URL (url, href).toString(); 75 } catch (MalformedURLException e) { 76 } 77 } 78 return href; 79 } 80 81 84 public StyleSheet getCSSStyleSheet() { 85 if (styleSheet == null) { 86 HashTable attrs = getPseudoAttributes(); 87 String type = (String )attrs.get("type"); 88 89 if ("text/css".equals(type)) { 90 String title = (String )attrs.get("title"); 91 String media = (String )attrs.get("media"); 92 String href = (String )attrs.get("href"); 93 String alternate = (String )attrs.get("alternate"); 94 SVGOMDocument doc = (SVGOMDocument)getOwnerDocument(); 95 URL durl = doc.getURLObject(); 96 URL burl = durl; 97 try { 98 burl = new URL (durl, href); 99 } catch (Exception ex) { 100 } 101 CSSEngine e = doc.getCSSEngine(); 102 103 styleSheet = e.parseStyleSheet 104 (burl, media); 105 styleSheet.setAlternate("yes".equals(alternate)); 106 styleSheet.setTitle(title); 107 } 108 } 109 return styleSheet; 110 } 111 112 116 public void setData(String data) throws DOMException { 117 super.setData(data); 118 styleSheet = null; 119 } 120 121 124 protected Node newNode() { 125 return new SVGStyleSheetProcessingInstruction(); 126 } 127 } 128 | Popular Tags |