/** * @param va * @param fw * @throws Exception * @throws IOException */ public void generate(VelocityAction va, Writer fw) throws Exception, IOException { Assert.isNotNull(va.getContext(), "velocity context must be given"); Assert.isNotNull(va.getTemplatePath(), "velocity template must be given"); // get Template VelocityContext context = va.getContext(); String templatePath = va.getTemplatePath(); InputStream template = null; File templateFile = new File(templatePath); if (templateFile.exists()) { // the template is located on File System template = new FileInputStream(templateFile); } else { // resource may be acceded in classPath template = getClass().getResourceAsStream(templatePath); } Assert.isNotNull(template, "velocity template resource can't be loaded"); // execute Velocity.init(); String s = IOUtils.toString(template); Velocity.evaluate(context, fw, "log", s); // close streams template.close(); fw.flush(); fw.close(); }