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