use of org.apache.velocity.VelocityContext in project stanbol by apache.
the class BenchmarkServlet method getVelocityContext.
private VelocityContext getVelocityContext(HttpServletRequest request, String pageTitle) {
final VelocityContext ctx = new VelocityContext();
ctx.put("title", getServletInfo() + " - " + pageTitle);
ctx.put("contextPath", request.getContextPath());
ctx.put("cssPath", request.getContextPath() + mountPath + "/benchmark.css");
ctx.put("esc", new EscapeTool());
return ctx;
}
use of org.apache.velocity.VelocityContext in project stanbol by apache.
the class BenchmarkServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final String path = request.getPathInfo() == null ? "" : request.getPathInfo();
if (path.endsWith(".css")) {
// Serve our css
final Template t = getTemplate("/velocity/benchmark.css");
response.setContentType("text/css");
response.setCharacterEncoding("UTF-8");
t.merge(getVelocityContext(request, null), response.getWriter());
} else if (path.length() < 2) {
// No benchmark specified -> redirect to default
response.sendRedirect(getExampleBenchmarkPath(request, DEFAULT_BENCHMARK));
} else {
// Benchmark input form pre-filled with selected example
final Template t = getTemplate("/velocity/benchmark-input.html");
final VelocityContext ctx = getVelocityContext(request, "Benchmark Input");
ctx.put("formAction", request.getContextPath() + mountPath);
ctx.put("benchmarkText", getBenchmarkText(path));
ctx.put("benchmarkPaths", getExampleBenchmarkPaths(request));
ctx.put("currentBenchmarkPath", path);
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
t.merge(ctx, response.getWriter());
}
}
use of org.apache.velocity.VelocityContext in project stanbol by apache.
the class BenchmarkServlet method doPost.
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
final String content = request.getParameter(PARAM_CONTENT);
if (content == null) {
throw new ServletException("Missing " + PARAM_CONTENT + " parameter");
}
String chainName = request.getParameter(PARAM_CHAIN);
final Template t = AccessController.doPrivileged(new PrivilegedAction<Template>() {
@Override
public Template run() {
return getTemplate("/velocity/benchmark-results.html");
}
});
final VelocityContext ctx = getVelocityContext(request, "Benchmark Results");
ctx.put("contentItemFactory", ciFactory);
ctx.put("jobManager", jobManager);
List<? extends Benchmark> benchmarks = parser.parse(new StringReader(content));
if (chainName != null && !chainName.isEmpty()) {
Chain chain = chainManager.getChain(chainName);
if (chain == null) {
response.setStatus(404);
PrintWriter w = response.getWriter();
w.println("Unable to perform benchmark on EnhancementChain '" + StringEscapeUtils.escapeHtml(chainName) + "' because no chain with that name is active!");
IOUtils.closeQuietly(w);
return;
}
for (Benchmark benchmark : benchmarks) {
benchmark.setChain(chain);
}
}
ctx.put("benchmarks", benchmarks);
ctx.put("graphFormatter", new GraphFormatter(graphSerializer));
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws IOException {
t.merge(ctx, response.getWriter());
return null;
}
});
} catch (PrivilegedActionException pae) {
Exception e = pae.getException();
if (e instanceof IOException) {
throw (IOException) e;
} else {
throw RuntimeException.class.cast(e);
}
}
}
use of org.apache.velocity.VelocityContext in project ngAndroid by davityle.
the class NgModelSourceLink method getVelocityContext.
public VelocityContext getVelocityContext() {
VelocityContext vc = new VelocityContext();
vc.put("simpleClassName", modelName);
vc.put("className", packageName.fold(new Option.OptionCB<String, String>() {
@Override
public String absent() {
return modelName;
}
@Override
public String present(String pack) {
return pack + '.' + modelName;
}
}));
vc.put("packageName", packageName.getOrElse(""));
vc.put("fullName", fullName);
vc.put("isInterface", isInterface);
vc.put("fields", fields);
return vc;
}
use of org.apache.velocity.VelocityContext in project ngAndroid by davityle.
the class ScopeSourceLink method getVelocityContext.
@Override
public VelocityContext getVelocityContext() {
VelocityContext vc = new VelocityContext();
vc.put("scope", scope);
vc.put("className", className);
vc.put("package", pack);
vc.put("packageName", packageName);
return vc;
}
Aggregations