Search in sources :

Example 1 with TemplateViewRoute

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());
}
Also used : Response(spark.Response) VelocityTemplateEngine(spark.template.velocity.VelocityTemplateEngine) Request(spark.Request) ModelAndView(spark.ModelAndView) Map(java.util.Map) TemplateViewRoute(spark.TemplateViewRoute)

Aggregations

Map (java.util.Map)1 ModelAndView (spark.ModelAndView)1 Request (spark.Request)1 Response (spark.Response)1 TemplateViewRoute (spark.TemplateViewRoute)1 VelocityTemplateEngine (spark.template.velocity.VelocityTemplateEngine)1