org.thymeleaf.context.IWebContext Java Examples
The following examples show how to use
org.thymeleaf.context.IWebContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChallengeAttrProcessor.java From webauthn4j-spring-security with Apache License 2.0 | 5 votes |
private Challenge getChallenge(ITemplateContext context) { ApplicationContext applicationContext = SpringContextUtils.getApplicationContext(context); IWebContext webContext = (IWebContext) context; HttpServletRequest httpServletRequest = webContext.getRequest(); ChallengeRepository challengeRepository = applicationContext.getBean(ChallengeRepository.class); Challenge challenge = challengeRepository.loadChallenge(httpServletRequest); if (challenge == null) { challenge = challengeRepository.generateChallenge(); challengeRepository.saveChallenge(challenge, httpServletRequest); } return challenge; }
Example #2
Source File: ViewEngineProducer.java From portals-pluto with Apache License 2.0 | 5 votes |
@PortletRequestScoped @Produces public ViewEngine getTimeleafViewEngine(TemplateEngineSupplier templateEngineSupplier, IWebContext webContext) { return new ThymeleafViewEngine(templateEngineSupplier.get(), webContext, viewEngineContext -> { MimeResponse mimeResponse = viewEngineContext.getResponse(MimeResponse.class); try { return mimeResponse.getWriter(); } catch (IOException e) { throw new ViewEngineException(e); } }); }
Example #3
Source File: WebContextProducer.java From portals-pluto with Apache License 2.0 | 5 votes |
@PortletRequestScoped @Produces public IWebContext getWebContext(BeanManager beanManager, VariableValidator variableValidator, MvcContext mvcContext, Models models, PortletRequest portletRequest, MimeResponse mimeResponse, ServletContext servletContext) { return new CDIPortletWebContext(beanManager, variableValidator, models, (String) portletRequest.getAttribute(PortletRequest.LIFECYCLE_PHASE), new HttpServletRequestAdapter(portletRequest), new HttpServletResponseAdapter(mimeResponse), servletContext, mvcContext.getLocale()); }
Example #4
Source File: ViewEngineProducer.java From portals-pluto with Apache License 2.0 | 5 votes |
@Bean @Scope(proxyMode = ScopedProxyMode.INTERFACES, value = "portletRequest") public ViewEngine getViewEngine(TemplateEngineSupplier templateEngineSupplier, IWebContext webContext) { return new ThymeleafViewEngine(templateEngineSupplier.get(), webContext, viewEngineContext -> { MimeResponse mimeResponse = viewEngineContext.getResponse(MimeResponse.class); try { return mimeResponse.getWriter(); } catch (IOException e) { throw new ViewEngineException(e); } }); }
Example #5
Source File: WebContextProducer.java From portals-pluto with Apache License 2.0 | 5 votes |
@Scope(proxyMode = ScopedProxyMode.INTERFACES, value = "portletRequest") @Bean public IWebContext getWebContext(MvcContext mvcContext, Models models, PortletRequest portletRequest, MimeResponse mimeResponse, ServletContext servletContext) { return new SpringPortletWebContext(applicationContext, models, (String) portletRequest.getAttribute(PortletRequest.LIFECYCLE_PHASE), new HttpServletRequestAdapter(portletRequest), new HttpServletResponseAdapter(mimeResponse), servletContext, mvcContext.getLocale(), mvcContext.getConfig()); }
Example #6
Source File: PageUtils.java From thymeleaf-spring-data-dialect with Apache License 2.0 | 4 votes |
public static Page<?> findPage(final ITemplateContext context) { // 1. Get Page object from local variables (defined with sd:page-object) // 2. Search Page using ${page} expression // 3. Search Page object as request attribute final Object pageFromLocalVariable = context.getVariable(Keys.PAGE_VARIABLE_KEY); if (isPageInstance(pageFromLocalVariable)) { return (Page<?>) pageFromLocalVariable; } // Check if not null and Page instance available with ${page} expression final IEngineConfiguration configuration = context.getConfiguration(); final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration); final IStandardExpression expression = parser.parseExpression(context, Keys.PAGE_EXPRESSION); final Object page = expression.execute(context); if (isPageInstance(page)) { return (Page<?>) page; } // Search for Page object, and only one instance, as request attribute if (context instanceof IWebContext) { HttpServletRequest request = ((IWebContext) context).getRequest(); Enumeration<String> attrNames = request.getAttributeNames(); Page<?> pageOnRequest = null; while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); Object attr = request.getAttribute(attrName); if (isPageInstance(attr)) { if (pageOnRequest != null) { throw new InvalidObjectParameterException("More than one Page object found on request!"); } pageOnRequest = (Page<?>) attr; } } if (pageOnRequest != null) { return pageOnRequest; } } throw new InvalidObjectParameterException("Invalid or not present Page object found on request!"); }
Example #7
Source File: PageUtils.java From thymeleaf-spring-data-dialect with Apache License 2.0 | 4 votes |
private static String buildBaseUrl(final ITemplateContext context, Collection<String> excludeParams) { // URL defined with pagination-url tag final String url = (String) context.getVariable(Keys.PAGINATION_URL_KEY); if (url == null && context instanceof IWebContext) { // Creates url from actual request URI and parameters final StringBuilder builder = new StringBuilder(); final IWebContext webContext = (IWebContext) context; final HttpServletRequest request = webContext.getRequest(); // URL base path from request builder.append(request.getRequestURI()); Map<String, String[]> params = request.getParameterMap(); Set<Entry<String, String[]>> entries = params.entrySet(); boolean firstParam = true; for (Entry<String, String[]> param : entries) { // Append params not excluded to basePath String name = param.getKey(); if (!excludeParams.contains(name)) { if (firstParam) { builder.append(Q_MARK); firstParam = false; } else { builder.append(AND); } // Iterate over all values to create multiple values per // parameter String[] values = param.getValue(); Collection<String> paramValues = Arrays.asList(values); Iterator<String> it = paramValues.iterator(); while (it.hasNext()) { String value = it.next(); builder.append(name).append(EQ).append(value); if (it.hasNext()) { builder.append(AND); } } } } // Escape to HTML content return HtmlEscape.escapeHtml4Xml(builder.toString()); } return url == null ? EMPTY : url; }
Example #8
Source File: Devices.java From wallride with Apache License 2.0 | 4 votes |
private Device resolveDevice() { return deviceResolver.resolveDevice(((IWebContext) context).getRequest()); }
Example #9
Source File: ThymeleafViewEngine.java From portals-pluto with Apache License 2.0 | 4 votes |
public ThymeleafViewEngine(TemplateEngine templateEngine, IWebContext webContext, WriterSupplier writerSupplier) { this.templateEngine = templateEngine; this.webContext = webContext; this.writerSupplier = writerSupplier; }