org.xwiki.velocity.internal.util
Class VelocityParser

java.lang.Object
  extended by org.xwiki.velocity.internal.util.VelocityParser

public class VelocityParser
extends java.lang.Object

Provide helpers to parse velocity scripts.

Version:
$Id$

Field Summary
static java.util.Set<java.lang.String> VELOCITYDIRECTIVE_ALL
          All the velocity reserved directives.
static java.util.Set<java.lang.String> VELOCITYDIRECTIVE_BEGIN
          The directives which start a new level which will have to be close by a #end.
static java.util.Set<java.lang.String> VELOCITYDIRECTIVE_END
          Close an opened level.
static java.util.Set<java.lang.String> VELOCITYDIRECTIVE_NOPARAM
          Reserved directives without parameters like #else.
static java.util.Set<java.lang.String> VELOCITYDIRECTIVE_PARAM
          Reserved directive containing parameter(s) like #if.
 
Constructor Summary
VelocityParser()
           
 
Method Summary
 int getDirective(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Get any valid Velocity block starting with a sharp character except comments.
 int getDirectiveEndOfLine(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Get the newline consumed by Velocity directive other than macros.
 int getDirectiveName(char[] array, int currentIndex, java.lang.StringBuffer directiveName, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Get a Velocity directive name block.
 int getEscape(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
           
 int getKeyWord(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Get any valid Velocity block starting with a sharp character (#if, #somemaccro(), ##comment etc.).
 int getMacroParameter(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
           
 int getMacroParametersSeparator(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
           
 int getMethodOrProperty(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Get a velocity method call or a property starting with a ..
 int getMethodParameters(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Get the Velocity method parameters (including ( and )).
 int getMultilinesComment(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Get multilines comment (between #* and *#).
 int getParameters(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, char endingChar, VelocityParserContext context)
          Get a group of parameters between two characters.
 int getSimpleComment(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Get comment single line comment (starting with ##).
 int getSpaces(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Match a group of space characters (ASCII 32).
 int getTableElement(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Get a Velocity table.
 int getVar(char[] array, int currentIndex, java.lang.StringBuffer varName, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Get any valid Velocity starting with a $.
 int getVar(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Get any valid Velocity starting with a $.
 int getVelocityIdentifier(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Get a valid Velocity identifier used for variable of macro.
 int getWhiteSpaces(char[] array, int currentIndex, java.lang.StringBuffer velocityBlock, VelocityParserContext context)
          Match a group of Character.isWhitespace(char).
 boolean isValidVelocityIdentifierChar(char c)
          Indicate if the provided character is valid in a velocity identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VELOCITYDIRECTIVE_BEGIN

public static final java.util.Set<java.lang.String> VELOCITYDIRECTIVE_BEGIN
The directives which start a new level which will have to be close by a #end.


VELOCITYDIRECTIVE_END

public static final java.util.Set<java.lang.String> VELOCITYDIRECTIVE_END
Close an opened level.


VELOCITYDIRECTIVE_PARAM

public static final java.util.Set<java.lang.String> VELOCITYDIRECTIVE_PARAM
Reserved directive containing parameter(s) like #if.


VELOCITYDIRECTIVE_NOPARAM

public static final java.util.Set<java.lang.String> VELOCITYDIRECTIVE_NOPARAM
Reserved directives without parameters like #else.


VELOCITYDIRECTIVE_ALL

public static final java.util.Set<java.lang.String> VELOCITYDIRECTIVE_ALL
All the velocity reserved directives.

Constructor Detail

VelocityParser

public VelocityParser()
Method Detail

getKeyWord

public int getKeyWord(char[] array,
                      int currentIndex,
                      java.lang.StringBuffer velocityBlock,
                      VelocityParserContext context)
               throws InvalidVelocityException
Get any valid Velocity block starting with a sharp character (#if, #somemaccro(), ##comment etc.).

Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block
Throws:
InvalidVelocityException - not a valid velocity block

getDirective

public int getDirective(char[] array,
                        int currentIndex,
                        java.lang.StringBuffer velocityBlock,
                        VelocityParserContext context)
                 throws InvalidVelocityException
Get any valid Velocity block starting with a sharp character except comments.

Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block
Throws:
InvalidVelocityException - not a valid velocity block

getVelocityIdentifier

public int getVelocityIdentifier(char[] array,
                                 int currentIndex,
                                 java.lang.StringBuffer velocityBlock,
                                 VelocityParserContext context)
                          throws InvalidVelocityException
Get a valid Velocity identifier used for variable of macro.

Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block
Throws:
InvalidVelocityException - not a valid velocity block

isValidVelocityIdentifierChar

public boolean isValidVelocityIdentifierChar(char c)
Indicate if the provided character is valid in a velocity identifier.

Parameters:
c - the character
Returns:
true if the character is valid

getDirectiveName

public int getDirectiveName(char[] array,
                            int currentIndex,
                            java.lang.StringBuffer directiveName,
                            java.lang.StringBuffer velocityBlock,
                            VelocityParserContext context)
                     throws InvalidVelocityException
Get a Velocity directive name block. It's different from getVelocityIdentifier(char[], int, StringBuffer, VelocityParserContext) because is include the optional { and }.

Parameters:
array - the source to parse
currentIndex - the current index in the array
directiveName - the buffer where to append the name of the directive
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block
Throws:
InvalidVelocityException - not a valid velocity block

getDirectiveEndOfLine

public int getDirectiveEndOfLine(char[] array,
                                 int currentIndex,
                                 java.lang.StringBuffer velocityBlock,
                                 VelocityParserContext context)
Get the newline consumed by Velocity directive other than macros.

Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block

getSimpleComment

public int getSimpleComment(char[] array,
                            int currentIndex,
                            java.lang.StringBuffer velocityBlock,
                            VelocityParserContext context)
Get comment single line comment (starting with ##).

Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block

getMultilinesComment

public int getMultilinesComment(char[] array,
                                int currentIndex,
                                java.lang.StringBuffer velocityBlock,
                                VelocityParserContext context)
Get multilines comment (between #* and *#).

Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block

getVar

public int getVar(char[] array,
                  int currentIndex,
                  java.lang.StringBuffer velocityBlock,
                  VelocityParserContext context)
           throws InvalidVelocityException
Get any valid Velocity starting with a $.

Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block
Throws:
InvalidVelocityException - not a valid velocity block

getVar

public int getVar(char[] array,
                  int currentIndex,
                  java.lang.StringBuffer varName,
                  java.lang.StringBuffer velocityBlock,
                  VelocityParserContext context)
           throws InvalidVelocityException
Get any valid Velocity starting with a $.

Parameters:
array - the source to parse
currentIndex - the current index in the array
varName - the buffer where to append the name of the variable
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block
Throws:
InvalidVelocityException - not a valid velocity block

getMethodOrProperty

public int getMethodOrProperty(char[] array,
                               int currentIndex,
                               java.lang.StringBuffer velocityBlock,
                               VelocityParserContext context)
                        throws InvalidVelocityException
Get a velocity method call or a property starting with a ..

Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block
Throws:
InvalidVelocityException - not a valid velocity block

getTableElement

public int getTableElement(char[] array,
                           int currentIndex,
                           java.lang.StringBuffer velocityBlock,
                           VelocityParserContext context)
Get a Velocity table.

Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block

getMethodParameters

public int getMethodParameters(char[] array,
                               int currentIndex,
                               java.lang.StringBuffer velocityBlock,
                               VelocityParserContext context)
Get the Velocity method parameters (including ( and )).

Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block

getParameters

public int getParameters(char[] array,
                         int currentIndex,
                         java.lang.StringBuffer velocityBlock,
                         char endingChar,
                         VelocityParserContext context)
Get a group of parameters between two characters. Generic version of getTableElement(char[], int, StringBuffer, VelocityParserContext) and getMethodParameters(char[], int, StringBuffer, VelocityParserContext).

Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
endingChar - the char to end to
context - the parser context to put some informations
Returns:
the index in the array after the matched block

getEscape

public int getEscape(char[] array,
                     int currentIndex,
                     java.lang.StringBuffer velocityBlock,
                     VelocityParserContext context)
Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block

getWhiteSpaces

public int getWhiteSpaces(char[] array,
                          int currentIndex,
                          java.lang.StringBuffer velocityBlock,
                          VelocityParserContext context)
Match a group of Character.isWhitespace(char).

Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block

getSpaces

public int getSpaces(char[] array,
                     int currentIndex,
                     java.lang.StringBuffer velocityBlock,
                     VelocityParserContext context)
Match a group of space characters (ASCII 32).

Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block

getMacroParametersSeparator

public int getMacroParametersSeparator(char[] array,
                                       int currentIndex,
                                       java.lang.StringBuffer velocityBlock,
                                       VelocityParserContext context)
Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block

getMacroParameter

public int getMacroParameter(char[] array,
                             int currentIndex,
                             java.lang.StringBuffer velocityBlock,
                             VelocityParserContext context)
Parameters:
array - the source to parse
currentIndex - the current index in the array
velocityBlock - the buffer where to append matched velocity block
context - the parser context to put some informations
Returns:
the index in the array after the matched block


Copyright © 2004-2011 XWiki. All Rights Reserved.