KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > syntax > deprecated > JspMultiSyntax


1 /*
2   * The contents of this file are subject to the terms of the Common Development
3   * and Distribution License (the License). You may not use this file except in
4   * compliance with the License.
5   *
6   * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7   * or http://www.netbeans.org/cddl.txt.
8   *
9   * When distributing Covered Code, include this CDDL Header Notice in each file
10   * and include the License file at http://www.netbeans.org/cddl.txt.
11   * If applicable, add the following below the CDDL Header, with the fields
12   * enclosed by brackets [] replaced by your own identifying information:
13   * "Portions Copyrighted [year] [name of copyright owner]"
14   *
15   * The Original Software is NetBeans. The Initial Developer of the Original
16   * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17   * Microsystems, Inc. All Rights Reserved.
18   */

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 /**
32 * Syntax for JSP files. This is a MultiSyntax consisting of three slave syntaxes:
33 * content language syntax (for example HTMLSyntax), JspTagSyntax and scripting
34 * language syntax (for example JavaSyntax). The content language and scripting language
35 * syntaxes are completely pluggable, moreover, they can be changed dynamically by
36 * setContentSyntax() and setScriptingSyntax() methods. The caller of these methods should
37 * make sure that the whole document is recolored after calling these methods.
38 *
39 * @author Petr Jiricka
40 * @version 1.00
41 * @deprecated Use JSP Lexer instead
42 */

43
44 public class JspMultiSyntax extends Syntax {
45
46     //<editor-fold defaultstate="collapsed" desc="class & instance members">
47

48     // modes of nesting of languages
49
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     // constants for result of operation of checking delimiters
57
protected static final int DELIMCHECK_NO = -1;
58     protected static final int DELIMCHECK_PART = -2;
59   
60     // states of this multisyntax
61
private static final int ISI_LANGUAGE = 1; // one syntax is active and working
62
// states for switching from the host language to JSP tag or Java or EL
63
private static final int ISI_HOST_JSPTAG = 2; // just before <jsptag or similar (recognized by JspTagSyntax)
64
private static final int ISI_HOST_JAVA = 3; // just before <% or similar, after such a delimiter Java block starts, host language
65
private static final int ISI_HOST_JAVA_LT = 4; // as ISI_HOST_JAVA after <
66
private static final int ISI_HOST_JAVA_LT_PC = 5; // as ISI_HOST_JAVA after <%
67
private static final int ISI_HOST_JAVA_JUMP = 6; // after a Java delimiter in host language, now really switch
68
private static final int ISI_HOST_EL = 17; // just before ${ , after such a delimiter EL block starts, host language
69
private static final int ISI_HOST_EL_D = 18; // as ISI_HOST_EL after $
70
private static final int ISI_HOST_EL_JUMP = 20; // after a EL delimiter ${ in host language, now really switch
71
// states for switching from a JSP tag to Java or EL
72
private static final int ISI_JSPTAG_JAVA = 7; // just before <% or similar, after such a delimiter Java block starts, JSPTAG language
73
private static final int ISI_JSPTAG_JAVA_LT = 8; // as ISI_JSPTAG_JAVA after <
74
private static final int ISI_JSPTAG_JAVA_LT_PC = 9; // as ISI_JSPTAG_JAVA after <%
75
private static final int ISI_JSPTAG_JAVA_JUMP = 10; // after a Java delimiter in JSPTAG language, now really switch
76
private static final int ISI_JSPTAG_EL = 21; // just before ${ , after such a delimiter EL block starts, JSPTAG language
77
private static final int ISI_JSPTAG_EL_D = 22; // as ISI_JSPTAG_EL after $
78
private static final int ISI_JSPTAG_EL_JUMP = 24; // after a EL delimiter ${ in JSPTAG language, now really switch
79
// states for switching from Java to a JSP tag
80
private static final int ISI_JAVA1_SWITCH = 11; // just before %> in Java (go to JSPTAG)
81
private static final int ISI_JAVA1_PC = 12; // as ISI_JAVA1_SWITCH after %
82
private static final int ISI_JAVA1_JUMP = 13; // after %> in Java, now really switch to JSPTAG
83
// states for switching from Java to host
84
private static final int ISI_JAVA2_SWITCH = 14; // just before %> in Java (go to host)
85
private static final int ISI_JAVA2_PC = 15; // as ISI_JAVA2_SWITCH after %
86
private static final int ISI_JAVA2_JUMP = 16; // after %> in Java, now really switch to host
87
// states for switching from EL to a JSP tag
88
private static final int ISI_EL1_SWITCH = 25; // just before } in EL (go to JSPTAG)
89
private static final int ISI_EL1_JUMP = 26; // after } in EL, now really switch to JSPTAG
90
// states for switching from EL to host
91
private static final int ISI_EL2_SWITCH = 27; // just before } in EL (go to host)
92
private static final int ISI_EL2_JUMP = 28; // after } in EL, now really switch to host
93

94     // states of the automaton which looks for delimiters in the host language
95
private static final int HOST_INIT = 1; // initial state - host language
96
private static final int HOST_LT = 2; // after < - host language
97
private static final int HOST_LT_PC = 3; // after <% - host language
98
private static final int HOST_LT_BLANK = 4; // after < or </ and several blanks or \t - host language
99
private static final int HOST_TAG = 5; // inside a tag, don't know whether html or JSP - host language
100
private static final int HOST_LT_SLASH = 6; // after </ - host lanaguage
101
private static final int HOST_BS = 7; // after \ (escapes $) - host language
102
private static final int HOST_D = 8; // after $ - host language
103

104     // states of the automaton which looks for delimiters in the JSP tag
105
private static final int JSPTAG_INIT = 1; // initial state - JSP tag
106
private static final int JSPTAG_LT = 2; // after < - JSP tag
107
private static final int JSPTAG_LT_PC = 3; // after <% - JSP tag
108
private static final int JSPTAG_BS = 7; // after \ (escapes $) - JSPTAG language
109
private static final int JSPTAG_D = 8; // after $ - JSPTAG language
110

111     // states of the automaton which looks for delimiters in Java
112
private static final int JAVA_INIT = 1; // initial state - Java block
113
private static final int JAVA_PC = 2; // after % - Java block
114

115     // states of the automaton which looks for delimiters in EL
116
private static final int EL_INIT = 1; // initial state - EL block
117

118     //States of java scripting element type
119
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     //state info defining contexts of java tokens (declaration/scriptlet/expression)
124
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     /** When returning from parseToken(), contains the state of the 'host' slave syntax at 'offset'.
134     * Always a part of the StateInfo. */

135     protected StateInfo hostStateInfo;
136     /** When returning from parseToken(), contains the state of the 'jspTag' slave syntax at 'offset'.
137     * Always a part of the StateInfo. */

138     protected StateInfo jspTagStateInfo;
139     /** When returning from parseToken(), contains the state of the 'el' slave syntax at 'offset'.
140     * Always a part of the StateInfo. */

141     protected StateInfo elStateInfo;
142     /** When returning from parseToken(), contains the state of the 'java' slave syntax at 'offset'.
143     * Always a part of the StateInfo. */

144     protected StateInfo javaStateInfo;
145   
146     // Contains the tokenLength returned by the first call of nextToken() on the slave syntax. May need to be
147
// stored in the stateinfo if tokenOffset != offset.
148
// If the first call of slave's nextToken() returned null, this variable will not be valid, and
149
// the next call must update this variable with the correct value
150
private int firstTokenLength;
151
152     // Contains the tokenID returned by the first call of nextToken() on the slave syntax. May need to be
153
// stored in the stateinfo if tokenOffset != offset.
154
// If the first call of slave's nextToken() returned null, it will be reflected in this variable, and
155
// the next call must update this variable with the correct value
156
private TokenID firstTokenID;
157
158     // One of the following stateInfos will be a part of the stateInfo, if we are returning null.
159
// In such a case it will contain the state of the scanning syntax at 'tokenOffset'.
160
private StateInfo helpHostStateInfo;
161     private StateInfo helpJspTagStateInfo;
162     private StateInfo helpELStateInfo;
163     private StateInfo helpJavaStateInfo;
164                          
165     // These stateinfos hold the stateinfo after the first token returned by the scanning stave syntax.
166
// Only when tokenOffset == offset, in the other case need to rescan the first token before returning.
167
private StateInfo firstHostStateInfo;
168     private StateInfo firstJspTagStateInfo;
169     private StateInfo firstELStateInfo;
170     private StateInfo firstJavaStateInfo;
171   
172     //</editor-fold>
173

174     public JspMultiSyntax() {
175         // create the JSP tag syntax
176
jspTagSyntax = new JspTagSyntax();
177         firstJspTagStateInfo = jspTagSyntax.createStateInfo();
178         helpJspTagStateInfo = jspTagSyntax.createStateInfo();
179         // create the EL syntax
180
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     /** Parses the next token. Before entering this method the following assumptions hold:
213     * <ul>
214     * <li>'Regular' stateinfos contain the state of all active languages at 'offset'. For inactive
215     * languages they are <code>null</code>.</li>
216     * <li>If <code>tokenOffset != offset</code>, the scanning 'help' stateinfo contains the state of the scanning
217     * language at 'tokenOffset'.</li>
218     * <li>If <code>tokenOffset != offset</code>, firstTokenID contains the token returned by the first call of
219     * slave's nextToken() in the current token, may be null !</li>
220     * </ul>
221     */

222     protected TokenID parseToken() {
223 //debug = (tokenOffset != offset);
224
//debug = !((tokenOffset == offset) || (firstTokenID == null)); // !firstTokenNotRead
225

226 //if (debug)
227
//System.out.println("parseToken tokenOffset=" + tokenOffset + ", offset=" + offset + ", state=" + state +
228
//", nestMode=" + nestMode + ", stopOffset=" + stopOffset + ", lastBuffer=" + lastBuffer);
229

230         //<editor-fold defaultstate="collapsed" desc="setting states">
231
if (state != ISI_LANGUAGE) {
232             char actChar;
233             while(offset < stopOffset) {
234                 actChar = buffer[offset];
235                 // System.out.println("JspMultiSyntax: parseToken tokenOffset=" + tokenOffset + ", actChar='" + actChar + ", offset=" + offset + ", state=" + getStateName(state) +
236
// ", nestMode=" + getNestModeName( nestMode) + ", stopOffset=" + stopOffset + ", lastBuffer=" + lastBuffer);
237
switch (state) {
238                     case ISI_HOST_JSPTAG: // switch to JspTagSyntax
239
//if (debug)
240
//System.out.println("switching from HOST to JSPTAG, hostState " + ((BaseStateInfo)hostStateInfo).toString(this));
241
nestMode = MODE_HOST_JSPTAG;
242                         state = ISI_LANGUAGE;
243                         transferMasterToSlave(jspTagSyntax, null);
244                         //jspTagSyntax.load(null, buffer, offset, stopOffset - offset, lastBuffer);
245
if (jspTagStateInfo == null) {
246                             jspTagStateInfo = jspTagSyntax.createStateInfo();
247                         }
248                         jspTagSyntax.storeState(jspTagStateInfo);
249                         break;
250
251                     case ISI_HOST_JAVA: // switch from hostSyntax to JavaSyntax
252
switch (actChar) {
253                             case '<':
254                                 state = ISI_HOST_JAVA_LT;
255                                 break;
256                             default:
257                                 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception JavaDoc("bad hostsyntax analyzer")); // NOI18N
258
} // switch (actChar)
259
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 JavaDoc("bad hostsyntax analyzer")); // NOI18N
268
} // switch (actChar)
269
break;
270
271                     case ISI_HOST_JAVA_LT_PC:
272                         switch (actChar) {
273                             case '!': // declaration
274
javaNestMode = JAVA_DECLARATION;
275                                 state = ISI_HOST_JAVA_JUMP;
276                                 offset++;
277                                 tokenContextPath = JspMultiTokenContext.jspTagContextPath;
278                                 return JspTagTokenContext.SYMBOL2;
279                             case '=': // expression
280
javaNestMode = JAVA_EXPRESSION;
281                                 state = ISI_HOST_JAVA_JUMP;
282                                 offset++;
283                                 tokenContextPath = JspMultiTokenContext.jspTagContextPath;
284                                 return JspTagTokenContext.SYMBOL2;
285                             default: // assume this is a scriptlet
286
javaNestMode = JAVA_SCRIPTLET;
287                                 state = ISI_HOST_JAVA_JUMP;
288                                 tokenContextPath = JspMultiTokenContext.jspTagContextPath;
289                                 return JspTagTokenContext.SYMBOL2;
290                         } // switch (actChar)
291
// break; - not reached
292

293                     case ISI_HOST_JAVA_JUMP:
294                         nestMode = MODE_HOST_JAVA;
295                         state = ISI_LANGUAGE;
296                         transferMasterToSlave(javaSyntax, null);
297                         //javaSyntax.load(null, buffer, offset, stopOffset - offset, lastBuffer);
298
if (javaStateInfo == null) {
299                             javaStateInfo = javaSyntax.createStateInfo();
300                         }
301                         javaSyntax.storeState(javaStateInfo);
302                         break;
303
304                     case ISI_HOST_EL: // switch from hostSyntax to ELSyntax
305
switch (actChar) {
306                             case '$':
307                             case '#':
308                                 state = ISI_HOST_EL_D;
309                                 break;
310                             default:
311                                 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception JavaDoc("bad hostsyntax analyzer")); // NOI18N
312
} // switch (actChar)
313
break;
314
315                     case ISI_HOST_EL_D:
316                         switch (actChar) {
317                             case '{': // EL expression
318
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 JavaDoc("bad hostsyntax analyzer")); // NOI18N
324
} // switch (actChar)
325
break;
326
327                     case ISI_HOST_EL_JUMP:
328                         nestMode = MODE_HOST_EL;
329                         state = ISI_LANGUAGE;
330                         transferMasterToSlave(elSyntax, null);
331                         //elSyntax.load(null, buffer, offset, stopOffset - offset, lastBuffer);
332
if (elStateInfo == null) {
333                             elStateInfo = elSyntax.createStateInfo();
334                         }
335                         elSyntax.storeState(elStateInfo);
336                         break;
337
338                     case ISI_JSPTAG_JAVA: // switch from JSP tag to JavaSyntax
339
switch (actChar) {
340                             case '<':
341                                 state = ISI_JSPTAG_JAVA_LT;
342                                 break;
343                             default:
344                                 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception JavaDoc("bad hostsyntax analyzer")); // NOI18N
345
} // switch (actChar)
346
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 JavaDoc("bad hostsyntax analyzer")); // NOI18N
355
} // switch (actChar)
356
break;
357
358                     case ISI_JSPTAG_JAVA_LT_PC:
359                         switch (actChar) {
360                             case '!': // declaration
361
javaNestMode = JAVA_DECLARATION;
362                                 state = ISI_JSPTAG_JAVA_JUMP;
363                                 offset++;
364                                 tokenContextPath = JspMultiTokenContext.jspTagContextPath;
365                                 return JspTagTokenContext.SYMBOL2;
366                             case '=': // expression
367
javaNestMode = JAVA_EXPRESSION;
368                                 state = ISI_JSPTAG_JAVA_JUMP;
369                                 offset++;
370 //if (debug)
371
//System.out.println("returning (1x) pos " + offset + " symbol " + getTokenName(JspTagSyntax.JSP_SYMBOL2 + jspTagSyntaxInfo.tokenIDShift));
372
tokenContextPath = JspMultiTokenContext.jspTagContextPath;
373                                 return JspTagTokenContext.SYMBOL2;
374                             default: // assume this is a scriptlet
375
javaNestMode = JAVA_SCRIPTLET;
376                                 state = ISI_JSPTAG_JAVA_JUMP;
377 //if (debug)
378
//System.out.println("returning (2x) pos " + offset + " symbol " + getTokenName(JspTagSyntax.JSP_SYMBOL2 + jspTagSyntaxInfo.tokenIDShift));
379
tokenContextPath = JspMultiTokenContext.jspTagContextPath;
380                                 return JspTagTokenContext.SYMBOL2;
381                         } // switch (actChar)
382
// break; - not reached
383

384                     case ISI_JSPTAG_JAVA_JUMP:
385                         nestMode = MODE_HOST_JSPTAG_JAVA;
386                         state = ISI_LANGUAGE;
387                         transferMasterToSlave(javaSyntax, null);
388                         //javaSyntax.load(null, buffer, offset, stopOffset - offset, lastBuffer);
389
if (javaStateInfo == null) {
390                             javaStateInfo = javaSyntax.createStateInfo();
391                         }
392                         javaSyntax.storeState(javaStateInfo);
393                         break;
394             
395                     case ISI_JSPTAG_EL: // switch from JspTagSyntax to ELSyntax
396
switch (actChar) {
397                             case '$':
398                             case '#':
399                                 state = ISI_JSPTAG_EL_D;
400                                 break;
401                             default:
402                                 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception JavaDoc("bad hostsyntax analyzer")); // NOI18N
403
} // switch (actChar)
404
break;
405
406                     case ISI_JSPTAG_EL_D:
407                         switch (actChar) {
408                             case '{': // EL expression
409
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 JavaDoc("bad hostsyntax analyzer")); // NOI18N
415
} // switch (actChar)
416
break;
417
418                     case ISI_JSPTAG_EL_JUMP:
419                         nestMode = MODE_HOST_JSPTAG_EL;
420                         state = ISI_LANGUAGE;
421                         transferMasterToSlave(elSyntax, null);
422                         //elSyntax.load(null, buffer, offset, stopOffset - offset, lastBuffer);
423
if (elStateInfo == null) {
424                             elStateInfo = elSyntax.createStateInfo();
425                         }
426                         elSyntax.storeState(elStateInfo);
427                         break;
428
429                     // switching from Java back to JSPTAG
430
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 JavaDoc("bad hostsyntax analyzer")); // NOI18N
437
} // switch (actChar)
438
break;
439             
440                     case ISI_JAVA1_PC:
441                         switch (actChar) {
442                             case '>':
443                                 state = ISI_JAVA1_JUMP;
444                                 offset++;
445 //if (debug)
446
//System.out.println("returning (1xx) pos " + offset + " symbol " + getTokenName(JspTagSyntax.JSP_SYMBOL2 + jspTagSyntaxInfo.tokenIDShift));
447
tokenContextPath = JspMultiTokenContext.jspTagContextPath;
448                                 return JspTagTokenContext.SYMBOL2;
449                             default:
450                                 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception JavaDoc("bad hostsyntax analyzer")); // NOI18N
451
}
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                     // switching from Java back to host
461
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 JavaDoc("bad hostsyntax analyzer")); // NOI18N
468
} // switch (actChar)
469
break;
470             
471                     case ISI_JAVA2_PC:
472
473                         switch (actChar) {
474                             case '>':
475                                 state = ISI_JAVA2_JUMP;
476                                 offset++;
477 //if (debug)
478
//System.out.println("returning (2xx) pos " + offset + " symbol " + getTokenName(JspTagSyntax.JSP_SYMBOL2 + jspTagSyntaxInfo.tokenIDShift));
479
tokenContextPath = JspMultiTokenContext.jspTagContextPath;
480                                 return JspTagTokenContext.SYMBOL2;
481                             default:
482                                 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception JavaDoc("bad hostsyntax analyzer")); // NOI18N
483
}
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                     // switching from EL back to JSPTAG
493
case ISI_EL1_SWITCH:
494                         switch (actChar) {
495                             case '}':
496                                 state = ISI_EL1_JUMP;
497                                 offset++;
498 //if (debug)
499
//System.out.println("returning (1xx) pos " + offset + " symbol " + getTokenName(ELSyntax.ED_DELIM + elSyntaxInfo.tokenIDShift));
500
tokenContextPath = JspMultiTokenContext.elContextPath;
501                                 return ELTokenContext.EL_DELIM;
502                             default:
503                                 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception JavaDoc("bad hostsyntax analyzer")); // NOI18N
504
} // switch (actChar)
505
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                     // switching from EL back to host
515
case ISI_EL2_SWITCH:
516                         switch (actChar) {
517                             case '}':
518                                 state = ISI_EL2_JUMP;
519                                 offset++;
520 //if (debug)
521
//System.out.println("returning (1xx) pos " + offset + " symbol " + getTokenName(ELSyntax.ED_DELIM + elSyntaxInfo.tokenIDShift));
522
tokenContextPath = JspMultiTokenContext.elContextPath;
523                                 return ELTokenContext.EL_DELIM;
524                             default:
525                                 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception JavaDoc("bad hostsyntax analyzer")); // NOI18N
526
} // switch (actChar)
527
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             } // end of while(offset...)
543

544             if (state != ISI_LANGUAGE) {
545                 /** At this stage there's no more text in the scanned buffer.
546                 * Scanner first checks whether this is completely the last
547                 * available buffer.
548                 */

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 //if (debug)
567
//System.out.println("returning (3) pos " + offset + " symbol " + getTokenName(JspTagSyntax.JSP_SYMBOL2 + jspTagSyntaxInfo.tokenIDShift));
568
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 //if (debug)
582
//System.out.println("returning (3.5) pos " + offset + " symbol " + getTokenName(JspELSyntax.EL_DELIM + elSyntaxInfo.tokenIDShift));
583
tokenContextPath = JspMultiTokenContext.elContextPath;
584                             return ELTokenContext.EL_DELIM;
585                     } // switch (state)
586
} // if lastBuffer
587
//if (debug)
588
//System.out.println("returning (4) pos " + offset + " symbol " + getTokenName(null));
589
return null;
590             } // if state != ISI_LANGUAGE - inner
591
} // if state != ISI_LANGUAGE - outer
592

593         //</editor-fold>
594

595         // now state is ISI_LANGUAGE
596
//if (state != ISI_LANGUAGE) new Exception("state should be ISI_LANGUAGE").printStackTrace();
597
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             // BIG BRANCH - we are in the HOST mode
607
//<editor-fold defaultstate="collapsed" desc="MODE_HOST & MODE_JSPTAG">
608
case MODE_HOST:
609                 if (hostStateInfo == null) {
610                     hostStateInfo = hostSyntax.createStateInfo();
611                     hostSyntax.reset();
612                     hostSyntax.storeState(hostStateInfo);
613                 }
614                     
615 /*if (debug) {
616 System.out.print("NOT EQUAL tokenOffset=" + tokenOffset + ", offset=" + offset + ", tokenPart='");
617 for (int i = tokenOffset; i<offset;i++) System.out.print(buffer[i]);
618 System.out.println("', firstTokenID=" + firstTokenID + ", firstTokenLength=" + firstTokenLength);
619 System.out.println("hoststate " + hostStateInfo.getState() + ", prescan=" + hostStateInfo.getPreScan());
620 System.out.println("helpstate " + helpHostStateInfo.getState() + ", prescan=" + helpHostStateInfo.getPreScan());
621 } */

622         
623 //if (equalPositions && (hostStateInfo.getPreScan() != 0))
624
//new Exception("prescan should be 0 !!").printStackTrace();
625
//if (debug)
626
//System.out.println("html state at offset " + ((BaseStateInfo)hostStateInfo).toString(this));
627
if (firstTokenNotRead) {
628                     // the first step - parse the first token of the slave
629
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                         // need to property transfer states
641
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 //if (debug)
653
//System.out.println("returnuju (1) " + null + " at " + offset);
654
return null;
655                     }
656                     if (returnedTokenID.getNumericID() == HTMLTokenContext.BLOCK_COMMENT_ID && isXMLSyntax() )
657                         canBe = DELIMCHECK_NO;
658                     else{
659                         // find out if the token could contain a starting symbol for JspTag or Java
660
canBe = canBeHostDelimiter(tokenOffset, slaveOffset, slaveOffset, false);
661                     }
662                     if (canBe == DELIMCHECK_NO) { // do not switch
663
offset = slaveOffset;
664                         if (hostStateInfo == null) {
665                             hostStateInfo = hostSyntax.createStateInfo();
666                         }
667                         hostSyntax.storeState(hostStateInfo);
668 //if (debug)
669
//System.out.println("returnuju (2) " + slaveTokenID + " at " + offset);
670
return slaveTokenID;
671                     }
672                     // store the state
673
hostSyntax.storeState(firstHostStateInfo);
674 //if (firstHostStateInfo == hostStateInfo)
675
//new Exception("stateinfo instance conflict").printStackTrace();
676
}
677                 else { // first position read - offsets different and firstTokenID is a valid token
678
transferMasterToSlave(hostSyntax, hostStateInfo);
679                     canBe = DELIMCHECK_PART;
680                 }
681
682                 // we have successfully read the first token, the following statements hold:
683
// - canBe is not DELIMCHECK_NO
684
// - firstTokenID and firstTokenLength are meaningful
685
// - if (equalPositions) then firstHostStateInfo is meaningful
686
//if (firstTokenID == null) {
687
//new Exception("invalid firstTokenID !!!!!!!").printStackTrace();
688
//}
689
while (canBe == DELIMCHECK_PART) { // need another token
690
// now get the new token
691
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                         // ask about the delimiter, but with lastPart=true
699
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 //if (debug)
722
//System.out.println("returnuju (3) " + null + " at " + offset);
723
return null;
724                     }
725                     canBe = canBeHostDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, false);
726                 }
727         
728                 // now canBe is not DELIMCHECK_PART
729
// now we have read possibly more tokens and know whether to switch or not
730
if (canBe == DELIMCHECK_NO) { // do not switch
731
offset = tokenOffset + firstTokenLength;
732                     if (equalPositions) {
733                         hostStateInfo = firstHostStateInfo;
734                         firstHostStateInfo = hostSyntax.createStateInfo();
735                     }
736                     else {
737 //if (debug)
738
//System.out.println("= imagine - rescan called !!");
739
//if (helpHostStateInfo.getPreScan() != 0)
740
//new Exception("help prescan should be 0 !!").printStackTrace();
741
// we need to rescan the first token to find out the state
742
// now helpHostStateInfo is useful
743
hostSyntax.load(helpHostStateInfo, buffer, tokenOffset, stopOffset - tokenOffset, lastBuffer, -1);
744                         returnedTokenID = hostSyntax.nextToken();
745 //if (tokenOffset != hostSyntax.getTokenOffset())
746
//new Exception("starts of tokens do not match").printStackTrace();
747
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 //if (debug)
757
//System.out.println("returnuju (4) " + firstTokenID + " at " + offset);
758

759                     return firstTokenID;
760                 }
761                 else { // we found a delimiter
762
//if (canBe >= tokenOffset + firstTokenLength)
763
//new Exception("value of canBe is invalid !!!!!!!").printStackTrace();
764
// now use the saved state
765
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                     // we got the StateInfo, which is why we did all this
775
if (hostStateInfo == null) {
776                         hostStateInfo = hostSyntax.createStateInfo();
777                     }
778 //if (debug)
779
//System.out.println("html state before saving back " + ((BaseStateInfo)hostStateInfo).toString(this));
780
hostSyntax.storeState(hostStateInfo);
781                     hostStateInfo.setPreScan(0);
782 //if (hostSyntax.getOffset() != canBe)
783
//new Exception("bad number of characters parsed !!!").printStackTrace();
784
offset = canBe;
785 /*if (debug) {
786 System.out.println("switching from HOST to JSPTAG at offset " + offset + ", hostState " + ((BaseStateInfo)hostStateInfo).toString(this));
787 System.out.println("offset of the returned (a)" + hostSyntax.getOffset());
788 System.out.println("found delimiter at " + offset);
789 System.out.println("returnuju (5) " + firstTokenID + " at " + offset);
790 }*/

791                     return firstTokenID;
792                 }
793                 //break; //- not reached
794

795         
796             // BIG BRANCH - we are in the HOST_JSPTAG mode
797
case MODE_HOST_JSPTAG:
798                 // check if the JSP tag hasn't finished on its own will
799
if ((jspTagStateInfo != null) && (jspTagStateInfo.getState() == JspTagSyntax.ISA_END_JSP)) {
800                     // give up control
801
jspTagStateInfo = null;
802                     nestMode = MODE_HOST;
803 //if (debug) {
804
//System.out.println("switching back to HOST from JSPTAG at offset " + offset + ", hostState " + ((BaseStateInfo)hostStateInfo).toString(this));
805
//System.out.println("returnuju (6) " /*+ JspTagSyntax.TEXT + jspTagSyntaxInfo.tokenIDShift */+ " at " + offset);
806
//}
807
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                     // the first step - parse the first token of the slave
818
transferMasterToSlave(jspTagSyntax, jspTagStateInfo);
819                     returnedTokenID = jspTagSyntax.nextToken();
820                     if (returnedTokenID == JspTagTokenContext.AFTER_UNEXPECTED_LT) {
821                         // give up control
822
jspTagStateInfo = null;
823                         nestMode = MODE_HOST;
824                         hostStateInfo.setPreScan(0);
825                         tokenContextPath = JspMultiTokenContext.jspTagContextPath;
826 //System.out.println("switch to host " + returnedTokenID + " at " + offset);
827
return returnedTokenID;
828                     }
829                     slaveTokenID = returnedTokenID;
830                     tokenContextPath = JspMultiTokenContext.jspTagContextPath;
831 //if (debug)
832
//System.out.println("first JSPtoken returned '" + getToken(jspTagSyntax) + "' id " + slaveTokenID);
833
slaveOffset = jspTagSyntax.getOffset();
834                     firstTokenID = slaveTokenID;
835                     firstTokenLength = jspTagSyntax.getTokenLength();
836                     if (slaveTokenID == null) {
837                         offset = slaveOffset;
838                         firstTokenLength = -1;
839                         // need to properly transfer states
840
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 //if (debug)
852
//System.out.println("returnuju (7) " + null + " at " + offset);
853
return null;
854                     }
855                     // find out if the token could contain a starting symbol for Java
856
canBe = canBeJspTagDelimiter(tokenOffset, slaveOffset, slaveOffset, false, returnedTokenID == JspTagTokenContext.COMMENT);
857                     if (canBe == DELIMCHECK_NO) { // do not switch
858
offset = slaveOffset;
859                         if (jspTagStateInfo == null) {
860                             jspTagStateInfo = jspTagSyntax.createStateInfo();
861                         }
862                         jspTagSyntax.storeState(jspTagStateInfo);
863 //if (debug)
864
//System.out.println("returnuju (8) " + slaveTokenID + " at " + offset);
865
return slaveTokenID;
866                     }
867                     // store the state
868
jspTagSyntax.storeState(firstJspTagStateInfo);
869                 }
870                 else { // first position read - offsets different and firstTokenID is a valid token
871
transferMasterToSlave(jspTagSyntax, jspTagStateInfo);
872                     canBe = DELIMCHECK_PART;
873                 }
874
875                 // we have successfully read the first token, the following statements hold:
876
// - canBe is not DELIMCHECK_NO
877
// - firstTokenID and firstTokenLength are meaningful
878
// - if (equalPositions) then firstJspTagStateInfo is meaningful
879
//if (firstTokenID == null) {
880
//new Exception("invalid firstTokenID !!!!!!!").printStackTrace();
881
//}
882
while (canBe == DELIMCHECK_PART) { // need another token
883
// now get the new token
884
returnedTokenID = jspTagSyntax.nextToken();
885                     slaveTokenID = returnedTokenID;
886                     tokenContextPath = JspMultiTokenContext.jspTagContextPath;
887                     slaveOffset = jspTagSyntax.getOffset();
888
889                     if ((slaveTokenID == null) && lastBuffer) {
890                         // ask about the delimiter, but with lastPart=true
891
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 //if (debug)
914
//System.out.println("returnuju (9) " + null + " at " + offset);
915
return null;
916                     }
917                     canBe = canBeJspTagDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, false, returnedTokenID == JspTagTokenContext.COMMENT);
918                 }
919         
920                 // now canBe is not DELIMCHECK_PART
921
// now we have read possibly more tokens and know whether to switch or not
922
if (canBe == DELIMCHECK_NO) { // do not switch
923
offset = tokenOffset + firstTokenLength;
924                     if (equalPositions) {
925                         jspTagStateInfo = firstJspTagStateInfo;
926                         firstJspTagStateInfo = jspTagSyntax.createStateInfo();
927                     }
928                     else {
929 //if (debug)
930
//System.out.println("= imagine - rescan called !!");
931
// we need to rescan the first token to find out the state
932
// now helpJspTagStateInfo is useful
933
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 //if (slaveTokenID != firstTokenID)
942
//new Exception("token ID does not match !!!!!!!").printStackTrace();
943
//if (offset != jspTagSyntax.getOffset())
944
//new Exception("offset does not match !!!!!!!").printStackTrace();
945
}
946 //if (debug)
947
//System.out.println("returnuju (10) " + firstTokenID + " at " + offset);
948
return firstTokenID;
949                 }
950                 else { // we found a delimiter
951
//if (canBe >= tokenOffset + firstTokenLength)
952
//new Exception("value of canBe is invalid !!!!!!!").printStackTrace();
953
// now use the saved state
954
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                     // we got the StateInfo, which is why we did all this
963
if (jspTagStateInfo == null) {
964                         jspTagStateInfo = jspTagSyntax.createStateInfo();
965                     }
966                     jspTagSyntax.storeState(jspTagStateInfo);
967                     jspTagStateInfo.setPreScan(0);
968 //if (jspTagSyntax.getOffset() != canBe)
969
//new Exception("bad number of characters parsed !!!").printStackTrace();
970
offset = canBe;
971 //if (debug) {
972
//System.out.println("offset of the returned (a)" + jspTagSyntax.getOffset());
973
//System.out.println("found delimiter at " + offset);
974
//System.out.println("returnuju (11) " + firstTokenID + " at " + offset);
975
//}
976
return firstTokenID;
977                 }
978                 //break; //- not reached
979

980                 //</editor-fold>
981
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                     // the first step - parse the first token of the slave
990
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                        // need to property transfer states
1001
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//if (debug)
1013
//System.out.println("returnuju (12) " + null + " at " + offset);
1014
return null;
1015                    }
1016                    // find out if the token could contain an ending symbol for a Java block
1017
canBe = canBeJavaDelimiter(tokenOffset, slaveOffset, slaveOffset, false, nestMode);
1018                    if (canBe == DELIMCHECK_NO) { // do not switch
1019
offset = slaveOffset;
1020                        if (javaStateInfo == null) {
1021                            javaStateInfo = javaSyntax.createStateInfo();
1022                        }
1023                        javaSyntax.storeState(javaStateInfo);
1024//if (debug)
1025
//System.out.println("returnuju (13) " + slaveTokenID + " at " + offset);
1026
return slaveTokenID;
1027                    }
1028                    // store the state
1029
javaSyntax.storeState(firstJavaStateInfo);
1030                }
1031                else { // first position read - offsets different and firstTokenID is a valid token
1032
transferMasterToSlave(javaSyntax, javaStateInfo);
1033                    canBe = DELIMCHECK_PART;
1034                }
1035
1036                // we have successfully read the first token, the following statements hold:
1037
// - canBe is not DELIMCHECK_NO
1038
// - firstTokenID and firstTokenLength are meaningful
1039
// - if (equalPositions) then firstJavaStateInfo is meaningful
1040
//if (firstTokenID == null) {
1041
//new Exception("invalid firstTokenID !!!!!!!").printStackTrace();
1042
//}
1043
while (canBe == DELIMCHECK_PART) { // need another token
1044
// now get the new token
1045
returnedTokenID = javaSyntax.nextToken();
1046                    slaveTokenID = returnedTokenID;
1047                    tokenContextPath = getJavaTokenContextPath();
1048                    slaveOffset = javaSyntax.getOffset();
1049
1050                    if ((slaveTokenID == null) && lastBuffer) {
1051                        // ask about the delimiter, but with lastPart=true
1052
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//if (debug)
1075
//System.out.println("returnuju (14) " + null + " at " + offset);
1076
return null;
1077                    }
1078                    canBe = canBeJavaDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, false, nestMode);
1079                }
1080        
1081                // now canBe is not DELIMCHECK_PART
1082
// now we have read possibly more tokens and know whether to switch or not
1083
if (canBe == DELIMCHECK_NO) { // do not switch
1084
offset = tokenOffset + firstTokenLength;
1085                    if (equalPositions) {
1086                        javaStateInfo = firstJavaStateInfo;
1087                        firstJavaStateInfo = javaSyntax.createStateInfo();
1088                    }
1089                    else {
1090//if (debug)
1091
//System.out.println("= imagine - rescan called !!");
1092
// we need to rescan the first token to find out the state
1093
// now helpJavaStateInfo is useful
1094
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//if (slaveTokenID != firstTokenID)
1103
//new Exception("token ID does not match !!!!!!!").printStackTrace();
1104
//if (offset != javaSyntax.getOffset())
1105
//new Exception("offset does not match !!!!!!!").printStackTrace();
1106
}
1107//if (debug)
1108
//System.out.println("returnuju (15) " + firstTokenID + " at " + offset);
1109
return firstTokenID;
1110                }
1111                else { // we found a delimiter
1112
//if (canBe >= tokenOffset + firstTokenLength)
1113
//new Exception("value of canBe is invalid !!!!!!!").printStackTrace();
1114
// now use the saved state
1115
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                    // we got the StateInfo, which is why we did all this
1124
if (javaStateInfo == null) {
1125                        javaStateInfo = javaSyntax.createStateInfo();
1126                    }
1127                    javaSyntax.storeState(javaStateInfo);
1128                    javaStateInfo.setPreScan(0);
1129//if (javaSyntax.getOffset() != canBe)
1130
//new Exception("bad number of characters parsed !!!").printStackTrace();
1131
offset = canBe;
1132/*if (debug) {
1133System.out.println("offset of the returned (a)" + javaSyntax.getOffset());
1134System.out.println("found delimiter at " + offset);
1135System.out.println("returnuju (16) " + firstTokenID + " at " + offset);
1136}*/

1137                    
1138                    return firstTokenID;
1139                }
1140                // break; //- not reached
1141

1142                //<editor-fold defaultstate="collapsed" desc="MODE_HOST_EL">
1143
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                    // the first step - parse the first token of the slave
1152
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                        // need to property transfer states
1163
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//if (debug)
1175
//System.out.println("returnuju (12.5) " + null + " at " + offset);
1176
return null;
1177                    }
1178                    // find out if the token could contain an ending symbol for a EL block
1179
canBe = canBeELDelimiter(tokenOffset, slaveOffset, slaveOffset, false, nestMode);
1180                    if (canBe == DELIMCHECK_NO) { // do not switch
1181
offset = slaveOffset;
1182                        if (elStateInfo == null) {
1183                            elStateInfo = elSyntax.createStateInfo();
1184                        }
1185                        elSyntax.storeState(elStateInfo);
1186//if (debug)
1187
//System.out.println("returnuju (13.5) " + slaveTokenID + " at " + offset);
1188
return slaveTokenID;
1189                    }
1190                    // store the state
1191
elSyntax.storeState(firstELStateInfo);
1192                }
1193                else { // first position read - offsets different and firstTokenID is a valid token
1194
transferMasterToSlave(elSyntax, elStateInfo);
1195                    canBe = DELIMCHECK_PART;
1196                }
1197
1198                // we have successfully read the first token, the following statements hold:
1199
// - canBe is not DELIMCHECK_NO
1200
// - firstTokenID and firstTokenLength are meaningful
1201
// - if (equalPositions) then firstELStateInfo is meaningful
1202
//if (firstTokenID == null) {
1203
//new Exception("invalid firstTokenID !!!!!!!").printStackTrace();
1204
//}
1205
while (canBe == DELIMCHECK_PART) { // need another token
1206
// now get the new token
1207
returnedTokenID = elSyntax.nextToken();
1208                    slaveTokenID = returnedTokenID;
1209                    tokenContextPath = JspMultiTokenContext.elContextPath;
1210                    slaveOffset = elSyntax.getOffset();
1211
1212                    if ((slaveTokenID == null) && lastBuffer) {
1213                        // ask about the delimiter, but with lastPart=true
1214
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//if (debug)
1237
//System.out.println("returnuju (14) " + null + " at " + offset);
1238
return null;
1239                    }
1240                    canBe = canBeELDelimiter(tokenOffset, slaveOffset, tokenOffset + firstTokenLength, false, nestMode);
1241                }
1242        
1243                // now canBe is not DELIMCHECK_PART
1244
// now we have read possibly more tokens and know whether to switch or not
1245
if (canBe == DELIMCHECK_NO) { // do not switch
1246
offset = tokenOffset + firstTokenLength;
1247                    if (equalPositions) {
1248                        elStateInfo = firstELStateInfo;
1249                        firstELStateInfo = elSyntax.createStateInfo();
1250                    }
1251                    else {
1252//if (debug)
1253
//System.out.println("= imagine - rescan called !!");
1254
// we need to rescan the first token to find out the state
1255
// now helpELStateInfo is useful
1256
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//if (slaveTokenID != firstTokenID)
1265
//new Exception("token ID does not match !!!!!!!").printStackTrace();
1266
//if (offset != elSyntax.getOffset())
1267
//new Exception("offset does not match !!!!!!!").printStackTrace();
1268
}
1269//if (debug)
1270
//System.out.println("returnuju (15.5) " + firstTokenID + " at " + offset);
1271
return firstTokenID;
1272                }
1273                else { // we found a delimiter
1274
//if (canBe >= tokenOffset + firstTokenLength)
1275
//new Exception("value of canBe is invalid !!!!!!!").printStackTrace();
1276
// now use the saved state
1277
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                    // we got the StateInfo, which is why we did all this
1286
if (elStateInfo == null) {
1287                        elStateInfo = elSyntax.createStateInfo();
1288                    }
1289                    elSyntax.storeState(elStateInfo);
1290                    elStateInfo.setPreScan(0);
1291//if (elSyntax.getOffset() != canBe)
1292
//new Exception("bad number of characters parsed !!!").printStackTrace();
1293
offset = canBe;
1294/*if (debug) {
1295System.out.println("offset of the returned (a)" + elSyntax.getOffset());
1296System.out.println("found delimiter at " + offset);
1297System.out.println("returnuju (16.5) " + firstTokenID + " at " + offset);
1298}*/

1299                    return firstTokenID;
1300                }
1301                // break; //- not reached
1302

1303                //</editor-fold>
1304
default:
1305                ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception JavaDoc("bad nestmode")); // NOI18N
1306
tokenContextPath = JspMultiTokenContext.contextPath;
1307                return JspMultiTokenContext.ERROR; // !!! don't know what to return
1308
}
1309    }
1310        
1311    //<editor-fold defaultstate="collapsed" desc="help methods">
1312

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    /** Method for debugging purposes * /
1326    private String getToken(Syntax syntax) {
1327        StringBuffer token = new StringBuffer();
1328        for (int i=syntax.getOffset()-syntax.getTokenLength();i<syntax.getOffset();i++)
1329            token.append(buffer[i]);
1330        return token.toString();
1331    }
1332     */

1333  
1334    /** Checks if the part of the buffer starting at tokenOffset and ending just before endOffset
1335    * contains a "delimiter" or could contain a starting part of a "delimiter", where
1336    * "delimiter" is a lexical structure which could start a JSP tag of a Java block in
1337    * the host language, i.e. <code>&lt;jsp:useBean</code> or <code>&lt;%=</code>.
1338    * @return <ul>
1339    * <li><code>DELIMCHECK_NO</code> if the part of the buffer does not contain a delimiter or its part</li>
1340    * <li><code>DELIMCHECK_PART</code> if the part of the buffer contains part of the delimiter</li>
1341    * <li>index of the starting symbol of the delimiter if the part of the buffer contains the delimiter.
1342    * In such a case variable <code>state</code> is set properly.</li>
1343    * </ul>
1344    */

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 JavaDoc 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; // not really true, the delimiter can't start here
1379
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                    ) { // possible tag begining
1391
delimState = HOST_TAG;
1392                        tagString = new StringBuffer JavaDoc();
1393                        tagString.append(actChar);
1394                        break; // the switch statement
1395
}
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                    ) { // possible tag begining
1422
delimState = HOST_TAG;
1423                        tagString = new StringBuffer JavaDoc();
1424                        tagString.append(actChar);
1425                        break; // the switch statement
1426
}
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                    ) { // possible tag begining
1448
delimState = HOST_TAG;
1449                        // we are checking whether this is a JSP tag, however even if it is,
1450
// JspTagSyntax will report any spaces between < and tagname as errors
1451
tagString = new StringBuffer JavaDoc();
1452                        //if there is a space after </ let the text be parsed by JSP parser - it will report an error
1453
if(actChar != '/') tagString.append(actChar);
1454                        break; // the switch statement
1455
}
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                    ) { // the tag continues
1478
tagString.append(actChar);
1479                        break; // the switch statement
1480
}
1481          
1482                    switch (actChar) {
1483                        default:
1484                            if (isJspTag(tagString.toString())) {
1485                                state = ISI_HOST_JSPTAG;
1486//if (debug)
1487
//System.out.println("found beginning of JspTag at " + possibleBeginning);
1488
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 '@': // directive
1501
case '-': // JSP comment
1502
state = ISI_HOST_JSPTAG;
1503//if (debug)
1504
//System.out.println("found beginning of directive/comment at " + possibleBeginning);
1505
return possibleBeginning;
1506                        case '!': // declaration
1507
javaNestMode = JAVA_DECLARATION;
1508                            state = ISI_HOST_JAVA;
1509//if (debug)
1510
//System.out.println("found beginning of declaration/expression at " + possibleBeginning);
1511
return possibleBeginning;
1512                            
1513                        case '=': // expression
1514
javaNestMode = JAVA_EXPRESSION;
1515                            state = ISI_HOST_JAVA;
1516//if (debug)
1517
//System.out.println("found beginning of declaration/expression at " + possibleBeginning);
1518
return possibleBeginning;
1519                        default: // scriptlet
1520
javaNestMode = JAVA_SCRIPTLET;
1521                            state = ISI_HOST_JAVA;
1522//if (debug)
1523
//System.out.println("found beginning of scriptlet at " + possibleBeginning);
1524
return possibleBeginning;
1525                    }
1526                    //break;
1527

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; // not really true, the delimiter can't start here
1555
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//if (debug)
1575
//System.out.println("found beginning of JspTag at " + possibleBeginning);
1576
return possibleBeginning;
1577                    }
1578            }
1579        }
1580    
1581        // we have reached the end of the scanned area
1582
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 JavaDoc("invalid state")); // NOI18N
1595
return DELIMCHECK_NO;
1596        }
1597    }
1598  
1599    /** Checks if the part of the buffer starting at tokenOffset and ending just before endOffset
1600    * contains a "delimiter" or could contain a starting part of a "delimiter", where
1601    * "delimiter" is a lexical structure which could start a Java block inside a JSP tag,
1602    * i.e. <code>&lt;%=</code>.
1603    * @return <ul>
1604    * <li><code>DELIMCHECK_NO</code> if the part of the buffer does not contain a delimiter or its part</li>
1605    * <li><code>DELIMCHECK_PART</code> if the part of the buffer contains part of the delimiter</li>
1606    * <li>index of the starting symbol of the delimiter if the part of the buffer contains the delimiter.
1607    * In such a case variable <code>state</code> is set properly.</li>
1608    * </ul>
1609    */

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; // not really true, the delimiter can't start here
1646
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 '!': // declaration
1672
javaNestMode = JAVA_DECLARATION;
1673                            state = ISI_JSPTAG_JAVA;
1674//if (debug)
1675
//System.out.println("found beginning of declaration/expression at " + possibleBeginning);
1676
return possibleBeginning;
1677                            
1678                        case '=': // expression
1679
javaNestMode = JAVA_EXPRESSION;
1680                            state = ISI_JSPTAG_JAVA;
1681//if (debug)
1682
//System.out.println("found beginning of declaration/expression at " + possibleBeginning);
1683
return possibleBeginning;
1684                        case '@': // declaration
1685
case '-': // comment
1686
delimState = JSPTAG_INIT;
1687                            break;
1688                        default: // scriptlet
1689
javaNestMode = JAVA_SCRIPTLET;
1690                            state = ISI_JSPTAG_JAVA;
1691//if (debug)
1692
//System.out.println("found beginning of scriptlet at " + possibleBeginning);
1693
return possibleBeginning;
1694                    }
1695                    //break;
1696

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; // not really true, the delimiter can't start here
1724
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//if (debug)
1740
//System.out.println("found beginning of scriptlet at " + possibleBeginning);
1741
return possibleBeginning;
1742            }
1743        }
1744    
1745        // we have reached the end of the scanned area
1746
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                //this state (error???) happens when only one character '\'
1757
//is scanned by this method (tokenOffset = endOffset - 1)
1758
return DELIMCHECK_NO;
1759            default:
1760                ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception JavaDoc("invalid state " + delimState)); // NOI18N
1761
return DELIMCHECK_NO;
1762        }
1763    }
1764  
1765    /** Checks if the part of the buffer starting at tokenOffset and ending just before endOffset
1766    * contains a "delimiter" or could contain a starting part of a "delimiter", where
1767    * "delimiter" is a lexical structure which could end a Java block,
1768    * i.e. <code>%&gt;</code>.
1769    * @return <ul>
1770    * <li><code>DELIMCHECK_NO</code> if the part of the buffer does not contain a delimiter or its part</li>
1771    * <li><code>DELIMCHECK_PART</code> if the part of the buffer contains part of the delimiter</li>
1772    * <li>index of the starting symbol of the delimiter if the part of the buffer contains the delimiter.
1773    * In such a case variable <code>state</code> is set properly.</li>
1774    * </ul>
1775    */

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//if (debug)
1809
//System.out.println("found end of Java at " + possibleBeginning);
1810
return possibleBeginning;
1811                                case MODE_HOST_JAVA:
1812                                    state = ISI_JAVA2_SWITCH;
1813//if (debug)
1814
//System.out.println("found end of Java at " + possibleBeginning);
1815
return possibleBeginning;
1816                            }
1817                            ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception JavaDoc("bad nestMode")); // NOI18N
1818
//break; - not reached
1819
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        // we have reached the end of the scanned area
1836
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 JavaDoc("invalid state")); // NOI18N
1843
return DELIMCHECK_NO;
1844        }
1845    }
1846  
1847    /** Checks if the part of the buffer starting at tokenOffset and ending just before endOffset
1848    * contains a "delimiter" or could contain a starting part of a "delimiter", where
1849    * "delimiter" is a lexical structure which could end a EL block,
1850    * i.e. <code>}</code>.
1851    * @return <ul>
1852    * <li><code>DELIMCHECK_NO</code> if the part of the buffer does not contain a delimiter or its part</li>
1853    * <li><code>DELIMCHECK_PART</code> if the part of the buffer contains part of the delimiter</li>
1854    * <li>index of the starting symbol of the delimiter if the part of the buffer contains the delimiter.
1855    * In such a case variable <code>state</code> is set properly.</li>
1856    * </ul>
1857    */

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: // the only state for now
1870
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//if (debug)
1879
//System.out.println("found end of EL at " + possibleBeginning);
1880
return possibleBeginning;
1881                                case MODE_HOST_EL:
1882                                    state = ISI_EL2_SWITCH;
1883//if (debug)
1884
//System.out.println("found end of EL at " + possibleBeginning);
1885
return possibleBeginning;
1886                            }
1887                            ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception JavaDoc("bad nestMode")); // NOI18N
1888
break;
1889                        default:
1890                            if (offset >= firstTokenEnd)
1891                                return DELIMCHECK_NO;
1892                            break;
1893                    }
1894                    break;
1895            }
1896      
1897            offset++;
1898        }
1899    
1900        // we have reached the end of the scanned area
1901
switch (delimState) {
1902            case EL_INIT:
1903                return DELIMCHECK_NO;
1904            default:
1905                ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, new Exception JavaDoc("invalid state")); // NOI18N
1906
return DELIMCHECK_NO;
1907        }
1908    }
1909  
1910    /** Determines whether a given string is a JSP tag. */
1911    protected boolean isJspTag(String JavaDoc tagName) {
1912        boolean canBeJsp = tagName.startsWith("jsp:"); // NOI18N
1913
return canBeJsp;
1914    }
1915    
1916    /** Determines whether any EL expressions should be colored as expressions,
1917     * or ignored. This class does not have all the context necessary to decide this,
1918     * so it just returns false (meaning that EL should be colored). Subclasses
1919     * should override this to return the correct value per section JSP.3.3.2
1920     * of the specification.
1921     * @param whether this expression is inside the JSP tag value, or just in template text
1922     * @return true if the expression should be ignored, false if it should be treated as an expression
1923     */

1924    protected boolean isELIgnored(boolean inJspTag) {
1925        return false;
1926    }
1927
1928    /** Determines whether the page is in xml syntax or not.
1929     * This class does not have all the context necessary to decide this,
1930     * so it just returns false. Subclasses
1931     * should override this to return the correct value.
1932     * @return true if the page is JSP Document, false if the page is in standart syntax
1933     */

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        //slave.setLastBuffer(lastBuffer); // PENDING - maybe not necessary
1941
//slave.setStopOffset(stopOffset); // PENDING - maybe not necessary
1942
}
1943  
1944    /** Store state of this analyzer into given mark state. */
1945    public void storeState(StateInfo stateInfo) {
1946        super.storeState(stateInfo);
1947        JspStateInfo jspsi = (JspStateInfo)stateInfo;
1948        // nest mode
1949
jspsi.nestMode = nestMode;
1950        jspsi.javaNestMode = javaNestMode;
1951        
1952        // regular stateinfos
1953
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        // stateOfScanningAtInit, firstTokenID, firstTokenLength
1986
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/*System.out.print("storing state at offset=" + offset + ", tokenOffset=" + tokenOffset + ", token=");
2020for(int i=tokenOffset;i<offset;i++)
2021System.out.print(buffer[i]);
2022System.out.println();
2023System.out.println(((JspStateInfo)stateInfo).toString(this));*/

2024    }
2025
2026    public void loadState(StateInfo stateInfo) {
2027/*System.out.println("loading state");
2028System.out.println(((JspStateInfo)stateInfo).toString(this)); */

2029        super.loadState(stateInfo);
2030        JspStateInfo jspsi = (JspStateInfo)stateInfo;
2031        nestMode = jspsi.nestMode;
2032        javaNestMode = jspsi.javaNestMode;
2033 
2034        // now all the slave states
2035
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        // stateOfScanningAtInit, firstTokenID, firstTokenLength
2068
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                // host
2144
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                // host
2155
transferMasterToSlave(hostSyntax, hostStateInfo);
2156                ret = hostSyntax.compareState(jspsi.hostStateInfo);
2157                if (ret == Syntax.DIFFERENT_STATE) return ret;
2158                // jspTag
2159
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                // host
2170
transferMasterToSlave(hostSyntax, hostStateInfo);
2171                ret = hostSyntax.compareState(jspsi.hostStateInfo);
2172                if (ret == DIFFERENT_STATE) return ret;
2173                // jspTag
2174
transferMasterToSlave(jspTagSyntax, jspTagStateInfo);
2175                ret = jspTagSyntax.compareState(jspsi.jspTagStateInfo);
2176                if (ret == DIFFERENT_STATE) return ret;
2177                // el
2178
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                // host
2189
transferMasterToSlave(hostSyntax, hostStateInfo);
2190                ret = hostSyntax.compareState(jspsi.hostStateInfo);
2191                if (ret == DIFFERENT_STATE) return ret;
2192                // el
2193
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                // host
2204
transferMasterToSlave(hostSyntax, hostStateInfo);
2205                ret = hostSyntax.compareState(jspsi.hostStateInfo);
2206                if (ret == DIFFERENT_STATE) return ret;
2207                // jspTag
2208
transferMasterToSlave(jspTagSyntax, jspTagStateInfo);
2209                ret = jspTagSyntax.compareState(jspsi.jspTagStateInfo);
2210                if (ret == DIFFERENT_STATE) return ret;
2211                // java
2212
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                // host
2223
transferMasterToSlave(hostSyntax, hostStateInfo);
2224                ret = hostSyntax.compareState(jspsi.hostStateInfo);
2225                if (ret == DIFFERENT_STATE) return ret;
2226                // java
2227
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 JavaDoc getNestModeName (int nestMode){
2241        switch (nestMode){
2242            case MODE_HOST:
2243                return "MODE_HOST"; // NOI18N
2244
case MODE_HOST_JSPTAG:
2245                return "MODE_HOST_JSPTAG"; // NOI18N
2246
case MODE_HOST_EL:
2247                return "MODE_HOST_EL"; // NOI18N
2248
case MODE_HOST_JSPTAG_EL:
2249                return "MODE_HOST_JSPTAG_EL"; // NOI18N
2250
case MODE_HOST_JSPTAG_JAVA:
2251                return "MODE_HOST_JSPTAG_JAVA"; // NOI18N
2252
case MODE_HOST_JAVA:
2253                return "MODE_HOST_JAVA"; // NOI18N
2254
default:
2255                return "unknown nestMode " + nestMode; // NOI18N
2256
}
2257    }
2258
2259    public String JavaDoc getStateName(int stateNumber) {
2260        switch(stateNumber) {
2261            case ISI_LANGUAGE:
2262                 return "ISI_LANGUAGE"; // NOI18N
2263
case ISI_HOST_JSPTAG:
2264                return "ISI_HOST_JSPTAG"; // NOI18N
2265
case ISI_HOST_JAVA:
2266                return "ISI_HOST_JAVA"; // NOI18N
2267
case ISI_HOST_JAVA_LT:
2268                return "ISI_HOST_JAVA_LT"; // NOI18N
2269
case ISI_HOST_JAVA_LT_PC:
2270                return "ISI_HOST_JAVA_LT_PC"; // NOI18N
2271
case ISI_HOST_JAVA_JUMP:
2272                return "ISI_HOST_JAVA_JUMP"; // NOI18N
2273
case ISI_HOST_EL:
2274                return "ISI_HOST_EL"; // NOI18N
2275
case ISI_HOST_EL_D:
2276                return "ISI_HOST_EL_D"; // NOI18N
2277
case ISI_HOST_EL_JUMP:
2278                return "ISI_HOST_EL_JUMP"; // NOI18N
2279
case ISI_JSPTAG_JAVA:
2280                return "ISI_JSPTAG_JAVA"; // NOI18N
2281
case ISI_JSPTAG_JAVA_LT:
2282                return "ISI_JSPTAG_JAVA_LT"; // NOI18N
2283
case ISI_JSPTAG_JAVA_LT_PC:
2284                return "ISI_JSPTAG_JAVA_LT_PC"; // NOI18N
2285
case ISI_JSPTAG_JAVA_JUMP:
2286                return "ISI_JSPTAG_JAVA_JUMP"; // NOI18N
2287
case ISI_JSPTAG_EL:
2288                return "ISI_JSPTAG_EL"; // NOI18N
2289
case ISI_JSPTAG_EL_D:
2290                return "ISI_JSPTAG_EL_D"; // NOI18N
2291
case ISI_JSPTAG_EL_JUMP:
2292                return "ISI_JSPTAG_EL_JUMP"; // NOI18N
2293
case ISI_JAVA1_SWITCH:
2294                return "ISI_JAVA1_SWITCH"; // NOI18N
2295
case ISI_JAVA1_PC:
2296                return "ISI_JAVA1_PC"; // NOI18N
2297
case ISI_JAVA1_JUMP:
2298                return "ISI_JAVA1_JUMP"; // NOI18N
2299
case ISI_JAVA2_SWITCH:
2300                return "ISI_JAVA2_SWITCH"; // NOI18N
2301
case ISI_JAVA2_PC:
2302                return "ISI_JAVA2_PC"; // NOI18N
2303
case ISI_JAVA2_JUMP:
2304                return "ISI_JAVA2_JUMP"; // NOI18N
2305
case ISI_EL1_SWITCH:
2306                return "ISI_EL1_SWITCH"; // NOI18N
2307
case ISI_EL1_JUMP:
2308                return "ISI_EL1_JUMP"; // NOI18N
2309
case ISI_EL2_SWITCH:
2310                return "ISI_EL2_SWITCH"; // NOI18N
2311
case ISI_EL2_JUMP:
2312                return "ISI_EL2_JUMP"; // NOI18N
2313
default:
2314                return super.getStateName(stateNumber); // NOI18N
2315
}
2316        
2317        //</editor-fold>
2318

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        /** State info for the scanning syntax at 'tokenOffset', if tokenOffset != offset (i.e. null was returned). */
2331        StateInfo stateOfScanningAtInit;
2332
2333        //state info defining contexts of java tokens (declaration/scriptlet/expression)
2334
int javaNestMode;
2335        
2336        /** Token ID returned by the first call of the scanning slave's nextToken(), possibly null. */
2337        TokenID firstTokenID;
2338    
2339        /** Token length of the token returned by the first call of the scanning slave's nextToken(), possibly invalid. */
2340        int firstTokenLength;
2341    
2342        public boolean isFirstTokenValid() {
2343            return (JspStateInfo.this.getPreScan() != 0);
2344        }
2345    
2346        public String JavaDoc toString(Syntax s) {
2347//if ((getPreScan() != 0) && (stateOfScanningAtInit != null) && (stateOfScanningAtInit.getPreScan() != 0))
2348
//new Exception("scanning prescan should be 0").printStackTrace();
2349
return "JspStateInfo state=" + getState() + ", prescan=" + JspStateInfo.this.getPreScan() + ", nestMode=" + nestMode + // NOI18N
2350
((JspStateInfo.this.getPreScan() == 0) ? "" : "\n firstTokenID=" + firstTokenID + ", firstTokenLength=" + firstTokenLength) + // NOI18N
2351
"\n hostStateInfo=" + (hostStateInfo == null ? "null" : ((BaseStateInfo)hostStateInfo).toString(s)) + // NOI18N
2352
"\n jspTagStateInfo=" + (jspTagStateInfo == null ? "null" : ((BaseStateInfo)jspTagStateInfo).toString(s)) + // NOI18N
2353
"\n elStateInfo=" + (elStateInfo == null ? "null" : ((BaseStateInfo)elStateInfo).toString(s)) + // NOI18N
2354
"\n javaStateInfo=" + (javaStateInfo == null ? "null" : ((BaseStateInfo)javaStateInfo).toString(s)) + // NOI18N
2355
"\n scanning Info=" + (stateOfScanningAtInit == null ? "null" : ((BaseStateInfo)stateOfScanningAtInit).toString(s)); // NOI18N
2356
}
2357    }
2358
2359  
2360}
2361
Popular Tags