如何创建Apache的速度自定义指令 [英] How do I create a custom directive for Apache Velocity

查看:165
本文介绍了如何创建Apache的速度自定义指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apache的Velocity模板引擎,我想创建一个自定义的指令。也就是说,我希望能够写#doMyThing(),并让它调用一些Java code我以产生文中写道。

I am using Apache's Velocity templating engine, and I would like to create a custom Directive. That is, I want to be able to write "#doMyThing()" and have it invoke some java code I wrote in order to generate the text.

我知道我可以通过添加一行注册自定义指令

I know that I can register a custom directive by adding a line

userdirective=my.package.here.MyDirectiveName

我velocity.properties文件。我知道我可以通过扩展写出这样一类的<一个href=\"http://svn.apache.org/repos/asf/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Directive.java\">Directive类。我不知道的如何的扩展指令类 - 某种文档的新指令的作者。比如我想知道我的getType()方法返回BLOCK或LINE,我想知道我应该的setLocation()方法应该怎么办?

to my velocity.properties file. And I know that I can write such a class by extending the Directive class. What I don't know is how to extend the Directive class -- some sort of documentation for the author of a new Directive. For instance I'd like to know if my getType() method return "BLOCK" or "LINE" and I'd like to know what should my setLocation() method should do?

有出有任何文档不仅仅是使用源,卢克更好

Is there any documentation out there that is better than just "Use the source, Luke"?

推荐答案

我放在一起一点点的文章有关编写自定义指令的速度(和工具)。也许有人会觉得它有用。

I put together a little article about writing custom velocity directives (and tools). Maybe someone will find it useful.

这篇关于如何创建Apache的速度自定义指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆