예제 #1
0
 public void count(
     Counter counter,
     int times,
     String name,
     Map<String, Object> context,
     Writer writer,
     Writer discardWriter,
     OutputStream discardStream)
     throws Exception {
   counter.beginning();
   GroupTemplate group = new GroupTemplate();
   group.enableOptimize();
   group.enableNativeCall();
   counter.initialized();
   Template template =
       group.getReaderTemplate(
           new InputStreamReader(
               BeetlCase.class.getClassLoader().getResourceAsStream("performance/books.btl")));
   for (Map.Entry<String, Object> entry : context.entrySet()) {
     template.set(entry.getKey(), entry.getValue());
   }
   counter.compiled();
   template.getText(writer);
   counter.executed();
   if (discardStream != null) {
     for (int i = times; i >= 0; i--) {
       template.getText(discardStream);
     }
   } else {
     for (int i = times; i >= 0; i--) {
       template.getText(discardWriter);
     }
   }
   counter.finished();
 }
예제 #2
0
  @SuppressWarnings("unchecked")
  @Override
  protected void renderMergedTemplateModel(
      Map model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    BeetlGroupUtilConfiguration config =
        (BeetlGroupUtilConfiguration) this.getApplicationContext().getBean("beetlConfig");
    GroupTemplate group = config.getGroupTemplate();
    Template t = group.getFileTemplate(getUrl());
    group.enableNativeCall();
    Iterator<Entry<String, Object>> it = model.entrySet().iterator();
    Entry<String, Object> entry = null;
    while (it.hasNext()) {
      entry = it.next();
      t.set(entry.getKey(), entry.getValue());
    }
    WebVariable webVariable = new WebVariable();
    webVariable.setRequest(request);
    webVariable.setResponse(response);
    webVariable.setSession(request.getSession());

    t.set("servlet", webVariable);
    t.set("ctxPath", request.getContextPath());
    t.setRawValue("session", new SessionWrapper(request.getSession()));
    t.getText(response.getWriter());
  }