1 20 21 25 26 package org.ozoneDB.xml.dom; 27 28 import org.w3c.dom.*; 29 30 31 50 public abstract class CharacterDataImpl extends NodeImpl implements CharacterDataProxy { 51 52 final static long serialVersionUID = 1; 53 54 55 public final String getData() { 56 return getNodeValue(); 58 } 59 60 61 public final void setData( String value ) throws DOMException { 62 setNodeValue( value == null ? "" : value ); 63 } 64 65 66 public final int getLength() { 67 return getNodeValue().length(); 68 } 69 70 71 public synchronized final String substringData( int start, int count ) throws DOMException { 72 if (start < 0 || start >= getLength()) { 75 throw new DOMExceptionImpl( DOMException.INDEX_SIZE_ERR, "'start' out of data size." ); 76 } 77 if (start + count > getLength()) { 78 throw new DOMExceptionImpl( DOMException.INDEX_SIZE_ERR, "'start + count' out of data size." ); 79 } 80 return getNodeValue().substring( start, count ); 82 } 83 84 85 public synchronized final void appendData( String value ) { 86 if (isReadOnly()) { 87 throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR ); 88 } 89 if (value == null) { 90 value = ""; 91 } 92 setNodeValue( getNodeValue() + value ); 93 } 94 95 96 public synchronized final void insertData( int offset, String value ) throws DOMException { 97 if (isReadOnly()) { 98 throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR ); 99 } 100 if (value == null) { 101 value = ""; 102 } 103 if (offset < 0 || offset > getLength()) { 105 throw new DOMExceptionImpl( DOMException.INDEX_SIZE_ERR, "'start' out of data size." ); 106 } 107 if (offset == 0) { 110 setNodeValue( value + getNodeValue() ); 111 } else if (offset == getLength()) { 112 setNodeValue( getNodeValue() + value ); 113 } else { 114 setNodeValue( getNodeValue().substring( 0, offset ) + value + getNodeValue().substring( offset ) ); 116 } 117 } 118 119 120 public synchronized final void deleteData( int offset, int count ) throws DOMException { 121 if (isReadOnly()) { 124 throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR ); 125 } 126 if (offset < 0 || offset >= getLength()) { 127 throw new DOMExceptionImpl( DOMException.INDEX_SIZE_ERR, "'start' out of data size." ); 128 } 129 if (offset + count > getLength()) { 130 throw new DOMExceptionImpl( DOMException.INDEX_SIZE_ERR, "'start + count' out of data size." ); 131 } 132 if (count == 0) { 133 return; 134 } 135 136 if (offset + count == getLength()) { 139 setNodeValue( getNodeValue().substring( 0, offset ) ); 140 } else if (offset == 0) { 141 setNodeValue( getNodeValue().substring( count ) ); 142 } else { 143 setNodeValue( getNodeValue().substring( 0, offset ) + getNodeValue().substring( offset + count ) ); 145 } 146 } 147 148 149 public synchronized final void replaceData( int offset, int count, String value ) throws DOMException { 150 if (isReadOnly()) { 151 throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR ); 152 } 153 if (value == null) { 154 value = ""; 155 } 156 deleteData( offset, count ); 160 insertData( offset, value ); 161 } 162 163 164 protected final boolean supportsChildern() { 165 return false; 166 } 167 168 169 176 protected CharacterDataImpl( DocumentImpl owner, String name, String value ) { 177 super(); 178 init( owner, name, value ); 179 } 180 181 182 public CharacterDataImpl() { 183 super(); 184 } 185 186 187 public void init( DocumentProxy owner, String name, String value ) { 188 super.init( owner, name, value, false ); 189 } 190 191 } 192 | Popular Tags |