velocity

VelocityEngine 和Velocity类解析

試著忘記壹切 提交于 2019-12-02 10:01:11
在我们 普通使用 velocity 的过程中,或者一开始使用 velocity 做 demo 的同学,总会对这段代码有印象: VelocityEngine velocity = new VelocityEngine (); VelocityContext context = new VelocityContext (); context . put ( "name" , "czy" ); Template template = velocity . getTemplate ( "/src/main/resources/test.vm" ); BufferedWriter writer = new BufferedWriter ( new OutputStreamWriter ( System . out )); template . merge ( context , writer ); writer . flush (); writer . close (); 但是阅读源码会发现在 org.apache.velocity.app包下,会有velocoty和velocityEngine这两个类,里面的方法大同小异,都是init 加setproperty这里设置属性的方法,然后将 VelocityEngine velocity = new VelocityEngine ();

Velocity练习:使用vm模板生成最简单的html页面

亡梦爱人 提交于 2019-12-02 09:59:55
这几天要用到Velocity模板引擎去做一些页面,所以学习了下这个工具。我的jdk版本为 1.8.0_25 需要做的准备工作有: 1、建立一个Java工程,需要引用Velocity相关的jar包,这些jar包可从apache.org下载到最新版本。 下载地址在: http://velocity.apache.org/download.cgi 。我下载的文件是velocity-tools-2.0.zip,将这些文件导入到项目中,就可以使用Velocity进行编码了。 2、安装Eclipse上的Velocity插件Veloedit。因为googlecode被gfw墙掉了,没有条件的朋友们可以安装网上下载到的离线安装版。这里还有一个需要注意,我的Eclipse版本为 Luna Service Release 1 (4.4.1),这个版本必须要先利用Eclipse自带的update功能,下载“Elipse Tests, Examples, and Extras”。 我要用Velocity绘制一个通讯录的联系人资料页面,使用Balsamiq工具绘制的页面原型如下: 建立一个JavaProject,取名VelocityTool,里面新建两个java文件。 其中,VelocityHelper.java包含一个Velocity模板转换工具类,代码如下: import java.io.File;

JMeter add velocity language to JSR 223 Sampler

懵懂的女人 提交于 2019-12-02 08:42:50
I want to use velocity language as Scripting language in JMeter's JSR 223 Sampler . According to the list velocity can be used in JSR223, According to the answer velocity should be added to JMeter classpath for discovery of available scripting engines. How can I add velocity as a Scripting engine in JMeter? Download new velocity engine scripting version 2.0 in order to support scripting engine. Put velocity-engine-scripting-2.0.jar in JMeter's lib folder. When JMeter loaded it can find velocity as scripting engine and use it. EDIT Also add relevant velocity jar(s) as velocity-engine-core-2.0

Velocity array to javascript array

牧云@^-^@ 提交于 2019-12-02 01:57:00
问题 I need to pass a velocity string array to JavaScript function. So, for that, I want to convert the velocity array into JavaScript array. The source code looks like this : String[] arrStr[] = new String[3]; arrStr[0] = "String 1"; arrStr[1] = "String 2"; arrStr[2] = "String 3"; request.setAttribute("a", arrStr); In my HTML template, #set ( #arr = $request.getAttribute("a")) <script language="javascript"> var newArr = "${arr}"; </script> But the string arrays are not copied to newArr. Can

How do I pass get request parameters to my Velocity Template to send mails

こ雲淡風輕ζ 提交于 2019-12-01 23:21:26
I have a JSP and in that JSP I have a link which looks something like http://mydomain.com/verify.do?email=emailid&id=123 Now when users clicks that link, it goes to my velocityview servlet, now my question is how do I pull out those parameters in velocity servlet and put it into the context so that I can send it to my template. I tried getparameter,#set(#request.getAttribute(email) etc.But for some reason I dont see the value getting into the context or template. I know there is velocity parameter tool out there,but I am not able to find as how to install and use it.So appreciate if someone

Tiny模板引擎(Velocity Plus)应用示例

こ雲淡風輕ζ 提交于 2019-12-01 19:49:48
把TinyTemplate当成是Velocity的升级版其实也是可以的,毕竟它的语法是基到Veloccity扩展而来的,兼容度在80%以上。 至于TinyTemplate的实例是怎样的,且看下面: 宏的可变参数 在Java中的可变参数使用起来非常方便,Tiny模板也对可变参有一定支持。 #macro hello() ParameterList: ${helloParameterList.size()} #for(para:helloParameterList) hello:${para} #end #end #call("hello","aa",1,true,false) 运行结果: ParameterList: 4 hello:aa hello:1 hello:true hello:false 说明:在宏的包体中,有一个默认的变量,名称就是宏的名字+ParameterList,当前例子中,宏的名字是hello,所以变量的名字就是:helloParameterList。 此变量的类似是一个List,因此可以调用List的方法。 Set示例 运行结果: 宏定义及其调用示例 1:1 2:2 3:1 4:2 5:2 解释: 首先设置abc=1,然后显示它的值,结果是1,这个是理所当然的。 然后定义一个宏,在宏里设置变量abc的值为2,然后显示这个值。 在调用setAbc宏的时候

Mocha-web client-side tests not running with Velocity for Meteor application

醉酒当歌 提交于 2019-12-01 19:49:03
I have 2 samples Mocha web tests which I'm trying to run using Velocity. For some reason, client-side tests under the /tests/mocha/client folder are never executed, whereas the server side tests under the /tests/mocha/server folder run fine. Here is the structure of my project todos (meteor example project) client lib packages server tests mocha client server Thoughts ? I ran into this problem and it was related to having the browser-policy package installed. What you need to do is look in the JavaScript console, e.g. in Chrome developer tools, look at the console tab. (Apple Key + option key

can Velocity set a default value for a variable when no value found in VelocityContext?

我只是一个虾纸丫 提交于 2019-12-01 17:40:18
Velocity just print the tag name if no value was found in VelocityContext, ie, $name in my template file, but there is no value for "name" in VelocityContext, so just "$name" was printed. I want Velocity to print a default value if there is no value for the variable, I just tried to extends AbstractCotnext and override internalGet() method, but the return value of internalGet() will be cast to Node object, I don't know how to create a new Node object in my internalGet() method, and also I think this way is very complex. is there a simple way to set a default value (default value is just a

Atlassian JIRA Plugin Development: How to make variables available to velocity templates

北慕城南 提交于 2019-12-01 16:43:55
FAIR WARNING: this question is going to be pretty tough to answer unless you have experience with JIRA and have access to their source (enterprise users). Greetings all, I am writing a plugin which extends AbstractIssueSelectAction. I noticed that ${issue.summary} , etc are all available from within my velocity template, however, there are other things I wish to expose. I can't figure out how to add other things to the velocity parameter map. I even used a remote debugger to try to step through the stack and figure out what is going on - but it was pretty unclear to me both due to a deep stack

How to XML escaping with Apache Velocity?

允我心安 提交于 2019-12-01 16:42:23
I am generating XML using Apache Velocity. What is the best (most straight-forward) way to XML-escape the output? (I saw there is an escape tool, but could not figure out it's dev state. I also think that XML escaping is something that is very likely supported by Velocity directly.) Take a look at event handlers . eventhandler.referenceinsertion.class = org.apache.velocity.app.event.implement.EscapeXmlReference Escape tool is a production ready as well if you need to escape only selective references (final version of tools was released just recently but it was in beta stage before that for 2