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(); } }
@Before public void setUp() { Play.configuration.clear(); Http.Request.current.set(request = newHttpRequest()); Http.Response.current.set(response = new Http.Response()); Scope.Session.current.set(new Scope.Session()); Scope.RenderArgs.current.set(new Scope.RenderArgs()); request.path = "/"; Play.langs.add("en"); Play.langs.add("ru"); Play.mode = DEV; Router.routes.clear(); plugin = new WebContentPlugin(); pages = asList(forPath("/en/marketing/"), forPath("/ru/marketing/")); resetWebCacheSetting(); }
public static void reviewModule(Module module, ModuleVersion version) { List<String> emails = getEmails(); configureEmailSettings(emails, SUBJECT_REVIEW_CODE); String baseUrl = getBaseUrl(); String appName = Config.getApplicationName(); Scope.RenderArgs renderArgs = Scope.RenderArgs.current(); send(getTemplatePath("recheckCode", Lang.get()), renderArgs, appName, baseUrl, module, version); }
public static void complainModule(Module module, Inappropriate inappropriate) { String emails = module.getAuthor().getEmail(); String actualLang = Lang.get(); Lang.set(module.getAuthor().getPreferredLang()); configureEmailSettings(emails, SUBJECT_COMPLAIN_MODULE); String baseUrl = getBaseUrl(); String appName = Config.getApplicationName(); Scope.RenderArgs renderArgs = Scope.RenderArgs.current(); send(getTemplatePath("complainModule", module.getAuthor().getPreferredLang()), renderArgs, appName, baseUrl, module, inappropriate); Lang.set(actualLang); }
public static void notifyComplainModuleAdmin(Module module, Inappropriate inappropriate) { List<String> emails = getEmails(); configureEmailSettings(emails, SUBJECT_NOTIFY_COMPLAIN_MODULE_ADMIN); String baseUrl = getBaseUrl(); String appName = Config.getApplicationName(); Scope.RenderArgs renderArgs = Scope.RenderArgs.current(); send(getTemplatePath("notifyComplainModuleAdmin", Lang.get()), renderArgs, appName, baseUrl, module, inappropriate); }
public void serve404(GrizzlyRequest request, GrizzlyResponse response, NotFound e) { Logger.warn("404 -> %s %s (%s)", request.getMethod(), request.getRequestURI(), e.getMessage()); response.setStatus(404); response.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; response.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(request.getHeader("X-Requested-With")) && (format == null || format.equals("html"))) { format = "txt"; } if (format == null) { format = "txt"; } response.setContentType(MimeTypes.getContentType("404." + format, "text/plain")); String errorHtml = TemplateLoader.load("errors/404." + format).render(binding); try { response.getOutputStream().write(errorHtml.getBytes("utf-8")); } catch (Exception fex) { Logger.error(fex, "(utf-8 ?)"); } }
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 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 ?)"); } }
@Override public void beforeActionInvocation(Method actionMethod) { if (actionMethod.isAnnotationPresent(SetLangByURL.class)) setLangByURL(); if (cacheEnabled() && actionMethod.isAnnotationPresent(CacheFor.class)) Http.Response.current().cacheFor("12h"); Scope.RenderArgs.current().put("rootPage", WebPage.rootForLocale()); if ("controllers.Web".equals(actionMethod.getDeclaringClass().getName()) && shouldStartTx()) { JPA.startTx(JPA.DEFAULT, true); Http.Request.current().args.put("webTxStarted", true); } }
public static Map<String, String> filterParams(Scope.Params params, String prefix) { return filterParams(params.all(), prefix); }
private static boolean isLoggedIn() { return Scope.Session.current().contains("username"); }