/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.velocity.app.Velocity;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.Template;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import java.io.*;
import java.util.ArrayList;
/**
* This class is a simple demonstration of how the Velocity Template Engine
* can be used in a standalone application.
*
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
* @version $Id: Example.java 463298 2006-10-12 16:10:32Z henning $
*/
public class Example
{
public Example()
{
try
{
/*
* setup
*/
//Velocity.init("velocity.properties");
/*
* Make a context object and populate with the data. This
* is where the Velocity engine gets the data to resolve the
* references (ex. $list) in the template
*/
VelocityContext context = new VelocityContext();
context.put("list", getNames());
/*
* get the Template object. This is the parsed version of your
* template input file. Note that getTemplate() can throw
* ResourceNotFoundException : if it doesn't find the template
* ParseErrorException : if there is something wrong with the VTL
* Exception : if something else goes wrong (this is generally
* indicative of as serious problem...)
*/
Template template = null;
try
{
template = Velocity.getTemplate("example.vm");
}
catch( ResourceNotFoundException rnfe )
{
System.out.println("Example : error : cannot find template " );
}
catch( ParseErrorException pee )
{
System.out.println("Example : Syntax error in template " + ":" + pee );
}
/*
* Now have the template engine process your template using the
* data placed into the context. Think of it as a 'merge'
* of the template and the data to produce the output stream.
*/
BufferedWriter writer = writer = new BufferedWriter(
new OutputStreamWriter(System.out));
if ( template != null)
template.merge(context, writer);
/*
* flush and cleanup
*/
writer.flush();
writer.close();
}
catch( Exception e )
{
System.out.println(e);
}
}
public ArrayList getNames()
{
ArrayList list = new ArrayList();
list.add("ArrayList element 1");
list.add("ArrayList element 2");
list.add("ArrayList element 3");
list.add("ArrayList element 4");
return list;
}
public static void main(String[] args)
{
Example t = new Example();
}
}
## Licensed to the Apache Software Foundation (ASF) under one
## or more contributor license agreements. See the NOTICE file
## distributed with this work for additional information
## regarding copyright ownership. The ASF licenses this file
## to you under the Apache License, Version 2.0 (the
## "License"); you may not use this file except in compliance
## with the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing,
## software distributed under the License is distributed on an
## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
## KIND, either express or implied. See the License for the
## specific language governing permissions and limitations
## under the License.
#set( $this = "Velocity")
$this is great!
#foreach( $name in $list )
$name is great!
#end
#set( $condition = true)
#if ($condition)
The condition is true!
#else
The condition is false!
#end
分享到:
相关推荐
这是一个基于Velocity+SpringMVC+Spring+MyBatis架构的网站示例。 1.生成工程的步骤(前提jdk,eclipse,gradle都已安装配置完毕): 1)创建webapp目录,然后编写build.gradle 2)运行gradle createWebProject命令,...
the initial velocity. Pinch to zoom in/out. Battle Sats is written in Java (using Eclipse). It uses some bits from the Lunar Lander sample included with the Android SDK. It is available under the New ...
A novel type of sampled fiber Bragg gratings (FBGs) written in polarization-maintaining fiber (PMF) is proposed. The reflection spectrum, time delay, and group velocity dispersion (GVD) of the ...
Become aware of the seamlessness and power of Spring by referencing the easy-to- understand sample application we provide. Learn how to replace common EJB features with Spring alternatives, including...
velocity. % delay time can be calculated from range and speed of light r_t(i) = range + v*t(i); td(i) = 2*r_t(i)/c; % *%TODO* : %For each time sample we need update the transmitted and %received
During the ion etching, the sample is moved back and forth repeatedly with a constant velocity for the purpose of obtaining the linearly varied thickness of the cavity. Combined with ion beam ...
JSP 使用原始Java 代码,或者JSTL,Velocity 或Smarty 也使用特殊表达式等。jin-template 的目的是将视图构建逻辑与视图分离,并在模板端保留纯HTML。 jin-template 的解决方案非常简单:在 HTML(或 XML)中定义带...
A new PA cell structure is designed to accelerate the drift velocity of the sample gas near the cell surface, so that the short response time at the flow rate of 100 sccm (standard cubic centimeter ...
Modify the properties of rigid body dynamics like mass, velocity, force, and so on Understand joints and their types including fixed, revolute, spherical, distance, and D6 Understand the types of ...
总览 该项目提供了LaTeX与Java的简单集成。... 浏览到latex-renderer/src/test/resources/META-INF并通过执行pdflatex sample.tex编译sample.tex文件。 MiKTeX将尝试从互联网上下载缺少的软件包。 您可能必须使用tlmgr
Both the amplitude and the phase of the interometric heterodyne signal can be exploited to obtain the profile of sample reflectivity related to its microstructure and the bi-directional blood flowing ...
13. Reach 1 LiDAR Cross Sections and Sample Point Location 31 14. Differences Between LiDAR and Field Based Elevations 37 15. Regression ofLiDAR and Field Cross section Elevations 38 16. Comparison of...
8.3.7 KLD-Sampling: Adapting the Size of Sample Sets 263 8.4 Localization in Dynamic Environments 267 8.5 Practical Considerations 273 8.6 Summary 274 8.7 Bibliographical Remarks 275 8.8 Exercises 276...
Tags are one of the things that make Struts unique compared to other frameworks like Velocity. Note: "Think thin" when extending the Action class. The Action class should control the flow and not ...
3.5 A Sample Visualization Program...........................................................................64 3.6 Four- and Higher-Dimensional Visualization: Yes, It Really Works!.............65 3.7...