use of org.apache.velocity.Template in project selenium-tests by Wikia.
the class VelocityWrapper method fillLogRowWithLink.
public static String fillLogRowWithLink(String link, String label) {
StringBuilder builder = new StringBuilder();
Template t = velocityEngine.getTemplate(LOG_ROW_WITH_LINK_TEMPLATE_PATH);
VelocityContext context = new VelocityContext();
context.put("link", link);
context.put("label", label);
StringWriter writer = new StringWriter();
t.merge(context, writer);
builder.append(writer.toString());
return builder.toString();
}
use of org.apache.velocity.Template in project selenium-tests by Wikia.
the class VelocityWrapper method fillButton.
static String fillButton(String id, String label) {
StringBuilder builder = new StringBuilder();
Template t = velocityEngine.getTemplate(BUTTON_TEMPLATE_PATH);
VelocityContext context = new VelocityContext();
context.put("id", id);
context.put("label", label);
StringWriter writer = new StringWriter();
t.merge(context, writer);
builder.append(writer.toString());
return builder.toString();
}
use of org.apache.velocity.Template in project camel by apache.
the class AbstractGeneratorMojo method mergeTemplate.
protected void mergeTemplate(VelocityContext context, File outFile, String templateName) throws MojoExecutionException {
// ensure parent directories exist
final File outDir = outFile.getParentFile();
if (!outDir.isDirectory() && !outDir.mkdirs()) {
throw new MojoExecutionException("Error creating directory " + outDir);
}
// add generated date
context.put("generatedDate", new Date().toString());
// add output package
context.put("packageName", outPackage);
context.put("newLine", "\n");
// load velocity template
final Template template = getEngine().getTemplate(templateName, "UTF-8");
// generate file
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(outFile));
template.merge(context, writer);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
} catch (VelocityException e) {
throw new MojoExecutionException(e.getMessage(), e);
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException ignore) {
}
}
}
}
use of org.apache.velocity.Template in project midpoint by Evolveum.
the class SchemaDocMojo method renderSchema.
private void renderSchema(PrismSchema schema, PrismContext prismContext, VelocityEngine velocityEngine, PathGenerator pathGenerator) throws IOException {
getLog().info("Processing schema: " + schema);
VelocityContext velocityContext = new VelocityContext();
populateVelocityContextBase(velocityContext, prismContext, pathGenerator, schema, "..");
Template template = velocityEngine.getTemplate(TEMPLATE_SCHEMA_NAME);
Writer writer = new FileWriter(pathGenerator.prepareSchemaOutputFile(schema));
template.merge(velocityContext, writer);
writer.close();
// Object Definitions
for (PrismObjectDefinition objectDefinition : schema.getObjectDefinitions()) {
renderObjectDefinition(objectDefinition, schema, prismContext, velocityEngine, pathGenerator);
}
// Types
for (ComplexTypeDefinition typeDefinition : schema.getComplexTypeDefinitions()) {
renderComplexTypeDefinition(typeDefinition, schema, prismContext, velocityEngine, pathGenerator);
}
}
use of org.apache.velocity.Template in project lucene-solr by apache.
the class VelocityResponseWriter method write.
@Override
public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response) throws IOException {
// TODO: have HTTP headers available for configuring engine
VelocityEngine engine = createEngine(request);
Template template = getTemplate(engine, request);
VelocityContext context = createContext(request, response);
// for $engine.resourceExists(...)
context.put("engine", engine);
String layoutTemplate = request.getParams().get(LAYOUT);
boolean layoutEnabled = request.getParams().getBool(LAYOUT_ENABLED, true) && layoutTemplate != null;
String jsonWrapper = request.getParams().get(JSON);
boolean wrapResponse = layoutEnabled || jsonWrapper != null;
// create output
if (!wrapResponse) {
// straight-forward template/context merge to output
template.merge(context, writer);
} else {
// merge to a string buffer, then wrap with layout and finally as JSON
StringWriter stringWriter = new StringWriter();
template.merge(context, stringWriter);
if (layoutEnabled) {
context.put("content", stringWriter.toString());
stringWriter = new StringWriter();
try {
engine.getTemplate(layoutTemplate + TEMPLATE_EXTENSION).merge(context, stringWriter);
} catch (Exception e) {
throw new IOException(e.getMessage());
}
}
if (jsonWrapper != null) {
writer.write(jsonWrapper + "(");
writer.write(getJSONWrap(stringWriter.toString()));
writer.write(')');
} else {
// using a layout, but not JSON wrapping
writer.write(stringWriter.toString());
}
}
}
Aggregations