View Javadoc

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