The Android Open Source Project | 0eec464 | 2012-04-01 00:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | package org.apache.harmony.xml.dom; |
| 18 | |
| 19 | import org.w3c.dom.DOMException; |
| 20 | import org.w3c.dom.DocumentType; |
| 21 | import org.w3c.dom.NamedNodeMap; |
| 22 | import org.w3c.dom.Node; |
| 23 | |
| 24 | /** |
| 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. |
| 29 | * <p> |
| 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 |
| 32 | * structure. |
| 33 | */ |
| 34 | public final class DocumentTypeImpl extends LeafNodeImpl implements DocumentType { |
| 35 | |
| 36 | private String qualifiedName; |
| 37 | |
| 38 | private String publicId; |
| 39 | |
| 40 | private String systemId; |
| 41 | |
| 42 | public DocumentTypeImpl(DocumentImpl document, String qualifiedName, |
| 43 | String publicId, String systemId) { |
| 44 | super(document); |
| 45 | |
| 46 | if (qualifiedName == null || "".equals(qualifiedName)) { |
| 47 | throw new DOMException(DOMException.NAMESPACE_ERR, qualifiedName); |
| 48 | } |
| 49 | |
| 50 | int prefixSeparator = qualifiedName.lastIndexOf(":"); |
| 51 | if (prefixSeparator != -1) { |
| 52 | String prefix = qualifiedName.substring(0, prefixSeparator); |
| 53 | String localName = qualifiedName.substring(prefixSeparator + 1); |
| 54 | |
| 55 | if (!DocumentImpl.isXMLIdentifier(prefix)) { |
| 56 | throw new DOMException(DOMException.NAMESPACE_ERR, qualifiedName); |
| 57 | } |
| 58 | |
| 59 | if (!DocumentImpl.isXMLIdentifier(localName)) { |
| 60 | throw new DOMException(DOMException.INVALID_CHARACTER_ERR, qualifiedName); |
| 61 | } |
| 62 | } else { |
| 63 | if (!DocumentImpl.isXMLIdentifier(qualifiedName)) { |
| 64 | throw new DOMException(DOMException.INVALID_CHARACTER_ERR, qualifiedName); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | this.qualifiedName = qualifiedName; |
| 69 | this.publicId = publicId; |
| 70 | this.systemId = systemId; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public String getNodeName() { |
| 75 | return qualifiedName; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public short getNodeType() { |
| 80 | return Node.DOCUMENT_TYPE_NODE; |
| 81 | } |
| 82 | |
| 83 | public NamedNodeMap getEntities() { |
| 84 | // TODO Dummy. Implement this later, if at all (we're DOM level 2 only). |
| 85 | return null; |
| 86 | } |
| 87 | |
| 88 | public String getInternalSubset() { |
| 89 | // TODO Dummy. Implement this later, if at all (we're DOM level 2 only). |
| 90 | return null; |
| 91 | } |
| 92 | |
| 93 | public String getName() { |
| 94 | return qualifiedName; |
| 95 | } |
| 96 | |
| 97 | public NamedNodeMap getNotations() { |
| 98 | // TODO Dummy. Implement this later, if at all (we're DOM level 2 only). |
| 99 | return null; |
| 100 | } |
| 101 | |
| 102 | public String getPublicId() { |
| 103 | return publicId; |
| 104 | } |
| 105 | |
| 106 | public String getSystemId() { |
| 107 | return systemId; |
| 108 | } |
| 109 | |
| 110 | @Override public String getTextContent() throws DOMException { |
| 111 | return null; |
| 112 | } |
| 113 | } |