use of spark.TemplateViewRoute in project newts by OpenNMS.
the class Web method main.
public static void main(String... args) {
staticFileLocation("/static");
get("/stations", new TemplateViewRoute() {
@Override
public ModelAndView handle(Request request, Response response) {
Map<String, Object> model = Maps.newHashMap();
model.put("stationsMap", STATION_NAMES);
return new ModelAndView(model, "index.wm");
}
}, new VelocityTemplateEngine());
get("/summer88", new TemplateViewRoute() {
@Override
public ModelAndView handle(Request request, Response response) {
Map<String, Object> model = Maps.newHashMap();
model.put("stationIds", STATION_IDS);
return new ModelAndView(model, "summer.wm");
}
}, new VelocityTemplateEngine());
get("/stations/:stationName", new TemplateViewRoute() {
@Override
public ModelAndView handle(Request request, Response response) {
String stationName = request.params(":stationName");
String id = STATION_IDS.get(stationName);
if (id == null) {
halt(404, "No such station");
}
Map<String, String> model = Maps.newHashMap();
model.put("location", STATION_NAMES.get(stationName));
model.put("id", id);
model.put("start", request.queryParams("start"));
model.put("end", request.queryParams("end"));
model.put("resolution", request.queryParams("resolution"));
return new ModelAndView(model, "station.wm");
}
}, new VelocityTemplateEngine());
}
Aggregations