1 57 58 package com.sun.org.apache.xerces.internal.impl; 59 60 import java.io.IOException ; 61 62 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; 63 import com.sun.org.apache.xerces.internal.util.XML11Char; 64 import com.sun.org.apache.xerces.internal.util.XMLChar; 65 import com.sun.org.apache.xerces.internal.util.XMLStringBuffer; 66 import com.sun.org.apache.xerces.internal.xni.XMLString; 67 import com.sun.org.apache.xerces.internal.xni.XNIException; 68 69 95 public class XML11DocumentScannerImpl 96 extends XMLDocumentScannerImpl { 97 98 99 100 private String [] fStrings = new String [3]; 101 102 103 private XMLString fString = new XMLString(); 104 105 106 private XMLStringBuffer fStringBuffer = new XMLStringBuffer(); 107 private XMLStringBuffer fStringBuffer2 = new XMLStringBuffer(); 108 private XMLStringBuffer fStringBuffer3 = new XMLStringBuffer(); 109 110 114 115 public XML11DocumentScannerImpl() {super();} 117 121 123 128 protected int scanContent() throws IOException , XNIException { 129 130 XMLString content = fString; 131 int c = fEntityScanner.scanContent(content); 132 if (c == '\r' || c == 0x85 || c == 0x2028) { 133 fEntityScanner.scanChar(); 137 fStringBuffer.clear(); 138 fStringBuffer.append(fString); 139 fStringBuffer.append((char)c); 140 content = fStringBuffer; 141 c = -1; 142 } 143 if (fDocumentHandler != null && content.length > 0) { 144 fDocumentHandler.characters(content, null); 145 } 146 147 if (c == ']' && fString.length == 0) { 148 fStringBuffer.clear(); 149 fStringBuffer.append((char)fEntityScanner.scanChar()); 150 fInScanContent = true; 154 if (fEntityScanner.skipChar(']')) { 159 fStringBuffer.append(']'); 160 while (fEntityScanner.skipChar(']')) { 161 fStringBuffer.append(']'); 162 } 163 if (fEntityScanner.skipChar('>')) { 164 reportFatalError("CDEndInContent", null); 165 } 166 } 167 if (fDocumentHandler != null && fStringBuffer.length != 0) { 168 fDocumentHandler.characters(fStringBuffer, null); 169 } 170 fInScanContent = false; 171 c = -1; 172 } 173 return c; 174 175 } 177 194 protected void scanAttributeValue(XMLString value, 195 XMLString nonNormalizedValue, 196 String atName, 197 boolean checkEntities,String eleName) 198 throws IOException , XNIException 199 { 200 int quote = fEntityScanner.peekChar(); 202 if (quote != '\'' && quote != '"') { 203 reportFatalError("OpenQuoteExpected", new Object []{eleName,atName}); 204 } 205 206 fEntityScanner.scanChar(); 207 int entityDepth = fEntityDepth; 208 209 int c = fEntityScanner.scanLiteral(quote, value); 210 if (DEBUG_ATTR_NORMALIZATION) { 211 System.out.println("** scanLiteral -> \"" 212 + value.toString() + "\""); 213 } 214 fStringBuffer2.clear(); 215 fStringBuffer2.append(value); 216 normalizeWhitespace(value); 217 if (DEBUG_ATTR_NORMALIZATION) { 218 System.out.println("** normalizeWhitespace -> \"" 219 + value.toString() + "\""); 220 } 221 if (c != quote) { 222 fScanningAttribute = true; 223 fStringBuffer.clear(); 224 do { 225 fStringBuffer.append(value); 226 if (DEBUG_ATTR_NORMALIZATION) { 227 System.out.println("** value2: \"" 228 + fStringBuffer.toString() + "\""); 229 } 230 if (c == '&') { 231 fEntityScanner.skipChar('&'); 232 if (entityDepth == fEntityDepth) { 233 fStringBuffer2.append('&'); 234 } 235 if (fEntityScanner.skipChar('#')) { 236 if (entityDepth == fEntityDepth) { 237 fStringBuffer2.append('#'); 238 } 239 int ch = scanCharReferenceValue(fStringBuffer, fStringBuffer2); 240 if (ch != -1) { 241 if (DEBUG_ATTR_NORMALIZATION) { 242 System.out.println("** value3: \"" 243 + fStringBuffer.toString() 244 + "\""); 245 } 246 } 247 } 248 else { 249 String entityName = fEntityScanner.scanName(); 250 if (entityName == null) { 251 reportFatalError("NameRequiredInReference", null); 252 } 253 else if (entityDepth == fEntityDepth) { 254 fStringBuffer2.append(entityName); 255 } 256 if (!fEntityScanner.skipChar(';')) { 257 reportFatalError("SemicolonRequiredInReference", 258 new Object []{entityName}); 259 } 260 else if (entityDepth == fEntityDepth) { 261 fStringBuffer2.append(';'); 262 } 263 if (entityName == fAmpSymbol) { 264 fStringBuffer.append('&'); 265 if (DEBUG_ATTR_NORMALIZATION) { 266 System.out.println("** value5: \"" 267 + fStringBuffer.toString() 268 + "\""); 269 } 270 } 271 else if (entityName == fAposSymbol) { 272 fStringBuffer.append('\''); 273 if (DEBUG_ATTR_NORMALIZATION) { 274 System.out.println("** value7: \"" 275 + fStringBuffer.toString() 276 + "\""); 277 } 278 } 279 else if (entityName == fLtSymbol) { 280 fStringBuffer.append('<'); 281 if (DEBUG_ATTR_NORMALIZATION) { 282 System.out.println("** value9: \"" 283 + fStringBuffer.toString() 284 + "\""); 285 } 286 } 287 else if (entityName == fGtSymbol) { 288 fStringBuffer.append('>'); 289 if (DEBUG_ATTR_NORMALIZATION) { 290 System.out.println("** valueB: \"" 291 + fStringBuffer.toString() 292 + "\""); 293 } 294 } 295 else if (entityName == fQuotSymbol) { 296 fStringBuffer.append('"'); 297 if (DEBUG_ATTR_NORMALIZATION) { 298 System.out.println("** valueD: \"" 299 + fStringBuffer.toString() 300 + "\""); 301 } 302 } 303 else { 304 if (fEntityManager.isExternalEntity(entityName)) { 305 reportFatalError("ReferenceToExternalEntity", 306 new Object [] { entityName }); 307 } 308 else { 309 if (!fEntityManager.isDeclaredEntity(entityName)) { 310 if (checkEntities) { 312 if (fValidation) { 313 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 314 "EntityNotDeclared", 315 new Object []{entityName}, 316 XMLErrorReporter.SEVERITY_ERROR); 317 } 318 } 319 else { 320 reportFatalError("EntityNotDeclared", 321 new Object []{entityName}); 322 } 323 } 324 fEntityManager.startEntity(entityName, true); 325 } 326 } 327 } 328 } 329 else if (c == '<') { 330 reportFatalError("LessthanInAttValue", 331 new Object [] { eleName, atName }); 332 fEntityScanner.scanChar(); 333 if (entityDepth == fEntityDepth) { 334 fStringBuffer2.append((char)c); 335 } 336 } 337 else if (c == '%' || c == ']') { 338 fEntityScanner.scanChar(); 339 fStringBuffer.append((char)c); 340 if (entityDepth == fEntityDepth) { 341 fStringBuffer2.append((char)c); 342 } 343 if (DEBUG_ATTR_NORMALIZATION) { 344 System.out.println("** valueF: \"" 345 + fStringBuffer.toString() + "\""); 346 } 347 } 348 else if (c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) { 352 fEntityScanner.scanChar(); 353 fStringBuffer.append(' '); 354 if (entityDepth == fEntityDepth) { 355 fStringBuffer2.append('\n'); 356 } 357 } 358 else if (c != -1 && XMLChar.isHighSurrogate(c)) { 359 fStringBuffer3.clear(); 360 if (scanSurrogates(fStringBuffer3)) { 361 fStringBuffer.append(fStringBuffer3); 362 if (entityDepth == fEntityDepth) { 363 fStringBuffer2.append(fStringBuffer3); 364 } 365 if (DEBUG_ATTR_NORMALIZATION) { 366 System.out.println("** valueI: \"" 367 + fStringBuffer.toString() 368 + "\""); 369 } 370 } 371 } 372 else if (c != -1 && XML11Char.isXML11Invalid(c)) { 373 reportFatalError("InvalidCharInAttValue", 374 new Object [] {eleName, atName, Integer.toString(c, 16)}); 375 fEntityScanner.scanChar(); 376 if (entityDepth == fEntityDepth) { 377 fStringBuffer2.append((char)c); 378 } 379 } 380 c = fEntityScanner.scanLiteral(quote, value); 381 if (entityDepth == fEntityDepth) { 382 fStringBuffer2.append(value); 383 } 384 normalizeWhitespace(value); 385 } while (c != quote || entityDepth != fEntityDepth); 386 fStringBuffer.append(value); 387 if (DEBUG_ATTR_NORMALIZATION) { 388 System.out.println("** valueN: \"" 389 + fStringBuffer.toString() + "\""); 390 } 391 value.setValues(fStringBuffer); 392 fScanningAttribute = false; 393 } 394 nonNormalizedValue.setValues(fStringBuffer2); 395 396 int cquote = fEntityScanner.scanChar(); 398 if (cquote != quote) { 399 reportFatalError("CloseQuoteExpected", new Object []{eleName,atName}); 400 } 401 } 403 428 protected boolean scanPubidLiteral(XMLString literal) 429 throws IOException , XNIException 430 { 431 int quote = fEntityScanner.scanChar(); 432 if (quote != '\'' && quote != '"') { 433 reportFatalError("QuoteRequiredInPublicID", null); 434 return false; 435 } 436 437 fStringBuffer.clear(); 438 boolean skipSpace = true; 440 boolean dataok = true; 441 while (true) { 442 int c = fEntityScanner.scanChar(); 443 if (c == ' ' || c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) { 445 if (!skipSpace) { 446 fStringBuffer.append(' '); 448 skipSpace = true; 449 } 450 } 451 else if (c == quote) { 452 if (skipSpace) { 453 fStringBuffer.length--; 455 } 456 literal.setValues(fStringBuffer); 457 break; 458 } 459 else if (XMLChar.isPubid(c)) { 460 fStringBuffer.append((char)c); 461 skipSpace = false; 462 } 463 else if (c == -1) { 464 reportFatalError("PublicIDUnterminated", null); 465 return false; 466 } 467 else { 468 dataok = false; 469 reportFatalError("InvalidCharInPublicID", 470 new Object []{Integer.toHexString(c)}); 471 } 472 } 473 return dataok; 474 } 475 476 480 protected void normalizeWhitespace(XMLString value) { 481 int end = value.offset + value.length; 482 for (int i = value.offset; i < end; i++) { 483 int c = value.ch[i]; 484 if (XMLChar.isSpace(c)) { 485 value.ch[i] = ' '; 486 } 487 } 488 } 489 490 protected boolean isInvalid(int value) { 494 return (XML11Char.isXML11Invalid(value)); 495 } 497 protected boolean isInvalidLiteral(int value) { 501 return (!XML11Char.isXML11ValidLiteral(value)); 502 } 504 protected boolean isValidNameChar(int value) { 508 return (XML11Char.isXML11Name(value)); 509 } 511 protected boolean isValidNameStartChar(int value) { 515 return (XML11Char.isXML11NameStart(value)); 516 } 518 protected boolean isValidNCName(int value) { 522 return (XML11Char.isXML11NCName(value)); 523 } 525 protected boolean isValidNameStartHighSurrogate(int value) { 530 return XML11Char.isXML11NameHighSurrogate(value); 531 } 533 protected boolean versionSupported(String version) { 534 return (version.equals("1.1") || version.equals("1.0")); 535 } 537 protected String getVersionNotSupportedKey () { 541 return "VersionNotSupported11"; 542 } 544 } | Popular Tags |