freemarker.template.TemplateNumberModel Java Examples
The following examples show how to use
freemarker.template.TemplateNumberModel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransformUtil.java From scipio-erp with Apache License 2.0 | 6 votes |
/** * Gets string arg. * <p> * If number or date passed, will be coerced to string. Other types such as maps or lists * will throw TemplateModelException. */ public static String getStringArg(TemplateModel obj, String defaultValue, boolean useDefaultWhenEmpty, boolean nonEscaping) throws TemplateModelException { String result = null; if (obj instanceof TemplateScalarModel) { TemplateScalarModel s = (TemplateScalarModel) obj; result = LangFtlUtil.getAsString(s, nonEscaping); } else if (obj == null) { return defaultValue; } else if (obj instanceof TemplateNumberModel || obj instanceof TemplateDateModel) { // TODO: optimize this call result = LangFtlUtil.execStringBuiltIn(obj, FreeMarkerWorker.getCurrentEnvironment()).getAsString(); } else { throw new TemplateModelException("Expected string model or something coercible to string, but got a " + obj.getClass() + " instead"); } if (useDefaultWhenEmpty && result.isEmpty()) { return defaultValue; } return result; }
Example #2
Source File: DirectiveUtils.java From Lottery with GNU General Public License v2.0 | 6 votes |
public static Boolean getBool(String name, Map<String, TemplateModel> params) throws TemplateException { TemplateModel model = params.get(name); if (model == null) { return null; } if (model instanceof TemplateBooleanModel) { return ((TemplateBooleanModel) model).getAsBoolean(); } else if (model instanceof TemplateNumberModel) { return !(((TemplateNumberModel) model).getAsNumber().intValue() == 0); } else if (model instanceof TemplateScalarModel) { String s = ((TemplateScalarModel) model).getAsString(); // 空串应该返回null还是true呢? if (!StringUtils.isBlank(s)) { return !(s.equals("0") || s.equalsIgnoreCase("false") || s .equalsIgnoreCase("f")); } else { return null; } } else { throw new MustBooleanException(name); } }
Example #3
Source File: DirectiveUtils.java From Lottery with GNU General Public License v2.0 | 6 votes |
public static Integer getInt(String name, Map<String, TemplateModel> params) throws TemplateException { TemplateModel model = params.get(name); if (model == null) { return null; } if (model instanceof TemplateScalarModel) { String s = ((TemplateScalarModel) model).getAsString(); if (StringUtils.isBlank(s)) { return null; } try { return Integer.parseInt(s); } catch (NumberFormatException e) { throw new MustNumberException(name); } } else if (model instanceof TemplateNumberModel) { return ((TemplateNumberModel) model).getAsNumber().intValue(); } else { throw new MustNumberException(name); } }
Example #4
Source File: DirectiveUtils.java From Lottery with GNU General Public License v2.0 | 6 votes |
public static Long getLong(String name, Map<String, TemplateModel> params) throws TemplateException { TemplateModel model = params.get(name); if (model == null) { return null; } if (model instanceof TemplateScalarModel) { String s = ((TemplateScalarModel) model).getAsString(); if (StringUtils.isBlank(s)) { return null; } try { return Long.parseLong(s); } catch (NumberFormatException e) { throw new MustNumberException(name); } } else if (model instanceof TemplateNumberModel) { return ((TemplateNumberModel) model).getAsNumber().longValue(); } else { throw new MustNumberException(name); } }
Example #5
Source File: MaskValueMethod.java From scipio-erp with Apache License 2.0 | 6 votes |
@Override public Object exec(@SuppressWarnings("rawtypes") List args) throws TemplateModelException { if (args == null || args.size() < 2 || args.size() > 3) { throw new TemplateModelException("Invalid number of arguments (expected: 2-3)"); } Environment env = FreeMarkerWorker.getCurrentEnvironment(); String str = LangFtlUtil.toRawJavaString((TemplateModel) args.get(0), env); int maskLength = ((TemplateNumberModel) args.get(1)).getAsNumber().intValue(); char maskChar = DEFAULT_MASK_CHAR; if (args.size() >= 3) { String maskCharStr = LangFtlUtil.toRawJavaString(((TemplateModel) args.get(2)), env); if (maskCharStr != null && !maskCharStr.isEmpty()) { maskChar = maskCharStr.charAt(0); } } return doMask(str, maskLength, maskChar); }
Example #6
Source File: InterestNumberFormatFactoryTest.java From robozonky with Apache License 2.0 | 5 votes |
@Test void formattingEnglishRoundingEvenUp() throws TemplateValueFormatException, TemplateModelException { final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> new BigDecimal("0.00055"); final Object result = f.formatToPlainText(m); assertThat(result).isEqualTo("0.06%"); }
Example #7
Source File: GetLogarithmicDistribution.java From windup with Eclipse Public License 1.0 | 5 votes |
@Override public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { if (arguments.size() < 2) throw new TemplateModelException(NAME + ": Expected 2 arguments, count and maximum count."); if (!(arguments.get(0) instanceof TemplateNumberModel)) throw new TemplateModelException(NAME + ": Both arguments must be numbers, but the first was " + arguments.get(0).getClass().getName()); if (!(arguments.get(1) instanceof TemplateNumberModel)) throw new TemplateModelException(NAME + ": Both arguments must be numbers, but the second was " + arguments.get(1).getClass().getName()); int count = ((TemplateNumberModel) arguments.get(0)).getAsNumber().intValue(); if (count < 1) return new SimpleNumber(0); int maximum = ((TemplateNumberModel) arguments.get(1)).getAsNumber().intValue(); if (maximum < 0) throw new TemplateModelException(NAME + "Maximum must be at least 0, " + maximum); if (count > maximum) { LOG.severe("Count " + count + " is larger than maximum " + maximum + ". Using the maximum as count."); count = maximum; } double ratio = ((double)count) / ((double)maximum + QUITE_A_LOT_FACTOR); // <0..1> // Map it to scale 1..1000. double ratio2 = 1.0d + ratio * (998d * (1-FLATTENER)); double log10 = Math.log10(ratio2) / 3D; // 0..2.999 => 0..0.999 //LOG.info(String.format("count: %d, max: %d, ratio %f, ratio2 %f, log10 %f", count, maximum, ratio, ratio2, log10)); return new NumberModel(Double.valueOf(log10), new DefaultObjectWrapper()); }
Example #8
Source File: DirectiveUtils.java From Lottery with GNU General Public License v2.0 | 5 votes |
public static String getString(String name, Map<String, TemplateModel> params) throws TemplateException { TemplateModel model = params.get(name); if (model == null) { return null; } if (model instanceof TemplateScalarModel) { return ((TemplateScalarModel) model).getAsString(); } else if ((model instanceof TemplateNumberModel)) { return ((TemplateNumberModel) model).getAsNumber().toString(); } else { throw new MustStringException(name); } }
Example #9
Source File: ProcessTimeDirective.java From Lottery with GNU General Public License v2.0 | 5 votes |
private long getStartTime(Environment env) throws TemplateModelException { TemplateModel startTime = env.getGlobalVariable(START_TIME); if (startTime == null) { log.warn("Variable '{}' not found in GlobalVariable", START_TIME); return -1; } if (startTime instanceof TemplateNumberModel) { return ((TemplateNumberModel) startTime).getAsNumber().longValue(); } else { throw new MustNumberException(START_TIME); } }
Example #10
Source File: FrontUtils.java From Lottery with GNU General Public License v2.0 | 5 votes |
/** * 标签中获得页码 * * @param env * @return * @throws TemplateException */ public static int getPageNo(Environment env) throws TemplateException { TemplateModel pageNo = env.getGlobalVariable(PAGE_NO); if (pageNo instanceof TemplateNumberModel) { return ((TemplateNumberModel) pageNo).getAsNumber().intValue(); } else { throw new TemplateModelException("'" + PAGE_NO + "' not found in DataModel."); } }
Example #11
Source File: DataReportHelper.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Override public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { if (arguments.size() != 1) { throw new TemplateModelException("Wrong arguments, expected single millisSinceEpoch"); } TemplateNumberModel tnm = (TemplateNumberModel) arguments.get(0); if (tnm == null) { return null; } Long millisSinceEpoch = tnm.getAsNumber().longValue(); DateTime date = new DateTime(millisSinceEpoch, TZ); return date.toString(DATE_PATTERN); }
Example #12
Source File: FtlUtils.java From onetwo with Apache License 2.0 | 5 votes |
public static int getParameterByInt(Map<?, ?> params, String name, int def){ TemplateModel attr = getParameter(params, name, false); if(attr!=null){ try { if(TemplateNumberModel.class.isInstance(attr)){ return ((TemplateNumberModel)attr).getAsNumber().intValue(); }else{ return Integer.parseInt(attr.toString()); } } catch (Exception e) { return def; } } return def; }
Example #13
Source File: InterestNumberFormatFactoryTest.java From robozonky with Apache License 2.0 | 5 votes |
@Test void formattingEnglishRoundingDown() throws TemplateValueFormatException, TemplateModelException { final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> new BigDecimal("0.00051"); final Object result = f.formatToPlainText(m); assertThat(result).isEqualTo("0.05%"); }
Example #14
Source File: InterestNumberFormatFactoryTest.java From robozonky with Apache License 2.0 | 5 votes |
@Test void formattingEnglishRoundingEvenDown() throws TemplateValueFormatException, TemplateModelException { final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> new BigDecimal("0.00025"); final Object result = f.formatToPlainText(m); assertThat(result).isEqualTo("0.02%"); }
Example #15
Source File: CropContentMethod.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * @see freemarker.template.TemplateMethodModel#exec(java.util.List) */ public Object exec(List args) throws TemplateModelException { String result = null; if (args.size() == 2) { Object arg0 = args.get(0); Object arg1 = args.get(1); if (arg0 instanceof BeanModel && arg1 instanceof TemplateNumberModel) { Object wrapped = ((BeanModel)arg0).getWrappedObject(); if (wrapped instanceof TemplateContentData) { int bytes = ((TemplateNumberModel)arg1).getAsNumber().intValue(); try { result = ((TemplateContentData)wrapped).getContentAsText(bytes); } catch (ContentIOException e) { logger.warn("unable to getContentAsText", e); /* * Unable to extract content - return empty text instead. * Probably here through a transformation failure. * This method is called from FreeMarker so throwing the * exception causes problems. */ result = ""; } } } } return result != null ? result : ""; }
Example #16
Source File: InterestNumberFormatFactoryTest.java From robozonky with Apache License 2.0 | 5 votes |
@Test void formattingEnglishRoundingUp() throws TemplateValueFormatException, TemplateModelException { final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> new BigDecimal("0.00049"); final Object result = f.formatToPlainText(m); assertThat(result).isEqualTo("0.05%"); }
Example #17
Source File: InterestNumberFormatFactoryTest.java From robozonky with Apache License 2.0 | 5 votes |
@Test void formattingEnglishLongZero() throws TemplateValueFormatException, TemplateModelException { final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> new BigDecimal("0.000000000000000000"); final Object result = f.formatToPlainText(m); assertThat(result).isEqualTo("0.00%"); }
Example #18
Source File: InterestNumberFormatFactoryTest.java From robozonky with Apache License 2.0 | 5 votes |
@Test void formattingEnglishZero() throws TemplateValueFormatException, TemplateModelException { final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> BigDecimal.ZERO; final Object result = f.formatToPlainText(m); assertThat(result).isEqualTo("0.00%"); }
Example #19
Source File: InterestNumberFormatFactoryTest.java From robozonky with Apache License 2.0 | 5 votes |
@Test void formattingEnglish() throws TemplateValueFormatException, TemplateModelException { final BigDecimal n = new BigDecimal("0.0001"); final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> n; final Object result = f.formatToPlainText(m); assertThat(result).isEqualTo("0.01%"); }
Example #20
Source File: InterestNumberFormatFactoryTest.java From robozonky with Apache License 2.0 | 5 votes |
@DisabledOnJre(JRE.JAVA_8) @Test void formattingCzech3() throws TemplateValueFormatException, TemplateModelException { final BigDecimal n = new BigDecimal("0.001"); final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Defaults.LOCALE, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> n; final String result = f.formatToPlainText(m); assertThat(result.trim()).isEqualTo("0,10" + (char) 160 + "%"); }
Example #21
Source File: InterestNumberFormatFactoryTest.java From robozonky with Apache License 2.0 | 5 votes |
@DisabledOnJre(JRE.JAVA_8) @Test void formattingCzech2() throws TemplateValueFormatException, TemplateModelException { final BigDecimal n = new BigDecimal("0.0000"); final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Defaults.LOCALE, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> n; final String result = f.formatToPlainText(m); assertThat(result.trim()).isEqualTo("0,00" + (char) 160 + "%"); }
Example #22
Source File: InterestNumberFormatFactoryTest.java From robozonky with Apache License 2.0 | 5 votes |
@DisabledOnJre(JRE.JAVA_8) @Test void formattingCzech() throws TemplateValueFormatException, TemplateModelException { final BigDecimal n = new BigDecimal("0.0001"); final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Defaults.LOCALE, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> n; final String result = f.formatToPlainText(m); assertThat(result.trim()).isEqualTo("0,01" + (char) 160 + "%"); }
Example #23
Source File: TransformUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * Gets BigDecimal arg. * <p> * If string or number passed, will be parsed as BigDecimal. Other types such as maps or lists * will throw TemplateModelException. */ public static BigDecimal getBigDecimalArg(TemplateModel obj, BigDecimal defaultValue) throws TemplateModelException, NumberFormatException { if (obj instanceof TemplateNumberModel) { Number number = ((TemplateNumberModel) obj).getAsNumber(); return UtilNumber.toBigDecimal(number); } else if (obj instanceof TemplateScalarModel) { String strResult = LangFtlUtil.getAsString((TemplateScalarModel) obj, true); return strResult.isEmpty() ? defaultValue : UtilNumber.toBigDecimal(strResult); } else if (obj == null) { return defaultValue; } throw new TemplateModelException("Expected BigDecimal model or string representing of BigDecimal, but got a " + obj.getClass() + " instead"); }
Example #24
Source File: TransformUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * Gets integer arg. * <p> * If string passed, will be parsed as integer. Other types such as maps or lists * will throw TemplateModelException. */ public static Double getDoubleArg(TemplateModel obj, Double defaultValue) throws TemplateModelException, NumberFormatException { if (obj instanceof TemplateNumberModel) { return ((TemplateNumberModel) obj).getAsNumber().doubleValue(); } else if (obj instanceof TemplateScalarModel) { String strResult = LangFtlUtil.getAsString((TemplateScalarModel) obj, true); return strResult.isEmpty() ? defaultValue : Double.parseDouble(strResult); } else if (obj == null) { return defaultValue; } throw new TemplateModelException("Expected integer model or string representing of integer, but got a " + obj.getClass() + " instead"); }
Example #25
Source File: TransformUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * Gets integer arg. * <p> * If string passed, will be parsed as integer. Other types such as maps or lists * will throw TemplateModelException. */ public static Integer getIntegerArg(TemplateModel obj, Integer defaultValue) throws TemplateModelException, NumberFormatException { if (obj instanceof TemplateNumberModel) { return ((TemplateNumberModel) obj).getAsNumber().intValue(); } else if (obj instanceof TemplateScalarModel) { String strResult = LangFtlUtil.getAsString((TemplateScalarModel) obj, true); return strResult.isEmpty() ? defaultValue : Integer.parseInt(strResult); } else if (obj == null) { return defaultValue; } throw new TemplateModelException("Expected integer model or string representing of integer, but got a " + obj.getClass() + " instead"); }
Example #26
Source File: LoopDirective.java From pcgen with GNU Lesser General Public License v2.1 | 4 votes |
@SuppressWarnings("rawtypes") @Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { // Check if no parameters were given: int fromVal = 0; Integer toVal = null; int step = 1; for (Object entryObj : params.entrySet()) { Map.Entry entry = (Entry) entryObj; String paramName = (String) entry.getKey(); TemplateModel paramValue = (TemplateModel) entry.getValue(); switch (paramName) { case "from": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } fromVal = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); break; case "to": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } toVal = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); break; case "step": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } step = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); if (step == 0) { throw new TemplateModelException("The \"" + paramName + "\" parameter must not be 0."); } break; default: //Case not caught, should this cause an error? break; } } if (toVal == null) { throw new TemplateModelException("The \"to\" parameter must be provided."); } if (body == null) { throw new TemplateModelException("This directive must have content."); } if (step > 0) { for (int i = fromVal; i <= toVal; i += step) { // Set the loop variable, if there is one: if (loopVars.length > 0) { loopVars[0] = new SimpleNumber(i); } if (loopVars.length > 1) { loopVars[1] = i + step <= toVal ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } // Executes the nested body (same as <#nested> in FTL). In this // case we don't provide a special writer as the parameter: body.render(env.getOut()); } } else { for (int i = fromVal; i >= toVal; i += step) { // Set the loop variable, if there is one: if (loopVars.length > 0) { loopVars[0] = new SimpleNumber(i); } if (loopVars.length > 1) { loopVars[1] = i + step >= toVal ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } // Executes the nested body (same as <#nested> in FTL). In this // case we don't provide a special writer as the parameter: body.render(env.getOut()); } } }
Example #27
Source File: LoopDirective.java From pcgen with GNU Lesser General Public License v2.1 | 4 votes |
@SuppressWarnings("rawtypes") @Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { // Check if no parameters were given: int fromVal = 0; Integer toVal = null; int step = 1; for (Object entryObj : params.entrySet()) { Map.Entry entry = (Entry) entryObj; String paramName = (String) entry.getKey(); TemplateModel paramValue = (TemplateModel) entry.getValue(); switch (paramName) { case "from": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } fromVal = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); break; case "to": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } toVal = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); break; case "step": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } step = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); if (step == 0) { throw new TemplateModelException("The \"" + paramName + "\" parameter must not be 0."); } break; default: //Case not caught, should this cause an error? break; } } if (toVal == null) { throw new TemplateModelException("The \"to\" parameter must be provided."); } if (body == null) { throw new TemplateModelException("This directive must have content."); } if (step > 0) { for (int i = fromVal; i <= toVal; i += step) { // Set the loop variable, if there is one: if (loopVars.length > 0) { loopVars[0] = new SimpleNumber(i); } if (loopVars.length > 1) { loopVars[1] = i + step <= toVal ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } // Executes the nested body (same as <#nested> in FTL). In this // case we don't provide a special writer as the parameter: body.render(env.getOut()); } } else { for (int i = fromVal; i >= toVal; i += step) { // Set the loop variable, if there is one: if (loopVars.length > 0) { loopVars[0] = new SimpleNumber(i); } if (loopVars.length > 1) { loopVars[1] = i + step >= toVal ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } // Executes the nested body (same as <#nested> in FTL). In this // case we don't provide a special writer as the parameter: body.render(env.getOut()); } } }
Example #28
Source File: AbstractMessageFormatTemplateMethod.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Object exec( @SuppressWarnings( "rawtypes" ) List arguments ) throws TemplateModelException { int argsSize = arguments.size( ); if ( argsSize < 1 ) { throw new TemplateModelException( "Must be called with at least one argument (the message key)" ); } String key = ( (TemplateScalarModel) arguments.get( 0 ) ).getAsString( ); Locale locale = Environment.getCurrentEnvironment( ).getLocale( ); if ( argsSize == 1 ) { // no arguments, the message is not a MessageFormat return getPattern( key, locale ); } Object [ ] args = new Object [ argsSize - 1]; for ( int i = 1; i < argsSize; i++ ) { TemplateModel arg = (TemplateModel) arguments.get( i ); if ( arg instanceof TemplateScalarModel ) { args [i - 1] = ( (TemplateScalarModel) arg ).getAsString( ); } else if ( arg instanceof TemplateNumberModel ) { args [i - 1] = ( (TemplateNumberModel) arg ).getAsNumber( ); } else if ( arg instanceof TemplateDateModel ) { args [i - 1] = ( (TemplateDateModel) arg ).getAsDate( ); } else { throw new TemplateModelException( "Unsupported argument type : " + arg ); } } return new MessageFormat( getPattern( key, locale ), locale ).format( args, new StringBuffer( ), null ).toString( ); }
Example #29
Source File: InterestNumberFormatFactory.java From robozonky with Apache License 2.0 | 4 votes |
@Override public String formatToPlainText(final TemplateNumberModel numberModel) throws UnformattableValueException, TemplateModelException { return format.format(TemplateFormatUtil.getNonNullNumber(numberModel)); }
Example #30
Source File: I18NMessageMethod.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * @see freemarker.template.TemplateMethodModel#exec(java.util.List) */ public Object exec(List args) throws TemplateModelException { String result = ""; int argSize = args.size(); if (argSize != 0) { String id = ""; Object arg0 = args.get(0); if (arg0 instanceof TemplateScalarModel) { id = ((TemplateScalarModel)arg0).getAsString(); } if (id != null) { if (argSize == 1) { // shortcut for no additional msg params result = I18NUtil.getMessage(id); } else { Object[] params = new Object[argSize - 1]; for (int i = 0; i < argSize-1; i++) { // ignore first passed-in arg which is the msg id Object arg = args.get(i + 1); if (arg instanceof TemplateScalarModel) { params[i] = ((TemplateScalarModel)arg).getAsString(); } else if (arg instanceof TemplateNumberModel) { params[i] = ((TemplateNumberModel)arg).getAsNumber(); } else if (arg instanceof TemplateDateModel) { params[i] = ((TemplateDateModel)arg).getAsDate(); } else { params[i] = ""; } } result = I18NUtil.getMessage(id, params); } } } return result; }