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);
   }
 }
 static void clear() {
   try {
     if (Http.Response.current() != null && Http.Response.current().cookies != null) {
       Cookie cookie = new Cookie();
       cookie.name = Scope.COOKIE_PREFIX + "_ERRORS";
       cookie.value = "";
       cookie.sendOnError = true;
       Http.Response.current().cookies.put(cookie.name, cookie);
     }
   } catch (Exception e) {
     throw new UnexpectedException("Errors serializationProblem", e);
   }
 }
  public static void list(String unitId) {

    Http.Header hd = new Http.Header();

    hd.name = "Access-Control-Allow-Origin";
    hd.values = new ArrayList<String>();
    hd.values.add("*");

    Http.Response.current().headers.put("Access-Control-Allow-Origin", hd);

    if (unitId == null) badRequest();

    Phone p = Phone.find("unitId = ?", unitId).first();

    if (p == null) badRequest();

    List<TripPattern> patterns = TripPattern.find("route.phone = ?", p).fetch();

    Gson gson =
        new GsonBuilder()
            .registerTypeAdapter(TripPattern.class, new TripPatternSerializer())
            .serializeSpecialFloatingPointValues()
            .serializeNulls()
            .create();

    renderJSON(gson.toJson(patterns));
  }
Exemple #4
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 #5
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 #6
0
 /**
  * Generates a html form element linked to a controller action
  *
  * @param args tag attributes
  * @param body tag inner body
  * @param out the output writer
  * @param template enclosing template
  * @param fromLine template line number where the tag is defined
  */
 public static void _form(
     Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
   ActionDefinition actionDef = (ActionDefinition) args.get("arg");
   if (actionDef == null) {
     actionDef = (ActionDefinition) args.get("action");
   }
   String enctype = (String) args.get("enctype");
   if (enctype == null) {
     enctype = "application/x-www-form-urlencoded";
   }
   if (actionDef.star) {
     actionDef.method = "POST"; // prefer POST for form ....
   }
   if (args.containsKey("method")) {
     actionDef.method = args.get("method").toString();
   }
   String name = null;
   if (args.containsKey("name")) {
     name = args.get("name").toString();
   }
   if (!("GET".equals(actionDef.method) || "POST".equals(actionDef.method))) {
     String separator = actionDef.url.indexOf('?') != -1 ? "&" : "?";
     actionDef.url += separator + "x-http-method-override=" + actionDef.method.toUpperCase();
     actionDef.method = "POST";
   }
   String encoding = Http.Response.current().encoding;
   out.print(
       "<form action=\""
           + actionDef.url
           + "\" method=\""
           + actionDef.method.toLowerCase()
           + "\" accept-charset=\""
           + encoding
           + "\" enctype=\""
           + enctype
           + "\" "
           + serialize(args, "name", "action", "method", "accept-charset", "enctype")
           + (name != null ? "name=\"" + name + "\"" : "")
           + ">");
   if (!("GET".equals(actionDef.method))) {
     _authenticityToken(args, body, out, template, fromLine);
   }
   out.println(JavaExtensions.toString(body));
   out.print("</form>");
 }
  public static void pattern(Long patternId) {

    Http.Header hd = new Http.Header();

    hd.name = "Access-Control-Allow-Origin";
    hd.values = new ArrayList<String>();
    hd.values.add("*");

    Http.Response.current().headers.put("Access-Control-Allow-Origin", hd);

    TripPattern pattern = TripPattern.findById(patternId);

    Gson gson =
        new GsonBuilder()
            .registerTypeAdapter(TripPattern.class, new TripPatternShapeSerializer())
            .serializeSpecialFloatingPointValues()
            .serializeNulls()
            .create();

    renderJSON(gson.toJson(pattern));
  }
Exemple #8
0
 public String urlEncode() {
   checkAndParse();
   String encoding = Http.Response.current().encoding;
   StringBuilder ue = new StringBuilder();
   for (String key : data.keySet()) {
     if (key.equals("body")) {
       continue;
     }
     String[] values = data.get(key);
     for (String value : values) {
       try {
         ue.append(URLEncoder.encode(key, encoding))
             .append("=")
             .append(URLEncoder.encode(value, encoding))
             .append("&");
       } catch (Exception e) {
         Logger.error(e, "Error (encoding ?)");
       }
     }
   }
   return ue.toString();
 }
Exemple #9
0
  public static void invoke(Http.Request request, Http.Response response) {
    Monitor monitor = null;

    try {

      resolve(request, response);
      Method actionMethod = request.invokedMethod;

      // 1. Prepare request params
      Scope.Params.current().__mergeWith(request.routeArgs);

      // add parameters from the URI query string
      String encoding = Http.Request.current().encoding;
      Scope.Params.current()
          ._mergeWith(
              UrlEncodedParser.parseQueryString(
                  new ByteArrayInputStream(request.querystring.getBytes(encoding))));

      // 2. Easy debugging ...
      if (Play.mode == Play.Mode.DEV) {
        Class<Controller> cclass = Controller.class;
        cclass.getDeclaredField("params").set(null, Scope.Params.current());
        cclass.getDeclaredField("request").set(null, Http.Request.current());
        cclass.getDeclaredField("response").set(null, Http.Response.current());
        cclass.getDeclaredField("session").set(null, Scope.Session.current());
        cclass.getDeclaredField("flash").set(null, Scope.Flash.current());
        cclass.getDeclaredField("renderArgs").set(null, Scope.RenderArgs.current());
        cclass.getDeclaredField("routeArgs").set(null, Scope.RouteArgs.current());
        cclass.getDeclaredField("validation").set(null, Validation.current());
      }

      ControllerInstrumentation.stopActionCall();
      Play.pluginCollection.beforeActionInvocation(actionMethod);

      // Monitoring
      monitor = MonitorFactory.start(request.action + "()");

      // 3. Invoke the action
      try {
        // @Before
        handleBefores(request);

        // Action

        Result actionResult = null;
        String cacheKey = null;

        // Check the cache (only for GET or HEAD)
        if ((request.method.equals("GET") || request.method.equals("HEAD"))
            && actionMethod.isAnnotationPresent(CacheFor.class)) {
          cacheKey = actionMethod.getAnnotation(CacheFor.class).id();
          if ("".equals(cacheKey)) {
            cacheKey = "urlcache:" + request.url + request.querystring;
          }
          actionResult = (Result) play.cache.Cache.get(cacheKey);
        }

        if (actionResult == null) {
          ControllerInstrumentation.initActionCall();
          try {
            inferResult(invokeControllerMethod(actionMethod));
          } catch (Result result) {
            actionResult = result;
            // Cache it if needed
            if (cacheKey != null) {
              play.cache.Cache.set(
                  cacheKey, actionResult, actionMethod.getAnnotation(CacheFor.class).value());
            }
          } catch (InvocationTargetException ex) {
            // It's a Result ? (expected)
            if (ex.getTargetException() instanceof Result) {
              actionResult = (Result) ex.getTargetException();
              // Cache it if needed
              if (cacheKey != null) {
                play.cache.Cache.set(
                    cacheKey, actionResult, actionMethod.getAnnotation(CacheFor.class).value());
              }

            } else {
              // @Catch
              Object[] args = new Object[] {ex.getTargetException()};
              List<Method> catches =
                  Java.findAllAnnotatedMethods(Controller.getControllerClass(), Catch.class);
              ControllerInstrumentation.stopActionCall();
              for (Method mCatch : catches) {
                Class[] exceptions = mCatch.getAnnotation(Catch.class).value();
                if (exceptions.length == 0) {
                  exceptions = new Class[] {Exception.class};
                }
                for (Class exception : exceptions) {
                  if (exception.isInstance(args[0])) {
                    mCatch.setAccessible(true);
                    inferResult(invokeControllerMethod(mCatch, args));
                    break;
                  }
                }
              }

              throw ex;
            }
          }
        }

        // @After
        handleAfters(request);

        monitor.stop();
        monitor = null;

        // OK, re-throw the original action result
        if (actionResult != null) {
          throw actionResult;
        }

        throw new NoResult();

      } catch (IllegalAccessException ex) {
        throw ex;
      } catch (IllegalArgumentException ex) {
        throw ex;
      } catch (InvocationTargetException ex) {
        // It's a Result ? (expected)
        if (ex.getTargetException() instanceof Result) {
          throw (Result) ex.getTargetException();
        }
        // Re-throw the enclosed exception
        if (ex.getTargetException() instanceof PlayException) {
          throw (PlayException) ex.getTargetException();
        }
        StackTraceElement element =
            PlayException.getInterestingStackTraceElement(ex.getTargetException());
        if (element != null) {
          throw new JavaExecutionException(
              Play.classes.getApplicationClass(element.getClassName()),
              element.getLineNumber(),
              ex.getTargetException());
        }
        throw new JavaExecutionException(Http.Request.current().action, ex);
      }

    } catch (Result result) {

      Play.pluginCollection.onActionInvocationResult(result);

      // OK there is a result to apply
      // Save session & flash scope now

      Scope.Session.current().save();
      Scope.Flash.current().save();

      result.apply(request, response);

      Play.pluginCollection.afterActionInvocation();

      // @Finally
      handleFinallies(request, null);

    } catch (PlayException e) {
      handleFinallies(request, e);
      throw e;
    } catch (Throwable e) {
      handleFinallies(request, e);
      throw new UnexpectedException(e);
    } finally {
      Play.pluginCollection.onActionInvocationFinally();

      if (monitor != null) {
        monitor.stop();
      }
    }
  }
Exemple #10
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 #11
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 #12
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 #13
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);
  }
}
//
// NOTE: This file was generated from: japidviews/templates/invokeInLoop.html
// Change to this file will be lost next time the template file is compiled.
//
@cn.bran.play.NoEnhance
public class invokeInLoop extends cn.bran.play.JapidTemplateBase {
  public static final String sourceTemplate = "japidviews/templates/invokeInLoop.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 invokeInLoop() {
    super(null);
  }

  public invokeInLoop(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<Post>",
      };
  public static final Object[] argDefaults =
      new Object[] {
        null,
      };
  public static java.lang.reflect.Method renderMethod =
      getRenderMethod(japidviews.templates.invokeInLoop.class);

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

  private List<Post> posts; // line 2

  public cn.bran.japid.template.RenderResult render(List<Post> posts) {
    this.posts = posts;
    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
    p("\n"); // line 2
    p("\n" + "\n"); // line 7
    for (int i = 0; i < 3; i++) { // line 9
      final int j = i; // line 10
      p("	"); // line 10
      actionRunners.put(
          getOut().length(),
          new cn.bran.play.CacheablePlayActionRunner("", Application.class, "echo", j) {
            @Override
            public void runPlayAction() throws cn.bran.play.JapidResult {
              Application.echo(j); // line 11
            }
          });
      p("\n"); // line 11
      p("\n"); // line 11
    } // line 12
    p("<p/>\n"); // line 12
    p("\n" + "\n"); // line 14
    for (final Post p : posts) { // line 16
      p("    another notation for invoking actions:  \n" + "    "); // line 16
      actionRunners.put(
          getOut().length(),
          new cn.bran.play.CacheablePlayActionRunner("", Application.class, "echoPost", p) {
            @Override
            public void runPlayAction() throws cn.bran.play.JapidResult {
              Application.echoPost(p); // line 18
            }
          });
      p("\n"); // line 18
    } // line 19
    ; // line 19

    endDoLayout(sourceTemplate);
  }
}
Exemple #15
0
//
// NOTE: This file was generated from: japidviews/templates/Actions.html
// Change to this file will be lost next time the template file is compiled.
//
public class Actions extends cn.bran.play.JapidTemplateBase {
  public static final String sourceTemplate = "japidviews/templates/Actions.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 Actions() {
    super(null);
  }

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

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

  private models.japidsample.Post post; // line 1

  public cn.bran.japid.template.RenderResult render(models.japidsample.Post post) {
    this.post = post;
    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" + "\n" + "<form url=\""); // line 1
    p(lookup("showAll", new Object[] {})); // line 4
    p("\"></form>\n" + "<form url=\""); // line 4
    p(lookup("Clients.showAccounts", post.title, post.title)); // line 5
    p("\"></form>\n" + "<form url=\""); // line 5
    p(lookupAbs("Clients.showAccounts", post.title.substring(1, 2))); // line 6
    p("\"></form>\n" + "<form url='"); // line 6
    p(lookupAbs("Clients.showAccounts", new String[] {"aa", "bb"})); // line 7
    p("'></form>\n" + "<form url=\""); // line 7
    p(lookupStatic("/public/stylesheets/main.css")); // line 8
    p("\"></form>\n"); // line 8

    endDoLayout(sourceTemplate);
  }
}
//
// NOTE: This file was generated from: japidviews/AdminController/flashPurchaseList.html
// Change to this file will be lost next time the template file is compiled.
//
@cn.bran.play.NoEnhance
public class flashPurchaseList extends backStageLayout {
  public static final String sourceTemplate = "japidviews/AdminController/flashPurchaseList.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 flashPurchaseList() {
    super((StringBuilder) null);
    initHeaders();
  }

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

  public flashPurchaseList(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*/
        "announcementList", "currentPage", "totalPage",
      };
  public static final String[] argTypes =
      new String[] {
          /* arg types of the template*/
        "List<Announcements>", "int", "int",
      };
  public static final Object[] argDefaults =
      new Object[] {
        null, null, null,
      };
  public static java.lang.reflect.Method renderMethod =
      getRenderMethod(japidviews.AdminController.flashPurchaseList.class);

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

  private List<Announcements>
      announcementList; // line 3, japidviews/AdminController/flashPurchaseList.html
  private int currentPage; // line 3, japidviews/AdminController/flashPurchaseList.html
  private int totalPage; // line 3, japidviews/AdminController/flashPurchaseList.html

  public cn.bran.japid.template.RenderResult render(
      List<Announcements> announcementList, int currentPage, int totalPage) {
    this.announcementList = announcementList;
    this.currentPage = currentPage;
    this.totalPage = totalPage;
    try {
      super.layout();
    } catch (RuntimeException __e) {
      super.handleException(__e);
    } // line 3, japidviews/AdminController/flashPurchaseList.html
    return getRenderResult();
  }

  public static cn.bran.japid.template.RenderResult apply(
      List<Announcements> announcementList, int currentPage, int totalPage) {
    return new flashPurchaseList().render(announcementList, currentPage, totalPage);
  }

  @Override
  protected void doLayout() {
    beginDoLayout(sourceTemplate);
    ; // line 1, japidviews\AdminController\flashPurchaseList.html
    // line 6, japidviews\AdminController\flashPurchaseList.html
    // line 7, japidviews\AdminController\flashPurchaseList.html
    p(
        "<div class=\"navbar-inner\">\n"
            + "</div>\n"
            + "<div class=\"container\">\n"
            + "	<!-- 左菜单 -->\n"
            + "	"); // line 11, japidviews\AdminController\flashPurchaseList.html
    new leftMenusTag(flashPurchaseList.this)
        .render(); // line 16, japidviews\AdminController\flashPurchaseList.html// line 16,
                   // japidviews\AdminController\flashPurchaseList.html
    p(
        "    	<!-- 主内容 -->\n"
            + "		  <div class=\"content\" id=\"content\">\n"
            + "            <!-- 标题 -->\n"
            + "            <h3 class=\"title add-commodity-title\">活动列表</h3>\n"
            + "			"); // line 16, japidviews\AdminController\flashPurchaseList.html
    p(
        "            <!-- table -->\n"
            + "            <table class=\"table\">\n"
            + "                <tr>\n"
            + "                    <th>活动名称</th>\n"
            + "                    <th>开始时间</th>\n"
            + "                    <th>结束时间</th>\n"
            + "                    <th class=\"handle-w1\">操作</th>\n"
            + "                </tr>\n"
            + "                "); // line 24, japidviews\AdminController\flashPurchaseList.html
    if (!announcementList.isEmpty()) { // line 33, japidviews\AdminController\flashPurchaseList.html
      for (Announcements announcements :
          announcementList) { // line 34, japidviews\AdminController\flashPurchaseList.html
        p(
            "                	<tr>\n"
                + "                    <td>"); // line 34,
                                               // japidviews\AdminController\flashPurchaseList.html
        p(announcements.title); // line 36, japidviews\AdminController\flashPurchaseList.html
        p(
            "</td>\n"
                + "                    <td>"); // line 36,
                                               // japidviews\AdminController\flashPurchaseList.html
        p(announcements.startTime); // line 37, japidviews\AdminController\flashPurchaseList.html
        p(
            "</td>\n"
                + "                    <td>"); // line 37,
                                               // japidviews\AdminController\flashPurchaseList.html
        p(announcements.endTime); // line 38, japidviews\AdminController\flashPurchaseList.html
        p(
            "</td>\n"
                + "                    <td>\n"
                + "                    	<a id=\"preview\" href=\""); // line 38,
                                                                     // japidviews\AdminController\flashPurchaseList.html
        p(
            lookup(
                "AdminController.preview",
                announcements.id)); // line 40, japidviews\AdminController\flashPurchaseList.html
        p(
            "\" class=\"defaultBtn btn-sm btn-green\">预览</a>\n"
                + "                        <a id=\"del\" href=\""); // line 40,
                                                                    // japidviews\AdminController\flashPurchaseList.html
        p(
            lookup(
                "AdminController.deleteFastGood",
                announcements.id)); // line 41, japidviews\AdminController\flashPurchaseList.html
        p(
            "\" class=\"defaultBtn btn-sm btn-red\">删除</a>\n"
                + "                    </td>\n"
                + "                </tr>\n"
                + "                "); // line 41, japidviews\AdminController\flashPurchaseList.html
      } // line 44, japidviews\AdminController\flashPurchaseList.html
    } // line 45, japidviews\AdminController\flashPurchaseList.html
    p(
        "            </table>\n"
            + "            "); // line 45, japidviews\AdminController\flashPurchaseList.html
    new pagination(flashPurchaseList.this)
        .render(
            getUrl(),
            "page",
            currentPage,
            totalPage,
            null); // line 47, japidviews\AdminController\flashPurchaseList.html// line 47,
                   // japidviews\AdminController\flashPurchaseList.html
    // line 48, japidviews\AdminController\flashPurchaseList.html
    p(
        "            <!-- h20 -->\n"
            + "            <div class=\"h20\"></div>\n"
            + "		</div>\n"
            + "\n"
            + "    </div>\n"
            + "</body>\n"
            + "</html>"); // line 50, japidviews\AdminController\flashPurchaseList.html

    endDoLayout(sourceTemplate);
  }

  @Override
  protected void moreJSLink() {
    // line 7, japidviews\AdminController\flashPurchaseList.html
    p(
        "<script>\n"
            + "    main.setSidebarHover(\"index\");\n"
            + "</script>\n"); // line 7, japidviews\AdminController\flashPurchaseList.html
    ;
  }

  @Override
  protected void title() {
    // line 6, japidviews\AdminController\flashPurchaseList.html
    p("后台管理-活动列表"); // line 6, japidviews\AdminController\flashPurchaseList.html
    ;
  }

  public String getUrl() {
    StringBuilder sb = new StringBuilder();
    StringBuilder ori = getOut();
    this.setOut(sb);
    TreeMap<Integer, cn.bran.japid.template.ActionRunner> parentActionRunners = actionRunners;
    actionRunners = new TreeMap<Integer, cn.bran.japid.template.ActionRunner>();
    // line 48, japidviews\AdminController\flashPurchaseList.html
    p("            	"); // line 48, japidviews\AdminController\flashPurchaseList.html
    p(
        lookup(
            "AdminController.flashPurchaseList",
            new Object[] {})); // line 49, japidviews\AdminController\flashPurchaseList.html
    p("            "); // line 49, japidviews\AdminController\flashPurchaseList.html

    this.setOut(ori);
    if (actionRunners.size() > 0) {
      StringBuilder _sb2 = new StringBuilder();
      int segStart = 0;
      for (Map.Entry<Integer, cn.bran.japid.template.ActionRunner> _arEntry :
          actionRunners.entrySet()) {
        int pos = _arEntry.getKey();
        _sb2.append(sb.substring(segStart, pos));
        segStart = pos;
        cn.bran.japid.template.ActionRunner _a_ = _arEntry.getValue();
        _sb2.append(_a_.run().getContent().toString());
      }
      _sb2.append(sb.substring(segStart));
      actionRunners = parentActionRunners;
      return _sb2.toString();
    } else {
      actionRunners = parentActionRunners;
      return sb.toString();
    }
  }
}
Exemple #17
0
//
// NOTE: This file was generated from: japidviews/more/ContentNegotiation/index.xml
// Change to this file will be lost next time the template file is compiled.
//
@cn.bran.play.NoEnhance
public class index_xml extends cn.bran.play.JapidTemplateBase {
  public static final String sourceTemplate = "japidviews/more/ContentNegotiation/index.xml";

  private void initHeaders() {
    putHeader("Content-Type", "text/xml; charset=utf-8");
    setContentType("text/xml; 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 index_xml() {
    super((StringBuilder) null);
    initHeaders();
  }

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

  public index_xml(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*/
      };
  public static final String[] argTypes = new String[] {
        /* arg types of the template*/
      };
  public static final Object[] argDefaults = new Object[] {};
  public static java.lang.reflect.Method renderMethod =
      getRenderMethod(japidviews.more.ContentNegotiation.index_xml.class);

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

  public cn.bran.japid.template.RenderResult render() {
    try {
      super.layout();
    } catch (RuntimeException __e) {
      super.handleException(__e);
    } // line 0, japidviews/more/ContentNegotiation/index.xml
    return getRenderResult();
  }

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

  @Override
  protected void doLayout() {
    beginDoLayout(sourceTemplate);
    p("<format>\n"); // line 1, index.xml
    p(request.format); // line 2, index.xml
    p("\n" + "</format>"); // line 2, index.xml

    endDoLayout(sourceTemplate);
  }
}
Exemple #18
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 #19
0
  /** Start the application. Recall to restart ! */
  public static synchronized void start() {
    try {

      if (started) {
        stop();
      }

      if (standalonePlayServer) {
        // Can only register shutdown-hook if running as standalone server
        if (!shutdownHookEnabled) {
          // registers shutdown hook - Now there's a good chance that we can notify
          // our plugins that we're going down when some calls ctrl+c or just kills our process..
          shutdownHookEnabled = true;
          Runtime.getRuntime()
              .addShutdownHook(
                  new Thread() {
                    public void run() {
                      Play.stop();
                    }
                  });
        }
      }

      if (mode == Mode.DEV) {
        // Need a new classloader
        classloader = new ApplicationClassloader();
        // Put it in the current context for any code that relies on having it there
        Thread.currentThread().setContextClassLoader(classloader);
        // Reload plugins
        pluginCollection.reloadApplicationPlugins();
      }

      // Reload configuration
      readConfiguration();

      // Configure logs
      String logLevel = configuration.getProperty("application.log", "INFO");
      // only override log-level if Logger was not configured manually
      if (!Logger.configuredManually) {
        Logger.setUp(logLevel);
      }
      Logger.recordCaller =
          Boolean.parseBoolean(configuration.getProperty("application.log.recordCaller", "false"));

      // Locales
      langs =
          new ArrayList<String>(
              Arrays.asList(configuration.getProperty("application.langs", "").split(",")));
      if (langs.size() == 1 && langs.get(0).trim().length() == 0) {
        langs = new ArrayList<String>(16);
      }

      // Clean templates
      TemplateLoader.cleanCompiledCache();

      // SecretKey
      secretKey = configuration.getProperty("application.secret", "").trim();
      if (secretKey.length() == 0) {
        Logger.warn("No secret key defined. Sessions will not be encrypted");
      }

      // Default web encoding
      String _defaultWebEncoding = configuration.getProperty("application.web_encoding");
      if (_defaultWebEncoding != null) {
        Logger.info("Using custom default web encoding: " + _defaultWebEncoding);
        defaultWebEncoding = _defaultWebEncoding;
        // Must update current response also, since the request/response triggering
        // this configuration-loading in dev-mode have already been
        // set up with the previous encoding
        if (Http.Response.current() != null) {
          Http.Response.current().encoding = _defaultWebEncoding;
        }
      }

      // Try to load all classes
      Play.classloader.getAllClasses();

      // Routes
      Router.detectChanges(ctxPath);

      // Cache
      Cache.init();

      // Plugins
      try {
        pluginCollection.onApplicationStart();
      } catch (Exception e) {
        if (Play.mode.isProd()) {
          Logger.error(e, "Can't start in PROD mode with errors");
        }
        if (e instanceof RuntimeException) {
          throw (RuntimeException) e;
        }
        throw new UnexpectedException(e);
      }

      if (firstStart) {
        Logger.info(
            "Application '%s' is now started !", configuration.getProperty("application.name", ""));
        firstStart = false;
      }

      // We made it
      started = true;
      startedAt = System.currentTimeMillis();

      // Plugins
      pluginCollection.afterApplicationStart();

    } catch (PlayException e) {
      started = false;
      try {
        Cache.stop();
      } catch (Exception ignored) {
      }
      throw e;
    } catch (Exception e) {
      started = false;
      try {
        Cache.stop();
      } catch (Exception ignored) {
      }
      throw new UnexpectedException(e);
    }
  }