@Test void getDirective() throws InvalidVelocityException { VelocityParserContext context = new VelocityParserContext(); StringBuffer buffer = new StringBuffer(); int index = this.parser.getDirective("#if($a==1)true enough#elseno way!#end".toCharArray(), 0, buffer, context); assertEquals("#if($a==1)".length(), index); assertEquals("#if($a==1)", buffer.toString()); assertTrue(context.isInVelocityBlock()); }
public int getDirective(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) throws InvalidVelocityException { int i = currentIndex + 1; StringBuffer directiveNameBuffer = new StringBuffer(); i = getDirectiveName(array, i, directiveNameBuffer, null, context); String directiveName = directiveNameBuffer.toString(); if (!VELOCITYDIRECTIVE_NOPARAM.contains(directiveName)) { while (i < array.length && array[i] == ' ') { ++i; } if (i < array.length && array[i] == '(') { i = getMethodParameters(array, i, null, context); } else { throw new InvalidVelocityException(); } } if (VELOCITYDIRECTIVE_ALL.contains(directiveName)) { if (VELOCITYDIRECTIVE_BEGIN.contains(directiveName)) { 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); } if (velocityBlock != null) { velocityBlock.append(array, currentIndex, i - currentIndex); } return i; }
VelocityParser { public int getDirective(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) throws InvalidVelocityException { int i = currentIndex + 1; StringBuffer directiveNameBuffer = new StringBuffer(); i = getDirectiveName(array, i, directiveNameBuffer, null, context); String directiveName = directiveNameBuffer.toString(); if (!VELOCITYDIRECTIVE_NOPARAM.contains(directiveName)) { while (i < array.length && array[i] == ' ') { ++i; } if (i < array.length && array[i] == '(') { i = getMethodParameters(array, i, null, context); } else { throw new InvalidVelocityException(); } } if (VELOCITYDIRECTIVE_ALL.contains(directiveName)) { if (VELOCITYDIRECTIVE_BEGIN.contains(directiveName)) { 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); } if (velocityBlock != null) { velocityBlock.append(array, currentIndex, i - currentIndex); } return i; } }
VelocityParser { public int getDirective(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) throws InvalidVelocityException { int i = currentIndex + 1; StringBuffer directiveNameBuffer = new StringBuffer(); i = getDirectiveName(array, i, directiveNameBuffer, null, context); String directiveName = directiveNameBuffer.toString(); if (!VELOCITYDIRECTIVE_NOPARAM.contains(directiveName)) { while (i < array.length && array[i] == ' ') { ++i; } if (i < array.length && array[i] == '(') { i = getMethodParameters(array, i, null, context); } else { throw new InvalidVelocityException(); } } if (VELOCITYDIRECTIVE_ALL.contains(directiveName)) { if (VELOCITYDIRECTIVE_BEGIN.contains(directiveName)) { 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); } if (velocityBlock != null) { velocityBlock.append(array, currentIndex, i - currentIndex); } return i; }  }
VelocityParser { public int getDirective(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) throws InvalidVelocityException { int i = currentIndex + 1; StringBuffer directiveNameBuffer = new StringBuffer(); i = getDirectiveName(array, i, directiveNameBuffer, null, context); String directiveName = directiveNameBuffer.toString(); if (!VELOCITYDIRECTIVE_NOPARAM.contains(directiveName)) { while (i < array.length && array[i] == ' ') { ++i; } if (i < array.length && array[i] == '(') { i = getMethodParameters(array, i, null, context); } else { throw new InvalidVelocityException(); } } if (VELOCITYDIRECTIVE_ALL.contains(directiveName)) { if (VELOCITYDIRECTIVE_BEGIN.contains(directiveName)) { 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); } if (velocityBlock != null) { velocityBlock.append(array, currentIndex, i - currentIndex); } return i; }  int getKeyWord(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getDirective(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getVelocityIdentifier(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); boolean isValidVelocityIdentifierChar(char c); int getDirectiveName(char[] array, int currentIndex, StringBuffer directiveName, StringBuffer velocityBlock,
        VelocityParserContext context); int getDirectiveEndOfLine(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getSimpleComment(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getMultilinesComment(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getVar(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getVar(char[] array, int currentIndex, StringBuffer varName, StringBuffer velocityBlock,
        VelocityParserContext context); int getMethodOrProperty(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getTableElement(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getMethodParameters(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getParameters(char[] array, int currentIndex, StringBuffer velocityBlock, char endingChar,
        VelocityParserContext context); int getEscape(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getWhiteSpaces(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getSpaces(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getMacroParametersSeparator(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getMacroParameter(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); }
VelocityParser { public int getDirective(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) throws InvalidVelocityException { int i = currentIndex + 1; StringBuffer directiveNameBuffer = new StringBuffer(); i = getDirectiveName(array, i, directiveNameBuffer, null, context); String directiveName = directiveNameBuffer.toString(); if (!VELOCITYDIRECTIVE_NOPARAM.contains(directiveName)) { while (i < array.length && array[i] == ' ') { ++i; } if (i < array.length && array[i] == '(') { i = getMethodParameters(array, i, null, context); } else { throw new InvalidVelocityException(); } } if (VELOCITYDIRECTIVE_ALL.contains(directiveName)) { if (VELOCITYDIRECTIVE_BEGIN.contains(directiveName)) { 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); } if (velocityBlock != null) { velocityBlock.append(array, currentIndex, i - currentIndex); } return i; }  int getKeyWord(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getDirective(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getVelocityIdentifier(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); boolean isValidVelocityIdentifierChar(char c); int getDirectiveName(char[] array, int currentIndex, StringBuffer directiveName, StringBuffer velocityBlock,
        VelocityParserContext context); int getDirectiveEndOfLine(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getSimpleComment(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getMultilinesComment(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getVar(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getVar(char[] array, int currentIndex, StringBuffer varName, StringBuffer velocityBlock,
        VelocityParserContext context); int getMethodOrProperty(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getTableElement(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getMethodParameters(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getParameters(char[] array, int currentIndex, StringBuffer velocityBlock, char endingChar,
        VelocityParserContext context); int getEscape(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getWhiteSpaces(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getSpaces(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getMacroParametersSeparator(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getMacroParameter(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); static final Set<String> VELOCITYDIRECTIVE_BEGIN; static final Set<String> VELOCITYDIRECTIVE_END; static final Set<String> VELOCITYDIRECTIVE_PARAM; static final Set<String> VELOCITYDIRECTIVE_NOPARAM; static final Set<String> VELOCITYDIRECTIVE_ALL; }