Search in sources :

Example 1 with IAttribute

use of org.thymeleaf.model.IAttribute 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 IAttribute

use of org.thymeleaf.model.IAttribute in project thymeleaf by thymeleaf.

the class OpenElementTag method asEngineOpenElementTag.

// Meant to be called only from within the engine
static OpenElementTag asEngineOpenElementTag(final IOpenElementTag openElementTag) {
    if (openElementTag instanceof OpenElementTag) {
        return (OpenElementTag) openElementTag;
    }
    final IAttribute[] originalAttributeArray = openElementTag.getAllAttributes();
    final Attributes attributes;
    if (originalAttributeArray == null || originalAttributeArray.length == 0) {
        attributes = null;
    } else {
        // We will perform a deep cloning of the attributes into objects of the Attribute class, so that
        // we make sure absolutely all Attributes in the new event are under the engine's control
        final Attribute[] newAttributeArray = new Attribute[originalAttributeArray.length];
        for (int i = 0; i < originalAttributeArray.length; i++) {
            final IAttribute originalAttribute = originalAttributeArray[i];
            newAttributeArray[i] = new Attribute(originalAttribute.getAttributeDefinition(), originalAttribute.getAttributeCompleteName(), originalAttribute.getOperator(), originalAttribute.getValue(), originalAttribute.getValueQuotes(), originalAttribute.getTemplateName(), originalAttribute.getLine(), originalAttribute.getCol());
        }
        final String[] newInnerWhiteSpaces;
        if (newAttributeArray.length == 1) {
            newInnerWhiteSpaces = Attributes.DEFAULT_WHITE_SPACE_ARRAY;
        } else {
            newInnerWhiteSpaces = new String[newAttributeArray.length];
            Arrays.fill(newInnerWhiteSpaces, Attributes.DEFAULT_WHITE_SPACE);
        }
        attributes = new Attributes(newAttributeArray, newInnerWhiteSpaces);
    }
    return new OpenElementTag(openElementTag.getTemplateMode(), openElementTag.getElementDefinition(), openElementTag.getElementCompleteName(), attributes, openElementTag.isSynthetic(), openElementTag.getTemplateName(), openElementTag.getLine(), openElementTag.getCol());
}
Also used : IAttribute(org.thymeleaf.model.IAttribute) IAttribute(org.thymeleaf.model.IAttribute) IOpenElementTag(org.thymeleaf.model.IOpenElementTag)

Example 3 with IAttribute

use of org.thymeleaf.model.IAttribute in project thymeleaf by thymeleaf.

the class StandardDefaultAttributesTagProcessor method process.

// Default implementation - meant to be overridden by subclasses if needed
public void process(final ITemplateContext context, final IProcessableElementTag tag, final IElementTagStructureHandler structureHandler) {
    final TemplateMode templateMode = getTemplateMode();
    final IAttribute[] attributes = tag.getAllAttributes();
    // should not be affected by modifications on the original tag attribute set
    for (final IAttribute attribute : attributes) {
        final AttributeName attributeName = attribute.getAttributeDefinition().getAttributeName();
        if (attributeName.isPrefixed()) {
            if (TextUtil.equals(templateMode.isCaseSensitive(), attributeName.getPrefix(), this.dialectPrefix)) {
                // We will process each 'default' attribute separately
                processDefaultAttribute(getTemplateMode(), context, tag, attribute, structureHandler);
            }
        }
    }
}
Also used : TemplateMode(org.thymeleaf.templatemode.TemplateMode) IAttribute(org.thymeleaf.model.IAttribute) MatchingAttributeName(org.thymeleaf.processor.element.MatchingAttributeName) AttributeName(org.thymeleaf.engine.AttributeName)

Example 4 with IAttribute

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

the class ElementStackAttrProcessor method doProcess.

@Override
protected void doProcess(final ITemplateContext context, final IProcessableElementTag tag, final IElementTagStructureHandler 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());
        }
    }
    structureHandler.setAttribute("stack", HtmlEscape.escapeHtml5(stringBuilder.toString()));
}
Also used : IProcessableElementTag(org.thymeleaf.model.IProcessableElementTag) IAttribute(org.thymeleaf.model.IAttribute)

Example 5 with IAttribute

use of org.thymeleaf.model.IAttribute in project thymeleaf by thymeleaf.

the class StandaloneElementTag method asEngineStandaloneElementTag.

// Meant to be called only from within the engine
static StandaloneElementTag asEngineStandaloneElementTag(final IStandaloneElementTag standaloneElementTag) {
    if (standaloneElementTag instanceof StandaloneElementTag) {
        return (StandaloneElementTag) standaloneElementTag;
    }
    final IAttribute[] originalAttributeArray = standaloneElementTag.getAllAttributes();
    final Attributes attributes;
    if (originalAttributeArray == null || originalAttributeArray.length == 0) {
        attributes = null;
    } else {
        // We will perform a deep cloning of the attributes into objects of the Attribute class, so that
        // we make sure absolutely all Attributes in the new event are under the engine's control
        final Attribute[] newAttributeArray = new Attribute[originalAttributeArray.length];
        for (int i = 0; i < originalAttributeArray.length; i++) {
            final IAttribute originalAttribute = originalAttributeArray[i];
            newAttributeArray[i] = new Attribute(originalAttribute.getAttributeDefinition(), originalAttribute.getAttributeCompleteName(), originalAttribute.getOperator(), originalAttribute.getValue(), originalAttribute.getValueQuotes(), originalAttribute.getTemplateName(), originalAttribute.getLine(), originalAttribute.getCol());
        }
        final String[] newInnerWhiteSpaces;
        if (newAttributeArray.length == 1) {
            newInnerWhiteSpaces = Attributes.DEFAULT_WHITE_SPACE_ARRAY;
        } else {
            newInnerWhiteSpaces = new String[newAttributeArray.length];
            Arrays.fill(newInnerWhiteSpaces, Attributes.DEFAULT_WHITE_SPACE);
        }
        attributes = new Attributes(newAttributeArray, newInnerWhiteSpaces);
    }
    return new StandaloneElementTag(standaloneElementTag.getTemplateMode(), standaloneElementTag.getElementDefinition(), standaloneElementTag.getElementCompleteName(), attributes, standaloneElementTag.isSynthetic(), standaloneElementTag.isMinimized(), standaloneElementTag.getTemplateName(), standaloneElementTag.getLine(), standaloneElementTag.getCol());
}
Also used : IAttribute(org.thymeleaf.model.IAttribute) IStandaloneElementTag(org.thymeleaf.model.IStandaloneElementTag) IAttribute(org.thymeleaf.model.IAttribute)

Aggregations

IAttribute (org.thymeleaf.model.IAttribute)7 AttributeName (org.thymeleaf.engine.AttributeName)3 IProcessableElementTag (org.thymeleaf.model.IProcessableElementTag)3 TemplateProcessingException (org.thymeleaf.exceptions.TemplateProcessingException)2 IModelFactory (org.thymeleaf.model.IModelFactory)1 IOpenElementTag (org.thymeleaf.model.IOpenElementTag)1 IStandaloneElementTag (org.thymeleaf.model.IStandaloneElementTag)1 MatchingAttributeName (org.thymeleaf.processor.element.MatchingAttributeName)1 TemplateMode (org.thymeleaf.templatemode.TemplateMode)1