1 28 29 package com.caucho.xml; 30 31 import org.w3c.dom.CharacterData ; 32 import org.w3c.dom.DOMException ; 33 34 import java.io.IOException ; 35 36 abstract class QCharacterData extends QAbstractNode implements CharacterData { 37 protected String _data; 38 protected boolean _whitespaceOnly; 39 40 43 QCharacterData() 44 { 45 } 46 47 50 QCharacterData(String data) 51 { 52 _data = data; 53 } 54 55 58 public String getNodeValue() 59 { 60 return _data; 61 } 62 63 66 public void setNodeValue(String data) 67 { 68 _data = data; 69 } 70 71 74 public String getData() 75 { 76 return _data; 77 } 78 79 82 public void setData(String data) 83 { 84 _data = data; 85 } 86 87 90 public int getLength() 91 { 92 return _data.length(); 93 } 94 95 public String substringData(int start, int count) 96 throws DOMException 97 { 98 if (start + count >= _data.length()) 99 return _data.substring(start); 100 else 101 return _data.substring(start, start + count); 102 } 103 104 public String substringData(int start) 105 throws DOMException 106 { 107 return _data.substring(start); 108 } 109 110 public void appendData(String arg) 111 throws DOMException 112 { 113 _data = _data + arg; 114 } 115 116 public void insertData(int offset, String arg) 117 throws DOMException 118 { 119 _data = _data.substring(0, offset) + arg + _data.substring(offset); 120 } 121 122 public void deleteData(int offset, int count) 123 throws DOMException 124 { 125 if (_data.length() <= offset + count) 126 _data = _data.substring(0, offset); 127 else 128 _data = _data.substring(0, offset) + _data.substring(offset + count); 129 } 130 131 public void deleteData(int offset) 132 throws DOMException 133 { 134 _data = _data.substring(0, offset); 135 } 136 137 public void replaceData(int offset, int count, String arg) 138 throws DOMException 139 { 140 if (_data.length() <= offset + count) 141 _data = _data.substring(0, offset) + arg; 142 else 143 _data = _data.substring(0, offset) + arg + _data.substring(offset + count); 144 } 145 146 public boolean hasContent() 147 { 148 for (int i = 0; i < _data.length(); i++) 149 if (! Character.isWhitespace(_data.charAt(i))) 150 return true; 151 152 return false; 153 } 154 155 public boolean isElementContentWhitespace() 156 { 157 for (int i = 0; i < _data.length(); i++) 158 if (! Character.isWhitespace(_data.charAt(i))) 159 return false; 160 161 return true; 162 } 163 164 public void print(XmlPrinter os) throws IOException 165 { 166 os.text(getData()); 167 } 168 } 169 | Popular Tags |