Package cn.bran.japid.template

Examples of cn.bran.japid.template.RenderResult


    for (int i = 0; i < 5; i++) {
      posts.add(p);
    }

    long t = System.currentTimeMillis();
    RenderResult r = new AllPost().render("抬头", posts);
    System.out.println(System.currentTimeMillis() - t);
    System.out.println(r.getContent().toString());
  }
View Full Code Here


  }
 
  public static void testCachedRenderResult() {
    CachedItemStatus cis = new CachedItemStatus(0);
    HashMap<String, String> headers = new HashMap<String, String>();
    RenderResult rr = new RenderResult(headers, new StringBuilder(), 123);
    CachedRenderResult crr = new CachedRenderResult(cis, rr);
    Cache.safeAdd("crr", crr, "10s");
    crr = (CachedRenderResult) Cache.get("crr");
    if(crr.isExpired())
      renderText("good to know..");
View Full Code Here

      renderText("StringBuilder does not works...");
  }
 
  public static void testRenderResult() {
    HashMap<String, String> headers = null; //new HashMap<String, String>();
    RenderResult rr = new RenderResult(headers, new StringBuilder(), 123);
//    RenderResult rr = new RenderResult(headers, null, 123);
    Cache.safeAdd("crr", rr, "10s");
    rr = (RenderResult) Cache.get("crr");
    if (rr != null)
      renderText("good to know 2...");
View Full Code Here

 
 
  public static void foo() {
    StringBuilder sb = new StringBuilder();
    sb.append("------foo() action invoked:Hello foo!");
    RenderResult rr = new RenderResult(null, sb, 0);
   
    throw new JapidResult(rr);
   
//    runWithCache(new ActionRunner() {
//      @Override
View Full Code Here

  public RenderResult run() {
    if (!shouldCache()) {
      return render();
    } else {
      // cache in work
      RenderResult rr = null;
      if (!readThru) {
        try {
          rr = RenderResultCache.get(getKeyString());
          if (rr != null)
            return rr;
View Full Code Here

   * @param cls
   * @param args
   * @return
   */
  public static String render(Class<? extends JapidTemplateBaseWithoutPlay> cls, Object... args) {
    RenderResult r = RenderInvokerUtils.invokeRender(cls, args);
    return r.getText();
  }
View Full Code Here

   * @param p
   * @return
   */
  public static String render(Object... args) {
    String templateName = findTemplate();
    RenderResult r = JapidController.getRenderResultWith(templateName, args);
    return r.getText();
  }
View Full Code Here

   *            ClassLoader.getResource().
   * @param args
   * @return the result string
   */
  public static String renderWith(String templateName, Object... args) {
    RenderResult r = JapidController.getRenderResultWith(templateName, args);
    return r.getText();
  }
View Full Code Here

    // throw new RuntimeException(e);
    //
    Class<? extends JapidTemplateBaseWithoutPlay> rendererClass = getErrorRendererClass();

    if (e instanceof JapidTemplateException) {
      RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, (JapidTemplateException) e);
      return (rr);
    }

    if (e instanceof RuntimeException && e.getCause() != null)
      e = e.getCause();

    if (e instanceof JapidCompilationException) {
      JapidCompilationException jce = (JapidCompilationException) e;
      JapidTemplateException te = JapidTemplateException.from(jce);
      RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, te);
      return (rr);
    }

    e.printStackTrace();

    // find the latest japidviews exception or the controller that caused
    // the exception
    StackTraceElement[] stackTrace = e.getStackTrace();
    for (StackTraceElement ele : stackTrace) {
      String className = ele.getClassName();
      if (className.startsWith("japidviews")) {
        int lineNumber = ele.getLineNumber();
        RendererClass applicationClass = japidClasses.get(className);
        if (applicationClass != null) {
          // let's get the line of problem
          int oriLineNumber = applicationClass.mapJavaLineToJapidScriptLine(lineNumber);
          if (oriLineNumber > 0) {
            if (rendererClass != null) {
              String path = applicationClass.getOriSourceCode();
              JapidTemplateException te = new JapidTemplateException("Japid Error", path + "("
                  + oriLineNumber + "): " + e.getClass().getName() + ": " + e.getMessage(),
                  oriLineNumber, path, applicationClass.getOriSourceCode());
              RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, te);
              return (rr);
            }
          }
        }
      } else if (className.startsWith("controllers.")) {
        if (e instanceof RuntimeException)
          throw (RuntimeException) e;
        else
          throw new RuntimeException(e);
      }
    }

    JapidTemplateException te = new JapidTemplateException(e);
    RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, te);
    return rr;
    // if (e instanceof RuntimeException)
    // throw (RuntimeException) e;
    // else
    // throw new RuntimeException(e);
View Full Code Here

    return japidviews.devError.class;
  }

  public static String renderPlayException(Exception e) {
    Exception exp = cn.bran.play.util.PlayExceptionUtils.mapJapidJavaCodeError(e);
    RenderResult rr = error500ForPlay.apply(exp);
    return rr.toString();
  }
View Full Code Here

TOP

Related Classes of cn.bran.japid.template.RenderResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.