org.thymeleaf.context.ITemplateContext Java Examples
The following examples show how to use
org.thymeleaf.context.ITemplateContext.
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: PageUtils.java From thymeleaf-spring-data-dialect with Apache License 2.0 | 6 votes |
/** * Creates an url to sort data by fieldName * * @param context execution context * @param fieldName field name to sort * @param forcedDir optional, if specified then only this sort direction will be allowed * @return sort URL */ public static String createSortUrl(final ITemplateContext context, final String fieldName, final Direction forcedDir) { // Params can be prefixed to manage multiple pagination on the same page final String prefix = getParamPrefix(context); final Collection<String> excludedParams = Arrays .asList(new String[] { prefix.concat(SORT), prefix.concat(PAGE) }); final String baseUrl = buildBaseUrl(context, excludedParams); final StringBuilder sortParam = new StringBuilder(); final Page<?> page = findPage(context); final Sort sort = page.getSort(); final boolean hasPreviousOrder = sort != null && sort.getOrderFor(fieldName) != null; if (forcedDir != null) { sortParam.append(fieldName).append(COMMA).append(forcedDir.toString().toLowerCase()); } else if (hasPreviousOrder) { // Sort parameters exists for this field, modify direction Order previousOrder = sort.getOrderFor(fieldName); Direction dir = previousOrder.isAscending() ? Direction.DESC : Direction.ASC; sortParam.append(fieldName).append(COMMA).append(dir.toString().toLowerCase()); } else { sortParam.append(fieldName); } return buildUrl(baseUrl, context).append(SORT).append(EQ).append(sortParam).toString(); }
Example #2
Source File: DictShowProcessor.java From FEBS-Security with Apache License 2.0 | 6 votes |
@Override protected void doProcess(ITemplateContext context, IProcessableElementTag tag, IElementTagStructureHandler structureHandler) { String fieldName = tag.getAttribute(FIELD_NAME).getValue(); String keyy = tag.getAttribute(KEYY).getValue(); final IEngineConfiguration configuration = context.getConfiguration(); final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration); final IStandardExpression expression = parser.parseExpression(context, keyy); final String realvalue = String.valueOf(expression.execute(context)); ApplicationContext appCtx = SpringContextUtils.getApplicationContext(context); DictService dictService = appCtx.getBean(DictService.class); Dict dict = dictService.findDictByFieldNameAndKeyy(fieldName, realvalue); if (log.isDebugEnabled()) { log.debug("dict== fieldName:{}, keyy:{}, realvalue:{}", fieldName, keyy, realvalue); } String label = ""; if (dict != null) { label = dict.getValuee(); } structureHandler.replaceWith(label, false); }
Example #3
Source File: EnabledImageTagProcessor.java From konker-platform with Apache License 2.0 | 6 votes |
protected void doProcess(final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final IElementTagStructureHandler structureHandler) { IStandardExpressionParser expressionParser = StandardExpressions .getExpressionParser(context.getConfiguration()); IStandardExpression expression = expressionParser.parseExpression(context, attributeValue); Boolean enabled = (Boolean) expression.execute(context); if (enabled) { expression = expressionParser.parseExpression(context, "@{/resources/konker/images/enabled.svg}"); } else { expression = expressionParser.parseExpression(context, "@{/resources/konker/images/disabled.svg}"); } structureHandler.setAttribute("src", (String) expression.execute(context)); structureHandler.setAttribute("class", (String) "enabled-img"); }
Example #4
Source File: AbstractPagerDecorator.java From thymeleaf-spring-data-dialect with Apache License 2.0 | 6 votes |
public final String decorate(final IProcessableElementTag tag, final ITemplateContext context) { String bundleName = getClass().getSimpleName(); Locale locale = context.getLocale(); Page<?> page = PageUtils.findPage(context); // previous String previousPage = PageUtils.createPageUrl(context, page.getNumber() - 1); String prevKey = PageUtils.isFirstPage(page) ? "pager.previous" : "pager.previous.link"; String prev = Messages.getMessage(bundleName, prevKey, locale, previousPage); // next String nextPage = PageUtils.createPageUrl(context, page.getNumber() + 1); String nextKey = page.isLast() ? "pager.next" : "pager.next.link"; String next = Messages.getMessage(bundleName, nextKey, locale, nextPage); String content = Strings.concat(prev, next); return Messages.getMessage(bundleName, "pager", locale, content); }
Example #5
Source File: PaginationSortBaseAttrProcessor.java From thymeleaf-spring-data-dialect with Apache License 2.0 | 6 votes |
@Override protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler) { String attrValue = String.valueOf(Expressions.evaluate(context, attributeValue)).trim(); Page<?> page = PageUtils.findPage(context); String url = PageUtils.createSortUrl(context, attrValue, getForcedDirection()); // Append class to the element if sorted by this field Sort sort = page.getSort(); boolean isSorted = sort != null && sort.getOrderFor(attrValue) != null; String clas = isSorted ? SORTED_PREFIX.concat(sort.getOrderFor(attrValue).getDirection().toString().toLowerCase()) : EMPTY; structureHandler.setAttribute(HREF, url); String currentClass = tag.getAttributeValue(CLASS); structureHandler.setAttribute(CLASS, Strings.concat(currentClass, BLANK, clas)); }
Example #6
Source File: PageObjectAttrProcessor.java From thymeleaf-spring-data-dialect with Apache License 2.0 | 6 votes |
@Override protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler) { if (context instanceof WebEngineContext) { Object page = Expressions.evaluate(context, attributeValue); if (!(page instanceof Page<?>)) { throw new InvalidObjectParameterException( "Parameter " + attributeValue + " is not an Page<?> instance!"); } ((WebEngineContext) context).setVariable(Keys.PAGE_VARIABLE_KEY, page); } }
Example #7
Source File: PageSizeSelectorAttrProcessor.java From thymeleaf-spring-data-dialect with Apache License 2.0 | 6 votes |
/** * Create select html content, list of options * * @param selectorStyle * html selector style * @param context * execution context * @return available page size options as html */ private String composeSelectorOptions(String selectorStyle, ITemplateContext context) { Page<?> page = PageUtils.findPage(context); int currentPageSize = page.getSize(); Locale locale = context.getLocale(); StringBuilder sb = new StringBuilder(); for (int value : selectorValues) { String url = PageUtils.createPageSizeUrl(context, value); boolean isSelectedValue = value == currentPageSize; String messageKey = getMessageKey(selectorStyle).concat(isSelectedValue ? ".option.selected" : ".option"); String option = Messages.getMessage(BUNDLE_NAME, messageKey, locale, value, url); sb.append(option); } return sb.toString(); }
Example #8
Source File: PrincipalAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 6 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler iElementTagStructureHandler) { final String type = iProcessableElementTag.getAttributeValue("type"); final String property = iProcessableElementTag.getAttributeValue("property"); final String text = ShiroFacade.getPrincipalText(type, property); final String elementCompleteName = iProcessableElementTag.getElementCompleteName(); final IModelFactory modelFactory = iTemplateContext.getModelFactory(); final IModel model = modelFactory.createModel(); model.add(modelFactory.createOpenElementTag(elementCompleteName)); model.add(modelFactory.createText(HtmlEscape.escapeHtml5(text))); model.add(modelFactory.createCloseElementTag(elementCompleteName)); iElementTagStructureHandler.replaceWith(model, false); }
Example #9
Source File: PaginationSummaryAttrProcessor.java From thymeleaf-spring-data-dialect with Apache License 2.0 | 6 votes |
@Override protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler) { // Compose message with parameters: // {0} first reg. position // {1} latest page reg. position // {2} total elements // pagination.summary=Showing {0} to {1} of {2} entries Locale locale = context.getLocale(); Page<?> page = PageUtils.findPage(context); int firstItem = PageUtils.getFirstItemInPage(page); int latestItem = PageUtils.getLatestItemInPage(page); int totalElements = (int) page.getTotalElements(); boolean isEmpty = page.getTotalElements() == 0; String attrValue = String.valueOf(attributeValue).trim(); String messageTemplate = COMPACT.equals(attrValue) ? COMPACT_MESSAGE_KEY : DEFAULT_MESSAGE_KEY; String messageKey = isEmpty ? NO_VALUES_MESSAGE_KEY : messageTemplate; String message = Messages.getMessage(BUNDLE_NAME, messageKey, locale, firstItem, latestItem, totalElements); structureHandler.setBody(message, false); }
Example #10
Source File: UserAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler iElementTagStructureHandler) { if (ShiroFacade.isUser()) { iElementTagStructureHandler.removeAttribute(attributeName); } else { iElementTagStructureHandler.removeElement(); } }
Example #11
Source File: PrincipalElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, IElementTagStructureHandler iElementTagStructureHandler) { final String type = iProcessableElementTag.getAttributeValue("type"); final String property = iProcessableElementTag.getAttributeValue("property"); final String text = ShiroFacade.getPrincipalText(type, property); iElementTagStructureHandler.replaceWith(text, false); }
Example #12
Source File: AuthenticatedElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, IElementTagStructureHandler iElementTagStructureHandler) { if (ShiroFacade.isAuthenticated()) { iElementTagStructureHandler.removeTags(); } else { iElementTagStructureHandler.removeElement(); } }
Example #13
Source File: HasAllRolesElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, IElementTagStructureHandler iElementTagStructureHandler) { final String rawValue = getRawValue(iProcessableElementTag, "name"); final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER); if (ShiroFacade.hasAllRoles(values)) { iElementTagStructureHandler.removeTags(); } else { iElementTagStructureHandler.removeElement(); } }
Example #14
Source File: GuestAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler iElementTagStructureHandler) { if (ShiroFacade.isGuest()) { iElementTagStructureHandler.removeAttribute(attributeName); } else { iElementTagStructureHandler.removeElement(); } }
Example #15
Source File: HasAllRolesAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler iElementTagStructureHandler) { final String rawValue = getRawValue(iProcessableElementTag, attributeName); final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER); if (ShiroFacade.hasAllRoles(values)) { iElementTagStructureHandler.removeAttribute(attributeName); } else { iElementTagStructureHandler.removeElement(); } }
Example #16
Source File: UserElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, IElementTagStructureHandler iElementTagStructureHandler) { if (ShiroFacade.isUser()) { iElementTagStructureHandler.removeTags(); } else { iElementTagStructureHandler.removeElement(); } }
Example #17
Source File: HasAnyRolesAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler iElementTagStructureHandler) { final String rawValue = getRawValue(iProcessableElementTag, attributeName); final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER); if (ShiroFacade.hasAnyRoles(values)) { iElementTagStructureHandler.removeAttribute(attributeName); } else { iElementTagStructureHandler.removeElement(); } }
Example #18
Source File: AuthenticatedAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler iElementTagStructureHandler) { if (ShiroFacade.isAuthenticated()) { iElementTagStructureHandler.removeAttribute(attributeName); } else { iElementTagStructureHandler.removeElement(); } }
Example #19
Source File: HasPermissionAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler iElementTagStructureHandler) { final String rawValue = getRawValue(iProcessableElementTag, attributeName); final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER); if (ShiroFacade.hasAllPermissions(values)) { iElementTagStructureHandler.removeAttribute(attributeName); } else { iElementTagStructureHandler.removeElement(); } }
Example #20
Source File: NotAuthenticatedAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler iElementTagStructureHandler) { if (ShiroFacade.isNotAuthenticated()) { iElementTagStructureHandler.removeAttribute(attributeName); } else { iElementTagStructureHandler.removeElement(); } }
Example #21
Source File: HasAnyPermissionsAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler iElementTagStructureHandler) { final String rawValue = getRawValue(iProcessableElementTag, attributeName); final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER); if (ShiroFacade.hasAnyPermissions(values)) { iElementTagStructureHandler.removeAttribute(attributeName); } else { iElementTagStructureHandler.removeElement(); } }
Example #22
Source File: HasAnyPermissionsElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, IElementTagStructureHandler iElementTagStructureHandler) { final String rawValue = getRawValue(iProcessableElementTag, "name"); final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER); if (ShiroFacade.hasAnyPermissions(values)) { iElementTagStructureHandler.removeTags(); } else { iElementTagStructureHandler.removeElement(); } }
Example #23
Source File: HasPermissionElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, IElementTagStructureHandler iElementTagStructureHandler) { final String rawValue = getRawValue(iProcessableElementTag, "name"); final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER); if (ShiroFacade.hasAllPermissions(values)) { iElementTagStructureHandler.removeTags(); } else { iElementTagStructureHandler.removeElement(); } }
Example #24
Source File: DataProcessor.java From thymeleaf-extras-data-attribute with Apache License 2.0 | 5 votes |
@Override public void process(ITemplateContext context, IProcessableElementTag tag, IElementTagStructureHandler structureHandler) { TemplateMode templateMode = getTemplateMode(); IAttribute[] attributes = tag.getAllAttributes(); for (IAttribute attribute : attributes) { AttributeName attributeName = attribute.getAttributeDefinition().getAttributeName(); if (attributeName.isPrefixed()) { if (TextUtil.equals(templateMode.isCaseSensitive(), attributeName.getPrefix(), dialectPrefix)) { processDataAttribute(context, tag, attribute, structureHandler); } } } }
Example #25
Source File: NotAuthenticatedElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, IElementTagStructureHandler iElementTagStructureHandler) { if (ShiroFacade.isNotAuthenticated()) { iElementTagStructureHandler.removeTags(); } else { iElementTagStructureHandler.removeElement(); } }
Example #26
Source File: LacksRoleElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, IElementTagStructureHandler iElementTagStructureHandler) { final String rawValue = getRawValue(iProcessableElementTag, "name"); final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER); if (!ShiroFacade.hasAnyRoles(values)) { iElementTagStructureHandler.removeTags(); } else { iElementTagStructureHandler.removeElement(); } }
Example #27
Source File: HasRoleElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, IElementTagStructureHandler iElementTagStructureHandler) { final String rawValue = getRawValue(iProcessableElementTag, "name"); final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER); if (ShiroFacade.hasAllRoles(values)) { iElementTagStructureHandler.removeTags(); } else { iElementTagStructureHandler.removeElement(); } }
Example #28
Source File: LacksPermissionElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, IElementTagStructureHandler iElementTagStructureHandler) { final String rawValue = getRawValue(iProcessableElementTag, "name"); final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER); if (!ShiroFacade.hasAnyPermissions(values)) { iElementTagStructureHandler.removeTags(); } else { iElementTagStructureHandler.removeElement(); } }
Example #29
Source File: HasAnyRolesElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, IElementTagStructureHandler iElementTagStructureHandler) { final String rawValue = getRawValue(iProcessableElementTag, "name"); final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER); if (ShiroFacade.hasAnyRoles(values)) { iElementTagStructureHandler.removeTags(); } else { iElementTagStructureHandler.removeElement(); } }
Example #30
Source File: HasAllPermissionsElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
@Override protected void doProcess(ITemplateContext iTemplateContext, IProcessableElementTag iProcessableElementTag, IElementTagStructureHandler iElementTagStructureHandler) { final String rawValue = getRawValue(iProcessableElementTag, "name"); final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER); if (ShiroFacade.hasAllPermissions(values)) { iElementTagStructureHandler.removeTags(); } else { iElementTagStructureHandler.removeElement(); } }