View Javadoc

    1   /*
    2    * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
    3    *
    4    * This software is open source.
    5    * See the bottom of this file for the licence.
    6    */
    7
    8   package org.dom4j.dom;
    9
    10  import org.dom4j.tree.DefaultDocumentType;
    11
    12  import org.w3c.dom.DOMException;
    13  import org.w3c.dom.Document;
    14  import org.w3c.dom.NamedNodeMap;
    15  import org.w3c.dom.NodeList;
    16
    17  /***
    18   * <p>
    19   * <code>DOMDocumentType</code> implements a DocumentType node which supports
    20   * the W3C DOM API.
    21   * </p>
    22   *
    23   * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
    24   * @version $Revision: 1.11 $
    25   */
    26  public class DOMDocumentType extends DefaultDocumentType implements
    27          org.w3c.dom.DocumentType {
    28      public DOMDocumentType() {
    29      }
    30
    31      public DOMDocumentType(String elementName, String systemID) {
    32          super(elementName, systemID);
    33      }
    34
    35      public DOMDocumentType(String name, String publicID, String systemID) {
    36          super(name, publicID, systemID);
    37      }
    38
    39      // org.w3c.dom.Node interface
    40      // -------------------------------------------------------------------------
    41      public boolean supports(String feature, String version) {
    42          return DOMNodeHelper.supports(this, feature, version);
    43      }
    44
    45      public String getNamespaceURI() {
    46          return DOMNodeHelper.getNamespaceURI(this);
    47      }
    48
    49      public String getPrefix() {
    50          return DOMNodeHelper.getPrefix(this);
    51      }
    52
    53      public void setPrefix(String prefix) throws DOMException {
    54          DOMNodeHelper.setPrefix(this, prefix);
    55      }
    56
    57      public String getLocalName() {
    58          return DOMNodeHelper.getLocalName(this);
    59      }
    60
    61      public String getNodeName() {
    62          return getName();
    63      }
    64
    65      // already part of API
    66      //
    67      // public short getNodeType();
    68      public String getNodeValue() throws DOMException {
    69          return null;
    70      }
    71
    72      public void setNodeValue(String nodeValue) throws DOMException {
    73      }
    74
    75      public org.w3c.dom.Node getParentNode() {
    76          return DOMNodeHelper.getParentNode(this);
    77      }
    78
    79      public NodeList getChildNodes() {
    80          return DOMNodeHelper.getChildNodes(this);
    81      }
    82
    83      public org.w3c.dom.Node getFirstChild() {
    84          return DOMNodeHelper.getFirstChild(this);
    85      }
    86
    87      public org.w3c.dom.Node getLastChild() {
    88          return DOMNodeHelper.getLastChild(this);
    89      }
    90
    91      public org.w3c.dom.Node getPreviousSibling() {
    92          return DOMNodeHelper.getPreviousSibling(this);
    93      }
    94
    95      public org.w3c.dom.Node getNextSibling() {
    96          return DOMNodeHelper.getNextSibling(this);
    97      }
    98
    99      public NamedNodeMap getAttributes() {
    100         return null;
    101     }
    102
    103     public Document getOwnerDocument() {
    104         return DOMNodeHelper.getOwnerDocument(this);
    105     }
    106
    107     public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild,
    108             org.w3c.dom.Node refChild) throws DOMException {
    109         checkNewChildNode(newChild);
    110
    111         return DOMNodeHelper.insertBefore(this, newChild, refChild);
    112     }
    113
    114     public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild,
    115             org.w3c.dom.Node oldChild) throws DOMException {
    116         checkNewChildNode(newChild);
    117
    118         return DOMNodeHelper.replaceChild(this, newChild, oldChild);
    119     }
    120
    121     public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
    122             throws DOMException {
    123         return DOMNodeHelper.removeChild(this, oldChild);
    124     }
    125
    126     public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
    127             throws DOMException {
    128         checkNewChildNode(newChild);
    129
    130         return DOMNodeHelper.appendChild(this, newChild);
    131     }
    132
    133     private void checkNewChildNode(org.w3c.dom.Node newChild)
    134             throws DOMException {
    135         throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
    136                 "DocumentType nodes cannot have children");
    137     }
    138
    139     public boolean hasChildNodes() {
    140         return DOMNodeHelper.hasChildNodes(this);
    141     }
    142
    143     public org.w3c.dom.Node cloneNode(boolean deep) {
    144         return DOMNodeHelper.cloneNode(this, deep);
    145     }
    146
    147     public void normalize() {
    148         DOMNodeHelper.normalize(this);
    149     }
    150
    151     public boolean isSupported(String feature, String version) {
    152         return DOMNodeHelper.isSupported(this, feature, version);
    153     }
    154
    155     public boolean hasAttributes() {
    156         return DOMNodeHelper.hasAttributes(this);
    157     }
    158
    159     // org.w3c.dom.DocumentType interface
    160     // -------------------------------------------------------------------------
    161     public NamedNodeMap getEntities() {
    162         return null;
    163     }
    164
    165     public NamedNodeMap getNotations() {
    166         return null;
    167     }
    168
    169     public String getPublicId() {
    170         return getPublicID();
    171     }
    172
    173     public String getSystemId() {
    174         return getSystemID();
    175     }
    176
    177     public String getInternalSubset() {
    178         return getElementName();
    179     }
    180 }
    181
    182 /*
    183  * Redistribution and use of this software and associated documentation
    184  * ("Software"), with or without modification, are permitted provided that the
    185  * following conditions are met:
    186  *
    187  * 1. Redistributions of source code must retain copyright statements and
    188  * notices. Redistributions must also contain a copy of this document.
    189  *
    190  * 2. Redistributions in binary form must reproduce the above copyright notice,
    191  * this list of conditions and the following disclaimer in the documentation
    192  * and/or other materials provided with the distribution.
    193  *
    194  * 3. The name "DOM4J" must not be used to endorse or promote products derived
    195  * from this Software without prior written permission of MetaStuff, Ltd. For
    196  * written permission, please contact dom4j-info@metastuff.com.
    197  *
    198  * 4. Products derived from this Software may not be called "DOM4J" nor may
    199  * "DOM4J" appear in their names without prior written permission of MetaStuff,
    200  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
    201  *
    202  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
    203  *
    204  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
    205  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    206  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    207  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
    208  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    209  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    210  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    211  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    212  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    213  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    214  * POSSIBILITY OF SUCH DAMAGE.
    215  *
    216  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
    217  */