2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.apache.harmony.xml.dom;
19 import org.w3c.dom.DOMException;
20 import org.w3c.dom.DocumentType;
21 import org.w3c.dom.NamedNodeMap;
22 import org.w3c.dom.Node;
25 * Provides a straightforward implementation of the corresponding W3C DOM
26 * interface. The class is used internally only, thus only notable members that
27 * are not in the original interface are documented (the W3C docs are quite
28 * extensive). Hope that's ok.
30 * Some of the fields may have package visibility, so other classes belonging to
31 * the DOM implementation can easily access them while maintaining the DOM tree
34 public final class DocumentTypeImpl extends LeafNodeImpl implements DocumentType {
36 private String qualifiedName;
38 private String publicId;
40 private String systemId;
42 public DocumentTypeImpl(DocumentImpl document, String qualifiedName,
43 String publicId, String systemId) {
46 if (qualifiedName == null || "".equals(qualifiedName)) {
47 throw new DOMException(DOMException.NAMESPACE_ERR, qualifiedName);
50 int prefixSeparator = qualifiedName.lastIndexOf(":");
51 if (prefixSeparator != -1) {
52 String prefix = qualifiedName.substring(0, prefixSeparator);
53 String localName = qualifiedName.substring(prefixSeparator + 1);
55 if (!DocumentImpl.isXMLIdentifier(prefix)) {
56 throw new DOMException(DOMException.NAMESPACE_ERR, qualifiedName);
59 if (!DocumentImpl.isXMLIdentifier(localName)) {
60 throw new DOMException(DOMException.INVALID_CHARACTER_ERR, qualifiedName);
63 if (!DocumentImpl.isXMLIdentifier(qualifiedName)) {
64 throw new DOMException(DOMException.INVALID_CHARACTER_ERR, qualifiedName);
68 this.qualifiedName = qualifiedName;
69 this.publicId = publicId;
70 this.systemId = systemId;
74 public String getNodeName() {
79 public short getNodeType() {
80 return Node.DOCUMENT_TYPE_NODE;
83 public NamedNodeMap getEntities() {
84 // TODO Dummy. Implement this later, if at all (we're DOM level 2 only).
88 public String getInternalSubset() {
89 // TODO Dummy. Implement this later, if at all (we're DOM level 2 only).
93 public String getName() {
97 public NamedNodeMap getNotations() {
98 // TODO Dummy. Implement this later, if at all (we're DOM level 2 only).
102 public String getPublicId() {
106 public String getSystemId() {
110 @Override public String getTextContent() throws DOMException {