Search in sources :

Example 1 with IProcessableElementTag

use of org.thymeleaf.model.IProcessableElementTag in project thymeleaf-tests by thymeleaf.

the class ElementStackTextProcessor method doProcess.

@Override
protected void doProcess(final ITemplateContext context, final IText text, final ITextStructureHandler structureHandler) {
    final List<IProcessableElementTag> stack = context.getElementStack();
    final StringBuilder stringBuilder = new StringBuilder();
    for (final IProcessableElementTag stackTag : stack) {
        if (stringBuilder.length() > 0) {
            stringBuilder.append(", ");
        }
        stringBuilder.append(stackTag.getElementCompleteName());
        for (final IAttribute attribute : stackTag.getAllAttributes()) {
            stringBuilder.append(" ");
            stringBuilder.append(attribute.getAttributeCompleteName());
        }
    }
    final String t = text.getText();
    structureHandler.setText(t + " " + stringBuilder.toString());
}
Also used : IProcessableElementTag(org.thymeleaf.model.IProcessableElementTag) IAttribute(org.thymeleaf.model.IAttribute)

Example 2 with IProcessableElementTag

use of org.thymeleaf.model.IProcessableElementTag in project thymeleaf-tests by thymeleaf.

the class Attr2ModelAttributeTagProcessor method doProcess.

@Override
protected void doProcess(final ITemplateContext context, final IModel model, final AttributeName attributeName, final String attributeValue, final IElementModelStructureHandler structureHandler) {
    final IModelFactory modelFactory = context.getModelFactory();
    final IProcessableElementTag firstEvent = (IProcessableElementTag) model.get(0);
    final IProcessableElementTag newFirstEvent = modelFactory.setAttribute(firstEvent, "var2", (String) context.getVariable("var"));
    model.replace(0, newFirstEvent);
}
Also used : IProcessableElementTag(org.thymeleaf.model.IProcessableElementTag) IModelFactory(org.thymeleaf.model.IModelFactory)

Example 3 with IProcessableElementTag

use of org.thymeleaf.model.IProcessableElementTag in project thymeleaf-tests by thymeleaf.

the class ModelAttributeTagProcessor method doProcess.

@Override
protected void doProcess(final ITemplateContext context, final IModel model, final AttributeName attributeName, final String attributeValue, final IElementModelStructureHandler structureHandler) {
    final IModelFactory modelFactory = context.getModelFactory();
    final IProcessableElementTag firstEvent = (IProcessableElementTag) model.get(0);
    final Map<String, String> attributes = firstEvent.getAttributeMap();
    final ITemplateEvent lastEvent = model.get(model.size() - 1);
    if (firstEvent == lastEvent) {
        final IStandaloneElementTag newFirstEvent = modelFactory.createStandaloneElementTag("ctx", attributes, AttributeValueQuotes.DOUBLE, false, false);
        model.replace(0, newFirstEvent);
    } else {
        final IOpenElementTag newFirstEvent = modelFactory.createOpenElementTag("ctx", attributes, AttributeValueQuotes.DOUBLE, false);
        final ICloseElementTag newLastEvent = modelFactory.createCloseElementTag("ctx", false, false);
        model.replace(0, newFirstEvent);
        model.replace(model.size() - 1, newLastEvent);
    }
}
Also used : ITemplateEvent(org.thymeleaf.model.ITemplateEvent) IProcessableElementTag(org.thymeleaf.model.IProcessableElementTag) IOpenElementTag(org.thymeleaf.model.IOpenElementTag) IModelFactory(org.thymeleaf.model.IModelFactory) ICloseElementTag(org.thymeleaf.model.ICloseElementTag) IStandaloneElementTag(org.thymeleaf.model.IStandaloneElementTag)

Example 4 with IProcessableElementTag

use of org.thymeleaf.model.IProcessableElementTag in project thymeleaf-tests by thymeleaf.

the class MarkupPrintAfterElementModelProcessor method doProcess.

@Override
protected void doProcess(final ITemplateContext context, final IModel model, final AttributeName attributeName, final String attributeValue, final IElementModelStructureHandler structureHandler) {
    final String markupStr = HtmlEscape.escapeHtml4Xml(model.toString().replaceAll("\\r\\n|\\r|\\n", "\\\\n"));
    final IModelFactory modelFactory = context.getModelFactory();
    final IProcessableElementTag newTag = modelFactory.setAttribute((IProcessableElementTag) model.get(0), "aggafter", markupStr);
    model.replace(0, newTag);
}
Also used : IProcessableElementTag(org.thymeleaf.model.IProcessableElementTag) IModelFactory(org.thymeleaf.model.IModelFactory)

Example 5 with IProcessableElementTag

use of org.thymeleaf.model.IProcessableElementTag in project thymeleaf-tests by thymeleaf.

the class MarkupPrintBeforeElementModelProcessor method doProcess.

@Override
protected void doProcess(final ITemplateContext context, final IModel model, final AttributeName attributeName, final String attributeValue, final IElementModelStructureHandler structureHandler) {
    final String markupStr = HtmlEscape.escapeHtml4Xml(model.toString().replaceAll("\\r\\n|\\r|\\n", "\\\\n"));
    final IModelFactory modelFactory = context.getModelFactory();
    final IProcessableElementTag newTag = modelFactory.setAttribute((IProcessableElementTag) model.get(0), "aggbefore", markupStr);
    model.replace(0, newTag);
}
Also used : IProcessableElementTag(org.thymeleaf.model.IProcessableElementTag) IModelFactory(org.thymeleaf.model.IModelFactory)

Aggregations

IProcessableElementTag (org.thymeleaf.model.IProcessableElementTag)9 IModelFactory (org.thymeleaf.model.IModelFactory)6 IAttribute (org.thymeleaf.model.IAttribute)3 TemplateProcessingException (org.thymeleaf.exceptions.TemplateProcessingException)2 ICloseElementTag (org.thymeleaf.model.ICloseElementTag)2 IOpenElementTag (org.thymeleaf.model.IOpenElementTag)2 ITemplateEvent (org.thymeleaf.model.ITemplateEvent)2 Writer (java.io.Writer)1 Map (java.util.Map)1 IEngineConfiguration (org.thymeleaf.IEngineConfiguration)1 IEngineContext (org.thymeleaf.context.IEngineContext)1 ITemplateContext (org.thymeleaf.context.ITemplateContext)1 AttributeName (org.thymeleaf.engine.AttributeName)1 TemplateData (org.thymeleaf.engine.TemplateData)1 TemplateModel (org.thymeleaf.engine.TemplateModel)1 TemplateInputException (org.thymeleaf.exceptions.TemplateInputException)1 IModel (org.thymeleaf.model.IModel)1 IStandaloneElementTag (org.thymeleaf.model.IStandaloneElementTag)1 Fragment (org.thymeleaf.standard.expression.Fragment)1 FragmentSignature (org.thymeleaf.standard.expression.FragmentSignature)1