1 2 9 10 package org.xmlpull.mxp1; 11 12 import java.io.IOException ; 13 import org.xmlpull.v1.XmlPullParserException; 14 15 21 22 public class MXParserNonValidating extends MXParserCachingStrings 23 { 24 private boolean processDocDecl; 25 26 public MXParserNonValidating() { 27 super(); 28 } 29 30 33 public void setFeature(String name, 34 boolean state) throws XmlPullParserException 35 { 36 if(FEATURE_PROCESS_DOCDECL.equals(name)) { 37 if(eventType != START_DOCUMENT) throw new XmlPullParserException( 38 "process DOCDECL feature can only be changed before parsing", this, null); 39 processDocDecl = state; 40 if(state == false) { 41 } 43 } else { 44 super.setFeature(name, state); 45 } 46 } 47 48 public boolean getFeature(String name) 49 { 50 if(FEATURE_PROCESS_DOCDECL.equals(name)) { 51 return processDocDecl; 52 } else { 53 return super.getFeature(name); 54 } 55 } 56 57 58 protected char more() throws IOException , XmlPullParserException { 60 return super.more(); 61 } 62 63 protected char[] lookuEntityReplacement(int entitNameLen) 64 throws XmlPullParserException, IOException 65 66 { 67 if(!allStringsInterned) { 68 int hash = fastHash(buf, posStart, posEnd - posStart); 69 LOOP: 70 for (int i = entityEnd - 1; i >= 0; --i) 71 { 72 if(hash == entityNameHash[ i ] && entitNameLen == entityNameBuf[ i ].length) { 73 char[] entityBuf = entityNameBuf[ i ]; 74 for (int j = 0; j < entitNameLen; j++) 75 { 76 if(buf[posStart + j] != entityBuf[j]) continue LOOP; 77 } 78 if(tokenize) text = entityReplacement[ i ]; 79 return entityReplacementBuf[ i ]; 80 } 81 } 82 } else { 83 entityRefName = newString(buf, posStart, posEnd - posStart); 84 for (int i = entityEnd - 1; i >= 0; --i) 85 { 86 if(entityRefName == entityName[ i ]) { 88 if(tokenize) text = entityReplacement[ i ]; 89 return entityReplacementBuf[ i ]; 90 } 91 } 92 } 93 return null; 94 } 95 96 97 protected void parseDocdecl() 98 throws XmlPullParserException, IOException 99 { 100 boolean oldTokenize = tokenize; 102 try { 103 char ch = more(); 105 if(ch != 'O') throw new XmlPullParserException( 106 "expected <!DOCTYPE", this, null); 107 ch = more(); 108 if(ch != 'C') throw new XmlPullParserException( 109 "expected <!DOCTYPE", this, null); 110 ch = more(); 111 if(ch != 'T') throw new XmlPullParserException( 112 "expected <!DOCTYPE", this, null); 113 ch = more(); 114 if(ch != 'Y') throw new XmlPullParserException( 115 "expected <!DOCTYPE", this, null); 116 ch = more(); 117 if(ch != 'P') throw new XmlPullParserException( 118 "expected <!DOCTYPE", this, null); 119 ch = more(); 120 if(ch != 'E') throw new XmlPullParserException( 121 "expected <!DOCTYPE", this, null); 122 posStart = pos; 123 125 ch = requireNextS(); 128 int nameStart = pos; 129 ch = readName(ch); 130 int nameEnd = pos; 131 ch = skipS(ch); 132 if(ch == 'S' || ch == 'P') { 134 ch = processExternalId(ch); 135 ch = skipS(ch); 136 } 137 if(ch == '[') { 138 processInternalSubset(); 139 } 140 ch = skipS(ch); 141 if(ch != '>') { 142 throw new XmlPullParserException( 143 "expected > to finish <[DOCTYPE but got "+printable(ch), this, null); 144 } 145 posEnd = pos - 1; 146 } finally { 147 tokenize = oldTokenize; 148 } 149 } 150 protected char processExternalId(char ch) 151 throws XmlPullParserException, IOException 152 { 153 158 160 return ch; 161 } 162 163 protected void processInternalSubset() 164 throws XmlPullParserException, IOException 165 { 166 169 while(true) { 171 char ch = more(); if(ch == ']') break; 173 if(ch == '%') { 174 processPEReference(); 175 } else if(isS(ch)) { 176 ch = skipS(ch); 177 } else { 178 processMarkupDecl(ch); 179 } 180 } 181 } 182 183 protected void processPEReference() 184 throws XmlPullParserException, IOException 185 { 186 } 188 protected void processMarkupDecl(char ch) 189 throws XmlPullParserException, IOException 190 { 191 194 195 if(ch != '<') { 197 throw new XmlPullParserException("expected < for markupdecl in DTD not "+printable(ch), 198 this, null); 199 } 200 ch = more(); 201 if(ch == '?') { 202 parsePI(); 203 } else if(ch == '!') { 204 ch = more(); 205 if(ch == '-') { 206 parseComment(); 208 } else { 209 ch = more(); 210 if(ch == 'A') { 211 processAttlistDecl(ch); } else if(ch == 'E') { 213 ch = more(); 214 if(ch == 'L') { 215 processElementDecl(ch); } else if(ch == 'N') { 217 processEntityDecl(ch); } else { 219 throw new XmlPullParserException( 220 "expected ELEMENT or ENTITY after <! in DTD not "+printable(ch), 221 this, null); 222 } 223 } else if(ch == 'N') { 224 processNotationDecl(ch); } else { 226 throw new XmlPullParserException( 227 "expected markupdecl after <! in DTD not "+printable(ch),this, null); 228 } 229 } 230 231 } else { 232 throw new XmlPullParserException("expected markupdecl in DTD not "+printable(ch), 233 this, null); 234 } 235 } 236 237 protected void processElementDecl(char ch) 238 throws XmlPullParserException, IOException 239 { 240 250 ch = requireNextS(); 252 readName(ch); 253 ch = requireNextS(); 254 } 256 257 protected void processAttlistDecl(char ch) 258 throws XmlPullParserException, IOException 259 { 260 272 274 } 275 276 277 protected void processEntityDecl(char ch) 278 throws XmlPullParserException, IOException 279 { 280 281 288 291 293 } 294 295 protected void processNotationDecl(char ch) 296 throws XmlPullParserException, IOException 297 { 298 299 302 } 304 305 306 307 protected char readName(char ch) 308 throws XmlPullParserException, IOException 309 { 310 if(isNameStartChar(ch)) { 311 throw new XmlPullParserException( 312 "XML name must start with name start character not "+printable(ch), this, null); 313 } 314 while(isNameChar(ch)) { 315 ch = more(); 316 } 317 return ch; 318 } 319 } 320 321 322 371 372 | Popular Tags |