⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 velocityfactory.java.svn-base

📁 EasyJWeb是基于java技术
💻 SVN-BASE
字号:
package com.easyjf.web.tools.generator;

import java.io.File;
import java.util.Properties;

import org.apache.velocity.Template;
import org.apache.velocity.app.VelocityEngine;

public class VelocityFactory {
	private static VelocityEngine ve;

	private VelocityFactory() {
	}

	private static VelocityEngine getVEngine(String templateDir) {
		if (ve == null)
			doInit(templateDir);
		
		ve.setProperty("file.resource.loader.path", templateDir);
		return ve;
	}

	private static void doInit(String templateDir) {
		Properties p = new Properties();
		ve = new VelocityEngine();		
		File f=new File(templateDir);
		System.out.println(f.getAbsolutePath());
		if(!f.exists())System.out.println("模板目录:" + templateDir+"不存在!");
		p.setProperty("file.resource.loader.path", templateDir);
		try {
			ve.init(p);
		} catch (Exception e) {
			System.out.println("初始化错误:" + e);
		}
	}

	public static VelocityEngine getVelocityEngine(String templateDir) {

		Properties p = new Properties();
		VelocityEngine ve = new VelocityEngine();
		p.setProperty("file.resource.loader.path", templateDir);
		try {
			ve.init(p);
		} catch (Exception e) {
			System.out.println("初始化错误:" + e);
		}
		return ve;
	}

	public static Template getTemplate(String templateDir, String fileName)
			throws Exception {
		return getTemplate(templateDir, fileName, "UTF-8");
	}

	public static Template getTemplate(String templateDir, String fileName,
			String encoding) throws Exception {
		Template template = null;
		try {
			template = getVEngine(templateDir).getTemplate(fileName, encoding);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		return template;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -