jaxp/src/com/sun/org/apache/xpath/internal/compiler/Lexer.java
author lana
Tue, 18 Mar 2014 17:49:48 -0700
changeset 23377 2af1ddf102a4
parent 12457 c348e06f0e82
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 1999-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: Lexer.java,v 1.2.4.1 2005/09/10 03:55:45 jeffsuttor Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xpath.internal.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import java.util.Vector;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xml.internal.utils.PrefixResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * This class is in charge of lexical processing of the XPath
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * expression into tokens.
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
class Lexer
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
   * The target XPath.
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
  private Compiler m_compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
   * The prefix resolver to map prefixes to namespaces in the XPath.
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
  PrefixResolver m_namespaceContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
   * The XPath processor object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
  XPathParser m_processor;
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
   * This value is added to each element name in the TARGETEXTRA
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
   * that is a 'target' (right-most top-level element name).
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
  static final int TARGETEXTRA = 10000;
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
   * Ignore this, it is going away.
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
   * This holds a map to the m_tokenQueue that tells where the top-level elements are.
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
   * It is used for pattern matching so the m_tokenQueue can be walked backwards.
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   * Each element that is a 'target', (right-most top level element name) has
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
   * TARGETEXTRA added to it.
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
  private int m_patternMap[] = new int[100];
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
   * Ignore this, it is going away.
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
   * The number of elements that m_patternMap maps;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
  private int m_patternMapSize;
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
   * Create a Lexer object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
   * @param compiler The owning compiler for this lexer.
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
   * @param resolver The prefix resolver for mapping qualified name prefixes
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
   *                 to namespace URIs.
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   * @param xpathProcessor The parser that is processing strings to opcodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
  Lexer(Compiler compiler, PrefixResolver resolver,
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
        XPathParser xpathProcessor)
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    m_compiler = compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
    m_namespaceContext = resolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    m_processor = xpathProcessor;
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
   * Walk through the expression and build a token queue, and a map of the top-level
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   * elements.
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   * @param pat XSLT Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
  void tokenize(String pat) throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    tokenize(pat, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
   * Walk through the expression and build a token queue, and a map of the top-level
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
   * elements.
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
   * @param pat XSLT Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
   * @param targetStrings Vector to hold Strings, may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
  void tokenize(String pat, Vector targetStrings)
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
          throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
    m_compiler.m_currentPattern = pat;
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
    m_patternMapSize = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
    // This needs to grow too.
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    m_compiler.m_opMap = new OpMapVector(OpMap.MAXTOKENQUEUESIZE * 5, OpMap.BLOCKTOKENQUEUESIZE * 5, OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    int nChars = pat.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    int startSubstring = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    int posOfNSSep = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    boolean isStartOfPat = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
    boolean isAttrName = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
    boolean isNum = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
    // Nesting of '[' so we can know if the given element should be
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    // counted inside the m_patternMap.
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
    int nesting = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    // char[] chars = pat.toCharArray();
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    for (int i = 0; i < nChars; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
      char c = pat.charAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
      switch (c)
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
      case '\"' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
        if (startSubstring != -1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
          isNum = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
          isStartOfPat = mapPatternElemPos(nesting, isStartOfPat, isAttrName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
          isAttrName = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
          if (-1 != posOfNSSep)
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
            posOfNSSep = mapNSTokens(pat, startSubstring, posOfNSSep, i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
            addToTokenQueue(pat.substring(startSubstring, i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
        startSubstring = i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
        for (i++; (i < nChars) && ((c = pat.charAt(i)) != '\"'); i++);
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
        if (c == '\"' && i < nChars)
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
          addToTokenQueue(pat.substring(startSubstring, i + 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
          startSubstring = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
          m_processor.error(XPATHErrorResources.ER_EXPECTED_DOUBLE_QUOTE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
                            null);  //"misquoted literal... expected double quote!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
      case '\'' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
        if (startSubstring != -1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
          isNum = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
          isStartOfPat = mapPatternElemPos(nesting, isStartOfPat, isAttrName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
          isAttrName = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
          if (-1 != posOfNSSep)
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
            posOfNSSep = mapNSTokens(pat, startSubstring, posOfNSSep, i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
            addToTokenQueue(pat.substring(startSubstring, i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
        startSubstring = i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
        for (i++; (i < nChars) && ((c = pat.charAt(i)) != '\''); i++);
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
        if (c == '\'' && i < nChars)
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
          addToTokenQueue(pat.substring(startSubstring, i + 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
          startSubstring = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
          m_processor.error(XPATHErrorResources.ER_EXPECTED_SINGLE_QUOTE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
                            null);  //"misquoted literal... expected single quote!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
      case 0x0A :
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
      case 0x0D :
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
      case ' ' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
      case '\t' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
        if (startSubstring != -1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
          isNum = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
          isStartOfPat = mapPatternElemPos(nesting, isStartOfPat, isAttrName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
          isAttrName = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
          if (-1 != posOfNSSep)
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
            posOfNSSep = mapNSTokens(pat, startSubstring, posOfNSSep, i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
            addToTokenQueue(pat.substring(startSubstring, i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
          startSubstring = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
      case '@' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
        isAttrName = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
      // fall-through on purpose
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
      case '-' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
        if ('-' == c)
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
          if (!(isNum || (startSubstring == -1)))
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
          isNum = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
      // fall-through on purpose
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
      case '(' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
      case '[' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
      case ')' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
      case ']' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
      case '|' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
      case '/' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
      case '*' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
      case '+' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
      case '=' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
      case ',' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
      case '\\' :  // Unused at the moment
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
      case '^' :  // Unused at the moment
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
      case '!' :  // Unused at the moment
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
      case '$' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
      case '<' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
      case '>' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
        if (startSubstring != -1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
          isNum = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
          isStartOfPat = mapPatternElemPos(nesting, isStartOfPat, isAttrName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
          isAttrName = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
          if (-1 != posOfNSSep)
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
            posOfNSSep = mapNSTokens(pat, startSubstring, posOfNSSep, i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
            addToTokenQueue(pat.substring(startSubstring, i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
          startSubstring = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
        else if (('/' == c) && isStartOfPat)
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
          isStartOfPat = mapPatternElemPos(nesting, isStartOfPat, isAttrName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
        else if ('*' == c)
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
          isStartOfPat = mapPatternElemPos(nesting, isStartOfPat, isAttrName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
          isAttrName = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
        if (0 == nesting)
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
          if ('|' == c)
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
            if (null != targetStrings)
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
              recordTokenString(targetStrings);
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
            isStartOfPat = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
        if ((')' == c) || (']' == c))
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
          nesting--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        else if (('(' == c) || ('[' == c))
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
          nesting++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
        addToTokenQueue(pat.substring(i, i + 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
      case ':' :
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
        if (i>0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
          if (posOfNSSep == (i - 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
            if (startSubstring != -1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
              if (startSubstring < (i - 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
                addToTokenQueue(pat.substring(startSubstring, i - 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
            isNum = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
            isAttrName = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
            startSubstring = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
            posOfNSSep = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
            addToTokenQueue(pat.substring(i - 1, i + 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
            posOfNSSep = i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
      // fall through on purpose
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
      default :
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
        if (-1 == startSubstring)
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
          startSubstring = i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
          isNum = Character.isDigit(c);
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
        else if (isNum)
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
          isNum = Character.isDigit(c);
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
    if (startSubstring != -1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
      isNum = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
      isStartOfPat = mapPatternElemPos(nesting, isStartOfPat, isAttrName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
      if ((-1 != posOfNSSep) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
         ((m_namespaceContext != null) && (m_namespaceContext.handlesNullPrefixes())))
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
        posOfNSSep = mapNSTokens(pat, startSubstring, posOfNSSep, nChars);
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
        addToTokenQueue(pat.substring(startSubstring, nChars));
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
    if (0 == m_compiler.getTokenQueueSize())
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
      m_processor.error(XPATHErrorResources.ER_EMPTY_EXPRESSION, null);  //"Empty expression!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
    else if (null != targetStrings)
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
      recordTokenString(targetStrings);
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
    m_processor.m_queueMark = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
   * Record the current position on the token queue as long as
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
   * this is a top-level element.  Must be called before the
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
   * next token is added to the m_tokenQueue.
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
   * @param nesting The nesting count for the pattern element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
   * @param isStart true if this is the start of a pattern.
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
   * @param isAttrName true if we have determined that this is an attribute name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
   * @return true if this is the start of a pattern.
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
  private boolean mapPatternElemPos(int nesting, boolean isStart,
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
                                    boolean isAttrName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
    if (0 == nesting)
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
      if(m_patternMapSize >= m_patternMap.length)
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
        int patternMap[] = m_patternMap;
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
        int len = m_patternMap.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
        m_patternMap = new int[m_patternMapSize + 100];
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
        System.arraycopy(patternMap, 0, m_patternMap, 0, len);
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
      if (!isStart)
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
        m_patternMap[m_patternMapSize - 1] -= TARGETEXTRA;
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
      m_patternMap[m_patternMapSize] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
        (m_compiler.getTokenQueueSize() - (isAttrName ? 1 : 0)) + TARGETEXTRA;
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
      m_patternMapSize++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
      isStart = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
    return isStart;
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
   * Given a map pos, return the corresponding token queue pos.
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
   * @param i The index in the m_patternMap.
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
   * @return the token queue position.
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
  private int getTokenQueuePosFromMap(int i)
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
    int pos = m_patternMap[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
    return (pos >= TARGETEXTRA) ? (pos - TARGETEXTRA) : pos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
   * Reset token queue mark and m_token to a
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
   * given position.
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
   * @param mark The new position.
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
  private final void resetTokenMark(int mark)
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
    int qsz = m_compiler.getTokenQueueSize();
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
    m_processor.m_queueMark = (mark > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
                              ? ((mark <= qsz) ? mark - 1 : mark) : 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
    if (m_processor.m_queueMark < qsz)
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
      m_processor.m_token =
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
        (String) m_compiler.getTokenQueue().elementAt(m_processor.m_queueMark++);
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
      m_processor.m_tokenChar = m_processor.m_token.charAt(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
      m_processor.m_token = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
      m_processor.m_tokenChar = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
   * Given a string, return the corresponding keyword token.
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
   * @param key The keyword.
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
   * @return An opcode value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
  final int getKeywordToken(String key)
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
    int tok;
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
      Integer itok = (Integer) Keywords.getKeyWord(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
      tok = (null != itok) ? itok.intValue() : 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
    catch (NullPointerException npe)
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
      tok = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
    catch (ClassCastException cce)
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
      tok = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
    return tok;
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
   * Record the current token in the passed vector.
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
   * @param targetStrings Vector of string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
  private void recordTokenString(Vector targetStrings)
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
    int tokPos = getTokenQueuePosFromMap(m_patternMapSize - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
    resetTokenMark(tokPos + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
    if (m_processor.lookahead('(', 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
      int tok = getKeywordToken(m_processor.m_token);
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
      switch (tok)
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
      case OpCodes.NODETYPE_COMMENT :
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
        targetStrings.addElement(PsuedoNames.PSEUDONAME_COMMENT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
      case OpCodes.NODETYPE_TEXT :
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
        targetStrings.addElement(PsuedoNames.PSEUDONAME_TEXT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
      case OpCodes.NODETYPE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
        targetStrings.addElement(PsuedoNames.PSEUDONAME_ANY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
      case OpCodes.NODETYPE_ROOT :
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
        targetStrings.addElement(PsuedoNames.PSEUDONAME_ROOT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
      case OpCodes.NODETYPE_ANYELEMENT :
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
        targetStrings.addElement(PsuedoNames.PSEUDONAME_ANY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
      case OpCodes.NODETYPE_PI :
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
        targetStrings.addElement(PsuedoNames.PSEUDONAME_ANY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
      default :
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
        targetStrings.addElement(PsuedoNames.PSEUDONAME_ANY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
      if (m_processor.tokenIs('@'))
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
        tokPos++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
        resetTokenMark(tokPos + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
      if (m_processor.lookahead(':', 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
        tokPos += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
      targetStrings.addElement(m_compiler.getTokenQueue().elementAt(tokPos));
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
   * Add a token to the token queue.
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
   * @param s The token.
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
  private final void addToTokenQueue(String s)
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
    m_compiler.getTokenQueue().addElement(s);
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
   * When a seperator token is found, see if there's a element name or
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
   * the like to map.
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
   * @param pat The XPath name string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
   * @param startSubstring The start of the name string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
   * @param posOfNSSep The position of the namespace seperator (':').
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
   * @param posOfScan The end of the name index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
   * @return -1 always.
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
  private int mapNSTokens(String pat, int startSubstring, int posOfNSSep,
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
                          int posOfScan)
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
           throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
 {
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
    String prefix = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
    if ((startSubstring >= 0) && (posOfNSSep >= 0))
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
       prefix = pat.substring(startSubstring, posOfNSSep);
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
    String uName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
    if ((null != m_namespaceContext) &&!prefix.equals("*")
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
            &&!prefix.equals("xmlns"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
      try
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
        if (prefix.length() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
          uName = ((PrefixResolver) m_namespaceContext).getNamespaceForPrefix(
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
            prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
          // Assume last was wildcard. This is not legal according
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
          // to the draft. Set the below to true to make namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
          // wildcards work.
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
          if (false)
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
            addToTokenQueue(":");
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
            String s = pat.substring(posOfNSSep + 1, posOfScan);
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
            if (s.length() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
              addToTokenQueue(s);
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
            return -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
            uName =
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
              ((PrefixResolver) m_namespaceContext).getNamespaceForPrefix(
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
                prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
      catch (ClassCastException cce)
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
        uName = m_namespaceContext.getNamespaceForPrefix(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
      uName = prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
    if ((null != uName) && (uName.length() > 0))
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
      addToTokenQueue(uName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
      addToTokenQueue(":");
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
      String s = pat.substring(posOfNSSep + 1, posOfScan);
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
      if (s.length() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
        addToTokenQueue(s);
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
        // To older XPath code it doesn't matter if
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
        // error() is called or errorForDOM3().
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
                m_processor.errorForDOM3(XPATHErrorResources.ER_PREFIX_MUST_RESOLVE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
                                                 new String[] {prefix});  //"Prefix must resolve to a namespace: {0}";
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
/** old code commented out 17-Sep-2004
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
// error("Could not locate namespace for prefix: "+prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
//                m_processor.error(XPATHErrorResources.ER_PREFIX_MUST_RESOLVE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
//                                       new String[] {prefix});  //"Prefix must resolve to a namespace: {0}";
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
*/
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
      /***  Old code commented out 10-Jan-2001
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
      addToTokenQueue(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
      addToTokenQueue(":");
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
      String s = pat.substring(posOfNSSep + 1, posOfScan);
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
      if (s.length() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
        addToTokenQueue(s);
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
      ***/
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
    return -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
}