public SortTool getSortTool() { return new SortTool(); }
/** * 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); } }
/** * 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); } }
/** * 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); } }
context.put("sort", new SortTool()); context.put("number", new NumberTool()); context.put("list", new ListTool());
context.put("date", new ComparisonDateTool()); context.put("list", new ListTool()); context.put(SORT, new SortTool());
public Generator initEngine() { Context context = createEngineContext(); // 添加公共内置对象 context.setProperty(GENERATOR_TOOL, GeneratorUtils.class); context.setProperty(JAVA_CLASS, Class.class); context.setProperty(INLINE_SOURCE, false); velocityEngine = new VelocityEngine(); if(config.useClasspathResourceLoader()){ // 从classpath加载模板 velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "class"); velocityEngine.setProperty("class.resource.loader.description", "Velocity Multi Class path Resource Loader"); //velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); // 使用自定义的 ResourceLoader velocityEngine.setProperty("class.resource.loader.class", MultiClasspathResourceLoader.class.getName()); velocityEngine.setProperty("class.resource.loader.path", config.getTemplateRoot()); }else{ // 从文件系统加载模板 velocityEngine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, config.getTemplateRoot()); } velocityEngine.setProperty(VelocityEngine.INPUT_ENCODING, "UTF-8"); velocityEngine.setProperty(VelocityEngine.OUTPUT_ENCODING, "UTF-8"); velocityContext = new VelocityContext(context.getContext()); // 字符串转义工具 velocityContext.put(VELOCITY_ESC, new EscapeTool()); // 排序工具 velocityContext.put(VELOCITY_SORTER, new SortTool()); return this; }