1 16 package org.apache.axis2.saaj; 17 18 import org.apache.axis2.om.OMElement; 19 import org.apache.axis2.om.OMText; 20 import org.w3c.dom.DOMException ; 21 22 import javax.xml.soap.SOAPElement ; 23 import javax.xml.soap.SOAPException ; 24 import javax.xml.soap.Text ; 25 26 32 public class TextImpl extends NodeImpl implements Text { 33 34 private OMText omText; 35 36 public TextImpl(String s){ 37 omNode = omText = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createText(s); 39 } 40 41 public TextImpl(SOAPElementImpl parent, String s) throws SOAPException { 42 OMElement par = parent.getOMElement(); 45 omNode = omText = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createText(par, s); 46 } 47 48 public TextImpl(org.w3c.dom.CharacterData data){ 49 if ( data == null ){ 50 throw new IllegalArgumentException ( "Text value may not be null." ); 51 } 52 omText = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createText(data.getData()); 53 } 54 55 56 public SOAPElement getParentElement() { 57 OMElement parent = (OMElement)omText.getParent(); 58 return new SOAPElementImpl(parent); 59 } 60 61 62 public void setParentElement(SOAPElement parent) throws SOAPException { 63 OMElement omParent = ((SOAPElementImpl)parent).getOMElement(); 64 omText.setParent(omParent); 65 } 66 67 68 public String getValue() { 69 return omText.getText(); 70 } 71 72 public boolean isComment() { 73 74 String temp = omText.getText(); 75 if(temp.startsWith("<!--") && temp.endsWith("-->")) 76 return true; 77 return false; 78 } 79 80 84 85 86 public org.w3c.dom.Text splitText(int offset) throws DOMException { 87 88 String temp = omText.getText(); 89 int length = temp.length(); 90 String tailData = temp.substring(offset); 91 temp = temp.substring(0, offset); 92 omText = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createText(temp); 93 TextImpl tailText = new TextImpl(tailData); 94 org.w3c.dom.Node myParent = getParentNode(); 95 if(myParent != null){ 96 org.w3c.dom.NodeList brothers = myParent.getChildNodes(); 97 for(int i = 0;i < brothers.getLength(); i++){ 98 if(brothers.item(i).equals(this)){ 99 myParent.insertBefore(tailText, this); 100 return tailText; 101 } 102 } 103 } 104 return tailText; 105 } 106 107 108 public int getLength() { 109 110 return omText.getText().length(); 111 } 112 113 114 public void deleteData(int offset, int count) throws DOMException { 115 116 String temp = omText.getText(); 117 StringBuffer subString = new StringBuffer (temp.substring(0,offset)); 118 if(temp.length() - offset >= count - offset) 119 subString = subString.append(temp.substring(offset+count)); 120 temp = subString.toString(); 121 omText = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createText(temp); 122 123 } 124 125 126 public String getData() throws DOMException { 127 128 return omText.getText(); 129 } 130 131 132 public String substringData(int offset, int count) throws DOMException { 133 134 String temp = omText.getText(); 135 if(temp.length() - offset >= count - offset) 136 return temp.substring(offset, count); 137 else 138 return temp.substring(offset); 139 } 140 141 142 public void replaceData(int offset, int count, String arg) 143 throws DOMException { 144 145 deleteData(offset, count); 146 StringBuffer temp = new StringBuffer (omText.getText()); 147 temp.append(arg); 148 omText = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createText(temp.toString()); 149 } 150 151 152 public void insertData(int offset, String arg) throws DOMException { 153 154 if(offset < 0 || offset > omText.getText().length()) 155 throw new DOMException (DOMException.INDEX_SIZE_ERR, ""); 156 StringBuffer temp = new StringBuffer (omText.getText().substring(0, offset)); 157 temp = temp.append(arg); 158 omText = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createText(temp.toString()); 159 } 160 161 162 public void appendData(String arg) throws DOMException { 163 164 StringBuffer temp = new StringBuffer (omText.getText()); 165 temp = temp.append(arg); 166 omText = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createText(temp.toString()); 167 168 } 169 170 171 public void setData(String arg) throws DOMException { 172 173 omText = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createText(arg); 174 } 175 176 } 177 | Popular Tags |