本文整理匯總了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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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();
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}