当前位置: 首页>>代码示例>>Java>>正文


Java VelocityEngine.setProperty方法代码示例

本文整理汇总了Java中org.apache.velocity.app.VelocityEngine.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java VelocityEngine.setProperty方法的具体用法?Java VelocityEngine.setProperty怎么用?Java VelocityEngine.setProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.velocity.app.VelocityEngine的用法示例。


在下文中一共展示了VelocityEngine.setProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTemplate1

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
public void testTemplate1() throws Exception {
    VelocityContext context = new VelocityContext();
    MyBean bean = createBean();
    context.put("bean", bean);
    Yaml yaml = new Yaml();
    context.put("list", yaml.dump(bean.getList()));
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty("file.resource.loader.class", ClasspathResourceLoader.class.getName());
    ve.init();
    Template t = ve.getTemplate("template/mybean1.vm");
    StringWriter writer = new StringWriter();
    t.merge(context, writer);
    String output = writer.toString().trim().replaceAll("\\r\\n", "\n");
    // System.out.println(output);
    String etalon = Util.getLocalResource("template/etalon2-template.yaml").trim();
    assertEquals(etalon.length(), output.length());
    assertEquals(etalon, output);
    // parse the YAML document
    Yaml loader = new Yaml();
    MyBean parsedBean = loader.loadAs(output, MyBean.class);
    assertEquals(bean, parsedBean);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:23,代码来源:VelocityTest.java

示例2: setUp

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
@Before
public void setUp() throws TikaException, IOException, SAXException {
    VelocityEngine engine = new VelocityEngine();
    engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    engine.init();

    Templater templater = new Templater();
    templater.setEngine(engine);

    exporter = new HtmlExporter();
    exporter.setTemplater(templater);

    TikaProvider provider = new TikaProvider();
    Tika tika = provider.tika();

    transformer = new TikaTransformer();
    transformer.setTika(tika);
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:20,代码来源:HtmlExporterTest.java

示例3: setUp

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
@Before
public void setUp() throws TikaException, IOException, SAXException {
    VelocityEngine engine = new VelocityEngine();
    engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    engine.init();

    Templater templater = new Templater();
    templater.setEngine(engine);

    exporter = new PdfExporter();
    exporter.setTemplater(templater);

    TikaProvider provider = new TikaProvider();
    Tika tika = provider.tika();

    transformer = new TikaTransformer();
    transformer.setTika(tika);
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:20,代码来源:PdfExporterTest.java

示例4: renderTemplate

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * Return the String representation of the template rendered using Velocity.
 *
 * @param context context use to render the template
 * @param templateFileName file name of the template in the classpath
 * @throws TemplateRenderException if there is an error with the template
 */
public static String renderTemplate(String templateFileName,
                                    VelocityContext context)
    throws TemplateRenderException {
  VelocityEngine ve = new VelocityEngine();
  ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
  ve.setProperty("classpath.resource.loader.class",
      ClasspathResourceLoader.class.getName());

  StringWriter sw = new StringWriter();

  try {
    ve.mergeTemplate(templateFileName, "UTF-8", context, sw);
  } catch (ResourceNotFoundException
      | ParseErrorException
      | MethodInvocationException e) {
    throw new TemplateRenderException("Error rendering template file: " + templateFileName, e);
  }

  return sw.toString();
}
 
开发者ID:airbnb,项目名称:reair,代码行数:28,代码来源:VelocityUtils.java

示例5: SQLGenerator

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
public SQLGenerator(String type) {
    this.type = type;

    this.javaClassGenerator = new JavaClassGenerator();

    velocityEngine = new VelocityEngine();

    velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());

    try {
        velocityEngine.init();
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("VelocityEngine can not initialize.");
        System.exit(0);
    }
}
 
开发者ID:wangdao,项目名称:x-worker,代码行数:19,代码来源:SQLGenerator.java

示例6: initVMEngine

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
private static VelocityEngine initVMEngine()
{
    VelocityEngine ret = new VelocityEngine();
    ret.setProperty("file.resource.loader.path", VM_PATH);
    try
    {
        ret.init();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    return ret;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:15,代码来源:CodeGenerator.java

示例7: init

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
@PostConstruct
public void init() {

    // create velocity engine
    velocityEngine = new VelocityEngine();
    velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    velocityEngine.init();
}
 
开发者ID:chrisipa,项目名称:cloud-portal,代码行数:10,代码来源:VelocityService.java

示例8: setUp

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
@Before
public void setUp() {
    VelocityEngine engine = new VelocityEngine();
    engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    engine.init();

    templater = new Templater();
    templater.setEngine(engine);
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:11,代码来源:TemplaterTest.java

示例9: setUp

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
@Before
public void setUp() throws IOException, TikaException, SAXException {
    MockitoAnnotations.initMocks(this);

    createDirectories(Paths.get("fileTestFiles"));

    docxExporter = new DocxExporter();

    xlsxExporter = new XlsxExporter();

    VelocityEngine engine = new VelocityEngine();
    engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    engine.init();

    templater = new Templater();
    templater.setEngine(engine);

    pdfExporter = new PdfExporter();
    pdfExporter.setTemplater(templater);

    ObjectMapperProducer objectMapperProducer = new ObjectMapperProducer();
    mapper = objectMapperProducer.objectMapper(false, false);

    TikaProvider provider = new TikaProvider();
    Tika tika = provider.tika();

    transformer = new TikaTransformer();
    transformer.setTika(tika);
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:31,代码来源:ReportGeneratorTest.java

示例10: setApplicationContext

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
	this.applicationContext=applicationContext;
	ve = new VelocityEngine();
	ve.setProperty(Velocity.RESOURCE_LOADER, "class");
	ve.setProperty("class.resource.loader.class","org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
	ve.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM,new NullLogChute());
	ve.init();	
}
 
开发者ID:youseries,项目名称:urule,代码行数:10,代码来源:RenderPageServletHandler.java

示例11: initSpringResourceLoader

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * Initialize a SpringResourceLoader for the given VelocityEngine.
 * <p>Called by {@code initVelocityResourceLoader}.
 * @param velocityEngine the VelocityEngine to configure
 * @param resourceLoaderPath the path to load Velocity resources from
 * @see SpringResourceLoader
 * @see #initVelocityResourceLoader
 */
protected void initSpringResourceLoader(VelocityEngine velocityEngine, String resourceLoaderPath) {
	velocityEngine.setProperty(
			RuntimeConstants.RESOURCE_LOADER, SpringResourceLoader.NAME);
	velocityEngine.setProperty(
			SpringResourceLoader.SPRING_RESOURCE_LOADER_CLASS, SpringResourceLoader.class.getName());
	velocityEngine.setProperty(
			SpringResourceLoader.SPRING_RESOURCE_LOADER_CACHE, "true");
	velocityEngine.setApplicationAttribute(
			SpringResourceLoader.SPRING_RESOURCE_LOADER, getResourceLoader());
	velocityEngine.setApplicationAttribute(
			SpringResourceLoader.SPRING_RESOURCE_LOADER_PATH, resourceLoaderPath);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:VelocityEngineFactory.java

示例12: parse

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
public static String parse(String templateFileName, AbstractFileWrapper data) {

        // 初始化模板引擎
        VelocityEngine engine = new VelocityEngine();
        engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
        engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());

        Properties props = new Properties();

        URL resource = VelocityUtil.class.getClassLoader().getResource(".");
        Objects.requireNonNull(resource);

        // 设置模板目录
        String basePath = resource.getPath() + Const.TEMPLATE_LOCATION_DIR;
        props.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,  basePath);
        //设置velocity的编码
        props.setProperty(Velocity.ENCODING_DEFAULT, StandardCharsets.UTF_8.name());
        props.setProperty(Velocity.INPUT_ENCODING,   StandardCharsets.UTF_8.name());
        props.setProperty(Velocity.OUTPUT_ENCODING,  StandardCharsets.UTF_8.name());
        engine.init(props);

        Template template = engine.getTemplate(templateFileName);
        // 设置变量
        VelocityContext ctx = new VelocityContext();

        ctx.put("data", data);

        StringWriter writer = new StringWriter();
        template.merge(ctx, writer);

        return writer.toString();


    }
 
开发者ID:MrHunterZhao,项目名称:CoffeeMaker,代码行数:35,代码来源:VelocityUtil.java

示例13: getTempate

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
public static Template getTempate(String path) {
	VelocityEngine ve = new VelocityEngine();
	ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
	ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
	ve.init();
	Template t = ve.getTemplate(path, "utf-8");
	return t;
}
 
开发者ID:wu191287278,项目名称:sc-generator,代码行数:9,代码来源:VelocityUtil.java

示例14: generateHtmlfile

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
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();
 }
}
 
开发者ID:WillemJiang,项目名称:acmeair,代码行数:28,代码来源:ReportGenerator.java

示例15: velocityEngine

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
@Bean
public VelocityEngine velocityEngine() throws Exception {
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());

    ve.setProperty(Velocity.ENCODING_DEFAULT, DEFAULT_CHARSET.name());
    ve.setProperty(Velocity.INPUT_ENCODING, DEFAULT_CHARSET.name());
    ve.setProperty(Velocity.OUTPUT_ENCODING, DEFAULT_CHARSET.name());

    ve.init();
    return ve;
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:14,代码来源:AppConfig.java


注:本文中的org.apache.velocity.app.VelocityEngine.setProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。