KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > dom > svg12 > SVG12DOMImplementation


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.svg12;
19
20 import java.net.URL JavaDoc;
21
22 import org.apache.batik.css.engine.CSSContext;
23 import org.apache.batik.css.engine.CSSEngine;
24 import org.apache.batik.css.engine.SVG12CSSEngine;
25 import org.apache.batik.css.engine.value.ShorthandManager;
26 import org.apache.batik.css.engine.value.ValueManager;
27 import org.apache.batik.css.parser.ExtendedParser;
28 import org.apache.batik.dom.AbstractDocument;
29 import org.apache.batik.dom.AbstractStylableDocument;
30 import org.apache.batik.dom.GenericElement;
31 import org.apache.batik.dom.GenericElementNS;
32 import org.apache.batik.dom.svg.SVGDOMImplementation;
33 import org.apache.batik.dom.svg.SVGOMDocument;
34 import org.apache.batik.dom.util.HashTable;
35 import org.apache.batik.dom.util.DOMUtilities;
36 import org.apache.batik.util.SVG12Constants;
37
38
39 import org.w3c.css.sac.InputSource;
40 import org.w3c.dom.Document JavaDoc;
41 import org.w3c.dom.DocumentType JavaDoc;
42 import org.w3c.dom.DOMImplementation JavaDoc;
43 import org.w3c.dom.DOMException JavaDoc;
44 import org.w3c.dom.Element JavaDoc;
45
46 /**
47  * This class implements the {@link DOMImplementation} interface.
48  * It provides support the SVG 1.2 documents.
49  *
50  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
51  * @version $Id: SVG12DOMImplementation.java,v 1.3 2005/02/22 09:13:02 cam Exp $
52  */

53 public class SVG12DOMImplementation
54     extends SVGDOMImplementation {
55     
56     /**
57      * Creates a new SVGDOMImplementation object.
58      */

59     public SVG12DOMImplementation() {
60         factories = svg12Factories;
61         registerFeature("CSS", "2.0");
62         registerFeature("StyleSheets", "2.0");
63         registerFeature("SVG", new String JavaDoc[] {"1.0", "1.1", "1.2"});
64         registerFeature("SVGEvents", new String JavaDoc[] {"1.0", "1.1", "1.2"});
65     }
66
67     public CSSEngine createCSSEngine(AbstractStylableDocument doc,
68                                      CSSContext ctx,
69                                      ExtendedParser ep,
70                                      ValueManager [] vms,
71                                      ShorthandManager [] sms) {
72         URL JavaDoc durl = ((SVGOMDocument)doc).getURLObject();
73         CSSEngine result = new SVG12CSSEngine(doc, durl, ep, vms, sms, ctx);
74
75         URL JavaDoc url = getClass().getResource("resources/UserAgentStyleSheet.css");
76         if (url != null) {
77             InputSource is = new InputSource(url.toString());
78             result.setUserAgentStyleSheet
79                 (result.parseStyleSheet(is, url, "all"));
80         }
81
82         return result;
83     }
84
85     /**
86      * <b>DOM</b>: Implements {@link
87      * DOMImplementation#createDocument(String,String,DocumentType)}.
88      */

89     public Document createDocument(String JavaDoc namespaceURI,
90                                    String JavaDoc qualifiedName,
91                                    DocumentType JavaDoc doctype)
92         throws DOMException JavaDoc {
93         Document result = new SVGOMDocument(doctype, this);
94         // BUG 32108: return empty document if qualifiedName is null.
95
if (qualifiedName != null)
96             result.appendChild(result.createElementNS(namespaceURI,
97                                                       qualifiedName));
98         return result;
99     }
100
101     /**
102      * Implements the behavior of Document.createElementNS() for this
103      * DOM implementation.
104      */

105     public Element createElementNS(AbstractDocument document,
106                                    String JavaDoc namespaceURI,
107                                    String JavaDoc qualifiedName) {
108         if (namespaceURI == null)
109             return new GenericElement(qualifiedName.intern(), document);
110
111         if (SVG12Constants.SVG_NAMESPACE_URI.equals(namespaceURI)) {
112             String JavaDoc name = DOMUtilities.getLocalName(qualifiedName);
113             ElementFactory ef = (ElementFactory)factories.get(name);
114             if (ef != null)
115                 return ef.create(DOMUtilities.getPrefix(qualifiedName),
116                                  document);
117         }
118         return new GenericElementNS(namespaceURI.intern(),
119                                     qualifiedName.intern(),
120                                     document);
121     }
122
123     // The element factories /////////////////////////////////////////////////
124

125     /**
126      * The SVG element factories.
127      */

128     protected static HashTable svg12Factories = new HashTable(svg11Factories);
129
130     static {
131         svg12Factories.put(SVG12Constants.SVG_FLOW_DIV_TAG,
132                            new FlowDivElementFactory());
133
134         svg12Factories.put(SVG12Constants.SVG_FLOW_LINE_TAG,
135                            new FlowLineElementFactory());
136
137         svg12Factories.put(SVG12Constants.SVG_FLOW_PARA_TAG,
138                            new FlowParaElementFactory());
139
140         svg12Factories.put(SVG12Constants.SVG_FLOW_REGION_BREAK_TAG,
141                            new FlowRegionBreakElementFactory());
142
143         svg12Factories.put(SVG12Constants.SVG_FLOW_REGION_TAG,
144                            new FlowRegionElementFactory());
145
146         svg12Factories.put(SVG12Constants.SVG_FLOW_REGION_EXCLUDE_TAG,
147                            new FlowRegionExcludeElementFactory());
148
149         svg12Factories.put(SVG12Constants.SVG_FLOW_ROOT_TAG,
150                            new FlowRootElementFactory());
151
152         svg12Factories.put(SVG12Constants.SVG_FLOW_SPAN_TAG,
153                            new FlowSpanElementFactory());
154
155         svg12Factories.put(SVG12Constants.SVG_MULTI_IMAGE_TAG,
156                            new MultiImageElementFactory());
157
158         svg12Factories.put(SVG12Constants.SVG_SOLID_COLOR_TAG,
159                            new SolidColorElementFactory());
160
161         svg12Factories.put(SVG12Constants.SVG_SUB_IMAGE_TAG,
162                            new SubImageElementFactory());
163
164         svg12Factories.put(SVG12Constants.SVG_SUB_IMAGE_REF_TAG,
165                            new SubImageRefElementFactory());
166
167     }
168
169     /**
170      * To create a 'flowDiv' element.
171      */

172     protected static class FlowDivElementFactory
173         implements ElementFactory {
174         public FlowDivElementFactory() {
175         }
176         /**
177          * Creates an instance of the associated element type.
178          */

179         public Element create(String JavaDoc prefix, Document doc) {
180             return new SVGOMFlowDivElement(prefix, (AbstractDocument)doc);
181         }
182     }
183
184     /**
185      * To create a 'flowLine' element.
186      */

187     protected static class FlowLineElementFactory
188         implements ElementFactory {
189         public FlowLineElementFactory() {
190         }
191         /**
192          * Creates an instance of the associated element type.
193          */

194         public Element create(String JavaDoc prefix, Document doc) {
195             return new SVGOMFlowLineElement(prefix, (AbstractDocument)doc);
196         }
197     }
198
199     /**
200      * To create a 'flowPara' element.
201      */

202     protected static class FlowParaElementFactory
203         implements ElementFactory {
204         public FlowParaElementFactory() {
205         }
206         /**
207          * Creates an instance of the associated element type.
208          */

209         public Element create(String JavaDoc prefix, Document doc) {
210             return new SVGOMFlowParaElement(prefix, (AbstractDocument)doc);
211         }
212     }
213
214     /**
215      * To create a 'flowRegionBreak' element.
216      */

217     protected static class FlowRegionBreakElementFactory
218         implements ElementFactory {
219         public FlowRegionBreakElementFactory() {
220         }
221         /**
222          * Creates an instance of the associated element type.
223          */

224         public Element create(String JavaDoc prefix, Document doc) {
225             return new SVGOMFlowRegionBreakElement(prefix, (AbstractDocument)doc);
226         }
227     }
228
229     /**
230      * To create a 'flowRegion' element.
231      */

232     protected static class FlowRegionElementFactory
233         implements ElementFactory {
234         public FlowRegionElementFactory() {
235         }
236         /**
237          * Creates an instance of the associated element type.
238          */

239         public Element create(String JavaDoc prefix, Document doc) {
240             return new SVGOMFlowRegionElement(prefix, (AbstractDocument)doc);
241         }
242     }
243
244     /**
245      * To create a 'flowRegion' element.
246      */

247     protected static class FlowRegionExcludeElementFactory
248         implements ElementFactory {
249         public FlowRegionExcludeElementFactory() {
250         }
251         /**
252          * Creates an instance of the associated element type.
253          */

254         public Element create(String JavaDoc prefix, Document doc) {
255             return new SVGOMFlowRegionExcludeElement(prefix, (AbstractDocument)doc);
256         }
257     }
258
259     /**
260      * To create a 'flowRoot' element.
261      */

262     protected static class FlowRootElementFactory
263         implements ElementFactory {
264         public FlowRootElementFactory() {
265         }
266         /**
267          * Creates an instance of the associated element type.
268          */

269         public Element create(String JavaDoc prefix, Document doc) {
270             return new SVGOMFlowRootElement(prefix, (AbstractDocument)doc);
271         }
272     }
273
274     /**
275      * To create a 'flowSpan' element.
276      */

277     protected static class FlowSpanElementFactory
278         implements ElementFactory {
279         public FlowSpanElementFactory() {
280         }
281         /**
282          * Creates an instance of the associated element type.
283          */

284         public Element create(String JavaDoc prefix, Document doc) {
285             return new SVGOMFlowSpanElement(prefix, (AbstractDocument)doc);
286         }
287     }
288     /**
289      * To create a 'multiImage' element.
290      */

291     protected static class MultiImageElementFactory
292         implements ElementFactory {
293         public MultiImageElementFactory() {}
294         /**
295          * Creates an instance of the associated element type.
296          */

297         public Element create(String JavaDoc prefix, Document doc) {
298             return new SVGOMMultiImageElement
299                 (prefix, (AbstractDocument)doc);
300         }
301     }
302
303     /**
304      * To create a 'solidColor' element.
305      */

306     protected static class SolidColorElementFactory
307         implements ElementFactory {
308         public SolidColorElementFactory() {
309         }
310         /**
311          * Creates an instance of the associated element type.
312          */

313         public Element create(String JavaDoc prefix, Document doc) {
314             return new SVGOMSolidColorElement(prefix, (AbstractDocument)doc);
315         }
316     }
317
318     /**
319      * To create a 'subImage' element.
320      */

321     protected static class SubImageElementFactory
322         implements ElementFactory {
323         public SubImageElementFactory() {}
324         /**
325          * Creates an instance of the associated element type.
326          */

327         public Element create(String JavaDoc prefix, Document doc) {
328             return new SVGOMSubImageElement(prefix, (AbstractDocument)doc);
329         }
330     }
331
332     /**
333      * To create a 'SubImageRef' element.
334      */

335     protected static class SubImageRefElementFactory
336         implements ElementFactory {
337         public SubImageRefElementFactory() {}
338         /**
339          * Creates an instance of the associated element type.
340          */

341         public Element create(String JavaDoc prefix, Document doc) {
342             return new SVGOMSubImageRefElement(prefix, (AbstractDocument)doc);
343         }
344     }
345
346     /**
347      * The default instance of this class.
348      */

349     protected final static DOMImplementation DOM_IMPLEMENTATION =
350         new SVG12DOMImplementation();
351
352     /**
353      * Returns the default instance of this class.
354      */

355     public static DOMImplementation getDOMImplementation() {
356         return DOM_IMPLEMENTATION;
357     }
358 }
359
Popular Tags