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.XMLChar; 64 import com.sun.org.apache.xerces.internal.util.XML11Char; 65 import com.sun.org.apache.xerces.internal.util.XMLStringBuffer; 66 import com.sun.org.apache.xerces.internal.xni.QName; 67 import com.sun.org.apache.xerces.internal.xni.XMLString; 68 69 77 78 public class XML11EntityScanner 79 extends XMLEntityScanner { 80 81 85 86 public XML11EntityScanner() { 87 super(); 88 } 90 94 102 public int peekChar() throws IOException { 103 104 if (fCurrentEntity.position == fCurrentEntity.count) { 106 load(0, true); 107 } 108 109 int c = fCurrentEntity.ch[fCurrentEntity.position]; 111 112 if (fCurrentEntity.isExternal()) { 114 return (c != '\r' && c != 0x85 && c != 0x2028) ? c : '\n'; 115 } 116 else { 117 return c; 118 } 119 120 } 122 130 public int scanChar() throws IOException { 131 132 if (fCurrentEntity.position == fCurrentEntity.count) { 134 load(0, true); 135 } 136 137 int c = fCurrentEntity.ch[fCurrentEntity.position++]; 139 boolean external = false; 140 if (c == '\n' || 141 ((c == '\r' || c == 0x85 || c == 0x2028) && (external = fCurrentEntity.isExternal()))) { 142 fCurrentEntity.lineNumber++; 143 fCurrentEntity.columnNumber = 1; 144 if (fCurrentEntity.position == fCurrentEntity.count) { 145 fCurrentEntity.ch[0] = (char)c; 146 load(1, false); 147 } 148 if (c == '\r' && external) { 149 int cc = fCurrentEntity.ch[fCurrentEntity.position++]; 150 if (cc != '\n' && cc != 0x85) { 151 fCurrentEntity.position--; 152 } 153 } 154 c = '\n'; 155 } 156 157 fCurrentEntity.columnNumber++; 159 return c; 160 161 } 163 178 public String scanNmtoken() throws IOException { 179 if (fCurrentEntity.position == fCurrentEntity.count) { 181 load(0, true); 182 } 183 184 int offset = fCurrentEntity.position; 186 187 do { 188 char ch = fCurrentEntity.ch[fCurrentEntity.position]; 189 if (XML11Char.isXML11Name(ch)) { 190 if (++fCurrentEntity.position == fCurrentEntity.count) { 191 int length = fCurrentEntity.position - offset; 192 if (length == fCurrentEntity.ch.length) { 193 char[] tmp = new char[fCurrentEntity.ch.length << 1]; 195 System.arraycopy(fCurrentEntity.ch, offset, 196 tmp, 0, length); 197 fCurrentEntity.ch = tmp; 198 } 199 else { 200 System.arraycopy(fCurrentEntity.ch, offset, 201 fCurrentEntity.ch, 0, length); 202 } 203 offset = 0; 204 if (load(length, false)) { 205 break; 206 } 207 } 208 } 209 else if (XML11Char.isXML11NameHighSurrogate(ch)) { 210 if (++fCurrentEntity.position == fCurrentEntity.count) { 211 int length = fCurrentEntity.position - offset; 212 if (length == fCurrentEntity.ch.length) { 213 char[] tmp = new char[fCurrentEntity.ch.length << 1]; 215 System.arraycopy(fCurrentEntity.ch, offset, 216 tmp, 0, length); 217 fCurrentEntity.ch = tmp; 218 } 219 else { 220 System.arraycopy(fCurrentEntity.ch, offset, 221 fCurrentEntity.ch, 0, length); 222 } 223 offset = 0; 224 if (load(length, false)) { 225 --fCurrentEntity.position; 226 break; 227 } 228 } 229 char ch2 = fCurrentEntity.ch[fCurrentEntity.position]; 230 if ( !XMLChar.isLowSurrogate(ch2) || 231 !XML11Char.isXML11Name(XMLChar.supplemental(ch, ch2)) ) { 232 --fCurrentEntity.position; 233 break; 234 } 235 if (++fCurrentEntity.position == fCurrentEntity.count) { 236 int length = fCurrentEntity.position - offset; 237 if (length == fCurrentEntity.ch.length) { 238 char[] tmp = new char[fCurrentEntity.ch.length << 1]; 240 System.arraycopy(fCurrentEntity.ch, offset, 241 tmp, 0, length); 242 fCurrentEntity.ch = tmp; 243 } 244 else { 245 System.arraycopy(fCurrentEntity.ch, offset, 246 fCurrentEntity.ch, 0, length); 247 } 248 offset = 0; 249 if (load(length, false)) { 250 break; 251 } 252 } 253 } 254 else { 255 break; 256 } 257 } 258 while (true); 259 260 int length = fCurrentEntity.position - offset; 261 fCurrentEntity.columnNumber += length; 262 263 String symbol = null; 265 if (length > 0) { 266 symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length); 267 } 268 return symbol; 269 270 } 272 288 public String scanName() throws IOException { 289 if (fCurrentEntity.position == fCurrentEntity.count) { 291 load(0, true); 292 } 293 294 int offset = fCurrentEntity.position; 296 char ch = fCurrentEntity.ch[offset]; 297 298 if (XML11Char.isXML11NameStart(ch)) { 299 if (++fCurrentEntity.position == fCurrentEntity.count) { 300 fCurrentEntity.ch[0] = ch; 301 offset = 0; 302 if (load(1, false)) { 303 fCurrentEntity.columnNumber++; 304 String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1); 305 return symbol; 306 } 307 } 308 } 309 else if (XML11Char.isXML11NameHighSurrogate(ch)) { 310 if (++fCurrentEntity.position == fCurrentEntity.count) { 311 fCurrentEntity.ch[0] = ch; 312 offset = 0; 313 if (load(1, false)) { 314 --fCurrentEntity.position; 315 return null; 316 } 317 } 318 char ch2 = fCurrentEntity.ch[fCurrentEntity.position]; 319 if ( !XMLChar.isLowSurrogate(ch2) || 320 !XML11Char.isXML11NameStart(XMLChar.supplemental(ch, ch2)) ) { 321 --fCurrentEntity.position; 322 return null; 323 } 324 if (++fCurrentEntity.position == fCurrentEntity.count) { 325 fCurrentEntity.ch[0] = ch; 326 fCurrentEntity.ch[1] = ch2; 327 offset = 0; 328 if (load(2, false)) { 329 fCurrentEntity.columnNumber += 2; 330 String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 2); 331 return symbol; 332 } 333 } 334 } 335 else { 336 return null; 337 } 338 339 do { 340 ch = fCurrentEntity.ch[fCurrentEntity.position]; 341 if (XML11Char.isXML11Name(ch)) { 342 if (++fCurrentEntity.position == fCurrentEntity.count) { 343 int length = fCurrentEntity.position - offset; 344 if (length == fCurrentEntity.ch.length) { 345 char[] tmp = new char[fCurrentEntity.ch.length << 1]; 347 System.arraycopy(fCurrentEntity.ch, offset, 348 tmp, 0, length); 349 fCurrentEntity.ch = tmp; 350 } 351 else { 352 System.arraycopy(fCurrentEntity.ch, offset, 353 fCurrentEntity.ch, 0, length); 354 } 355 offset = 0; 356 if (load(length, false)) { 357 break; 358 } 359 } 360 } 361 else if (XML11Char.isXML11NameHighSurrogate(ch)) { 362 if (++fCurrentEntity.position == fCurrentEntity.count) { 363 int length = fCurrentEntity.position - offset; 364 if (length == fCurrentEntity.ch.length) { 365 char[] tmp = new char[fCurrentEntity.ch.length << 1]; 367 System.arraycopy(fCurrentEntity.ch, offset, 368 tmp, 0, length); 369 fCurrentEntity.ch = tmp; 370 } 371 else { 372 System.arraycopy(fCurrentEntity.ch, offset, 373 fCurrentEntity.ch, 0, length); 374 } 375 offset = 0; 376 if (load(length, false)) { 377 --fCurrentEntity.position; 378 break; 379 } 380 } 381 char ch2 = fCurrentEntity.ch[fCurrentEntity.position]; 382 if ( !XMLChar.isLowSurrogate(ch2) || 383 !XML11Char.isXML11Name(XMLChar.supplemental(ch, ch2)) ) { 384 --fCurrentEntity.position; 385 break; 386 } 387 if (++fCurrentEntity.position == fCurrentEntity.count) { 388 int length = fCurrentEntity.position - offset; 389 if (length == fCurrentEntity.ch.length) { 390 char[] tmp = new char[fCurrentEntity.ch.length << 1]; 392 System.arraycopy(fCurrentEntity.ch, offset, 393 tmp, 0, length); 394 fCurrentEntity.ch = tmp; 395 } 396 else { 397 System.arraycopy(fCurrentEntity.ch, offset, 398 fCurrentEntity.ch, 0, length); 399 } 400 offset = 0; 401 if (load(length, false)) { 402 break; 403 } 404 } 405 } 406 else { 407 break; 408 } 409 } 410 while (true); 411 412 int length = fCurrentEntity.position - offset; 413 fCurrentEntity.columnNumber += length; 414 415 String symbol = null; 417 if (length > 0) { 418 symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length); 419 } 420 return symbol; 421 422 } 424 440 public String scanNCName() throws IOException { 441 442 if (fCurrentEntity.position == fCurrentEntity.count) { 444 load(0, true); 445 } 446 447 int offset = fCurrentEntity.position; 449 char ch = fCurrentEntity.ch[offset]; 450 451 if (XML11Char.isXML11NCNameStart(ch)) { 452 if (++fCurrentEntity.position == fCurrentEntity.count) { 453 fCurrentEntity.ch[0] = ch; 454 offset = 0; 455 if (load(1, false)) { 456 fCurrentEntity.columnNumber++; 457 String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1); 458 return symbol; 459 } 460 } 461 } 462 else if (XML11Char.isXML11NameHighSurrogate(ch)) { 463 if (++fCurrentEntity.position == fCurrentEntity.count) { 464 fCurrentEntity.ch[0] = ch; 465 offset = 0; 466 if (load(1, false)) { 467 --fCurrentEntity.position; 468 return null; 469 } 470 } 471 char ch2 = fCurrentEntity.ch[fCurrentEntity.position]; 472 if ( !XMLChar.isLowSurrogate(ch2) || 473 !XML11Char.isXML11NCNameStart(XMLChar.supplemental(ch, ch2)) ) { 474 --fCurrentEntity.position; 475 return null; 476 } 477 if (++fCurrentEntity.position == fCurrentEntity.count) { 478 fCurrentEntity.ch[0] = ch; 479 fCurrentEntity.ch[1] = ch2; 480 offset = 0; 481 if (load(2, false)) { 482 fCurrentEntity.columnNumber += 2; 483 String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 2); 484 return symbol; 485 } 486 } 487 } 488 else { 489 return null; 490 } 491 492 do { 493 ch = fCurrentEntity.ch[fCurrentEntity.position]; 494 if (XML11Char.isXML11NCName(ch)) { 495 if (++fCurrentEntity.position == fCurrentEntity.count) { 496 int length = fCurrentEntity.position - offset; 497 if (length == fCurrentEntity.ch.length) { 498 char[] tmp = new char[fCurrentEntity.ch.length << 1]; 500 System.arraycopy(fCurrentEntity.ch, offset, 501 tmp, 0, length); 502 fCurrentEntity.ch = tmp; 503 } 504 else { 505 System.arraycopy(fCurrentEntity.ch, offset, 506 fCurrentEntity.ch, 0, length); 507 } 508 offset = 0; 509 if (load(length, false)) { 510 break; 511 } 512 } 513 } 514 else if (XML11Char.isXML11NameHighSurrogate(ch)) { 515 if (++fCurrentEntity.position == fCurrentEntity.count) { 516 int length = fCurrentEntity.position - offset; 517 if (length == fCurrentEntity.ch.length) { 518 char[] tmp = new char[fCurrentEntity.ch.length << 1]; 520 System.arraycopy(fCurrentEntity.ch, offset, 521 tmp, 0, length); 522 fCurrentEntity.ch = tmp; 523 } 524 else { 525 System.arraycopy(fCurrentEntity.ch, offset, 526 fCurrentEntity.ch, 0, length); 527 } 528 offset = 0; 529 if (load(length, false)) { 530 --fCurrentEntity.position; 531 break; 532 } 533 } 534 char ch2 = fCurrentEntity.ch[fCurrentEntity.position]; 535 if ( !XMLChar.isLowSurrogate(ch2) || 536 !XML11Char.isXML11NCName(XMLChar.supplemental(ch, ch2)) ) { 537 --fCurrentEntity.position; 538 break; 539 } 540 if (++fCurrentEntity.position == fCurrentEntity.count) { 541 int length = fCurrentEntity.position - offset; 542 if (length == fCurrentEntity.ch.length) { 543 char[] tmp = new char[fCurrentEntity.ch.length << 1]; 545 System.arraycopy(fCurrentEntity.ch, offset, 546 tmp, 0, length); 547 fCurrentEntity.ch = tmp; 548 } 549 else { 550 System.arraycopy(fCurrentEntity.ch, offset, 551 fCurrentEntity.ch, 0, length); 552 } 553 offset = 0; 554 if (load(length, false)) { 555 break; 556 } 557 } 558 } 559 else { 560 break; 561 } 562 } 563 while (true); 564 565 int length = fCurrentEntity.position - offset; 566 fCurrentEntity.columnNumber += length; 567 568 String symbol = null; 570 if (length > 0) { 571 symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length); 572 } 573 return symbol; 574 575 } 577 599 public boolean scanQName(QName qname) throws IOException { 600 601 if (fCurrentEntity.position == fCurrentEntity.count) { 603 load(0, true); 604 } 605 606 int offset = fCurrentEntity.position; 608 char ch = fCurrentEntity.ch[offset]; 609 610 if (XML11Char.isXML11NCNameStart(ch)) { 611 if (++fCurrentEntity.position == fCurrentEntity.count) { 612 fCurrentEntity.ch[0] = ch; 613 offset = 0; 614 if (load(1, false)) { 615 fCurrentEntity.columnNumber++; 616 String name = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1); 617 qname.setValues(null, name, name, null); 618 return true; 619 } 620 } 621 } 622 else if (XML11Char.isXML11NameHighSurrogate(ch)) { 623 if (++fCurrentEntity.position == fCurrentEntity.count) { 624 fCurrentEntity.ch[0] = ch; 625 offset = 0; 626 if (load(1, false)) { 627 --fCurrentEntity.position; 628 return false; 629 } 630 } 631 char ch2 = fCurrentEntity.ch[fCurrentEntity.position]; 632 if ( !XMLChar.isLowSurrogate(ch2) || 633 !XML11Char.isXML11NCNameStart(XMLChar.supplemental(ch, ch2)) ) { 634 --fCurrentEntity.position; 635 return false; 636 } 637 if (++fCurrentEntity.position == fCurrentEntity.count) { 638 fCurrentEntity.ch[0] = ch; 639 fCurrentEntity.ch[1] = ch2; 640 offset = 0; 641 if (load(2, false)) { 642 fCurrentEntity.columnNumber += 2; 643 String name = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 2); 644 qname.setValues(null, name, name, null); 645 return true; 646 } 647 } 648 } 649 else { 650 return false; 651 } 652 653 int index = -1; 654 boolean sawIncompleteSurrogatePair = false; 655 do { 656 ch = fCurrentEntity.ch[fCurrentEntity.position]; 657 if (XML11Char.isXML11Name(ch)) { 658 if (ch == ':') { 659 if (index != -1) { 660 break; 661 } 662 index = fCurrentEntity.position; 663 } 664 if (++fCurrentEntity.position == fCurrentEntity.count) { 665 int length = fCurrentEntity.position - offset; 666 if (length == fCurrentEntity.ch.length) { 667 char[] tmp = new char[fCurrentEntity.ch.length << 1]; 669 System.arraycopy(fCurrentEntity.ch, offset, 670 tmp, 0, length); 671 fCurrentEntity.ch = tmp; 672 } 673 else { 674 System.arraycopy(fCurrentEntity.ch, offset, 675 fCurrentEntity.ch, 0, length); 676 } 677 if (index != -1) { 678 index = index - offset; 679 } 680 offset = 0; 681 if (load(length, false)) { 682 break; 683 } 684 } 685 } 686 else if (XML11Char.isXML11NameHighSurrogate(ch)) { 687 if (++fCurrentEntity.position == fCurrentEntity.count) { 688 int length = fCurrentEntity.position - offset; 689 if (length == fCurrentEntity.ch.length) { 690 char[] tmp = new char[fCurrentEntity.ch.length << 1]; 692 System.arraycopy(fCurrentEntity.ch, offset, 693 tmp, 0, length); 694 fCurrentEntity.ch = tmp; 695 } 696 else { 697 System.arraycopy(fCurrentEntity.ch, offset, 698 fCurrentEntity.ch, 0, length); 699 } 700 if (index != -1) { 701 index = index - offset; 702 } 703 offset = 0; 704 if (load(length, false)) { 705 sawIncompleteSurrogatePair = true; 706 --fCurrentEntity.position; 707 break; 708 } 709 } 710 char ch2 = fCurrentEntity.ch[fCurrentEntity.position]; 711 if ( !XMLChar.isLowSurrogate(ch2) || 712 !XML11Char.isXML11Name(XMLChar.supplemental(ch, ch2)) ) { 713 sawIncompleteSurrogatePair = true; 714 --fCurrentEntity.position; 715 break; 716 } 717 if (++fCurrentEntity.position == fCurrentEntity.count) { 718 int length = fCurrentEntity.position - offset; 719 if (length == fCurrentEntity.ch.length) { 720 char[] tmp = new char[fCurrentEntity.ch.length << 1]; 722 System.arraycopy(fCurrentEntity.ch, offset, 723 tmp, 0, length); 724 fCurrentEntity.ch = tmp; 725 } 726 else { 727 System.arraycopy(fCurrentEntity.ch, offset, 728 fCurrentEntity.ch, 0, length); 729 } 730 if (index != -1) { 731 index = index - offset; 732 } 733 offset = 0; 734 if (load(length, false)) { 735 break; 736 } 737 } 738 } 739 else { 740 break; 741 } 742 } 743 while (true); 744 745 int length = fCurrentEntity.position - offset; 746 fCurrentEntity.columnNumber += length; 747 748 if (length > 0) { 749 String prefix = null; 750 String localpart = null; 751 String rawname = fSymbolTable.addSymbol(fCurrentEntity.ch, 752 offset, length); 753 if (index != -1) { 754 int prefixLength = index - offset; 755 prefix = fSymbolTable.addSymbol(fCurrentEntity.ch, 756 offset, prefixLength); 757 int len = length - prefixLength - 1; 758 int startLocal = index +1; 759 if (!XML11Char.isXML11NCNameStart(fCurrentEntity.ch[startLocal]) && 760 (!XML11Char.isXML11NameHighSurrogate(fCurrentEntity.ch[startLocal]) || 761 sawIncompleteSurrogatePair)){ 762 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 763 "IllegalQName", 764 null, 765 XMLErrorReporter.SEVERITY_FATAL_ERROR); 766 } 767 localpart = fSymbolTable.addSymbol(fCurrentEntity.ch, 768 index + 1, len); 769 770 } 771 else { 772 localpart = rawname; 773 } 774 qname.setValues(prefix, localpart, rawname, null); 775 return true; 776 } 777 return false; 778 779 } 781 807 public int scanContent(XMLString content) throws IOException { 808 809 if (fCurrentEntity.position == fCurrentEntity.count) { 811 load(0, true); 812 } 813 else if (fCurrentEntity.position == fCurrentEntity.count - 1) { 814 fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1]; 815 load(1, false); 816 fCurrentEntity.position = 0; 817 } 818 819 int offset = fCurrentEntity.position; 821 int c = fCurrentEntity.ch[offset]; 822 int newlines = 0; 823 boolean external = fCurrentEntity.isExternal(); 824 if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) { 825 do { 826 c = fCurrentEntity.ch[fCurrentEntity.position++]; 827 if ((c == '\r' ) && external) { 828 newlines++; 829 fCurrentEntity.lineNumber++; 830 fCurrentEntity.columnNumber = 1; 831 if (fCurrentEntity.position == fCurrentEntity.count) { 832 offset = 0; 833 fCurrentEntity.position = newlines; 834 if (load(newlines, false)) { 835 break; 836 } 837 } 838 int cc = fCurrentEntity.ch[fCurrentEntity.position]; 839 if (cc == '\n' || cc == 0x85) { 840 fCurrentEntity.position++; 841 offset++; 842 } 843 844 else { 845 newlines++; 846 } 847 } 848 else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) { 849 newlines++; 850 fCurrentEntity.lineNumber++; 851 fCurrentEntity.columnNumber = 1; 852 if (fCurrentEntity.position == fCurrentEntity.count) { 853 offset = 0; 854 fCurrentEntity.position = newlines; 855 if (load(newlines, false)) { 856 break; 857 } 858 } 859 } 860 else { 861 fCurrentEntity.position--; 862 break; 863 } 864 } while (fCurrentEntity.position < fCurrentEntity.count - 1); 865 for (int i = offset; i < fCurrentEntity.position; i++) { 866 fCurrentEntity.ch[i] = '\n'; 867 } 868 int length = fCurrentEntity.position - offset; 869 if (fCurrentEntity.position == fCurrentEntity.count - 1) { 870 content.setValues(fCurrentEntity.ch, offset, length); 871 return -1; 872 } 873 } 874 875 if (external) { 877 while (fCurrentEntity.position < fCurrentEntity.count) { 878 c = fCurrentEntity.ch[fCurrentEntity.position++]; 879 if (!XML11Char.isXML11Content(c) || c == 0x85 || c == 0x2028) { 880 fCurrentEntity.position--; 881 break; 882 } 883 } 884 } 885 else { 886 while (fCurrentEntity.position < fCurrentEntity.count) { 887 c = fCurrentEntity.ch[fCurrentEntity.position++]; 888 if (!XML11Char.isXML11InternalEntityContent(c)) { 890 fCurrentEntity.position--; 891 break; 892 } 893 } 894 } 895 int length = fCurrentEntity.position - offset; 896 fCurrentEntity.columnNumber += length - newlines; 897 content.setValues(fCurrentEntity.ch, offset, length); 898 899 if (fCurrentEntity.position != fCurrentEntity.count) { 901 c = fCurrentEntity.ch[fCurrentEntity.position]; 902 if ((c == '\r' || c == 0x85 || c == 0x2028) && external) { 905 c = '\n'; 906 } 907 } 908 else { 909 c = -1; 910 } 911 return c; 912 913 } 915 943 public int scanLiteral(int quote, XMLString content) 944 throws IOException { 945 946 if (fCurrentEntity.position == fCurrentEntity.count) { 948 load(0, true); 949 } 950 else if (fCurrentEntity.position == fCurrentEntity.count - 1) { 951 fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1]; 952 load(1, false); 953 fCurrentEntity.position = 0; 954 } 955 956 int offset = fCurrentEntity.position; 958 int c = fCurrentEntity.ch[offset]; 959 int newlines = 0; 960 boolean external = fCurrentEntity.isExternal(); 961 if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) { 962 do { 963 c = fCurrentEntity.ch[fCurrentEntity.position++]; 964 if ((c == '\r' ) && external) { 965 newlines++; 966 fCurrentEntity.lineNumber++; 967 fCurrentEntity.columnNumber = 1; 968 if (fCurrentEntity.position == fCurrentEntity.count) { 969 offset = 0; 970 fCurrentEntity.position = newlines; 971 if (load(newlines, false)) { 972 break; 973 } 974 } 975 int cc = fCurrentEntity.ch[fCurrentEntity.position]; 976 if (cc == '\n' || cc == 0x85) { 977 fCurrentEntity.position++; 978 offset++; 979 } 980 981 else { 982 newlines++; 983 } 984 } 985 else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) { 986 newlines++; 987 fCurrentEntity.lineNumber++; 988 fCurrentEntity.columnNumber = 1; 989 if (fCurrentEntity.position == fCurrentEntity.count) { 990 offset = 0; 991 fCurrentEntity.position = newlines; 992 if (load(newlines, false)) { 993 break; 994 } 995 } 996 } 997 else { 998 fCurrentEntity.position--; 999 break; 1000 } 1001 } while (fCurrentEntity.position < fCurrentEntity.count - 1); 1002 for (int i = offset; i < fCurrentEntity.position; i++) { 1003 fCurrentEntity.ch[i] = '\n'; 1004 } 1005 int length = fCurrentEntity.position - offset; 1006 if (fCurrentEntity.position == fCurrentEntity.count - 1) { 1007 content.setValues(fCurrentEntity.ch, offset, length); 1008 return -1; 1009 } 1010 } 1011 1012 if (external) { 1014 while (fCurrentEntity.position < fCurrentEntity.count) { 1015 c = fCurrentEntity.ch[fCurrentEntity.position++]; 1016 if (c == quote || c == '%' || !XML11Char.isXML11Content(c) 1017 || c == 0x85 || c == 0x2028) { 1018 fCurrentEntity.position--; 1019 break; 1020 } 1021 } 1022 } 1023 else { 1024 while (fCurrentEntity.position < fCurrentEntity.count) { 1025 c = fCurrentEntity.ch[fCurrentEntity.position++]; 1026 if ((c == quote && !fCurrentEntity.literal) 1028 || c == '%' || !XML11Char.isXML11InternalEntityContent(c)) { 1029 fCurrentEntity.position--; 1030 break; 1031 } 1032 } 1033 } 1034 int length = fCurrentEntity.position - offset; 1035 fCurrentEntity.columnNumber += length - newlines; 1036 content.setValues(fCurrentEntity.ch, offset, length); 1037 1038 if (fCurrentEntity.position != fCurrentEntity.count) { 1040 c = fCurrentEntity.ch[fCurrentEntity.position]; 1041 if (c == quote && fCurrentEntity.literal) { 1045 c = -1; 1046 } 1047 } 1048 else { 1049 c = -1; 1050 } 1051 return c; 1052 1053 } 1055 1085 public boolean scanData(String delimiter, XMLStringBuffer buffer) 1086 throws IOException { 1087 1088 boolean done = false; 1089 int delimLen = delimiter.length(); 1090 char charAt0 = delimiter.charAt(0); 1091 boolean external = fCurrentEntity.isExternal(); 1092 do { 1093 if (fCurrentEntity.position == fCurrentEntity.count) { 1095 load(0, true); 1096 } 1097 1098 boolean bNextEntity = false; 1099 1100 while ((fCurrentEntity.position >= fCurrentEntity.count - delimLen) 1101 && (!bNextEntity)) 1102 { 1103 System.arraycopy(fCurrentEntity.ch, 1104 fCurrentEntity.position, 1105 fCurrentEntity.ch, 1106 0, 1107 fCurrentEntity.count - fCurrentEntity.position); 1108 1109 bNextEntity = load(fCurrentEntity.count - fCurrentEntity.position, false); 1110 fCurrentEntity.position = 0; 1111 } 1112 1113 if (fCurrentEntity.position >= fCurrentEntity.count - delimLen) { 1114 int length = fCurrentEntity.count - fCurrentEntity.position; 1116 buffer.append (fCurrentEntity.ch, fCurrentEntity.position, length); 1117 fCurrentEntity.columnNumber += fCurrentEntity.count; 1118 fCurrentEntity.position = fCurrentEntity.count; 1119 load(0,true); 1120 return false; 1121 } 1122 1123 int offset = fCurrentEntity.position; 1125 int c = fCurrentEntity.ch[offset]; 1126 int newlines = 0; 1127 if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) { 1128 do { 1129 c = fCurrentEntity.ch[fCurrentEntity.position++]; 1130 if ((c == '\r' ) && external) { 1131 newlines++; 1132 fCurrentEntity.lineNumber++; 1133 fCurrentEntity.columnNumber = 1; 1134 if (fCurrentEntity.position == fCurrentEntity.count) { 1135 offset = 0; 1136 fCurrentEntity.position = newlines; 1137 if (load(newlines, false)) { 1138 break; 1139 } 1140 } 1141 int cc = fCurrentEntity.ch[fCurrentEntity.position]; 1142 if (cc == '\n' || cc == 0x85) { 1143 fCurrentEntity.position++; 1144 offset++; 1145 } 1146 1147 else { 1148 newlines++; 1149 } 1150 } 1151 else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) { 1152 newlines++; 1153 fCurrentEntity.lineNumber++; 1154 fCurrentEntity.columnNumber = 1; 1155 if (fCurrentEntity.position == fCurrentEntity.count) { 1156 offset = 0; 1157 fCurrentEntity.position = newlines; 1158 fCurrentEntity.count = newlines; 1159 if (load(newlines, false)) { 1160 break; 1161 } 1162 } 1163 } 1164 else { 1165 fCurrentEntity.position--; 1166 break; 1167 } 1168 } while (fCurrentEntity.position < fCurrentEntity.count - 1); 1169 for (int i = offset; i < fCurrentEntity.position; i++) { 1170 fCurrentEntity.ch[i] = '\n'; 1171 } 1172 int length = fCurrentEntity.position - offset; 1173 if (fCurrentEntity.position == fCurrentEntity.count - 1) { 1174 buffer.append(fCurrentEntity.ch, offset, length); 1175 return true; 1176 } 1177 } 1178 1179 if (external) { 1181 OUTER: while (fCurrentEntity.position < fCurrentEntity.count) { 1182 c = fCurrentEntity.ch[fCurrentEntity.position++]; 1183 if (c == charAt0) { 1184 int delimOffset = fCurrentEntity.position - 1; 1186 for (int i = 1; i < delimLen; i++) { 1187 if (fCurrentEntity.position == fCurrentEntity.count) { 1188 fCurrentEntity.position -= i; 1189 break OUTER; 1190 } 1191 c = fCurrentEntity.ch[fCurrentEntity.position++]; 1192 if (delimiter.charAt(i) != c) { 1193 fCurrentEntity.position--; 1194 break; 1195 } 1196 } 1197 if (fCurrentEntity.position == delimOffset + delimLen) { 1198 done = true; 1199 break; 1200 } 1201 } 1202 else if (c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) { 1203 fCurrentEntity.position--; 1204 break; 1205 } 1206 else if (!XML11Char.isXML11ValidLiteral(c)) { 1209 fCurrentEntity.position--; 1210 int length = fCurrentEntity.position - offset; 1211 fCurrentEntity.columnNumber += length - newlines; 1212 buffer.append(fCurrentEntity.ch, offset, length); 1213 return true; 1214 } 1215 } 1216 } 1217 else { 1218 OUTER: while (fCurrentEntity.position < fCurrentEntity.count) { 1219 c = fCurrentEntity.ch[fCurrentEntity.position++]; 1220 if (c == charAt0) { 1221 int delimOffset = fCurrentEntity.position - 1; 1223 for (int i = 1; i < delimLen; i++) { 1224 if (fCurrentEntity.position == fCurrentEntity.count) { 1225 fCurrentEntity.position -= i; 1226 break OUTER; 1227 } 1228 c = fCurrentEntity.ch[fCurrentEntity.position++]; 1229 if (delimiter.charAt(i) != c) { 1230 fCurrentEntity.position--; 1231 break; 1232 } 1233 } 1234 if (fCurrentEntity.position == delimOffset + delimLen) { 1235 done = true; 1236 break; 1237 } 1238 } 1239 else if (c == '\n') { 1240 fCurrentEntity.position--; 1241 break; 1242 } 1243 else if (!XML11Char.isXML11Valid(c)) { 1246 fCurrentEntity.position--; 1247 int length = fCurrentEntity.position - offset; 1248 fCurrentEntity.columnNumber += length - newlines; 1249 buffer.append(fCurrentEntity.ch, offset, length); 1250 return true; 1251 } 1252 } 1253 } 1254 int length = fCurrentEntity.position - offset; 1255 fCurrentEntity.columnNumber += length - newlines; 1256 if (done) { 1257 length -= delimLen; 1258 } 1259 buffer.append(fCurrentEntity.ch, offset, length); 1260 1261 } while (!done); 1263 return !done; 1264 1265 } 1267 1280 public boolean skipChar(int c) throws IOException { 1281 1282 if (fCurrentEntity.position == fCurrentEntity.count) { 1284 load(0, true); 1285 } 1286 1287 int cc = fCurrentEntity.ch[fCurrentEntity.position]; 1289 if (cc == c) { 1290 fCurrentEntity.position++; 1291 if (c == '\n') { 1292 fCurrentEntity.lineNumber++; 1293 fCurrentEntity.columnNumber = 1; 1294 } 1295 else { 1296 fCurrentEntity.columnNumber++; 1297 } 1298 return true; 1299 } 1300 else if (c == '\n' && ((cc == 0x2028 || cc == 0x85) && fCurrentEntity.isExternal())) { 1301 fCurrentEntity.position++; 1302 fCurrentEntity.lineNumber++; 1303 fCurrentEntity.columnNumber = 1; 1304 return true; 1305 } 1306 else if (c == '\n' && (cc == '\r' ) && fCurrentEntity.isExternal()) { 1307 if (fCurrentEntity.position == fCurrentEntity.count) { 1309 fCurrentEntity.ch[0] = (char)cc; 1310 load(1, false); 1311 } 1312 int ccc = fCurrentEntity.ch[++fCurrentEntity.position]; 1313 if (ccc == '\n' || ccc == 0x85) { 1314 fCurrentEntity.position++; 1315 } 1316 fCurrentEntity.lineNumber++; 1317 fCurrentEntity.columnNumber = 1; 1318 return true; 1319 } 1320 1321 return false; 1323 1324 } 1326 1340 public boolean skipSpaces() throws IOException { 1341 1342 if (fCurrentEntity.position == fCurrentEntity.count) { 1344 load(0, true); 1345 } 1346 1347 int c = fCurrentEntity.ch[fCurrentEntity.position]; 1349 1350 if (fCurrentEntity.isExternal()) { 1352 if (XML11Char.isXML11Space(c)) { 1353 do { 1354 boolean entityChanged = false; 1355 if (c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) { 1357 fCurrentEntity.lineNumber++; 1358 fCurrentEntity.columnNumber = 1; 1359 if (fCurrentEntity.position == fCurrentEntity.count - 1) { 1360 fCurrentEntity.ch[0] = (char)c; 1361 entityChanged = load(1, true); 1362 if (!entityChanged) 1363 fCurrentEntity.position = 0; 1366 } 1367 if (c == '\r') { 1368 int cc = fCurrentEntity.ch[++fCurrentEntity.position]; 1371 if (cc != '\n' && cc != 0x85 ) { 1372 fCurrentEntity.position--; 1373 } 1374 } 1375 } 1376 else { 1377 fCurrentEntity.columnNumber++; 1378 } 1379 if (!entityChanged) 1381 fCurrentEntity.position++; 1382 if (fCurrentEntity.position == fCurrentEntity.count) { 1383 load(0, true); 1384 } 1385 } while (XML11Char.isXML11Space(c = fCurrentEntity.ch[fCurrentEntity.position])); 1386 return true; 1387 } 1388 } 1389 else if (XMLChar.isSpace(c)) { 1391 do { 1392 boolean entityChanged = false; 1393 if (c == '\n') { 1395 fCurrentEntity.lineNumber++; 1396 fCurrentEntity.columnNumber = 1; 1397 if (fCurrentEntity.position == fCurrentEntity.count - 1) { 1398 fCurrentEntity.ch[0] = (char)c; 1399 entityChanged = load(1, true); 1400 if (!entityChanged) 1401 fCurrentEntity.position = 0; 1404 } 1405 } 1406 else { 1407 fCurrentEntity.columnNumber++; 1408 } 1409 if (!entityChanged) 1411 fCurrentEntity.position++; 1412 if (fCurrentEntity.position == fCurrentEntity.count) { 1413 load(0, true); 1414 } 1415 } while (XMLChar.isSpace(c = fCurrentEntity.ch[fCurrentEntity.position])); 1416 return true; 1417 } 1418 1419 return false; 1421 1422 } 1424 1437 public boolean skipString(String s) throws IOException { 1438 1439 if (fCurrentEntity.position == fCurrentEntity.count) { 1441 load(0, true); 1442 } 1443 1444 final int length = s.length(); 1446 for (int i = 0; i < length; i++) { 1447 char c = fCurrentEntity.ch[fCurrentEntity.position++]; 1448 if (c != s.charAt(i)) { 1449 fCurrentEntity.position -= i + 1; 1450 return false; 1451 } 1452 if (i < length - 1 && fCurrentEntity.position == fCurrentEntity.count) { 1453 System.arraycopy(fCurrentEntity.ch, fCurrentEntity.count - i - 1, fCurrentEntity.ch, 0, i + 1); 1454 if (load(i + 1, false)) { 1457 fCurrentEntity.position -= i + 1; 1458 return false; 1459 } 1460 } 1461 } 1462 fCurrentEntity.columnNumber += length; 1463 return true; 1464 1465 } 1467} 1469 | Popular Tags |