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