use of org.apache.velocity.VelocityContext in project eweb4j-framework by laiweiwei.
the class VelocityRendererImpl method render.
public synchronized void render(Writer writer, Map<String, Object> datas) {
VelocityContext context = new VelocityContext();
if (datas != null) {
for (Iterator<Entry<String, Object>> it = datas.entrySet().iterator(); it.hasNext(); ) {
Entry<String, Object> e = it.next();
context.put(e.getKey(), e.getValue());
}
}
String tplPath = paths.get(MVCConfigConstant.LAYOUT_SCREEN_CONTENT_KEY);
// 将环境变量和输出部分结合
if (this.layout != null) {
for (Iterator<Entry<String, String>> it = this.paths.entrySet().iterator(); it.hasNext(); ) {
Entry<String, String> e = it.next();
String paramName = e.getKey();
String path = e.getValue();
StringWriter w = new StringWriter();
ve.getTemplate(path).merge(context, w);
String screenContent = w.toString();
context.put(paramName, screenContent);
}
tplPath = layout;
}
ve.getTemplate(tplPath).merge(context, writer);
}
use of org.apache.velocity.VelocityContext in project hive by apache.
the class TestScripts method getTemplateResult.
protected static String getTemplateResult(String command, Map<String, String> keyValues) throws IOException {
VelocityContext context = new VelocityContext();
for (String key : keyValues.keySet()) {
context.put(key, keyValues.get(key));
}
StringWriter writer = new StringWriter();
if (!Velocity.evaluate(context, writer, command, command)) {
throw new IOException("Unable to render " + command + " with " + keyValues);
}
writer.close();
return writer.toString();
}
use of org.apache.velocity.VelocityContext 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.VelocityContext in project opennms by OpenNMS.
the class GraphConfigGenerator method generateSnmpGraphInternal.
private String generateSnmpGraphInternal(Collection<Report> reports, String graphTemplate) {
Velocity.init();
VelocityContext context = new VelocityContext();
context.put("reportsList", reports.iterator());
context.put("reportsBody", reports.iterator());
Template template = Velocity.getTemplate(graphTemplate);
StringWriter sw = new StringWriter();
if (template != null) {
template.merge(context, sw);
}
return sw.toString();
}
use of org.apache.velocity.VelocityContext 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