コード例 #1
0
 protected Map<String, Object> buildScope(Request request) {
   Map<String, Object> scope = new HashMap<String, Object>();
   List<String> availableScopes = request.getAvailableScopes();
   for (int i = availableScopes.size() - 1; i >= 0; --i) {
     scope.putAll(request.getContext(availableScopes.get(i)));
   }
   return scope;
 }
コード例 #2
0
 @Override
 public ViewPreparer getPreparer(String name, Request context) {
   WebApplicationContext webApplicationContext =
       (WebApplicationContext)
           context.getContext("request").get(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
   if (webApplicationContext == null) {
     webApplicationContext =
         (WebApplicationContext)
             context
                 .getContext("application")
                 .get(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
     if (webApplicationContext == null) {
       throw new IllegalStateException(
           "No WebApplicationContext found: no ContextLoaderListener registered?");
     }
   }
   return getPreparer(name, webApplicationContext);
 }
コード例 #3
0
  @Override
  public void render(String templateName, Request request) throws IOException {
    // Compile template after reading file from file system.
    String templatePath =
        new StringBuilder(prefix).append("/").append(templateName).append(suffix).toString();
    if (!templateMap.containsKey(templateName))
      templateMap.put(templateName, Handlebars.compile(getFileContent(templatePath)));

    // Render template
    Template compiledTemplate = templateMap.get(templateName);
    compiledTemplate.apply(buildScope(request), request.getWriter());
  }