1 16 17 package org.apache.axis.message; 18 19 import org.apache.axis.InternalException; 20 import org.w3c.dom.DOMException ; 21 22 30 public class Text extends NodeImpl implements javax.xml.soap.Text { 31 32 public Text(org.w3c.dom.CharacterData data) { 33 if ( data == null ) 34 { 35 throw new IllegalArgumentException ( "Text value may not be null." ); 36 } 37 textRep = data; 38 } 39 40 public Text(String s) { 41 try { 42 org.w3c.dom.Document doc = org.apache.axis.utils.XMLUtils.newDocument(); 43 textRep = doc.createTextNode(s); 44 } catch (javax.xml.parsers.ParserConfigurationException e) { 45 throw new InternalException(e); 46 } 47 } 48 49 public Text() 50 { 51 this((String )null); 52 } 53 54 60 public boolean isComment() { 61 String temp = textRep.getNodeValue().trim(); 62 if(temp.startsWith("<!--") && temp.endsWith("-->")) 63 return true; 64 return false; 65 } 66 67 71 72 public String getNodeValue() throws DOMException { 74 return textRep.getNodeValue(); 75 } 76 77 public void setNodeValue(String nodeValue) throws DOMException { 79 setDirty(true); 80 textRep.setNodeValue(nodeValue); 81 } 82 83 95 public org.w3c.dom.Text splitText(int offset) throws DOMException 96 { 97 int length = textRep.getLength(); 98 String tailData = textRep.substringData(offset,length); 101 textRep.deleteData(offset,length); 102 103 Text tailText = new Text(tailData); 105 org.w3c.dom.Node myParent = getParentNode(); 106 if(myParent != null){ 107 org.w3c.dom.NodeList brothers = myParent.getChildNodes(); 108 for(int i = 0;i < brothers.getLength(); i++){ 109 if(brothers.item(i).equals(this)){ 110 myParent.insertBefore(tailText, this); 111 return tailText; 112 } 113 } 114 } 115 return tailText; 116 } 117 118 121 public String getData() throws DOMException { 122 return textRep.getData(); 123 } 124 125 128 public void setData(String data) throws DOMException { 129 textRep.setData(data); 130 } 131 132 137 public int getLength(){ 138 return textRep.getLength(); 139 } 140 141 148 public String substringData(int offset, int count)throws DOMException { 149 return textRep.substringData(offset,count); 150 } 151 152 158 public void appendData(String arg) throws DOMException { 159 textRep.appendData(arg); 160 } 161 162 168 public void insertData(int offset, String arg)throws DOMException { 169 textRep.insertData(offset, arg); 170 } 171 172 179 public void replaceData(int offset, int count, String arg) throws DOMException { 180 textRep.replaceData(offset, count, arg); 181 } 182 183 189 public void deleteData(int offset, int count) throws DOMException { 190 textRep.deleteData(offset, count); 191 } 192 193 public String toString() 194 { 195 return textRep.getNodeValue(); 196 } 197 198 public boolean equals( Object obj ) 199 { 200 if ( !( obj instanceof Text ) ) 201 { 202 return false; 203 } 204 return this == obj || hashCode() == obj.hashCode(); 205 } 206 207 public int hashCode() 208 { 209 if ( textRep == null ) 210 { 211 return -1; 212 } 213 return ( textRep.getData() != null ? textRep.getData().hashCode() : 0 ); 214 } 215 216 } 217 | Popular Tags |