1 28 29 package com.caucho.xml.readers; 30 31 import com.caucho.util.CharBuffer; 32 import com.caucho.util.L10N; 33 import com.caucho.vfs.Path; 34 import com.caucho.vfs.ReadStream; 35 import com.caucho.xml.XmlChar; 36 import com.caucho.xml.XmlParser; 37 38 import org.xml.sax.SAXException ; 39 40 import java.io.IOException ; 41 42 45 public class XmlReader { 46 static final L10N L = new L10N(XmlReader.class); 47 48 protected static boolean []isAsciiNameChar; 49 50 protected XmlParser _parser; 51 protected XmlReader _next; 52 53 protected Path _searchPath; 54 protected ReadStream _is; 55 protected String _filename; 56 protected int _line; 57 58 protected String _systemId; 59 protected String _publicId; 60 61 64 public XmlReader() 65 { 66 } 67 68 71 public XmlReader(XmlParser parser, ReadStream is) 72 { 73 init(parser, is); 74 } 75 76 79 public void init(XmlParser parser, ReadStream is) 80 { 81 _parser = parser; 82 _is = is; 83 _filename = is.getUserPath(); 84 _line = 1; 85 } 86 87 90 public void setFilename(String filename) 91 { 92 _filename = filename; 93 } 94 95 98 public String getFilename() 99 { 100 return _filename; 101 } 102 103 106 public void setLine(int line) 107 { 108 _line = line; 109 } 110 111 114 public int getLine() 115 { 116 return _line; 117 } 118 119 122 public void setSystemId(String systemId) 123 { 124 _systemId = systemId; 125 } 126 127 130 public String getSystemId() 131 { 132 return _systemId; 133 } 134 135 138 public void setPublicId(String publicId) 139 { 140 _publicId = publicId; 141 } 142 143 146 public String getPublicId() 147 { 148 return _publicId; 149 } 150 151 154 public void setSearchPath(Path searchPath) 155 { 156 _searchPath = searchPath; 157 } 158 159 162 public Path getSearchPath() 163 { 164 return _searchPath; 165 } 166 167 170 public void setNext(XmlReader next) 171 { 172 _next = next; 173 } 174 175 178 public XmlReader getNext() 179 { 180 return _next; 181 } 182 183 186 public ReadStream getReadStream() 187 { 188 return _is; 189 } 190 191 194 public int read() 195 throws IOException 196 { 197 int ch = _is.readChar(); 198 199 if (ch == '\n') 200 _parser.setLine(++_line); 201 202 return ch; 203 } 204 205 208 public int parseName(CharBuffer name, int ch) 209 throws IOException , SAXException 210 { 211 char []buffer = name.getBuffer(); 212 int capacity = buffer.length; 213 int offset = 0; 214 215 buffer[offset++] = (char) ch; 216 217 for (ch = read(); 218 ch > 0 && ch < 128 && isAsciiNameChar[ch] || XmlChar.isNameChar(ch); 219 ch = read()) { 220 if (offset >= capacity) { 221 name.setLength(offset); 222 name.append((char) ch); 223 offset++; 224 buffer = name.getBuffer(); 225 capacity = buffer.length; 226 } 227 else 228 buffer[offset++] = (char) ch; 229 } 230 231 name.setLength(offset); 232 233 return ch; 234 } 235 236 239 public void finish() 240 { 241 _is = null; 242 } 243 244 static { 245 isAsciiNameChar = XmlChar.getAsciiNameCharArray(); 246 } 247 } 248 249 | Popular Tags |