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 static TemplateModelException newInvocationTemplateModelException( Object parentObject, Object member, boolean isStatic, boolean isConstructor, Throwable e) { while (e instanceof InvocationTargetException) { Throwable cause = ((InvocationTargetException) e).getTargetException(); if (cause != null) { e = cause; } else { break; } } return new _TemplateModelException(e, invocationErrorMessageStart(member, isConstructor), " threw an exception", isStatic || isConstructor ? (Object) "" : new Object[] { " when invoked on ", parentObject.getClass(), " object ", new _DelayedJQuote(parentObject) }, "; see cause exception in the Java stack trace."); }
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); }
@Override TemplateModel calculateResult(String s, Environment env) throws TemplateException { final boolean b; if (s.equals("true")) { b = true; } else if (s.equals("false")) { b = false; } else if (s.equals(env.getTrueStringValue())) { b = true; } else if (s.equals(env.getFalseStringValue())) { b = false; } else { throw new _MiscTemplateException(this, env, "Can't convert this string to boolean: ", new _DelayedJQuote(s)); } return b ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } }
throw new _TemplateModelException(e, "ClassCastException while getting Map entry with String key ", new _DelayedJQuote(key)); } catch (NullPointerException e) { throw new _TemplateModelException(e, "NullPointerException while getting Map entry with String key ", new _DelayedJQuote(key)); throw new _TemplateModelException(e, "ClassCastException while getting Map entry with Character key ", new _DelayedJQuote(key)); } catch (NullPointerException e) { throw new _TemplateModelException(e, "NullPointerException while getting Map entry with Character key ", new _DelayedJQuote(key));
throw new _TemplateModelException(e, "ClassCastException while getting Map entry with String key ", new _DelayedJQuote(key)); } catch (NullPointerException e) { throw new _TemplateModelException(e, "NullPointerException while getting Map entry with String key ", new _DelayedJQuote(key)); throw new _TemplateModelException(e, "Class casting exception while getting Map entry with Character key ", new _DelayedJQuote(charKey)); } catch (NullPointerException e) { throw new _TemplateModelException(e, "NullPointerException while getting Map entry with Character key ", new _DelayedJQuote(charKey));
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); }