public _TemplateModelException(Throwable cause, Environment env, Object... descriptionParts) { super(cause, env, new _ErrorDescriptionBuilder(descriptionParts), true); }
public _MiscTemplateException(Throwable cause, Environment env, Object... descriptionParts) { super(cause, env, null, new _ErrorDescriptionBuilder(descriptionParts)); }
public _MiscTemplateException(Expression blamed, Throwable cause, Environment env, String description) { super(cause, env, blamed, new _ErrorDescriptionBuilder(description).blame(blamed)); }
public _TemplateModelException(Expression blamed, Throwable cause, Environment env, String description) { super(cause, env, new _ErrorDescriptionBuilder(description).blame(blamed), true); }
public _MiscTemplateException(Expression blamed, Throwable cause, Environment env, Object... descriptionParts) { super(cause, env, blamed, new _ErrorDescriptionBuilder(descriptionParts).blame(blamed)); }
public _TemplateModelException(Expression blamed, Throwable cause, Environment env, Object... descriptionParts) { super(cause, env, new _ErrorDescriptionBuilder(descriptionParts).blame(blamed), true); }
protected InvalidReferenceException newNullPropertyException( String propertyName, TemplateModel tm, Environment env) { if (env.getFastInvalidReferenceExceptions()) { return InvalidReferenceException.FAST_INSTANCE; } else { return new InvalidReferenceException( new _ErrorDescriptionBuilder( "The exteneded hash (of class ", tm.getClass().getName(), ") has returned null for its \"", propertyName, "\" property. This is maybe a bug. The extended hash was returned by this expression:") .blame(target), env, this); } }
public static _TemplateModelException newCantFormatUnknownTypeDateException( Expression dateSourceExpr, UnknownDateTypeFormattingUnsupportedException cause) { return new _TemplateModelException(cause, null, new _ErrorDescriptionBuilder( _MessageUtil.UNKNOWN_DATE_TO_STRING_ERROR_MESSAGE) .blame(dateSourceExpr) .tips(_MessageUtil.UNKNOWN_DATE_TO_STRING_TIPS)); }
protected void checkDateTypeNotUnknown(int dateType) throws TemplateException { if (dateType == TemplateDateModel.UNKNOWN) { throw new _MiscTemplateException(new _ErrorDescriptionBuilder( "The value of the following has unknown date type, but ?", key, " needs a value where it's known if it's a date (no time part), time, or date-time value:" ).blame(target).tip(_MessageUtil.UNKNOWN_DATE_TYPE_ERROR_TIP)); } }
static NonNumericalException newMalformedNumberException(Expression blamed, String text, Environment env) { return new NonNumericalException( new _ErrorDescriptionBuilder("Can't convert this string to number: ", new _DelayedJQuote(text)) .blame(blamed), env); }
static void checkOnlyHasNonRegexpFlags(String biName, long flags, boolean strict) throws _TemplateModelException { if (!strict && !flagWarningsEnabled) return; String flag; if ((flags & RE_FLAG_MULTILINE) != 0) { flag = "m"; } else if ((flags & RE_FLAG_DOTALL) != 0) { flag = "s"; } else if ((flags & RE_FLAG_COMMENTS) != 0) { flag = "c"; } else { return; } final Object[] msg = { "?", biName ," doesn't support the \"", flag, "\" flag " + "without the \"r\" flag." }; if (strict) { throw new _TemplateModelException(msg); } else { // Suppress error for backward compatibility logFlagWarning(new _ErrorDescriptionBuilder(msg).toString()); } }
private TemplateModelException createArgumentTypeMismarchException( int argIdx, TemplateModel argVal, Class targetType) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( _MethodUtil.invocationErrorMessageStart(member), " couldn't be called: Can't convert the ", new _DelayedOrdinal(Integer.valueOf(argIdx + 1)), " argument's value to the target Java type, ", ClassUtil.getShortClassName(targetType), ". The type of the actual value was: ", new _DelayedFTLTypeDescription(argVal)); if (argVal instanceof TemplateMarkupOutputModel && (targetType.isAssignableFrom(String.class))) { desc.tip(MARKUP_OUTPUT_TO_STRING_TIP); } return new _TemplateModelException(desc); }
private _ErrorDescriptionBuilder getNullBooleanFormatErrorDescription() { return new _ErrorDescriptionBuilder( "Can't convert boolean to string automatically, because the \"", BOOLEAN_FORMAT_KEY ,"\" setting was ", new _DelayedJQuote(getBooleanFormat()), (getBooleanFormat().equals(C_TRUE_FALSE) ? ", which is the legacy default computer-language format, and hence isn't accepted." : ".") ).tips( "If you just want \"true\"/\"false\" result as you are generting computer-language output, " + "use \"?c\", like ${myBool?c}.", "You can write myBool?string('yes', 'no') and like to specify boolean formatting in place.", new Object[] { "If you need the same two values on most places, the programmers should set the \"", BOOLEAN_FORMAT_KEY ,"\" setting to something like \"yes,no\"." } ); }
public int size() throws TemplateModelException { throw new _TemplateModelException( new _ErrorDescriptionBuilder( "Getting the number of items or listing the items is not supported on this ", new _DelayedFTLTypeDescription(this), " value, because this value wraps the following Java method, " + "not a real listable value: ", new _DelayedToString(getMember())) .tips( "Maybe you should to call this method first and then do something with its return value.", "obj.someMethod(i) and obj.someMethod[i] does the same for this method, hence it's a " + "\"+sequence\".")); }
public static TemplateModelException newKeyValuePairListingNonStringKeyExceptionMessage( TemplateModel key, TemplateHashModelEx listedHashEx) { return new _TemplateModelException(new _ErrorDescriptionBuilder( "When listing key-value pairs of traditional hash " + "implementations, all keys must be strings, but one of them " + "was ", new _DelayedAOrAn(new _DelayedFTLTypeDescription(key)), "." ).tip("The listed value's TemplateModel class was ", new _DelayedShortClassName(listedHashEx.getClass()), ", which doesn't implement ", new _DelayedShortClassName(TemplateHashModelEx2.class), ", which leads to this restriction.")); }
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); }
public static TemplateException newCantFormatNumberException(TemplateNumberFormat format, Expression dataSrcExp, TemplateValueFormatException e, boolean useTempModelExc) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Failed to format number with format ", new _DelayedJQuote(format.getDescription()), ": ", e.getMessage()) .blame(dataSrcExp); return useTempModelExc ? new _TemplateModelException(e, (Environment) null, desc) : new _MiscTemplateException(e, (Environment) 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); }
/** * Convenience wrapper around {@link #getTemplateNumberFormat(String)} to be called during expression evaluation. * * @param exp * The blamed expression if an error occurs; it's only needed for better error messages */ TemplateNumberFormat getTemplateNumberFormat(String formatString, Expression exp, boolean useTempModelExc) throws TemplateException { TemplateNumberFormat format; try { format = getTemplateNumberFormat(formatString); } catch (TemplateValueFormatException e) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Failed to get number format object for the ", new _DelayedJQuote(formatString), " number format string: ", e.getMessage()) .blame(exp); throw useTempModelExc ? new _TemplateModelException(e, this, desc) : new _MiscTemplateException(e, this, desc); } return format; }
/** * Convenience wrapper around {@link #getTemplateNumberFormat()} to be called during expression evaluation. */ TemplateNumberFormat getTemplateNumberFormat(Expression exp, boolean useTempModelExc) throws TemplateException { TemplateNumberFormat format; try { format = getTemplateNumberFormat(); } catch (TemplateValueFormatException e) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Failed to get number format object for the current number format string, ", new _DelayedJQuote(getNumberFormat()), ": ", e.getMessage()) .blame(exp); throw useTempModelExc ? new _TemplateModelException(e, this, desc) : new _MiscTemplateException(e, this, desc); } return format; }