throw new TemplateProcessingException("Fragment specifications cannot be empty"); final IEngineConfiguration configuration = context.getConfiguration(); structureHandler.removeElement(); } else { structureHandler.removeBody(); if (context.getTemplateMode() != fragmentModel.getTemplateMode()) { structureHandler.replaceWith(stringWriter.toString(), false); } else { structureHandler.setBody(stringWriter.toString(), false); structureHandler.setTemplateData(fragmentTemplateData); structureHandler.setLocalVariable(fragmentParameterEntry.getKey(), fragmentParameterEntry.getValue()); structureHandler.replaceWith(model, true); } else { structureHandler.setBody(model, true); structureHandler.replaceWith(fragmentModel, true); } else { structureHandler.setBody(fragmentModel, true);
EscapedAttributeUtils.unescapeAttribute(context.getTemplateMode(), attribute.getValue()); final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); structureHandler.removeAttribute(attributeName); return; structureHandler.removeAttribute(newAttributeName); structureHandler.removeAttribute(attributeName); } else { structureHandler.replaceAttribute(attributeName, newAttributeName, (newAttributeValue == null? "" : newAttributeValue)); if (!e.hasTemplateName()) { e.setTemplateName(tag.getTemplateName()); if (!e.hasLineAndCol()) { e.setLineAndCol(attribute.getLine(), attribute.getCol());
context, attributeValue, false /* no parameters without value */); if (assignations == null) { throw new TemplateProcessingException( "Could not parse value as attribute assignations: \"" + attributeValue + "\""); throw new TemplateProcessingException( "Attribute name expression evaluated as null or empty: \"" + leftExpr + "\""); structureHandler.setAttribute(newAttributeName, newAttributeName); } else { structureHandler.removeAttribute(newAttributeName); structureHandler.removeAttribute(newAttributeName); tag.getAttributeValue(newAttributeName).length() == 0) { structureHandler.setAttribute(newAttributeName, newAttributeValue); } else { String currentValue = tag.getAttributeValue(newAttributeName); if (this.modificationType == ModificationType.APPEND) { structureHandler.setAttribute(newAttributeName, currentValue + newAttributeValue); } else if (this.modificationType == ModificationType.APPEND_WITH_SPACE) { structureHandler.setAttribute(newAttributeName, currentValue + ' ' + newAttributeValue); } else if (this.modificationType == ModificationType.PREPEND) { structureHandler.setAttribute(newAttributeName, newAttributeValue + currentValue); } else { // modification type is PREPEND_WITH_SPACE structureHandler.setAttribute(newAttributeName, newAttributeValue + ' ' + currentValue);
@Override protected void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final Object expressionResult, final IElementTagStructureHandler structureHandler) { if (expressionResult != null) { final String resultStr = expressionResult.toString(); if (VALUE_ALL.equalsIgnoreCase(resultStr)) { structureHandler.removeElement(); } else if (VALUE_TAG.equalsIgnoreCase(resultStr) || VALUE_TAGS.equalsIgnoreCase(resultStr)) { structureHandler.removeTags(); } else if (VALUE_ALL_BUT_FIRST.equalsIgnoreCase(resultStr)) { structureHandler.removeAllButFirstChild(); } else if (VALUE_BODY.equalsIgnoreCase(resultStr)) { structureHandler.removeBody(); } else if (!VALUE_NONE.equalsIgnoreCase(resultStr)) { throw new TemplateProcessingException( "Invalid value specified for \"" + attributeName + "\": only 'all', 'tag', 'body', 'none' " + "and 'all-but-first' are allowed, but \"" + attributeValue + "\" was specified."); } } }
@Override protected final void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final IElementTagStructureHandler structureHandler) { final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); final IStandardExpression expression = expressionParser.parseExpression(context, attributeValue); validateSelectionValue(context, tag, attributeName, attributeValue, expression); final Object newSelectionTarget = expression.execute(context); final Map<String,Object> additionalLocalVariables = computeAdditionalLocalVariables(context, tag, attributeName, attributeValue, expression); if (additionalLocalVariables != null && additionalLocalVariables.size() > 0) { for (final Map.Entry<String,Object> variableEntry : additionalLocalVariables.entrySet()) { structureHandler.setLocalVariable(variableEntry.getKey(), variableEntry.getValue()); } } structureHandler.setSelectionTarget(newSelectionTarget); }
final BindStatus bindStatus, final IElementTagStructureHandler structureHandler) { String name = bindStatus.getExpression(); name = (name == null? "" : name); boolean checked = false; Object boundValue = bindStatus.getValue(); final Class<?> valueType = bindStatus.getValueType(); throw new TemplateProcessingException( "Attribute \"value\" is required in \"input(checkbox)\" tags " + "when binding to non-boolean values"); checked = SelectedValueComparatorWrapper.isSelected(bindStatus, HtmlEscape.unescapeHtml(value)); StandardProcessorUtils.setAttribute(structureHandler, this.checkedAttributeDefinition, CHECKED_ATTR_NAME, CHECKED_ATTR_NAME); } else { structureHandler.removeAttribute(this.checkedAttributeDefinition.getAttributeName()); final IModelFactory modelFactory = context.getModelFactory(); structureHandler.insertBefore(hiddenTagModel); } else { structureHandler.insertImmediatelyAfter(hiddenTagModel, false);
@Override protected void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final IElementTagStructureHandler structureHandler) { final BindStatus bindStatus = FieldUtils.getBindStatus(context, attributeValue); if (bindStatus.isError()) { final StringBuilder strBuilder = new StringBuilder(); final String[] errorMsgs = bindStatus.getErrorMessages(); for (int i = 0; i < errorMsgs.length; i++) { if (i > 0) { strBuilder.append(ERROR_DELIMITER); } final String displayString = ValueFormatterWrapper.getDisplayString(errorMsgs[i], false); strBuilder.append(displayString); } structureHandler.setBody(strBuilder.toString(), false); // Just in case we also have a th:errorclass in this tag structureHandler.setLocalVariable(SpringContextVariableNames.SPRING_FIELD_BIND_STATUS, bindStatus); } else { structureHandler.removeElement(); } }
@Override protected void doProcess(final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final BindStatus bindStatus, final IElementTagStructureHandler structureHandler) { String name = bindStatus.getExpression(); name = (name == null? "" : name); final String value = tag.getAttributeValue(this.valueAttributeDefinition.getAttributeName()); if (value == null) { throw new TemplateProcessingException( "Attribute \"value\" is required in \"option\" tags"); } final boolean selected = SelectedValueComparatorWrapper.isSelected(bindStatus, HtmlEscape.unescapeHtml(value)); StandardProcessorUtils.setAttribute( structureHandler, this.valueAttributeDefinition, VALUE_ATTR_NAME, RequestDataValueProcessorUtils.processFormFieldValue(context, name, value, "option")); if (selected) { StandardProcessorUtils.setAttribute(structureHandler, this.selectedAttributeDefinition, SELECTED_ATTR_NAME, SELECTED_ATTR_NAME); } else { structureHandler.removeAttribute(this.selectedAttributeDefinition.getAttributeName()); } }
@Override protected void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final IElementTagStructureHandler structureHandler) { final AttributeName selectAttrNameToAdd = (AttributeName) context.getVariable(SpringSelectFieldTagProcessor.OPTION_IN_SELECT_ATTR_NAME); if (selectAttrNameToAdd == null) { // Nothing to do return; } // It seems this <option> is inside a <select th:field="...">, and the processor for that "th:field" has left // as a local variable the name and value of the attribute to be added final String selectAttrValueToAdd = (String) context.getVariable(SpringSelectFieldTagProcessor.OPTION_IN_SELECT_ATTR_VALUE); if (tag.hasAttribute(selectAttrNameToAdd)) { if (!selectAttrValueToAdd.equals(tag.getAttributeValue(selectAttrNameToAdd))) { throw new TemplateProcessingException( "If specified (which is not required), attribute \"" + selectAttrNameToAdd + "\" in " + "\"option\" tag must have exactly the same value as in its containing \"select\" tag"); } } // This attribute value does not need to be escaped, because we are just "transporting" the th:field in the // container <select> to its <option>'s, without any modifications. It will be executed (and its results // escaped) later... structureHandler.setAttribute(selectAttrNameToAdd.getCompleteAttributeNames()[0], selectAttrValueToAdd); }
final IElementTagStructureHandler structureHandler) { final String newAttributeValue = HtmlEscape.escapeHtml4Xml(expressionResult == null ? null : expressionResult.toString()); structureHandler.removeAttribute(this.targetAttributeDefinition.getAttributeName()); structureHandler.removeAttribute(attributeName); } else { StandardProcessorUtils.replaceAttribute(structureHandler, attributeName, this.targetAttributeDefinition, TARGET_ATTR_NAME, newAttributeValue); final IModelFactory modelFactory = context.getModelFactory(); structureHandler.insertImmediatelyAfter(hiddenMethodModel, false);
EscapedAttributeUtils.unescapeAttribute(context.getTemplateMode(), tag.getAttributeValue(attributeName)); structureHandler.removeAttribute(attributeName); if (!e.hasTemplateName()) { e.setTemplateName(tag.getTemplateName()); if (!e.hasLineAndCol()) { if (attributeName == null) {
@Override protected void doProcess(final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final IThymeleafBindStatus bindStatus, final IElementTagStructureHandler structureHandler) { String name = bindStatus.getExpression(); name = (name == null? "" : name); final String value = tag.getAttributeValue(this.valueAttributeDefinition.getAttributeName()); if (value == null) { throw new TemplateProcessingException( "Attribute \"value\" is required in \"option\" tags"); } final boolean selected = SpringSelectedValueComparator.isSelected(bindStatus, HtmlEscape.unescapeHtml(value)); StandardProcessorUtils.setAttribute( structureHandler, this.valueAttributeDefinition, VALUE_ATTR_NAME, RequestDataValueProcessorUtils.processFormFieldValue(context, name, value, "option")); if (selected) { StandardProcessorUtils.setAttribute(structureHandler, this.selectedAttributeDefinition, SELECTED_ATTR_NAME, SELECTED_ATTR_NAME); } else { structureHandler.removeAttribute(this.selectedAttributeDefinition.getAttributeName()); } }
throw new TemplateProcessingException( "Attribute \"value\" is required in \"input(checkbox)\" tags " + "when binding to non-boolean values"); checked = SpringSelectedValueComparator.isSelected(bindStatus, HtmlEscape.unescapeHtml(value)); StandardProcessorUtils.setAttribute(structureHandler, this.checkedAttributeDefinition, CHECKED_ATTR_NAME, CHECKED_ATTR_NAME); } else { structureHandler.removeAttribute(this.checkedAttributeDefinition.getAttributeName()); final IModelFactory modelFactory = context.getModelFactory(); structureHandler.insertBefore(hiddenTagModel); } else { structureHandler.insertImmediatelyAfter(hiddenTagModel, false);
final BindStatus bindStatus, final IElementTagStructureHandler structureHandler) { String name = bindStatus.getExpression(); name = (name == null? "" : name); StandardProcessorUtils.setAttribute(structureHandler, this.nameAttributeDefinition, NAME_ATTR_NAME, name); // No need to escape: this is a java-valid token structureHandler.setLocalVariable(OPTION_IN_SELECT_ATTR_NAME, attributeName); structureHandler.setLocalVariable(OPTION_IN_SELECT_ATTR_VALUE, attributeValue); final IModelFactory modelFactory = context.getModelFactory(); structureHandler.insertBefore(hiddenMethodElementModel);
final IElementTagStructureHandler structureHandler) { String newAttributeValue = HtmlEscape.escapeHtml4Xml(expressionResult == null ? "" : expressionResult.toString()); final IModelFactory modelFactory = context.getModelFactory(); structureHandler.insertImmediatelyAfter(extraHiddenElementTags, false);
@Override protected void doProcess(final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final BindStatus bindStatus, final IElementTagStructureHandler structureHandler) { String name = bindStatus.getExpression(); name = (name == null? "" : name); final String id = computeId(context, tag, name, false); final String value = ValueFormatterWrapper.getDisplayString(bindStatus.getValue(), bindStatus.getEditor(), true); String processedValue = RequestDataValueProcessorUtils.processFormFieldValue(context, name, value, "textarea"); if (!StringUtils.isEmpty(processedValue)) { final char c0 = processedValue.charAt(0); if (c0 == '\n') { processedValue = '\n' + processedValue; } else if (c0 == '\r' && processedValue.length() > 1 && processedValue.charAt(1) == '\n') { processedValue = "\r\n" + processedValue; } else if (c0 == '\r') { processedValue = '\r' + processedValue; } } StandardProcessorUtils.setAttribute(structureHandler, this.idAttributeDefinition, ID_ATTR_NAME, id); // No need to escape: this comes from an existing 'id' or from a token StandardProcessorUtils.setAttribute(structureHandler, this.nameAttributeDefinition, NAME_ATTR_NAME, name); // No need to escape: this is a java-valid token structureHandler.setBody((processedValue == null? "" : processedValue), false); }
final IElementTagStructureHandler structureHandler) { final IEngineConfiguration configuration = context.getConfiguration(); structureHandler.removeBody(); return; structureHandler.setBody(((Fragment)expressionResult).getTemplateModel(), false); return; structureHandler.setBody(unescapedTextStr, false); return; structureHandler.setBody(unescapedTextStr, false); return; context.getTemplateData(), unescapedTextStr, 0, 0, // we won't apply offset here because the inserted text does not really come from the template itself structureHandler.setBody(parsedFragment, false);
text = new LazyEscapingCharSequence(context.getConfiguration(), templateMode, input); } else { text = new LazyEscapingCharSequence(context.getConfiguration(), templateMode, expressionResult); structureHandler.setBody(text, false);
@Override protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler) { Locale locale = context.getLocale(); loadSelectorValues(locale); String selectorStyle = String.valueOf(attributeValue).trim(); String messageKey = getMessageKey(selectorStyle); String options = composeSelectorOptions(selectorStyle, context); String message = Messages.getMessage(BUNDLE_NAME, messageKey, locale, options); structureHandler.setBody(message, false); }
@Override protected void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final IElementTagStructureHandler structureHandler) { final IThymeleafBindStatus bindStatus = FieldUtils.getBindStatus(context, attributeValue); if (bindStatus.isError()) { final StringBuilder strBuilder = new StringBuilder(); final String[] errorMsgs = bindStatus.getErrorMessages(); for (int i = 0; i < errorMsgs.length; i++) { if (i > 0) { strBuilder.append(ERROR_DELIMITER); } final String displayString = SpringValueFormatter.getDisplayString(errorMsgs[i], false); strBuilder.append(HtmlEscape.escapeHtml4Xml(displayString)); } structureHandler.setBody(strBuilder.toString(), false); // Just in case we also have a th:errorclass in this tag structureHandler.setLocalVariable(SpringContextVariableNames.THYMELEAF_FIELD_BIND_STATUS, bindStatus); } else { structureHandler.removeElement(); } }