/** * Converts a value to plain text {@link String}, or a {@link TemplateMarkupOutputModel} if that's what the * {@link TemplateValueFormat} involved produces. * * @param seqTip * Tip to display if the value type is not coercable, but it's sequence or collection. * * @return Never {@code null} * @throws TemplateException */ static Object coerceModelToStringOrMarkup(TemplateModel tm, Expression exp, String seqTip, Environment env) throws TemplateException { return coerceModelToStringOrMarkup(tm, exp, false, seqTip, env); }
@Override protected Object calculateInterpolatedStringOrMarkup(Environment env) throws TemplateException { return EvalUtil.coerceModelToStringOrMarkup(escapedExpression.eval(env), escapedExpression, null, env); }
/** * @param seqTip Tip to display if the value type is not coercable, but it's sequence or collection. */ Object evalAndCoerceToStringOrMarkup(Environment env, String seqTip) throws TemplateException { return EvalUtil.coerceModelToStringOrMarkup(eval(env), this, seqTip, env); }
Object evalAndCoerceToStringOrMarkup(Environment env) throws TemplateException { return EvalUtil.coerceModelToStringOrMarkup(eval(env), this, null, env); }
@Override TemplateModel _eval(Environment env) throws TemplateException { TemplateModel tm = target.eval(env); Object moOrStr = EvalUtil.coerceModelToStringOrMarkup(tm, target, null, env); if (moOrStr instanceof String) { return calculateResult((String) moOrStr, env); } else { TemplateMarkupOutputModel<?> mo = (TemplateMarkupOutputModel<?>) moOrStr; if (mo.getOutputFormat().isLegacyBuiltInBypassed(key)) { return mo; } throw new NonStringException(target, tm, env); } }
Object leftOMOrStr = EvalUtil.coerceModelToStringOrMarkup( Object rightOMOrStr = EvalUtil.coerceModelToStringOrMarkup(
@Override protected TemplateModel calculateResult(Environment env) throws TemplateException { TemplateModel lhoTM = target.eval(env); Object lhoMOOrStr = EvalUtil.coerceModelToStringOrMarkup(lhoTM, target, null, env); MarkupOutputFormat contextOF = outputFormat; if (lhoMOOrStr instanceof String) { // TemplateMarkupOutputModel return calculateResult((String) lhoMOOrStr, contextOF, env); } else { TemplateMarkupOutputModel lhoMO = (TemplateMarkupOutputModel) lhoMOOrStr; MarkupOutputFormat lhoOF = lhoMO.getOutputFormat(); // ATTENTION: Keep this logic in sync. with ${...}'s logic! if (lhoOF == contextOF || contextOF.isOutputFormatMixingAllowed()) { // bypass return lhoMO; } else { // ATTENTION: Keep this logic in sync. with ${...}'s logic! String lhoPlainTtext = lhoOF.getSourcePlainText(lhoMO); if (lhoPlainTtext == null) { throw new _TemplateModelException(target, "The left side operand of ?", key, " is in ", new _DelayedToString(lhoOF), " format, which differs from the current output format, ", new _DelayedToString(contextOF), ". Conversion wasn't possible."); } // Here we know that lho is escaped plain text. So we re-escape it to the current format and // bypass it, just as if the two output formats were the same earlier. return contextOF.fromPlainTextByEscaping(lhoPlainTtext); } } }
/** * Converts a value to plain text {@link String}, or a {@link TemplateMarkupOutputModel} if that's what the * {@link TemplateValueFormat} involved produces. * * @param seqTip * Tip to display if the value type is not coercable, but it's sequence or collection. * * @return Never {@code null} * @throws TemplateException */ static Object coerceModelToStringOrMarkup(TemplateModel tm, Expression exp, String seqTip, Environment env) throws TemplateException { return coerceModelToStringOrMarkup(tm, exp, false, seqTip, env); }
/** * Converts a value to plain text {@link String}, or a {@link TemplateMarkupOutputModel} if that's what the * {@link TemplateValueFormat} involved produces. * * @param seqTip * Tip to display if the value type is not coercable, but it's sequence or collection. * * @return Never {@code null} * @throws TemplateException */ static Object coerceModelToStringOrMarkup(TemplateModel tm, Expression exp, String seqTip, Environment env) throws TemplateException { return coerceModelToStringOrMarkup(tm, exp, false, seqTip, env); }
/** * @param seqTip Tip to display if the value type is not coercable, but it's sequence or collection. */ Object evalAndCoerceToStringOrMarkup(Environment env, String seqTip) throws TemplateException { return EvalUtil.coerceModelToStringOrMarkup(eval(env), this, seqTip, env); }
@Override protected Object calculateInterpolatedStringOrMarkup(Environment env) throws TemplateException { return EvalUtil.coerceModelToStringOrMarkup(escapedExpression.eval(env), escapedExpression, null, env); }
/** * @param seqTip Tip to display if the value type is not coercable, but it's sequence or collection. */ Object evalAndCoerceToStringOrMarkup(Environment env, String seqTip) throws TemplateException { return EvalUtil.coerceModelToStringOrMarkup(eval(env), this, seqTip, env); }
@Override protected Object calculateInterpolatedStringOrMarkup(Environment env) throws TemplateException { return EvalUtil.coerceModelToStringOrMarkup(escapedExpression.eval(env), escapedExpression, null, env); }
Object evalAndCoerceToStringOrMarkup(Environment env) throws TemplateException { return EvalUtil.coerceModelToStringOrMarkup(eval(env), this, null, env); }
Object evalAndCoerceToStringOrMarkup(Environment env) throws TemplateException { return EvalUtil.coerceModelToStringOrMarkup(eval(env), this, null, env); }
@Override TemplateModel _eval(Environment env) throws TemplateException { TemplateModel tm = target.eval(env); Object moOrStr = EvalUtil.coerceModelToStringOrMarkup(tm, target, null, env); if (moOrStr instanceof String) { return calculateResult((String) moOrStr, env); } else { TemplateMarkupOutputModel<?> mo = (TemplateMarkupOutputModel<?>) moOrStr; if (mo.getOutputFormat().isLegacyBuiltInBypassed(key)) { return mo; } throw new NonStringException(target, tm, env); } }
@Override TemplateModel _eval(Environment env) throws TemplateException { TemplateModel tm = target.eval(env); Object moOrStr = EvalUtil.coerceModelToStringOrMarkup(tm, target, null, env); if (moOrStr instanceof String) { return calculateResult((String) moOrStr, env); } else { TemplateMarkupOutputModel<?> mo = (TemplateMarkupOutputModel<?>) moOrStr; if (mo.getOutputFormat().isLegacyBuiltInBypassed(key)) { return mo; } throw new NonStringException(target, tm, env); } }
Object leftOMOrStr = EvalUtil.coerceModelToStringOrMarkup( Object rightOMOrStr = EvalUtil.coerceModelToStringOrMarkup(
@Override protected TemplateModel calculateResult(Environment env) throws TemplateException { TemplateModel lhoTM = target.eval(env); Object lhoMOOrStr = EvalUtil.coerceModelToStringOrMarkup(lhoTM, target, null, env); MarkupOutputFormat contextOF = outputFormat; if (lhoMOOrStr instanceof String) { // TemplateMarkupOutputModel return calculateResult((String) lhoMOOrStr, contextOF, env); } else { TemplateMarkupOutputModel lhoMO = (TemplateMarkupOutputModel) lhoMOOrStr; MarkupOutputFormat lhoOF = lhoMO.getOutputFormat(); // ATTENTION: Keep this logic in sync. with ${...}'s logic! if (lhoOF == contextOF || contextOF.isOutputFormatMixingAllowed()) { // bypass return lhoMO; } else { // ATTENTION: Keep this logic in sync. with ${...}'s logic! String lhoPlainTtext = lhoOF.getSourcePlainText(lhoMO); if (lhoPlainTtext == null) { throw new _TemplateModelException(target, "The left side operand of ?", key, " is in ", new _DelayedToString(lhoOF), " format, which differs from the current output format, ", new _DelayedToString(contextOF), ". Conversion wasn't possible."); } // Here we know that lho is escaped plain text. So we re-escape it to the current format and // bypass it, just as if the two output formats were the same earlier. return contextOF.fromPlainTextByEscaping(lhoPlainTtext); } } }
@Override protected TemplateModel calculateResult(Environment env) throws TemplateException { TemplateModel lhoTM = target.eval(env); Object lhoMOOrStr = EvalUtil.coerceModelToStringOrMarkup(lhoTM, target, null, env); MarkupOutputFormat contextOF = outputFormat; if (lhoMOOrStr instanceof String) { // TemplateMarkupOutputModel return calculateResult((String) lhoMOOrStr, contextOF, env); } else { TemplateMarkupOutputModel lhoMO = (TemplateMarkupOutputModel) lhoMOOrStr; MarkupOutputFormat lhoOF = lhoMO.getOutputFormat(); // ATTENTION: Keep this logic in sync. with ${...}'s logic! if (lhoOF == contextOF || contextOF.isOutputFormatMixingAllowed()) { // bypass return lhoMO; } else { // ATTENTION: Keep this logic in sync. with ${...}'s logic! String lhoPlainTtext = lhoOF.getSourcePlainText(lhoMO); if (lhoPlainTtext == null) { throw new _TemplateModelException(target, "The left side operand of ?", key, " is in ", new _DelayedToString(lhoOF), " format, which differs from the current output format, ", new _DelayedToString(contextOF), ". Conversion wasn't possible."); } // Here we know that lho is escaped plain text. So we re-escape it to the current format and // bypass it, just as if the two output formats were the same earlier. return contextOF.fromPlainTextByEscaping(lhoPlainTtext); } } }