/** * The type of the argument was good, but the values of two or more arguments are inconsistent with each other. */ public static TemplateModelException newMethodArgsInvalidValueException( String methodName, Object... details) { return new _TemplateModelException(methodName, "(...) arguments have invalid value: ", details); }
/** Signals the buggy case where we have a non-null model, but it wraps a null. */ static TemplateModelException newModelHasStoredNullException( Class expected, TemplateModel model, Expression expr) { return new _TemplateModelException(expr, _TemplateModelException.modelHasStoredNullDescription(expected, model)); }
public int size() throws TemplateModelException { try { return firedEntireInputMatcher.groupCount() + 1; } catch (Exception e) { throw new _TemplateModelException(e, "Failed to get regular expression match group count"); } }
/** Signals the buggy case where we have a non-null model, but it wraps a null. */ static TemplateModelException newModelHasStoredNullException( Class expected, TemplateModel model, Expression expr) { return new _TemplateModelException(expr, _TemplateModelException.modelHasStoredNullDescription(expected, model)); }
/** * The type of the argument was good, but it's value wasn't. */ public static TemplateModelException newMethodArgInvalidValueException( String methodName, int argIdx, Object... details) { return new _TemplateModelException( methodName, "(...) argument #", Integer.valueOf(argIdx + 1), " had invalid value: ", details); }
public TemplateModel next() throws TemplateModelException { try { return (TemplateModel) matchingInputParts.get(nextIdx++); } catch (IndexOutOfBoundsException e) { throw new _TemplateModelException(e, "There were no more regular expression matches"); } } };
public TemplateModel get(int i) throws TemplateModelException { try { return new SimpleScalar(firedEntireInputMatcher.group(i)); } catch (Exception e) { throw new _TemplateModelException(e, "Failed to read regular expression match group"); } }
public Object exec(List args) throws TemplateModelException { if (!args.isEmpty()) { throw new TemplateModelException("This method supports no parameters."); } try { return env.importLib(template, null); } catch (IOException e) { throw new _TemplateModelException(e, "Failed to import loaded template; see cause exception"); } catch (TemplateException e) { throw new _TemplateModelException(e, "Failed to import loaded template; see cause exception"); } } });
public TemplateModel next() throws TemplateModelException { final ArrayList matchingInputParts = RegexMatchModel.this.matchingInputParts; if (matchingInputParts == null) { if (!hasFindInfo) { throw new _TemplateModelException("There were no more regular expression matches"); } MatchWithGroups result = new MatchWithGroups(input, matcher); nextIdx++; hasFindInfo = matcher.find(); return result; } else { try { return (TemplateModel) matchingInputParts.get(nextIdx++); } catch (IndexOutOfBoundsException e) { throw new _TemplateModelException(e, "There were no more regular expression matches"); } } }
double d = Math.round(((Double) num).doubleValue()); if (d > Long.MAX_VALUE || d < Long.MIN_VALUE) { throw new _TemplateModelException( "Number doesn't fit into a 64 bit signed integer (long): ", Double.valueOf(d)); } else { float f = Math.round(((Float) num).floatValue()); if (f > Long.MAX_VALUE || f < Long.MIN_VALUE) { throw new _TemplateModelException( "Number doesn't fit into a 64 bit signed integer (long): ", Float.valueOf(f)); } else { BigDecimal bd = ((BigDecimal) num).setScale(0, BigDecimal.ROUND_HALF_UP); if (bd.compareTo(BIG_DECIMAL_LONG_MAX) > 0 || bd.compareTo(BIG_DECIMAL_LONG_MIN) < 0) { throw new _TemplateModelException("Number doesn't fit into a 64 bit signed integer (long): ", bd); } else { return bd.longValue(); BigInteger bi = (BigInteger) num; if (bi.compareTo(BIG_INTEGER_LONG_MAX) > 0 || bi.compareTo(BIG_INTEGER_LONG_MIN) < 0) { throw new _TemplateModelException("Number doesn't fit into a 64 bit signed integer (long): ", bi); } else { return bi.longValue(); } else { throw new _TemplateModelException("Unsupported number type: ", num.getClass());
public String getAsString() throws TemplateModelException { if (cachedResult == null) { String cs = env.getEffectiveURLEscapingCharset(); if (cs == null) { throw new _TemplateModelException( "To do URL encoding, the framework that encloses FreeMarker must specify the \"", Configuration.OUTPUT_ENCODING_KEY, "\" setting or the \"", Configuration.URL_ESCAPING_CHARSET_KEY, "\" setting, so ask the programmers to set them. Or, as a last chance, you can set the " + "url_encoding_charset setting in the template, e.g. <#setting ", Configuration.URL_ESCAPING_CHARSET_KEY, "='ISO-8859-1'>, or give the charset explicitly to the built-in, e.g. " + "foo?url('ISO-8859-1')."); } try { cachedResult = encodeWithCharset(cs); } catch (UnsupportedEncodingException e) { throw new _TemplateModelException(e, "Failed to execute URL encoding."); } } return cachedResult; }
public Object exec(List args) throws TemplateModelException { checkMethodArgCount(args, 1, 2); int chunkSize = getNumberMethodArg(args, 0).intValue(); if (chunkSize < 1) { throw new _TemplateModelException("The 1st argument to ?", key, " (...) must be at least 1."); } return new ChunkedSequence( tsm, chunkSize, args.size() > 1 ? (TemplateModel) args.get(1) : null); } }
private TemplateDateModel toTemplateDateModel(Object date) throws _TemplateModelException { if (date instanceof Date) { return new SimpleDate((Date) date, dateType); } else { TemplateDateModel tm = (TemplateDateModel) date; if (tm.getDateType() != dateType) { throw new _TemplateModelException("The result of the parsing was of the wrong date type."); } return tm; } }
return new _TemplateModelException(desc.toArray());
public Object exec(List args) throws TemplateModelException { parent.checkMethodArgCount(args.size(), 1); try { return new SimpleScalar(encodeWithCharset((String) args.get(0))); } catch (UnsupportedEncodingException e) { throw new _TemplateModelException(e, "Failed to execute URL encoding."); } }
@Override TemplateModel calculateResult(Number num, TemplateModel model) throws TemplateModelException { final int n; try { n = NumberUtil.toIntExact(num); } catch (ArithmeticException e) { throw new _TemplateModelException(target, "The left side operand value isn't compatible with ?", key, ": ", e.getMessage()); } if (n <= 0) { throw new _TemplateModelException(target, "The left side operand of to ?", key, " must be at least 1, but was ", Integer.valueOf(n), "."); } return new SimpleScalar(toABC(n)); }
Object[] unwrapArguments(List arguments, BeansWrapper wrapper) throws TemplateModelException { if (arguments == null) { arguments = Collections.EMPTY_LIST; } boolean isVarArg = _MethodUtil.isVarargs(member); int typesLen = argTypes.length; if (isVarArg) { if (typesLen - 1 > arguments.size()) { throw new _TemplateModelException( _MethodUtil.invocationErrorMessageStart(member), " takes at least ", Integer.valueOf(typesLen - 1), typesLen - 1 == 1 ? " argument" : " arguments", ", but ", Integer.valueOf(arguments.size()), " was given."); } } else if (typesLen != arguments.size()) { throw new _TemplateModelException( _MethodUtil.invocationErrorMessageStart(member), " takes ", Integer.valueOf(typesLen), typesLen == 1 ? " argument" : " arguments", ", but ", Integer.valueOf(arguments.size()), " was given."); } Object[] args = unwrapArguments(arguments, argTypes, isVarArg, wrapper); return args; }
public boolean contains(TemplateModel item) throws TemplateModelException { Object itemPojo = ((ObjectWrapperAndUnwrapper) getObjectWrapper()).unwrap(item); try { return collection.contains(itemPojo); } catch (ClassCastException e) { throw new _TemplateModelException(e, "Failed to check if the collection contains the item. Probably the item's Java type, ", itemPojo != null ? new _DelayedShortClassName(itemPojo.getClass()) : (Object) "Null", ", doesn't match the type of (some of) the collection items; see cause exception."); } }
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."); }
/** * 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)."); } }