com.xiaoleilu.hutool
类 VelocityUtil

java.lang.Object
  继承者 com.xiaoleilu.hutool.VelocityUtil

public class VelocityUtil
extends Object

Velocity模板引擎工具类
使用前必须初始化工具类

作者:
xiaoleilu

构造方法摘要
VelocityUtil()
           
 
方法摘要
static String getContent(String templateDir, String templateFileName, org.apache.velocity.VelocityContext context, String charset)
          获得指定模板填充后的内容
static String getContent(String templateFileName, org.apache.velocity.VelocityContext context)
          获得指定模板填充后的内容,使用默认引擎
static String getContent(org.apache.velocity.app.VelocityEngine ve, String templateFileName, org.apache.velocity.VelocityContext context)
          获得指定模板填充后的内容
static void init(String templateDir, String charset)
          初始化Velocity全局属性
static String merge(String templateContent, org.apache.velocity.VelocityContext context)
          融合模板和内容
static org.apache.velocity.app.VelocityEngine newEngine(String templateDir, String charset)
          新建Velocity模板引擎
static org.apache.velocity.VelocityContext parseRequest(javax.servlet.http.HttpServletRequest request)
          将Request中的数据转换为模板引擎
static void toFile(String templateFileName, org.apache.velocity.VelocityContext context, String destPath)
          生成文件,使用默认引擎
static void toFile(org.apache.velocity.Template template, org.apache.velocity.VelocityContext context, String destPath)
          生成文件
static void toFile(org.apache.velocity.app.VelocityEngine ve, String templateFileName, org.apache.velocity.VelocityContext context, String destPath)
          生成文件
static void toWriter(String templateFileName, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          生成内容写到响应内容中
模板的变量来自于Request的Attribute对象
static void toWriter(String templateFileName, org.apache.velocity.VelocityContext context, Writer writer)
          生成内容写入流
会自动关闭Writer
static void toWriter(org.apache.velocity.app.VelocityEngine ve, String templateFileName, org.apache.velocity.VelocityContext context, Writer writer)
          生成内容写入流
会自动关闭Writer
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

VelocityUtil

public VelocityUtil()
方法详细信息

init

public static void init(String templateDir,
                        String charset)
初始化Velocity全局属性

参数:
templateDir - 模板所在目录,绝对路径

newEngine

public static org.apache.velocity.app.VelocityEngine newEngine(String templateDir,
                                                               String charset)
新建Velocity模板引擎

参数:
templateDir - 模板所在目录,绝对路径
返回:
VelocityEngine

getContent

public static String getContent(String templateDir,
                                String templateFileName,
                                org.apache.velocity.VelocityContext context,
                                String charset)
获得指定模板填充后的内容

参数:
templateDir - 模板所在目录,绝对路径
templateFileName - 模板名称
context - 上下文(变量值的容器)
charset - 字符集
返回:
模板和内容匹配后的内容

getContent

public static String getContent(org.apache.velocity.app.VelocityEngine ve,
                                String templateFileName,
                                org.apache.velocity.VelocityContext context)
获得指定模板填充后的内容

参数:
ve - 模板引擎
templateFileName - 模板名称
context - 上下文(变量值的容器)
返回:
模板和内容匹配后的内容

getContent

public static String getContent(String templateFileName,
                                org.apache.velocity.VelocityContext context)
获得指定模板填充后的内容,使用默认引擎

参数:
templateFileName - 模板文件
context - 上下文(变量值的容器)
返回:
模板和内容匹配后的内容

toFile

public static void toFile(org.apache.velocity.app.VelocityEngine ve,
                          String templateFileName,
                          org.apache.velocity.VelocityContext context,
                          String destPath)
生成文件

参数:
ve - 模板引擎
templateFileName - 模板文件名
context - 上下文
destPath - 目标路径(绝对)

toFile

public static void toFile(String templateFileName,
                          org.apache.velocity.VelocityContext context,
                          String destPath)
生成文件,使用默认引擎

参数:
templateFileName - 模板文件名
context - 模板上下文
destPath - 目标路径(绝对)

toFile

public static void toFile(org.apache.velocity.Template template,
                          org.apache.velocity.VelocityContext context,
                          String destPath)
生成文件

参数:
template - 模板
context - 模板上下文
destPath - 目标路径(绝对)

toWriter

public static void toWriter(org.apache.velocity.app.VelocityEngine ve,
                            String templateFileName,
                            org.apache.velocity.VelocityContext context,
                            Writer writer)
生成内容写入流
会自动关闭Writer

参数:
ve - 引擎
templateFileName - 模板文件名
context - 上下文
writer - 流

toWriter

public static void toWriter(String templateFileName,
                            org.apache.velocity.VelocityContext context,
                            Writer writer)
生成内容写入流
会自动关闭Writer

参数:
templateFileName - 模板文件名
context - 上下文
writer - 流

merge

public static String merge(String templateContent,
                           org.apache.velocity.VelocityContext context)
融合模板和内容

参数:
templateContent - 模板的内容字符串
context - 上下文
返回:
模板和内容匹配后的内容

toWriter

public static void toWriter(String templateFileName,
                            javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
生成内容写到响应内容中
模板的变量来自于Request的Attribute对象

参数:
templateFileName - 模板文件
request - 请求对象,用于获取模板中的变量值
response - 响应对象

parseRequest

public static org.apache.velocity.VelocityContext parseRequest(javax.servlet.http.HttpServletRequest request)
将Request中的数据转换为模板引擎

参数:
request - 请求对象
返回:
模板引擎


Copyright © 2014. All rights reserved.