Refine search
public String render(HttpServletRequest request, HttpServletResponse response, Model model, String tplName, KeyPrefix prefix, String key) { if(!pageCacheEnable) { return tplName; } //取缓存 String html = redisService.get(prefix, key, String.class); if(!StringUtils.isEmpty(html)) { out(response, html); return null; } //手动渲染 WebContext ctx = new WebContext(request,response, request.getServletContext(),request.getLocale(), model.asMap()); html = thymeleafViewResolver.getTemplateEngine().process(tplName, ctx); if(!StringUtils.isEmpty(html)) { redisService.set(prefix, key, html); } out(response, html); return null; }
/** {@inheritDoc} */ public void get(HttpServletRequest req, HttpServletResponse res, WebContext ctx) throws IOException { ctx.setVariable(KEY_TITLE, "Not Found "); }
/** {@inheritDoc} */ public void get(HttpServletRequest req, HttpServletResponse res, WebContext ctx) throws IOException { ctx.setVariable(KEY_TITLE, "Settings"); String operation = req.getParameter(WebConstants.OPERATION); String msgType = "success"; String msg = null; if (Util.hasLength(operation) && TOGGLE_AUDIT.equalsIgnoreCase(operation)) { if (getFf4j().isEnableAudit()) { getFf4j().audit(false); msg = "Audit is now DISABLED"; LOGGER.info("Audit has been disabled"); } else { getFf4j().audit(true); msg = "Audit is now ENABLED"; LOGGER.info("Audit has been enabled"); } } ctx.setVariable(KEY_AUDITENABLE, getFf4j().isEnableAudit()); ctx.setVariable("msgType", msgType); ctx.setVariable("msgInfo", msg); }
String link = ""; String contextPath = "http://" + req.getServerName() + ":" + req.getServerPort(); WebContext ctx = new WebContext(req, res, req.getServletContext(), req.getLocale()); link = contextPath + req.getContextPath() + "/checkToken/" + person.getToken(); ctx.setVariable("tokenLink", link); String template = templateEngine.process("email/email_join", ctx); msg.setSubject("subject", "UTF-8");
WebContext context = new WebContext(requestInvoker.get(), responseInvoker.get(), servletContext, requestInvoker.get().getLocale()); if (viewable.getModel() != null) { context.setVariables((Map) viewable.getModel()); else { context.setVariables(variables); context.setVariable("_csrf", CSRFTokenManager.getTokenForSession(context.getSession())); Enumeration<String> elements = context.getSession().getAttributeNames(); while (elements.hasMoreElements()) { String key = elements.nextElement(); if (key.contains("org.segrada.session.Identity")) { context.setVariable("identity", context.getSession().getAttribute(key)); break; if (templateSelectors == null && "XMLHttpRequest".equals(context.getRequest().getHeader("X-Requested-With")) && !templateName.startsWith("redirect:")) { templateSelectors = new HashSet<>(); templateSelectors.add(".container/div"); context.getResponse().setContentType("text/html; charset=utf-8");
/** * Invoked by dispatcher. * * @param req * current request * @param res * current response * @throws IOException * error occured. */ public void post(HttpServletRequest req, HttpServletResponse res) throws IOException { WebContext ctx = new WebContext(req, res, req.getSession().getServletContext(), req.getLocale()); ctx.setVariable("uptime", getUptime()); ctx.setVariable("version", ff4j.getVersion()); // Adding attribute to response try { post(req, res, ctx); } catch(Throwable t) { ctx.setVariable("msgType", "error"); ctx.setVariable("msgInfo", t.getMessage()); } // Render to view templateEngine.process(getSuccessView(), ctx, res.getWriter()); }
i18n(req, res); WebContext ctx = new WebContext(req, res, req.getSession().getServletContext(), res.getLocale()); ctx.setVariable("uptime", getUptime()); ctx.setVariable("version", ff4j.getVersion()); ctx.setVariable("secure", false); if (getFf4j().getAuthorizationsManager() != null) { ctx.setVariable("secure", true); ctx.setVariable("userName", getFf4j().getAuthorizationsManager().getCurrentUserName()); Set < String > permissions = getFf4j().getAuthorizationsManager().getCurrentUserPermissions(); ctx.setVariable("userPermissions", permissions); get(req, res, ctx); } catch(Throwable t) { ctx.setVariable("msgType", "error"); ctx.setVariable("msgInfo", t.getMessage());
WebContext ctx = new WebContext(handlerContext.getRequest(), handlerContext.getResponse(), handlerContext .getRequest().getServletContext(), handlerContext.getRequest().getLocale()); ctx.setVariables(requestData.getAttributes());
request.getServletContext(), request.getLocale()); ctx.setVariable("info", info);
/** * Build a new IContext (exposing the HttpCallContext, where possible) * * @return */ private IContext makeContext() { final HttpCallContext http = HttpCallContext.peek(); if (http != null) { return new WebContext(http.getRequest(), http.getResponse(), http.getServletContext(), http.getRequest().getLocale()); } else { return new Context(); } } }
@Override public void processView(ViewEngineContext context) throws ViewEngineException { try { HttpServletRequest request = context.getRequest(); HttpServletResponse response = context.getResponse(); WebContext ctx = new WebContext(request, response, servletContext, request.getLocale()); ctx.setVariables(context.getModels()); engine.process(resolveView(context), ctx, response.getWriter()); } catch (IOException e) { throw new ViewEngineException(e); } } }
public void handler(String path, Map<String, Object> data, Writer writer) { Request request = Request.current(); templateEngine.process(path, new WebContext(request.getOriginalRequest(), Response.current().getOriginalResponse(), request.getOriginalRequest().getServletContext(), Locale.getDefault(), data), writer); }
protected IWebContext doCreateWebContextInstance( final ITest test, final HttpServletRequest request, final HttpServletResponse response, final ServletContext servletContext, final Locale locale, final Map<String,Object> variables) { return new WebContext(request, response, servletContext, locale, variables); }
/** * {@inheritDoc} */ @Override protected ProcessorResult doProcessAttribute(Arguments arguments, Element element, String attributeName) { String strippedAttributeName = AttributesUtil.stripPrefix(attributeName, DandelionDialect.DIALECT_PREFIX); BundleAttributeNames assetsAttributeName = (BundleAttributeNames) AttributesUtil.find(strippedAttributeName, BundleAttributeNames.values()); HttpServletRequest request = ArgumentsUtil.getWebContext(arguments).getHttpServletRequest(); AssetRequestContext context = AssetRequestContext.get(request); switch (assetsAttributeName) { case INCLUDES: context.addBundles(element.getAttributeValue(attributeName)); break; case EXCLUDES: context.excludeBundles(element.getAttributeValue(attributeName)); break; } return ProcessorResult.ok(); } }
String msg = null; String msgType = "success"; String operation = req.getParameter(WebConstants.OPERATION); ctx.setVariable("msgType", msgType); ctx.setVariable("msgInfo", msg); get(req, res, ctx); } else if (WebConstants.OP_CREATE_SCHEMA.equalsIgnoreCase(operation)) { getFf4j().createSchema(); msg = "Schema has been created in DB (if required)."; ctx.setVariable("msgType", msgType); ctx.setVariable("msgInfo", msg); get(req, res, ctx); } catch(RuntimeException re) { ctx.setVariable("msgType", ERROR); ctx.setVariable("msgInfo", "Cannot create Schema:" + re.getMessage()); ctx.setVariable(KEY_TITLE, "Home"); ctx.setVariable("today", Calendar.getInstance()); ctx.setVariable("homebean", new HomeBean()); msg = "Cache not present: it cannot be cleared!"; ctx.setVariable("msgType", msgType); ctx.setVariable("msgInfo", msg); get(req, res, ctx);
WebContext ctx = new WebContext(handlerContext.getRequest(), handlerContext.getResponse(), handlerContext .getRequest().getServletContext(), handlerContext.getRequest().getLocale()); ctx.setVariables(requestData.getAttributes());
/** * Build a new IContext (exposing the HttpCallContext, where possible) * * @return */ protected IContext makeContext() { final HttpCallContext http = HttpCallContext.peek(); if (http != null) { return new WebContext(http.getRequest(), http.getResponse(), http.getServletContext(), http.getRequest().getLocale()); } else { return new Context(); } } }
public IWebContext versionSpecificCreateContextInstance( final ApplicationContext applicationContext, final HttpServletRequest request, final HttpServletResponse response, final ServletContext servletContext, final Locale locale, final Map<String, Object> variables) { return new WebContext(request, response, servletContext, locale, variables); }
/** * {@inheritDoc} */ @Override protected ProcessorResult doProcessAttribute(Arguments arguments, Element element, String attributeName) { String strippedAttributeName = AttributesUtil.stripPrefix(attributeName, DandelionDialect.DIALECT_PREFIX); BundleAttributeNames assetsAttributeName = (BundleAttributeNames) AttributesUtil.find(strippedAttributeName, BundleAttributeNames.values()); HttpServletRequest request = ArgumentsUtil.getWebContext(arguments).getHttpServletRequest(); AssetRequestContext context = AssetRequestContext.get(request); switch (assetsAttributeName) { case INCLUDES: context.addBundles(element.getAttributeValue(attributeName)); break; case EXCLUDES: context.excludeBundles(element.getAttributeValue(attributeName)); break; } return ProcessorResult.ok(); } }
/** {@inheritDoc} */ public void get(HttpServletRequest req, HttpServletResponse res, WebContext ctx) throws IOException { String operation = req.getParameter(WebConstants.OPERATION); String propertyName = req.getParameter(WebConstants.FEATID); String msgType = "success"; String msg = null; if (Util.hasLength(operation) && Util.hasLength(propertyName) && getFf4j().getPropertiesStore().existProperty(propertyName)) { if (OP_DELETE_FIXEDVALUE.equalsIgnoreCase(operation)) { String fixedValue = req.getParameter(PARAM_FIXEDVALUE); Property<?> ap = getFf4j().getPropertiesStore().readProperty(propertyName); // Need to convert back to object to use the remove() ap.getFixedValues().remove(ap.fromString(fixedValue)); getFf4j().getPropertiesStore().updateProperty(ap); LOGGER.info("Property '" + propertyName + "' remove fixedValue '" + fixedValue + "'"); } if (OP_ADD_FIXEDVALUE.equalsIgnoreCase(operation)) { String fixedValue = req.getParameter(PARAM_FIXEDVALUE); Property<?> ap = getFf4j().getPropertiesStore().readProperty(propertyName); ap.add2FixedValueFromString(fixedValue); getFf4j().getPropertiesStore().updateProperty(ap); LOGGER.info("Property '" + propertyName + "' add fixedValue '" + fixedValue + "'"); } } ctx.setVariable("msgType", msgType); ctx.setVariable("msgInfo", msg); renderPage(ctx); }