Beispiel #1
0
  /** 默认构造函数 */
  public JetbrickRender() {
    config = new Properties();
    config.put("jetx.input.encoding", Blade.encoding());
    config.put("jetx.output.encoding", Blade.encoding());
    config.put("jetx.template.suffix", ".html");
    config.put("jetx.template.loaders", "jetbrick.template.loader.FileSystemResourceLoader");

    jetEngine = JetEngine.create(config);
  }
Beispiel #2
0
  /** 渲染视图 */
  @Override
  public Object render(String view) {

    HttpServletRequest request = BladeWebContext.servletRequest();
    HttpServletResponse response = BladeWebContext.servletResponse();

    try {

      view = Blade.webRoot() + disposeView(view);

      JetTemplate template = jetEngine.getTemplate(view);

      Map<String, Object> context = new HashMap<String, Object>();

      Enumeration<String> attrs = request.getAttributeNames();

      if (null != attrs && attrs.hasMoreElements()) {
        while (attrs.hasMoreElements()) {
          String attr = attrs.nextElement();
          context.put(attr, request.getAttribute(attr));
        }
      }

      template.render(context, response.getOutputStream());
    } catch (ResourceNotFoundException e) {
      render404(response, view);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }