public String generateSubTemplateString(GenerationContext generationContext, String template) throws Exception { StringWriter writer = new StringWriter(); // This is necessary to cover possible included sub-templates generationContext.setCurrentOutput(writer); //read the template to use String templatePath = null; try { templatePath = getFullVelocityPath(generationContext.getTemplatesPath(), template); Template t = velocityEngine.getTemplate(templatePath); t.merge(generationContext.getVelocityContext(), writer); } catch (Exception e) { logger.error("An error was produced during template adf: template: " + template + ", templatePath: " + templatePath, e); } return writer.toString(); }
public void generateSubTemplate(GenerationContext generationContext, String template) throws Exception { //read the template to use String templatePath = null; try { templatePath = getFullVelocityPath(generationContext.getTemplatesPath(), template); Template t = velocityEngine.getTemplate(templatePath); t.merge(generationContext.getVelocityContext(), generationContext.getCurrentOutput()); } catch (Exception e) { logger.error("An error was produced during template adf: template: " + template + ", templatePath: " + templatePath, e); } }
/** * Runs the code adf. * * @param generationContext Context information for the adf. * * @throws Exception * */ public void generate(GenerationContext generationContext) throws Exception { VelocityContext context = buildContext(generationContext); String templatesPath = generationContext.getTemplatesPath(); String initialTemplate = generationContext.getInitialTemplate(); if (logger.isDebugEnabled()) { logger.debug("Starting code adf with templatesPath: " + templatesPath + ", initialTemplate: " + initialTemplate); } // Always start by the initial template String templatePath = getFullVelocityPath(templatesPath, initialTemplate); if (logger.isDebugEnabled()) logger.debug("Initial templatePath: " + templatePath); StringWriter writer = new StringWriter(); Template t = velocityEngine.getTemplate(templatePath); t.merge(context, writer); }
String templatePath = getFullVelocityPath(generationContext.getTemplatesPath(), template); VelocityContext context = buildContext(generationContext);