|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
DOMImplementationImpl.java | 21.4% | 22.7% | 57.1% | 27.9% |
|
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. 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 | * $Id: DOMImplementationImpl.java 541508 2007-05-25 01:54:12Z vgritsenko $ | |
18 | */ | |
19 | ||
20 | package org.apache.xindice.xml.dom; | |
21 | ||
22 | import org.w3c.dom.DOMException; | |
23 | import org.w3c.dom.DOMImplementation; | |
24 | import org.w3c.dom.Document; | |
25 | import org.w3c.dom.DocumentType; | |
26 | import org.w3c.dom.Element; | |
27 | ||
28 | /** | |
29 | * DOMImplementationImpl | |
30 | * | |
31 | * @version $Revision: 541508 $, $Date: 2007-05-24 18:54:12 -0700 (Thu, 24 May 2007) $ | |
32 | */ | |
33 | public final class DOMImplementationImpl implements DOMImplementation { | |
34 | ||
35 | private static final String[][] FEATURES = { | |
36 | {"XML", "1.0"}, | |
37 | {"XML", "2.0"}, | |
38 | {"Traversal", "2.0"}, | |
39 | {"Xindice-DB", "1.0"}, // DBNode and DBDocument | |
40 | {"Xindice-Comp", "1.0"} // CompressedNode and CompressedDocument | |
41 | }; | |
42 | ||
43 | private static final DOMImplementation IMPL = new DOMImplementationImpl(); | |
44 | ||
45 | ||
46 | 4 | private DOMImplementationImpl() { |
47 | } | |
48 | ||
49 | 2697 | public static DOMImplementation getInstance() { |
50 | 2697 | return IMPL; |
51 | } | |
52 | ||
53 | 2697 | static boolean HasFeature(String feature, String version) { |
54 | 5394 | for (int i = 0; i < FEATURES.length; i++) { |
55 | 5394 | if (FEATURES[i][0].equals(feature) && FEATURES[i][1].equals(version)) { |
56 | 2697 | return true; |
57 | } | |
58 | } | |
59 | ||
60 | 0 | return false; |
61 | } | |
62 | ||
63 | /** | |
64 | * Test if the DOM implementation implements a specific feature. | |
65 | * @param feature The package name of the feature to test. In Level 1, the | |
66 | * legal values are "HTML" and "XML" (case-insensitive). | |
67 | * @param version This is the version number of the package name to test. | |
68 | * In Level 1, this is the string "1.0". If the version is not specified, | |
69 | * supporting any version of the feature will cause the method to return | |
70 | * <code>true</code>. | |
71 | * @return <code>true</code> if the feature is implemented in the specified | |
72 | * version, <code>false</code> otherwise. | |
73 | */ | |
74 | 2697 | public boolean hasFeature(String feature, String version) { |
75 | 2697 | return HasFeature(feature, version); |
76 | } | |
77 | ||
78 | /** | |
79 | * Creates an empty <code>DocumentType</code> node. Entity declarations | |
80 | * and notations are not made available. Entity reference expansions and | |
81 | * default attribute additions do not occur. It is expected that a | |
82 | * future version of the DOM will provide a way for populating a | |
83 | * <code>DocumentType</code>. | |
84 | * <br>HTML-only DOM implementations do not need to implement this method. | |
85 | * @param qualifiedName The qualified name of the document type to be | |
86 | * created. | |
87 | * @param publicId The external subset public identifier. | |
88 | * @param systemId The external subset system identifier. | |
89 | * @return A new <code>DocumentType</code> node with | |
90 | * <code>Node.ownerDocument</code> set to <code>null</code>. | |
91 | * @exception DOMException | |
92 | * INVALID_CHARACTER_ERR: Raised if the specified qualified name | |
93 | * contains an illegal character. | |
94 | * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is | |
95 | * malformed. | |
96 | * @since DOM Level 2 | |
97 | */ | |
98 | 0 | public DocumentType createDocumentType(String qualifiedName, String publicId, String systemId) throws DOMException { |
99 | 0 | return new DocumentTypeImpl(); |
100 | } | |
101 | ||
102 | /** | |
103 | * Creates an XML <code>Document</code> object of the specified type with | |
104 | * its document element. HTML-only DOM implementations do not need to | |
105 | * implement this method. | |
106 | * @param namespaceURI The namespace URI of the document element to create. | |
107 | * @param qualifiedName The qualified name of the document element to be | |
108 | * created. | |
109 | * @param doctype The type of document to be created or <code>null</code>. | |
110 | * When <code>doctype</code> is not <code>null</code>, its | |
111 | * <code>Node.ownerDocument</code> attribute is set to the document | |
112 | * being created. | |
113 | * @return A new <code>Document</code> object. | |
114 | * @exception DOMException | |
115 | * INVALID_CHARACTER_ERR: Raised if the specified qualified name | |
116 | * contains an illegal character. | |
117 | * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is | |
118 | * malformed, if the <code>qualifiedName</code> has a prefix and the | |
119 | * <code>namespaceURI</code> is <code>null</code>, or if the | |
120 | * <code>qualifiedName</code> has a prefix that is "xml" and the | |
121 | * <code>namespaceURI</code> is different from " | |
122 | * http://www.w3.org/XML/1998/namespace" . | |
123 | * <br>WRONG_DOCUMENT_ERR: Raised if <code>doctype</code> has already | |
124 | * been used with a different document or was created from a different | |
125 | * implementation. | |
126 | * @since DOM Level 2 | |
127 | */ | |
128 | 0 | public Document createDocument(String namespaceURI, String qualifiedName, DocumentType doctype) throws DOMException { |
129 | 0 | DocumentImpl doc = new DocumentImpl(); |
130 | 0 | Element elem = doc.createElement(qualifiedName); |
131 | 0 | doc.appendChild(elem); |
132 | 0 | if (namespaceURI != null) { |
133 | 0 | if (qualifiedName.indexOf(":") != -1) { |
134 | 0 | elem.setAttribute("xmlns:" + qualifiedName.substring(0, qualifiedName.indexOf(":")), namespaceURI); |
135 | } else { | |
136 | 0 | elem.setAttribute("xmlns", namespaceURI); |
137 | } | |
138 | } | |
139 | 0 | if (doctype != null) { |
140 | 0 | if (doctype.getOwnerDocument() != null |
141 | || !(doctype instanceof DocumentTypeImpl)) { | |
142 | 0 | throw NodeImpl.EX_WRONG_DOCUMENT; |
143 | } | |
144 | 0 | doc.setDoctype(doctype); |
145 | } | |
146 | 0 | return doc; |
147 | } | |
148 | ||
149 | /** | |
150 | * @since DOM Level 3 | |
151 | */ | |
152 | 0 | public Object getFeature(String feature, String version) { |
153 | 0 | if (hasFeature(feature, version)) { |
154 | 0 | return this; |
155 | } | |
156 | ||
157 | 0 | return null; |
158 | } | |
159 | } | |
160 |
|