KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2000,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;
19
20 import org.w3c.dom.Attr JavaDoc;
21 import org.w3c.dom.CDATASection JavaDoc;
22 import org.w3c.dom.Comment JavaDoc;
23 import org.w3c.dom.DOMException JavaDoc;
24 import org.w3c.dom.DOMImplementation JavaDoc;
25 import org.w3c.dom.DocumentFragment JavaDoc;
26 import org.w3c.dom.DocumentType JavaDoc;
27 import org.w3c.dom.Element JavaDoc;
28 import org.w3c.dom.EntityReference JavaDoc;
29 import org.w3c.dom.Node JavaDoc;
30 import org.w3c.dom.ProcessingInstruction JavaDoc;
31 import org.w3c.dom.Text JavaDoc;
32
33 /**
34  * This class implements the {@link org.w3c.dom.Document},
35  * {@link org.w3c.dom.events.DocumentEvent}.
36  *
37  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
38  * @version $Id: GenericDocument.java,v 1.11 2005/03/03 01:19:53 deweese Exp $
39  */

40 public class GenericDocument
41     extends AbstractDocument {
42
43     /** Local name for 'id' attributes. */
44     protected final static String JavaDoc ATTR_ID = "id";
45
46     /**
47      * Is this document immutable?
48      */

49     protected boolean readonly;
50
51     /**
52      * Creates a new uninitialized document.
53      */

54     protected GenericDocument() {
55     }
56
57     /**
58      * Creates a new uninitialized document.
59      */

60     public GenericDocument(DocumentType JavaDoc dt, DOMImplementation JavaDoc impl) {
61         super(dt, impl);
62     }
63
64     /**
65      * Tests whether this node is readonly.
66      */

67     public boolean isReadonly() {
68         return readonly;
69     }
70
71     /**
72      * Sets this node readonly attribute.
73      */

74     public void setReadonly(boolean v) {
75         readonly = v;
76     }
77
78     /**
79      * Returns true if the given Attr node represents an 'id'
80      * for this document.
81      */

82     public boolean isId(Attr JavaDoc node) {
83         if (node.getNamespaceURI() != null) return false;
84         return ATTR_ID.equals(node.getNodeName());
85     }
86
87     /**
88      * <b>DOM</b>: Implements {@link
89      * org.w3c.dom.Document#createElement(String)}.
90      */

91     public Element JavaDoc createElement(String JavaDoc tagName) throws DOMException JavaDoc {
92         return new GenericElement(tagName.intern(), this);
93     }
94
95     /**
96      * <b>DOM</b>: Implements {@link
97      * org.w3c.dom.Document#createDocumentFragment()}.
98      */

99     public DocumentFragment JavaDoc createDocumentFragment() {
100         return new GenericDocumentFragment(this);
101     }
102
103     /**
104      * <b>DOM</b>: Implements {@link
105      * org.w3c.dom.Document#createTextNode(String)}.
106      */

107     public Text JavaDoc createTextNode(String JavaDoc data) {
108         return new GenericText(data, this);
109     }
110
111     /**
112      * <b>DOM</b>: Implements {@link
113      * org.w3c.dom.Document#createComment(String)}.
114      */

115     public Comment JavaDoc createComment(String JavaDoc data) {
116         return new GenericComment(data, this);
117     }
118
119     /**
120      * <b>DOM</b>: Implements {@link
121      * org.w3c.dom.Document#createCDATASection(String)}.
122      */

123     public CDATASection JavaDoc createCDATASection(String JavaDoc data) throws DOMException JavaDoc {
124         return new GenericCDATASection(data, this);
125     }
126
127     /**
128      * <b>DOM</b>: Implements {@link
129      * org.w3c.dom.Document#createProcessingInstruction(String,String)}.
130      * @return a {@link StyleSheetProcessingInstruction} if target is
131      * "xml-stylesheet" or a GenericProcessingInstruction otherwise.
132      */

133     public ProcessingInstruction JavaDoc createProcessingInstruction(String JavaDoc target,
134                                                              String JavaDoc data)
135         throws DOMException JavaDoc {
136         return new GenericProcessingInstruction(target, data, this);
137     }
138
139     /**
140      * <b>DOM</b>: Implements {@link
141      * org.w3c.dom.Document#createAttribute(String)}.
142      */

143     public Attr JavaDoc createAttribute(String JavaDoc name) throws DOMException JavaDoc {
144         return new GenericAttr(name.intern(), this);
145     }
146
147     /**
148      * <b>DOM</b>: Implements {@link
149      * org.w3c.dom.Document#createEntityReference(String)}.
150      */

151     public EntityReference JavaDoc createEntityReference(String JavaDoc name)
152         throws DOMException JavaDoc {
153         return new GenericEntityReference(name, this);
154     }
155
156     /**
157      * <b>DOM</b>: Implements {@link
158      * org.w3c.dom.Document#createElementNS(String,String)}.
159      */

160     public Element JavaDoc createElementNS(String JavaDoc namespaceURI, String JavaDoc qualifiedName)
161         throws DOMException JavaDoc {
162         if (namespaceURI == null) {
163             return new GenericElement(qualifiedName.intern(), this);
164         } else {
165             return new GenericElementNS(namespaceURI.intern(),
166                                         qualifiedName.intern(),
167                                         this);
168         }
169     }
170
171     /**
172      * <b>DOM</b>: Implements {@link
173      * org.w3c.dom.Document#createAttributeNS(String,String)}.
174      */

175     public Attr JavaDoc createAttributeNS(String JavaDoc namespaceURI, String JavaDoc qualifiedName)
176         throws DOMException JavaDoc {
177         if (namespaceURI == null) {
178             return new GenericAttr(qualifiedName.intern(), this);
179         } else {
180             return new GenericAttrNS(namespaceURI.intern(),
181                                      qualifiedName.intern(),
182                                      this);
183         }
184     }
185
186     /**
187      * Returns a new uninitialized instance of this object's class.
188      */

189     protected Node JavaDoc newNode() {
190         return new GenericDocument();
191     }
192 }
193
Popular Tags