コード例 #1
0
ファイル: JetbrickRender.java プロジェクト: caoyingde/blade
  /** 默认构造函数 */
  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);
  }
コード例 #2
0
ファイル: JetbrickRender.java プロジェクト: caoyingde/blade
  /** 渲染视图 */
  @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;
  }