velocity

How to include a static or uploaded file in Velocity macro via #include

喜夏-厌秋 提交于 2019-12-06 03:19:50
问题 I am trying to optimize some mobile web pages (or number of server requests more accurately) by in-lining some CSS in the HTML downloaded with initial request. These pages are delivered from our Vosao-based CMS, and use Apache Velocity macros. This works fine, as expected. <link rel="stylesheet" type="text/css" media="screen" href="/file/downloads/contact.css" This fails <style> #include( "/file/downloads/contact.css" ) </style> as Velocity cannot find the file, with this output org.apache

Velocity宏定义的坑与解决办法

白昼怎懂夜的黑 提交于 2019-12-06 03:00:12
使用Velocity,当然就免不了要使用宏,或者说 使用Velocity而 不使用其宏,就相当于废了Velocity一半以上的武功,非常可惜的。 怎么使用Velocity的宏呢,才最大程度的发挥其作用但是又避免掉入其中的坑呢?且听悠然乱弹乱弹: 官方文档中,关于Macro是这么说的: #macro - Allows users to define a Velocimacro (VM), a repeated segment of a VTL template, as required Format: # [ { ] macro [ } ] ( vmname $arg1 [ $arg2 $arg3 ... $argn ] ) [ VM VTL code... ] # [ { ] #end [ } ] vmname - Name used to call the VM ( #vmname ) $arg1 $arg2 [ ... ] - Arguments to the VM. There can be any number of arguments, but the number used at invocation must match the number specified in the definition. [ VM VTL code... ] - Any valid VTL

How to load a velocity template into an EJB to be used as a mail template

99封情书 提交于 2019-12-06 02:22:18
I have a Java EE 6 application in which I'd like to use velocity to generate mails from a template. I have a @Named bean which is responsible for loading and filling a particular template. The project is a web application, so I placed my templates into WEB-INF/classes (which btw seems to be rather ugly, but I didn't find a more elegant solution by now) and used the ClasspathResourceLoader to access the files. The configuration is as follows: Properties props = new Properties(); props.setProperty("resource.loader", "class"); props.setProperty("resource.loader.class", "org.apache.velocity

How to validate that HTML matches W3C standards

核能气质少年 提交于 2019-12-06 02:22:00
问题 I have a project that generates HTML pages using a Velocity template and Java. But most of the pages do not comply with W3C standards. How can I validate those HTML pages and get a log telling me what errors/warnings on what pages? Then I can fix the errors manually. I have tried JTidyFilter, but that doesn't work for me. 回答1: You can use the W3C validator directly from Java, see w3c-jabi. 回答2: There is also an experimental API available from W3C to help automate validation. They kindly ask

Configure velocity tools with spring 3.x

眉间皱痕 提交于 2019-12-05 21:48:23
I am new to both spring and velocity I want to configure velocity tools with spring 3.x but I could not find a good article on that + the velocity template is not showing the session variable I set from Spring controller As for configuring Velocity tools in spring 3.x, first put your tools.xml file somewhere useful, eg: /WEB-INF/vm/toolbox.xml THEN configure your view resovler to look in that place: <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> ... <!--Other config properties in here --> ... <property name="toolboxConfigLocation" value="

How to obtain the languageid in a Liferay theme with velocity

泄露秘密 提交于 2019-12-05 21:02:39
For the current theme im creating there are multiple images that require to change based on the current language. For example if the user is visiting the page in english we would load image_ languageid .jpg How can you replace languageid with the actual id of the language in velocity & liferay? Is this a good technique or is there a nicer one? vinzcelavi Try adding this line in init_custom.vm or portal_normal.vm #set ($language_id = $themeDisplay.getLanguageId()) 来源: https://stackoverflow.com/questions/8254603/how-to-obtain-the-languageid-in-a-liferay-theme-with-velocity

How to set velocity template character encoding with spring boot?

流过昼夜 提交于 2019-12-05 20:22:08
My templates have UTF-8 as encoding but the output from my web app is not correct. The problem is that velocity think that my templates have ISO-8859-1 as encoding since that is the output from this: System.out.println(ctx.getBean(VelocityEngine.class).getTemplate("index.html").getEncoding()); It is possible to configure the output encoding by setting spring.velocity.charSet=UTF-8 in application.properties, but my problem is not the output, it is the template encoding that is wrong. Velocity have this property input.encoding but I can not figure out how to set that with spring boot in an easy

Using Velocity's WebappResourceLoader with Spring

五迷三道 提交于 2019-12-05 19:47:46
I'm trying to use Velocity to create an email template that is mailed by Spring's JavaMailSender class. The resource loader that I decided to use to find the Velocity template in my web app is WebappResourceLoader which is located in the Velocity tool jar. However, depending on how I use the WebappResourceLoader, I get either a NPE when the web app starts up or the template can't be found. If I specify the init properties for the Velocity engine in my Spring application context I get the NPE. My configuration is as follows: <bean id="velocityEngine" class="org.springframework.ui.velocity

Use Velocity to generate HTML based email

拟墨画扇 提交于 2019-12-05 17:50:46
I try this tutorials http://www.java2s.com/Code/Java/Velocity/UseVelocitytogenerateHTMLbasedemail.htm but, when i add css, it look like not executed. <HTML> <HEAD> <TITLE>Pet Store Sale!</TITLE> <style type="text/css"> body { margin: 0 0 0 0; padding: 0 0 0 0; text-align: center; background-color: #FFF; border-top: 3px solid #CCC; } #container { position: relative; width: 860px; height: 1600px; margin: 84 auto 0 auto; padding: 0 0 0 0; background-color: #FFF; } p { font-family: times, Times New Roman, times-roman, georgia, serif; color: #444; margin: 0 0 0 0; padding: 0 0 0 0; text-align:

发送邮件(Spring+Velocity)

丶灬走出姿态 提交于 2019-12-05 17:40:35
最近有需实现邮件发送的功能,为了让邮件界面和业务数据分离,故采用Velocity模板引擎。需引入velocity的时候,在Maven配置文件中添加如下依赖: <dependency> <groupId>velocity</groupId> <artifactId>velocity</artifactId> <version>1.5</version> </dependency> <dependency> <groupId>velocity-tools</groupId> <artifactId>velocity-tools</artifactId> <version>2.0-beta1</version> </dependency> 接着在Spring的配置文件中定义添加如下配置: <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"> <property name="velocityProperties"> <props> <prop key="resource.loader">file</prop> <prop key="file.resource.loader.class">org.apache.velocity.runtime.resource