
com.jfinal.render.VelocityRender Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jfinal-java8 Show documentation
Show all versions of jfinal-java8 Show documentation
JFinal is a simple, light, rapid,independent, extensible Java WEB + ORM framework. The feature of JFinal looks like ruby on rails especially ActiveRecord.
The newest version!
/**
* Copyright (c) 2011-2019, James Zhan 詹波 ([email protected]).
*
* Licensed 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.
*/
package com.jfinal.render;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Map.Entry;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import javax.servlet.ServletContext;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
/**
* VelocityRender.
*/
public class VelocityRender extends Render {
private static final String contentType = "text/html; charset=" + getEncoding();
private static final Properties properties = new Properties();
private static boolean notInit = true;
public VelocityRender(String view) {
this.view = view;
}
/*
static {
String webPath = RenderManager.me().getServletContext().getRealPath("/");
Properties properties = new Properties();
properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, webPath);
properties.setProperty(Velocity.ENCODING_DEFAULT, encoding);
properties.setProperty(Velocity.INPUT_ENCODING, encoding);
properties.setProperty(Velocity.OUTPUT_ENCODING, encoding);
Velocity.init(properties); // Velocity.init("velocity.properties"); // setup
}*/
static void init(ServletContext servletContext) {
String webPath = servletContext.getRealPath("/");
if (webPath == null) {
try {
// 支持 weblogic: http://www.jfinal.com/feedback/1994
webPath = servletContext.getResource("/").getPath();
} catch (java.net.MalformedURLException e) {
com.jfinal.kit.LogKit.error(e.getMessage(), e);
}
}
properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, webPath);
properties.setProperty(Velocity.ENCODING_DEFAULT, getEncoding());
properties.setProperty(Velocity.INPUT_ENCODING, getEncoding());
properties.setProperty(Velocity.OUTPUT_ENCODING, getEncoding());
}
public static void setProperties(Properties properties) {
Set> set = properties.entrySet();
for (Iterator> it=set.iterator(); it.hasNext();) {
Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy