Java 类org.apache.velocity.tools.generic.ComparisonDateTool 实例源码

项目:acmeair    文件:ReportGenerator.java   
private void generateHtmlfile(Map<String, Object> input) {     
 try{
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    ve.setProperty("classpath.resource.loader.class",ClasspathResourceLoader.class.getName());
    ve.init();
    Template template = ve.getTemplate("templates/acmeair-report.vtl");
    VelocityContext context = new VelocityContext();


    for(Map.Entry<String, Object> entry: input.entrySet()){
        context.put(entry.getKey(), entry.getValue());
    }
    context.put("math", new MathTool());
    context.put("number", new NumberTool());
    context.put("date", new ComparisonDateTool());

    Writer file = new FileWriter(new File(searchingLocation
    + System.getProperty("file.separator") + RESULTS_FILE));        
    template.merge( context, file );
    file.flush();
    file.close();

 }catch(Exception e){
    e.printStackTrace();
 }
}
项目:kc-rice    文件:VelocityTemplateEngine.java   
/**
 * Initializes Velocity engine
 */
private void init() {
       velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "class");
       velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
       setLogFile();

       DateTool dateTool = new DateTool();
       dateTool.configure(this.configMap);
       MathTool mathTool = new MathTool();
       NumberTool numberTool = new NumberTool();
       numberTool.configure(this.configMap);
       SortTool sortTool = new SortTool();

       defaultContext = new VelocityContext();
       defaultContext.put("dateTool", dateTool);
       defaultContext.put("dateComparisonTool", new ComparisonDateTool());
       defaultContext.put("mathTool", mathTool);
       defaultContext.put("numberTool", numberTool);
       defaultContext.put("sortTool", sortTool);
       // Following tools need VelocityTools version 2.0+
       //defaultContext.put("displayTool", new DisplayTool());
       //defaultContext.put("xmlTool", new XmlTool());

       try {
        velocityEngine.init();
    } catch (Exception e) {
        throw new VelocityException(e);
    }
}
项目:rice    文件:VelocityTemplateEngine.java   
/**
 * Initializes Velocity engine
 */
private void init() {
       velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "class");
       velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
       setLogFile();

       DateTool dateTool = new DateTool();
       dateTool.configure(this.configMap);
       MathTool mathTool = new MathTool();
       NumberTool numberTool = new NumberTool();
       numberTool.configure(this.configMap);
       SortTool sortTool = new SortTool();

       defaultContext = new VelocityContext();
       defaultContext.put("dateTool", dateTool);
       defaultContext.put("dateComparisonTool", new ComparisonDateTool());
       defaultContext.put("mathTool", mathTool);
       defaultContext.put("numberTool", numberTool);
       defaultContext.put("sortTool", sortTool);
       // Following tools need VelocityTools version 2.0+
       //defaultContext.put("displayTool", new DisplayTool());
       //defaultContext.put("xmlTool", new XmlTool());

       try {
        velocityEngine.init();
    } catch (Exception e) {
        throw new VelocityException(e);
    }
}