velocity

我的关于 Velocity 的文章在 IBM 上发表了

亡梦爱人 提交于 2019-12-05 17:39:52
编写自定义的 Velocity 指令 Velocity 是一个高效、简洁的 Java 模板引擎,而且有很好的可扩展性,这使之特别适合在 Web 项目中使用。本文通过一个实际应用例子对 Velocity 的模板语言中的指令系统进行了介绍,并演示了如何通过编写自定义的指令来扩展 Velocity 的功能。 这篇文章写了也有一两个月了,感觉最近 IBM 的文章发表效率有点低,不像以前,如果决定采用一篇文章后,一般两三个星期就可以看到,但现在就很难说了,同事的一篇cacti的文章是去年过年前提交的,到前两天才发出来。 来源: oschina 链接: https://my.oschina.net/u/12/blog/504

Velocity, different template paths

无人久伴 提交于 2019-12-05 15:08:45
问题 Does anyone know if it is possible to get templates from different paths with velocity? After initialization Velocity refuses to change the "file.resource.loader.path". This is my code: public Generator(){ Properties p = new Properties(); p.setProperty("resource.loader", "file"); p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader"); p.setProperty("file.resource.loader.path", ""); Velocity.init(p); } The templates can be located in

复合和继承

核能气质少年 提交于 2019-12-05 15:07:29
这里举一个继承的初始化例子 // reuse/Detergent.java // (c)2017 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://OnJava8.com for more book information. // Inheritance syntax & properties class Cleanser { private String s = "Cleanser"; public void append(String a) { s += a; } public void dilute() { append(" dilute()"); } public void apply() { append(" apply()"); } public void scrub() { append(" scrub()"); } @Override public String toString() { return s; } public static void main(String[] args) { Cleanser x = new Cleanser(); x.dilute(); x.apply();

Eclipse AutoValue class fails to build

走远了吗. 提交于 2019-12-05 12:11:24
I'm running Eclipse Kepler SR2, with Maven 3.1.1 attached with the m2e and m2e-apt plugins, and I'm getting an error I don't know how to resolve. I managed to find all the dependencies needed to get @AutoValue working into my pom.xml, but now I'm in a state where it only works if the methods which need to be defined all have primitive return types. If I provide an abstract getter which returns an Object or more specific, I get this error: @AutoValue processor threw an exception: java.lang.IllegalArgumentException: Failed to invoke com.google.auto.value.processor.AutoValueProcessor$Property

Using Velocity Tools with Spring 3.0.3

独自空忆成欢 提交于 2019-12-05 11:19:04
When I update the bean: <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> <property name="cache" value="true"/> <property name="prefix" value=""/> <property name="suffix" value=".vm"/> <property name="toolboxConfigLocation" value="tools.xml" /> </bean> With the tools.xml path for Velocity Tools, I get: Caused by: java.lang.ClassNotFoundException: org.apache.velocity.tools.view.ToolboxManager I've tried plugging in tools version 2 and 1.4, neither have this package structure. Did I miss something obvious? What version of Velocity Tools is the

Need a Java-based HTML prettifier to clean up Velocity-generated HTML

点点圈 提交于 2019-12-05 09:55:19
Web app I'm working on generates HTML using Velocity templates. Problem is that using whitespace in velocity templates and other formatting results in butt-ugly HTML (excessive whitespace, misalignment, etc.) Looking for a nice (single jar packaging would be nice) Java-based HTML prettifier to run over the generated HTML right before we dump it to the servlet response to make the source nicer to look at. Third party integrators would like to be able to glance at the HTML and know which templates are causing problems. The first step to this is having the HTML formatted nicely. Thanks in advance

How to throw an user-defined exception from Velocity Template Script (VTL)?

↘锁芯ラ 提交于 2019-12-05 09:31:49
How to throw an user-defined exception from Velocity Template Script (VTL) ? From my velocity script, i need to throw an exception based on a condition, so that the caller can catch the exception and present an useful error messages to the end user. For Example. #if($passwordfield1 != $passwordfield2) throw an exception here #elseif($passwordfield1 == $passwordfield2) do something #end In the above example, if passwordfield1 and passwordfield2 is not matching,an appropriate exception should be thrown and that needs to be propagated to the end-user. Is there any way to achieve this from

Access velocity variable with javascript

☆樱花仙子☆ 提交于 2019-12-05 09:25:39
<head> #set($test = "works")) </head> <script> var get = "${test}"; // I also tried using '$test' and "$test" also alert(get); </script> And it alerts out ${test} , but should print works . How can I get it to work? patel.milanb try this... #set ($test = "works") <script type="text/javascript"> var myvar = "${test}"; alert (myvar); </script> THIS WORKS SURELY!!!! Try var get = "$test"; instead of var get = "${test}"; I realize the question is old, but this worked for me: #set ($test = "hi") <script> alert("$test"); </script> Need to include quotes around the variable in the alert since it is a

Velocity templates not substituting methods

随声附和 提交于 2019-12-05 06:05:13
In the Velocity User's Guide it seems pretty straight forward to use methods in templates. I tried, but could not make it work. Can someone tell me what I did wrong? Thanks. This is my code @Test public void testVelocity() { Velocity.init(); VelocityContext map = new VelocityContext(); map.put("test", "Success"); map.put("ok", "OK!"); map.put("func", new Object() {public String test() {return "Yay!";}}); map.put("func2", new Object() {public String test(String t) {return t+t;}}); String template = "${func.test()} $test $func2.test($ok)"; StringWriter writer = new StringWriter(); Velocity

Build failure - Apache Parquet-MR source (mvn install failure)

江枫思渺然 提交于 2019-12-05 04:55:56
I am getting following error while trying to execute "mvn clean install" for building parquet-mr source obtained from https://github.com/apache/parquet-mr [INFO] Storing buildScmBranch: UNKNOWN [INFO] [INFO] --- maven-remote-resources-plugin:1.5:process (default) @ parquet-generator --- [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] Apache Parquet MR ................................. SUCCESS [1.494s] [INFO] Apache Parquet Generator .......................... FAILURE [0.064s] [INFO] Apache Parquet Common ....................