`
san_yun
  • 浏览: 2652199 次
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

velocity配置详解

    博客分类:
  • java
阅读更多

velocity配置详解

在velocity二方包中有一个velocity.properties
文件定义了velocity的配置信息(位于org.apache.velocity.runtime.defaults package下,org.apache.velocity.runtime.RuntimeConstants中定义了key值)

#模板编码:

input.encoding=ISO-8859-1 //模板输入编码
output.encoding=ISO-8859-1 //模板输出编码

#foreach配置

directive.foreach.counter.name = velocityCount //计数器名称
directive.foreach.counter.initial.value = 1 //计数器初始值
directive.foreach.maxloops = -1 //最大循环次数,-1为默认不限制 directive.foreach.iterator.name = velocityHasNex //迭代器名称

#set配置

directive.set.null.allowed = false //是否可设置空值

#include配置

directive.include.output.errormsg.start = <!-- include error : //错误信息提示开始字符串
directive.include.output.errormsg.end = see error log --> //错误信息提示结束字符串

#parse配置

directive.parse.max.depth = 10 //解析深度

模板加载器配置

resource.loader = file //模板加载器类型,默认为文件,可定义多个

file.resource.loader.description = Velocity File Resource Loader //加载器描述
file.resource.loader.class = Velocity.Runtime.Resource.Loader.FileResourceLoader //加载器类名称
file.resource.loader.path = . //模板路径
file.resource.loader.cache = false //是否启用模板缓存
file.resource.loader.modificationCheckInterval = 2 //检查模板更改时间间隔

宏配置

velocimacro.permissions.allow.inline = true //是否可以行内定义
velocimacro.permissions.allow.inline.to.replace.global = false //是否可以用行内定义代替全局定义
velocimacro.permissions.allow.inline.local.scope = false //行内定义是否只用于局部

velocimacro.context.localscope = false //宏上下文是否只用于局部
velocimacro.max.depth = 20 //解析深度

velocimacro.arguments.strict = false //宏参数是否启用严格模式

资源管理器配置

resource.manager.class = Velocity.Runtime.Resource.ResourceManagerImpl //管理器类名称
resource.manager.cache.class = Velocity.Runtime.Resource.ResourceCacheImpl //缓存器类名称

解析器池配置

parser.pool.class = Velocity.Runtime.ParserPoolImpl //解析池类名称
parser.pool.size = 40 //初始大小

#evaluate配置

directive.evaluate.context.class = Velocity.VelocityContext //上下问类名称

可插入introspector配置
runtime.introspector.uberspect = Velocity.Util.Introspection.UberspectImpl //默认introspector类名称

更详细的可以参考:Velocity的控制讨论

velocity.properties

# 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.    

# ----------------------------------------------------------------------------
# R U N T I M E  L O G
# ----------------------------------------------------------------------------

# ----------------------------------------------------------------------------
#  default
 LogChute to use: default
: AvalonLogChute, Log4JLogChute, CommonsLogLogChute, ServletLogChute, JdkLogChute
# ----------------------------------------------------------------------------

runtime.log.logsystem.class = org.apache.velocity.runtime.log.AvalonLogChute,org.apache.velocity.runtime.log.Log4JLogChute,org.apache.velocity.runtime.log.CommonsLogLogChute,org.apache.velocity.runtime.log.ServletLogChute,org.apache.velocity.runtime.log.JdkLogChute

# ---------------------------------------------------------------------------
# This is the location of the Velocity Runtime
 log.
# ----------------------------------------------------------------------------

runtime.log = velocity.log

# ----------------------------------------------------------------------------
# This controls whether invalid references are logged.
# ----------------------------------------------------------------------------

runtime.log.invalid.references = true


# ----------------------------------------------------------------------------
# T E M P L A T E  E N C O D I N G
# ----------------------------------------------------------------------------

input.encoding=ISO-8859-1
output.encoding=ISO-8859-1

# ----------------------------------------------------------------------------
# F O R E A C H  P R O P E R T I E S
# ----------------------------------------------------------------------------
# These properties control how the counter is accessed in the #foreach
# directive. By default
 the reference $velocityCount and $velocityHasNext
# will be available in the body of the #foreach directive.
# The default
 starting value for
 $velocityCount is 1.
# ----------------------------------------------------------------------------

directive.foreach.counter.name = velocityCount
directive.foreach.counter.initial.value = 1
directive.foreach.maxloops = -1

directive.foreach.iterator.name = velocityHasNext

# ----------------------------------------------------------------------------
# S E T  P R O P E R T I E S
# ----------------------------------------------------------------------------
# These properties control the behavior of #set.
# For compatibility, the default
 behavior is to disallow setting a reference
# to null
.  This default
 may be changed in a future
 version.
# ----------------------------------------------------------------------------

directive.set.null
.allowed = false


# ----------------------------------------------------------------------------
# I F  P R O P E R T I E S
# ----------------------------------------------------------------------------
# These properties control the behavior of #if

# Default behavior is to check return
 value of toString() and treat an object
# with toString() that returns null
 as null
. If all objects have toString()
# methods that never return
 null
, this
 check is unnecessary and can be disabled
# to gain performance. In Velocity 1.5, no such null
 check was performed.
directive.if
.tostring.nullcheck = true


# ----------------------------------------------------------------------------
# I N C L U D E  P R O P E R T I E S
# ----------------------------------------------------------------------------
# These are the properties that governed the way #include'd content
# is governed.
# ----------------------------------------------------------------------------

directive.include.output.errormsg.start = <!-- include error :
directive.include.output.errormsg.end   =  see error log -->

# ----------------------------------------------------------------------------
# P A R S E  P R O P E R T I E S
# ----------------------------------------------------------------------------

directive.parse.max.depth = 10

# ----------------------------------------------------------------------------
# T E M P L A T E  L O A D E R S
# ----------------------------------------------------------------------------
#
#
# ----------------------------------------------------------------------------

resource.loader = file

file.resource.loader.description = Velocity File Resource Loader
file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
file.resource.loader.path = .
file.resource.loader.cache = false

file.resource.loader.modificationCheckInterval = 2

# ----------------------------------------------------------------------------
# VELOCIMACRO PROPERTIES
# ----------------------------------------------------------------------------
# global : name of default
 global library.  It is expected to be in the regular
# template path.  You may remove it (either the file or this
 property) if

# you wish with no harm.
# ----------------------------------------------------------------------------
# velocimacro.library = VM_global_library.vm

velocimacro.permissions.allow.inline = true

velocimacro.permissions.allow.inline.to.replace.global = false

velocimacro.permissions.allow.inline.local.scope = false


velocimacro.context.localscope = false

velocimacro.max.depth = 20

# ----------------------------------------------------------------------------
# VELOCIMACRO STRICT MODE
# ----------------------------------------------------------------------------
# if
 true
, will throw
 an exception for
 incorrect number 
# of arguments.  false
 by default
 (for
 backwards compatibility)
# but this
 option will eventually be removed and will always
# act as if
 true

# ----------------------------------------------------------------------------
velocimacro.arguments.strict = false


# ----------------------------------------------------------------------------
# STRICT REFERENCE MODE
# ----------------------------------------------------------------------------
# if
 true
, will throw
 a MethodInvocationException for
 references
# that are not defined in the context, or have not been defined
# with a #set directive. This setting will also throw
 an exception
# if
 an attempt is made to call a non-existing property on an object
# or if
 the object is null
.  When this
 property is true
 then property
# 'directive.set.null
.allowed' is also set to true
.
# ----------------------------------------------------------------------------
runtime.references.strict = false


# ----------------------------------------------------------------------------
# INTERPOLATION
# ----------------------------------------------------------------------------
# turn off and on interpolation of references and directives in string
# literals.  ON by default
 :)
# ----------------------------------------------------------------------------
runtime.interpolate.string.literals = true



# ----------------------------------------------------------------------------
# RESOURCE MANAGEMENT
# ----------------------------------------------------------------------------
# Allows alternative ResourceManager and ResourceCache implementations
# to be plugged in.
# ----------------------------------------------------------------------------
resource.manager.class = org.apache.velocity.runtime.resource.ResourceManagerImpl
resource.manager.cache.class = org.apache.velocity.runtime.resource.ResourceCacheImpl

# ----------------------------------------------------------------------------
# PARSER POOL
# ----------------------------------------------------------------------------
# Selects a custom factory class for
 the parser pool.  Must implement
# ParserPool.  parser.pool.size is used by the default
 implementation
# ParserPoolImpl
# ----------------------------------------------------------------------------

parser.pool.class = org.apache.velocity.runtime.ParserPoolImpl
parser.pool.size = 20


# ----------------------------------------------------------------------------
# EVENT HANDLER
# ----------------------------------------------------------------------------
# Allows alternative event handlers to be plugged in.  Note that each
# class property is actually a comma-separated list of classes (which will
# be called in order).
# ----------------------------------------------------------------------------
# eventhandler.referenceinsertion.class =
# eventhandler.nullset.class =
# eventhandler.methodexception.class =
# eventhandler.include.class =


# ----------------------------------------------------------------------------
# EVALUATE
# ----------------------------------------------------------------------------
# Evaluate VTL dynamically in template.  Select a class for
 the Context
# ----------------------------------------------------------------------------

directive.evaluate.context.class = org.apache.velocity.VelocityContext


# ----------------------------------------------------------------------------
# PLUGGABLE INTROSPECTOR
# ----------------------------------------------------------------------------
# Allows alternative introspection and all that can of worms brings.
# ----------------------------------------------------------------------------

runtime.introspector.uberspect = org.apache.velocity.util.introspection.UberspectImpl


# ----------------------------------------------------------------------------
# SECURE INTROSPECTOR
# ----------------------------------------------------------------------------
# If selected, prohibits methods in certain classes and packages from being 
# accessed.
# ----------------------------------------------------------------------------

introspector.restrict.packages = java.lang.reflect

# The two most dangerous classes

introspector.restrict.classes = java.lang.Class

introspector.restrict.classes = java.lang.ClassLoader

                
# Restrict these for
 extra safety

introspector.restrict.classes = java.lang.Compiler

introspector.restrict.classes = java.lang.InheritableThreadLocal
introspector.restrict.classes = java.lang.Package
introspector.restrict.classes = java.lang.Process

introspector.restrict.classes = java.lang.Runtime

introspector.restrict.classes = java.lang.RuntimePermission
introspector.restrict.classes = java.lang.SecurityManager

introspector.restrict.classes = java.lang.System

introspector.restrict.classes = java.lang.Thread

introspector.restrict.classes = java.lang.ThreadGroup

introspector.restrict.classes = java.lang.ThreadLocal
分享到:
评论

相关推荐

    Velocity配置文件详解

    ### Velocity配置文件详解 #### 一、概述 在Apache Velocity框架中,`velocity.properties`配置文件扮演着核心角色。此文件通常位于`org.apache.velocity.runtime.defaults`包下,并且定义了Velocity运行时所需的...

    velocity 配置jar包

    ** Velocity 模板引擎配置详解 ** Velocity 是一个开源的 Java 模板引擎,它允许开发者将业务逻辑与页面展示分离,使得 HTML 页面更专注于布局和设计,而将动态数据处理交由后端代码处理。Velocity 通过使用简单的...

    Velocity之HelloWorld配置

    ** Velocity之HelloWorld配置详解 ** Velocity是一款Java模板引擎,它是Apache软件基金会的Jakarta项目之一,主要用于生成动态Web内容。Velocity通过将内容展示与业务逻辑分离,使得开发者可以专注于后端逻辑,而...

    velocity插件

    【 Velocity 插件详解】 Velocity 是一款基于 Java 的模板引擎,它被广泛应用于 Web 开发中,特别是作为 Apache Struts 和 Spring MVC 框架的一部分。Velocity 插件则是为了在开发环境中提供对 Velocity 模板语言的...

    struts2 result配置详解

    Struts2 Result 配置详解 Struts2 框架中 Result 配置是一种非常重要的配置,它直接影响着应用程序的执行结果。Result 配置通常用于定义 Action 的执行结果,例如将结果.redirect 到一个新的 URL,或者将结果....

    velocity中文

    Velocity配置 Velocity的配置主要通过`velocity.properties`文件进行,其中包括模板目录、缓存策略、编码设置等。例如,设置模板路径: ``` resource.loader=class class.resource.loader.class=org.apache....

    myeclipse的velocity插件

    ** Velocity 插件详解 ** Velocity 是一个基于 Java 的模板引擎,它允许开发者将静态文本与 Java 代码相分离,从而使得网页设计更加简洁、易维护。在 Web 开发领域,Velocity 被广泛用于生成动态内容,尤其在 ...

    maven velocity

    ** Maven与Velocity整合详解 ** Maven和Velocity都是在Java开发中非常重要的工具。Maven是一个项目管理和综合工具,它帮助开发者管理项目的构建、报告和文档。Velocity则是一个基于Java的模板引擎,它允许开发者将...

    velocity(eclipse插件)

    **Velocity Eclipse 插件详解** Velocity 是一个基于 Java 的模板引擎,它被广泛用于Web开发中的视图层,尤其在Apache Struts 和Spring MVC等框架中。然而,为了方便Java开发者在Eclipse集成开发环境中更好地利用...

    velocity使用

    【Velocity使用详解】 Velocity是一个基于Java的模板引擎,它的核心功能是将模板语言与Java代码相结合,使得非程序员,如网页设计师,能够专注于页面的视觉呈现,而开发者则专注于业务逻辑的实现。这种分离使得开发...

    velocity入门使用教程

    - **安装与配置**:介绍如何在项目中引入Velocity库,设置配置文件`velocity.properties`。 - **快速开始**:通过一个简单的示例展示如何创建第一个Velocity模板并运行。 - **模板语法详解**:详细解释Velocity...

    velocity 入门文档及应用源码,很适合做自动代码生成

    手册中会详细介绍Velocity上下文(Context)、模板(Templates)、模板语言(Template Language)等核心概念,还有Velocity Engine的配置、宏库(Macro Library)的使用,以及与其他Java库如Spring的集成等高级主题。...

    velocity总结

    - **创建多个 Velocity 实例**:可以在同一 JVM 或 Web 应用中创建和配置任意数量的 Velocity 实例。通过 `org.apache.velocity.app.VelocityEngine` 类来使用分离的实例。 - **示例代码**: ```java ...

    velocity-1.6.zip

    2. **设置配置**:配置Velocity,例如模板路径、缓存策略等。 3. **加载模板**:使用引擎加载模板文件。 4. **填充上下文**:将Java对象放入上下文,供模板使用。 5. **渲染模板**:使用上下文数据渲染模板,生成...

    92.Spring Boot使用模板velocity【从零开始学Spring Boot】

    虽然Spring Boot提供了默认的Velocity配置,但我们也可以根据需求自定义配置。在`application.properties`或`application.yml`中,可以设置Velocity的相关属性,如模板路径、编码等: ```properties # ...

Global site tag (gtag.js) - Google Analytics