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());
}
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());
}
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);
}
}
}
}
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()));
}
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());
}
Aggregations