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


Java VelocityEngine类代码示例

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


VelocityEngine类属于org.apache.velocity.app包,在下文中一共展示了VelocityEngine类的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: generate

import org.apache.velocity.app.VelocityEngine; //导入依赖的package包/类
/**
 * 根据模板生成文件
 * @param inputVmFilePath 模板路径
 * @param outputFilePath 输出文件路径
 * @param context
 * @throws Exception
 */
public static void generate(String inputVmFilePath, String outputFilePath, VelocityContext context) throws Exception {
	try {
		Properties properties = new Properties();
		properties.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, getPath(inputVmFilePath));
		Velocity.init(properties);
		//VelocityEngine engine = new VelocityEngine();
		Template template = Velocity.getTemplate(getFile(inputVmFilePath), "utf-8");
		File outputFile = new File(outputFilePath);
		FileWriterWithEncoding writer = new FileWriterWithEncoding(outputFile, "utf-8");
		template.merge(context, writer);
		writer.close();
	} catch (Exception ex) {
		throw ex;
	}
}
 
开发者ID:ChangyiHuang,项目名称:shuzheng,代码行数:23,代码来源:VelocityUtil.java

示例3: testApp

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

    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 writer = new StringWriter(1024);
    t.merge(context, writer);

    String output = writer.toString();
    System.out.println(output);
}
 
开发者ID:TFdream,项目名称:okmail,代码行数:23,代码来源:VelocityTest.java

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

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

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

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

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

示例9: postProcessVelocityEngine

import org.apache.velocity.app.VelocityEngine; //导入依赖的package包/类
/**
 * Provides a ClasspathResourceLoader in addition to any default or user-defined
 * loader in order to load the spring Velocity macros from the class path.
 * @see org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
 */
@Override
protected void postProcessVelocityEngine(VelocityEngine velocityEngine) {
	velocityEngine.setApplicationAttribute(ServletContext.class.getName(), this.servletContext);
	velocityEngine.setProperty(
			SPRING_MACRO_RESOURCE_LOADER_CLASS, ClasspathResourceLoader.class.getName());
	velocityEngine.addProperty(
			VelocityEngine.RESOURCE_LOADER, SPRING_MACRO_RESOURCE_LOADER_NAME);
	velocityEngine.addProperty(
			VelocityEngine.VM_LIBRARY, SPRING_MACRO_LIBRARY);

	if (logger.isInfoEnabled()) {
		logger.info("ClasspathResourceLoader with name '" + SPRING_MACRO_RESOURCE_LOADER_NAME +
				"' added to configured VelocityEngine");
	}
}
 
开发者ID:ghimisradu,项目名称:spring-velocity-adapter,代码行数:21,代码来源:VelocityConfigurer.java

示例10: getMessageEncoder

import org.apache.velocity.app.VelocityEngine; //导入依赖的package包/类
/**
 * Build the WebSSO handler for sending and receiving SAML2 messages.
 *
 * @param ctx             the ctx
 * @param spssoDescriptor the spsso descriptor
 * @return the encoder instance
 */
private MessageEncoder getMessageEncoder(final SAML2MessageContext ctx) {

    final Pac4jSAMLResponse adapter = ctx.getProfileRequestContextOutboundMessageTransportResponse();

    if (SAMLConstants.SAML2_POST_BINDING_URI.equals(destinationBindingType)) {

        final VelocityEngine velocityEngine = VelocityEngineFactory.getEngine();
        final Pac4jHTTPPostEncoder encoder = new Pac4jHTTPPostEncoder(adapter);
        encoder.setVelocityEngine(velocityEngine);
        return encoder;
    }

    if (SAMLConstants.SAML2_REDIRECT_BINDING_URI.equals(destinationBindingType)) {
        return new Pac4jHTTPRedirectDeflateEncoder(adapter, forceSignRedirectBindingAuthnRequest);
    }

    throw new UnsupportedOperationException("Binding type - "
            + destinationBindingType + " is not supported");
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:27,代码来源:SAML2WebSSOMessageSender.java

示例11: getEngine

import org.apache.velocity.app.VelocityEngine; //导入依赖的package包/类
public static VelocityEngine getEngine() {

        try {

            final Properties props =
                    new Properties();
            props.putAll(net.shibboleth.utilities.java.support.velocity.VelocityEngine.getDefaultProperties());
            props.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8");
            props.setProperty(RuntimeConstants.OUTPUT_ENCODING, "UTF-8");
            props.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
            props.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, SLF4JLogChute.class.getName());

            final VelocityEngine velocityEngine =
                    net.shibboleth.utilities.java.support.velocity.VelocityEngine
                    .newVelocityEngine(props);
            return velocityEngine;
        } catch (final Exception e) {
            throw new TechnicalException("Error configuring velocity", e);
        }

    }
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:22,代码来源:VelocityEngineFactory.java

示例12: format

import org.apache.velocity.app.VelocityEngine; //导入依赖的package包/类
public static String format(VelocityEngine ve,Reader reader, Object dataModel){
	if(ve == null){
		ve = VlocityFormat.ve;
	}
	Context context = createVelocityContext(dataModel);

	//raw return 
	if(context == null){
		return reader.toString();
	}
	
	StringWriter writer = new StringWriter();
	ve.evaluate(context, writer, "logTag", reader);
	
	return writer.toString();
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:17,代码来源:VlocityFormat.java

示例13: renderNonWebAppTemplate

import org.apache.velocity.app.VelocityEngine; //导入依赖的package包/类
@Test
public void renderNonWebAppTemplate() throws Exception {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
			VelocityAutoConfiguration.class);
	try {
		VelocityEngine velocity = context.getBean(VelocityEngine.class);
		StringWriter writer = new StringWriter();
		Template template = velocity.getTemplate("message.vm");
		template.process();
		VelocityContext velocityContext = new VelocityContext();
		velocityContext.put("greeting", "Hello World");
		template.merge(velocityContext, writer);
		assertThat(writer.toString()).contains("Hello World");
	}
	finally {
		context.close();
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:VelocityAutoConfigurationTests.java

示例14: velocityEngineFactoryBeanWithVelocityProperties

import org.apache.velocity.app.VelocityEngine; //导入依赖的package包/类
@Test
public void velocityEngineFactoryBeanWithVelocityProperties() throws VelocityException, IOException {
	VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
	Properties props = new Properties();
	props.setProperty("myprop", "/mydir");
	vefb.setVelocityProperties(props);
	Object value = new Object();
	Map<String, Object> map = new HashMap<>();
	map.put("myentry", value);
	vefb.setVelocityPropertiesMap(map);
	vefb.afterPropertiesSet();
	assertThat(vefb.getObject(), instanceOf(VelocityEngine.class));
	VelocityEngine ve = vefb.getObject();
	assertEquals("/mydir", ve.getProperty("myprop"));
	assertEquals(value, ve.getProperty("myentry"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:VelocityConfigurerTests.java

示例15: renderSchema

import org.apache.velocity.app.VelocityEngine; //导入依赖的package包/类
private void renderSchema(PrismSchema schema, PrismContext prismContext, VelocityEngine velocityEngine, PathGenerator pathGenerator) throws IOException {
    getLog().info("Processing schema: "+schema);
    VelocityContext velocityContext = new VelocityContext();
    populateVelocityContextBase(velocityContext, prismContext, pathGenerator, schema, "..");

    Template template = velocityEngine.getTemplate(TEMPLATE_SCHEMA_NAME);

    Writer writer = new FileWriter(pathGenerator.prepareSchemaOutputFile(schema));
    template.merge(velocityContext, writer);
    writer.close();

    // Object Definitions
    for (PrismObjectDefinition objectDefinition: schema.getObjectDefinitions()) {
        renderObjectDefinition(objectDefinition, schema, prismContext, velocityEngine, pathGenerator);
    }

    // Types
    for (ComplexTypeDefinition typeDefinition : schema.getComplexTypeDefinitions()) {
        renderComplexTypeDefinition(typeDefinition, schema, prismContext, velocityEngine, pathGenerator);
    }

}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:23,代码来源:SchemaDocMojo.java


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