KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2001-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 package org.apache.batik.dom.svg;
19
20 import java.net.MalformedURLException JavaDoc;
21 import java.net.URL JavaDoc;
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 JavaDoc;
31 import org.w3c.dom.Node JavaDoc;
32
33 /**
34  * This class provides an implementation of the 'xml-stylesheet' processing
35  * instructions.
36  *
37  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
38  * @version $Id: SVGStyleSheetProcessingInstruction.java,v 1.8 2004/08/18 07:13:18 vhardy Exp $
39  */

40 public class SVGStyleSheetProcessingInstruction
41     extends StyleSheetProcessingInstruction
42     implements CSSStyleSheetNode {
43     
44     /**
45      * The style-sheet.
46      */

47     protected StyleSheet styleSheet;
48
49     /**
50      * Creates a new ProcessingInstruction object.
51      */

52     protected SVGStyleSheetProcessingInstruction() {
53     }
54
55     /**
56      * Creates a new ProcessingInstruction object.
57      */

58     public SVGStyleSheetProcessingInstruction(String JavaDoc data,
59                                               AbstractDocument owner,
60                                               StyleSheetFactory f) {
61         super(data, owner, f);
62     }
63
64     /**
65      * Returns the URI of the referenced stylesheet.
66      */

67     public String JavaDoc getStyleSheetURI() {
68         SVGOMDocument svgDoc;
69         svgDoc = (SVGOMDocument)getOwnerDocument();
70         URL JavaDoc url = svgDoc.getURLObject();
71         String JavaDoc href = (String JavaDoc)getPseudoAttributes().get("href");
72         if (url != null) {
73             try {
74                 return new URL JavaDoc(url, href).toString();
75             } catch (MalformedURLException JavaDoc e) {
76             }
77         }
78         return href;
79     }
80
81     /**
82      * Returns the associated style-sheet.
83      */

84     public StyleSheet getCSSStyleSheet() {
85         if (styleSheet == null) {
86             HashTable attrs = getPseudoAttributes();
87             String JavaDoc type = (String JavaDoc)attrs.get("type");
88
89             if ("text/css".equals(type)) {
90                 String JavaDoc title = (String JavaDoc)attrs.get("title");
91                 String JavaDoc media = (String JavaDoc)attrs.get("media");
92                 String JavaDoc href = (String JavaDoc)attrs.get("href");
93                 String JavaDoc alternate = (String JavaDoc)attrs.get("alternate");
94                 SVGOMDocument doc = (SVGOMDocument)getOwnerDocument();
95                 URL JavaDoc durl = doc.getURLObject();
96                 URL JavaDoc burl = durl;
97                 try {
98                     burl = new URL JavaDoc(durl, href);
99                 } catch (Exception JavaDoc 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     /**
113      * <b>DOM</b>: Implements {@link
114      * org.w3c.dom.ProcessingInstruction#setData(String)}.
115      */

116     public void setData(String JavaDoc data) throws DOMException JavaDoc {
117     super.setData(data);
118         styleSheet = null;
119     }
120
121     /**
122      * Returns a new uninitialized instance of this object's class.
123      */

124     protected Node newNode() {
125         return new SVGStyleSheetProcessingInstruction();
126     }
127 }
128
Popular Tags