1 38 package com.gargoylesoftware.htmlunit.html; 39 40 47 public abstract class DomCharacterData extends DomNode { 48 49 50 private String data_; 51 52 58 public DomCharacterData(final HtmlPage page, final String data) { 59 super(page); 60 data_ = data; 61 } 62 63 64 68 public String getData() { 69 return data_; 70 } 71 72 73 77 public void setData( final String newValue ) { 78 data_ = newValue; 79 } 80 81 85 public void setNodeValue(String newValue) { 86 data_ = newValue; 87 } 88 89 93 public int getLength() { 94 return data_.length(); 95 } 96 97 98 102 public void appendData(final String newData) { 103 data_ += newData; 104 } 105 106 107 112 public void deleteData(final int offset, final int count) { 113 if(offset < 0 || count < 0) { 114 throw new IllegalArgumentException ("offset: "+offset+" count: "+count); 115 } 116 117 final int tailLength = Math.max(data_.length() - count - offset, 0); 118 if(tailLength > 0) { 119 data_ = data_.substring(0, offset) + data_.substring(offset + count, offset + count + tailLength); 120 } 121 else { 122 data_ = ""; 123 } 124 } 125 126 127 133 public void insertData(final int offset, final String arg) { 134 data_ = new StringBuffer (data_).insert(offset, arg).toString(); 135 } 136 137 138 146 public void replaceData(final int offset, final int count, final String arg) { 147 deleteData(offset, count); 148 insertData(offset, arg); 149 } 150 151 152 159 public String substringData(final int offset, final int count) { 160 final int length = data_.length(); 161 if (count < 0 || offset < 0 || offset > length - 1) { 162 throw new IllegalArgumentException ("offset: "+offset+" count: "+count); 163 } 164 165 final int tailIndex = Math.min(offset + count, length); 166 return data_.substring(offset, tailIndex); 167 } 168 169 172 public String getNodeValue() { 173 return data_; 174 } 175 } 176 | Popular Tags |