/** * Converts a value to plain text {@link String}, even if the {@link TemplateValueFormat} involved normally produces * markup. This should be used rarely, where the user clearly intend to use the plain text variant of the format. * * @param seqTip * Tip to display if the value type is not coercable, but it's sequence or collection. * * @return Never {@code null} */ static String coerceModelToPlainText(TemplateModel tm, Expression exp, String seqTip, Environment env) throws TemplateException { if (tm instanceof TemplateNumberModel) { return assertFormatResultNotNull(env.formatNumberToPlainText((TemplateNumberModel) tm, exp, false)); } else if (tm instanceof TemplateDateModel) { return assertFormatResultNotNull(env.formatDateToPlainText((TemplateDateModel) tm, exp, false)); } else { return coerceModelToTextualCommon(tm, exp, seqTip, false, false, env); } }
/** * Format number with the number format specified as the parameter, with the current locale. * * @param exp * The blamed expression if an error occurs; it's only needed for better error messages */ String formatNumberToPlainText( TemplateNumberModel number, TemplateNumberFormat format, Expression exp, boolean useTempModelExc) throws TemplateException { try { return EvalUtil.assertFormatResultNotNull(format.formatToPlainText(number)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatNumberException(format, exp, e, useTempModelExc); } }
/** * @param tdmSourceExpr * The blamed expression if an error occurs; only used for error messages. */ String formatDateToPlainText(TemplateDateModel tdm, Expression tdmSourceExpr, boolean useTempModelExc) throws TemplateException { TemplateDateFormat format = getTemplateDateFormat(tdm, tdmSourceExpr, useTempModelExc); try { return EvalUtil.assertFormatResultNotNull(format.formatToPlainText(tdm)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatDateException(format, tdmSourceExpr, e, useTempModelExc); } }
/** * @param blamedDateSourceExp * The blamed expression if an error occurs; only used for error messages. * @param blamedFormatterExp * The blamed expression if an error occurs; only used for error messages. */ String formatDateToPlainText(TemplateDateModel tdm, String formatString, Expression blamedDateSourceExp, Expression blamedFormatterExp, boolean useTempModelExc) throws TemplateException { Date date = EvalUtil.modelToDate(tdm, blamedDateSourceExp); TemplateDateFormat format = getTemplateDateFormat( formatString, tdm.getDateType(), date.getClass(), blamedDateSourceExp, blamedFormatterExp, useTempModelExc); try { return EvalUtil.assertFormatResultNotNull(format.formatToPlainText(tdm)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatDateException(format, blamedDateSourceExp, e, useTempModelExc); } }
TemplateNumberFormat format = env.getTemplateNumberFormat(exp, false); try { return assertFormatResultNotNull(format.format(tnm)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatNumberException(format, exp, e, false); TemplateDateFormat format = env.getTemplateDateFormat(tdm, exp, false); try { return assertFormatResultNotNull(format.format(tdm)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatDateException(format, exp, e, false);
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); }
public String getAsString() throws TemplateModelException { if (cachedValue == null) { if (defaultFormat == null) { if (dateModel.getDateType() == TemplateDateModel.UNKNOWN) { throw _MessageUtil.newCantFormatUnknownTypeDateException(target, null); } else { throw new BugException(); } } try { cachedValue = EvalUtil.assertFormatResultNotNull(defaultFormat.formatToPlainText(dateModel)); } catch (TemplateValueFormatException e) { try { throw _MessageUtil.newCantFormatDateException(defaultFormat, target, e, true); } catch (TemplateException e2) { // `e` should always be a TemplateModelException here, but to be sure: throw _CoreAPI.ensureIsTemplateModelException("Failed to format date/time/datetime", e2); } } } return cachedValue; }
/** * Converts a value to plain text {@link String}, even if the {@link TemplateValueFormat} involved normally produces * markup. This should be used rarely, where the user clearly intend to use the plain text variant of the format. * * @param seqTip * Tip to display if the value type is not coercable, but it's sequence or collection. * * @return Never {@code null} */ static String coerceModelToPlainText(TemplateModel tm, Expression exp, String seqTip, Environment env) throws TemplateException { if (tm instanceof TemplateNumberModel) { return assertFormatResultNotNull(env.formatNumberToPlainText((TemplateNumberModel) tm, exp, false)); } else if (tm instanceof TemplateDateModel) { return assertFormatResultNotNull(env.formatDateToPlainText((TemplateDateModel) tm, exp, false)); } else { return coerceModelToTextualCommon(tm, exp, seqTip, false, false, env); } }
/** * Converts a value to plain text {@link String}, even if the {@link TemplateValueFormat} involved normally produces * markup. This should be used rarely, where the user clearly intend to use the plain text variant of the format. * * @param seqTip * Tip to display if the value type is not coercable, but it's sequence or collection. * * @return Never {@code null} */ static String coerceModelToPlainText(TemplateModel tm, Expression exp, String seqTip, Environment env) throws TemplateException { if (tm instanceof TemplateNumberModel) { return assertFormatResultNotNull(env.formatNumberToPlainText((TemplateNumberModel) tm, exp, false)); } else if (tm instanceof TemplateDateModel) { return assertFormatResultNotNull(env.formatDateToPlainText((TemplateDateModel) tm, exp, false)); } else { return coerceModelToTextualCommon(tm, exp, seqTip, false, false, env); } }
/** * Format number with the number format specified as the parameter, with the current locale. * * @param exp * The blamed expression if an error occurs; it's only needed for better error messages */ String formatNumberToPlainText( TemplateNumberModel number, TemplateNumberFormat format, Expression exp, boolean useTempModelExc) throws TemplateException { try { return EvalUtil.assertFormatResultNotNull(format.formatToPlainText(number)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatNumberException(format, exp, e, useTempModelExc); } }
/** * Format number with the number format specified as the parameter, with the current locale. * * @param exp * The blamed expression if an error occurs; it's only needed for better error messages */ String formatNumberToPlainText( TemplateNumberModel number, TemplateNumberFormat format, Expression exp, boolean useTempModelExc) throws TemplateException { try { return EvalUtil.assertFormatResultNotNull(format.formatToPlainText(number)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatNumberException(format, exp, e, useTempModelExc); } }
/** * @param tdmSourceExpr * The blamed expression if an error occurs; only used for error messages. */ String formatDateToPlainText(TemplateDateModel tdm, Expression tdmSourceExpr, boolean useTempModelExc) throws TemplateException { TemplateDateFormat format = getTemplateDateFormat(tdm, tdmSourceExpr, useTempModelExc); try { return EvalUtil.assertFormatResultNotNull(format.formatToPlainText(tdm)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatDateException(format, tdmSourceExpr, e, useTempModelExc); } }
/** * @param tdmSourceExpr * The blamed expression if an error occurs; only used for error messages. */ String formatDateToPlainText(TemplateDateModel tdm, Expression tdmSourceExpr, boolean useTempModelExc) throws TemplateException { TemplateDateFormat format = getTemplateDateFormat(tdm, tdmSourceExpr, useTempModelExc); try { return EvalUtil.assertFormatResultNotNull(format.formatToPlainText(tdm)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatDateException(format, tdmSourceExpr, e, useTempModelExc); } }
/** * @param blamedDateSourceExp * The blamed expression if an error occurs; only used for error messages. * @param blamedFormatterExp * The blamed expression if an error occurs; only used for error messages. */ String formatDateToPlainText(TemplateDateModel tdm, String formatString, Expression blamedDateSourceExp, Expression blamedFormatterExp, boolean useTempModelExc) throws TemplateException { Date date = EvalUtil.modelToDate(tdm, blamedDateSourceExp); TemplateDateFormat format = getTemplateDateFormat( formatString, tdm.getDateType(), date.getClass(), blamedDateSourceExp, blamedFormatterExp, useTempModelExc); try { return EvalUtil.assertFormatResultNotNull(format.formatToPlainText(tdm)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatDateException(format, blamedDateSourceExp, e, useTempModelExc); } }
/** * @param blamedDateSourceExp * The blamed expression if an error occurs; only used for error messages. * @param blamedFormatterExp * The blamed expression if an error occurs; only used for error messages. */ String formatDateToPlainText(TemplateDateModel tdm, String formatString, Expression blamedDateSourceExp, Expression blamedFormatterExp, boolean useTempModelExc) throws TemplateException { Date date = EvalUtil.modelToDate(tdm, blamedDateSourceExp); TemplateDateFormat format = getTemplateDateFormat( formatString, tdm.getDateType(), date.getClass(), blamedDateSourceExp, blamedFormatterExp, useTempModelExc); try { return EvalUtil.assertFormatResultNotNull(format.formatToPlainText(tdm)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatDateException(format, blamedDateSourceExp, e, useTempModelExc); } }
TemplateNumberFormat format = env.getTemplateNumberFormat(exp, false); try { return assertFormatResultNotNull(format.format(tnm)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatNumberException(format, exp, e, false); TemplateDateFormat format = env.getTemplateDateFormat(tdm, exp, false); try { return assertFormatResultNotNull(format.format(tdm)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatDateException(format, exp, e, false);
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); }
public String getAsString() throws TemplateModelException { if (cachedValue == null) { if (defaultFormat == null) { if (dateModel.getDateType() == TemplateDateModel.UNKNOWN) { throw _MessageUtil.newCantFormatUnknownTypeDateException(target, null); } else { throw new BugException(); } } try { cachedValue = EvalUtil.assertFormatResultNotNull(defaultFormat.formatToPlainText(dateModel)); } catch (TemplateValueFormatException e) { try { throw _MessageUtil.newCantFormatDateException(defaultFormat, target, e, true); } catch (TemplateException e2) { // `e` should always be a TemplateModelException here, but to be sure: throw _CoreAPI.ensureIsTemplateModelException("Failed to format date/time/datetime", e2); } } } return cachedValue; }
public String getAsString() throws TemplateModelException { if (cachedValue == null) { if (defaultFormat == null) { if (dateModel.getDateType() == TemplateDateModel.UNKNOWN) { throw _MessageUtil.newCantFormatUnknownTypeDateException(target, null); } else { throw new BugException(); } } try { cachedValue = EvalUtil.assertFormatResultNotNull(defaultFormat.formatToPlainText(dateModel)); } catch (TemplateValueFormatException e) { try { throw _MessageUtil.newCantFormatDateException(defaultFormat, target, e, true); } catch (TemplateException e2) { // `e` should always be a TemplateModelException here, but to be sure: throw _CoreAPI.ensureIsTemplateModelException("Failed to format date/time/datetime", e2); } } } return cachedValue; }