Exemple #1
0
 public static Object invokeControllerMethod(Method method, Object[] forceArgs) throws Exception {
   if (Modifier.isStatic(method.getModifiers())
       && !method.getDeclaringClass().getName().matches("^controllers\\..*\\$class$")) {
     return invoke(
         method, null, forceArgs == null ? getActionMethodArgs(method, null) : forceArgs);
   } else if (Modifier.isStatic(method.getModifiers())) {
     Object[] args = getActionMethodArgs(method, null);
     args[0] = Http.Request.current().controllerClass.getDeclaredField("MODULE$").get(null);
     return invoke(method, null, args);
   } else {
     Object instance = null;
     try {
       instance = method.getDeclaringClass().getDeclaredField("MODULE$").get(null);
     } catch (Exception e) {
       Annotation[] annotations = method.getDeclaredAnnotations();
       String annotation = Utils.getSimpleNames(annotations);
       if (!StringUtils.isEmpty(annotation)) {
         throw new UnexpectedException(
             "Method public static void "
                 + method.getName()
                 + "() annotated with "
                 + annotation
                 + " in class "
                 + method.getDeclaringClass().getName()
                 + " is not static.");
       }
       // TODO: Find a better error report
       throw new ActionNotFoundException(Http.Request.current().action, e);
     }
     return invoke(
         method, instance, forceArgs == null ? getActionMethodArgs(method, instance) : forceArgs);
   }
 }
Exemple #2
0
  // Gets baseUrl from current request or application.baseUrl in application.conf
  protected static String getBaseUrl() {
    if (Http.Request.current() == null) {
      // No current request is present - must get baseUrl from config
      String appBaseUrl =
          Play.configuration.getProperty("application.baseUrl", "application.baseUrl");
      if (appBaseUrl.endsWith("/")) {
        // remove the trailing slash
        appBaseUrl = appBaseUrl.substring(0, appBaseUrl.length() - 1);
      }
      return appBaseUrl;

    } else {
      return Http.Request.current().getBase();
    }
  }
Exemple #3
0
    static Session restore() {
      try {
        Session session = new Session();
        Http.Cookie cookie = Http.Request.current().cookies.get(COOKIE_PREFIX + "_SESSION");
        final int duration = Time.parseDuration(COOKIE_EXPIRE);
        final long expiration = (duration * 1000l);

        if (cookie != null
            && Play.started
            && cookie.value != null
            && !cookie.value.trim().equals("")) {
          String value = cookie.value;
          int firstDashIndex = value.indexOf("-");
          if (firstDashIndex > -1) {
            String sign = value.substring(0, firstDashIndex);
            String data = value.substring(firstDashIndex + 1);
            if (CookieDataCodec.safeEquals(sign, Crypto.sign(data, Play.secretKey.getBytes()))) {
              CookieDataCodec.decode(session.data, data);
            }
          }
          if (COOKIE_EXPIRE != null) {
            // Verify that the session contains a timestamp, and that it's not expired
            if (!session.contains(TS_KEY)) {
              session = new Session();
            } else {
              if ((Long.parseLong(session.get(TS_KEY))) < System.currentTimeMillis()) {
                // Session expired
                session = new Session();
              }
            }
            session.put(TS_KEY, System.currentTimeMillis() + expiration);
          } else {
            // Just restored. Nothing changed. No cookie-expire.
            session.changed = false;
          }
        } else {
          // no previous cookie to restore; but we may have to set the timestamp in the new cookie
          if (COOKIE_EXPIRE != null) {
            session.put(TS_KEY, (System.currentTimeMillis() + expiration));
          }
        }

        return session;
      } catch (Exception e) {
        throw new UnexpectedException(
            "Corrupted HTTP session from " + Http.Request.current().remoteAddress, e);
      }
    }
 static void save() {
   if (Http.Response.current() == null) {
     // Some request like WebSocket don't have any response
     return;
   }
   if (Validation.errors().isEmpty()) {
     // Only send "delete cookie" header when the cookie was present in the request
     if (Http.Request.current().cookies.containsKey(Scope.COOKIE_PREFIX + "_ERRORS")
         || !Scope.SESSION_SEND_ONLY_IF_CHANGED) {
       Http.Response.current().setCookie(Scope.COOKIE_PREFIX + "_ERRORS", "", "0s");
     }
     return;
   }
   try {
     StringBuilder errors = new StringBuilder();
     if (Validation.current() != null && Validation.current().keep) {
       for (Error error : Validation.errors()) {
         errors.append("\u0000");
         errors.append(error.key);
         errors.append(":");
         errors.append(error.message);
         for (String variable : error.variables) {
           errors.append("\u0001");
           errors.append(variable);
         }
         errors.append("\u0000");
       }
     }
     String errorsData = URLEncoder.encode(errors.toString(), "utf-8");
     Http.Response.current().setCookie(Scope.COOKIE_PREFIX + "_ERRORS", errorsData);
   } catch (Exception e) {
     throw new UnexpectedException("Errors serializationProblem", e);
   }
 }
Exemple #5
0
 public void checkAndParse() {
   if (!requestIsParsed) {
     Http.Request request = Http.Request.current();
     if (request == null) {
       throw new UnexpectedException("Current request undefined");
     } else {
       String contentType = request.contentType;
       if (contentType != null) {
         DataParser dataParser = DataParser.parsers.get(contentType);
         if (dataParser != null) {
           _mergeWith(dataParser.parse(request.body));
         } else {
           if (contentType.startsWith("text/")) {
             _mergeWith(new TextParser().parse(request.body));
           }
         }
       }
       try {
         request.body.close();
       } catch (Exception e) {
         //
       }
       requestIsParsed = true;
     }
   }
 }
Exemple #6
0
  public static Object invokeControllerMethod(Method method, Object[] forceArgs) throws Exception {
    boolean isStatic = Modifier.isStatic(method.getModifiers());
    String declaringClassName = method.getDeclaringClass().getName();
    boolean isProbablyScala = declaringClassName.contains("$");

    Http.Request request = Http.Request.current();

    if (!isStatic && request.controllerInstance == null) {
      request.controllerInstance = request.controllerClass.newInstance();
    }

    Object[] args =
        forceArgs != null ? forceArgs : getActionMethodArgs(method, request.controllerInstance);

    if (isProbablyScala) {
      try {
        Object scalaInstance = request.controllerClass.getDeclaredField("MODULE$").get(null);
        if (declaringClassName.endsWith("$class")) {
          args[0] = scalaInstance; // Scala trait method
        } else {
          request.controllerInstance = (Controller) scalaInstance; // Scala
          // object
          // method
        }
      } catch (NoSuchFieldException e) {
        // not Scala
      }
    }

    return invoke(method, request.controllerInstance, args);
  }
Exemple #7
0
 private void renderDocuments(Map<String, Object> args) {
   for (PDFDocument doc : docs.documents) {
     Request request = Http.Request.current();
     String templateName = PDF.resolveTemplateName(doc.template, request, request.format);
     Template template = TemplateLoader.load(templateName);
     doc.content = template.render(new HashMap<String, Object>(args));
     loadHeaderAndFooter(doc, args);
   }
 }
  public GTRenderingResult internalGTRender(Map<String, Object> args) {
    Http.Request currentResponse = Http.Request.current();
    if (currentResponse != null) {
      args.put("_response_encoding", currentResponse.encoding);
    }
    args.put("play", new Play());
    args.put("messages", new Messages());
    args.put("lang", Lang.get());

    return renderGTTemplate(args);
  }
Exemple #9
0
 static Flash restore() {
   try {
     Flash flash = new Flash();
     Http.Cookie cookie = Http.Request.current().cookies.get(COOKIE_PREFIX + "_FLASH");
     if (cookie != null) {
       CookieDataCodec.decode(flash.data, cookie.value);
     }
     return flash;
   } catch (Exception e) {
     throw new UnexpectedException("Flash corrupted", e);
   }
 }
Exemple #10
0
 public void absolute() {
   boolean isSecure = Http.Request.current() == null ? false : Http.Request.current().secure;
   String base = getBaseUrl();
   String hostPart = host;
   String domain = Http.Request.current() == null ? "" : Http.Request.current().get().domain;
   int port = Http.Request.current() == null ? 80 : Http.Request.current().get().port;
   if (port != 80 && port != 443) {
     hostPart += ":" + port;
   }
   // ~
   if (!url.startsWith("http")) {
     if (StringUtils.isEmpty(host)) {
       url = base + url;
     } else if (host.contains("{_}")) {
       java.util.regex.Matcher matcher =
           java.util.regex.Pattern.compile("([-_a-z0-9A-Z]+([.][-_a-z0-9A-Z]+)?)$")
               .matcher(domain);
       if (matcher.find()) {
         url =
             (isSecure ? "https://" : "http://")
                 + hostPart.replace("{_}", matcher.group(1))
                 + url;
       } else {
         url = (isSecure ? "https://" : "http://") + hostPart + url;
       }
     } else {
       url = (isSecure ? "https://" : "http://") + hostPart + url;
     }
     if (method.equals("WS")) {
       url = url.replaceFirst("https?", "ws");
     }
   }
 }
Exemple #11
0
 public static String reverse(VirtualFile file, boolean absolute) {
   if (file == null || !file.exists()) {
     throw new NoRouteFoundException("File not found (" + file + ")");
   }
   String path = file.relativePath();
   path = path.substring(path.indexOf("}") + 1);
   for (Route route : routes) {
     String staticDir = route.staticDir;
     if (staticDir != null) {
       if (!staticDir.startsWith("/")) {
         staticDir = "/" + staticDir;
       }
       if (!staticDir.equals("/") && !staticDir.endsWith("/")) {
         staticDir = staticDir + "/";
       }
       if (path.startsWith(staticDir)) {
         String to = route.path + path.substring(staticDir.length());
         if (to.endsWith("/index.html")) {
           to = to.substring(0, to.length() - "/index.html".length() + 1);
         }
         if (absolute) {
           boolean isSecure =
               Http.Request.current() == null ? false : Http.Request.current().secure;
           String base = getBaseUrl();
           if (!StringUtils.isEmpty(route.host)) {
             // Compute the host
             int port = Http.Request.current() == null ? 80 : Http.Request.current().get().port;
             String host = (port != 80 && port != 443) ? route.host + ":" + port : route.host;
             to = (isSecure ? "https://" : "http://") + host + to;
           } else {
             to = base + to;
           }
         }
         return to;
       }
     }
   }
   throw new NoRouteFoundException(file.relativePath());
 }
Exemple #12
0
//
// NOTE: This file was generated from: japidviews/_tags/SampleTag.html
// Change to this file will be lost next time the template file is compiled.
//
@cn.bran.play.NoEnhance
public class SampleTag extends cn.bran.japid.template.JapidTemplateBase {
  public static final String sourceTemplate = "japidviews/_tags/SampleTag.html";

  {
    headers.put("Content-Type", "text/html; charset=utf-8");
  }

  // - add implicit fields with Play

  final Request request = Request.current();
  final Response response = Response.current();
  final Session session = Session.current();
  final RenderArgs renderArgs = RenderArgs.current();
  final Params params = Params.current();
  final Validation validation = Validation.current();
  final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation);
  final play.Play _play = new play.Play();

  // - end of implicit fields with Play

  public SampleTag() {
    super(null);
  }

  public SampleTag(StringBuilder out) {
    super(out);
  }

  private String a;

  public cn.bran.japid.template.RenderResult render(String a) {
    this.a = a;
    long t = -1;
    super.layout();
    return new cn.bran.japid.template.RenderResult(this.headers, getOut(), t);
  }

  @Override
  protected void doLayout() {
    // ------
    ; // line 1
    p("Hi "); // line 1
    p(a); // line 2
    p("!\n"); // line 2
  }
}
Exemple #13
0
 void save() {
   if (Http.Response.current() == null) {
     // Some request like WebSocket don't have any response
     return;
   }
   if (!changed && SESSION_SEND_ONLY_IF_CHANGED && COOKIE_EXPIRE == null) {
     // Nothing changed and no cookie-expire, consequently send nothing back.
     return;
   }
   if (isEmpty()) {
     // The session is empty: delete the cookie
     if (Http.Request.current().cookies.containsKey(COOKIE_PREFIX + "_SESSION")
         || !SESSION_SEND_ONLY_IF_CHANGED) {
       Http.Response.current()
           .setCookie(
               COOKIE_PREFIX + "_SESSION", "", null, "/", 0, COOKIE_SECURE, SESSION_HTTPONLY);
     }
     return;
   }
   try {
     String sessionData = CookieDataCodec.encode(data);
     String sign = Crypto.sign(sessionData, Play.secretKey.getBytes());
     if (COOKIE_EXPIRE == null) {
       Http.Response.current()
           .setCookie(
               COOKIE_PREFIX + "_SESSION",
               sign + "-" + sessionData,
               null,
               "/",
               null,
               COOKIE_SECURE,
               SESSION_HTTPONLY);
     } else {
       Http.Response.current()
           .setCookie(
               COOKIE_PREFIX + "_SESSION",
               sign + "-" + sessionData,
               null,
               "/",
               Time.parseDuration(COOKIE_EXPIRE),
               COOKIE_SECURE,
               SESSION_HTTPONLY);
     }
   } catch (Exception e) {
     throw new UnexpectedException("Session serializationProblem", e);
   }
 }
Exemple #14
0
//
// NOTE: This file was generated from: japidviews/more/MyController/myLayout.html
// Change to this file will be lost next time the template file is compiled.
//
@cn.bran.play.NoEnhance
public abstract class myLayout extends cn.bran.japid.template.JapidTemplateBase {
  public static final String sourceTemplate = "japidviews/more/MyController/myLayout.html";

  {
    putHeader("Content-Type", "text/html; charset=utf-8");
  }

  // - add implicit fields with Play

  final Request request = Request.current();
  final Response response = Response.current();
  final Session session = Session.current();
  final RenderArgs renderArgs = RenderArgs.current();
  final Params params = Params.current();
  final Validation validation = Validation.current();
  final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation);
  final play.Play _play = new play.Play();

  // - end of implicit fields with Play

  public myLayout() {
    super(null);
  }

  public myLayout(StringBuilder out) {
    super(out);
  }

  @Override
  public void layout() {
    p("<p>"); // line 1
    title(); // line 1
    p("</p>\n" + "<p>"); // line 1
    side(); // line 2
    p("</p>\n" + "<p>\n"); // line 2
    doLayout(); // line 4
    p("</p>"); // line 4
  }

  protected void title() {};

  protected void side() {};

  protected abstract void doLayout();
}
 public List<ConstraintViolation> validateAction(Method actionMethod) throws Exception {
   List<ConstraintViolation> violations = new ArrayList<ConstraintViolation>();
   Object instance = null;
   // Patch for scala defaults
   if (!Modifier.isStatic(actionMethod.getModifiers())
       && actionMethod.getDeclaringClass().getSimpleName().endsWith("$")) {
     try {
       instance = actionMethod.getDeclaringClass().getDeclaredField("MODULE$").get(null);
     } catch (Exception e) {
       throw new ActionNotFoundException(Http.Request.current().action, e);
     }
   }
   Object[] rArgs = ActionInvoker.getActionMethodArgs(actionMethod, instance);
   validateMethodParameters(null, actionMethod, rArgs, violations);
   validateMethodPre(null, actionMethod, rArgs, violations);
   return violations;
 }
 static Validation restore() {
   try {
     Validation validation = new Validation();
     Http.Cookie cookie = Http.Request.current().cookies.get(Scope.COOKIE_PREFIX + "_ERRORS");
     if (cookie != null) {
       String errorsData = URLDecoder.decode(cookie.value, "utf-8");
       Matcher matcher = errorsParser.matcher(errorsData);
       while (matcher.find()) {
         String[] g2 = matcher.group(2).split("\u0001");
         String message = g2[0];
         String[] args = new String[g2.length - 1];
         System.arraycopy(g2, 1, args, 0, args.length);
         validation.errors.add(new Error(matcher.group(1), message, args));
       }
     }
     return validation;
   } catch (Exception e) {
     return new Validation();
   }
 }
Exemple #17
0
 void save() {
   if (Http.Response.current() == null) {
     // Some request like WebSocket don't have any response
     return;
   }
   if (out.isEmpty()) {
     if (Http.Request.current().cookies.containsKey(COOKIE_PREFIX + "_FLASH")
         || !SESSION_SEND_ONLY_IF_CHANGED) {
       Http.Response.current()
           .setCookie(COOKIE_PREFIX + "_FLASH", "", null, "/", 0, COOKIE_SECURE);
     }
     return;
   }
   try {
     String flashData = CookieDataCodec.encode(out);
     Http.Response.current()
         .setCookie(COOKIE_PREFIX + "_FLASH", flashData, null, "/", null, COOKIE_SECURE);
   } catch (Exception e) {
     throw new UnexpectedException("Flash serializationProblem", e);
   }
 } // ThreadLocal access
Exemple #18
0
  protected static Map<String, Object> getBindingForErrors(Exception e, boolean isError) {

    Map<String, Object> binding = new HashMap<String, Object>();
    if (!isError) {
      binding.put("result", e);
    } else {
      binding.put("exception", e);
    }
    binding.put("session", Scope.Session.current());
    binding.put("request", Http.Request.current());
    binding.put("flash", Scope.Flash.current());
    binding.put("params", Scope.Params.current());
    binding.put("play", new Play());
    try {
      binding.put("errors", Validation.errors());
    } catch (Exception ex) {
      // Logger.error(ex, "Error when getting Validation errors");
    }

    return binding;
  }
Exemple #19
0
 /** @see IdentityProvider#doAuth(java.util.Map) */
 @Override
 protected SocialUser doAuth(Map<String, Object> authContext) {
   if (!OpenID.isAuthenticationResponse()) {
     OpenID openId = OpenID.id(getUser());
     final String url = getFullUrl();
     openId.returnTo(url);
     openId.forRealm(Http.Request.current().getBase());
     configure(openId);
     if (!openId.verify()) {
       throw new AuthenticationException();
     }
   }
   //
   OpenID.UserInfo verifiedUser = OpenID.getVerifiedID();
   if (verifiedUser == null) {
     throw new AuthenticationException();
   }
   authContext.put(USER_INFO, verifiedUser);
   SocialUser user = createUser();
   user.id.id = verifiedUser.id;
   return user;
 }
Exemple #20
0
 public void serve404(
     HttpServletRequest servletRequest, HttpServletResponse servletResponse, NotFound e) {
   Logger.warn(
       "404 -> %s %s (%s)",
       servletRequest.getMethod(), servletRequest.getRequestURI(), e.getMessage());
   servletResponse.setStatus(404);
   servletResponse.setContentType("text/html");
   Map<String, Object> binding = new HashMap<String, Object>();
   binding.put("result", e);
   binding.put("session", Scope.Session.current());
   binding.put("request", Http.Request.current());
   binding.put("flash", Scope.Flash.current());
   binding.put("params", Scope.Params.current());
   binding.put("play", new Play());
   try {
     binding.put("errors", Validation.errors());
   } catch (Exception ex) {
     //
   }
   String format = Request.current().format;
   servletResponse.setStatus(404);
   // Do we have an ajax request? If we have then we want to display some text even if it is html
   // that is requested
   if ("XMLHttpRequest".equals(servletRequest.getHeader("X-Requested-With"))
       && (format == null || format.equals("html"))) {
     format = "txt";
   }
   if (format == null) {
     format = "txt";
   }
   servletResponse.setContentType(MimeTypes.getContentType("404." + format, "text/plain"));
   String errorHtml = TemplateLoader.load("errors/404." + format).render(binding);
   try {
     servletResponse.getOutputStream().write(errorHtml.getBytes(Response.current().encoding));
   } catch (Exception fex) {
     Logger.error(fex, "(encoding ?)");
   }
 }
Exemple #21
0
//
// NOTE: This file was generated from: japidviews/_tags/picka.html
// Change to this file will be lost next time the template file is compiled.
//
@cn.bran.play.NoEnhance
public class picka extends cn.bran.play.JapidTemplateBase {
  public static final String sourceTemplate = "japidviews/_tags/picka.html";

  private void initHeaders() {
    putHeader("Content-Type", "text/html; charset=utf-8");
    setContentType("text/html; charset=utf-8");
  }

  {
  }

  // - add implicit fields with Play

  final play.mvc.Http.Request request = play.mvc.Http.Request.current();
  final play.mvc.Http.Response response = play.mvc.Http.Response.current();
  final play.mvc.Scope.Session session = play.mvc.Scope.Session.current();
  final play.mvc.Scope.RenderArgs renderArgs = play.mvc.Scope.RenderArgs.current();
  final play.mvc.Scope.Params params = play.mvc.Scope.Params.current();
  final play.data.validation.Validation validation = play.data.validation.Validation.current();
  final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation);
  final play.Play _play = new play.Play();

  // - end of implicit fields with Play

  public picka() {
    super((StringBuilder) null);
    initHeaders();
  }

  public picka(StringBuilder out) {
    super(out);
    initHeaders();
  }

  public picka(cn.bran.japid.template.JapidTemplateBaseWithoutPlay caller) {
    super(caller);
  }

  /* based on https://github.com/branaway/Japid/issues/12
   */
  public static final String[] argNames =
      new String[] {
          /* args of the template*/
        "a", "b",
      };
  public static final String[] argTypes =
      new String[] {
          /* arg types of the template*/
        "String", "String",
      };
  public static final Object[] argDefaults =
      new Object[] {
        null, null,
      };
  public static java.lang.reflect.Method renderMethod =
      getRenderMethod(japidviews._tags.picka.class);

  {
    setRenderMethod(renderMethod);
    setArgNames(argNames);
    setArgTypes(argTypes);
    setArgDefaults(argDefaults);
    setSourceTemplate(sourceTemplate);
  }
  ////// end of named args stuff

  {
    setHasDoBody();
  }

  private String a; // line 1, japidviews/_tags/picka.html
  private String b; // line 1, japidviews/_tags/picka.html

  public cn.bran.japid.template.RenderResult render(
      DoBody body, cn.bran.japid.compiler.NamedArgRuntime... named) {
    Object[] args = buildArgs(named, body);
    try {
      return runRenderer(args);
    } catch (RuntimeException e) {
      handleException(e);
      throw e;
    } // line 1, japidviews/_tags/picka.html
  }

  private DoBody body;

  public static interface DoBody<A> {
    void render(A a);

    void setBuffer(StringBuilder sb);

    void resetBuffer();
  }

  <A> String renderBody(A a) {
    StringBuilder sb = new StringBuilder();
    if (body != null) {
      body.setBuffer(sb);
      body.render(a);
      body.resetBuffer();
    }
    return sb.toString();
  }

  public cn.bran.japid.template.RenderResult render(String a, String b, DoBody body) {
    this.body = body;
    this.a = a;
    this.b = b;
    try {
      super.layout();
    } catch (RuntimeException __e) {
      super.handleException(__e);
    } // line 1, japidviews/_tags/picka.html
    return getRenderResult();
  }

  public cn.bran.japid.template.RenderResult render(String a, String b) {
    this.a = a;
    this.b = b;
    try {
      super.layout();
    } catch (RuntimeException __e) {
      super.handleException(__e);
    } // line 1, japidviews/_tags/picka.html
    return getRenderResult();
  }

  public static cn.bran.japid.template.RenderResult apply(String a, String b) {
    return new picka().render(a, b);
  }

  @Override
  protected void doLayout() {
    beginDoLayout(sourceTemplate);
    ; // line 1, picka.html
    p("<p>\n" + "some text: "); // line 1, picka.html
    p(a); // line 3, picka.html
    p(" \n" + "</p>\n" + "<p>\n"); // line 3, picka.html
    if (body != null) {
      body.setBuffer(getOut());
      body.render(a + b);
      body.resetBuffer();
    } // line 6, picka.html
    p("</p>\n"); // line 6, picka.html
    String x = renderBody("xxx"); // line 8, picka.html
    p("["); // line 8, picka.html
    p(x); // line 9, picka.html
    p("]\n" + "<p>\n" + "more text: "); // line 9, picka.html
    p(b); // line 11, picka.html
    p("\n" + "</p>\n" + " "); // line 11, picka.html

    endDoLayout(sourceTemplate);
  }
}
Exemple #22
0
//
// NOTE: This file was generated from: japidviews/Application/decorateName.html
// Change to this file will be lost next time the template file is compiled.
//
@cn.bran.play.NoEnhance
public class decorateName extends cn.bran.play.JapidTemplateBase {
  public static final String sourceTemplate = "japidviews/Application/decorateName.html";

  {
    putHeader("Content-Type", "text/html; charset=utf-8");
  }

  // - add implicit fields with Play

  final Request request = Request.current();
  final Response response = Response.current();
  final Session session = Session.current();
  final RenderArgs renderArgs = RenderArgs.current();
  final Params params = Params.current();
  final Validation validation = Validation.current();
  final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation);
  final play.Play _play = new play.Play();

  // - end of implicit fields with Play

  public decorateName() {
    super(null);
  }

  public decorateName(StringBuilder out) {
    super(out);
  }
  /* based on https://github.com/branaway/Japid/issues/12
   */
  public static final String[] argNames =
      new String[] {
          /* args of the template*/
        "s",
      };
  public static final String[] argTypes =
      new String[] {
          /* arg types of the template*/
        "String",
      };
  public static final Object[] argDefaults =
      new Object[] {
        null,
      };
  public static java.lang.reflect.Method renderMethod =
      getRenderMethod(japidviews.Application.decorateName.class);

  {
    setRenderMethod(renderMethod);
    setArgNames(argNames);
    setArgTypes(argTypes);
    setArgDefaults(argDefaults);
    setSourceTemplate(sourceTemplate);
  }
  ////// end of named args stuff

  private String s;

  public cn.bran.japid.template.RenderResult render(String s) {
    this.s = s;
    long t = -1;
    try {
      super.layout();
    } catch (RuntimeException e) {
      super.handleException(e);
    }
    return new cn.bran.japid.template.RenderResultPartial(getHeaders(), getOut(), t, actionRunners);
  }

  @Override
  protected void doLayout() {
    // ------
    ; // line 1
    p("\n" + "^^^_ "); // line 1
    p(s); // line 3
    p(" _^^^\n"); // line 3
  }
}
Exemple #23
0
//
// NOTE: This file was generated from: japidviews/templates/AllPost2.html
// Change to this file will be lost next time the template file is compiled.
//
@cn.bran.play.NoEnhance
public class AllPost2 extends Layout {
  public static final String sourceTemplate = "japidviews/templates/AllPost2.html";

  {
    putHeader("Content-Type", "text/html; charset=utf-8");
    setContentType("text/html; charset=utf-8");
  }

  // - add implicit fields with Play

  final Request request = Request.current();
  final Response response = Response.current();
  final Session session = Session.current();
  final RenderArgs renderArgs = RenderArgs.current();
  final Params params = Params.current();
  final Validation validation = Validation.current();
  final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation);
  final play.Play _play = new play.Play();

  // - end of implicit fields with Play

  public AllPost2() {
    super(null);
  }

  public AllPost2(StringBuilder out) {
    super(out);
  }
  /* based on https://github.com/branaway/Japid/issues/12
   */
  public static final String[] argNames =
      new String[] {
          /* args of the template*/
        "blogTitle", "allPost",
      };
  public static final String[] argTypes =
      new String[] {
          /* arg types of the template*/
        "String", "List<Post>",
      };
  public static final Object[] argDefaults =
      new Object[] {
        null, null,
      };
  public static java.lang.reflect.Method renderMethod =
      getRenderMethod(japidviews.templates.AllPost2.class);

  {
    setRenderMethod(renderMethod);
    setArgNames(argNames);
    setArgTypes(argTypes);
    setArgDefaults(argDefaults);
    setSourceTemplate(sourceTemplate);
  }
  ////// end of named args stuff

  private String blogTitle; // line 3
  private List<Post> allPost; // line 3

  public cn.bran.japid.template.RenderResult render(String blogTitle, List<Post> allPost) {
    this.blogTitle = blogTitle;
    this.allPost = allPost;
    long t = -1;
    try {
      super.layout();
    } catch (RuntimeException e) {
      super.handleException(e);
    } // line 3
    return new cn.bran.japid.template.RenderResultPartial(
        getHeaders(), getOut(), t, actionRunners, sourceTemplate);
  }

  @Override
  protected void doLayout() {
    beginDoLayout(sourceTemplate);
    // ------
    ; // line 1
    p("\n"); // line 3
    p("\n" + "\n"); // line 5
    if (allPost.size() > 0) { // line 8
      p("	<p></p>\n" + "	"); // line 8
      for (Post p : allPost) { // line 10
        p("	    "); // line 10
        final Display _Display1 = new Display(getOut());
        _Display1.setActionRunners(getActionRunners()).setOut(getOut());
        _Display1.render( // line 11
            new Display.DoBody<String>() { // line 11
              public void render(final String title) { // line 11
                // line 11
                p("			<p>The real title is: "); // line 11
                p(title); // line 12
                p(";</p>\n" + "	    "); // line 12
              }

              StringBuilder oriBuffer;

              @Override
              public void setBuffer(StringBuilder sb) {
                oriBuffer = getOut();
                setOut(sb);
              }

              @Override
              public void resetBuffer() {
                setOut(oriBuffer);
              }
            },
            named("post", p),
            named("as", "home")); // line 11
        p("	"); // line 13
      } // line 14
    } else { // line 15
      p("	<p>There is no post at this moment</p>\n"); // line 15
    } // line 17
    p("\n"); // line 17
    final Tag2 _Tag22 = new Tag2(getOut());
    _Tag22.setActionRunners(getActionRunners()).setOut(getOut());
    _Tag22.render(named("msg", blogTitle), named("age", 1000)); // line 19// line 19
    p("\n" + "<p>end of it</p>"); // line 19

    endDoLayout(sourceTemplate);
  }

  @Override
  protected void title() {
    p("Home");
    ;
  }
}
Exemple #24
0
//
// NOTE: This file was generated from: japidviews/Application/testCacheForEager.html
// Change to this file will be lost next time the template file is compiled.
//
@cn.bran.play.NoEnhance
public class testCacheForEager extends cn.bran.play.JapidTemplateBase {
  public static final String sourceTemplate = "japidviews/Application/testCacheForEager.html";

  private void initHeaders() {
    putHeader("Content-Type", "text/html; charset=utf-8");
    setContentType("text/html; charset=utf-8");
  }

  {
  }

  // - add implicit fields with Play

  final play.mvc.Http.Request request = play.mvc.Http.Request.current();
  final play.mvc.Http.Response response = play.mvc.Http.Response.current();
  final play.mvc.Scope.Session session = play.mvc.Scope.Session.current();
  final play.mvc.Scope.RenderArgs renderArgs = play.mvc.Scope.RenderArgs.current();
  final play.mvc.Scope.Params params = play.mvc.Scope.Params.current();
  final play.data.validation.Validation validation = play.data.validation.Validation.current();
  final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation);
  final play.Play _play = new play.Play();

  // - end of implicit fields with Play

  public testCacheForEager() {
    super((StringBuilder) null);
    initHeaders();
  }

  public testCacheForEager(StringBuilder out) {
    super(out);
    initHeaders();
  }

  public testCacheForEager(cn.bran.japid.template.JapidTemplateBaseWithoutPlay caller) {
    super(caller);
  }

  /* based on https://github.com/branaway/Japid/issues/12
   */
  public static final String[] argNames =
      new String[] {
          /* args of the template*/
        "a",
      };
  public static final String[] argTypes =
      new String[] {
          /* arg types of the template*/
        "String",
      };
  public static final Object[] argDefaults =
      new Object[] {
        null,
      };
  public static java.lang.reflect.Method renderMethod =
      getRenderMethod(japidviews.Application.testCacheForEager.class);

  {
    setRenderMethod(renderMethod);
    setArgNames(argNames);
    setArgTypes(argTypes);
    setArgDefaults(argDefaults);
    setSourceTemplate(sourceTemplate);
  }
  ////// end of named args stuff

  private String a; // line 1, japidviews/Application/testCacheForEager.html

  public cn.bran.japid.template.RenderResult render(String a) {
    this.a = a;
    try {
      super.layout();
    } catch (RuntimeException __e) {
      super.handleException(__e);
    } // line 1, japidviews/Application/testCacheForEager.html
    return getRenderResult();
  }

  public static cn.bran.japid.template.RenderResult apply(String a) {
    return new testCacheForEager().render(a);
  }

  @Override
  protected void doLayout() {
    beginDoLayout(sourceTemplate);
    ; // line 1, testCacheForEager.html
    p("\n" + "<html>\n" + "\n" + "<body>\n" + "	hello "); // line 1, testCacheForEager.html
    p(a); // line 6, testCacheForEager.html
    p(", now seconds is "); // line 6, testCacheForEager.html
    actionRunners.put(
        getOut().length(),
        new cn.bran.play.CacheablePlayActionRunner("", Application.class, "seconds", "") {
          @Override
          public void runPlayAction() throws cn.bran.play.JapidResult {
            Application.seconds(); // line 6, testCacheForEager.html
          }
        });
    p("\n"); // line 6, testCacheForEager.html
    p("\n" + "</body>\n" + "</html>"); // line 6, testCacheForEager.html

    endDoLayout(sourceTemplate);
  }
}
Exemple #25
0
//
// NOTE: This file was generated from: japidviews/more/MyController/subview.html
// Change to this file will be lost next time the template file is compiled.
//
@cn.bran.play.NoEnhance
public class subview extends superview {
  public static final String sourceTemplate = "japidviews/more/MyController/subview.html";

  private void initHeaders() {
    putHeader("Content-Type", "text/html; charset=utf-8");
    setContentType("text/html; charset=utf-8");
  }

  {
  }

  // - add implicit fields with Play

  final play.mvc.Http.Request request = play.mvc.Http.Request.current();
  final play.mvc.Http.Response response = play.mvc.Http.Response.current();
  final play.mvc.Scope.Session session = play.mvc.Scope.Session.current();
  final play.mvc.Scope.RenderArgs renderArgs = play.mvc.Scope.RenderArgs.current();
  final play.mvc.Scope.Params params = play.mvc.Scope.Params.current();
  final play.data.validation.Validation validation = play.data.validation.Validation.current();
  final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation);
  final play.Play _play = new play.Play();

  // - end of implicit fields with Play

  public subview() {
    super((StringBuilder) null);
    initHeaders();
  }

  public subview(StringBuilder out) {
    super(out);
    initHeaders();
  }

  public subview(cn.bran.japid.template.JapidTemplateBaseWithoutPlay caller) {
    super(caller);
  }

  /* based on https://github.com/branaway/Japid/issues/12
   */
  public static final String[] argNames =
      new String[] {
        /* args of the template*/
        "s",
      };
  public static final String[] argTypes =
      new String[] {
        /* arg types of the template*/
        "String",
      };
  public static final Object[] argDefaults =
      new Object[] {
        null,
      };
  public static java.lang.reflect.Method renderMethod =
      getRenderMethod(japidviews.more.MyController.subview.class);

  {
    setRenderMethod(renderMethod);
    setArgNames(argNames);
    setArgTypes(argTypes);
    setArgDefaults(argDefaults);
    setSourceTemplate(sourceTemplate);
  }
  ////// end of named args stuff

  private String s; // line 2, japidviews/more/MyController/subview.html

  public cn.bran.japid.template.RenderResult render(String s) {
    this.s = s;
    try {
      super.layout();
    } catch (RuntimeException __e) {
      super.handleException(__e);
    } // line 2, japidviews/more/MyController/subview.html
    return getRenderResult();
  }

  public static cn.bran.japid.template.RenderResult apply(String s) {
    return new subview().render(s);
  }

  @Override
  protected void doLayout() {
    beginDoLayout(sourceTemplate);
    ; // line 1, subview.html
    ; // line 2, subview.html
    // line 4, subview.html
    ; // line 4, subview.html
    // line 5, subview.html
    p("\n" + "\n" + "hello "); // line 5, subview.html
    p(s); // line 8, subview.html
    p("\n"); // line 8, subview.html
    new japidviews.more.MyController._tags.taggy(subview.this)
        .render(s); // line 10, subview.html// line 10, subview.html
    p(" "); // line 10, subview.html

    endDoLayout(sourceTemplate);
  }

  @Override
  protected void side() {
    p("my side bar");
    ;
  }

  @Override
  protected void title() {
    p("my title from subview");
    ;
  }
}
Exemple #26
0
//
// NOTE: This file was generated from: japidviews/_tags/picka.html
// Change to this file will be lost next time the template file is compiled.
//
@cn.bran.play.NoEnhance
public class picka extends cn.bran.japid.template.JapidTemplateBase {
  public static final String sourceTemplate = "japidviews/_tags/picka.html";

  {
    putHeader("Content-Type", "text/html; charset=utf-8");
  }

  // - add implicit fields with Play

  final Request request = Request.current();
  final Response response = Response.current();
  final Session session = Session.current();
  final RenderArgs renderArgs = RenderArgs.current();
  final Params params = Params.current();
  final Validation validation = Validation.current();
  final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation);
  final play.Play _play = new play.Play();

  // - end of implicit fields with Play

  public picka() {
    super(null);
  }

  public picka(StringBuilder out) {
    super(out);
  }
  /* based on https://github.com/branaway/Japid/issues/12
   */
  public static final String[] argNames =
      new String[] {
          /* args of the template*/
        "a", "b",
      };
  public static final String[] argTypes =
      new String[] {
          /* arg types of the template*/
        "String", "String",
      };
  public static final Object[] argDefaults =
      new Object[] {
        null, null,
      };
  public static java.lang.reflect.Method renderMethod =
      getRenderMethod(japidviews._tags.picka.class);

  {
    setRenderMethod(renderMethod);
    setArgNames(argNames);
    setArgTypes(argTypes);
    setArgDefaults(argDefaults);
  }
  ////// end of named args stuff

  private String a;
  private String b;

  public cn.bran.japid.template.RenderResult render(
      DoBody body, cn.bran.japid.compiler.NamedArgRuntime... named) {
    Object[] args = buildArgs(named, body);
    return runRenderer(args);
  }

  private DoBody body;

  public static interface DoBody<A> {
    void render(A a);
  }

  public cn.bran.japid.template.RenderResult render(String a, String b, DoBody body) {
    this.body = body;
    this.a = a;
    this.b = b;
    long t = -1;
    super.layout();
    return new cn.bran.japid.template.RenderResultPartial(getHeaders(), getOut(), t, actionRunners);
  }

  @Override
  protected void doLayout() {
    // ------
    ; // line 1
    p("<p>\n" + "some text \n" + "</p>\n" + "<p>\n"); // line 1
    if (body != null) body.render(a + b);
    p("</p>\n" + "<p>\n" + "more text \n" + "</p>\n" + " "); // line 6
  }
}
Exemple #27
0
//
// NOTE: This file was generated from: japidviews/templates/Posts.html
// Change to this file will be lost next time the template file is compiled.
//
public class Posts extends cn.bran.play.JapidTemplateBase {
  public static final String sourceTemplate = "japidviews/templates/Posts.html";

  {
    putHeader("Content-Type", "text/html; charset=utf-8");
    setContentType("text/html; charset=utf-8");
  }

  // - add implicit fields with Play

  final play.mvc.Http.Request request = play.mvc.Http.Request.current();
  final play.mvc.Http.Response response = play.mvc.Http.Response.current();
  final play.mvc.Scope.Session session = play.mvc.Scope.Session.current();
  final play.mvc.Scope.RenderArgs renderArgs = play.mvc.Scope.RenderArgs.current();
  final play.mvc.Scope.Params params = play.mvc.Scope.Params.current();
  final play.data.validation.Validation validation = play.data.validation.Validation.current();
  final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation);
  final play.Play _play = new play.Play();

  // - end of implicit fields with Play

  public Posts() {
    super(null);
  }

  public Posts(StringBuilder out) {
    super(out);
  }
  /* based on https://github.com/branaway/Japid/issues/12
   */
  public static final String[] argNames =
      new String[] {
        /* args of the template*/
        "blogTitle", "allPost",
      };
  public static final String[] argTypes =
      new String[] {
        /* arg types of the template*/
        "String", "List<Post>",
      };
  public static final Object[] argDefaults =
      new Object[] {
        null, null,
      };
  public static java.lang.reflect.Method renderMethod =
      getRenderMethod(japidviews.templates.Posts.class);

  {
    setRenderMethod(renderMethod);
    setArgNames(argNames);
    setArgTypes(argTypes);
    setArgDefaults(argDefaults);
    setSourceTemplate(sourceTemplate);
  }
  ////// end of named args stuff

  private String blogTitle; // line 2
  private List<Post> allPost; // line 2

  public cn.bran.japid.template.RenderResult render(String blogTitle, List<Post> allPost) {
    this.blogTitle = blogTitle;
    this.allPost = allPost;
    long t = -1;
    try {
      super.layout();
    } catch (RuntimeException e) {
      super.handleException(e);
    } // line 2
    return new cn.bran.japid.template.RenderResultPartial(
        getHeaders(), getOut(), t, actionRunners, sourceTemplate);
  }

  @Override
  protected void doLayout() {
    beginDoLayout(sourceTemplate);
    // ------
    ; // line 1

    for (Post post : allPost) { // line 4
      p("	- title: "); // line 4
      p(post.title); // line 5
      p("\n" + "	- date: "); // line 5
      p(post.postedAt); // line 6
      p("\n" + "	- author "); // line 6
      p(post.author.name); // line 7
      p(" "); // line 7
      p(post.author.gender); // line 7
      p("\n" + "	the real title: 你好\n"); // line 7
    } // line 9
    p("\n"); // line 9

    endDoLayout(sourceTemplate);
  }
}
Exemple #28
0
  public static ActionDefinition reverse(String action, Map<String, Object> args) {

    String encoding =
        Http.Response.current() == null
            ? Play.defaultWebEncoding
            : Http.Response.current().encoding;

    if (action.startsWith("controllers.")) {
      action = action.substring(12);
    }
    Map<String, Object> argsbackup = new HashMap<String, Object>(args);
    // Add routeArgs
    if (Scope.RouteArgs.current() != null) {
      for (String key : Scope.RouteArgs.current().data.keySet()) {
        if (!args.containsKey(key)) {
          args.put(key, Scope.RouteArgs.current().data.get(key));
        }
      }
    }
    for (Route route : routes) {
      if (route.actionPattern != null) {
        Matcher matcher = route.actionPattern.matcher(action);
        if (matcher.matches()) {
          for (String group : route.actionArgs) {
            String v = matcher.group(group);
            if (v == null) {
              continue;
            }
            args.put(group, v.toLowerCase());
          }
          List<String> inPathArgs = new ArrayList<String>(16);
          boolean allRequiredArgsAreHere = true;
          // les noms de parametres matchent ils ?
          for (Route.Arg arg : route.args) {
            inPathArgs.add(arg.name);
            Object value = args.get(arg.name);
            if (value == null) {
              // This is a hack for reverting on hostname that are a regex expression.
              // See [#344] for more into. This is not optimal and should retough. However,
              // it allows us to do things like {(.*}}.domain.com
              String host = route.host.replaceAll("\\{", "").replaceAll("\\}", "");
              if (host.equals(arg.name) || host.matches(arg.name)) {
                args.remove(arg.name);
                route.host = Http.Request.current() == null ? "" : Http.Request.current().domain;
                break;
              } else {
                allRequiredArgsAreHere = false;
                break;
              }
            } else {
              if (value instanceof List<?>) {
                @SuppressWarnings("unchecked")
                List<Object> l = (List<Object>) value;
                value = l.get(0);
              }
              if (!value.toString().startsWith(":") && !arg.constraint.matches(value.toString())) {
                allRequiredArgsAreHere = false;
                break;
              }
            }
          }
          // les parametres codes en dur dans la route matchent-ils ?
          for (String staticKey : route.staticArgs.keySet()) {
            if (staticKey.equals("format")) {
              if (!(Http.Request.current() == null ? "" : Http.Request.current().format)
                  .equals(route.staticArgs.get("format"))) {
                allRequiredArgsAreHere = false;
                break;
              }
              continue; // format is a special key
            }
            if (!args.containsKey(staticKey)
                || (args.get(staticKey) == null)
                || !args.get(staticKey).toString().equals(route.staticArgs.get(staticKey))) {
              allRequiredArgsAreHere = false;
              break;
            }
          }
          if (allRequiredArgsAreHere) {
            StringBuilder queryString = new StringBuilder();
            String path = route.path;
            String host = route.host;
            if (path.endsWith("/?")) {
              path = path.substring(0, path.length() - 2);
            }
            for (Map.Entry<String, Object> entry : args.entrySet()) {
              String key = entry.getKey();
              Object value = entry.getValue();
              if (inPathArgs.contains(key) && value != null) {
                if (List.class.isAssignableFrom(value.getClass())) {
                  @SuppressWarnings("unchecked")
                  List<Object> vals = (List<Object>) value;
                  path =
                      path.replaceAll("\\{(<[^>]+>)?" + key + "\\}", vals.get(0).toString())
                          .replace("$", "\\$");
                } else {
                  path =
                      path.replaceAll(
                          "\\{(<[^>]+>)?" + key + "\\}",
                          value
                              .toString()
                              .replace("$", "\\$")
                              .replace("%3A", ":")
                              .replace("%40", "@"));
                  host =
                      host.replaceAll(
                          "\\{(<[^>]+>)?" + key + "\\}",
                          value
                              .toString()
                              .replace("$", "\\$")
                              .replace("%3A", ":")
                              .replace("%40", "@"));
                }
              } else if (route.staticArgs.containsKey(key)) {
                // Do nothing -> The key is static
              } else if (Scope.RouteArgs.current() != null
                  && Scope.RouteArgs.current().data.containsKey(key)) {
                // Do nothing -> The key is provided in RouteArgs and not used (see #447)
              } else if (value != null) {
                if (List.class.isAssignableFrom(value.getClass())) {
                  @SuppressWarnings("unchecked")
                  List<Object> vals = (List<Object>) value;
                  for (Object object : vals) {
                    try {
                      queryString.append(URLEncoder.encode(key, encoding));
                      queryString.append("=");
                      if (object.toString().startsWith(":")) {
                        queryString.append(object.toString());
                      } else {
                        queryString.append(URLEncoder.encode(object.toString() + "", encoding));
                      }
                      queryString.append("&");
                    } catch (UnsupportedEncodingException ex) {
                    }
                  }
                } else if (value.getClass().equals(Default.class)) {
                  // Skip defaults in queryString
                } else {
                  try {
                    queryString.append(URLEncoder.encode(key, encoding));
                    queryString.append("=");
                    if (value.toString().startsWith(":")) {
                      queryString.append(value.toString());
                    } else {
                      queryString.append(URLEncoder.encode(value.toString() + "", encoding));
                    }
                    queryString.append("&");
                  } catch (UnsupportedEncodingException ex) {
                  }
                }
              }
            }
            String qs = queryString.toString();
            if (qs.endsWith("&")) {
              qs = qs.substring(0, qs.length() - 1);
            }
            ActionDefinition actionDefinition = new ActionDefinition();
            actionDefinition.url = qs.length() == 0 ? path : path + "?" + qs;
            actionDefinition.method =
                route.method == null || route.method.equals("*")
                    ? "GET"
                    : route.method.toUpperCase();
            actionDefinition.star = "*".equals(route.method);
            actionDefinition.action = action;
            actionDefinition.args = argsbackup;
            actionDefinition.host = host;
            return actionDefinition;
          }
        }
      }
    }
    throw new NoRouteFoundException(action, args);
  }
Exemple #29
0
//
// NOTE: This file was generated from: japidviews/templates/EachCall.html
// Change to this file will be lost next time the template file is compiled.
//
@cn.bran.play.NoEnhance
public class EachCall extends cn.bran.play.JapidTemplateBase {
  public static final String sourceTemplate = "japidviews/templates/EachCall.html";

  {
    putHeader("Content-Type", "text/html; charset=utf-8");
    setContentType("text/html; charset=utf-8");
  }

  // - add implicit fields with Play

  final Request request = Request.current();
  final Response response = Response.current();
  final Session session = Session.current();
  final RenderArgs renderArgs = RenderArgs.current();
  final Params params = Params.current();
  final Validation validation = Validation.current();
  final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation);
  final play.Play _play = new play.Play();

  // - end of implicit fields with Play

  public EachCall() {
    super(null);
  }

  public EachCall(StringBuilder out) {
    super(out);
  }
  /* based on https://github.com/branaway/Japid/issues/12
   */
  public static final String[] argNames =
      new String[] {
          /* args of the template*/
        "posts",
      };
  public static final String[] argTypes =
      new String[] {
          /* arg types of the template*/
        "List<String>",
      };
  public static final Object[] argDefaults =
      new Object[] {
        null,
      };
  public static java.lang.reflect.Method renderMethod =
      getRenderMethod(japidviews.templates.EachCall.class);

  {
    setRenderMethod(renderMethod);
    setArgNames(argNames);
    setArgTypes(argTypes);
    setArgDefaults(argDefaults);
    setSourceTemplate(sourceTemplate);
  }
  ////// end of named args stuff

  private List<String> posts; // line 1

  public cn.bran.japid.template.RenderResult render(List<String> posts) {
    this.posts = posts;
    long t = -1;
    try {
      super.layout();
    } catch (RuntimeException e) {
      super.handleException(e);
    } // line 1
    return new cn.bran.japid.template.RenderResultPartial(
        getHeaders(), getOut(), t, actionRunners, sourceTemplate);
  }

  @Override
  protected void doLayout() {
    beginDoLayout(sourceTemplate);
    // ------
    ; // line 1
    p(
        "\n"
            + "<p>\n"
            + "The \"each/Each\" command is a for loop on steroid, with lots of loop information. \n"
            + "</p>\n"
            + "\n"
            + "<p> \n"
            + "The instance variable is defined after the | line, the same way as any tag render-back\n"
            + "</p>\n"
            + "\n"); // line 1
    final Each _Each0 = new Each(getOut());
    _Each0.setOut(getOut());
    _Each0.render( // line 11
        posts,
        new Each.DoBody<String>() { // line 11
          public void render(
              final String p,
              final int _size,
              final int _index,
              final boolean _isOdd,
              final String _parity,
              final boolean _isFirst,
              final boolean _isLast) { // line 11
            // line 11
            p("    <p>index: "); // line 11
            p(_index); // line 12
            p(", parity: "); // line 12
            p(_parity); // line 12
            p(", is odd? "); // line 12
            p(_isOdd); // line 12
            p(", is first? "); // line 12
            p(_isFirst); // line 12
            p(", is last? "); // line 12
            p(_isLast); // line 12
            p(", total size: "); // line 12
            p(_size); // line 12
            p(" </p>\n" + "    call a tag:  "); // line 12
            final SampleTag _SampleTag1 = new SampleTag(getOut());
            _SampleTag1.setActionRunners(getActionRunners()).setOut(getOut());
            _SampleTag1.render(p); // line 13// line 13
          }

          StringBuilder oriBuffer;

          @Override
          public void setBuffer(StringBuilder sb) {
            oriBuffer = getOut();
            setOut(sb);
          }

          @Override
          public void resetBuffer() {
            setOut(oriBuffer);
          }
        }); // line 11
    p("\n"); // line 14
    final SampleTag _SampleTag2 = new SampleTag(getOut());
    _SampleTag2.setActionRunners(getActionRunners()).setOut(getOut());
    _SampleTag2.render("end"); // line 16// line 16
    p(
        "\n"
            + "<p> now we have an enhanced for loop (the \"open for loop\") that also makes all the loop properties available</p>\n"
            + "\n"); // line 16
    int k = 1; // line 20
    final Each _Each3 = new Each(getOut());
    _Each3.setOut(getOut());
    _Each3.render( // line 21
        posts,
        new Each.DoBody<String>() { // line 21
          public void render(
              final String p,
              final int _size,
              final int _index,
              final boolean _isOdd,
              final String _parity,
              final boolean _isFirst,
              final boolean _isLast) { // line 21
            // line 21
            p("    <p>index: "); // line 21
            p(_index); // line 22
            p(", parity: "); // line 22
            p(_parity); // line 22
            p(", is odd? "); // line 22
            p(_isOdd); // line 22
            p(", is first? "); // line 22
            p(_isFirst); // line 22
            p(", is last? "); // line 22
            p(_isLast); // line 22
            p(", total size: "); // line 22
            p(_size); // line 22
            p(" </p>\n" + "    call a tag:  "); // line 22
            final SampleTag _SampleTag4 = new SampleTag(getOut());
            _SampleTag4.setActionRunners(getActionRunners()).setOut(getOut());
            _SampleTag4.render(p); // line 23// line 23
          }

          StringBuilder oriBuffer;

          @Override
          public void setBuffer(StringBuilder sb) {
            oriBuffer = getOut();
            setOut(sb);
          }

          @Override
          public void resetBuffer() {
            setOut(oriBuffer);
          }
        }); // line 21
    p("\n" + "\n"); // line 24
    int[] ints = {1, 2, 3}; // line 27
    final Each _Each5 = new Each(getOut());
    _Each5.setOut(getOut());
    _Each5.render( // line 28
        ints,
        new Each.DoBody<Integer>() { // line 28
          public void render(
              final Integer i,
              final int _size,
              final int _index,
              final boolean _isOdd,
              final String _parity,
              final boolean _isFirst,
              final boolean _isLast) { // line 28
            // line 28
            p("    --> "); // line 28
            p(escape(i)); // line 29
            p("\n"); // line 29
          }

          StringBuilder oriBuffer;

          @Override
          public void setBuffer(StringBuilder sb) {
            oriBuffer = getOut();
            setOut(sb);
          }

          @Override
          public void resetBuffer() {
            setOut(oriBuffer);
          }
        }); // line 28
    ; // line 30

    endDoLayout(sourceTemplate);
  }
}
Exemple #30
0
 public void serve500(Exception e, HttpServletRequest request, HttpServletResponse response) {
   try {
     Map<String, Object> binding = new HashMap<String, Object>();
     if (!(e instanceof PlayException)) {
       e = new play.exceptions.UnexpectedException(e);
     }
     // Flush some cookies
     try {
       Map<String, Http.Cookie> cookies = Response.current().cookies;
       for (Http.Cookie cookie : cookies.values()) {
         if (cookie.sendOnError) {
           Cookie c = new Cookie(cookie.name, cookie.value);
           c.setSecure(cookie.secure);
           c.setPath(cookie.path);
           if (cookie.domain != null) {
             c.setDomain(cookie.domain);
           }
           response.addCookie(c);
         }
       }
     } catch (Exception exx) {
       // humm ?
     }
     binding.put("exception", e);
     binding.put("session", Scope.Session.current());
     binding.put("request", Http.Request.current());
     binding.put("flash", Scope.Flash.current());
     binding.put("params", Scope.Params.current());
     binding.put("play", new Play());
     try {
       binding.put("errors", Validation.errors());
     } catch (Exception ex) {
       //
     }
     response.setStatus(500);
     String format = "html";
     if (Request.current() != null) {
       format = Request.current().format;
     }
     // Do we have an ajax request? If we have then we want to display some text even if it is html
     // that is requested
     if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))
         && (format == null || format.equals("html"))) {
       format = "txt";
     }
     if (format == null) {
       format = "txt";
     }
     response.setContentType(MimeTypes.getContentType("500." + format, "text/plain"));
     try {
       String errorHtml = TemplateLoader.load("errors/500." + format).render(binding);
       response.getOutputStream().write(errorHtml.getBytes(Response.current().encoding));
       Logger.error(e, "Internal Server Error (500)");
     } catch (Throwable ex) {
       Logger.error(e, "Internal Server Error (500)");
       Logger.error(ex, "Error during the 500 response generation");
       throw ex;
     }
   } catch (Throwable exxx) {
     if (exxx instanceof RuntimeException) {
       throw (RuntimeException) exxx;
     }
     throw new RuntimeException(exxx);
   }
 }