Java Code Examples for org.thymeleaf.model.IProcessableElementTag#getAttributeValue()

The following examples show how to use org.thymeleaf.model.IProcessableElementTag#getAttributeValue() . 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: 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 2
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 3
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 4
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);
}