1 18 19 package org.apache.batik.dom.svg; 20 21 import java.net.URL ; 22 23 import org.apache.batik.css.engine.CSSImportedElementRoot; 24 import org.apache.batik.util.ParsedURL; 25 import org.apache.batik.util.XMLConstants; 26 import org.w3c.dom.Attr ; 27 import org.w3c.dom.Element ; 28 import org.w3c.dom.Node ; 29 30 36 public class XMLBaseSupport implements XMLConstants { 37 38 41 protected XMLBaseSupport() { 42 } 43 44 47 public static String getXMLBase(Element elt) { 48 return elt.getAttributeNS(XML_NAMESPACE_URI, "base"); 49 } 50 51 55 public static String getCascadedXMLBase(Element elt) { 56 String base = null; 57 Node n = elt.getParentNode(); 58 while (n != null) { 59 if (n.getNodeType() == Node.ELEMENT_NODE) { 60 base = getCascadedXMLBase((Element )n); 61 break; 62 } 63 if (n instanceof CSSImportedElementRoot) { 64 n = ((CSSImportedElementRoot)n).getCSSParentElement(); 65 } else { 66 n = n.getParentNode(); 67 } 68 } 69 if (base == null) { 70 SVGOMDocument svgDoc; 71 svgDoc = (SVGOMDocument)elt.getOwnerDocument(); 72 URL url = svgDoc.getURLObject(); 73 if (url != null) { 74 base = url.toString(); 75 } 76 } 77 Attr attr = elt.getAttributeNodeNS(XML_NAMESPACE_URI, "base"); 78 if (attr != null) { 79 if (base == null) { 80 base = attr.getNodeValue(); 81 } else { 82 base = new ParsedURL(base, attr.getNodeValue()).toString(); 83 } 84 } 85 return base; 86 } 87 88 } 89 | Popular Tags |