Java 类freemarker.template.SimpleDate 实例源码

项目:luchess    文件:FreemarkerMessageMethod.java   
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException {
    testAtLeastOneArgument(arguments);
    String value = readValue(arguments.get(0));
    MessageFormat formatter = new MessageFormat(value, bundle.getLocale());
    if (arguments.size() == 1) {
        value = formatter.format(new Object[] {});
    } else {
        List<Object> parameters = new ArrayList<>();
        for (Object obj : arguments.subList(1, arguments.size())) {
            if (obj instanceof SimpleNumber) {
                parameters.add(((SimpleNumber) obj).getAsNumber());
            } else if (obj instanceof SimpleDate) {
                parameters.add(((SimpleDate) obj).getAsDate());
            } else {
                parameters.add(obj.toString());
            }
        }
        value = formatter.format(parameters.toArray(), new StringBuffer(), null).toString();
    }
    return value;
}
项目:benerator    文件:DateSumMethod.java   
@Override
@SuppressWarnings("rawtypes")
public TemplateModel exec(List args) {
    long sum = 0;
    for (Object arg : args) {
        arg = LiteralParser.parse((String) arg);
        if (arg instanceof Date)
            sum += ((Date) arg).getTime();
        else if (arg instanceof Timestamp)
            sum += ((Timestamp) arg).getTime();
        else if (arg instanceof Number)
            sum += ((Number) arg).longValue();
        else if (arg != null)
            throw new IllegalArgumentException("Not a supported date type: " + arg.getClass());
    }
    return new SimpleDate(new java.sql.Date(sum));
}
项目:funsteroid    文件:MacroHelper.java   
public static Date getDate(Map params, String paramName){
    SimpleDate valueModel=(SimpleDate)params.get(paramName);
    if (valueModel!=null){
        Date value=valueModel.getAsDate();
        return value;
    }
    return null;
}
项目:luchess    文件:FreemarkerMessageMethodTest.java   
@Test
public void testParamTranslation() throws TemplateModelException, ParseException {
    ResourceBundle bundle = new SimpleBundle("foo", "bar {0} {1} {2}");
    FreemarkerMessageMethod method = new FreemarkerMessageMethod(bundle);
    SimpleNumber simpleNumber = new SimpleNumber(1234567);
    Date date = new Date(new SimpleDateFormat("yyyy-MM-dd hh:mm").parse("2014-03-14 13:11").getTime());
    SimpleDate simpleDate = new SimpleDate(date);
    assertEquals("bar baz 1,234,567 3/14/14 1:11 PM", method.exec(Arrays.asList("foo", "baz", simpleNumber, simpleDate)));
}
项目:pippo    文件:FormatTimeMethod.java   
private Date getFormattableObject(Object value) {
    if (value instanceof SimpleDate) {
        return ((SimpleDate) value).getAsDate();
    } else {
        throw new PippoRuntimeException("Formattable object for FormatTime not found!");
    }
}
项目:pippo    文件:PrettyTimeMethod.java   
private Date getFormattableObject(Object value) {
    if (value instanceof SimpleDate) {
        return ((SimpleDate) value).getAsDate();
    } else {
        throw new PippoRuntimeException("Formattable object for PrettyTime not found!");
    }
}
项目:private-freemarker    文件:SaicObjectWrapper.java   
@SuppressWarnings("rawtypes")
@Override
public TemplateModel wrap(Object obj) throws TemplateModelException {
       if (obj == null) {
           return super.wrap(null);
       }
       if (obj instanceof TemplateModel) {
           return (TemplateModel) obj;
       }
       if (obj instanceof String) {
           return new SimpleScalar((String) obj);
       }
       if (obj instanceof Number) {
           return new SimpleNumber((Number) obj);
       }
       if (obj instanceof java.util.Date) {
           if(obj instanceof java.sql.Date) {
               return new SimpleDate((java.sql.Date) obj);
           }
           if(obj instanceof java.sql.Time) {
               return new SimpleDate((java.sql.Time) obj);
           }
           if(obj instanceof java.sql.Timestamp) {
               return new SimpleDate((java.sql.Timestamp) obj);
           }
           return new SimpleDate((java.util.Date) obj, getDefaultDateType());
       }
       if (obj.getClass().isArray()) {
           obj = convertArray(obj);
       }
       if (obj instanceof Collection) {
           return new SimpleSequence((Collection) obj, this);
       }
       if (obj instanceof Boolean) {
           return obj.equals(Boolean.TRUE) ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE;
       }
       if (obj instanceof Iterator) {
           return new SimpleCollection((Iterator) obj, this);
       }
       return handleUnknownType(obj);
   }
项目:private-freemarker    文件:SaicObjectWrapper.java   
@SuppressWarnings("rawtypes")
@Override
public TemplateModel wrap(Object obj) throws TemplateModelException {
       if (obj == null) {
           return super.wrap(null);
       }
       if (obj instanceof TemplateModel) {
           return (TemplateModel) obj;
       }
       if (obj instanceof String) {
           return new SimpleScalar((String) obj);
       }
       if (obj instanceof Number) {
           return new SimpleNumber((Number) obj);
       }
       if (obj instanceof java.util.Date) {
           if(obj instanceof java.sql.Date) {
               return new SimpleDate((java.sql.Date) obj);
           }
           if(obj instanceof java.sql.Time) {
               return new SimpleDate((java.sql.Time) obj);
           }
           if(obj instanceof java.sql.Timestamp) {
               return new SimpleDate((java.sql.Timestamp) obj);
           }
           return new SimpleDate((java.util.Date) obj, getDefaultDateType());
       }
       if (obj.getClass().isArray()) {
           obj = convertArray(obj);
       }
       if (obj instanceof Collection) {
           return new SimpleSequence((Collection) obj, this);
       }
       if (obj instanceof Boolean) {
           return obj.equals(Boolean.TRUE) ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE;
       }
       if (obj instanceof Iterator) {
           return new SimpleCollection((Iterator) obj, this);
       }
       return handleUnknownType(obj);
   }
项目:benerator    文件:NowMethod.java   
@Override
@SuppressWarnings("rawtypes")
   public TemplateModel exec(List args) {
    return new SimpleDate(new Date(System.currentTimeMillis()));
}