KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > dom > svg > XMLBaseSupport


1 /*
2
3    Copyright 1999-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17 */

18
19 package org.apache.batik.dom.svg;
20
21 import java.net.URL JavaDoc;
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 JavaDoc;
27 import org.w3c.dom.Element JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
29
30 /**
31  * This class provides support for the xml:base attribute.
32  *
33  * @author <a HREF="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
34  * @version $Id: XMLBaseSupport.java,v 1.6 2004/10/30 18:38:04 deweese Exp $
35  */

36 public class XMLBaseSupport implements XMLConstants {
37     
38     /**
39      * This class does not need to be instanciated.
40      */

41     protected XMLBaseSupport() {
42     }
43
44     /**
45      * Returns the xml:base attribute value of the given element.
46      */

47     public static String JavaDoc getXMLBase(Element JavaDoc elt) {
48         return elt.getAttributeNS(XML_NAMESPACE_URI, "base");
49     }
50
51     /**
52      * Returns the xml:base attribute value of the given element
53      * Resolving any dependency on parent bases if needed.
54      */

55     public static String JavaDoc getCascadedXMLBase(Element JavaDoc elt) {
56         String JavaDoc base = null;
57         Node JavaDoc n = elt.getParentNode();
58         while (n != null) {
59             if (n.getNodeType() == Node.ELEMENT_NODE) {
60                 base = getCascadedXMLBase((Element JavaDoc)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 JavaDoc url = svgDoc.getURLObject();
73             if (url != null) {
74                 base = url.toString();
75             }
76         }
77         Attr JavaDoc 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