org.thymeleaf.model.IProcessableElementTag Java Examples

The following examples show how to use org.thymeleaf.model.IProcessableElementTag. 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: DictShowProcessor.java    From FEBS-Security with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: EnabledImageTagProcessor.java    From konker-platform with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: PrincipalAttrProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: PaginationSortBaseAttrProcessor.java    From thymeleaf-spring-data-dialect with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: PaginationSummaryAttrProcessor.java    From thymeleaf-spring-data-dialect with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: PageObjectAttrProcessor.java    From thymeleaf-spring-data-dialect with Apache License 2.0 6 votes vote down vote up
@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: AbstractPagerDecorator.java    From thymeleaf-spring-data-dialect with Apache License 2.0 6 votes vote down vote up
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 #8
Source File: HasAnyRolesAttrProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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 #9
Source File: HasAnyPermissionsAttrProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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 #10
Source File: UserAttrProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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: HasAllRolesAttrProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: GuestAttrProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@Override
protected void doProcess(ITemplateContext iTemplateContext,
                         IProcessableElementTag iProcessableElementTag,
                         AttributeName attributeName,
                         String attributeValue,
                         IElementTagStructureHandler iElementTagStructureHandler) {
    if (ShiroFacade.isGuest()) {
        iElementTagStructureHandler.removeAttribute(attributeName);
    } else {
        iElementTagStructureHandler.removeElement();
    }
}
 
Example #13
Source File: HasAllRolesElementProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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: AuthenticatedElementProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@Override
protected void doProcess(ITemplateContext iTemplateContext,
                         IProcessableElementTag iProcessableElementTag,
                         IElementTagStructureHandler iElementTagStructureHandler) {
    if (ShiroFacade.isAuthenticated()) {
        iElementTagStructureHandler.removeTags();
    } else {
        iElementTagStructureHandler.removeElement();
    }
}
 
Example #15
Source File: PrincipalElementProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: HasAnyPermissionsElementProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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 #17
Source File: HasPermissionElementProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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 #18
Source File: UserElementProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@Override
protected void doProcess(ITemplateContext iTemplateContext,
                         IProcessableElementTag iProcessableElementTag,
                         IElementTagStructureHandler iElementTagStructureHandler) {
    if (ShiroFacade.isUser()) {
        iElementTagStructureHandler.removeTags();
    } else {
        iElementTagStructureHandler.removeElement();
    }
}
 
Example #19
Source File: NotAuthenticatedElementProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@Override
protected void doProcess(ITemplateContext iTemplateContext,
                         IProcessableElementTag iProcessableElementTag,
                         IElementTagStructureHandler iElementTagStructureHandler) {
    if (ShiroFacade.isNotAuthenticated()) {
        iElementTagStructureHandler.removeTags();
    } else {
        iElementTagStructureHandler.removeElement();
    }
}
 
Example #20
Source File: LacksRoleElementProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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 #21
Source File: HasRoleElementProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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 #22
Source File: LacksPermissionElementProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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: HasAnyRolesElementProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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 #24
Source File: HasAllPermissionsElementProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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 #25
Source File: GuestElementProcessor.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@Override
protected void doProcess(ITemplateContext iTemplateContext,
                         IProcessableElementTag iProcessableElementTag,
                         IElementTagStructureHandler iElementTagStructureHandler) {
    if (ShiroFacade.isGuest()) {
        iElementTagStructureHandler.removeTags();
    } else {
        iElementTagStructureHandler.removeElement();
    }
}
 
Example #26
Source File: ThymeleafFacade.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
public static String getRawValue(final IProcessableElementTag element, final AttributeName attributeName) {
    notNull(element, "element must not be null");
    notNull(attributeName, "attributeName must not be empty");

    final String rawValue = trim(element.getAttributeValue(attributeName));
    notEmpty(rawValue, "value of '" + attributeName + "' must not be empty");

    return rawValue;
}
 
Example #27
Source File: ThymeleafFacade.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
public static String getRawValue(final IProcessableElementTag element, final String attributeName) {
    notNull(element, "element must not be null");
    notEmpty(attributeName, "attributeName must not be empty");

    final String rawValue = trim(element.getAttributeValue(attributeName));
    notEmpty(rawValue, "value of '" + attributeName + "' must not be empty");

    return rawValue;
}
 
Example #28
Source File: FullPaginationDecorator.java    From thymeleaf-spring-data-dialect with Apache License 2.0 5 votes vote down vote up
public String decorate(final IProcessableElementTag tag, final ITemplateContext context) {

        Page<?> page = PageUtils.findPage(context);

        // laquo
        String firstPage = PageUtils.createPageUrl(context, 0);
        Locale locale = context.getLocale();
        String laquo = PageUtils.isFirstPage(page) ? getLaquo(locale) : getLaquo(firstPage, locale);

        // Previous page
        String previous = getPreviousPageLink(page, context);

        // Links
        String pageLinks = createPageLinks(page, context);

        // Next page
        String next = getNextPageLink(page, context);

        // raquo
        String lastPage = PageUtils.createPageUrl(context, page.getTotalPages() - 1);
        String raquo = page.isLast() ? getRaquo(locale) : getRaquo(lastPage, locale);

        boolean isUl = Strings.UL.equalsIgnoreCase(tag.getElementCompleteName());
        String currentClass = tag.getAttributeValue(Strings.CLASS);
        String clas = (isUl && !Strings.isEmpty(currentClass)) ? currentClass : DEFAULT_CLASS;

        return Messages.getMessage(BUNDLE_NAME, "pagination", locale, clas, laquo, previous, pageLinks, next, raquo);
    }
 
Example #29
Source File: ThSysTagProcessor.java    From mayday with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName,
		String attributeValue, IElementTagStructureHandler structureHandler) {
	final IEngineConfiguration configuration = context.getConfiguration();
	final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration);
	final IStandardExpression expression = parser.parseExpression(context, attributeValue);
	final String title = (String) expression.execute(context);
	structureHandler.setBody(title + " - " + MaydayConst.OPTIONS.get("blog_name"), false);
}
 
Example #30
Source File: PaginationQualifierAttrProcessor.java    From thymeleaf-spring-data-dialect with Apache License 2.0 5 votes vote down vote up
@Override
protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName,
        String attributeValue, IElementTagStructureHandler structureHandler) {

    if (context instanceof WebEngineContext) {
        String attrValue = String.valueOf(attributeValue).trim();
        ((WebEngineContext) context).setVariable(Keys.PAGINATION_QUALIFIER_PREFIX, attrValue);
    }
}