/** * Formats the model to markup instead of to plain text if the result markup will be more than just plain text * escaped, otherwise falls back to formatting to plain text. If the markup result would be just the result of * {@link #formatToPlainText(TemplateDateModel)} escaped, it must return the {@link String} that * {@link #formatToPlainText(TemplateDateModel)} does. * * <p>The implementation in {@link TemplateDateFormat} simply calls {@link #formatToPlainText(TemplateDateModel)}. * * @return A {@link String} or a {@link TemplateMarkupOutputModel}; not {@code null}. */ public Object format(TemplateDateModel dateModel) throws TemplateValueFormatException, TemplateModelException { return formatToPlainText(dateModel); }
private Object parse(TemplateDateFormat df) throws TemplateModelException { try { return df.parse(text, dateType); } catch (TemplateValueFormatException e) { throw new _TemplateModelException(e, "The string doesn't match the expected date/time/date-time format. " + "The string to parse was: ", new _DelayedJQuote(text), ". ", "The expected format was: ", new _DelayedJQuote(df.getDescription()), ".", e.getMessage() != null ? "\nThe nested reason given follows:\n" : "", e.getMessage() != null ? e.getMessage() : ""); } }
@Override public void setLocale(Locale locale) { Locale prevLocale = getLocale(); super.setLocale(locale); if (!locale.equals(prevLocale)) { cachedTemplateNumberFormats = null; if (cachedTemplateNumberFormat != null && cachedTemplateNumberFormat.isLocaleBound()) { cachedTemplateNumberFormat = null; } if (cachedTempDateFormatArray != null) { for (int i = 0; i < CACHED_TDFS_LENGTH; i++) { final TemplateDateFormat f = cachedTempDateFormatArray[i]; if (f != null && f.isLocaleBound()) { cachedTempDateFormatArray[i] = null; } } } cachedTempDateFormatsByFmtStrArray = null; cachedCollator = null; } }
@Override public void setTimeZone(TimeZone timeZone) { TimeZone prevTimeZone = getTimeZone(); super.setTimeZone(timeZone); if (!timeZone.equals(prevTimeZone)) { if (cachedTempDateFormatArray != null) { for (int i = 0; i < CACHED_TDFS_SQL_D_T_TZ_OFFS; i++) { TemplateDateFormat f = cachedTempDateFormatArray[i]; if (f != null && f.isTimeZoneBound()) { cachedTempDateFormatArray[i] = null; } } } if (cachedTempDateFormatsByFmtStrArray != null) { for (int i = 0; i < CACHED_TDFS_SQL_D_T_TZ_OFFS; i++) { cachedTempDateFormatsByFmtStrArray[i] = null; } } cachedSQLDateAndTimeTimeZoneSameAsNormal = null; } }
TemplateDateFormat format = env.getTemplateDateFormat(tdm, exp, false); try { return assertFormatResultNotNull(format.format(tdm)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatDateException(format, exp, e, false);
public static TemplateException newCantFormatDateException(TemplateDateFormat format, Expression dataSrcExp, TemplateValueFormatException e, boolean useTempModelExc) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Failed to format date/time/datetime with format ", new _DelayedJQuote(format.getDescription()), ": ", e.getMessage()) .blame(dataSrcExp); return useTempModelExc ? new _TemplateModelException(e, (Environment) null, desc) : new _MiscTemplateException(e, (Environment) null, desc); }
@Override public void setSQLDateAndTimeTimeZone(TimeZone timeZone) { TimeZone prevTimeZone = getSQLDateAndTimeTimeZone(); super.setSQLDateAndTimeTimeZone(timeZone); if (!nullSafeEquals(timeZone, prevTimeZone)) { if (cachedTempDateFormatArray != null) { for (int i = CACHED_TDFS_SQL_D_T_TZ_OFFS; i < CACHED_TDFS_LENGTH; i++) { TemplateDateFormat format = cachedTempDateFormatArray[i]; if (format != null && format.isTimeZoneBound()) { cachedTempDateFormatArray[i] = null; } } } if (cachedTempDateFormatsByFmtStrArray != null) { for (int i = CACHED_TDFS_SQL_D_T_TZ_OFFS; i < CACHED_TDFS_LENGTH; i++) { cachedTempDateFormatsByFmtStrArray[i] = null; } } cachedSQLDateAndTimeTimeZoneSameAsNormal = null; } }
TemplateDateFormat format = env.getTemplateDateFormat(tdm, exp, false); try { return ensureFormatResultString(format.format(tdm), exp, env); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatDateException(format, exp, e, false);
public static TemplateException newCantFormatDateException(TemplateDateFormat format, Expression dataSrcExp, TemplateValueFormatException e, boolean useTempModelExc) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Failed to format date/time/datetime with format ", new _DelayedJQuote(format.getDescription()), ": ", e.getMessage()) .blame(dataSrcExp); return useTempModelExc ? new _TemplateModelException(e, (Environment) null, desc) : new _MiscTemplateException(e, (Environment) null, desc); }
/** * @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); } }
private Object parse(TemplateDateFormat df) throws TemplateModelException { try { return df.parse(text, dateType); } catch (TemplateValueFormatException e) { throw new _TemplateModelException(e, "The string doesn't match the expected date/time/date-time format. " + "The string to parse was: ", new _DelayedJQuote(text), ". ", "The expected format was: ", new _DelayedJQuote(df.getDescription()), ".", e.getMessage() != null ? "\nThe nested reason given follows:\n" : "", e.getMessage() != null ? e.getMessage() : ""); } }
@Override public void setTimeZone(TimeZone timeZone) { TimeZone prevTimeZone = getTimeZone(); super.setTimeZone(timeZone); if (!timeZone.equals(prevTimeZone)) { if (cachedTempDateFormatArray != null) { for (int i = 0; i < CACHED_TDFS_SQL_D_T_TZ_OFFS; i++) { TemplateDateFormat f = cachedTempDateFormatArray[i]; if (f != null && f.isTimeZoneBound()) { cachedTempDateFormatArray[i] = null; } } } if (cachedTempDateFormatsByFmtStrArray != null) { for (int i = 0; i < CACHED_TDFS_SQL_D_T_TZ_OFFS; i++) { cachedTempDateFormatsByFmtStrArray[i] = null; } } cachedSQLDateAndTimeTimeZoneSameAsNormal = null; } }
TemplateDateFormat format = env.getTemplateDateFormat(tdm, exp, false); try { return assertFormatResultNotNull(format.format(tdm)); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatDateException(format, exp, e, false);
public static TemplateException newCantFormatDateException(TemplateDateFormat format, Expression dataSrcExp, TemplateValueFormatException e, boolean useTempModelExc) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Failed to format date/time/datetime with format ", new _DelayedJQuote(format.getDescription()), ": ", e.getMessage()) .blame(dataSrcExp); return useTempModelExc ? new _TemplateModelException(e, (Environment) null, desc) : new _MiscTemplateException(e, (Environment) null, desc); }
@Override public void setLocale(Locale locale) { Locale prevLocale = getLocale(); super.setLocale(locale); if (!locale.equals(prevLocale)) { cachedTemplateNumberFormats = null; if (cachedTemplateNumberFormat != null && cachedTemplateNumberFormat.isLocaleBound()) { cachedTemplateNumberFormat = null; } if (cachedTempDateFormatArray != null) { for (int i = 0; i < CACHED_TDFS_LENGTH; i++) { final TemplateDateFormat f = cachedTempDateFormatArray[i]; if (f != null && f.isLocaleBound()) { cachedTempDateFormatArray[i] = null; } } } cachedTempDateFormatsByFmtStrArray = null; cachedCollator = null; } }
/** * @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); } }
private Object parse(TemplateDateFormat df) throws TemplateModelException { try { return df.parse(text, dateType); } catch (TemplateValueFormatException e) { throw new _TemplateModelException(e, "The string doesn't match the expected date/time/date-time format. " + "The string to parse was: ", new _DelayedJQuote(text), ". ", "The expected format was: ", new _DelayedJQuote(df.getDescription()), ".", e.getMessage() != null ? "\nThe nested reason given follows:\n" : "", e.getMessage() != null ? e.getMessage() : ""); } }
@Override public void setTimeZone(TimeZone timeZone) { TimeZone prevTimeZone = getTimeZone(); super.setTimeZone(timeZone); if (!timeZone.equals(prevTimeZone)) { if (cachedTempDateFormatArray != null) { for (int i = 0; i < CACHED_TDFS_SQL_D_T_TZ_OFFS; i++) { TemplateDateFormat f = cachedTempDateFormatArray[i]; if (f != null && f.isTimeZoneBound()) { cachedTempDateFormatArray[i] = null; } } } if (cachedTempDateFormatsByFmtStrArray != null) { for (int i = 0; i < CACHED_TDFS_SQL_D_T_TZ_OFFS; i++) { cachedTempDateFormatsByFmtStrArray[i] = null; } } cachedSQLDateAndTimeTimeZoneSameAsNormal = null; } }
TemplateDateFormat format = env.getTemplateDateFormat(tdm, exp, false); try { return ensureFormatResultString(format.format(tdm), exp, env); } catch (TemplateValueFormatException e) { throw _MessageUtil.newCantFormatDateException(format, exp, e, false);
@Override public void setLocale(Locale locale) { Locale prevLocale = getLocale(); super.setLocale(locale); if (!locale.equals(prevLocale)) { cachedTemplateNumberFormats = null; if (cachedTemplateNumberFormat != null && cachedTemplateNumberFormat.isLocaleBound()) { cachedTemplateNumberFormat = null; } if (cachedTempDateFormatArray != null) { for (int i = 0; i < CACHED_TDFS_LENGTH; i++) { final TemplateDateFormat f = cachedTempDateFormatArray[i]; if (f != null && f.isLocaleBound()) { cachedTempDateFormatArray[i] = null; } } } cachedTempDateFormatsByFmtStrArray = null; cachedCollator = null; } }