use of org.thymeleaf.engine.AttributeName in project thymeleaf by thymeleaf.
the class AbstractAttributeModelProcessor method doProcess.
@Override
protected final void doProcess(final ITemplateContext context, final IModel model, final IElementModelStructureHandler structureHandler) {
AttributeName attributeName = null;
IProcessableElementTag firstEvent = null;
try {
attributeName = getMatchingAttributeName().getMatchingAttributeName();
firstEvent = (IProcessableElementTag) model.get(0);
final String attributeValue = EscapedAttributeUtils.unescapeAttribute(context.getTemplateMode(), firstEvent.getAttributeValue(attributeName));
doProcess(context, model, attributeName, attributeValue, structureHandler);
if (this.removeAttribute) {
if (model.size() > 0 && model.get(0) instanceof IProcessableElementTag) {
firstEvent = (IProcessableElementTag) model.get(0);
final IModelFactory modelFactory = context.getModelFactory();
final IProcessableElementTag newFirstEvent = modelFactory.removeAttribute(firstEvent, attributeName);
if (newFirstEvent != firstEvent) {
model.replace(0, newFirstEvent);
}
}
}
} catch (final TemplateProcessingException e) {
if (firstEvent != null) {
String attributeTemplateName = firstEvent.getTemplateName();
final IAttribute attribute = firstEvent.getAttribute(attributeName);
int attributeLine = (attribute != null ? attribute.getLine() : -1);
int attributeCol = (attribute != null ? attribute.getCol() : -1);
if (attributeTemplateName != null) {
if (!e.hasTemplateName()) {
e.setTemplateName(attributeTemplateName);
}
}
if (attributeLine != -1 && attributeCol != -1) {
if (!e.hasLineAndCol()) {
e.setLineAndCol(attributeLine, attributeCol);
}
}
}
throw e;
} catch (final Exception e) {
// We will try to add all information possible to the exception report (template name, line, col)
String attributeTemplateName = null;
int attributeLine = -1;
int attributeCol = -1;
if (firstEvent != null) {
attributeTemplateName = firstEvent.getTemplateName();
final IAttribute attribute = firstEvent.getAttribute(attributeName);
attributeLine = (attribute != null ? attribute.getLine() : -1);
attributeCol = (attribute != null ? attribute.getCol() : -1);
}
throw new TemplateProcessingException("Error during execution of processor '" + this.getClass().getName() + "'", attributeTemplateName, attributeLine, attributeCol, e);
}
}
use of org.thymeleaf.engine.AttributeName in project thymeleaf by thymeleaf.
the class StandardStyleappendTagProcessor method doProcess.
@Override
protected final void doProcess(final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final Object expressionResult, final IElementTagStructureHandler structureHandler) {
String newAttributeValue = EscapedAttributeUtils.escapeAttribute(getTemplateMode(), expressionResult == null ? null : expressionResult.toString());
// If we are not adding anything, we'll just leave it untouched
if (newAttributeValue != null && newAttributeValue.length() > 0) {
final AttributeName targetAttributeName = this.targetAttributeDefinition.getAttributeName();
if (tag.hasAttribute(targetAttributeName)) {
final String currentValue = tag.getAttributeValue(targetAttributeName);
if (currentValue.length() > 0) {
newAttributeValue = currentValue + ' ' + newAttributeValue;
}
}
StandardProcessorUtils.setAttribute(structureHandler, this.targetAttributeDefinition, TARGET_ATTR_NAME, newAttributeValue);
}
}
Aggregations