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

📄 freemarkercontext.java

📁 Eclipse代码生成器,支持Eclipse3.3 WTP版本,该项目实现了Spring + hibernate + webService + struts 框架文件的自动生成,有这方面需求的个人公司
💻 JAVA
字号:
package com.newegg.eclipse.soaw.facet.codegen.ui.util;

import java.io.File;
import java.io.IOException;

import org.eclipse.core.runtime.IPath;
import org.eclipse.wst.ws.internal.common.BundleUtils;

import com.newegg.eclipse.soaw.facet.codegen.ui.CodeGenUIMessages;
import com.newegg.eclipse.soaw.facet.codegen.ui.plugin.CodeGenPlugin;

import freemarker.cache.ClassTemplateLoader;
import freemarker.cache.FileTemplateLoader;
import freemarker.cache.MultiTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.ObjectWrapper;

public class FreeMarkerContext
{
	private static FreeMarkerContext context = null;
	private static Configuration configuration;

	/**
	 * Default constructor.
	 * 
	 * @throws IOException
	 */
	private FreeMarkerContext () throws IOException
	{
		init();
	}

	/**
	 * Specify the data source where the template files come from. Here I set a file directory for
	 * it:
	 * 
	 * @throws IOException
	 */
	private void init() throws IOException
	{
		configuration = new Configuration();

		String pluginId = CodeGenUIMessages.NEWEGG_THIRDPART_PLUGINID;
		IPath templatePath = BundleUtils.getJarredPluginPath(pluginId).append("template/");
		IPath template_config_Path = templatePath.append("config/");
		IPath template_common_Path = templatePath.append("common/");
		IPath template_dao_Path = templatePath.append("dao/");
		IPath template_exception_Path = templatePath.append("exception/");
		IPath template_logic_Path = templatePath.append("service/");
		IPath template_model_Path = templatePath.append("model/");
		IPath template_service_Path = templatePath.append("webservice/");
		IPath template_profile_Path = templatePath.append("profile/");
		IPath template_servlet_Path = templatePath.append("servlet/");
		IPath template_util_Path = templatePath.append("util/");

		FileTemplateLoader ftl0 = new FileTemplateLoader(templatePath.toFile());
		FileTemplateLoader ftl1 = new FileTemplateLoader(template_config_Path.toFile());
		FileTemplateLoader ftl2 = new FileTemplateLoader(template_common_Path.toFile());
		FileTemplateLoader ftl3 = new FileTemplateLoader(template_dao_Path.toFile());
		FileTemplateLoader ftl4 = new FileTemplateLoader(template_exception_Path.toFile());
		FileTemplateLoader ftl5 = new FileTemplateLoader(template_logic_Path.toFile());
		FileTemplateLoader ftl6 = new FileTemplateLoader(template_model_Path.toFile());
		FileTemplateLoader ftl7 = new FileTemplateLoader(template_service_Path.toFile());
		FileTemplateLoader ftl8 = new FileTemplateLoader(template_profile_Path.toFile());
		FileTemplateLoader ftl9 = new FileTemplateLoader(template_servlet_Path.toFile());
		FileTemplateLoader ft20 = new FileTemplateLoader(template_util_Path.toFile());

		ClassTemplateLoader ctl = new ClassTemplateLoader(FreeMarkerContext.class, "");
		TemplateLoader[] loaders = new TemplateLoader[]
		{ ftl0, ftl1, ftl2, ftl3, ftl4, ftl5, ftl6, ftl7, ftl8, ftl9, ft20, ctl };
		MultiTemplateLoader mtl = new MultiTemplateLoader(loaders);
		configuration.setTemplateLoader(mtl);

		configuration.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
		configuration.setTemplateExceptionHandler(new CustomerTemplateExceptionHandler());
	}

	/**
	 * Get the instance.
	 * 
	 * @return the FreeMarkerContext
	 */
	public static FreeMarkerContext getInstance() throws IOException
	{
		if (context == null)
		{
			context = new FreeMarkerContext();
		}
		return context;
	}

	/**
	 * @return the configuration
	 */
	public static Configuration getConfiguration()
	{
		return configuration;
	}
}

⌨️ 快捷键说明

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