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