速度IncludeEventHandler困境 [英] Velocity IncludeEventHandler dilemma

查看:86
本文介绍了速度IncludeEventHandler困境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于IncludeEventHandler,这是一个有趣的问题.

Here is an interesting problem regarding the IncludeEventHandler.

我正在开发一个基于Spring的应用程序,该应用程序使用具有不同 VENDORS 且具有单独投资组合站点的速度.我让供应商通过提供Velocity模板来自定义页面,这些模板将存储在数据库中,并由速度引擎使用DataSourceResourceLoader拾取.

I am developing a Spring-Based application which uses velocity which has different VENDORS having a separate portfolio site. I am letting vendors customize the pages by providing them the Velocity templates which are being stored the database and are picked up by the velocity engine using a DataSourceResourceLoader.

我的表的组织方式类似于.

My table is organized like this.

供应商可以通过调用宏#parse并传递其vendorid/template-name来解析其他模板,以使它看起来像这样.

The vendors may parse other templates by calling the macro #parse and passing their vendorid/template-name so that it looks like this.

#parse("20160109144/common-css.vm")

现在,实际的问题是根据供应商标识获取模板. 我有一个类(扩展IncludeEventHandler),它覆盖了includeEvent方法.现在我该怎么做才能返回所需的模板?我不想更改名称并使它们看起来像20160109144/home.vm

Now the actual problem is picking up the template according to vendorid. I have a class (extending IncludeEventHandler) which overrides the includeEvent method. Now what can I do to return the desired template? I dont want to change the names and make them look like 20160109144/home.vm

推荐答案

关于OP的问题,目的是为

With OP's question, the intent was to provide an alternate behavior to the DataSourceResourceLoader.

不幸的是,Velocity Engine 1.7版本没有能力更改用于检索模板的SQL语句.

Unfortunately, the Velocity Engine version 1.7 doesn't have ability to change the SQL statement that is used to retrieve the template.

DataSourceResourceLoader扩展了参考源代码,您应该能够实现一个自定义的ResourceLoader,以符合您希望的方式运行.

The DataSourceResourceLoader extends the ResourceLoader abstract class. That said, if you reference the source, you should be able to implement a custom ResourceLoader that behaves the way you want it to.

一个选项,将大部分来自DataSourceResourceLoader的代码,并更改其确定要从数据库加载的模板内容的方式.

One option, glom most of the code from DataSourceResourceLoader and change the way it determines the template content to load from the database.

当您确定要为内容加载的特定列时,我将转储所有与查询相关的材料. DataSourceResourceLoader本质上将模板的名称映射到数据库条目,并且您的实现本质上围绕着上面定义的规则.

I would dump all of the query related material as you will be determining the specific columns you want to load for content. The DataSourceResourceLoader essentially maps the name of a template to a database entry and your implementation essentially revolves around the rules you've defined above.

希望可以提供足够的帮助以继续前进.我也建议将其引入调试器中,并确定将什么和哪些不传递给相关的加载方法.

Hopefully that can provide enough assistance to move forward. I would recommend pulling this in a debugger as well and determine what is and is-not passed in to the related load methods.

这篇关于速度IncludeEventHandler困境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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