/** * @param logger the logger to use */ public VelocityParser(Logger logger) { enableLogging(logger); }
/** * Get the Velocity method parameters (including <code>(</code> and <code>)</code>). * * @param array the source to parse * @param currentIndex the current index in the <code>array</code> * @param velocityBlock the buffer where to append matched velocity block * @param context the parser context to put some informations * @return the index in the <code>array</code> after the matched block */ public int getMethodParameters(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) { return getParameters(array, currentIndex, velocityBlock, ')', context); }
/** * Get any valid Velocity starting with a <code>$</code>. * * @param array the source to parse * @param currentIndex the current index in the <code>array</code> * @param velocityBlock the buffer where to append matched velocity block * @param context the parser context to put some informations * @return the index in the <code>array</code> after the matched block * @throws InvalidVelocityException not a valid velocity block */ public int getVar(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) throws InvalidVelocityException { return getVar(array, currentIndex, null, velocityBlock, context); }
i = getDirectiveName(array, i, directiveNameBuffer, null, context); i = getMethodParameters(array, i, null, context); } else { throw new InvalidVelocityException(); context.pushVelocityElement(new VelocityBlock(directiveName, VelocityBlock.VelocityType.DIRECTIVE)); } else if (VELOCITYDIRECTIVE_END.contains(directiveName)) { context.popVelocityElement(); i = getDirectiveEndOfLine(array, i, null, context); context.setType(VelocityBlock.VelocityType.DIRECTIVE); } else { context.setType(VelocityBlock.VelocityType.MACRO);
throw new InvalidVelocityException(); i = getSimpleComment(array, currentIndex, velocityBlock, context); } else if (array[i + 1] == '*') { i = getMultilinesComment(array, currentIndex, velocityBlock, context); } else if (array[i + 1] == '{' || Character.isLetter(array[i + 1])) { i = getDirective(array, currentIndex, velocityBlock, context); } else { throw new InvalidVelocityException();
VelocityParserContext context) throws InvalidVelocityException if (isVarEscaped(array, currentIndex)) { throw new InvalidVelocityException(); throw new InvalidVelocityException(); throw new InvalidVelocityException(); throw new InvalidVelocityException(); i = getVelocityIdentifier(array, i, varName, context); i = followVar(array, i, fullSyntax, context); context.setType(VelocityBlock.VelocityType.VAR);
throw new InvalidVelocityException(); i = getVelocityIdentifier(array, i, directiveName, context);
/** * Get a valid Velocity identifier used for variable of macro. * * @param array the source to parse * @param currentIndex the current index in the <code>array</code> * @param velocityBlock the buffer where to append matched velocity block * @param context the parser context to put some informations * @return the index in the <code>array</code> after the matched block * @throws InvalidVelocityException not a valid velocity block */ public int getVelocityIdentifier(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) throws InvalidVelocityException { // The first character of an identifier must be a [a-zA-Z] if (!Character.isLetter(array[currentIndex])) { throw new InvalidVelocityException(); } int i = currentIndex + 1; while (i < array.length && array[i] != '}' && isValidVelocityIdentifierChar(array[i])) { ++i; } if (velocityBlock != null) { velocityBlock.append(array, currentIndex, i - currentIndex); } return i; }
/** * Get comment single line comment (starting with <code>##</code>). * * @param array the source to parse * @param currentIndex the current index in the <code>array</code> * @param velocityBlock the buffer where to append matched velocity block * @param context the parser context to put some informations * @return the index in the <code>array</code> after the matched block */ public int getSimpleComment(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) { int i = currentIndex + 2; while (i < array.length && array[i - 1] != '\n') { ++i; } if (velocityBlock != null) { velocityBlock.append(array, currentIndex, i - currentIndex); } context.setType(VelocityBlock.VelocityType.COMMENT); return i; }
@Override public int getSimpleComment(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) { ((ExtendedVelocityParserContext) context).setVelocity(true); ((ExtendedVelocityParserContext) context).setInline(true); return super.getSimpleComment(array, currentIndex, velocityBlock, context); }
@Override public int getMultilinesComment(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) { ((ExtendedVelocityParserContext) context).setVelocity(true); ((ExtendedVelocityParserContext) context).setInline(true); return super.getMultilinesComment(array, currentIndex, velocityBlock, context); }
/** * @param array the source to parse * @param currentIndex the current index in the <code>array</code> * @param velocityBlock the buffer where to append matched velocity block * @param context the parser context to put some informations * @return the index in the <code>array</code> after the matched block */ public int getMacroParametersSeparator(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) { int i = currentIndex; i = getWhiteSpaces(array, i, null, context); if (array[i] == ',') { i++; } i = getWhiteSpaces(array, i, null, context); if (velocityBlock != null) { velocityBlock.append(array, currentIndex, i - currentIndex); } return i; }
/** * {@inheritDoc} * * @see org.xwiki.component.phase.Initializable#initialize() */ public void initialize() throws InitializationException { this.velocityParser = new VelocityParser(getLogger()); }
throw new InvalidVelocityException(); i = getSimpleComment(array, currentIndex, velocityBlock, context); } else if (array[i + 1] == '*') { i = getMultilinesComment(array, currentIndex, velocityBlock, context); } else if (array[i + 1] == '{' || Character.isLetter(array[i + 1])) { i = getDirective(array, currentIndex, velocityBlock, context); } else { throw new InvalidVelocityException();
throw new InvalidVelocityException(); i = getVelocityIdentifier(array, i, directiveName, context);
/** * Get any valid Velocity starting with a <code>$</code>. * * @param array the source to parse * @param currentIndex the current index in the <code>array</code> * @param velocityBlock the buffer where to append matched velocity block * @param context the parser context to put some informations * @return the index in the <code>array</code> after the matched block * @throws InvalidVelocityException not a valid velocity block */ public int getVar(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) throws InvalidVelocityException { return getVar(array, currentIndex, null, velocityBlock, context); }
/** * Get a Velocity table. * * @param array the source to parse * @param currentIndex the current index in the <code>array</code> * @param velocityBlock the buffer where to append matched velocity block * @param context the parser context to put some informations * @return the index in the <code>array</code> after the matched block */ public int getTableElement(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) { return getParameters(array, currentIndex, velocityBlock, ']', context); }
/** * @param array the source to parse * @param currentIndex the current index in the <code>array</code> * @param velocityBlock the buffer where to append matched velocity block * @param context the parser context to put some informations * @return the index in the <code>array</code> after the matched block */ public int getMacroParametersSeparator(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) { int i = currentIndex; i = getWhiteSpaces(array, i, null, context); if (array[i] == ',') { i++; } i = getWhiteSpaces(array, i, null, context); if (velocityBlock != null) { velocityBlock.append(array, currentIndex, i - currentIndex); } return i; }
/** * Get a Velocity table. * * @param array the source to parse * @param currentIndex the current index in the <code>array</code> * @param velocityBlock the buffer where to append matched velocity block * @param context the parser context to put some informations * @return the index in the <code>array</code> after the matched block */ public int getTableElement(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) { return getParameters(array, currentIndex, velocityBlock, ']', context); }
/** * Get the Velocity method parameters (including <code>(</code> and <code>)</code>). * * @param array the source to parse * @param currentIndex the current index in the <code>array</code> * @param velocityBlock the buffer where to append matched velocity block * @param context the parser context to put some informations * @return the index in the <code>array</code> after the matched block */ public int getMethodParameters(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) { return getParameters(array, currentIndex, velocityBlock, ')', context); }