1 package org.enhydra.xml; 2 3 import org.w3c.dom.CharacterData ; 4 import org.w3c.dom.DOMException ; 5 import org.w3c.dom.Node ; 6 7 15 public class CharacterDataImpl extends NodeImpl implements CharacterData { 16 17 18 21 public CharacterDataImpl() { 22 } 23 24 30 public CharacterDataImpl(Node node) { 31 super(node); 32 } 33 34 35 42 public String getData() throws DOMException { 43 return nodeValue; 44 } 45 46 53 public void setData(String data) throws DOMException { 54 nodeValue = data; 55 } 56 57 58 68 public String substringData(int offset, int count) throws DOMException { 69 int length = nodeValue.length(); 70 if (count < 0 || offset < 0 || offset > length - 1) 71 throw new DOMException (DOMException.INDEX_SIZE_ERR, "Index out of bounds"); 72 73 int tailIndex = length; 74 if(offset + count < length) 75 tailIndex = offset + count; 76 return nodeValue.substring(offset, tailIndex); 77 } 78 79 80 87 public void appendData(String arg) { 88 nodeValue += arg; 89 } 90 91 92 100 public void insertData(int offset, String arg) throws DOMException { 101 try { 102 nodeValue = new StringBuffer (nodeValue).insert(offset, arg).toString(); 103 } catch (StringIndexOutOfBoundsException e) { 104 throw new DOMException (DOMException.INDEX_SIZE_ERR, "Index out of bounds"); 105 } 106 } 107 108 109 117 public void deleteData(int offset, int count) throws DOMException { 118 int tailLength = nodeValue.length() - count - offset; 119 if(nodeValue.length() - count - offset < 0) 120 tailLength = 0; 121 try { 122 nodeValue = nodeValue.substring(0, offset) + 123 (tailLength > 0 ? nodeValue.substring(offset + count, offset + count + tailLength) : ""); 124 } catch (StringIndexOutOfBoundsException e) { 125 throw new DOMException (DOMException.INDEX_SIZE_ERR, "Index out of bounds"); 126 } 127 } 128 129 130 139 public void replaceData(int offset, int count, String arg) throws DOMException { 140 deleteData(offset, count); 141 insertData(offset, arg); 142 } 143 144 145 152 public String getNamespaceURI() { 153 return super.getNamespaceURI(); 154 } 155 156 157 } 158 | Popular Tags |