org.thymeleaf.processor.element.IElementTagStructureHandler Java Examples

The following examples show how to use org.thymeleaf.processor.element.IElementTagStructureHandler. 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: 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 #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: 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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
Source File: NotAuthenticatedAttrProcessor.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.isNotAuthenticated()) {
        iElementTagStructureHandler.removeAttribute(attributeName);
    } else {
        iElementTagStructureHandler.removeElement();
    }
}
 
Example #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
Source File: PaginationUrlAttrProcessor.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) {
        Object url = Expressions.evaluate(context, attributeValue);
        ((WebEngineContext) context).setVariable(Keys.PAGINATION_URL_KEY, url);
    }
}
 
Example #26
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 #27
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);
    }
}
 
Example #28
Source File: PageSizeSelectorAttrProcessor.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) {

    Locale locale = context.getLocale();
    loadSelectorValues(locale);
    String selectorStyle = String.valueOf(attributeValue).trim();
    String messageKey = getMessageKey(selectorStyle);
    String options = composeSelectorOptions(selectorStyle, context);
    String message = Messages.getMessage(BUNDLE_NAME, messageKey, locale, options);

    structureHandler.setBody(message, false);
}
 
Example #29
Source File: PaginationSplitAttrProcessor.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) {
        Number split = (Number) Expressions.evaluate(context, attributeValue);
        ((WebEngineContext) context).setVariable(Keys.PAGINATION_SPLIT_KEY, split.intValue());
    }
}
 
Example #30
Source File: PaginationAttrProcessor.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) {

    String attrValue = String.valueOf(attributeValue).trim();
    PaginationDecorator decorator = PaginationDecoratorRegistry.getInstance().getDecorator(attrValue);
    String html = decorator.decorate(tag, context);

    boolean isUlNode = Strings.UL.equalsIgnoreCase(tag.getElementCompleteName());
    if (isUlNode) {
        structureHandler.replaceWith(html, false);
    } else {
        structureHandler.setBody(html, false);
    }
}