Esempio n. 1
0
  /**
   * render an array of objects to a template defined by a Template class.
   *
   * @param <T> a sub-class type of JapidTemplateBaseWithoutPlay
   * @param c a sub-class of JapidTemplateBase
   * @param args arguments
   */
  public static <T extends JapidTemplateBaseWithoutPlay> String renderWith(
      Class<T> c, Object... args) {
    checkJapidInit();

    if (JapidRenderer.isDevMode()) return renderJapidWith(c.getName(), args);
    else
      try {
        return invokeRender(c, args);
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
  }
Esempio n. 2
0
  /**
   * render parameters to the prescribed template and return the RenderResult
   *
   * @param template relative path from japidviews folder. if empty, use implicit naming pattern to
   *     match the template
   * @param args
   */
  public static String getRenderResultWith(String template, Object... args) {
    checkJapidInit();

    if (template == null || template.length() == 0) {
      template = template();
    }

    if (template.endsWith(HTML)) {
      template = template.substring(0, template.length() - HTML.length());
    }

    String templateClassName =
        template.startsWith(JAPIDVIEWS_ROOT)
            ? template
            : JAPIDVIEWS_ROOT + File.separator + template;

    templateClassName = templateClassName.replace('/', DOT).replace('\\', DOT);

    Class<? extends JapidTemplateBaseWithoutPlay> tClass = null;

    // tClass = JapidRenderer.getClass(templateClassName);
    //
    // if (tClass == null) {
    // String templateFileName = templateClassName.replace(DOT, '/') + HTML;
    // throw new
    // RuntimeException("Could not find a Japid template with the name of: "
    // + templateFileName);
    // } else {
    // // render(tClass, args);
    // String rr = invokeRender(tClass, args);
    // return rr;
    // }
    RendererClass rc = JapidRenderer.getFunctionalRendererClass(templateClassName);
    if (rc == null) {
      String templateFileName = templateClassName.replace(DOT, '/') + HTML;
      throw new RuntimeException(
          "Could not find a Japid template with the name of: " + templateFileName);
    } else {
      String rr = invokeRender(rc, args);
      return rr;
    }
  }
Esempio n. 3
0
 private static void checkJapidInit() {
   if (!JapidRenderer.isInited()) {
     throw new RuntimeException(
         "The Japid is not initialized. Please use JapidRender.init(...) to set it up.");
   }
 }