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