當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。