1 19 20 package org.netbeans.modules.web.core.syntax.deprecated; 21 22 import org.netbeans.modules.web.core.syntax.deprecated.JspTagSyntax; 23 import org.netbeans.modules.web.core.syntax.*; 24 import org.netbeans.modules.web.core.syntax.deprecated.ELSyntax; 25 import org.netbeans.editor.TokenContextPath; 26 import org.openide.ErrorManager; 27 import org.netbeans.editor.Syntax; 28 import org.netbeans.editor.TokenID; 29 import org.netbeans.editor.ext.html.HTMLTokenContext; 30 31 43 44 public class JspMultiSyntax extends Syntax { 45 46 48 public static final int MODE_HOST = 1; 50 public static final int MODE_HOST_JSPTAG = 2; 51 public static final int MODE_HOST_EL = 5; 52 public static final int MODE_HOST_JSPTAG_EL = 6; 53 public static final int MODE_HOST_JSPTAG_JAVA = 3; 54 public static final int MODE_HOST_JAVA = 4; 55 56 protected static final int DELIMCHECK_NO = -1; 58 protected static final int DELIMCHECK_PART = -2; 59 60 private static final int ISI_LANGUAGE = 1; private static final int ISI_HOST_JSPTAG = 2; private static final int ISI_HOST_JAVA = 3; private static final int ISI_HOST_JAVA_LT = 4; private static final int ISI_HOST_JAVA_LT_PC = 5; private static final int ISI_HOST_JAVA_JUMP = 6; private static final int ISI_HOST_EL = 17; private static final int ISI_HOST_EL_D = 18; private static final int ISI_HOST_EL_JUMP = 20; private static final int ISI_JSPTAG_JAVA = 7; private static final int ISI_JSPTAG_JAVA_LT = 8; private static final int ISI_JSPTAG_JAVA_LT_PC = 9; private static final int ISI_JSPTAG_JAVA_JUMP = 10; private static final int ISI_JSPTAG_EL = 21; private static final int ISI_JSPTAG_EL_D = 22; private static final int ISI_JSPTAG_EL_JUMP = 24; private static final int ISI_JAVA1_SWITCH = 11; private static final int ISI_JAVA1_PC = 12; private static final int ISI_JAVA1_JUMP = 13; private static final int ISI_JAVA2_SWITCH = 14; private static final int ISI_JAVA2_PC = 15; private static final int ISI_JAVA2_JUMP = 16; private static final int ISI_EL1_SWITCH = 25; private static final int ISI_EL1_JUMP = 26; private static final int ISI_EL2_SWITCH = 27; private static final int ISI_EL2_JUMP = 28; 94 private static final int HOST_INIT = 1; private static final int HOST_LT = 2; private static final int HOST_LT_PC = 3; private static final int HOST_LT_BLANK = 4; private static final int HOST_TAG = 5; private static final int HOST_LT_SLASH = 6; private static final int HOST_BS = 7; private static final int HOST_D = 8; 104 private static final int JSPTAG_INIT = 1; private static final int JSPTAG_LT = 2; private static final int JSPTAG_LT_PC = 3; private static final int JSPTAG_BS = 7; private static final int JSPTAG_D = 8; 111 private static final int JAVA_INIT = 1; private static final int JAVA_PC = 2; 115 private static final int EL_INIT = 1; 118 private static final int JAVA_SCRIPTLET = 1; 120 private static final int JAVA_DECLARATION = 2; 121 private static final int JAVA_EXPRESSION = 3; 122 123 private static int javaNestMode; 125 126 protected int nestMode; 127 128 protected Syntax hostSyntax; 129 protected Syntax jspTagSyntax; 130 protected Syntax elSyntax; 131 protected Syntax javaSyntax; 132 133 135 protected StateInfo hostStateInfo; 136 138 protected StateInfo jspTagStateInfo; 139 141 protected StateInfo elStateInfo; 142 144 protected StateInfo javaStateInfo; 145 146 private int firstTokenLength; 151 152 private TokenID firstTokenID; 157 158 private StateInfo helpHostStateInfo; 161 private StateInfo helpJspTagStateInfo; 162 private StateInfo helpELStateInfo; 163 private StateInfo helpJavaStateInfo; 164 165 private StateInfo firstHostStateInfo; 168 private StateInfo firstJspTagStateInfo; 169 private StateInfo firstELStateInfo; 170 private StateInfo firstJavaStateInfo; 171 172 174 public JspMultiSyntax() { 175 jspTagSyntax = new JspTagSyntax(); 177 firstJspTagStateInfo = jspTagSyntax.createStateInfo(); 178 helpJspTagStateInfo = jspTagSyntax.createStateInfo(); 179 elSyntax = new ELSyntax(); 181 firstELStateInfo = elSyntax.createStateInfo(); 182 helpELStateInfo = elSyntax.createStateInfo(); 183 184 } 185 186 public JspMultiSyntax(Syntax contentSyntax, Syntax scriptingSyntax) { 187 this(); 188 setContentSyntax(contentSyntax); 189 setScriptingSyntax(scriptingSyntax); 190 } 191 192 public void setContentSyntax(Syntax contentSyntax) { 193 hostSyntax = contentSyntax; 194 firstHostStateInfo = hostSyntax.createStateInfo(); 195 helpHostStateInfo = hostSyntax.createStateInfo(); 196 } 197 198 public Syntax getContentSyntax() { 199 return hostSyntax; 200 } 201 202 public void setScriptingSyntax(Syntax scriptingSyntax) { 203 javaSyntax = scriptingSyntax; 204 firstJavaStateInfo = javaSyntax.createStateInfo(); 205 helpJavaStateInfo = javaSyntax.createStateInfo(); 206 } 207 208 public Syntax getScriptingSyntax() { 209 return javaSyntax; 210 } 211 212 222 protected TokenID parseToken() { 223 226 230 if (state != ISI_LANGUAGE) { 232 char actChar; 233 while(offset < stopOffset) { 234 actChar = buffer[offset]; 235 switch (state) { 238 case ISI_HOST_JSPTAG: nestMode = MODE_HOST_JSPTAG; 242 state = ISI_LANGUAGE; 243 transferMasterToSlave(jspTagSyntax, null); 244 if (jspTagStateInfo == null) { 246 jspTagStateInfo = jspTagSyntax.createStateInfo(); 247 } 248 jspTagSyntax.storeState(jspTagStateInfo); 249 break; 250 251 case ISI_HOST_JAVA: switch (actChar) { 253 case '<': 254 state = ISI_HOST_JAVA_LT; 255 break; 256 default: 257 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } break; 260 261 case ISI_HOST_JAVA_LT: 262 switch (actChar) { 263 case '%': 264 state = ISI_HOST_JAVA_LT_PC; 265 break; 266 default: 267 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } break; 270 271 case ISI_HOST_JAVA_LT_PC: 272 switch (actChar) { 273 case '!': javaNestMode = JAVA_DECLARATION; 275 state = ISI_HOST_JAVA_JUMP; 276 offset++; 277 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 278 return JspTagTokenContext.SYMBOL2; 279 case '=': javaNestMode = JAVA_EXPRESSION; 281 state = ISI_HOST_JAVA_JUMP; 282 offset++; 283 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 284 return JspTagTokenContext.SYMBOL2; 285 default: javaNestMode = JAVA_SCRIPTLET; 287 state = ISI_HOST_JAVA_JUMP; 288 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 289 return JspTagTokenContext.SYMBOL2; 290 } 293 case ISI_HOST_JAVA_JUMP: 294 nestMode = MODE_HOST_JAVA; 295 state = ISI_LANGUAGE; 296 transferMasterToSlave(javaSyntax, null); 297 if (javaStateInfo == null) { 299 javaStateInfo = javaSyntax.createStateInfo(); 300 } 301 javaSyntax.storeState(javaStateInfo); 302 break; 303 304 case ISI_HOST_EL: switch (actChar) { 306 case '$': 307 case '#': 308 state = ISI_HOST_EL_D; 309 break; 310 default: 311 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } break; 314 315 case ISI_HOST_EL_D: 316 switch (actChar) { 317 case '{': state = ISI_HOST_EL_JUMP; 319 offset++; 320 tokenContextPath = JspMultiTokenContext.elContextPath; 321 return ELTokenContext.EL_DELIM; 322 default: 323 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } break; 326 327 case ISI_HOST_EL_JUMP: 328 nestMode = MODE_HOST_EL; 329 state = ISI_LANGUAGE; 330 transferMasterToSlave(elSyntax, null); 331 if (elStateInfo == null) { 333 elStateInfo = elSyntax.createStateInfo(); 334 } 335 elSyntax.storeState(elStateInfo); 336 break; 337 338 case ISI_JSPTAG_JAVA: switch (actChar) { 340 case '<': 341 state = ISI_JSPTAG_JAVA_LT; 342 break; 343 default: 344 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } break; 347 348 case ISI_JSPTAG_JAVA_LT: 349 switch (actChar) { 350 case '%': 351 state = ISI_JSPTAG_JAVA_LT_PC; 352 break; 353 default: 354 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } break; 357 358 case ISI_JSPTAG_JAVA_LT_PC: 359 switch (actChar) { 360 case '!': javaNestMode = JAVA_DECLARATION; 362 state = ISI_JSPTAG_JAVA_JUMP; 363 offset++; 364 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 365 return JspTagTokenContext.SYMBOL2; 366 case '=': javaNestMode = JAVA_EXPRESSION; 368 state = ISI_JSPTAG_JAVA_JUMP; 369 offset++; 370 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 373 return JspTagTokenContext.SYMBOL2; 374 default: javaNestMode = JAVA_SCRIPTLET; 376 state = ISI_JSPTAG_JAVA_JUMP; 377 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 380 return JspTagTokenContext.SYMBOL2; 381 } 384 case ISI_JSPTAG_JAVA_JUMP: 385 nestMode = MODE_HOST_JSPTAG_JAVA; 386 state = ISI_LANGUAGE; 387 transferMasterToSlave(javaSyntax, null); 388 if (javaStateInfo == null) { 390 javaStateInfo = javaSyntax.createStateInfo(); 391 } 392 javaSyntax.storeState(javaStateInfo); 393 break; 394 395 case ISI_JSPTAG_EL: switch (actChar) { 397 case '$': 398 case '#': 399 state = ISI_JSPTAG_EL_D; 400 break; 401 default: 402 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } break; 405 406 case ISI_JSPTAG_EL_D: 407 switch (actChar) { 408 case '{': state = ISI_JSPTAG_EL_JUMP; 410 offset++; 411 tokenContextPath = JspMultiTokenContext.elContextPath; 412 return ELTokenContext.EL_DELIM; 413 default: 414 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } break; 417 418 case ISI_JSPTAG_EL_JUMP: 419 nestMode = MODE_HOST_JSPTAG_EL; 420 state = ISI_LANGUAGE; 421 transferMasterToSlave(elSyntax, null); 422 if (elStateInfo == null) { 424 elStateInfo = elSyntax.createStateInfo(); 425 } 426 elSyntax.storeState(elStateInfo); 427 break; 428 429 case ISI_JAVA1_SWITCH: 431 switch (actChar) { 432 case '%': 433 state = ISI_JAVA1_PC; 434 break; 435 default: 436 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } break; 439 440 case ISI_JAVA1_PC: 441 switch (actChar) { 442 case '>': 443 state = ISI_JAVA1_JUMP; 444 offset++; 445 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 448 return JspTagTokenContext.SYMBOL2; 449 default: 450 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } 452 453 case ISI_JAVA1_JUMP: 454 nestMode = MODE_HOST_JSPTAG; 455 jspTagStateInfo.setPreScan(0); 456 state = ISI_LANGUAGE; 457 javaStateInfo = null; 458 break; 459 460 case ISI_JAVA2_SWITCH: 462 switch (actChar) { 463 case '%': 464 state = ISI_JAVA2_PC; 465 break; 466 default: 467 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } break; 470 471 case ISI_JAVA2_PC: 472 473 switch (actChar) { 474 case '>': 475 state = ISI_JAVA2_JUMP; 476 offset++; 477 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 480 return JspTagTokenContext.SYMBOL2; 481 default: 482 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } 484 485 case ISI_JAVA2_JUMP: 486 nestMode = MODE_HOST; 487 hostStateInfo.setPreScan(0); 488 state = ISI_LANGUAGE; 489 javaStateInfo = null; 490 break; 491 492 case ISI_EL1_SWITCH: 494 switch (actChar) { 495 case '}': 496 state = ISI_EL1_JUMP; 497 offset++; 498 tokenContextPath = JspMultiTokenContext.elContextPath; 501 return ELTokenContext.EL_DELIM; 502 default: 503 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } break; 506 507 case ISI_EL1_JUMP: 508 nestMode = MODE_HOST_JSPTAG; 509 jspTagStateInfo.setPreScan(0); 510 state = ISI_LANGUAGE; 511 elStateInfo = null; 512 break; 513 514 case ISI_EL2_SWITCH: 516 switch (actChar) { 517 case '}': 518 state = ISI_EL2_JUMP; 519 offset++; 520 tokenContextPath = JspMultiTokenContext.elContextPath; 523 return ELTokenContext.EL_DELIM; 524 default: 525 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad hostsyntax analyzer")); } break; 528 529 case ISI_EL2_JUMP: 530 nestMode = MODE_HOST; 531 hostStateInfo.setPreScan(0); 532 state = ISI_LANGUAGE; 533 elStateInfo = null; 534 break; 535 536 } 537 538 if (state == ISI_LANGUAGE) 539 break; 540 541 offset = ++offset; 542 } 544 if (state != ISI_LANGUAGE) { 545 549 if (lastBuffer) { 550 switch(state) { 551 case ISI_HOST_JSPTAG: 552 case ISI_HOST_JAVA: 553 case ISI_HOST_JAVA_LT: 554 case ISI_HOST_JAVA_LT_PC: 555 case ISI_HOST_JAVA_JUMP: 556 case ISI_JSPTAG_JAVA: 557 case ISI_JSPTAG_JAVA_LT: 558 case ISI_JSPTAG_JAVA_LT_PC: 559 case ISI_JSPTAG_JAVA_JUMP: 560 case ISI_JAVA1_SWITCH: 561 case ISI_JAVA1_PC: 562 case ISI_JAVA1_JUMP: 563 case ISI_JAVA2_SWITCH: 564 case ISI_JAVA2_PC: 565 case ISI_JAVA2_JUMP: 566 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 569 return JspTagTokenContext.SYMBOL2; 570 571 case ISI_HOST_EL: 572 case ISI_HOST_EL_D: 573 case ISI_HOST_EL_JUMP: 574 case ISI_JSPTAG_EL: 575 case ISI_JSPTAG_EL_D: 576 case ISI_JSPTAG_EL_JUMP: 577 case ISI_EL1_SWITCH: 578 case ISI_EL1_JUMP: 579 case ISI_EL2_SWITCH: 580 case ISI_EL2_JUMP: 581 tokenContextPath = JspMultiTokenContext.elContextPath; 584 return ELTokenContext.EL_DELIM; 585 } } return null; 590 } } 593 595 TokenID slaveTokenID = null; 598 TokenID returnedTokenID; 599 600 int slaveOffset; 601 int canBe; 602 boolean firstTokenNotRead = ((tokenOffset == offset) || (firstTokenID == null)); 603 boolean equalPositions = (tokenOffset == offset); 604 605 switch (nestMode) { 606 case MODE_HOST: 609 if (hostStateInfo == null) { 610 hostStateInfo = hostSyntax.createStateInfo(); 611 hostSyntax.reset(); 612 hostSyntax.storeState(hostStateInfo); 613 } 614 615 622 623 if (firstTokenNotRead) { 628 transferMasterToSlave(hostSyntax, hostStateInfo); 630 returnedTokenID = hostSyntax.nextToken(); 631 slaveTokenID = returnedTokenID; 632 tokenContextPath = JspMultiTokenContext.context.getContextPath( 633 hostSyntax.getTokenContextPath()); 634 slaveOffset = hostSyntax.getOffset(); 635 firstTokenID = slaveTokenID; 636 firstTokenLength = hostSyntax.getTokenLength(); 637 if (slaveTokenID == null) { 638 offset = slaveOffset; 639 firstTokenLength = -1; 640 if (equalPositions) { 642 helpHostStateInfo = hostStateInfo; 643 hostStateInfo = hostSyntax.createStateInfo(); 644 hostSyntax.storeState(hostStateInfo); 645 } 646 else { 647 if (hostStateInfo == null) { 648 hostStateInfo = hostSyntax.createStateInfo(); 649 } 650 hostSyntax.storeState(hostStateInfo); 651 } 652 return null; 655 } 656 if (returnedTokenID.getNumericID() == HTMLTokenContext.BLOCK_COMMENT_ID && isXMLSyntax() ) 657 canBe = DELIMCHECK_NO; 658 else{ 659 canBe = canBeHostDelimiter(tokenOffset, slaveOffset, slaveOffset, false); 661 } 662 if (canBe == DELIMCHECK_NO) { offset = slaveOffset; 664 if (hostStateInfo == null) { 665 hostStateInfo = hostSyntax.createStateInfo(); 666 } 667 hostSyntax.storeState(hostStateInfo); 668 return slaveTokenID; 671 } 672 hostSyntax.storeState(firstHostStateInfo); 674 } 677 else { transferMasterToSlave(hostSyntax, hostStateInfo); 679 canBe = DELIMCHECK_PART; 680 } 681 682 while (canBe == DELIMCHECK_PART) { returnedTokenID = hostSyntax.nextToken(); 692 slaveTokenID = returnedTokenID; 693 tokenContextPath = JspMultiTokenContext.context.getContextPath( 694 hostSyntax.getTokenContextPath()); 695 slaveOffset = hostSyntax.getOffset(); 696 697 if ((slaveTokenID == null) && lastBuffer) { 698 canBe = canBeHostDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, true); 700 if (canBe != DELIMCHECK_PART) 701 break; 702 } 703 704 if (slaveTokenID == null) { 705 if (lastBuffer) { 706 canBe = DELIMCHECK_NO; 707 break; 708 } 709 offset = slaveOffset; 710 if (equalPositions) { 711 helpHostStateInfo = hostStateInfo; 712 hostStateInfo = hostSyntax.createStateInfo(); 713 hostSyntax.storeState(hostStateInfo); 714 } 715 else { 716 if (hostStateInfo == null) { 717 hostStateInfo = hostSyntax.createStateInfo(); 718 } 719 hostSyntax.storeState(hostStateInfo); 720 } 721 return null; 724 } 725 canBe = canBeHostDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, false); 726 } 727 728 if (canBe == DELIMCHECK_NO) { offset = tokenOffset + firstTokenLength; 732 if (equalPositions) { 733 hostStateInfo = firstHostStateInfo; 734 firstHostStateInfo = hostSyntax.createStateInfo(); 735 } 736 else { 737 hostSyntax.load(helpHostStateInfo, buffer, tokenOffset, stopOffset - tokenOffset, lastBuffer, -1); 744 returnedTokenID = hostSyntax.nextToken(); 745 slaveTokenID = returnedTokenID; 748 tokenContextPath = JspMultiTokenContext.context.getContextPath( 749 hostSyntax.getTokenContextPath()); 750 if (hostStateInfo == null) { 751 hostStateInfo = hostSyntax.createStateInfo(); 752 } 753 hostSyntax.storeState(hostStateInfo); 754 755 } 756 759 return firstTokenID; 760 } 761 else { if (equalPositions) { 766 hostSyntax.load(hostStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); 767 } 768 else { 769 hostSyntax.load(helpHostStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); 770 } 771 returnedTokenID = hostSyntax.nextToken(); 772 tokenContextPath = JspMultiTokenContext.context.getContextPath( 773 hostSyntax.getTokenContextPath()); 774 if (hostStateInfo == null) { 776 hostStateInfo = hostSyntax.createStateInfo(); 777 } 778 hostSyntax.storeState(hostStateInfo); 781 hostStateInfo.setPreScan(0); 782 offset = canBe; 785 791 return firstTokenID; 792 } 793 795 796 case MODE_HOST_JSPTAG: 798 if ((jspTagStateInfo != null) && (jspTagStateInfo.getState() == JspTagSyntax.ISA_END_JSP)) { 800 jspTagStateInfo = null; 802 nestMode = MODE_HOST; 803 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 808 return JspTagTokenContext.TEXT; 809 } 810 811 if (jspTagStateInfo == null) { 812 jspTagStateInfo = jspTagSyntax.createStateInfo(); 813 jspTagSyntax.reset(); 814 jspTagSyntax.storeState(jspTagStateInfo); 815 } 816 if (firstTokenNotRead) { 817 transferMasterToSlave(jspTagSyntax, jspTagStateInfo); 819 returnedTokenID = jspTagSyntax.nextToken(); 820 if (returnedTokenID == JspTagTokenContext.AFTER_UNEXPECTED_LT) { 821 jspTagStateInfo = null; 823 nestMode = MODE_HOST; 824 hostStateInfo.setPreScan(0); 825 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 826 return returnedTokenID; 828 } 829 slaveTokenID = returnedTokenID; 830 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 831 slaveOffset = jspTagSyntax.getOffset(); 834 firstTokenID = slaveTokenID; 835 firstTokenLength = jspTagSyntax.getTokenLength(); 836 if (slaveTokenID == null) { 837 offset = slaveOffset; 838 firstTokenLength = -1; 839 if (equalPositions) { 841 helpJspTagStateInfo = jspTagStateInfo; 842 jspTagStateInfo = jspTagSyntax.createStateInfo(); 843 jspTagSyntax.storeState(jspTagStateInfo); 844 } 845 else { 846 if (jspTagStateInfo == null) { 847 jspTagStateInfo = jspTagSyntax.createStateInfo(); 848 } 849 jspTagSyntax.storeState(jspTagStateInfo); 850 } 851 return null; 854 } 855 canBe = canBeJspTagDelimiter(tokenOffset, slaveOffset, slaveOffset, false, returnedTokenID == JspTagTokenContext.COMMENT); 857 if (canBe == DELIMCHECK_NO) { offset = slaveOffset; 859 if (jspTagStateInfo == null) { 860 jspTagStateInfo = jspTagSyntax.createStateInfo(); 861 } 862 jspTagSyntax.storeState(jspTagStateInfo); 863 return slaveTokenID; 866 } 867 jspTagSyntax.storeState(firstJspTagStateInfo); 869 } 870 else { transferMasterToSlave(jspTagSyntax, jspTagStateInfo); 872 canBe = DELIMCHECK_PART; 873 } 874 875 while (canBe == DELIMCHECK_PART) { returnedTokenID = jspTagSyntax.nextToken(); 885 slaveTokenID = returnedTokenID; 886 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 887 slaveOffset = jspTagSyntax.getOffset(); 888 889 if ((slaveTokenID == null) && lastBuffer) { 890 canBe = canBeJspTagDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, true, returnedTokenID == JspTagTokenContext.COMMENT); 892 if (canBe != DELIMCHECK_PART) 893 break; 894 } 895 896 if (slaveTokenID == null) { 897 if (lastBuffer) { 898 canBe = DELIMCHECK_NO; 899 break; 900 } 901 offset = slaveOffset; 902 if (equalPositions) { 903 helpJspTagStateInfo = jspTagStateInfo; 904 jspTagStateInfo = jspTagSyntax.createStateInfo(); 905 jspTagSyntax.storeState(jspTagStateInfo); 906 } 907 else { 908 if (jspTagStateInfo == null) { 909 jspTagStateInfo = jspTagSyntax.createStateInfo(); 910 } 911 jspTagSyntax.storeState(jspTagStateInfo); 912 } 913 return null; 916 } 917 canBe = canBeJspTagDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, false, returnedTokenID == JspTagTokenContext.COMMENT); 918 } 919 920 if (canBe == DELIMCHECK_NO) { offset = tokenOffset + firstTokenLength; 924 if (equalPositions) { 925 jspTagStateInfo = firstJspTagStateInfo; 926 firstJspTagStateInfo = jspTagSyntax.createStateInfo(); 927 } 928 else { 929 jspTagSyntax.load(helpJspTagStateInfo, buffer, tokenOffset, stopOffset - tokenOffset, lastBuffer, -1); 934 returnedTokenID = jspTagSyntax.nextToken(); 935 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 936 slaveTokenID = returnedTokenID; 937 if (jspTagStateInfo == null) { 938 jspTagStateInfo = jspTagSyntax.createStateInfo(); 939 } 940 jspTagSyntax.storeState(jspTagStateInfo); 941 } 946 return firstTokenID; 949 } 950 else { if (equalPositions) { 955 jspTagSyntax.load(jspTagStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); 956 } 957 else { 958 jspTagSyntax.load(helpJspTagStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); 959 } 960 returnedTokenID = jspTagSyntax.nextToken(); 961 tokenContextPath = JspMultiTokenContext.jspTagContextPath; 962 if (jspTagStateInfo == null) { 964 jspTagStateInfo = jspTagSyntax.createStateInfo(); 965 } 966 jspTagSyntax.storeState(jspTagStateInfo); 967 jspTagStateInfo.setPreScan(0); 968 offset = canBe; 971 return firstTokenID; 977 } 978 980 case MODE_HOST_JSPTAG_JAVA: 982 case MODE_HOST_JAVA: 983 if (javaStateInfo == null) { 984 javaStateInfo = javaSyntax.createStateInfo(); 985 javaSyntax.reset(); 986 javaSyntax.storeState(javaStateInfo); 987 } 988 if (firstTokenNotRead) { 989 transferMasterToSlave(javaSyntax, javaStateInfo); 991 returnedTokenID = javaSyntax.nextToken(); 992 tokenContextPath = getJavaTokenContextPath(); 993 slaveTokenID = returnedTokenID; 994 slaveOffset = javaSyntax.getOffset(); 995 firstTokenID = slaveTokenID; 996 firstTokenLength = javaSyntax.getTokenLength(); 997 if (slaveTokenID == null) { 998 offset = slaveOffset; 999 firstTokenLength = -1; 1000 if (equalPositions) { 1002 helpJavaStateInfo = javaStateInfo; 1003 javaStateInfo = javaSyntax.createStateInfo(); 1004 javaSyntax.storeState(javaStateInfo); 1005 } 1006 else { 1007 if (javaStateInfo == null) { 1008 javaStateInfo = javaSyntax.createStateInfo(); 1009 } 1010 javaSyntax.storeState(javaStateInfo); 1011 } 1012 return null; 1015 } 1016 canBe = canBeJavaDelimiter(tokenOffset, slaveOffset, slaveOffset, false, nestMode); 1018 if (canBe == DELIMCHECK_NO) { offset = slaveOffset; 1020 if (javaStateInfo == null) { 1021 javaStateInfo = javaSyntax.createStateInfo(); 1022 } 1023 javaSyntax.storeState(javaStateInfo); 1024 return slaveTokenID; 1027 } 1028 javaSyntax.storeState(firstJavaStateInfo); 1030 } 1031 else { transferMasterToSlave(javaSyntax, javaStateInfo); 1033 canBe = DELIMCHECK_PART; 1034 } 1035 1036 while (canBe == DELIMCHECK_PART) { returnedTokenID = javaSyntax.nextToken(); 1046 slaveTokenID = returnedTokenID; 1047 tokenContextPath = getJavaTokenContextPath(); 1048 slaveOffset = javaSyntax.getOffset(); 1049 1050 if ((slaveTokenID == null) && lastBuffer) { 1051 canBe = canBeJavaDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, true, nestMode); 1053 if (canBe != DELIMCHECK_PART) 1054 break; 1055 } 1056 1057 if (slaveTokenID == null) { 1058 if (lastBuffer) { 1059 canBe = DELIMCHECK_NO; 1060 break; 1061 } 1062 offset = slaveOffset; 1063 if (equalPositions) { 1064 helpJavaStateInfo = javaStateInfo; 1065 javaStateInfo = javaSyntax.createStateInfo(); 1066 javaSyntax.storeState(javaStateInfo); 1067 } 1068 else { 1069 if (javaStateInfo == null) { 1070 javaStateInfo = javaSyntax.createStateInfo(); 1071 } 1072 javaSyntax.storeState(javaStateInfo); 1073 } 1074 return null; 1077 } 1078 canBe = canBeJavaDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, false, nestMode); 1079 } 1080 1081 if (canBe == DELIMCHECK_NO) { offset = tokenOffset + firstTokenLength; 1085 if (equalPositions) { 1086 javaStateInfo = firstJavaStateInfo; 1087 firstJavaStateInfo = javaSyntax.createStateInfo(); 1088 } 1089 else { 1090 javaSyntax.load(helpJavaStateInfo, buffer, tokenOffset, stopOffset - tokenOffset, lastBuffer, -1); 1095 returnedTokenID = javaSyntax.nextToken(); 1096 slaveTokenID = returnedTokenID; 1097 tokenContextPath = getJavaTokenContextPath(); 1098 if (javaStateInfo == null) { 1099 javaStateInfo = javaSyntax.createStateInfo(); 1100 } 1101 javaSyntax.storeState(javaStateInfo); 1102 } 1107 return firstTokenID; 1110 } 1111 else { if (equalPositions) { 1116 javaSyntax.load(javaStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); 1117 } 1118 else { 1119 javaSyntax.load(helpJavaStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); 1120 } 1121 returnedTokenID = javaSyntax.nextToken(); 1122 tokenContextPath = getJavaTokenContextPath(); 1123 if (javaStateInfo == null) { 1125 javaStateInfo = javaSyntax.createStateInfo(); 1126 } 1127 javaSyntax.storeState(javaStateInfo); 1128 javaStateInfo.setPreScan(0); 1129 offset = canBe; 1132 1137 1138 return firstTokenID; 1139 } 1140 1142 case MODE_HOST_JSPTAG_EL: 1144 case MODE_HOST_EL: 1145 if (elStateInfo == null) { 1146 elStateInfo = elSyntax.createStateInfo(); 1147 elSyntax.reset(); 1148 elSyntax.storeState(elStateInfo); 1149 } 1150 if (firstTokenNotRead) { 1151 transferMasterToSlave(elSyntax, elStateInfo); 1153 returnedTokenID = elSyntax.nextToken(); 1154 tokenContextPath = JspMultiTokenContext.elContextPath; 1155 slaveTokenID = returnedTokenID; 1156 slaveOffset = elSyntax.getOffset(); 1157 firstTokenID = slaveTokenID; 1158 firstTokenLength = elSyntax.getTokenLength(); 1159 if (slaveTokenID == null) { 1160 offset = slaveOffset; 1161 firstTokenLength = -1; 1162 if (equalPositions) { 1164 helpELStateInfo = elStateInfo; 1165 elStateInfo = elSyntax.createStateInfo(); 1166 elSyntax.storeState(elStateInfo); 1167 } 1168 else { 1169 if (elStateInfo == null) { 1170 elStateInfo = elSyntax.createStateInfo(); 1171 } 1172 elSyntax.storeState(elStateInfo); 1173 } 1174 return null; 1177 } 1178 canBe = canBeELDelimiter(tokenOffset, slaveOffset, slaveOffset, false, nestMode); 1180 if (canBe == DELIMCHECK_NO) { offset = slaveOffset; 1182 if (elStateInfo == null) { 1183 elStateInfo = elSyntax.createStateInfo(); 1184 } 1185 elSyntax.storeState(elStateInfo); 1186 return slaveTokenID; 1189 } 1190 elSyntax.storeState(firstELStateInfo); 1192 } 1193 else { transferMasterToSlave(elSyntax, elStateInfo); 1195 canBe = DELIMCHECK_PART; 1196 } 1197 1198 while (canBe == DELIMCHECK_PART) { returnedTokenID = elSyntax.nextToken(); 1208 slaveTokenID = returnedTokenID; 1209 tokenContextPath = JspMultiTokenContext.elContextPath; 1210 slaveOffset = elSyntax.getOffset(); 1211 1212 if ((slaveTokenID == null) && lastBuffer) { 1213 canBe = canBeELDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, true, nestMode); 1215 if (canBe != DELIMCHECK_PART) 1216 break; 1217 } 1218 1219 if (slaveTokenID == null) { 1220 if (lastBuffer) { 1221 canBe = DELIMCHECK_NO; 1222 break; 1223 } 1224 offset = slaveOffset; 1225 if (equalPositions) { 1226 helpELStateInfo = elStateInfo; 1227 elStateInfo = elSyntax.createStateInfo(); 1228 elSyntax.storeState(elStateInfo); 1229 } 1230 else { 1231 if (elStateInfo == null) { 1232 elStateInfo = elSyntax.createStateInfo(); 1233 } 1234 elSyntax.storeState(elStateInfo); 1235 } 1236 return null; 1239 } 1240 canBe = canBeELDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, false, nestMode); 1241 } 1242 1243 if (canBe == DELIMCHECK_NO) { offset = tokenOffset + firstTokenLength; 1247 if (equalPositions) { 1248 elStateInfo = firstELStateInfo; 1249 firstELStateInfo = elSyntax.createStateInfo(); 1250 } 1251 else { 1252 elSyntax.load(helpELStateInfo, buffer, tokenOffset, stopOffset - tokenOffset, lastBuffer, -1); 1257 returnedTokenID = elSyntax.nextToken(); 1258 slaveTokenID = returnedTokenID; 1259 tokenContextPath = JspMultiTokenContext.elContextPath; 1260 if (elStateInfo == null) { 1261 elStateInfo = elSyntax.createStateInfo(); 1262 } 1263 elSyntax.storeState(elStateInfo); 1264 } 1269 return firstTokenID; 1272 } 1273 else { if (equalPositions) { 1278 elSyntax.load(elStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); 1279 } 1280 else { 1281 elSyntax.load(helpELStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); 1282 } 1283 returnedTokenID = elSyntax.nextToken(); 1284 tokenContextPath = JspMultiTokenContext.elContextPath; 1285 if (elStateInfo == null) { 1287 elStateInfo = elSyntax.createStateInfo(); 1288 } 1289 elSyntax.storeState(elStateInfo); 1290 elStateInfo.setPreScan(0); 1291 offset = canBe; 1294 1299 return firstTokenID; 1300 } 1301 1303 default: 1305 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad nestmode")); tokenContextPath = JspMultiTokenContext.contextPath; 1307 return JspMultiTokenContext.ERROR; } 1309 } 1310 1311 1313 private TokenContextPath getJavaTokenContextPath() { 1314 switch(javaNestMode) { 1315 case JAVA_DECLARATION: 1316 return JspMultiTokenContext.javaDeclarationContextPath; 1317 case JAVA_EXPRESSION: 1318 return JspMultiTokenContext.javaExpressionContextPath; 1319 case JAVA_SCRIPTLET: 1320 default: 1321 return JspMultiTokenContext.javaScriptletContextPath; 1322 } 1323 } 1324 1325 1333 1334 1345 protected int canBeHostDelimiter(int tokenOffset, int endOffset, int firstTokenEnd, boolean lastPart) { 1346 int offset = tokenOffset; 1347 char actChar; 1348 1349 int possibleBeginning = DELIMCHECK_NO; 1350 StringBuffer tagString = null; 1351 int delimState = HOST_INIT; 1352 1353 while(offset < endOffset) { 1354 actChar = buffer[offset]; 1355 1356 switch (delimState) { 1357 case HOST_INIT: 1358 switch (actChar) { 1359 case '<': 1360 if (offset >= firstTokenEnd) 1361 return DELIMCHECK_NO; 1362 delimState = HOST_LT; 1363 possibleBeginning = offset; 1364 break; 1365 case '$': 1366 case '#': 1367 if (offset >= firstTokenEnd) 1368 return DELIMCHECK_NO; 1369 if (!isELIgnored(false)) { 1370 delimState = HOST_D; 1371 possibleBeginning = offset; 1372 } 1373 break; 1374 case '\\': 1375 if (offset >= firstTokenEnd) 1376 return DELIMCHECK_NO; 1377 delimState = HOST_BS; 1378 possibleBeginning = offset; break; 1380 default: 1381 if (offset >= firstTokenEnd) 1382 return DELIMCHECK_NO; 1383 break; 1384 } 1385 break; 1386 1387 case HOST_LT: 1388 if (Character.isLetter(actChar) || 1389 (actChar == '_') 1390 ) { delimState = HOST_TAG; 1392 tagString = new StringBuffer (); 1393 tagString.append(actChar); 1394 break; } 1396 1397 switch (actChar) { 1398 case '\n': 1399 delimState = HOST_INIT; 1400 break; 1401 case '%': 1402 delimState = HOST_LT_PC; 1403 break; 1404 case '/': 1405 delimState = HOST_LT_SLASH; 1406 break; 1407 case ' ': 1408 case '\t': 1409 delimState = HOST_LT_BLANK; 1410 break; 1411 default: 1412 delimState = HOST_INIT; 1413 offset--; 1414 break; 1415 } 1416 break; 1417 1418 case HOST_LT_SLASH: 1419 if (Character.isLetter(actChar) || 1420 (actChar == '_') 1421 ) { delimState = HOST_TAG; 1423 tagString = new StringBuffer (); 1424 tagString.append(actChar); 1425 break; } 1427 1428 switch (actChar) { 1429 case '\n': 1430 delimState = HOST_INIT; 1431 break; 1432 case ' ': 1433 case '\t': 1434 delimState = HOST_LT_BLANK; 1435 break; 1436 default: 1437 delimState = HOST_INIT; 1438 offset--; 1439 break; 1440 } 1441 break; 1442 1443 case HOST_LT_BLANK: 1444 if (Character.isLetter(actChar) || 1445 (actChar == '_') || 1446 (actChar == '/') 1447 ) { delimState = HOST_TAG; 1449 tagString = new StringBuffer (); 1452 if(actChar != '/') tagString.append(actChar); 1454 break; } 1456 1457 switch (actChar) { 1458 case '\n': 1459 delimState = HOST_INIT; 1460 break; 1461 case ' ': 1462 case '\t': 1463 break; 1464 default: 1465 delimState = HOST_INIT; 1466 offset--; 1467 break; 1468 } 1469 break; 1470 1471 case HOST_TAG: 1472 if (Character.isLetter(actChar) || 1473 Character.isDigit(actChar) || 1474 (actChar == ':') || 1475 (actChar == '-') || 1476 (actChar == '_') 1477 ) { tagString.append(actChar); 1479 break; } 1481 1482 switch (actChar) { 1483 default: 1484 if (isJspTag(tagString.toString())) { 1485 state = ISI_HOST_JSPTAG; 1486 return possibleBeginning; 1489 } 1490 else { 1491 delimState = HOST_INIT; 1492 offset--; 1493 break; 1494 } 1495 } 1496 break; 1497 1498 case HOST_LT_PC: 1499 switch (actChar) { 1500 case '@': case '-': state = ISI_HOST_JSPTAG; 1503 return possibleBeginning; 1506 case '!': javaNestMode = JAVA_DECLARATION; 1508 state = ISI_HOST_JAVA; 1509 return possibleBeginning; 1512 1513 case '=': javaNestMode = JAVA_EXPRESSION; 1515 state = ISI_HOST_JAVA; 1516 return possibleBeginning; 1519 default: javaNestMode = JAVA_SCRIPTLET; 1521 state = ISI_HOST_JAVA; 1522 return possibleBeginning; 1525 } 1526 1528 case HOST_D: 1529 switch (actChar) { 1530 case '\n': 1531 delimState = HOST_INIT; 1532 break; 1533 case '{': 1534 state = ISI_HOST_EL; 1535 return possibleBeginning; 1536 default: 1537 delimState = HOST_INIT; 1538 offset--; 1539 break; 1540 } 1541 break; 1542 1543 case HOST_BS: 1544 switch (actChar) { 1545 case '<': 1546 if (offset >= firstTokenEnd) 1547 return DELIMCHECK_NO; 1548 delimState = HOST_LT; 1549 possibleBeginning = offset; 1550 break; 1551 case '\\': 1552 if (offset >= firstTokenEnd) 1553 return DELIMCHECK_NO; 1554 possibleBeginning = offset; break; 1556 default: 1557 delimState = HOST_INIT; 1558 break; 1559 } 1560 break; 1561 } 1562 1563 offset++; 1564 } 1565 1566 if (lastPart) { 1567 switch (delimState) { 1568 case HOST_LT_PC: 1569 state = ISI_HOST_JAVA; 1570 return possibleBeginning; 1571 case HOST_TAG: 1572 if (isJspTag(tagString.toString())) { 1573 state = ISI_HOST_JSPTAG; 1574 return possibleBeginning; 1577 } 1578 } 1579 } 1580 1581 switch (delimState) { 1583 case HOST_INIT: 1584 return DELIMCHECK_NO; 1585 case HOST_LT: 1586 case HOST_LT_SLASH: 1587 case HOST_LT_PC: 1588 case HOST_LT_BLANK: 1589 case HOST_TAG: 1590 case HOST_D: 1591 case HOST_BS: 1592 return DELIMCHECK_PART; 1593 default: 1594 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("invalid state")); return DELIMCHECK_NO; 1596 } 1597 } 1598 1599 1610 protected int canBeJspTagDelimiter(int tokenOffset, int endOffset, int firstTokenEnd, boolean lastPart, boolean isComment) { 1611 if (isComment) 1612 return DELIMCHECK_NO; 1613 1614 int offset = tokenOffset; 1615 char actChar; 1616 1617 int possibleBeginning = DELIMCHECK_NO; 1618 int delimState = JSPTAG_INIT; 1619 1620 while(offset < endOffset) { 1621 actChar = buffer[offset]; 1622 1623 switch (delimState) { 1624 case JSPTAG_INIT: 1625 switch (actChar) { 1626 case '<': 1627 if (offset >= firstTokenEnd) 1628 return DELIMCHECK_NO; 1629 delimState = JSPTAG_LT; 1630 possibleBeginning = offset; 1631 break; 1632 case '$': 1633 case '#': 1634 if (offset >= firstTokenEnd) 1635 return DELIMCHECK_NO; 1636 if (!isELIgnored(true)) { 1637 delimState = JSPTAG_D; 1638 possibleBeginning = offset; 1639 } 1640 break; 1641 case '\\': 1642 if (offset >= firstTokenEnd) 1643 return DELIMCHECK_NO; 1644 delimState = JSPTAG_BS; 1645 possibleBeginning = offset; break; 1647 default: 1648 if (offset >= firstTokenEnd) 1649 return DELIMCHECK_NO; 1650 break; 1651 } 1652 break; 1653 1654 case JSPTAG_LT: 1655 switch (actChar) { 1656 case '\n': 1657 delimState = JSPTAG_INIT; 1658 break; 1659 case '%': 1660 delimState = JSPTAG_LT_PC; 1661 break; 1662 default: 1663 delimState = JSPTAG_INIT; 1664 offset--; 1665 break; 1666 } 1667 break; 1668 1669 case JSPTAG_LT_PC: 1670 switch (actChar) { 1671 case '!': javaNestMode = JAVA_DECLARATION; 1673 state = ISI_JSPTAG_JAVA; 1674 return possibleBeginning; 1677 1678 case '=': javaNestMode = JAVA_EXPRESSION; 1680 state = ISI_JSPTAG_JAVA; 1681 return possibleBeginning; 1684 case '@': case '-': delimState = JSPTAG_INIT; 1687 break; 1688 default: javaNestMode = JAVA_SCRIPTLET; 1690 state = ISI_JSPTAG_JAVA; 1691 return possibleBeginning; 1694 } 1695 1697 case JSPTAG_D: 1698 switch (actChar) { 1699 case '\n': 1700 delimState = JSPTAG_INIT; 1701 break; 1702 case '{': 1703 state = ISI_JSPTAG_EL; 1704 return possibleBeginning; 1705 default: 1706 delimState = JSPTAG_INIT; 1707 offset--; 1708 break; 1709 } 1710 break; 1711 1712 case JSPTAG_BS: 1713 switch (actChar) { 1714 case '<': 1715 if (offset >= firstTokenEnd) 1716 return DELIMCHECK_NO; 1717 delimState = JSPTAG_LT; 1718 possibleBeginning = offset; 1719 break; 1720 case '\\': 1721 if (offset >= firstTokenEnd) 1722 return DELIMCHECK_NO; 1723 possibleBeginning = offset; break; 1725 default: 1726 delimState = JSPTAG_INIT; 1727 break; 1728 } 1729 break; 1730 } 1731 1732 offset++; 1733 } 1734 1735 if (lastPart) { 1736 switch (delimState) { 1737 case JSPTAG_LT_PC: 1738 state = ISI_JSPTAG_JAVA; 1739 return possibleBeginning; 1742 } 1743 } 1744 1745 switch (delimState) { 1747 case JSPTAG_INIT: 1748 return DELIMCHECK_NO; 1749 case JSPTAG_LT: 1750 return DELIMCHECK_PART; 1751 case JSPTAG_LT_PC: 1752 return DELIMCHECK_PART; 1753 case JSPTAG_D: 1754 return DELIMCHECK_PART; 1755 case JSPTAG_BS: 1756 return DELIMCHECK_NO; 1759 default: 1760 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("invalid state " + delimState)); return DELIMCHECK_NO; 1762 } 1763 } 1764 1765 1776 protected int canBeJavaDelimiter(int tokenOffset, int endOffset, int firstTokenEnd, boolean lastPart, int myNestMode) { 1777 int offset = tokenOffset; 1778 char actChar; 1779 1780 int possibleBeginning = DELIMCHECK_NO; 1781 int delimState = JAVA_INIT; 1782 1783 while(offset < endOffset) { 1784 actChar = buffer[offset]; 1785 1786 switch (delimState) { 1787 case JAVA_INIT: 1788 switch (actChar) { 1789 case '%': 1790 if (offset >= firstTokenEnd) 1791 return DELIMCHECK_NO; 1792 delimState = JAVA_PC; 1793 possibleBeginning = offset; 1794 break; 1795 default: 1796 if (offset >= firstTokenEnd) 1797 return DELIMCHECK_NO; 1798 break; 1799 } 1800 break; 1801 1802 case JAVA_PC: 1803 switch (actChar) { 1804 case '>': 1805 switch (myNestMode) { 1806 case MODE_HOST_JSPTAG_JAVA: 1807 state = ISI_JAVA1_SWITCH; 1808 return possibleBeginning; 1811 case MODE_HOST_JAVA: 1812 state = ISI_JAVA2_SWITCH; 1813 return possibleBeginning; 1816 } 1817 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad nestMode")); case '%': 1820 if (offset >= firstTokenEnd) 1821 return DELIMCHECK_NO; 1822 delimState = JAVA_PC; 1823 possibleBeginning = offset; 1824 break; 1825 default: 1826 delimState = JAVA_INIT; 1827 break; 1828 } 1829 break; 1830 } 1831 1832 offset++; 1833 } 1834 1835 switch (delimState) { 1837 case JAVA_INIT: 1838 return DELIMCHECK_NO; 1839 case JAVA_PC: 1840 return DELIMCHECK_PART; 1841 default: 1842 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("invalid state")); return DELIMCHECK_NO; 1844 } 1845 } 1846 1847 1858 protected int canBeELDelimiter(int tokenOffset, int endOffset, int firstTokenEnd, boolean lastPart, int myNestMode) { 1859 int offset = tokenOffset; 1860 char actChar; 1861 1862 int possibleBeginning = DELIMCHECK_NO; 1863 int delimState = EL_INIT; 1864 1865 while(offset < endOffset) { 1866 actChar = buffer[offset]; 1867 1868 switch (delimState) { 1869 case EL_INIT: switch (actChar) { 1871 case '}': 1872 if (offset >= firstTokenEnd) 1873 return DELIMCHECK_NO; 1874 possibleBeginning = offset; 1875 switch (myNestMode) { 1876 case MODE_HOST_JSPTAG_EL: 1877 state = ISI_EL1_SWITCH; 1878 return possibleBeginning; 1881 case MODE_HOST_EL: 1882 state = ISI_EL2_SWITCH; 1883 return possibleBeginning; 1886 } 1887 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("bad nestMode")); break; 1889 default: 1890 if (offset >= firstTokenEnd) 1891 return DELIMCHECK_NO; 1892 break; 1893 } 1894 break; 1895 } 1896 1897 offset++; 1898 } 1899 1900 switch (delimState) { 1902 case EL_INIT: 1903 return DELIMCHECK_NO; 1904 default: 1905 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception ("invalid state")); return DELIMCHECK_NO; 1907 } 1908 } 1909 1910 1911 protected boolean isJspTag(String tagName) { 1912 boolean canBeJsp = tagName.startsWith("jsp:"); return canBeJsp; 1914 } 1915 1916 1924 protected boolean isELIgnored(boolean inJspTag) { 1925 return false; 1926 } 1927 1928 1934 protected boolean isXMLSyntax(){ 1935 return false; 1936 } 1937 1938 private void transferMasterToSlave(Syntax slave, StateInfo stateInfo) { 1939 slave.load(stateInfo, buffer, offset, stopOffset - offset, lastBuffer, -1); 1940 } 1943 1944 1945 public void storeState(StateInfo stateInfo) { 1946 super.storeState(stateInfo); 1947 JspStateInfo jspsi = (JspStateInfo)stateInfo; 1948 jspsi.nestMode = nestMode; 1950 jspsi.javaNestMode = javaNestMode; 1951 1952 if (hostStateInfo == null) { 1954 jspsi.hostStateInfo = null; 1955 } 1956 else { 1957 jspsi.hostStateInfo = hostSyntax.createStateInfo(); 1958 hostSyntax.load(hostStateInfo, buffer, offset, 0, false, -1); 1959 hostSyntax.storeState(jspsi.hostStateInfo); 1960 } 1961 if (jspTagStateInfo == null) { 1962 jspsi.jspTagStateInfo = null; 1963 } 1964 else { 1965 jspsi.jspTagStateInfo = jspTagSyntax.createStateInfo(); 1966 jspTagSyntax.load(jspTagStateInfo, buffer, offset, 0, false, -1); 1967 jspTagSyntax.storeState(jspsi.jspTagStateInfo); 1968 } 1969 if (elStateInfo == null) { 1970 jspsi.elStateInfo = null; 1971 } 1972 else { 1973 jspsi.elStateInfo = elSyntax.createStateInfo(); 1974 elSyntax.load(elStateInfo, buffer, offset, 0, false, -1); 1975 elSyntax.storeState(jspsi.elStateInfo); 1976 } 1977 if (javaStateInfo == null) { 1978 jspsi.javaStateInfo = null; 1979 } 1980 else { 1981 jspsi.javaStateInfo = javaSyntax.createStateInfo(); 1982 javaSyntax.load(javaStateInfo, buffer, offset, 0, false, -1); 1983 javaSyntax.storeState(jspsi.javaStateInfo); 1984 } 1985 if (jspsi.isFirstTokenValid()) { 1987 jspsi.firstTokenID = firstTokenID; 1988 jspsi.firstTokenLength = firstTokenLength; 1989 switch (nestMode) { 1990 case MODE_HOST: 1991 jspsi.stateOfScanningAtInit = hostSyntax.createStateInfo(); 1992 hostSyntax.load(helpHostStateInfo, buffer, offset, 0, false, -1); 1993 hostSyntax.storeState(jspsi.stateOfScanningAtInit); 1994 break; 1995 case MODE_HOST_JSPTAG: 1996 jspsi.stateOfScanningAtInit = jspTagSyntax.createStateInfo(); 1997 jspTagSyntax.load(helpJspTagStateInfo, buffer, offset, 0, false, -1); 1998 jspTagSyntax.storeState(jspsi.stateOfScanningAtInit); 1999 break; 2000 case MODE_HOST_JSPTAG_EL: 2001 case MODE_HOST_EL: 2002 jspsi.stateOfScanningAtInit = elSyntax.createStateInfo(); 2003 elSyntax.load(helpELStateInfo, buffer, offset, 0, false, -1); 2004 elSyntax.storeState(jspsi.stateOfScanningAtInit); 2005 break; 2006 case MODE_HOST_JSPTAG_JAVA: 2007 case MODE_HOST_JAVA: 2008 jspsi.stateOfScanningAtInit = javaSyntax.createStateInfo(); 2009 javaSyntax.load(helpJavaStateInfo, buffer, offset, 0, false, -1); 2010 javaSyntax.storeState(jspsi.stateOfScanningAtInit); 2011 break; 2012 } 2013 } 2014 else { 2015 jspsi.stateOfScanningAtInit = null; 2016 jspsi.firstTokenID = null; 2017 jspsi.firstTokenLength = -1; 2018 } 2019 2024 } 2025 2026 public void loadState(StateInfo stateInfo) { 2027 2029 super.loadState(stateInfo); 2030 JspStateInfo jspsi = (JspStateInfo)stateInfo; 2031 nestMode = jspsi.nestMode; 2032 javaNestMode = jspsi.javaNestMode; 2033 2034 if (jspsi.hostStateInfo == null) { 2036 hostStateInfo = null; 2037 } 2038 else { 2039 hostSyntax.load(jspsi.hostStateInfo, buffer, offset, 0, false, -1); 2040 hostStateInfo = hostSyntax.createStateInfo(); 2041 hostSyntax.storeState(hostStateInfo); 2042 } 2043 if (jspsi.jspTagStateInfo == null) { 2044 jspTagStateInfo = null; 2045 } 2046 else { 2047 jspTagSyntax.load(jspsi.jspTagStateInfo, buffer, offset, 0, false, -1); 2048 jspTagStateInfo = jspTagSyntax.createStateInfo(); 2049 jspTagSyntax.storeState(jspTagStateInfo); 2050 } 2051 if (jspsi.elStateInfo == null) { 2052 elStateInfo = null; 2053 } 2054 else { 2055 elSyntax.load(jspsi.elStateInfo, buffer, offset, 0, false, -1); 2056 elStateInfo = elSyntax.createStateInfo(); 2057 elSyntax.storeState(elStateInfo); 2058 } 2059 if (jspsi.javaStateInfo == null) { 2060 javaStateInfo = null; 2061 } 2062 else { 2063 javaSyntax.load(jspsi.javaStateInfo, buffer, offset, 0, false, -1); 2064 javaStateInfo = javaSyntax.createStateInfo(); 2065 javaSyntax.storeState(javaStateInfo); 2066 } 2067 if (jspsi.isFirstTokenValid()) { 2069 firstTokenID = jspsi.firstTokenID; 2070 firstTokenLength = jspsi.firstTokenLength; 2071 switch (jspsi.nestMode) { 2072 case MODE_HOST: 2073 hostSyntax.load(jspsi.stateOfScanningAtInit, buffer, offset, 0, false, -1); 2074 hostSyntax.storeState(helpHostStateInfo); 2075 break; 2076 case MODE_HOST_JSPTAG: 2077 jspTagSyntax.load(jspsi.stateOfScanningAtInit, buffer, offset, 0, false, -1); 2078 jspTagSyntax.storeState(helpJspTagStateInfo); 2079 break; 2080 case MODE_HOST_JSPTAG_EL: 2081 case MODE_HOST_EL: 2082 elSyntax.load(jspsi.stateOfScanningAtInit, buffer, offset, 0, false, -1); 2083 elSyntax.storeState(helpELStateInfo); 2084 break; 2085 case MODE_HOST_JSPTAG_JAVA: 2086 case MODE_HOST_JAVA: 2087 javaSyntax.load(jspsi.stateOfScanningAtInit, buffer, offset, 0, false, -1); 2088 javaSyntax.storeState(helpJavaStateInfo); 2089 break; 2090 } 2091 } 2092 else { 2093 firstTokenID = null; 2094 firstTokenLength = -1; 2095 } 2096 } 2097 2098 public void loadInitState() { 2099 super.loadInitState(); 2100 nestMode = MODE_HOST; 2101 state = ISI_LANGUAGE; 2102 hostStateInfo = null; 2103 jspTagStateInfo = null; 2104 elStateInfo = null; 2105 javaStateInfo = null; 2106 firstTokenID = null; 2107 firstTokenLength = -1; 2108 } 2109 2110 public void load(StateInfo stateInfo, char buffer[], int offset, int len, boolean lastBuffer) { 2111 JspStateInfo jspsi = (JspStateInfo)stateInfo; 2112 if (jspsi == null) { 2113 hostStateInfo = null; 2114 jspTagStateInfo = null; 2115 elStateInfo = null; 2116 javaStateInfo = null; 2117 firstTokenID = null; 2118 firstTokenLength = -1; 2119 } 2120 super.load(stateInfo, buffer, offset, len, lastBuffer, -1); 2121 } 2122 2123 public StateInfo createStateInfo() { 2124 return new JspStateInfo(); 2125 } 2126 2127 public int compareState(StateInfo stateInfo) { 2128 if (super.compareState(stateInfo) == DIFFERENT_STATE) 2129 return DIFFERENT_STATE; 2130 JspStateInfo jspsi = (JspStateInfo)stateInfo; 2131 if (jspsi.nestMode != nestMode) 2132 return DIFFERENT_STATE; 2133 if (jspsi.isFirstTokenValid()) { 2134 if (jspsi.firstTokenID != firstTokenID) 2135 return DIFFERENT_STATE; 2136 if (jspsi.firstTokenLength != firstTokenLength) 2137 return DIFFERENT_STATE; 2138 } 2139 if(jspsi.javaNestMode != javaNestMode) return DIFFERENT_STATE; 2140 int ret; 2141 switch (nestMode) { 2142 case MODE_HOST: 2143 transferMasterToSlave(hostSyntax, hostStateInfo); 2145 ret = hostSyntax.compareState(jspsi.hostStateInfo); 2146 if (ret == DIFFERENT_STATE) return ret; 2147 if (jspsi.isFirstTokenValid()) { 2148 transferMasterToSlave(hostSyntax, helpHostStateInfo); 2149 ret = hostSyntax.compareState(jspsi.stateOfScanningAtInit); 2150 if (ret == DIFFERENT_STATE) return ret; 2151 } 2152 break; 2153 case MODE_HOST_JSPTAG: 2154 transferMasterToSlave(hostSyntax, hostStateInfo); 2156 ret = hostSyntax.compareState(jspsi.hostStateInfo); 2157 if (ret == Syntax.DIFFERENT_STATE) return ret; 2158 transferMasterToSlave(jspTagSyntax, jspTagStateInfo); 2160 ret = jspTagSyntax.compareState(jspsi.jspTagStateInfo); 2161 if (ret == DIFFERENT_STATE) return ret; 2162 if (jspsi.isFirstTokenValid()) { 2163 transferMasterToSlave(jspTagSyntax, helpJspTagStateInfo); 2164 ret = jspTagSyntax.compareState(jspsi.stateOfScanningAtInit); 2165 if (ret == DIFFERENT_STATE) return ret; 2166 } 2167 break; 2168 case MODE_HOST_JSPTAG_EL: 2169 transferMasterToSlave(hostSyntax, hostStateInfo); 2171 ret = hostSyntax.compareState(jspsi.hostStateInfo); 2172 if (ret == DIFFERENT_STATE) return ret; 2173 transferMasterToSlave(jspTagSyntax, jspTagStateInfo); 2175 ret = jspTagSyntax.compareState(jspsi.jspTagStateInfo); 2176 if (ret == DIFFERENT_STATE) return ret; 2177 transferMasterToSlave(elSyntax, elStateInfo); 2179 ret = elSyntax.compareState(jspsi.elStateInfo); 2180 if (ret == DIFFERENT_STATE) return ret; 2181 if (jspsi.isFirstTokenValid()) { 2182 transferMasterToSlave(elSyntax, helpELStateInfo); 2183 ret = elSyntax.compareState(jspsi.stateOfScanningAtInit); 2184 if (ret == DIFFERENT_STATE) return ret; 2185 } 2186 break; 2187 case MODE_HOST_EL: 2188 transferMasterToSlave(hostSyntax, hostStateInfo); 2190 ret = hostSyntax.compareState(jspsi.hostStateInfo); 2191 if (ret == DIFFERENT_STATE) return ret; 2192 transferMasterToSlave(elSyntax, elStateInfo); 2194 ret = elSyntax.compareState(jspsi.elStateInfo); 2195 if (ret == DIFFERENT_STATE) return ret; 2196 if (jspsi.isFirstTokenValid()) { 2197 transferMasterToSlave(elSyntax, helpELStateInfo); 2198 ret = elSyntax.compareState(jspsi.stateOfScanningAtInit); 2199 if (ret == DIFFERENT_STATE) return ret; 2200 } 2201 break; 2202 case MODE_HOST_JSPTAG_JAVA: 2203 transferMasterToSlave(hostSyntax, hostStateInfo); 2205 ret = hostSyntax.compareState(jspsi.hostStateInfo); 2206 if (ret == DIFFERENT_STATE) return ret; 2207 transferMasterToSlave(jspTagSyntax, jspTagStateInfo); 2209 ret = jspTagSyntax.compareState(jspsi.jspTagStateInfo); 2210 if (ret == DIFFERENT_STATE) return ret; 2211 transferMasterToSlave(javaSyntax, javaStateInfo); 2213 ret = javaSyntax.compareState(jspsi.javaStateInfo); 2214 if (ret == DIFFERENT_STATE) return ret; 2215 if (jspsi.isFirstTokenValid()) { 2216 transferMasterToSlave(javaSyntax, helpJavaStateInfo); 2217 ret = javaSyntax.compareState(jspsi.stateOfScanningAtInit); 2218 if (ret == DIFFERENT_STATE) return ret; 2219 } 2220 break; 2221 case MODE_HOST_JAVA: 2222 transferMasterToSlave(hostSyntax, hostStateInfo); 2224 ret = hostSyntax.compareState(jspsi.hostStateInfo); 2225 if (ret == DIFFERENT_STATE) return ret; 2226 transferMasterToSlave(javaSyntax, javaStateInfo); 2228 ret = javaSyntax.compareState(jspsi.javaStateInfo); 2229 if (ret == DIFFERENT_STATE) return ret; 2230 if (jspsi.isFirstTokenValid()) { 2231 transferMasterToSlave(javaSyntax, helpJavaStateInfo); 2232 ret = javaSyntax.compareState(jspsi.stateOfScanningAtInit); 2233 if (ret == DIFFERENT_STATE) return ret; 2234 } 2235 break; 2236 } 2237 return EQUAL_STATE; 2238 } 2239 2240 public String getNestModeName (int nestMode){ 2241 switch (nestMode){ 2242 case MODE_HOST: 2243 return "MODE_HOST"; case MODE_HOST_JSPTAG: 2245 return "MODE_HOST_JSPTAG"; case MODE_HOST_EL: 2247 return "MODE_HOST_EL"; case MODE_HOST_JSPTAG_EL: 2249 return "MODE_HOST_JSPTAG_EL"; case MODE_HOST_JSPTAG_JAVA: 2251 return "MODE_HOST_JSPTAG_JAVA"; case MODE_HOST_JAVA: 2253 return "MODE_HOST_JAVA"; default: 2255 return "unknown nestMode " + nestMode; } 2257 } 2258 2259 public String getStateName(int stateNumber) { 2260 switch(stateNumber) { 2261 case ISI_LANGUAGE: 2262 return "ISI_LANGUAGE"; case ISI_HOST_JSPTAG: 2264 return "ISI_HOST_JSPTAG"; case ISI_HOST_JAVA: 2266 return "ISI_HOST_JAVA"; case ISI_HOST_JAVA_LT: 2268 return "ISI_HOST_JAVA_LT"; case ISI_HOST_JAVA_LT_PC: 2270 return "ISI_HOST_JAVA_LT_PC"; case ISI_HOST_JAVA_JUMP: 2272 return "ISI_HOST_JAVA_JUMP"; case ISI_HOST_EL: 2274 return "ISI_HOST_EL"; case ISI_HOST_EL_D: 2276 return "ISI_HOST_EL_D"; case ISI_HOST_EL_JUMP: 2278 return "ISI_HOST_EL_JUMP"; case ISI_JSPTAG_JAVA: 2280 return "ISI_JSPTAG_JAVA"; case ISI_JSPTAG_JAVA_LT: 2282 return "ISI_JSPTAG_JAVA_LT"; case ISI_JSPTAG_JAVA_LT_PC: 2284 return "ISI_JSPTAG_JAVA_LT_PC"; case ISI_JSPTAG_JAVA_JUMP: 2286 return "ISI_JSPTAG_JAVA_JUMP"; case ISI_JSPTAG_EL: 2288 return "ISI_JSPTAG_EL"; case ISI_JSPTAG_EL_D: 2290 return "ISI_JSPTAG_EL_D"; case ISI_JSPTAG_EL_JUMP: 2292 return "ISI_JSPTAG_EL_JUMP"; case ISI_JAVA1_SWITCH: 2294 return "ISI_JAVA1_SWITCH"; case ISI_JAVA1_PC: 2296 return "ISI_JAVA1_PC"; case ISI_JAVA1_JUMP: 2298 return "ISI_JAVA1_JUMP"; case ISI_JAVA2_SWITCH: 2300 return "ISI_JAVA2_SWITCH"; case ISI_JAVA2_PC: 2302 return "ISI_JAVA2_PC"; case ISI_JAVA2_JUMP: 2304 return "ISI_JAVA2_JUMP"; case ISI_EL1_SWITCH: 2306 return "ISI_EL1_SWITCH"; case ISI_EL1_JUMP: 2308 return "ISI_EL1_JUMP"; case ISI_EL2_SWITCH: 2310 return "ISI_EL2_SWITCH"; case ISI_EL2_JUMP: 2312 return "ISI_EL2_JUMP"; default: 2314 return super.getStateName(stateNumber); } 2316 2317 2319 } 2320 2321 2322 public static class JspStateInfo extends BaseStateInfo { 2323 2324 int nestMode; 2325 StateInfo hostStateInfo; 2326 StateInfo jspTagStateInfo; 2327 StateInfo elStateInfo; 2328 StateInfo javaStateInfo; 2329 2330 2331 StateInfo stateOfScanningAtInit; 2332 2333 int javaNestMode; 2335 2336 2337 TokenID firstTokenID; 2338 2339 2340 int firstTokenLength; 2341 2342 public boolean isFirstTokenValid() { 2343 return (JspStateInfo.this.getPreScan() != 0); 2344 } 2345 2346 public String toString(Syntax s) { 2347 return "JspStateInfo state=" + getState() + ", prescan=" + JspStateInfo.this.getPreScan() + ", nestMode=" + nestMode + ((JspStateInfo.this.getPreScan() == 0) ? "" : "\n firstTokenID=" + firstTokenID + ", firstTokenLength=" + firstTokenLength) + "\n hostStateInfo=" + (hostStateInfo == null ? "null" : ((BaseStateInfo)hostStateInfo).toString(s)) + "\n jspTagStateInfo=" + (jspTagStateInfo == null ? "null" : ((BaseStateInfo)jspTagStateInfo).toString(s)) + "\n elStateInfo=" + (elStateInfo == null ? "null" : ((BaseStateInfo)elStateInfo).toString(s)) + "\n javaStateInfo=" + (javaStateInfo == null ? "null" : ((BaseStateInfo)javaStateInfo).toString(s)) + "\n scanning Info=" + (stateOfScanningAtInit == null ? "null" : ((BaseStateInfo)stateOfScanningAtInit).toString(s)); } 2357 } 2358 2359 2360} 2361 | Popular Tags |