KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.Serializable JavaDoc;
21
22 import org.apache.batik.dom.events.DocumentEventSupport;
23 import org.apache.batik.dom.util.HashTable;
24 import org.w3c.dom.DOMImplementation JavaDoc;
25
26 /**
27  * This class implements the {@link org.w3c.dom.DOMImplementation},
28  * {@link org.w3c.dom.css.DOMImplementationCSS} interfaces.
29  *
30  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
31  * @version $Id: AbstractDOMImplementation.java,v 1.13 2005/02/22 09:12:57 cam Exp $
32  */

33
34 public abstract class AbstractDOMImplementation
35     implements DOMImplementation JavaDoc,
36                Serializable JavaDoc {
37
38     /**
39      * The supported features.
40      */

41     protected final HashTable features = new HashTable();
42     {
43     registerFeature("XML", new String JavaDoc[] { "1.0", "2.0" });
44     registerFeature("Events", "2.0");
45     registerFeature("MouseEvents", "2.0");
46     registerFeature("MutationEvents", "2.0");
47     registerFeature("Traversal", "2.0");
48     registerFeature("UIEvents", "2.0");
49     }
50     
51     /**
52      * Registers a DOM feature.
53      */

54     protected void registerFeature(String JavaDoc name, Object JavaDoc value) {
55         features.put(name.toLowerCase(), value);
56     }
57
58     /**
59      * Creates a new AbstractDOMImplementation object.
60      */

61     protected AbstractDOMImplementation() {
62     }
63
64     /**
65      * <b>DOM</b>: Implements {@link
66      * org.w3c.dom.DOMImplementation#hasFeature(String,String)}.
67      */

68     public boolean hasFeature(String JavaDoc feature, String JavaDoc version) {
69     Object JavaDoc v = features.get(feature.toLowerCase());
70     if (v == null) {
71         return false;
72     }
73     if (version == null || version.length() == 0) {
74         return true;
75     }
76         if (v instanceof String JavaDoc) {
77             return version.equals(v);
78         } else {
79             String JavaDoc[] va = (String JavaDoc[])v;
80             for (int i = 0; i < va.length; i++) {
81                 if (version.equals(va[i])) {
82                     return true;
83                 }
84             }
85             return false;
86         }
87     }
88
89     /**
90      * Creates an DocumentEventSupport object suitable for use with this implementation.
91      */

92     public DocumentEventSupport createDocumentEventSupport() {
93         return new DocumentEventSupport();
94     }
95 }
96
Popular Tags