alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
  *                 Sun Public License Notice
  * 
  * The contents of this file are subject to the Sun Public License
  * Version 1.0 (the "License"). You may not use this file except in
  * compliance with the License. A copy of the License is available at
  * http://www.sun.com/
  * 
  * The Original Code is NetBeans. The Initial Developer of the Original
  * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
  * Microsystems, Inc. All Rights Reserved.
  */

package org.netbeans.modules.web.core.syntax;

import org.openide.ErrorManager;
import org.netbeans.editor.Syntax;
import org.netbeans.editor.TokenID;
import org.netbeans.editor.ext.html.HTMLTokenContext;

/** 
* Syntax for JSP files. This is a MultiSyntax consisting of three slave syntaxes: 
* content language syntax (for example HTMLSyntax), JspTagSyntax and scripting 
* language syntax (for example JavaSyntax). The content language and scripting language
* syntaxes are completely pluggable, moreover, they can be changed dynamically by 
* setContentSyntax() and setScriptingSyntax() methods. The caller of these methods should 
* make sure that the whole document is recolored after calling these methods.
*
* @author Petr Jiricka
* @version 1.00
*/

public class JspMultiSyntax extends Syntax {

    // modes of nesting of languages
    public static final int MODE_HOST             = 1;
    public static final int MODE_HOST_JSPTAG      = 2;
    public static final int MODE_HOST_EL          = 5;
    public static final int MODE_HOST_JSPTAG_EL   = 6;
    public static final int MODE_HOST_JSPTAG_JAVA = 3;
    public static final int MODE_HOST_JAVA        = 4;
                                 
    // constants for result of operation of checking delimiters                               
    protected static final int DELIMCHECK_NO = -1;
    protected static final int DELIMCHECK_PART = -2;
  
    // states of this multisyntax
    private static final int ISI_LANGUAGE = 1; // one syntax is active and working
    // states for switching from the host language to JSP tag or Java or EL
    private static final int ISI_HOST_JSPTAG = 2; // just before  in Java (go to JSPTAG)
    private static final int ISI_JAVA1_PC = 12; // as ISI_JAVA1_SWITCH after %
    private static final int ISI_JAVA1_JUMP = 13; // after %> in Java, now really switch to JSPTAG
    // states for switching from Java to host
    private static final int ISI_JAVA2_SWITCH = 14; // just before %> in Java (go to host)
    private static final int ISI_JAVA2_PC = 15; // as ISI_JAVA2_SWITCH after %
    private static final int ISI_JAVA2_JUMP = 16; // after %> in Java, now really switch to host
    // states for switching from EL to a JSP tag
    private static final int ISI_EL1_SWITCH = 25; // just before } in EL (go to JSPTAG)
    private static final int ISI_EL1_JUMP = 26; // after } in EL, now really switch to JSPTAG
    // states for switching from EL to host
    private static final int ISI_EL2_SWITCH = 27; // just before } in EL (go to host)
    private static final int ISI_EL2_JUMP = 28; // after } in EL, now really switch to host
  
    // states of the automaton which looks for delimiters in the host language
    private static final int HOST_INIT = 1; // initial state - host language
    private static final int HOST_LT = 2; // after < - host language
    private static final int HOST_LT_PC = 3; // after <% - host language
    private static final int HOST_LT_BLANK = 4; // after < or 
    *  
  • 'Regular' stateinfos contain the state of all active languages at 'offset'. For inactive * languages they are null.
  • *
  • If tokenOffset != offset, the scanning 'help' stateinfo contains the state of the scanning * language at 'tokenOffset'.
  • *
  • If tokenOffset != offset, firstTokenID contains the token returned by the first call of * slave's nextToken() in the current token, may be null !
  • * */ protected TokenID parseToken() { //debug = (tokenOffset != offset); //debug = !((tokenOffset == offset) || (firstTokenID == null)); // !firstTokenNotRead //if (debug) //System.out.println("parseToken tokenOffset=" + tokenOffset + ", offset=" + offset + ", state=" + state + //", nestMode=" + nestMode + ", stopOffset=" + stopOffset + ", lastBuffer=" + lastBuffer); if (state != ISI_LANGUAGE) { char actChar; while(offset < stopOffset) { actChar = buffer[offset]; // System.out.println("JspMultiSyntax: parseToken tokenOffset=" + tokenOffset + ", actChar='" + actChar + ", offset=" + offset + ", state=" + getStateName(state) + // ", nestMode=" + getNestModeName( nestMode) + ", stopOffset=" + stopOffset + ", lastBuffer=" + lastBuffer); switch (state) { case ISI_HOST_JSPTAG: // switch to JspTagSyntax //if (debug) //System.out.println("switching from HOST to JSPTAG, hostState " + ((BaseStateInfo)hostStateInfo).toString(this)); nestMode = MODE_HOST_JSPTAG; state = ISI_LANGUAGE; transferMasterToSlave(jspTagSyntax, null); //jspTagSyntax.load(null, buffer, offset, stopOffset - offset, lastBuffer); if (jspTagStateInfo == null) { jspTagStateInfo = jspTagSyntax.createStateInfo(); } jspTagSyntax.storeState(jspTagStateInfo); break; case ISI_HOST_JAVA: // switch from hostSyntax to JavaSyntax switch (actChar) { case '<': state = ISI_HOST_JAVA_LT; break; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } // switch (actChar) break; case ISI_HOST_JAVA_LT: switch (actChar) { case '%': state = ISI_HOST_JAVA_LT_PC; break; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } // switch (actChar) break; case ISI_HOST_JAVA_LT_PC: switch (actChar) { case '!': // declaration case '=': // expression state = ISI_HOST_JAVA_JUMP; offset++; tokenContextPath = JspMultiTokenContext.jspTagContextPath; return JspTagTokenContext.SYMBOL2; default: // assume this is a scriptlet state = ISI_HOST_JAVA_JUMP; tokenContextPath = JspMultiTokenContext.jspTagContextPath; return JspTagTokenContext.SYMBOL2; } // switch (actChar) // break; - not reached case ISI_HOST_JAVA_JUMP: nestMode = MODE_HOST_JAVA; state = ISI_LANGUAGE; transferMasterToSlave(javaSyntax, null); //javaSyntax.load(null, buffer, offset, stopOffset - offset, lastBuffer); if (javaStateInfo == null) { javaStateInfo = javaSyntax.createStateInfo(); } javaSyntax.storeState(javaStateInfo); break; case ISI_HOST_EL: // switch from hostSyntax to ELSyntax switch (actChar) { case '$': state = ISI_HOST_EL_D; break; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } // switch (actChar) break; case ISI_HOST_EL_D: switch (actChar) { case '{': // EL expression state = ISI_HOST_EL_JUMP; offset++; tokenContextPath = JspMultiTokenContext.elContextPath; return ELTokenContext.EL_DELIM; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } // switch (actChar) break; case ISI_HOST_EL_JUMP: nestMode = MODE_HOST_EL; state = ISI_LANGUAGE; transferMasterToSlave(elSyntax, null); //elSyntax.load(null, buffer, offset, stopOffset - offset, lastBuffer); if (elStateInfo == null) { elStateInfo = elSyntax.createStateInfo(); } elSyntax.storeState(elStateInfo); break; case ISI_JSPTAG_JAVA: // switch from JSP tag to JavaSyntax switch (actChar) { case '<': state = ISI_JSPTAG_JAVA_LT; break; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } // switch (actChar) break; case ISI_JSPTAG_JAVA_LT: switch (actChar) { case '%': state = ISI_JSPTAG_JAVA_LT_PC; break; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } // switch (actChar) break; case ISI_JSPTAG_JAVA_LT_PC: switch (actChar) { case '!': // declaration case '=': // expression state = ISI_JSPTAG_JAVA_JUMP; offset++; //if (debug) //System.out.println("returning (1x) pos " + offset + " symbol " + getTokenName(JspTagSyntax.JSP_SYMBOL2 + jspTagSyntaxInfo.tokenIDShift)); tokenContextPath = JspMultiTokenContext.jspTagContextPath; return JspTagTokenContext.SYMBOL2; default: // assume this is a scriptlet state = ISI_JSPTAG_JAVA_JUMP; //if (debug) //System.out.println("returning (2x) pos " + offset + " symbol " + getTokenName(JspTagSyntax.JSP_SYMBOL2 + jspTagSyntaxInfo.tokenIDShift)); tokenContextPath = JspMultiTokenContext.jspTagContextPath; return JspTagTokenContext.SYMBOL2; } // switch (actChar) // break; - not reached case ISI_JSPTAG_JAVA_JUMP: nestMode = MODE_HOST_JSPTAG_JAVA; state = ISI_LANGUAGE; transferMasterToSlave(javaSyntax, null); //javaSyntax.load(null, buffer, offset, stopOffset - offset, lastBuffer); if (javaStateInfo == null) { javaStateInfo = javaSyntax.createStateInfo(); } javaSyntax.storeState(javaStateInfo); break; case ISI_JSPTAG_EL: // switch from JspTagSyntax to ELSyntax switch (actChar) { case '$': state = ISI_JSPTAG_EL_D; break; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } // switch (actChar) break; case ISI_JSPTAG_EL_D: switch (actChar) { case '{': // EL expression state = ISI_JSPTAG_EL_JUMP; offset++; tokenContextPath = JspMultiTokenContext.elContextPath; return ELTokenContext.EL_DELIM; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } // switch (actChar) break; case ISI_JSPTAG_EL_JUMP: nestMode = MODE_HOST_JSPTAG_EL; state = ISI_LANGUAGE; transferMasterToSlave(elSyntax, null); //elSyntax.load(null, buffer, offset, stopOffset - offset, lastBuffer); if (elStateInfo == null) { elStateInfo = elSyntax.createStateInfo(); } elSyntax.storeState(elStateInfo); break; // switching from Java back to JSPTAG case ISI_JAVA1_SWITCH: switch (actChar) { case '%': state = ISI_JAVA1_PC; break; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } // switch (actChar) break; case ISI_JAVA1_PC: switch (actChar) { case '>': state = ISI_JAVA1_JUMP; offset++; //if (debug) //System.out.println("returning (1xx) pos " + offset + " symbol " + getTokenName(JspTagSyntax.JSP_SYMBOL2 + jspTagSyntaxInfo.tokenIDShift)); tokenContextPath = JspMultiTokenContext.jspTagContextPath; return JspTagTokenContext.SYMBOL2; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } case ISI_JAVA1_JUMP: nestMode = MODE_HOST_JSPTAG; jspTagStateInfo.setPreScan(0); state = ISI_LANGUAGE; javaStateInfo = null; break; // switching from Java back to host case ISI_JAVA2_SWITCH: switch (actChar) { case '%': state = ISI_JAVA2_PC; break; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } // switch (actChar) break; case ISI_JAVA2_PC: switch (actChar) { case '>': state = ISI_JAVA2_JUMP; offset++; //if (debug) //System.out.println("returning (2xx) pos " + offset + " symbol " + getTokenName(JspTagSyntax.JSP_SYMBOL2 + jspTagSyntaxInfo.tokenIDShift)); tokenContextPath = JspMultiTokenContext.jspTagContextPath; return JspTagTokenContext.SYMBOL2; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } case ISI_JAVA2_JUMP: nestMode = MODE_HOST; hostStateInfo.setPreScan(0); state = ISI_LANGUAGE; javaStateInfo = null; break; // switching from EL back to JSPTAG case ISI_EL1_SWITCH: switch (actChar) { case '}': state = ISI_EL1_JUMP; offset++; //if (debug) //System.out.println("returning (1xx) pos " + offset + " symbol " + getTokenName(ELSyntax.ED_DELIM + elSyntaxInfo.tokenIDShift)); tokenContextPath = JspMultiTokenContext.elContextPath; return ELTokenContext.EL_DELIM; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } // switch (actChar) break; case ISI_EL1_JUMP: nestMode = MODE_HOST_JSPTAG; jspTagStateInfo.setPreScan(0); state = ISI_LANGUAGE; elStateInfo = null; break; // switching from EL back to host case ISI_EL2_SWITCH: switch (actChar) { case '}': state = ISI_EL2_JUMP; offset++; //if (debug) //System.out.println("returning (1xx) pos " + offset + " symbol " + getTokenName(ELSyntax.ED_DELIM + elSyntaxInfo.tokenIDShift)); tokenContextPath = JspMultiTokenContext.elContextPath; return ELTokenContext.EL_DELIM; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad hostsyntax analyzer")); // NOI18N } // switch (actChar) break; case ISI_EL2_JUMP: nestMode = MODE_HOST; hostStateInfo.setPreScan(0); state = ISI_LANGUAGE; elStateInfo = null; break; } if (state == ISI_LANGUAGE) break; offset = ++offset; } // end of while(offset...) if (state != ISI_LANGUAGE) { /** At this stage there's no more text in the scanned buffer. * Scanner first checks whether this is completely the last * available buffer. */ if (lastBuffer) { switch(state) { case ISI_HOST_JSPTAG: case ISI_HOST_JAVA: case ISI_HOST_JAVA_LT: case ISI_HOST_JAVA_LT_PC: case ISI_HOST_JAVA_JUMP: case ISI_JSPTAG_JAVA: case ISI_JSPTAG_JAVA_LT: case ISI_JSPTAG_JAVA_LT_PC: case ISI_JSPTAG_JAVA_JUMP: case ISI_JAVA1_SWITCH: case ISI_JAVA1_PC: case ISI_JAVA1_JUMP: case ISI_JAVA2_SWITCH: case ISI_JAVA2_PC: case ISI_JAVA2_JUMP: //if (debug) //System.out.println("returning (3) pos " + offset + " symbol " + getTokenName(JspTagSyntax.JSP_SYMBOL2 + jspTagSyntaxInfo.tokenIDShift)); tokenContextPath = JspMultiTokenContext.jspTagContextPath; return JspTagTokenContext.SYMBOL2; case ISI_HOST_EL: case ISI_HOST_EL_D: case ISI_HOST_EL_JUMP: case ISI_JSPTAG_EL: case ISI_JSPTAG_EL_D: case ISI_JSPTAG_EL_JUMP: case ISI_EL1_SWITCH: case ISI_EL1_JUMP: case ISI_EL2_SWITCH: case ISI_EL2_JUMP: //if (debug) //System.out.println("returning (3.5) pos " + offset + " symbol " + getTokenName(JspELSyntax.EL_DELIM + elSyntaxInfo.tokenIDShift)); tokenContextPath = JspMultiTokenContext.elContextPath; return ELTokenContext.EL_DELIM; } // switch (state) } // if lastBuffer //if (debug) //System.out.println("returning (4) pos " + offset + " symbol " + getTokenName(null)); return null; } // if state != ISI_LANGUAGE - inner } // if state != ISI_LANGUAGE - outer // now state is ISI_LANGUAGE //if (state != ISI_LANGUAGE) new Exception("state should be ISI_LANGUAGE").printStackTrace(); TokenID slaveTokenID = null; TokenID returnedTokenID; int slaveOffset; int canBe; boolean firstTokenNotRead = ((tokenOffset == offset) || (firstTokenID == null)); boolean equalPositions = (tokenOffset == offset); switch (nestMode) { // BIG BRANCH - we are in the HOST mode case MODE_HOST: if (hostStateInfo == null) { hostStateInfo = hostSyntax.createStateInfo(); hostSyntax.reset(); hostSyntax.storeState(hostStateInfo); } /*if (debug) { System.out.print("NOT EQUAL tokenOffset=" + tokenOffset + ", offset=" + offset + ", tokenPart='"); for (int i = tokenOffset; i= tokenOffset + firstTokenLength) //new Exception("value of canBe is invalid !!!!!!!").printStackTrace(); // now use the saved state if (equalPositions) { hostSyntax.load(hostStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); } else { hostSyntax.load(helpHostStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); } returnedTokenID = hostSyntax.nextToken(); tokenContextPath = JspMultiTokenContext.context.getContextPath( hostSyntax.getTokenContextPath()); // we got the StateInfo, which is why we did all this if (hostStateInfo == null) { hostStateInfo = hostSyntax.createStateInfo(); } //if (debug) //System.out.println("html state before saving back " + ((BaseStateInfo)hostStateInfo).toString(this)); hostSyntax.storeState(hostStateInfo); hostStateInfo.setPreScan(0); //if (hostSyntax.getOffset() != canBe) //new Exception("bad number of characters parsed !!!").printStackTrace(); offset = canBe; /*if (debug) { System.out.println("switching from HOST to JSPTAG at offset " + offset + ", hostState " + ((BaseStateInfo)hostStateInfo).toString(this)); System.out.println("offset of the returned (a)" + hostSyntax.getOffset()); System.out.println("found delimiter at " + offset); System.out.println("returnuju (5) " + firstTokenID + " at " + offset); }*/ return firstTokenID; } //break; //- not reached // BIG BRANCH - we are in the HOST_JSPTAG mode case MODE_HOST_JSPTAG: // check if the JSP tag hasn't finished on its own will if ((jspTagStateInfo != null) && (jspTagStateInfo.getState() == JspTagSyntax.ISA_END_JSP)) { // give up control jspTagStateInfo = null; nestMode = MODE_HOST; //if (debug) { //System.out.println("switching back to HOST from JSPTAG at offset " + offset + ", hostState " + ((BaseStateInfo)hostStateInfo).toString(this)); //System.out.println("returnuju (6) " /*+ JspTagSyntax.TEXT + jspTagSyntaxInfo.tokenIDShift */+ " at " + offset); //} tokenContextPath = JspMultiTokenContext.jspTagContextPath; return JspTagTokenContext.TEXT; } if (jspTagStateInfo == null) { jspTagStateInfo = jspTagSyntax.createStateInfo(); jspTagSyntax.reset(); jspTagSyntax.storeState(jspTagStateInfo); } if (firstTokenNotRead) { // the first step - parse the first token of the slave transferMasterToSlave(jspTagSyntax, jspTagStateInfo); returnedTokenID = jspTagSyntax.nextToken(); if (returnedTokenID == JspTagTokenContext.AFTER_UNEXPECTED_LT) { // give up control jspTagStateInfo = null; nestMode = MODE_HOST; hostStateInfo.setPreScan(0); tokenContextPath = JspMultiTokenContext.jspTagContextPath; //System.out.println("switch to host " + returnedTokenID + " at " + offset); return returnedTokenID; } slaveTokenID = returnedTokenID; tokenContextPath = JspMultiTokenContext.jspTagContextPath; //if (debug) //System.out.println("first JSPtoken returned '" + getToken(jspTagSyntax) + "' id " + slaveTokenID); slaveOffset = jspTagSyntax.getOffset(); firstTokenID = slaveTokenID; firstTokenLength = jspTagSyntax.getTokenLength(); if (slaveTokenID == null) { offset = slaveOffset; firstTokenLength = -1; // need to properly transfer states if (equalPositions) { helpJspTagStateInfo = jspTagStateInfo; jspTagStateInfo = jspTagSyntax.createStateInfo(); jspTagSyntax.storeState(jspTagStateInfo); } else { if (jspTagStateInfo == null) { jspTagStateInfo = jspTagSyntax.createStateInfo(); } jspTagSyntax.storeState(jspTagStateInfo); } //if (debug) //System.out.println("returnuju (7) " + null + " at " + offset); return null; } // find out if the token could contain a starting symbol for Java canBe = canBeJspTagDelimiter(tokenOffset, slaveOffset, slaveOffset, false, returnedTokenID == JspTagTokenContext.COMMENT); if (canBe == DELIMCHECK_NO) { // do not switch offset = slaveOffset; if (jspTagStateInfo == null) { jspTagStateInfo = jspTagSyntax.createStateInfo(); } jspTagSyntax.storeState(jspTagStateInfo); //if (debug) //System.out.println("returnuju (8) " + slaveTokenID + " at " + offset); return slaveTokenID; } // store the state jspTagSyntax.storeState(firstJspTagStateInfo); } else { // first position read - offsets different and firstTokenID is a valid token transferMasterToSlave(jspTagSyntax, jspTagStateInfo); canBe = DELIMCHECK_PART; } // we have successfully read the first token, the following statements hold: // - canBe is not DELIMCHECK_NO // - firstTokenID and firstTokenLength are meaningful // - if (equalPositions) then firstJspTagStateInfo is meaningful //if (firstTokenID == null) { //new Exception("invalid firstTokenID !!!!!!!").printStackTrace(); //} while (canBe == DELIMCHECK_PART) { // need another token // now get the new token returnedTokenID = jspTagSyntax.nextToken(); slaveTokenID = returnedTokenID; tokenContextPath = JspMultiTokenContext.jspTagContextPath; slaveOffset = jspTagSyntax.getOffset(); if ((slaveTokenID == null) && lastBuffer) { // ask about the delimiter, but with lastPart=true canBe = canBeJspTagDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, true, returnedTokenID == JspTagTokenContext.COMMENT); if (canBe != DELIMCHECK_PART) break; } if (slaveTokenID == null) { if (lastBuffer) { canBe = DELIMCHECK_NO; break; } offset = slaveOffset; if (equalPositions) { helpJspTagStateInfo = jspTagStateInfo; jspTagStateInfo = jspTagSyntax.createStateInfo(); jspTagSyntax.storeState(jspTagStateInfo); } else { if (jspTagStateInfo == null) { jspTagStateInfo = jspTagSyntax.createStateInfo(); } jspTagSyntax.storeState(jspTagStateInfo); } //if (debug) //System.out.println("returnuju (9) " + null + " at " + offset); return null; } canBe = canBeJspTagDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, false, returnedTokenID == JspTagTokenContext.COMMENT); } // now canBe is not DELIMCHECK_PART // now we have read possibly more tokens and know whether to switch or not if (canBe == DELIMCHECK_NO) { // do not switch offset = tokenOffset + firstTokenLength; if (equalPositions) { jspTagStateInfo = firstJspTagStateInfo; firstJspTagStateInfo = jspTagSyntax.createStateInfo(); } else { //if (debug) //System.out.println("= imagine - rescan called !!"); // we need to rescan the first token to find out the state // now helpJspTagStateInfo is useful jspTagSyntax.load(helpJspTagStateInfo, buffer, tokenOffset, stopOffset - tokenOffset, lastBuffer, -1); returnedTokenID = jspTagSyntax.nextToken(); tokenContextPath = JspMultiTokenContext.jspTagContextPath; slaveTokenID = returnedTokenID; if (jspTagStateInfo == null) { jspTagStateInfo = jspTagSyntax.createStateInfo(); } jspTagSyntax.storeState(jspTagStateInfo); //if (slaveTokenID != firstTokenID) //new Exception("token ID does not match !!!!!!!").printStackTrace(); //if (offset != jspTagSyntax.getOffset()) //new Exception("offset does not match !!!!!!!").printStackTrace(); } //if (debug) //System.out.println("returnuju (10) " + firstTokenID + " at " + offset); return firstTokenID; } else { // we found a delimiter //if (canBe >= tokenOffset + firstTokenLength) //new Exception("value of canBe is invalid !!!!!!!").printStackTrace(); // now use the saved state if (equalPositions) { jspTagSyntax.load(jspTagStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); } else { jspTagSyntax.load(helpJspTagStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); } returnedTokenID = jspTagSyntax.nextToken(); tokenContextPath = JspMultiTokenContext.jspTagContextPath; // we got the StateInfo, which is why we did all this if (jspTagStateInfo == null) { jspTagStateInfo = jspTagSyntax.createStateInfo(); } jspTagSyntax.storeState(jspTagStateInfo); jspTagStateInfo.setPreScan(0); //if (jspTagSyntax.getOffset() != canBe) //new Exception("bad number of characters parsed !!!").printStackTrace(); offset = canBe; //if (debug) { //System.out.println("offset of the returned (a)" + jspTagSyntax.getOffset()); //System.out.println("found delimiter at " + offset); //System.out.println("returnuju (11) " + firstTokenID + " at " + offset); //} return firstTokenID; } //break; //- not reached case MODE_HOST_JSPTAG_JAVA: case MODE_HOST_JAVA: if (javaStateInfo == null) { javaStateInfo = javaSyntax.createStateInfo(); javaSyntax.reset(); javaSyntax.storeState(javaStateInfo); } if (firstTokenNotRead) { // the first step - parse the first token of the slave transferMasterToSlave(javaSyntax, javaStateInfo); returnedTokenID = javaSyntax.nextToken(); tokenContextPath = JspMultiTokenContext.javaContextPath; slaveTokenID = returnedTokenID; slaveOffset = javaSyntax.getOffset(); firstTokenID = slaveTokenID; firstTokenLength = javaSyntax.getTokenLength(); if (slaveTokenID == null) { offset = slaveOffset; firstTokenLength = -1; // need to property transfer states if (equalPositions) { helpJavaStateInfo = javaStateInfo; javaStateInfo = javaSyntax.createStateInfo(); javaSyntax.storeState(javaStateInfo); } else { if (javaStateInfo == null) { javaStateInfo = javaSyntax.createStateInfo(); } javaSyntax.storeState(javaStateInfo); } //if (debug) //System.out.println("returnuju (12) " + null + " at " + offset); return null; } // find out if the token could contain an ending symbol for a Java block canBe = canBeJavaDelimiter(tokenOffset, slaveOffset, slaveOffset, false, nestMode); if (canBe == DELIMCHECK_NO) { // do not switch offset = slaveOffset; if (javaStateInfo == null) { javaStateInfo = javaSyntax.createStateInfo(); } javaSyntax.storeState(javaStateInfo); //if (debug) //System.out.println("returnuju (13) " + slaveTokenID + " at " + offset); return slaveTokenID; } // store the state javaSyntax.storeState(firstJavaStateInfo); } else { // first position read - offsets different and firstTokenID is a valid token transferMasterToSlave(javaSyntax, javaStateInfo); canBe = DELIMCHECK_PART; } // we have successfully read the first token, the following statements hold: // - canBe is not DELIMCHECK_NO // - firstTokenID and firstTokenLength are meaningful // - if (equalPositions) then firstJavaStateInfo is meaningful //if (firstTokenID == null) { //new Exception("invalid firstTokenID !!!!!!!").printStackTrace(); //} while (canBe == DELIMCHECK_PART) { // need another token // now get the new token returnedTokenID = javaSyntax.nextToken(); slaveTokenID = returnedTokenID; tokenContextPath = JspMultiTokenContext.javaContextPath; slaveOffset = javaSyntax.getOffset(); if ((slaveTokenID == null) && lastBuffer) { // ask about the delimiter, but with lastPart=true canBe = canBeJavaDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, true, nestMode); if (canBe != DELIMCHECK_PART) break; } if (slaveTokenID == null) { if (lastBuffer) { canBe = DELIMCHECK_NO; break; } offset = slaveOffset; if (equalPositions) { helpJavaStateInfo = javaStateInfo; javaStateInfo = javaSyntax.createStateInfo(); javaSyntax.storeState(javaStateInfo); } else { if (javaStateInfo == null) { javaStateInfo = javaSyntax.createStateInfo(); } javaSyntax.storeState(javaStateInfo); } //if (debug) //System.out.println("returnuju (14) " + null + " at " + offset); return null; } canBe = canBeJavaDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, false, nestMode); } // now canBe is not DELIMCHECK_PART // now we have read possibly more tokens and know whether to switch or not if (canBe == DELIMCHECK_NO) { // do not switch offset = tokenOffset + firstTokenLength; if (equalPositions) { javaStateInfo = firstJavaStateInfo; firstJavaStateInfo = javaSyntax.createStateInfo(); } else { //if (debug) //System.out.println("= imagine - rescan called !!"); // we need to rescan the first token to find out the state // now helpJavaStateInfo is useful javaSyntax.load(helpJavaStateInfo, buffer, tokenOffset, stopOffset - tokenOffset, lastBuffer, -1); returnedTokenID = javaSyntax.nextToken(); slaveTokenID = returnedTokenID; tokenContextPath = JspMultiTokenContext.javaContextPath; if (javaStateInfo == null) { javaStateInfo = javaSyntax.createStateInfo(); } javaSyntax.storeState(javaStateInfo); //if (slaveTokenID != firstTokenID) //new Exception("token ID does not match !!!!!!!").printStackTrace(); //if (offset != javaSyntax.getOffset()) //new Exception("offset does not match !!!!!!!").printStackTrace(); } //if (debug) //System.out.println("returnuju (15) " + firstTokenID + " at " + offset); return firstTokenID; } else { // we found a delimiter //if (canBe >= tokenOffset + firstTokenLength) //new Exception("value of canBe is invalid !!!!!!!").printStackTrace(); // now use the saved state if (equalPositions) { javaSyntax.load(javaStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); } else { javaSyntax.load(helpJavaStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); } returnedTokenID = javaSyntax.nextToken(); tokenContextPath = JspMultiTokenContext.javaContextPath; // we got the StateInfo, which is why we did all this if (javaStateInfo == null) { javaStateInfo = javaSyntax.createStateInfo(); } javaSyntax.storeState(javaStateInfo); javaStateInfo.setPreScan(0); //if (javaSyntax.getOffset() != canBe) //new Exception("bad number of characters parsed !!!").printStackTrace(); offset = canBe; /*if (debug) { System.out.println("offset of the returned (a)" + javaSyntax.getOffset()); System.out.println("found delimiter at " + offset); System.out.println("returnuju (16) " + firstTokenID + " at " + offset); }*/ return firstTokenID; } // break; //- not reached case MODE_HOST_JSPTAG_EL: case MODE_HOST_EL: if (elStateInfo == null) { elStateInfo = elSyntax.createStateInfo(); elSyntax.reset(); elSyntax.storeState(elStateInfo); } if (firstTokenNotRead) { // the first step - parse the first token of the slave transferMasterToSlave(elSyntax, elStateInfo); returnedTokenID = elSyntax.nextToken(); tokenContextPath = JspMultiTokenContext.elContextPath; slaveTokenID = returnedTokenID; slaveOffset = elSyntax.getOffset(); firstTokenID = slaveTokenID; firstTokenLength = elSyntax.getTokenLength(); if (slaveTokenID == null) { offset = slaveOffset; firstTokenLength = -1; // need to property transfer states if (equalPositions) { helpELStateInfo = elStateInfo; elStateInfo = elSyntax.createStateInfo(); elSyntax.storeState(elStateInfo); } else { if (elStateInfo == null) { elStateInfo = elSyntax.createStateInfo(); } elSyntax.storeState(elStateInfo); } //if (debug) //System.out.println("returnuju (12.5) " + null + " at " + offset); return null; } // find out if the token could contain an ending symbol for a EL block canBe = canBeELDelimiter(tokenOffset, slaveOffset, slaveOffset, false, nestMode); if (canBe == DELIMCHECK_NO) { // do not switch offset = slaveOffset; if (elStateInfo == null) { elStateInfo = elSyntax.createStateInfo(); } elSyntax.storeState(elStateInfo); //if (debug) //System.out.println("returnuju (13.5) " + slaveTokenID + " at " + offset); return slaveTokenID; } // store the state elSyntax.storeState(firstELStateInfo); } else { // first position read - offsets different and firstTokenID is a valid token transferMasterToSlave(elSyntax, elStateInfo); canBe = DELIMCHECK_PART; } // we have successfully read the first token, the following statements hold: // - canBe is not DELIMCHECK_NO // - firstTokenID and firstTokenLength are meaningful // - if (equalPositions) then firstELStateInfo is meaningful //if (firstTokenID == null) { //new Exception("invalid firstTokenID !!!!!!!").printStackTrace(); //} while (canBe == DELIMCHECK_PART) { // need another token // now get the new token returnedTokenID = elSyntax.nextToken(); slaveTokenID = returnedTokenID; tokenContextPath = JspMultiTokenContext.elContextPath; slaveOffset = elSyntax.getOffset(); if ((slaveTokenID == null) && lastBuffer) { // ask about the delimiter, but with lastPart=true canBe = canBeELDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, true, nestMode); if (canBe != DELIMCHECK_PART) break; } if (slaveTokenID == null) { if (lastBuffer) { canBe = DELIMCHECK_NO; break; } offset = slaveOffset; if (equalPositions) { helpELStateInfo = elStateInfo; elStateInfo = elSyntax.createStateInfo(); elSyntax.storeState(elStateInfo); } else { if (elStateInfo == null) { elStateInfo = elSyntax.createStateInfo(); } elSyntax.storeState(elStateInfo); } //if (debug) //System.out.println("returnuju (14) " + null + " at " + offset); return null; } canBe = canBeELDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, false, nestMode); } // now canBe is not DELIMCHECK_PART // now we have read possibly more tokens and know whether to switch or not if (canBe == DELIMCHECK_NO) { // do not switch offset = tokenOffset + firstTokenLength; if (equalPositions) { elStateInfo = firstELStateInfo; firstELStateInfo = elSyntax.createStateInfo(); } else { //if (debug) //System.out.println("= imagine - rescan called !!"); // we need to rescan the first token to find out the state // now helpELStateInfo is useful elSyntax.load(helpELStateInfo, buffer, tokenOffset, stopOffset - tokenOffset, lastBuffer, -1); returnedTokenID = elSyntax.nextToken(); slaveTokenID = returnedTokenID; tokenContextPath = JspMultiTokenContext.elContextPath; if (elStateInfo == null) { elStateInfo = elSyntax.createStateInfo(); } elSyntax.storeState(elStateInfo); //if (slaveTokenID != firstTokenID) //new Exception("token ID does not match !!!!!!!").printStackTrace(); //if (offset != elSyntax.getOffset()) //new Exception("offset does not match !!!!!!!").printStackTrace(); } //if (debug) //System.out.println("returnuju (15.5) " + firstTokenID + " at " + offset); return firstTokenID; } else { // we found a delimiter //if (canBe >= tokenOffset + firstTokenLength) //new Exception("value of canBe is invalid !!!!!!!").printStackTrace(); // now use the saved state if (equalPositions) { elSyntax.load(elStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); } else { elSyntax.load(helpELStateInfo, buffer, tokenOffset, canBe - tokenOffset, true, -1); } returnedTokenID = elSyntax.nextToken(); tokenContextPath = JspMultiTokenContext.elContextPath; // we got the StateInfo, which is why we did all this if (elStateInfo == null) { elStateInfo = elSyntax.createStateInfo(); } elSyntax.storeState(elStateInfo); elStateInfo.setPreScan(0); //if (elSyntax.getOffset() != canBe) //new Exception("bad number of characters parsed !!!").printStackTrace(); offset = canBe; /*if (debug) { System.out.println("offset of the returned (a)" + elSyntax.getOffset()); System.out.println("found delimiter at " + offset); System.out.println("returnuju (16.5) " + firstTokenID + " at " + offset); }*/ return firstTokenID; } // break; //- not reached default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad nestmode")); // NOI18N tokenContextPath = JspMultiTokenContext.contextPath; return JspMultiTokenContext.ERROR; // !!! don't know what to return } } /** Method for debugging purposes */ private String getToken(Syntax syntax) { StringBuffer token = new StringBuffer(); for (int i=syntax.getOffset()-syntax.getTokenLength();i<jsp:useBean or <%=. * @return
      *
    • DELIMCHECK_NO if the part of the buffer does not contain a delimiter or its part
    • *
    • DELIMCHECK_PART if the part of the buffer contains part of the delimiter
    • *
    • index of the starting symbol of the delimiter if the part of the buffer contains the delimiter. * In such a case variable state is set properly.
    • *
    */ protected int canBeHostDelimiter(int tokenOffset, int endOffset, int firstTokenEnd, boolean lastPart) { int offset = tokenOffset; char actChar; int possibleBeginning = DELIMCHECK_NO; StringBuffer tagString = null; int delimState = HOST_INIT; while(offset < endOffset) { actChar = buffer[offset]; switch (delimState) { case HOST_INIT: switch (actChar) { case '<': if (offset >= firstTokenEnd) return DELIMCHECK_NO; delimState = HOST_LT; possibleBeginning = offset; break; case '$': if (offset >= firstTokenEnd) return DELIMCHECK_NO; if (!isELIgnored(false)) { delimState = HOST_D; possibleBeginning = offset; } break; case '\\': if (offset >= firstTokenEnd) return DELIMCHECK_NO; delimState = HOST_BS; possibleBeginning = offset; // not really true, the delimiter can't start here break; default: if (offset >= firstTokenEnd) return DELIMCHECK_NO; break; } break; case HOST_LT: if ((actChar >= 'A' && actChar <= 'Z') || (actChar >= 'a' && actChar <= 'z') || (actChar == '_') ) { // possible tag begining delimState = HOST_TAG; tagString = new StringBuffer(); tagString.append(actChar); break; // the switch statement } switch (actChar) { case '\n': delimState = HOST_INIT; break; case '%': delimState = HOST_LT_PC; break; case '/': delimState = HOST_LT_SLASH; break; case ' ': case '\t': delimState = HOST_LT_BLANK; break; default: delimState = HOST_INIT; offset--; break; } break; case HOST_LT_SLASH: if ((actChar >= 'A' && actChar <= 'Z') || (actChar >= 'a' && actChar <= 'z') || (actChar == '_') ) { // possible tag begining delimState = HOST_TAG; tagString = new StringBuffer(); tagString.append(actChar); break; // the switch statement } switch (actChar) { case '\n': delimState = HOST_INIT; break; case ' ': case '\t': delimState = HOST_LT_BLANK; break; default: delimState = HOST_INIT; offset--; break; } break; case HOST_LT_BLANK: if ((actChar >= 'A' && actChar <= 'Z') || (actChar >= 'a' && actChar <= 'z') || (actChar == '_') ) { // possible tag begining delimState = HOST_TAG; // we are checking whether this is a JSP tag, however even if it is, // JspTagSyntax will report any spaces between < and tagname as errors tagString = new StringBuffer(); tagString.append(actChar); break; // the switch statement } switch (actChar) { case '\n': delimState = HOST_INIT; break; case ' ': case '\t': break; default: delimState = HOST_INIT; offset--; break; } break; case HOST_TAG: if ((actChar >= 'A' && actChar <= 'Z') || (actChar >= 'a' && actChar <= 'z') || (actChar >= '0' && actChar <= '9') || (actChar == ':') || (actChar == '-') || (actChar == '_') ) { // the tag continues tagString.append(actChar); break; // the switch statement } switch (actChar) { default: if (isJspTag(tagString.toString())) { state = ISI_HOST_JSPTAG; //if (debug) //System.out.println("found beginning of JspTag at " + possibleBeginning); return possibleBeginning; } else { delimState = HOST_INIT; offset--; break; } } break; case HOST_LT_PC: switch (actChar) { case '@': // directive case '-': // JSP comment state = ISI_HOST_JSPTAG; //if (debug) //System.out.println("found beginning of directive/comment at " + possibleBeginning); return possibleBeginning; case '!': // declaration case '=': // expression state = ISI_HOST_JAVA; //if (debug) //System.out.println("found beginning of declaration/expression at " + possibleBeginning); return possibleBeginning; default: // scriptlet state = ISI_HOST_JAVA; //if (debug) //System.out.println("found beginning of scriptlet at " + possibleBeginning); return possibleBeginning; } //break; case HOST_D: switch (actChar) { case '\n': delimState = HOST_INIT; break; case '{': state = ISI_HOST_EL; return possibleBeginning; default: delimState = HOST_INIT; offset--; break; } break; case HOST_BS: switch (actChar) { case '<': if (offset >= firstTokenEnd) return DELIMCHECK_NO; delimState = HOST_LT; possibleBeginning = offset; break; case '\\': if (offset >= firstTokenEnd) return DELIMCHECK_NO; possibleBeginning = offset; // not really true, the delimiter can't start here break; default: delimState = HOST_INIT; break; } break; } offset++; } if (lastPart) { switch (delimState) { case HOST_LT_PC: state = ISI_HOST_JAVA; return possibleBeginning; case HOST_TAG: if (isJspTag(tagString.toString())) { state = ISI_HOST_JSPTAG; //if (debug) //System.out.println("found beginning of JspTag at " + possibleBeginning); return possibleBeginning; } } } // we have reached the end of the scanned area switch (delimState) { case HOST_INIT: return DELIMCHECK_NO; case HOST_LT: case HOST_LT_SLASH: case HOST_LT_PC: case HOST_LT_BLANK: case HOST_TAG: case HOST_D: case HOST_BS: return DELIMCHECK_PART; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("invalid state")); // NOI18N return DELIMCHECK_NO; } } /** Checks if the part of the buffer starting at tokenOffset and ending just before endOffset * contains a "delimiter" or could contain a starting part of a "delimiter", where * "delimiter" is a lexical structure which could start a Java block inside a JSP tag, * i.e. <%=. * @return
      *
    • DELIMCHECK_NO if the part of the buffer does not contain a delimiter or its part
    • *
    • DELIMCHECK_PART if the part of the buffer contains part of the delimiter
    • *
    • index of the starting symbol of the delimiter if the part of the buffer contains the delimiter. * In such a case variable state is set properly.
    • *
    */ protected int canBeJspTagDelimiter(int tokenOffset, int endOffset, int firstTokenEnd, boolean lastPart, boolean isComment) { if (isComment) return DELIMCHECK_NO; int offset = tokenOffset; char actChar; int possibleBeginning = DELIMCHECK_NO; int delimState = JSPTAG_INIT; while(offset < endOffset) { actChar = buffer[offset]; switch (delimState) { case JSPTAG_INIT: switch (actChar) { case '<': if (offset >= firstTokenEnd) return DELIMCHECK_NO; delimState = JSPTAG_LT; possibleBeginning = offset; break; case '$': if (offset >= firstTokenEnd) return DELIMCHECK_NO; if (!isELIgnored(true)) { delimState = JSPTAG_D; possibleBeginning = offset; } break; case '\\': if (offset >= firstTokenEnd) return DELIMCHECK_NO; delimState = JSPTAG_BS; possibleBeginning = offset; // not really true, the delimiter can't start here break; default: if (offset >= firstTokenEnd) return DELIMCHECK_NO; break; } break; case JSPTAG_LT: switch (actChar) { case '\n': delimState = JSPTAG_INIT; break; case '%': delimState = JSPTAG_LT_PC; break; default: delimState = JSPTAG_INIT; offset--; break; } break; case JSPTAG_LT_PC: switch (actChar) { case '!': // declaration case '=': // expression state = ISI_JSPTAG_JAVA; //if (debug) //System.out.println("found beginning of declaration/expression at " + possibleBeginning); return possibleBeginning; case '@': // declaration case '-': // comment delimState = JSPTAG_INIT; break; default: // scriptlet state = ISI_JSPTAG_JAVA; //if (debug) //System.out.println("found beginning of scriptlet at " + possibleBeginning); return possibleBeginning; } //break; case JSPTAG_D: switch (actChar) { case '\n': delimState = JSPTAG_INIT; break; case '{': state = ISI_JSPTAG_EL; return possibleBeginning; default: delimState = JSPTAG_INIT; offset--; break; } break; case JSPTAG_BS: switch (actChar) { case '<': if (offset >= firstTokenEnd) return DELIMCHECK_NO; delimState = JSPTAG_LT; possibleBeginning = offset; break; case '\\': if (offset >= firstTokenEnd) return DELIMCHECK_NO; possibleBeginning = offset; // not really true, the delimiter can't start here break; default: delimState = JSPTAG_INIT; break; } break; } offset++; } if (lastPart) { switch (delimState) { case JSPTAG_LT_PC: state = ISI_JSPTAG_JAVA; //if (debug) //System.out.println("found beginning of scriptlet at " + possibleBeginning); return possibleBeginning; } } // we have reached the end of the scanned area switch (delimState) { case JSPTAG_INIT: return DELIMCHECK_NO; case JSPTAG_LT: return DELIMCHECK_PART; case JSPTAG_LT_PC: return DELIMCHECK_PART; case JSPTAG_D: return DELIMCHECK_PART; case JSPTAG_BS: //this state (error???) happens when only one character '\' //is scanned by this method (tokenOffset = endOffset - 1) return DELIMCHECK_NO; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("invalid state " + delimState)); // NOI18N return DELIMCHECK_NO; } } /** Checks if the part of the buffer starting at tokenOffset and ending just before endOffset * contains a "delimiter" or could contain a starting part of a "delimiter", where * "delimiter" is a lexical structure which could end a Java block, * i.e. %>. * @return
      *
    • DELIMCHECK_NO if the part of the buffer does not contain a delimiter or its part
    • *
    • DELIMCHECK_PART if the part of the buffer contains part of the delimiter
    • *
    • index of the starting symbol of the delimiter if the part of the buffer contains the delimiter. * In such a case variable state is set properly.
    • *
    */ protected int canBeJavaDelimiter(int tokenOffset, int endOffset, int firstTokenEnd, boolean lastPart, int myNestMode) { int offset = tokenOffset; char actChar; int possibleBeginning = DELIMCHECK_NO; int delimState = JAVA_INIT; while(offset < endOffset) { actChar = buffer[offset]; switch (delimState) { case JAVA_INIT: switch (actChar) { case '%': if (offset >= firstTokenEnd) return DELIMCHECK_NO; delimState = JAVA_PC; possibleBeginning = offset; break; default: if (offset >= firstTokenEnd) return DELIMCHECK_NO; break; } break; case JAVA_PC: switch (actChar) { case '>': switch (myNestMode) { case MODE_HOST_JSPTAG_JAVA: state = ISI_JAVA1_SWITCH; //if (debug) //System.out.println("found end of Java at " + possibleBeginning); return possibleBeginning; case MODE_HOST_JAVA: state = ISI_JAVA2_SWITCH; //if (debug) //System.out.println("found end of Java at " + possibleBeginning); return possibleBeginning; } ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad nestMode")); // NOI18N //break; - not reached case '%': if (offset >= firstTokenEnd) return DELIMCHECK_NO; delimState = JAVA_PC; possibleBeginning = offset; break; default: delimState = JAVA_INIT; break; } break; } offset++; } // we have reached the end of the scanned area switch (delimState) { case JAVA_INIT: return DELIMCHECK_NO; case JAVA_PC: return DELIMCHECK_PART; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("invalid state")); // NOI18N return DELIMCHECK_NO; } } /** Checks if the part of the buffer starting at tokenOffset and ending just before endOffset * contains a "delimiter" or could contain a starting part of a "delimiter", where * "delimiter" is a lexical structure which could end a EL block, * i.e. }. * @return
      *
    • DELIMCHECK_NO if the part of the buffer does not contain a delimiter or its part
    • *
    • DELIMCHECK_PART if the part of the buffer contains part of the delimiter
    • *
    • index of the starting symbol of the delimiter if the part of the buffer contains the delimiter. * In such a case variable state is set properly.
    • *
    */ protected int canBeELDelimiter(int tokenOffset, int endOffset, int firstTokenEnd, boolean lastPart, int myNestMode) { int offset = tokenOffset; char actChar; int possibleBeginning = DELIMCHECK_NO; int delimState = EL_INIT; while(offset < endOffset) { actChar = buffer[offset]; switch (delimState) { case EL_INIT: // the only state for now switch (actChar) { case '}': if (offset >= firstTokenEnd) return DELIMCHECK_NO; possibleBeginning = offset; switch (myNestMode) { case MODE_HOST_JSPTAG_EL: state = ISI_EL1_SWITCH; //if (debug) //System.out.println("found end of EL at " + possibleBeginning); return possibleBeginning; case MODE_HOST_EL: state = ISI_EL2_SWITCH; //if (debug) //System.out.println("found end of EL at " + possibleBeginning); return possibleBeginning; } ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("bad nestMode")); // NOI18N break; default: if (offset >= firstTokenEnd) return DELIMCHECK_NO; break; } break; } offset++; } // we have reached the end of the scanned area switch (delimState) { case EL_INIT: return DELIMCHECK_NO; default: ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception("invalid state")); // NOI18N return DELIMCHECK_NO; } } /** Determines whether a given string is a JSP tag. */ protected boolean isJspTag(String tagName) { boolean canBeJsp = tagName.startsWith("jsp:"); // NOI18N return canBeJsp; } /** Determines whether any EL expressions should be colored as expressions, * or ignored. This class does not have all the context necessary to decide this, * so it just returns false (meaning that EL should be colored). Subclasses * should override this to return the correct value per section JSP.3.3.2 * of the specification. * @param whether this expression is inside the JSP tag value, or just in template text * @return true if the expression should be ignored, false if it should be treated as an expression */ protected boolean isELIgnored(boolean inJspTag) { return false; } /** Determines whether the page is in xml syntax or not. * This class does not have all the context necessary to decide this, * so it just returns false. Subclasses * should override this to return the correct value. * @return true if the page is JSP Document, false if the page is in standart syntax */ protected boolean isXMLSyntax(){ return false; } private void transferMasterToSlave(Syntax slave, StateInfo stateInfo) { slave.load(stateInfo, buffer, offset, stopOffset - offset, lastBuffer, -1); //slave.setLastBuffer(lastBuffer); // PENDING - maybe not necessary //slave.setStopOffset(stopOffset); // PENDING - maybe not necessary } /** Store state of this analyzer into given mark state. */ public void storeState(StateInfo stateInfo) { super.storeState(stateInfo); JspStateInfo jspsi = (JspStateInfo)stateInfo; // nest mode jspsi.nestMode = nestMode; // regular stateinfos if (hostStateInfo == null) { jspsi.hostStateInfo = null; } else { jspsi.hostStateInfo = hostSyntax.createStateInfo(); hostSyntax.load(hostStateInfo, buffer, offset, 0, false, -1); hostSyntax.storeState(jspsi.hostStateInfo); } if (jspTagStateInfo == null) { jspsi.jspTagStateInfo = null; } else { jspsi.jspTagStateInfo = jspTagSyntax.createStateInfo(); jspTagSyntax.load(jspTagStateInfo, buffer, offset, 0, false, -1); jspTagSyntax.storeState(jspsi.jspTagStateInfo); } if (elStateInfo == null) { jspsi.elStateInfo = null; } else { jspsi.elStateInfo = elSyntax.createStateInfo(); elSyntax.load(elStateInfo, buffer, offset, 0, false, -1); elSyntax.storeState(jspsi.elStateInfo); } if (javaStateInfo == null) { jspsi.javaStateInfo = null; } else { jspsi.javaStateInfo = javaSyntax.createStateInfo(); javaSyntax.load(javaStateInfo, buffer, offset, 0, false, -1); javaSyntax.storeState(jspsi.javaStateInfo); } // stateOfScanningAtInit, firstTokenID, firstTokenLength if (jspsi.isFirstTokenValid()) { jspsi.firstTokenID = firstTokenID; jspsi.firstTokenLength = firstTokenLength; switch (nestMode) { case MODE_HOST: jspsi.stateOfScanningAtInit = hostSyntax.createStateInfo(); hostSyntax.load(helpHostStateInfo, buffer, offset, 0, false, -1); hostSyntax.storeState(jspsi.stateOfScanningAtInit); break; case MODE_HOST_JSPTAG: jspsi.stateOfScanningAtInit = jspTagSyntax.createStateInfo(); jspTagSyntax.load(helpJspTagStateInfo, buffer, offset, 0, false, -1); jspTagSyntax.storeState(jspsi.stateOfScanningAtInit); break; case MODE_HOST_JSPTAG_EL: case MODE_HOST_EL: jspsi.stateOfScanningAtInit = elSyntax.createStateInfo(); elSyntax.load(helpELStateInfo, buffer, offset, 0, false, -1); elSyntax.storeState(jspsi.stateOfScanningAtInit); break; case MODE_HOST_JSPTAG_JAVA: case MODE_HOST_JAVA: jspsi.stateOfScanningAtInit = javaSyntax.createStateInfo(); javaSyntax.load(helpJavaStateInfo, buffer, offset, 0, false, -1); javaSyntax.storeState(jspsi.stateOfScanningAtInit); break; } } else { jspsi.stateOfScanningAtInit = null; jspsi.firstTokenID = null; jspsi.firstTokenLength = -1; } /*System.out.print("storing state at offset=" + offset + ", tokenOffset=" + tokenOffset + ", token="); for(int i=tokenOffset;i
    ... this post is sponsored by my books ...

    #1 New Release!

    FP Best Seller

     

    new blog posts

     

    Copyright 1998-2021 Alvin Alexander, alvinalexander.com
    All Rights Reserved.

    A percentage of advertising revenue from
    pages under the /java/jwarehouse URI on this website is
    paid back to open source projects.