KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > dom > StyleSheetProcessingInstruction


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;
20
21 import org.apache.batik.dom.util.DOMUtilities;
22 import org.apache.batik.dom.util.HashTable;
23 import org.w3c.dom.DOMException JavaDoc;
24 import org.w3c.dom.Node JavaDoc;
25 import org.w3c.dom.stylesheets.LinkStyle;
26 import org.w3c.dom.stylesheets.StyleSheet;
27
28 /**
29  * This class provides an implementation of the 'xml-stylesheet' processing
30  * instructions.
31  *
32  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
33  * @version $Id: StyleSheetProcessingInstruction.java,v 1.8 2004/10/30 18:38:04 deweese Exp $
34  */

35 public class StyleSheetProcessingInstruction
36     extends AbstractProcessingInstruction
37     implements LinkStyle {
38
39     /**
40      * Is this node immutable?
41      */

42     protected boolean readonly;
43
44     /**
45      * The style sheet.
46      */

47     protected transient StyleSheet sheet;
48
49     /**
50      * The stylesheet factory.
51      */

52     protected StyleSheetFactory factory;
53
54     /**
55      * The pseudo attributes.
56      */

57     protected transient HashTable pseudoAttributes;
58
59     /**
60      * Creates a new ProcessingInstruction object.
61      */

62     protected StyleSheetProcessingInstruction() {
63     }
64
65     /**
66      * Creates a new ProcessingInstruction object.
67      */

68     public StyleSheetProcessingInstruction(String JavaDoc data,
69                        AbstractDocument owner,
70                        StyleSheetFactory f) {
71     ownerDocument = owner;
72     setData(data);
73     factory = f;
74     }
75
76     /**
77      * Tests whether this node is readonly.
78      */

79     public boolean isReadonly() {
80     return readonly;
81     }
82
83     /**
84      * Sets this node readonly attribute.
85      */

86     public void setReadonly(boolean v) {
87     readonly = v;
88     }
89
90     /**
91      * Sets the node name.
92      */

93     public void setNodeName(String JavaDoc v) {
94     }
95
96     /**
97      * <b>DOM</b>: Implements {@link
98      * org.w3c.dom.ProcessingInstruction#getTarget()}.
99      * @return "xml-stylesheet".
100      */

101     public String JavaDoc getTarget() {
102     return "xml-stylesheet";
103     }
104
105     /**
106      * The style sheet.
107      */

108     public StyleSheet getSheet() {
109     if (sheet == null) {
110         sheet = factory.createStyleSheet(this, getPseudoAttributes());
111     }
112     return sheet;
113     }
114
115     /**
116      * Returns the pseudo attributes in a table.
117      */

118     public HashTable getPseudoAttributes() {
119         if (pseudoAttributes == null) {
120             pseudoAttributes = new HashTable();
121             pseudoAttributes.put("alternate", "no");
122             pseudoAttributes.put("media", "all");
123             DOMUtilities.parseStyleSheetPIData(data, pseudoAttributes);
124         }
125         return pseudoAttributes;
126     }
127
128     /**
129      * <b>DOM</b>: Implements {@link
130      * org.w3c.dom.ProcessingInstruction#setData(String)}.
131      */

132     public void setData(String JavaDoc data) throws DOMException JavaDoc {
133     super.setData(data);
134     sheet = null;
135         pseudoAttributes = null;
136     }
137
138     /**
139      * Returns a new uninitialized instance of this object's class.
140      */

141     protected Node JavaDoc newNode() {
142         return new StyleSheetProcessingInstruction();
143     }
144 }
145
Popular Tags