public final IThrottledTemplateProcessor processThrottled(final TemplateSpec templateSpec, final IContext context) { initialize(); new Object[]{TemplateEngine.threadIndex(), templateSpec, context.getLocale()}); new Object[]{TemplateEngine.threadIndex(), templateSpec, context.getLocale()}); final BigDecimal elapsed = BigDecimal.valueOf(endNanos - startNanos); final BigDecimal elapsedMs = elapsed.divide(BigDecimal.valueOf(NANOS_IN_SECOND), RoundingMode.HALF_UP); timerLogger.trace( "[THYMELEAF][{}][{}][{}][{}][{}] TEMPLATE \"{}\" WITH LOCALE {} PREPARED FOR THROTTLED PROCESSING IN {} nanoseconds (approx. {}ms)", logger.error(String.format("[THYMELEAF][%s] Exception preparing throttled template \"%s\": %s", new Object[] {TemplateEngine.threadIndex(), templateSpec, e.getMessage()}), e); throw new TemplateProcessingException("Exception preparing throttled template", templateSpec.toString(), e);
public final void process( final ITemplateContext context, final IComment comment, final ICommentStructureHandler structureHandler) { try { doProcess(context, comment, structureHandler); } catch (final TemplateProcessingException e) { if (comment.hasLocation()) { if (!e.hasTemplateName()) { e.setTemplateName(comment.getTemplateName()); } if (!e.hasLineAndCol()) { e.setLineAndCol(comment.getLine(), comment.getCol()); } } throw e; } catch (final Exception e) { throw new TemplateProcessingException( "Error during execution of processor '" + this.getClass().getName() + "'", comment.getTemplateName(), comment.getLine(), comment.getCol(), e); } }
EscapedAttributeUtils.unescapeAttribute(context.getTemplateMode(), expression); expressionResult = expressionObj.execute(context); } else { expressionResult = null; if (!e.hasTemplateName()) { e.setTemplateName(templateName); if (!e.hasLineAndCol()) { e.setLineAndCol(line, col); throw new TemplateProcessingException( "Error during execution of inlined expression '" + expression + "'", templateName, line, col, e);
static Object executeMinus( final IExpressionContext context, final MinusExpression expression, final StandardExpressionExecutionContext expContext) { if (logger.isTraceEnabled()) { logger.trace("[THYMELEAF][{}] Evaluating minus expression: \"{}\"", TemplateEngine.threadIndex(), expression.getStringRepresentation()); } Object operandValue = expression.getOperand().execute(context, expContext); if (operandValue == null) { operandValue = "null"; } final BigDecimal operandNumberValue = EvaluationUtils.evaluateAsNumber(operandValue); if (operandNumberValue != null) { // Addition will act as a mathematical 'plus' return operandNumberValue.multiply(BigDecimal.valueOf(-1)); } throw new TemplateProcessingException( "Cannot execute minus: operand is \"" + LiteralValue.unwrap(operandValue) + "\""); }
final GreaterOrEqualToExpression expression, final StandardExpressionExecutionContext expContext) { Object leftValue = expression.getLeft().execute(context, expContext); Object rightValue = expression.getRight().execute(context, expContext); result = Boolean.valueOf(leftNumberValue.compareTo(rightNumberValue) != -1); } else { if (leftValue != null && rightValue != null && result = Boolean.valueOf(((Comparable<Object>)leftValue).compareTo(rightValue) >= 0); } else { throw new TemplateProcessingException( "Cannot execute GREATER OR EQUAL TO from Expression \"" + expression.getStringRepresentation() + "\". Left is \"" + new Object[] {TemplateEngine.threadIndex(), expression.getStringRepresentation(), leftValue, rightValue, result});
logger.trace("[THYMELEAF][{}] Evaluating division expression: \"{}\"", TemplateEngine.threadIndex(), expression.getStringRepresentation()); Object leftValue = expression.getLeft().execute(context, expContext); Object rightValue = expression.getRight().execute(context, expContext); if (leftNumberValue != null && rightNumberValue != null) { try { return leftNumberValue.divide(rightNumberValue); } catch (final ArithmeticException ignored) { return leftNumberValue.divide( rightNumberValue, Math.max(Math.max(leftNumberValue.scale(),rightNumberValue.scale()), 10), RoundingMode.HALF_UP); throw new TemplateProcessingException( "Cannot execute division: operands are \"" + LiteralValue.unwrap(leftValue) + "\" and \"" + LiteralValue.unwrap(rightValue) + "\"");
static Object executeMultiplication( final IExpressionContext context, final MultiplicationExpression expression, final StandardExpressionExecutionContext expContext) { if (logger.isTraceEnabled()) { logger.trace("[THYMELEAF][{}] Evaluating multiplication expression: \"{}\"", TemplateEngine.threadIndex(), expression.getStringRepresentation()); } Object leftValue = expression.getLeft().execute(context, expContext); Object rightValue = expression.getRight().execute(context, expContext); if (leftValue == null) { leftValue = "null"; } if (rightValue == null) { rightValue = "null"; } final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue); if (leftNumberValue != null && rightNumberValue != null) { // Addition will act as a mathematical 'plus' return leftNumberValue.multiply(rightNumberValue); } throw new TemplateProcessingException( "Cannot execute multiplication: operands are \"" + LiteralValue.unwrap(leftValue) + "\" and \"" + LiteralValue.unwrap(rightValue) + "\""); }
static Object executeSubtraction( final IExpressionContext context, final SubtractionExpression expression, final StandardExpressionExecutionContext expContext) { if (logger.isTraceEnabled()) { logger.trace("[THYMELEAF][{}] Evaluating subtraction expression: \"{}\"", TemplateEngine.threadIndex(), expression.getStringRepresentation()); } Object leftValue = expression.getLeft().execute(context, expContext); Object rightValue = expression.getRight().execute(context, expContext); if (leftValue == null) { leftValue = "null"; } if (rightValue == null) { rightValue = "null"; } final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue); if (leftNumberValue != null && rightNumberValue != null) { // Addition will act as a mathematical 'plus' return leftNumberValue.subtract(rightNumberValue); } throw new TemplateProcessingException( "Cannot execute subtraction: operands are \"" + LiteralValue.unwrap(leftValue) + "\" and \"" + LiteralValue.unwrap(rightValue) + "\""); }
static Object executeRemainder( final IExpressionContext context, final RemainderExpression expression, final StandardExpressionExecutionContext expContext) { if (logger.isTraceEnabled()) { logger.trace("[THYMELEAF][{}] Evaluating remainder expression: \"{}\"", TemplateEngine.threadIndex(), expression.getStringRepresentation()); } Object leftValue = expression.getLeft().execute(context, expContext); Object rightValue = expression.getRight().execute(context, expContext); if (leftValue == null) { leftValue = "null"; } if (rightValue == null) { rightValue = "null"; } final BigDecimal leftNumberValue = EvaluationUtils.evaluateAsNumber(leftValue); final BigDecimal rightNumberValue = EvaluationUtils.evaluateAsNumber(rightValue); if (leftNumberValue != null && rightNumberValue != null) { // Addition will act as a mathematical 'plus' return leftNumberValue.remainder(rightNumberValue); } throw new TemplateProcessingException( "Cannot execute division: operands are \"" + LiteralValue.unwrap(leftValue) + "\" and \"" + LiteralValue.unwrap(rightValue) + "\""); }
private static Object computeFragment(final ITemplateContext context, final String input) { final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); fragmentExpressionResult = fragmentExpression.execute(context); throw new TemplateProcessingException( "Invalid fragment specification: \"" + input + "\": " + "expression does not return a Fragment object");
EscapedAttributeUtils.unescapeAttribute(context.getTemplateMode(), attribute.getValue()); final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); expressionResult = expression.execute(context, StandardExpressionExecutionContext.RESTRICTED); structureHandler.removeAttribute(attributeName); return; structureHandler.removeAttribute(newAttributeName); structureHandler.removeAttribute(attributeName); } else { if (!e.hasTemplateName()) { e.setTemplateName(tag.getTemplateName()); if (!e.hasLineAndCol()) { e.setLineAndCol(attribute.getLine(), attribute.getCol()); throw new TemplateProcessingException( "Error during execution of processor '" + StandardDefaultAttributesTagProcessor.class.getName() + "'", tag.getTemplateName(), attribute.getLine(), attribute.getCol(), e);
@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()); } }
(StandardSwitchTagProcessor.SwitchStructure) context.getVariable(StandardSwitchTagProcessor.SWITCH_VARIABLE_NAME); throw new TemplateProcessingException( "Cannot specify a \"" + attributeName + "\" attribute in an environment where no " + "switch operator has been defined before."); new Object[] {TemplateEngine.threadIndex(), LoggingUtils.loggifyTemplateName(context.getTemplateData().getTemplate()), attributeValue, attributeName, attributeValue, Boolean.TRUE}); final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); new Object[] {TemplateEngine.threadIndex(), LoggingUtils.loggifyTemplateName(context.getTemplateData().getTemplate()), attributeValue, attributeName, attributeValue, Boolean.valueOf(visible)});
public void handleAutoOpenElementStart( final char[] buffer, final int nameOffset, final int nameLen, final int line, final int col) { throw new TemplateProcessingException("Parse exception during processing of inlining: auto-open not allowed in text mode"); }
throw new TemplateProcessingException("Fragment specifications cannot be empty"); final IEngineConfiguration configuration = context.getConfiguration(); structureHandler.removeElement(); } else { structureHandler.removeBody(); throw new TemplateProcessingException( "Fragment '" + attributeValue + "' specifies synthetic (unnamed) parameters, but the resolved fragment " + "does not match a fragment signature (th:fragment,data-th-fragment) which could apply names to " + if (context.getTemplateMode() != fragmentModel.getTemplateMode()) { throw new TemplateProcessingException( "Template being processed uses template mode " + context.getTemplateMode() + ", " + "inserted fragment \"" + attributeValue + "\" uses template mode " + fragmentModel.getTemplateMode() + ". Cross-template-mode fragment insertion is not " + throw new TemplateProcessingException( "Parameterized fragment insertion is not supported because local variable support is DISABLED. This is due to " + "the use of an implementation of the " + ITemplateContext.class.getName() + " interface that does " + structureHandler.replaceWith(stringWriter.toString(), false); } else { structureHandler.setBody(stringWriter.toString(), false);
@Override protected IInliner getInliner(final ITemplateContext context, final StandardInlineMode inlineMode) { switch (inlineMode) { case NONE: return NoOpInliner.INSTANCE; case XML: return new StandardXMLInliner(context.getConfiguration()); case TEXT: return new StandardTextInliner(context.getConfiguration()); default: throw new TemplateProcessingException( "Invalid inline mode selected: " + inlineMode + ". Allowed inline modes in template mode " + getTemplateMode() + " are: " + "\"" + StandardInlineMode.XML + "\", \"" + StandardInlineMode.TEXT + "\", " + "\"" + StandardInlineMode.NONE + "\""); } }
context, attributeValue, false /* no parameters without value */); if (assignations == null) { throw new TemplateProcessingException( "Could not parse value as attribute assignations: \"" + attributeValue + "\""); final Object leftValue = leftExpr.execute(context, expCtx); final Object rightValue = rightExpr.execute(context, expCtx); throw new TemplateProcessingException( "Attribute name expression evaluated as null or empty: \"" + leftExpr + "\""); structureHandler.setAttribute(newAttributeName, newAttributeName); } else { structureHandler.removeAttribute(newAttributeName); structureHandler.removeAttribute(newAttributeName);
logger.trace("[THYMELEAF][{}] Evaluating message: \"{}\"", TemplateEngine.threadIndex(), expression.getStringRepresentation()); throw new TemplateProcessingException( "Cannot evaluate expression \"" + expression + "\". Message externalization expressions " + "can only be evaluated in a template-processing environment (as a part of an in-template expression) " + Object messageKey = baseExpression.execute(templateContext, expContext); messageKey = LiteralValue.unwrap(messageKey); if (messageKey != null && !(messageKey instanceof String)) { throw new TemplateProcessingException( "Message key for message resolution must be a non-null and non-empty String"); for (int i = 0; i < parameterExpressionValuesLen; i++) { final IStandardExpression parameterExpression = parameterExpressionValues.get(i); final Object result = parameterExpression.execute(templateContext, expContext); messageParameters[i] = LiteralValue.unwrap(result); return templateContext.getMessage(null, (String)messageKey, messageParameters, true);
logger.trace("[THYMELEAF][{}] Evaluating link: \"{}\"", TemplateEngine.threadIndex(), expression.getStringRepresentation()); throw new TemplateProcessingException( "Cannot evaluate expression \"" + expression + "\". Link expressions " + "can only be evaluated in a template-processing environment (as a part of an in-template expression) " + Object base = baseExpression.execute(templateContext, StandardExpressionExecutionContext.RESTRICTED); return templateContext.buildLink((String)base, parameters);
EscapedAttributeUtils.unescapeAttribute(context.getTemplateMode(), tag.getAttributeValue(attributeName)); structureHandler.removeAttribute(attributeName); if (!e.hasTemplateName()) { e.setTemplateName(tag.getTemplateName()); if (!e.hasLineAndCol()) { if (attributeName == null) { e.setLineAndCol(tag.getLine(), tag.getCol()); } else { final IAttribute attribute = tag.getAttribute(attributeName); if (attribute != null) { e.setLineAndCol(attribute.getLine(), attribute.getCol()); throw new TemplateProcessingException( "Error during execution of processor '" + this.getClass().getName() + "'", tag.getTemplateName(), line, col, e);