/** * 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; }
context.pushVelocityElement(new VelocityBlock(directiveName, VelocityBlock.VelocityType.DIRECTIVE)); } else if (VELOCITYDIRECTIVE_END.contains(directiveName)) { context.popVelocityElement(); context.setType(VelocityBlock.VelocityType.DIRECTIVE); } else { context.setType(VelocityBlock.VelocityType.MACRO);
if ("macro".equals(context.getCurrentElement().getName())) { HTMLFilter.appendHTMLClose(directiveBuffer, econtext.getFilterContext(), true); context.popVelocityElement(); context.setType(VelocityBlock.VelocityType.DIRECTIVE); context.pushVelocityElement(new VelocityBlock(directiveName, VelocityBlock.VelocityType.DIRECTIVE)); } else { econtext.setVelocity(true); context.setType(VelocityBlock.VelocityType.MACRO);
/** * Handle velocity comments and directive. * * @param contentBuffer the final result buffer * @param array the source * @param currentIndex the current index in the source * @param context the velocity parser context * @param filterContext the filter context * @return the index after the comment or directive * @throws InvalidVelocityException not velocity */ private int cleanKeyWord(StringBuffer contentBuffer, char[] array, int currentIndex, VelocityParserContext context, FilterContext filterContext) throws InvalidVelocityException { int i = this.velocityParser.getKeyWord(array, currentIndex, null, context); if (context.getType() != VelocityType.COMMENT) { if (context.getType() == VelocityType.DIRECTIVE) { if (filterContext.wsGroup.length() == 0) { flushWhiteSpaces(filterContext.wsGroup, filterContext, false); } filterContext.wsGroup.append(array, currentIndex, i - currentIndex); filterContext.removeWhiteSpaces = true; } else { flushWhiteSpaces(contentBuffer, filterContext, false); contentBuffer.append(array, currentIndex, i - currentIndex); } } return i; }
VelocityParserContext context = new VelocityParserContext(); FilterContext filterContext = new FilterContext();
context.pushVelocityElement(new VelocityBlock(directiveName, VelocityBlock.VelocityType.DIRECTIVE)); } else if (VELOCITYDIRECTIVE_END.contains(directiveName)) { context.popVelocityElement(); context.setType(VelocityBlock.VelocityType.DIRECTIVE); } else { context.setType(VelocityBlock.VelocityType.MACRO);
/** * 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; }
/** * Get multilines comment (between <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 getMultilinesComment(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) { int i = currentIndex + 2; while (i < array.length && (array[i - 1] != '#' || array[i - 2] != '*')) { ++i; } if (velocityBlock != null) { velocityBlock.append(array, currentIndex, i - currentIndex); } context.setType(VelocityBlock.VelocityType.COMMENT); return i; }
/** * Get multilines comment (between <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 getMultilinesComment(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) { int i = currentIndex + 2; while (i < array.length && (array[i - 1] != '#' || array[i - 2] != '*')) { ++i; } if (velocityBlock != null) { velocityBlock.append(array, currentIndex, i - currentIndex); } context.setType(VelocityBlock.VelocityType.COMMENT); return i; }
context.setType(VelocityBlock.VelocityType.VAR);
context.setType(VelocityBlock.VelocityType.VAR);