/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: Lexer.java,v 1.2.4.1 2005/09/10 03:55:45 jeffsuttor Exp $
*/
/**
* This class is in charge of lexical processing of the XPath
* expression into tokens.
*/
class Lexer
{
/**
* The target XPath.
*/
/**
* The prefix resolver to map prefixes to namespaces in the XPath.
*/
/**
* The XPath processor object.
*/
/**
* This value is added to each element name in the TARGETEXTRA
* that is a 'target' (right-most top-level element name).
*/
/**
* Ignore this, it is going away.
* This holds a map to the m_tokenQueue that tells where the top-level elements are.
* It is used for pattern matching so the m_tokenQueue can be walked backwards.
* Each element that is a 'target', (right-most top level element name) has
* TARGETEXTRA added to it.
*
*/
/**
* Ignore this, it is going away.
* The number of elements that m_patternMap maps;
*/
private int m_patternMapSize;
/**
* Create a Lexer object.
*
* @param compiler The owning compiler for this lexer.
* @param resolver The prefix resolver for mapping qualified name prefixes
* to namespace URIs.
* @param xpathProcessor The parser that is processing strings to opcodes.
*/
{
}
/**
* Walk through the expression and build a token queue, and a map of the top-level
* elements.
* @param pat XSLT Expression.
*
* @throws javax.xml.transform.TransformerException
*/
{
}
/**
* Walk through the expression and build a token queue, and a map of the top-level
* elements.
* @param pat XSLT Expression.
* @param targetStrings Vector to hold Strings, may be null.
*
* @throws javax.xml.transform.TransformerException
*/
{
m_patternMapSize = 0;
// This needs to grow too.
m_compiler.m_opMap = new OpMapVector(OpMap.MAXTOKENQUEUESIZE * 5, OpMap.BLOCKTOKENQUEUESIZE * 5, OpMap.MAPINDEX_LENGTH);
int startSubstring = -1;
int posOfNSSep = -1;
boolean isStartOfPat = true;
boolean isAttrName = false;
boolean isNum = false;
// Nesting of '[' so we can know if the given element should be
// counted inside the m_patternMap.
int nesting = 0;
// char[] chars = pat.toCharArray();
for (int i = 0; i < nChars; i++)
{
switch (c)
{
case '\"' :
{
if (startSubstring != -1)
{
isNum = false;
isAttrName = false;
if (-1 != posOfNSSep)
{
}
else
{
}
}
startSubstring = i;
if (c == '\"' && i < nChars)
{
startSubstring = -1;
}
else
{
null); //"misquoted literal... expected double quote!");
}
}
break;
case '\'' :
if (startSubstring != -1)
{
isNum = false;
isAttrName = false;
if (-1 != posOfNSSep)
{
}
else
{
}
}
startSubstring = i;
if (c == '\'' && i < nChars)
{
startSubstring = -1;
}
else
{
null); //"misquoted literal... expected single quote!");
}
break;
case 0x0A :
case 0x0D :
case ' ' :
case '\t' :
if (startSubstring != -1)
{
isNum = false;
isAttrName = false;
if (-1 != posOfNSSep)
{
}
else
{
}
startSubstring = -1;
}
break;
case '@' :
isAttrName = true;
// fall-through on purpose
case '-' :
if ('-' == c)
{
{
break;
}
isNum = false;
}
// fall-through on purpose
case '(' :
case '[' :
case ')' :
case ']' :
case '|' :
case '/' :
case '*' :
case '+' :
case '=' :
case ',' :
case '\\' : // Unused at the moment
case '^' : // Unused at the moment
case '!' : // Unused at the moment
case '$' :
case '<' :
case '>' :
if (startSubstring != -1)
{
isNum = false;
isAttrName = false;
if (-1 != posOfNSSep)
{
}
else
{
}
startSubstring = -1;
}
else if (('/' == c) && isStartOfPat)
{
}
else if ('*' == c)
{
isAttrName = false;
}
if (0 == nesting)
{
if ('|' == c)
{
if (null != targetStrings)
{
}
isStartOfPat = true;
}
}
if ((')' == c) || (']' == c))
{
nesting--;
}
else if (('(' == c) || ('[' == c))
{
nesting++;
}
break;
case ':' :
if (i>0)
{
if (posOfNSSep == (i - 1))
{
if (startSubstring != -1)
{
if (startSubstring < (i - 1))
}
isNum = false;
isAttrName = false;
startSubstring = -1;
posOfNSSep = -1;
break;
}
else
{
posOfNSSep = i;
}
}
// fall through on purpose
default :
if (-1 == startSubstring)
{
startSubstring = i;
}
else if (isNum)
{
}
}
}
if (startSubstring != -1)
{
isNum = false;
if ((-1 != posOfNSSep) ||
{
}
else
{
}
}
{
}
else if (null != targetStrings)
{
}
}
/**
* Record the current position on the token queue as long as
* this is a top-level element. Must be called before the
* next token is added to the m_tokenQueue.
*
* @param nesting The nesting count for the pattern element.
* @param isStart true if this is the start of a pattern.
* @param isAttrName true if we have determined that this is an attribute name.
*
* @return true if this is the start of a pattern.
*/
boolean isAttrName)
{
if (0 == nesting)
{
{
int patternMap[] = m_patternMap;
}
if (!isStart)
{
}
isStart = false;
}
return isStart;
}
/**
* Given a map pos, return the corresponding token queue pos.
*
* @param i The index in the m_patternMap.
*
* @return the token queue position.
*/
private int getTokenQueuePosFromMap(int i)
{
int pos = m_patternMap[i];
}
/**
* Reset token queue mark and m_token to a
* given position.
* @param mark The new position.
*/
{
{
}
else
{
}
}
/**
* Given a string, return the corresponding keyword token.
*
* @param key The keyword.
*
* @return An opcode value.
*/
{
int tok;
try
{
}
catch (NullPointerException npe)
{
tok = 0;
}
catch (ClassCastException cce)
{
tok = 0;
}
return tok;
}
/**
* Record the current token in the passed vector.
*
* @param targetStrings Vector of string.
*/
{
{
switch (tok)
{
case OpCodes.NODETYPE_COMMENT :
break;
case OpCodes.NODETYPE_TEXT :
break;
case OpCodes.NODETYPE_NODE :
break;
case OpCodes.NODETYPE_ROOT :
break;
case OpCodes.NODETYPE_ANYELEMENT :
break;
case OpCodes.NODETYPE_PI :
break;
default :
}
}
else
{
{
tokPos++;
}
{
tokPos += 2;
}
}
}
/**
* Add a token to the token queue.
*
*
* @param s The token.
*/
{
}
/**
* When a seperator token is found, see if there's a element name or
* the like to map.
*
* @param pat The XPath name string.
* @param startSubstring The start of the name string.
* @param posOfNSSep The position of the namespace seperator (':').
* @param posOfScan The end of the name index.
*
* @throws javax.xml.transform.TransformerException
*
* @return -1 always.
*/
int posOfScan)
{
{
}
{
try
{
prefix);
else
{
// Assume last was wildcard. This is not legal according
// to the draft. Set the below to true to make namespace
// wildcards work.
if (false)
{
addToTokenQueue(":");
if (s.length() > 0)
addToTokenQueue(s);
return -1;
}
else
{
uName =
prefix);
}
}
}
catch (ClassCastException cce)
{
}
}
else
{
}
{
addToTokenQueue(":");
if (s.length() > 0)
addToTokenQueue(s);
}
else
{
// To older XPath code it doesn't matter if
// error() is called or errorForDOM3().
/** old code commented out 17-Sep-2004
// error("Could not locate namespace for prefix: "+prefix);
// m_processor.error(XPATHErrorResources.ER_PREFIX_MUST_RESOLVE,
// new String[] {prefix}); //"Prefix must resolve to a namespace: {0}";
*/
/*** Old code commented out 10-Jan-2001
addToTokenQueue(prefix);
addToTokenQueue(":");
String s = pat.substring(posOfNSSep + 1, posOfScan);
if (s.length() > 0)
addToTokenQueue(s);
***/
}
return -1;
}
}