private UnknownSettingException(Environment env, String name, String correctedName) { super(env, "Unknown FreeMarker configuration setting: ", new _DelayedJQuote(name), correctedName == null ? (Object) "" : new Object[] { ". You may meant: ", new _DelayedJQuote(correctedName) }); }
private SettingValueAssignmentException(Environment env, String name, String value, Throwable cause) { super(cause, env, "Failed to set FreeMarker configuration setting ", new _DelayedJQuote(name), " to value ", new _DelayedJQuote(value), "; see cause exception."); }
private static Object[] invocationErrorMessageStart(Object member, boolean isConstructor) { return new Object[] { "Java ", isConstructor ? "constructor " : "method ", new _DelayedJQuote(member) }; }
protected TemplateException invalidSettingValueException(String name, String value) { return new _MiscTemplateException(getEnvironment(), "Invalid value for setting ", new _DelayedJQuote(name), ": ", new _DelayedJQuote(value)); }
/** * @param basePath Maybe {@code null} */ private String resolvePath(String basePath) throws TemplateModelException { try { return env.rootBasedToAbsoluteTemplateName(env.toFullTemplateName(basePath, pathToResolve)); } catch (MalformedTemplateNameException e) { throw new _TemplateModelException(e, "Can't resolve ", new _DelayedJQuote(pathToResolve), "to absolute template name using base ", new _DelayedJQuote(basePath), "; see cause exception"); } }
private boolean getYesNo(Expression exp, String s) throws TemplateException { try { return StringUtil.getYesNo(s); } catch (IllegalArgumentException iae) { throw new _MiscTemplateException(exp, "Value must be boolean (or one of these strings: " + "\"n\", \"no\", \"f\", \"false\", \"y\", \"yes\", \"t\", \"true\"), but it was ", new _DelayedJQuote(s), "."); } }
public TemplateModel get(String key) throws TemplateModelException { try { return getInternal(key); } catch (Exception e) { if (e instanceof TemplateModelException) { throw (TemplateModelException) e; } else { throw new _TemplateModelException(e, "Failed to get valeu for key ", new _DelayedJQuote(key), "; see cause exception."); } } }
/** * Overridden to invoke the getObject method of the resource bundle. */ @Override protected TemplateModel invokeGenericGet(Map keyMap, Class clazz, String key) throws TemplateModelException { try { return wrap(((ResourceBundle) object).getObject(key)); } catch (MissingResourceException e) { throw new _TemplateModelException(e, "No ", new _DelayedJQuote(key), " key in the ResourceBundle. " + "Note that conforming to the ResourceBundle Java API, this is an error and not just " + "a missing sub-variable (a null)."); } }
private Object[] noNodeHandlerDefinedDescription( TemplateNodeModel node, String ns, String nodeType) throws TemplateModelException { String nsPrefix; if (ns != null) { if (ns.length() > 0) { nsPrefix = " and namespace "; } else { nsPrefix = " and no namespace"; } } else { nsPrefix = ""; ns = ""; } return new Object[] { "No macro or directive is defined for node named ", new _DelayedJQuote(node.getNodeName()), nsPrefix, ns, ", and there is no fallback handler called @", nodeType, " either." }; }
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); }
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 TemplateModel _eval(Environment env) throws TemplateException { IterationContext iterCtx = IteratorBlock.findEnclosingIterationContext(env, loopVarName); if (iterCtx == null) { // The parser should prevent this situation throw new _MiscTemplateException( this, env, "There's no iteration in context that uses loop variable ", new _DelayedJQuote(loopVarName), "."); } return calculateResult(iterCtx, env); }
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\"." } ); }
/** * 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(Number number, BackwardCompatibleTemplateNumberFormat format, Expression exp) throws TemplateModelException, _MiscTemplateException { try { return format.format(number); } catch (UnformattableValueException e) { throw new _MiscTemplateException(exp, e, this, "Failed to format number with ", new _DelayedJQuote(format.getDescription()), ": ", e.getMessage()); } }
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); }
private static Object[] unexpectedTypeErrorDescription( String expectedTypesDesc, Expression blamed, String blamedAssignmentTargetVarName, TemplateModel model) { return new Object[] { "Expected ", new _DelayedAOrAn(expectedTypesDesc), ", but ", (blamedAssignmentTargetVarName == null ? (Object) (blamed != null ? "this" : "the expression") : new Object[] { "assignment target variable ", new _DelayedJQuote(blamedAssignmentTargetVarName) }), " has evaluated to ", new _DelayedAOrAn(new _DelayedFTLTypeDescription(model)), (blamed != null ? ":" : ".")}; }
private boolean getBooleanOption(String optionName, TemplateModel value) throws TemplateModelException { if (!(value instanceof TemplateBooleanModel)) { throw _MessageUtil.newMethodArgInvalidValueException(methodName, 1, "The value of the ", new _DelayedJQuote(optionName), " option must be a boolean, but it was ", new _DelayedAOrAn(new _DelayedFTLTypeDescription(value)), "."); } return ((TemplateBooleanModel) value).getAsBoolean(); }
private String getStringOption(String optionName, TemplateModel value) throws TemplateModelException { if (!(value instanceof TemplateScalarModel)) { throw _MessageUtil.newMethodArgInvalidValueException(methodName, 1, "The value of the ", new _DelayedJQuote(optionName), " option must be a string, but it was ", new _DelayedAOrAn(new _DelayedFTLTypeDescription(value)), "."); } return EvalUtil.modelToString((TemplateScalarModel) value, null, null); }