|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DocumentTypeImpl.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 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: DocumentTypeImpl.java 541508 2007-05-25 01:54:12Z vgritsenko $ | |
| 18 | */ | |
| 19 | ||
| 20 | package org.apache.xindice.xml.dom; | |
| 21 | ||
| 22 | import org.apache.xindice.util.StringUtilities; | |
| 23 | ||
| 24 | import org.w3c.dom.DocumentType; | |
| 25 | import org.w3c.dom.NamedNodeMap; | |
| 26 | import org.w3c.dom.Node; | |
| 27 | ||
| 28 | /** | |
| 29 | * DocumentTypeImpl | |
| 30 | * | |
| 31 | * @version $Revision: 541508 $, $Date: 2007-05-24 18:54:12 -0700 (Thu, 24 May 2007) $ | |
| 32 | */ | |
| 33 | public final class DocumentTypeImpl extends NodeImpl | |
| 34 | implements DocumentType { | |
| 35 | ||
| 36 | 0 | public DocumentTypeImpl() { |
| 37 | 0 | super(null, true); |
| 38 | } | |
| 39 | ||
| 40 | 0 | public short getNodeType() { |
| 41 | 0 | return Node.DOCUMENT_TYPE_NODE; |
| 42 | } | |
| 43 | ||
| 44 | /** | |
| 45 | * The name of DTD; i.e., the name immediately following the | |
| 46 | * <code>DOCTYPE</code> keyword. | |
| 47 | */ | |
| 48 | 0 | public String getName() { |
| 49 | 0 | return nodeName; |
| 50 | } | |
| 51 | ||
| 52 | /** | |
| 53 | * A <code>NamedNodeMap</code> containing the general entities, both | |
| 54 | * external and internal, declared in the DTD. Duplicates are discarded. | |
| 55 | * For example in:<!DOCTYPE ex SYSTEM "ex.dtd" [ <!ENTITY foo | |
| 56 | * "foo"> <!ENTITY bar "bar"> <!ENTITY % baz "baz">]> | |
| 57 | * <ex/> the interface provides access to <code>foo</code> and | |
| 58 | * <code>bar</code> but not <code>baz</code>. Every node in this map also | |
| 59 | * implements the <code>Entity</code> interface. | |
| 60 | * <br>The DOM Level 1 does not support editing entities, therefore | |
| 61 | * <code>entities</code> cannot be altered in any way. | |
| 62 | */ | |
| 63 | 0 | public NamedNodeMap getEntities() { |
| 64 | 0 | return null; |
| 65 | } | |
| 66 | ||
| 67 | /** | |
| 68 | * A <code>NamedNodeMap</code> containing the notations declared in the | |
| 69 | * DTD. Duplicates are discarded. Every node in this map also implements | |
| 70 | * the <code>Notation</code> interface. | |
| 71 | * <br>The DOM Level 1 does not support editing notations, therefore | |
| 72 | * <code>notations</code> cannot be altered in any way. | |
| 73 | */ | |
| 74 | 0 | public NamedNodeMap getNotations() { |
| 75 | 0 | return null; |
| 76 | } | |
| 77 | ||
| 78 | /** | |
| 79 | * The public identifier of the external subset. | |
| 80 | * @since DOM Level 2 | |
| 81 | */ | |
| 82 | 0 | public String getPublicId() { |
| 83 | 0 | return null; |
| 84 | } | |
| 85 | ||
| 86 | /** | |
| 87 | * The system identifier of the external subset. | |
| 88 | * @since DOM Level 2 | |
| 89 | */ | |
| 90 | 0 | public String getSystemId() { |
| 91 | 0 | return null; |
| 92 | } | |
| 93 | ||
| 94 | /** | |
| 95 | * The internal subset as a string.The actual content returned depends on | |
| 96 | * how much information is available to the implementation. This may | |
| 97 | * vary depending on various parameters, including the XML processor | |
| 98 | * used to build the document. | |
| 99 | * @since DOM Level 2 | |
| 100 | */ | |
| 101 | 0 | public String getInternalSubset() { |
| 102 | 0 | return null; |
| 103 | } | |
| 104 | ||
| 105 | // | |
| 106 | // DOM Level 3 Implementation | |
| 107 | // | |
| 108 | ||
| 109 | /** | |
| 110 | * @since DOM Level 3 | |
| 111 | */ | |
| 112 | 0 | public String getTextContent() { |
| 113 | 0 | return null; |
| 114 | } | |
| 115 | ||
| 116 | /** | |
| 117 | * Tests whether two nodes are equal. | |
| 118 | * This method tests for equality of nodes, not sameness (i.e., whether | |
| 119 | * the two nodes are references to the same object) which can be tested with | |
| 120 | * <code>Node.isSameNode()</code>. All nodes that are the same will also be | |
| 121 | * equal, though the reverse may not be true. | |
| 122 | * <br> | |
| 123 | * Two nodes are equal if and only if the following conditions are satisfied: | |
| 124 | * <ul><li>The two nodes are of the same type.</li> | |
| 125 | * <li>The following string attributes are equal: nodeName, localName, | |
| 126 | * namespaceURI, prefix, nodeValue. This is: they are both null, or they have | |
| 127 | * the same length and are character for character identical.</li> | |
| 128 | * <li>The attributes <code>NamedNodeMaps</code> are equal. This is: they are both null, | |
| 129 | * or they have the same length and for each node that exists in one map there | |
| 130 | * is a node that exists in the other map and is equal, although not | |
| 131 | * necessarily at the same index.</li> | |
| 132 | * <li>The childNodes NodeLists are equal. This is: they are both null, or they | |
| 133 | * have the same length and contain equal nodes at the same index. Note that | |
| 134 | * normalization can affect equality; to avoid this, nodes should be normalized | |
| 135 | * before being compared.</li></ul> | |
| 136 | * <br> | |
| 137 | * For two DocumentType nodes to be equal, the following conditions must also | |
| 138 | * be satisfied: | |
| 139 | * <ul><li>The following string attributes are equal: publicId, systemId, | |
| 140 | * internalSubset.</li> | |
| 141 | * <li>The entities <code>NamedNodeMaps</code> are equal.</li> | |
| 142 | * <li>The notations <code>NamedNodeMaps</code> are equal.</li></ul> | |
| 143 | * <br> | |
| 144 | * On the other hand, the following do not affect equality: the ownerDocument, | |
| 145 | * baseURI, and parentNode attributes, the specified attribute for Attr nodes, | |
| 146 | * the schemaTypeInfo attribute for Attr and Element nodes, | |
| 147 | * the Text.isElementContentWhitespace attribute for Text nodes, as well as any | |
| 148 | * user data or event listeners registered on the nodes. | |
| 149 | * @param other Node to test againts | |
| 150 | * @return true if nodes are equal, false otherwise | |
| 151 | * @since DOM Level 3 | |
| 152 | */ | |
| 153 | 0 | public boolean isEqualNode(Node other) { |
| 154 | 0 | if (!super.isEqualNode(other)) { |
| 155 | 0 | return false; |
| 156 | } | |
| 157 | ||
| 158 | 0 | DocumentType otherDocType = (DocumentType) other; |
| 159 | 0 | if (!(StringUtilities.equals(this.getPublicId(), otherDocType.getPublicId()) && |
| 160 | StringUtilities.equals(this.getSystemId(), otherDocType.getSystemId()) && | |
| 161 | StringUtilities.equals(this.getInternalSubset(), otherDocType.getInternalSubset()))) { | |
| 162 | 0 | return false; |
| 163 | } | |
| 164 | ||
| 165 | 0 | NamedNodeMap ent = getEntities(); |
| 166 | 0 | NamedNodeMap otherEnt = otherDocType.getEntities(); |
| 167 | 0 | if (!equalNodeMaps(ent, otherEnt)) { |
| 168 | 0 | return false; |
| 169 | } | |
| 170 | ||
| 171 | 0 | NamedNodeMap not = getNotations(); |
| 172 | 0 | NamedNodeMap otherNot = otherDocType.getNotations(); |
| 173 | ||
| 174 | 0 | return equalNodeMaps(not, otherNot); |
| 175 | } | |
| 176 | ||
| 177 | 0 | private boolean equalNodeMaps(NamedNodeMap map1, NamedNodeMap map2) { |
| 178 | 0 | if (map1 == null && map2 == null) { |
| 179 | 0 | return true; |
| 180 | } | |
| 181 | 0 | if (map1 == null || map2 == null) { |
| 182 | 0 | return false; |
| 183 | } | |
| 184 | ||
| 185 | 0 | if (map1.getLength() != map2.getLength()) { |
| 186 | 0 | return false; |
| 187 | } | |
| 188 | ||
| 189 | 0 | for (int i = 0; i < map1.getLength(); i++) { |
| 190 | 0 | if (!((NodeImpl) map1.item(i)).isEqualNode(map2.item(i))) { |
| 191 | 0 | return false; |
| 192 | } | |
| 193 | } | |
| 194 | ||
| 195 | 0 | return true; |
| 196 | } | |
| 197 | } |
|
||||||||||