use of org.apache.velocity.app.VelocityEngine in project bazel by bazelbuild.
the class TemplateEngine method newPage.
/**
* Returns a new {@link Page} using the given .vm template file path. The template file
* path must be the resource path for the .vm file in the JAR since the VelocityEngine
* is configured to load .vm files from JAR resources.
*/
public static Page newPage(String template) {
VelocityEngine engine = new VelocityEngine();
engine.setProperty("resource.loader", "classpath, jar");
engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
engine.setProperty("jar.resource.loader.class", JarResourceLoader.class.getName());
engine.setProperty("input.encoding", "UTF-8");
engine.setProperty("output.encoding", "UTF-8");
engine.setProperty("directive.set.null.allowed", true);
engine.setProperty("parser.pool.size", 3);
engine.setProperty("runtime.references.strict", true);
return new Page(engine, template);
}
use of org.apache.velocity.app.VelocityEngine in project gocd by gocd.
the class VelocityFixture method renderMacro.
public String renderMacro(String template, HashMap model) throws Exception {
String path = new File("../server/webapp/WEB-INF/vm").getCanonicalPath();
Properties properties = new Properties();
properties.setProperty(Velocity.RESOURCE_LOADER, "file");
properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
properties.setProperty(Velocity.FILE_RESOURCE_LOADER_CACHE, "false");
VelocityEngine engine = new VelocityEngine();
engine.init(properties);
Template t = engine.getTemplate(template + ".vm");
VelocityContext ctx = new VelocityContext();
for (Object key : model.keySet()) {
ctx.put((String) key, model.get(key));
}
ctx.put("req", new FakeRequest());
Writer writer = new StringWriter();
t.merge(ctx, writer);
return writer.toString();
}
use of org.apache.velocity.app.VelocityEngine in project midpoint by Evolveum.
the class SchemaDocMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("SchemaDoc plugin started");
PrismContext prismContext = createInitializedPrismContext();
File outDir = initializeOutDir();
PathGenerator pathGenerator = new PathGenerator(outDir);
VelocityEngine velocityEngine = createVelocityEngine();
SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
try {
renderSchemaIndex(schemaRegistry, prismContext, velocityEngine, pathGenerator);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
for (PrismSchema schema : schemaRegistry.getSchemas()) {
try {
renderSchema(schema, prismContext, velocityEngine, pathGenerator);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
try {
copyResources(outDir);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
File archiveFile = null;
try {
archiveFile = generateArchive(outDir, finalName + "-schemadoc.zip");
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
} catch (ArchiverException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
projectHelper.attachArtifact(project, "zip", "schemadoc", archiveFile);
getLog().info("SchemaDoc plugin finished");
}
use of org.apache.velocity.app.VelocityEngine in project opennms by OpenNMS.
the class GraphConfigGenerator method generateSnmpGraphInternal.
private String generateSnmpGraphInternal(Collection<Report> reports) {
// init VelocityEngine
VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
velocityEngine.init();
// create reader and writer for template extraction from jar
InputStream templateInputStream = this.getClass().getClassLoader().getResourceAsStream(INTERN_TEMPLATE_NAME);
StringWriter templateWriter = new StringWriter();
Reader templateReader = new InputStreamReader(templateInputStream);
// create context
VelocityContext context = new VelocityContext();
context.put("reportsList", reports.iterator());
context.put("reportsBody", reports.iterator());
// get template
Velocity.evaluate(context, templateWriter, INTERN_TEMPLATE_NAME, templateReader);
return templateWriter.toString();
}
use of org.apache.velocity.app.VelocityEngine in project Ebselen by Ardesco.
the class IDEToEbselen method generateJavaFile.
/**
* Writes Sky Selenium format test code into a Java file ready for tests to be run
*
* @param name - Name of the test
* @throws Exception
*/
public void generateJavaFile(String name) throws Exception {
Properties props = new Properties();
props.setProperty("resource.loader", "class");
props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
props.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader");
VelocityEngine ve = new VelocityEngine(props);
VelocityContext context = new VelocityContext();
context.put("template", name);
context.put("templateclass", name + ".class");
context.put("testname", name);
context.put("testdata", testCode);
Template ebselenTemplate = ve.getTemplate(ebselenTestTemplate);
FileHandler convertedFile = new FileHandler(conversionLocation + File.separator + name + ".java", true);
StringWriter writer = new StringWriter();
ebselenTemplate.merge(context, writer);
convertedFile.write(writer.toString());
convertedFile.close();
LOGGER.info("Selenium IDE test converted and saved as '" + convertedFile.getFilePath() + convertedFile.getFileName() + "'");
}
Aggregations