/** * 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); }
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"); } }
/** * 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"); } } });
/** 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 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; } }
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."); } }
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 TemplateModelException createNullToPrimitiveArgumentException(int argIdx, Class targetType) { return new _TemplateModelException( _MethodUtil.invocationErrorMessageStart(member), " couldn't be called: The value of the ", new _DelayedOrdinal(Integer.valueOf(argIdx + 1)), " argument was null, but the target Java parameter type (", ClassUtil.getShortClassName(targetType), ") is primitive and so can't store null."); }
/** * The work around the problematic cases where we should throw a {@link TemplateException}, but we are inside * a {@link TemplateModel} method and so we can only throw {@link TemplateModelException}-s. */ public static TemplateModelException ensureIsTemplateModelException(String modelOpMsg, TemplateException e) { if (e instanceof TemplateModelException) { return (TemplateModelException) e; } else { return new _TemplateModelException( _TemplateAPI.getBlamedExpression(e), e.getCause(), e.getEnvironment(), modelOpMsg); } }
final public TemplateModel get(int index) throws TemplateModelException { if (index < 0 || index >= size()) { throw new _TemplateModelException("Range item index ", Integer.valueOf(index), " is out of bounds."); } long value = begin + getStep() * (long) index; return value <= Integer.MAX_VALUE ? new SimpleNumber((int) value) : new SimpleNumber(value); }
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)); }
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); }
public static TemplateModelException newMethodArgUnexpectedTypeException( String methodName, int argIdx, String expectedType, TemplateModel arg) { return new _TemplateModelException( methodName, "(...) expects ", new _DelayedAOrAn(expectedType), " as argument #", Integer.valueOf(argIdx + 1), ", but received ", new _DelayedAOrAn(new _DelayedFTLTypeDescription(arg)), "."); }
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 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() : ""); } }
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\".")); }