gate.thymeleaf.processors.attribute.IconAttributeProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gate Show documentation
Show all versions of gate Show documentation
A multipurpose java library
package gate.thymeleaf.processors.attribute;
import gate.annotation.Icon;
import gate.thymeleaf.ELExpression;
import gate.icon.Icons;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.model.IProcessableElementTag;
import org.thymeleaf.processor.element.IElementTagStructureHandler;
@ApplicationScoped
public class IconAttributeProcessor extends AttributeProcessor
{
@Inject
ELExpression expression;
public IconAttributeProcessor()
{
super(null, "icon");
}
@Override
public void process(ITemplateContext context,
IProcessableElementTag element,
IElementTagStructureHandler handler)
{
handler.setAttribute("data-icon",
extract(element, handler, "g:icon")
.map(expression::evaluate)
.flatMap(Icon.Extractor::extract)
.orElse(Icons.UNKNOWN)
.toString());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy