com.novell.xml.xpath
Class Scanner

java.lang.Object
  extended bycom.novell.xml.xpath.Scanner

public class Scanner
extends Object

class to scan and separate a string containing an XPath expression into lexical tokens

See Also:
Token

Field Summary
protected static char EAT_CHAR
           
 
Constructor Summary
Scanner(String string)
          Construct a scanner for the passed expression
 
Method Summary
protected  void appendToken(Token token)
          Append a token to the result tokens.
protected  boolean checkOpNameMulOpState()
          Check the preceding Token type to see if an operator name ("div", "mod", "and", "or") or the multiply operator ("*") should be recognized as such
protected  void done()
          Allow a derived class to finish processing when the end of the input string is reached.
protected  char getNextChar()
          Get next character from input string
protected  char getNextXMLChar()
          Return next non-whitespace XML character from input string
protected  void handleChar(char scanChar)
          Add appropriate token for text starting with passed character This will continue scanning ahead if necessary, and may check the previous Token
protected  void handleLiteral(char startQuote)
          Create a LiteralToken for the literal text enclosed in single or double quotes
protected  void handleNumber(char startChar)
          Create a NumberToken from scanned text
protected  void handleQName(com.novell.xml.xpath.QName qName)
          Construct appropriate token based on an XML QName This will add a WildcardNameToken, FunctionNameToken, NodeTypeToken, or OperatorToken depending on characters and context
protected  boolean isDigit(char c)
          Determine if passed char is a digit
protected  Token lastToken()
          Return the last token appended to the result tokens.
protected  void popPos()
          Restore saved position in expression string
protected  char prescanChar(char scanChar)
          Perform any non-XPath processing for this character.
protected  void pushPos()
          Remember current position in expression string
protected  void reset()
          reset scanner to rescan string
protected  Token[] returnTokens()
          Return the result tokens as an array of tokens.
 Token[] scan()
          Return lexical tokens for expression
protected  String scanNCName(char firstChar)
          scan all characters making up an XML NCName
static double scanNumber(String string)
          Scan a string and return the numeric value if string matches the XPath Number production.
protected  com.novell.xml.xpath.QName scanQName(char firstChar)
          scan all characters making up an XML QName
protected  void tossPos()
          Throw away remembered position in expression string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EAT_CHAR

protected static final char EAT_CHAR
See Also:
Constant Field Values
Constructor Detail

Scanner

public Scanner(String string)
Construct a scanner for the passed expression

Parameters:
string - XPath expression
Method Detail

scan

public Token[] scan()
             throws XPathParserException
Return lexical tokens for expression

Returns:
array of Token objects
Throws:
java.lang.XPathParserException
XPathParserException

scanNumber

public static double scanNumber(String string)
Scan a string and return the numeric value if string matches the XPath Number production.

Parameters:
string - The string to scan.
Returns:
The numeric value, or NaN if string isn't a number.

prescanChar

protected char prescanChar(char scanChar)
Perform any non-XPath processing for this character. Return true if character should then be processed normally as part of an XPath expression. This is intended primarily for XSLT AttributeValueTemplate scanning.

Parameters:
scanChar - The character being scanned.
Returns:
True if char should be processed further.

done

protected void done()
Allow a derived class to finish processing when the end of the input string is reached.


handleQName

protected void handleQName(com.novell.xml.xpath.QName qName)
                    throws XPathParserException
Construct appropriate token based on an XML QName This will add a WildcardNameToken, FunctionNameToken, NodeTypeToken, or OperatorToken depending on characters and context

Parameters:
qName - object representing QName
Throws:
java.lang.XPathParserException
XPathParserException

handleChar

protected void handleChar(char scanChar)
                   throws XPathParserException
Add appropriate token for text starting with passed character This will continue scanning ahead if necessary, and may check the previous Token

Parameters:
scanChar - character scanned
Throws:
java.lang.XPathParserException
XPathParserException

handleLiteral

protected void handleLiteral(char startQuote)
Create a LiteralToken for the literal text enclosed in single or double quotes

Parameters:
startQuote - scanned quote char '\'' or '"'

handleNumber

protected void handleNumber(char startChar)
Create a NumberToken from scanned text

Parameters:
startChar - Either a digit ('0'-'9') or a decimal point ('.')

checkOpNameMulOpState

protected boolean checkOpNameMulOpState()
Check the preceding Token type to see if an operator name ("div", "mod", "and", "or") or the multiply operator ("*") should be recognized as such

Returns:
true if token being scanned should be recognized as an operator

scanQName

protected com.novell.xml.xpath.QName scanQName(char firstChar)
scan all characters making up an XML QName

Parameters:
firstChar - XML start name character already scanned
Returns:
object representing XML QName
See Also:
XML Names

scanNCName

protected String scanNCName(char firstChar)
scan all characters making up an XML NCName

Parameters:
firstChar - XML start name character already scanned
Returns:
string containing XML NCName
See Also:
XML Names

getNextXMLChar

protected char getNextXMLChar()
Return next non-whitespace XML character from input string

Returns:
character, or 0 if no more chars in string

getNextChar

protected char getNextChar()
Get next character from input string

Returns:
character, or 0 if no more characters

isDigit

protected boolean isDigit(char c)
Determine if passed char is a digit

Parameters:
c - char to check
Returns:
true if passed char in in range '0' to '9' inclusive

reset

protected void reset()
reset scanner to rescan string


pushPos

protected void pushPos()
Remember current position in expression string


tossPos

protected void tossPos()
Throw away remembered position in expression string

See Also:
pushPos()

popPos

protected void popPos()
Restore saved position in expression string

See Also:
pushPos()

appendToken

protected final void appendToken(Token token)
Append a token to the result tokens.

Parameters:
token - The token to append.

lastToken

protected final Token lastToken()
Return the last token appended to the result tokens.

Returns:
The last Token appended to the result tokens.

returnTokens

protected Token[] returnTokens()
Return the result tokens as an array of tokens.

Returns:
An array of Token objects.