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


Java VelocityEngine.init方法代码示例

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


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

示例1: sendEmail

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
private void sendEmail(final String fromEmail, final IUser to, final String inSubject, final String inTemplate, final Map<String, Object> values) {
    final Properties props = new Properties();
    props.setProperty("resource.loader", "class");
    props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

    final VelocityEngine engine = new VelocityEngine(props);
    final VelocityContext context = new VelocityContext();

    engine.init();

    for(final String key : values.keySet()) {
        LOGGER.debug(() -> String.format("\t -- %s=%s", key, values.get(key)));
        context.put(key, values.get(key));
    }

    final StringWriter writer = new StringWriter();
    final Template template = engine.getTemplate("templates/" + inTemplate);

    template.merge(context, writer);

    final String inBody = writer.toString();

    sendEmail(fromEmail, to.getEmail(), inSubject, inBody);
}
 
开发者ID:howma03,项目名称:sporticus,代码行数:25,代码来源:ServiceMailAbstract.java

示例2: 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

示例3: buildStringWriter

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
private static StringWriter buildStringWriter(List<Node> nodes, List<Edge> edges, Map<EVMEnvironment, SymExecutor> executions) throws ReportException {

        VelocityEngine velocityEngine = new VelocityEngine();
        Properties p = new Properties();
        p.setProperty("resource.loader", "class");
        p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        velocityEngine.init(p);
        Template template = velocityEngine.getTemplate(TEMPLATE_FILE);
        VelocityContext velocityContext = new VelocityContext();
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            velocityContext.put("nodes", objectMapper.writeValueAsString(nodes));
            velocityContext.put("edges", objectMapper.writeValueAsString(edges));
            velocityContext.put("executions", executions);
        } catch (IOException e) {
            logger.error("Error building the report: " + e);
            throw new ReportException("Failed creating ReportItem");
        }
        StringWriter stringWriter = new StringWriter();
        template.merge(velocityContext, stringWriter);
        return stringWriter;
    }
 
开发者ID:fergarrui,项目名称:ethereum-bytecode-analyzer,代码行数:23,代码来源:Report.java

示例4: 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

示例5: getInternalEngine

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
protected VelocityEngine getInternalEngine() throws IOException{
	
	VelocityEngine engine = new VelocityEngine();
       
	Properties ps = new Properties();
       ps.setProperty(";runtime.log", Docx4jProperties.getProperty("docx4j.velocity.runtime.log", "velocity.log"));
       ps.setProperty(";runtime.log.logsystem.class", Docx4jProperties.getProperty("docx4j.velocity.runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem"));
       ps.setProperty("resource.loader", Docx4jProperties.getProperty("docx4j.velocity.resource.loader", "file"));
       ps.setProperty("file.resource.loader.cache", Docx4jProperties.getProperty("docx4j.velocity.file.resource.loader.cache", "true"));
       ps.setProperty("file.resource.loader.class ", Docx4jProperties.getProperty("docx4j.velocity.file.resource.loader.class", "Velocity.Runtime.Resource.Loader.FileResourceLoader") );
       ps.setProperty(";resource.loader", Docx4jProperties.getProperty("docx4j.velocity.resource.loader", "webapp"));
       ps.setProperty(";webapp.resource.loader.class", Docx4jProperties.getProperty("docx4j.velocity.webapp.resource.loader.class", "org.apache.velocity.tools.view.servlet.WebappLoader"));
       ps.setProperty(";webapp.resource.loader.cache", Docx4jProperties.getProperty("docx4j.velocity.webapp.resource.loader.cache", "true"));
       ps.setProperty(";webapp.resource.loader.modificationCheckInterval", Docx4jProperties.getProperty("docx4j.velocity.webapp.resource.loader.modificationCheckInterval", "3") );
       ps.setProperty(";directive.foreach.counter.name", Docx4jProperties.getProperty("docx4j.velocity.directive.foreach.counter.name", "velocityCount"));
       ps.setProperty(";directive.foreach.counter.initial.value", Docx4jProperties.getProperty("docx4j.velocity.directive.foreach.counter.initial.value", "1"));
       ps.setProperty("file.resource.loader.path", this.getClass().getResource(Docx4jProperties.getProperty("docx4j.velocity.file.resource.loader.path", "/template")).getPath());
       //模板输入输出编码格式
       String input_charset = Docx4jProperties.getProperty("docx4j.velocity.input.encoding", Docx4jConstants.DEFAULT_CHARSETNAME);
       String output_charset = Docx4jProperties.getProperty("docx4j.velocity.output.encoding", Docx4jConstants.DEFAULT_CHARSETNAME );
       ps.setProperty("input.encoding", input_charset);
       ps.setProperty("output.encoding", output_charset);
       engine.init(ps);
       
       return engine;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:27,代码来源:WordprocessingMLVelocityTemplate.java

示例6: generateHtmlChunks

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
private static List<String> generateHtmlChunks(List<ReportItem> reportItemList) {
  List<String> htmlChunks = new ArrayList<>();

  VelocityEngine velocityEngine = new VelocityEngine();
  Properties p = new Properties();
  p.setProperty("resource.loader", "class");
  p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
  velocityEngine.init(p);
  Template template = velocityEngine.getTemplate("template/report_template.html");

  int maxItemsInReport = CliHelper.getMaxItemsInReport();
  List<List<ReportItem>> reportItemsChunks = Lists.partition(reportItemList, maxItemsInReport);

  for (List<ReportItem> reportItemsChunk : reportItemsChunks ) {
    VelocityContext velocityContext = new VelocityContext();
    velocityContext.put("jarPath", CliHelper.getPathToAnalyze());
    velocityContext.put("ruleName", reportItemsChunk.get(0).getRuleName());
    velocityContext.put("reportItems", reportItemsChunk);

    StringWriter stringWriter = new StringWriter();
    template.merge(velocityContext, stringWriter);
    htmlChunks.add(stringWriter.toString());
  }
  return htmlChunks;
}
 
开发者ID:fergarrui,项目名称:custom-bytecode-analyzer,代码行数:26,代码来源:ReportBuilder.java

示例7: initVelocityEngine

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * initializes the Velocity runtime engine, using default properties plus the properties in the Motu
 * velocity properties file.
 * 
 * @throws Exception
 * 
 * @throws MotuException the motu exception
 */
private void initVelocityEngine() throws Exception {
    velocityEngine = new VelocityEngine();

    Properties conf = new Properties();
    // To disable logs: VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS,
    // "org.apache.velocity.runtime.log.NullLogChute"
    conf.put(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
    conf.put(VelocityEngine.RUNTIME_LOG, System.getProperty("motu-log-dir") + "/velocity.log");
    // conf.put("runtime.log.logsystem.log4j.category", LOG.getName());

    // 1st try to load from the configuration folder,
    // then if not found, load project src/main/resources folder
    conf.put("file.resource.loader.path", BLLManager.getInstance().getConfigManager().getMotuConfigurationFolderPath());
    conf.put("resource.loader", "file, class");
    conf.put("velocimacro.library", "");
    conf.put("directive.foreach.maxloops", "-1");
    conf.put("velocimacro.permissions.allow.inline", "true");
    conf.put("velocimacro.permissions.allow.inline.to.replace.global", "true");
    conf.put("velocimacro.permissions.allow.inline.local.scope", "true");
    conf.put("class.resource.loader.description", "Velocity Classpath Resource Loader");
    conf.put("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

    velocityEngine.init(conf);
}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:33,代码来源:VelocityTemplateManager.java

示例8: 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

示例9: createIndexPage

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * Creates and returns the website's index page.
 * 
 * <p>This is not private only so that it can be unit-tested.
 * 
 * @param redirectUrl the Url of the booking page for the current date.
 * @param showRedirectMessage whether to show a redirect error message to the user
 */
protected String createIndexPage(String redirectUrl, Boolean showRedirectMessage) {

  logger.log("About to create the index page");

  // Create the page by merging the data with the page template
  VelocityEngine engine = new VelocityEngine();
  // Use the classpath loader so Velocity finds our template
  Properties properties = new Properties();
  properties.setProperty("resource.loader", "class");
  properties.setProperty("class.resource.loader.class",
      "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
  engine.init(properties);

  VelocityContext context = new VelocityContext();
  context.put("redirectUrl", redirectUrl);
  context.put("showRedirectMessage", showRedirectMessage);

  // Render the page
  StringWriter writer = new StringWriter();
  Template template = engine.getTemplate("squash/booking/lambdas/IndexPage.vm", "utf-8");
  template.merge(context, writer);
  logger.log("Rendered index page: " + writer);
  return writer.toString();
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:33,代码来源:PageManager.java

示例10: init

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Initialising " + this.toString());

    try {
        Properties properties = new Properties();
        URL url = this.getClass().getClassLoader().getResource("velocity.properties");
        properties.load(url.openStream());

        velocityEngine = new VelocityEngine(properties);
        velocityEngine.init();

    } catch (Exception e) {
        printError("Failed to initialise velocity engine:" + e.toString(), null);
    }
}
 
开发者ID:maxns,项目名称:deltaforce,代码行数:18,代码来源:DeltaBuilderProcessor.java

示例11: 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,项目名称:ureport,代码行数:10,代码来源:RenderPageServletAction.java

示例12: doInit

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
private VelocityEngine doInit(String name) throws IOException {
    Properties props = new Properties();
    props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(name));
    VelocityEngine ve = new VelocityEngine(props);
    ve.init();
    return ve;
}
 
开发者ID:TFdream,项目名称:code-generator,代码行数:8,代码来源:Lemon.java

示例13: testVelocityTemplate

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
@Test
@Ignore
public void testVelocityTemplate() throws IOException, MessagingException {

    Properties props = new Properties();
    props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("velocity.properties"));
    VelocityEngine ve = new VelocityEngine(props);
    ve.init();

    Template t = ve.getTemplate("/templates/registry.vm");
    VelocityContext context = new VelocityContext();

    context.put("username", "ricky");
    context.put("url", "http://www.thymeleaf.org");
    context.put("email", "[email protected]");

    StringWriter sw = new StringWriter(1024);
    t.merge(context, sw);

    String output = sw.toString();
    System.out.println(output);

    Mail mail = Mail.newBuilder().from(from,"ricky fung")
            .to(to)
            .subject("测试邮件[模板邮件-Velocity]")
            .html(output)
            .build();

    client.send(mail);
}
 
开发者ID:TFdream,项目名称:okmail,代码行数:31,代码来源:OkMailClientTest.java

示例14: 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

示例15: 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


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