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 com.sun.xml.internal.messaging.saaj.util.SAAJUtil;
  36 import org.w3c.dom.CDATASection;

  37 import org.w3c.dom.DOMException;
  38 import org.w3c.dom.Document;
  39 import org.w3c.dom.NamedNodeMap;
  40 import org.w3c.dom.Node;
  41 import org.w3c.dom.NodeList;
  42 import org.w3c.dom.Text;
  43 import org.w3c.dom.UserDataHandler;
  44 
  45 public class CDATAImpl implements CDATASection, javax.xml.soap.Text {
  46 
  47     protected static final Logger log =
  48         Logger.getLogger(LogDomainConstants.SOAP_IMPL_DOMAIN,
  49                          "com.sun.xml.internal.messaging.saaj.soap.impl.LocalStrings");
  50 
  51     static final String cdataUC = "<![CDATA[";
  52     static final String cdataLC = "<![cdata[";
  53 
  54     @Override
  55     public Text splitText(int offset) throws DOMException {
  56         return cdataSection.splitText(offset);
  57     }
  58 
  59     @Override
  60     public boolean isElementContentWhitespace() {
  61         return cdataSection.isElementContentWhitespace();
  62     }
  63 
  64     @Override
  65     public String getWholeText() {
  66         return cdataSection.getWholeText();
  67     }
  68 
  69     @Override
  70     public Text replaceWholeText(String content) throws DOMException {
  71         return cdataSection.replaceWholeText(content);
  72     }
  73 
  74     @Override
  75     public String getData() throws DOMException {
  76         return cdataSection.getData();
  77     }
  78 
  79     @Override
  80     public void setData(String data) throws DOMException {
  81         cdataSection.setData(data);
  82     }
  83 
  84     @Override
  85     public int getLength() {
  86         return cdataSection.getLength();
  87     }
  88 
  89     @Override
  90     public String substringData(int offset, int count) throws DOMException {
  91         return cdataSection.substringData(offset, count);
  92     }
  93 
  94     @Override
  95     public void appendData(String arg) throws DOMException {
  96         cdataSection.appendData(arg);
  97     }
  98 
  99     @Override
 100     public void insertData(int offset, String arg) throws DOMException {
 101         cdataSection.insertData(offset, arg);
 102     }
 103 
 104     @Override
 105     public void deleteData(int offset, int count) throws DOMException {
 106         cdataSection.deleteData(offset, count);
 107     }
 108 
 109     @Override
 110     public void replaceData(int offset, int count, String arg) throws DOMException {
 111         cdataSection.replaceData(offset, count, arg);
 112     }
 113 
 114     @Override
 115     public String getNodeName() {
 116         return cdataSection.getNodeName();
 117     }
 118 
 119     @Override
 120     public String getNodeValue() throws DOMException {
 121         return cdataSection.getNodeValue();
 122     }
 123 
 124     @Override
 125     public void setNodeValue(String nodeValue) throws DOMException {
 126         cdataSection.setNodeValue(nodeValue);
 127     }
 128 
 129     @Override
 130     public short getNodeType() {
 131         return cdataSection.getNodeType();
 132     }
 133 
 134     @Override
 135     public Node getParentNode() {
 136         return cdataSection.getParentNode();
 137     }
 138 
 139     @Override
 140     public NodeList getChildNodes() {
 141         return cdataSection.getChildNodes();
 142     }
 143 
 144     @Override
 145     public Node getFirstChild() {
 146         return cdataSection.getFirstChild();
 147     }
 148 
 149     @Override
 150     public Node getLastChild() {
 151         return cdataSection.getLastChild();
 152     }
 153 
 154     @Override
 155     public Node getPreviousSibling() {
 156         return cdataSection.getPreviousSibling();
 157     }
 158 
 159     @Override
 160     public Node getNextSibling() {
 161         return cdataSection.getNextSibling();
 162     }
 163 
 164     @Override
 165     public NamedNodeMap getAttributes() {
 166         return cdataSection.getAttributes();
 167     }
 168 
 169     @Override
 170     public Document getOwnerDocument() {
 171         return cdataSection.getOwnerDocument();
 172     }
 173 
 174     @Override
 175     public Node insertBefore(Node newChild, Node refChild) throws DOMException {
 176         return cdataSection.insertBefore(newChild, refChild);
 177     }
 178 
 179     @Override
 180     public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
 181         return cdataSection.replaceChild(newChild, oldChild);
 182     }
 183 
 184     @Override
 185     public Node removeChild(Node oldChild) throws DOMException {
 186         return cdataSection.removeChild(oldChild);
 187     }
 188 
 189     @Override
 190     public Node appendChild(Node newChild) throws DOMException {
 191         return cdataSection.appendChild(newChild);
 192     }
 193 
 194     @Override
 195     public boolean hasChildNodes() {
 196         return cdataSection.hasChildNodes();
 197     }
 198 
 199     @Override
 200     public Node cloneNode(boolean deep) {
 201         return cdataSection.cloneNode(deep);
 202     }
 203 
 204     @Override
 205     public void normalize() {
 206         cdataSection.normalize();
 207     }
 208 
 209     @Override
 210     public boolean isSupported(String feature, String version) {
 211         return cdataSection.isSupported(feature, version);
 212     }
 213 
 214     @Override
 215     public String getNamespaceURI() {
 216         return cdataSection.getNamespaceURI();
 217     }
 218 
 219     @Override
 220     public String getPrefix() {
 221         return cdataSection.getPrefix();
 222     }
 223 
 224     @Override
 225     public void setPrefix(String prefix) throws DOMException {
 226         cdataSection.setPrefix(prefix);
 227     }
 228 
 229     @Override
 230     public String getLocalName() {
 231         return cdataSection.getLocalName();
 232     }
 233 
 234     @Override
 235     public boolean hasAttributes() {
 236         return cdataSection.hasAttributes();
 237     }
 238 
 239     @Override
 240     public String getBaseURI() {
 241         return cdataSection.getBaseURI();
 242     }
 243 
 244     @Override
 245     public short compareDocumentPosition(Node other) throws DOMException {
 246         return cdataSection.compareDocumentPosition(other);
 247     }
 248 
 249     @Override
 250     public String getTextContent() throws DOMException {
 251         return cdataSection.getTextContent();
 252     }
 253 
 254     @Override
 255     public void setTextContent(String textContent) throws DOMException {
 256         cdataSection.setTextContent(textContent);
 257     }
 258 
 259     @Override
 260     public boolean isSameNode(Node other) {
 261         return cdataSection.isSameNode(other);
 262     }
 263 
 264     @Override
 265     public String lookupPrefix(String namespaceURI) {
 266         return cdataSection.lookupPrefix(namespaceURI);


 267     }
 268 
 269     @Override
 270     public boolean isDefaultNamespace(String namespaceURI) {
 271         return cdataSection.isDefaultNamespace(namespaceURI);

 272     }
 273 
 274     @Override
 275     public String lookupNamespaceURI(String prefix) {
 276         return cdataSection.lookupNamespaceURI(prefix);
 277     }
 278 
 279     @Override
 280     public boolean isEqualNode(Node arg) {
 281         return cdataSection.isEqualNode(arg);
 282     }
 283 
 284     @Override
 285     public Object getFeature(String feature, String version) {
 286         return cdataSection.getFeature(feature, version);
 287     }
 288 
 289     @Override
 290     public Object setUserData(String key, Object data, UserDataHandler handler) {
 291         return cdataSection.setUserData(key, data, handler);
 292     }
 293 
 294     @Override
 295     public Object getUserData(String key) {
 296         return cdataSection.getUserData(key);
 297     }
 298 
 299     private CDATASection cdataSection;
 300 
 301     public CDATAImpl(SOAPDocumentImpl ownerDoc, String text) {
 302         cdataSection = ownerDoc.getDomDocument().createCDATASection(text);
 303         ownerDoc.register(this);
 304     }
 305 
 306     public String getValue() {
 307         String nodeValue = getNodeValue();
 308         return (nodeValue.equals("") ? null : nodeValue);
 309     }
 310 
 311     public void setValue(String text) {
 312         setNodeValue(text);
 313     }
 314 
 315     public void setParentElement(SOAPElement parent) throws SOAPException {
 316         if (parent == null) {
 317             log.severe("SAAJ0145.impl.no.null.to.parent.elem");
 318             throw new SOAPException("Cannot pass NULL to setParentElement");
 319         }
 320         ((ElementImpl) parent).addNode(this);
 321     }
 322 
 323     public SOAPElement getParentElement() {
 324         return (SOAPElement) getParentNode();
 325     }
 326 
 327 
 328     public void detachNode() {
 329         org.w3c.dom.Node parent = getParentNode();
 330         if (parent != null) {
 331             parent.removeChild(this);
 332         }
 333     }
 334 
 335     public void recycleNode() {
 336         detachNode();
 337         // TBD
 338         //  - add this to the factory so subsequent
 339         //    creations can reuse this object.
 340     }
 341 
 342     public boolean isComment() {
 343         return false;
 344     }
 345 
 346     public CDATASection getDomElement() {
 347         return cdataSection;
 348     }
 349 }
--- EOF ---