1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.xml.internal.messaging.saaj.soap.impl;
  27 
  28 import java.util.logging.Logger;
  29 
  30 import javax.xml.soap.SOAPElement;
  31 import javax.xml.soap.SOAPException;
  32 
  33 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
  34 import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
  35 import org.w3c.dom.DOMException;
  36 import org.w3c.dom.Document;
  37 import org.w3c.dom.NamedNodeMap;
  38 import org.w3c.dom.Node;
  39 import org.w3c.dom.NodeList;
  40 import org.w3c.dom.Text;
  41 import org.w3c.dom.UserDataHandler;
  42 
  43 public class SOAPTextImpl
  44     implements javax.xml.soap.Text, org.w3c.dom.Text {
  45 
  46     @Override
  47     public Text splitText(int offset) throws DOMException {
  48         return textNode.splitText(offset);
  49     }
  50 
  51     @Override
  52     public boolean isElementContentWhitespace() {
  53         return textNode.isElementContentWhitespace();
  54     }
  55 
  56     @Override
  57     public String getWholeText() {
  58         return textNode.getWholeText();
  59     }
  60 
  61     @Override
  62     public Text replaceWholeText(String content) throws DOMException {
  63         return textNode.replaceWholeText(content);
  64     }
  65 
  66     @Override
  67     public String getData() throws DOMException {
  68         return textNode.getData();
  69     }
  70 
  71     @Override
  72     public void setData(String data) throws DOMException {
  73         textNode.setData(data);
  74     }
  75 
  76     @Override
  77     public int getLength() {
  78         return textNode.getLength();
  79     }
  80 
  81     @Override
  82     public String substringData(int offset, int count) throws DOMException {
  83         return textNode.substringData(offset, count);
  84     }
  85 
  86     @Override
  87     public void appendData(String arg) throws DOMException {
  88         textNode.appendData(arg);
  89     }
  90 
  91     @Override
  92     public void insertData(int offset, String arg) throws DOMException {
  93         textNode.insertData(offset, arg);
  94     }
  95 
  96     @Override
  97     public void deleteData(int offset, int count) throws DOMException {
  98         textNode.deleteData(offset, count);
  99     }
 100 
 101     @Override
 102     public void replaceData(int offset, int count, String arg) throws DOMException {
 103         textNode.replaceData(offset, count, arg);
 104     }
 105 
 106     @Override
 107     public String getNodeName() {
 108         return textNode.getNodeName();
 109     }
 110 
 111     @Override
 112     public String getNodeValue() throws DOMException {
 113         return textNode.getNodeValue();
 114     }
 115 
 116     @Override
 117     public void setNodeValue(String nodeValue) throws DOMException {
 118         textNode.setNodeValue(nodeValue);
 119     }
 120 
 121     @Override
 122     public short getNodeType() {
 123         return textNode.getNodeType();
 124     }
 125 
 126     @Override
 127     public Node getParentNode() {
 128         return textNode.getParentNode();
 129     }
 130 
 131     @Override
 132     public NodeList getChildNodes() {
 133         return textNode.getChildNodes();
 134     }
 135 
 136     @Override
 137     public Node getFirstChild() {
 138         return textNode.getFirstChild();
 139     }
 140 
 141     @Override
 142     public Node getLastChild() {
 143         return textNode.getLastChild();
 144     }
 145 
 146     @Override
 147     public Node getPreviousSibling() {
 148         return textNode.getPreviousSibling();
 149     }
 150 
 151     @Override
 152     public Node getNextSibling() {
 153         return textNode.getNextSibling();
 154     }
 155 
 156     @Override
 157     public NamedNodeMap getAttributes() {
 158         return textNode.getAttributes();
 159     }
 160 
 161     @Override
 162     public Document getOwnerDocument() {
 163         return textNode.getOwnerDocument();
 164     }
 165 
 166     @Override
 167     public Node insertBefore(Node newChild, Node refChild) throws DOMException {
 168         return textNode.insertBefore(newChild, refChild);
 169     }
 170 
 171     @Override
 172     public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
 173         return textNode.replaceChild(newChild, oldChild);
 174     }
 175 
 176     @Override
 177     public Node removeChild(Node oldChild) throws DOMException {
 178         return textNode.removeChild(oldChild);
 179     }
 180 
 181     @Override
 182     public Node appendChild(Node newChild) throws DOMException {
 183         return textNode.appendChild(newChild);
 184     }
 185 
 186     @Override
 187     public boolean hasChildNodes() {
 188         return textNode.hasChildNodes();
 189     }
 190 
 191     @Override
 192     public Node cloneNode(boolean deep) {
 193         return textNode.cloneNode(deep);
 194     }
 195 
 196     @Override
 197     public void normalize() {
 198         textNode.normalize();
 199     }
 200 
 201     @Override
 202     public boolean isSupported(String feature, String version) {
 203         return textNode.isSupported(feature, version);
 204     }
 205 
 206     @Override
 207     public String getNamespaceURI() {
 208         return textNode.getNamespaceURI();
 209     }
 210 
 211     @Override
 212     public String getPrefix() {
 213         return textNode.getPrefix();
 214     }
 215 
 216     @Override
 217     public void setPrefix(String prefix) throws DOMException {
 218         textNode.setPrefix(prefix);
 219     }
 220 
 221     @Override
 222     public String getLocalName() {
 223         return textNode.getLocalName();
 224     }
 225 
 226     @Override
 227     public boolean hasAttributes() {
 228         return textNode.hasAttributes();
 229     }
 230 
 231     @Override
 232     public String getBaseURI() {
 233         return textNode.getBaseURI();
 234     }
 235 
 236     @Override
 237     public short compareDocumentPosition(Node other) throws DOMException {
 238         return textNode.compareDocumentPosition(other);
 239     }
 240 
 241     @Override
 242     public String getTextContent() throws DOMException {
 243         return textNode.getTextContent();
 244     }
 245 
 246     @Override
 247     public void setTextContent(String textContent) throws DOMException {
 248         textNode.setTextContent(textContent);
 249     }
 250 
 251     @Override
 252     public boolean isSameNode(Node other) {
 253         return textNode.isSameNode(other);
 254     }
 255 
 256     @Override
 257     public String lookupPrefix(String namespaceURI) {
 258         return textNode.lookupPrefix(namespaceURI);


 259     }
 260 
 261     @Override
 262     public boolean isDefaultNamespace(String namespaceURI) {
 263         return textNode.isDefaultNamespace(namespaceURI);

 264     }
 265 
 266     @Override
 267     public String lookupNamespaceURI(String prefix) {
 268         return textNode.lookupNamespaceURI(prefix);
 269     }
 270 
 271     @Override
 272     public boolean isEqualNode(Node arg) {
 273         return textNode.isEqualNode(arg);
 274     }
 275 
 276     @Override
 277     public Object getFeature(String feature, String version) {
 278         return textNode.getFeature(feature, version);
 279     }
 280 
 281     @Override
 282     public Object setUserData(String key, Object data, UserDataHandler handler) {
 283         return textNode.setUserData(key, data, handler);
 284     }
 285 
 286     @Override
 287     public Object getUserData(String key) {
 288         return textNode.getUserData(key);
 289     }
 290 
 291     protected static final Logger log =
 292         Logger.getLogger(LogDomainConstants.SOAP_IMPL_DOMAIN,
 293                          "com.sun.xml.internal.messaging.saaj.soap.impl.LocalStrings");
 294 
 295     private Text textNode;
 296 
 297     public SOAPTextImpl(SOAPDocumentImpl ownerDoc, String text) {
 298         textNode = ownerDoc.getDomDocument().createTextNode(text);
 299         ownerDoc.register(this);
 300     }
 301 
 302     public String getValue() {
 303         String nodeValue = getNodeValue();
 304         return (nodeValue.equals("") ? null : nodeValue);
 305     }
 306 
 307     public void setValue(String text) {
 308         setNodeValue(text);
 309     }
 310 
 311     public void setParentElement(SOAPElement parent) throws SOAPException {
 312         if (parent == null) {
 313             log.severe("SAAJ0126.impl.cannot.locate.ns");
 314             throw new SOAPException("Cannot pass NULL to setParentElement");
 315         }
 316         ((ElementImpl) parent).addNode(this);
 317     }
 318 
 319     public SOAPElement getParentElement() {
 320         return (SOAPElement) getParentNode();
 321     }
 322 
 323 
 324     public void detachNode() {
 325         org.w3c.dom.Node parent = getParentNode();
 326         if (parent != null) {
 327             parent.removeChild(getDomElement());
 328         }
 329     }
 330 
 331     public void recycleNode() {
 332         detachNode();
 333         // TBD
 334         //  - add this to the factory so subsequent
 335         //    creations can reuse this object.
 336     }
 337 
 338     public boolean isComment() {
 339         String txt = getNodeValue();
 340         if (txt == null) {
 341             return false;
 342         }
 343         return txt.startsWith("<!--") && txt.endsWith("-->");
 344     }
 345 
 346     public Text getDomElement() {
 347         return textNode;
 348     }
 349 }
--- EOF ---