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

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

问题描述

我使用Apache的Velocity模板引擎,我想创建一个自定义的指令。也就是说,我想要写#doMyThing(),并且调用一些我写的java代码来生成文本。

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文件。而且我知道我可以通过扩展指令类。我不知道的是如何扩展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?

有没有任何文件比使用来源,Luke

推荐答案

我整理了一点文章。也许有人会觉得有用。

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

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

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