@Override protected TemplateModel calculateResult(TemplateMarkupOutputModel model) throws TemplateModelException { return new SimpleScalar(model.getOutputFormat().getMarkupString(model)); }
if (markupResult != null) { TemplateMarkupOutputModel<?> partMO = calcedPart instanceof String ? markupResult.getOutputFormat().fromPlainTextByEscaping((String) calcedPart) : (TemplateMarkupOutputModel<?>) calcedPart; markupResult = EvalUtil.concatMarkupOutputs(this, markupResult, partMO); TemplateMarkupOutputModel<?> moPart = (TemplateMarkupOutputModel<?>) calcedPart; if (plainTextResult != null) { TemplateMarkupOutputModel<?> leftHandMO = moPart.getOutputFormat() .fromPlainTextByEscaping(plainTextResult.toString()); markupResult = EvalUtil.concatMarkupOutputs(this, leftHandMO, moPart);
@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); } }
static boolean isEmpty(TemplateModel model) throws TemplateModelException { if (model instanceof BeanModel) { return ((BeanModel) model).isEmpty(); } else if (model instanceof TemplateSequenceModel) { return ((TemplateSequenceModel) model).size() == 0; } else if (model instanceof TemplateScalarModel) { String s = ((TemplateScalarModel) model).getAsString(); return (s == null || s.length() == 0); } else if (model == null) { return true; } else if (model instanceof TemplateMarkupOutputModel) { // Note: happens just after FTL string check TemplateMarkupOutputModel mo = (TemplateMarkupOutputModel) model; return mo.getOutputFormat().isEmpty(mo); } else if (model instanceof TemplateCollectionModel) { return !((TemplateCollectionModel) model).iterator().hasNext(); } else if (model instanceof TemplateHashModel) { return ((TemplateHashModel) model).isEmpty(); } else if (model instanceof TemplateNumberModel || model instanceof TemplateDateModel || model instanceof TemplateBooleanModel) { return false; } else { return true; } }
private static String ensureFormatResultString(Object formatResult, Expression exp, Environment env) throws NonStringException { if (formatResult instanceof String) { return (String) formatResult; } assertFormatResultNotNull(formatResult); TemplateMarkupOutputModel mo = (TemplateMarkupOutputModel) formatResult; _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Value was formatted to convert it to string, but the result was markup of ouput format ", new _DelayedJQuote(mo.getOutputFormat()), ".") .tip("Use value?string to force formatting to plain text.") .blame(exp); throw new NonStringException(null, desc); }
static TemplateMarkupOutputModel concatMarkupOutputs(TemplateObject parent, TemplateMarkupOutputModel leftMO, TemplateMarkupOutputModel rightMO) throws TemplateException { MarkupOutputFormat leftOF = leftMO.getOutputFormat(); MarkupOutputFormat rightOF = rightMO.getOutputFormat(); if (rightOF != leftOF) { String rightPT; String leftPT; if ((rightPT = rightOF.getSourcePlainText(rightMO)) != null) { return leftOF.concat(leftMO, leftOF.fromPlainTextByEscaping(rightPT)); } else if ((leftPT = leftOF.getSourcePlainText(leftMO)) != null) { return rightOF.concat(rightOF.fromPlainTextByEscaping(leftPT), rightMO); } else { Object[] message = { "Concatenation left hand operand is in ", new _DelayedToString(leftOF), " format, while the right hand operand is in ", new _DelayedToString(rightOF), ". Conversion to common format wasn't possible." }; if (parent instanceof Expression) { throw new _MiscTemplateException((Expression) parent, message); } else { throw new _MiscTemplateException(message); } } } else { return leftOF.concat(leftMO, rightMO); } }
final MarkupOutputFormat moOF = mo.getOutputFormat();
TemplateMarkupOutputModel<?> rightMO = (TemplateMarkupOutputModel<?>) rightOMOrStr; return EvalUtil.concatMarkupOutputs(parent, rightMO.getOutputFormat().fromPlainTextByEscaping((String) leftOMOrStr), rightMO); return EvalUtil.concatMarkupOutputs(parent, leftMO, leftMO.getOutputFormat().fromPlainTextByEscaping((String) rightOMOrStr)); } else { // rightOMOrStr instanceof TemplateMarkupOutputModel return EvalUtil.concatMarkupOutputs(parent,
@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(TemplateMarkupOutputModel model) throws TemplateModelException { return new SimpleScalar(model.getOutputFormat().getMarkupString(model)); }
@Override protected TemplateModel calculateResult(TemplateMarkupOutputModel model) throws TemplateModelException { return new SimpleScalar(model.getOutputFormat().getMarkupString(model)); }
if (markupResult != null) { TemplateMarkupOutputModel<?> partMO = calcedPart instanceof String ? markupResult.getOutputFormat().fromPlainTextByEscaping((String) calcedPart) : (TemplateMarkupOutputModel<?>) calcedPart; markupResult = EvalUtil.concatMarkupOutputs(this, markupResult, partMO); TemplateMarkupOutputModel<?> moPart = (TemplateMarkupOutputModel<?>) calcedPart; if (plainTextResult != null) { TemplateMarkupOutputModel<?> leftHandMO = moPart.getOutputFormat() .fromPlainTextByEscaping(plainTextResult.toString()); markupResult = EvalUtil.concatMarkupOutputs(this, leftHandMO, moPart);
if (markupResult != null) { TemplateMarkupOutputModel<?> partMO = calcedPart instanceof String ? markupResult.getOutputFormat().fromPlainTextByEscaping((String) calcedPart) : (TemplateMarkupOutputModel<?>) calcedPart; markupResult = EvalUtil.concatMarkupOutputs(this, markupResult, partMO); TemplateMarkupOutputModel<?> moPart = (TemplateMarkupOutputModel<?>) calcedPart; if (plainTextResult != null) { TemplateMarkupOutputModel<?> leftHandMO = moPart.getOutputFormat() .fromPlainTextByEscaping(plainTextResult.toString()); markupResult = EvalUtil.concatMarkupOutputs(this, leftHandMO, moPart);
@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); } }
static boolean isEmpty(TemplateModel model) throws TemplateModelException { if (model instanceof BeanModel) { return ((BeanModel) model).isEmpty(); } else if (model instanceof TemplateSequenceModel) { return ((TemplateSequenceModel) model).size() == 0; } else if (model instanceof TemplateScalarModel) { String s = ((TemplateScalarModel) model).getAsString(); return (s == null || s.length() == 0); } else if (model == null) { return true; } else if (model instanceof TemplateMarkupOutputModel) { // Note: happens just after FTL string check TemplateMarkupOutputModel mo = (TemplateMarkupOutputModel) model; return mo.getOutputFormat().isEmpty(mo); } else if (model instanceof TemplateCollectionModel) { return !((TemplateCollectionModel) model).iterator().hasNext(); } else if (model instanceof TemplateHashModel) { return ((TemplateHashModel) model).isEmpty(); } else if (model instanceof TemplateNumberModel || model instanceof TemplateDateModel || model instanceof TemplateBooleanModel) { return false; } else { return true; } }
static boolean isEmpty(TemplateModel model) throws TemplateModelException { if (model instanceof BeanModel) { return ((BeanModel) model).isEmpty(); } else if (model instanceof TemplateSequenceModel) { return ((TemplateSequenceModel) model).size() == 0; } else if (model instanceof TemplateScalarModel) { String s = ((TemplateScalarModel) model).getAsString(); return (s == null || s.length() == 0); } else if (model == null) { return true; } else if (model instanceof TemplateMarkupOutputModel) { // Note: happens just after FTL string check TemplateMarkupOutputModel mo = (TemplateMarkupOutputModel) model; return mo.getOutputFormat().isEmpty(mo); } else if (model instanceof TemplateCollectionModel) { return !((TemplateCollectionModel) model).iterator().hasNext(); } else if (model instanceof TemplateHashModel) { return ((TemplateHashModel) model).isEmpty(); } else if (model instanceof TemplateNumberModel || model instanceof TemplateDateModel || model instanceof TemplateBooleanModel) { return false; } else { return true; } }
private static String ensureFormatResultString(Object formatResult, Expression exp, Environment env) throws NonStringException { if (formatResult instanceof String) { return (String) formatResult; } assertFormatResultNotNull(formatResult); TemplateMarkupOutputModel mo = (TemplateMarkupOutputModel) formatResult; _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Value was formatted to convert it to string, but the result was markup of ouput format ", new _DelayedJQuote(mo.getOutputFormat()), ".") .tip("Use value?string to force formatting to plain text.") .blame(exp); throw new NonStringException(null, desc); }
private static String ensureFormatResultString(Object formatResult, Expression exp, Environment env) throws NonStringException { if (formatResult instanceof String) { return (String) formatResult; } assertFormatResultNotNull(formatResult); TemplateMarkupOutputModel mo = (TemplateMarkupOutputModel) formatResult; _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Value was formatted to convert it to string, but the result was markup of ouput format ", new _DelayedJQuote(mo.getOutputFormat()), ".") .tip("Use value?string to force formatting to plain text.") .blame(exp); throw new NonStringException(null, desc); }
static TemplateMarkupOutputModel concatMarkupOutputs(TemplateObject parent, TemplateMarkupOutputModel leftMO, TemplateMarkupOutputModel rightMO) throws TemplateException { MarkupOutputFormat leftOF = leftMO.getOutputFormat(); MarkupOutputFormat rightOF = rightMO.getOutputFormat(); if (rightOF != leftOF) { String rightPT; String leftPT; if ((rightPT = rightOF.getSourcePlainText(rightMO)) != null) { return leftOF.concat(leftMO, leftOF.fromPlainTextByEscaping(rightPT)); } else if ((leftPT = leftOF.getSourcePlainText(leftMO)) != null) { return rightOF.concat(rightOF.fromPlainTextByEscaping(leftPT), rightMO); } else { Object[] message = { "Concatenation left hand operand is in ", new _DelayedToString(leftOF), " format, while the right hand operand is in ", new _DelayedToString(rightOF), ". Conversion to common format wasn't possible." }; if (parent instanceof Expression) { throw new _MiscTemplateException((Expression) parent, message); } else { throw new _MiscTemplateException(message); } } } else { return leftOF.concat(leftMO, rightMO); } }