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

📄 freemarkertemplateengine.java

📁 struts 2 核心包 的源码 有错误是难免的
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   FreemarkerTemplateEngine.java

package org.apache.struts2.components.template;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.ValueStack;
import freemarker.template.*;
import java.io.IOException;
import java.io.Writer;
import java.util.*;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.views.freemarker.FreemarkerManager;

// Referenced classes of package org.apache.struts2.components.template:
//			BaseTemplateEngine, Template, TemplateRenderingContext

public class FreemarkerTemplateEngine extends BaseTemplateEngine
{

	static Class bodyContent = null;
	private FreemarkerManager freemarkerManager;
	private final HashMap templates = new HashMap();
	private final HashSet missingTemplates = new HashSet();
	private boolean freemarkerCaching;
	private static final Log LOG = LogFactory.getLog(org/apache/struts2/components/template/FreemarkerTemplateEngine);

	public FreemarkerTemplateEngine()
	{
		freemarkerCaching = false;
	}

	public void setFreemarkerManager(FreemarkerManager mgr)
	{
		freemarkerManager = mgr;
	}

	public void renderTemplate(TemplateRenderingContext templateContext)
		throws Exception
	{
		ValueStack stack;
		Template template;
		SimpleHash model;
		Writer writer;
		stack = templateContext.getStack();
		Map context = stack.getContext();
		ServletContext servletContext = (ServletContext)context.get("com.opensymphony.xwork2.dispatcher.ServletContext");
		HttpServletRequest req = (HttpServletRequest)context.get("com.opensymphony.xwork2.dispatcher.HttpServletRequest");
		HttpServletResponse res = (HttpServletResponse)context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse");
		Configuration config = freemarkerManager.getConfiguration(servletContext);
		List templates = templateContext.getTemplate().getPossibleTemplates(this);
		template = null;
		String templateName = null;
		Exception exception = null;
		Iterator i$ = templates.iterator();
		do
		{
			if (!i$.hasNext())
				break;
			org.apache.struts2.components.template.Template t = (org.apache.struts2.components.template.Template)i$.next();
			templateName = getFinalTemplateName(t);
			if (freemarkerCaching)
			{
				if (isTemplateMissing(templateName))
					continue;
				try
				{
					template = findInCache(templateName);
					if (template == null)
					{
						template = config.getTemplate(templateName);
						addToCache(templateName, template);
					}
					break;
				}
				catch (IOException e)
				{
					addToMissingTemplateCache(templateName);
					if (exception == null)
						exception = e;
				}
				continue;
			}
			try
			{
				template = config.getTemplate(templateName);
				break;
			}
			catch (IOException e)
			{
				if (exception == null)
					exception = e;
			}
		} while (true);
		if (template == null)
		{
			LOG.error((new StringBuilder()).append("Could not load template ").append(templateContext.getTemplate()).toString());
			if (exception != null)
				throw exception;
			else
				return;
		}
		if (LOG.isDebugEnabled())
			LOG.debug((new StringBuilder()).append("Rendering template ").append(templateName).toString());
		ActionInvocation ai = ActionContext.getContext().getActionInvocation();
		Object action = ai != null ? ai.getAction() : null;
		model = freemarkerManager.buildTemplateModel(stack, action, servletContext, req, res, config.getObjectWrapper());
		model.put("tag", templateContext.getTag());
		model.put("themeProperties", getThemeProps(templateContext.getTemplate()));
		writer = templateContext.getWriter();
		if (bodyContent != null && bodyContent.isAssignableFrom(writer.getClass()))
		{
			final Writer wrapped = writer;
			writer = new Writer() {

				final Writer val$wrapped;
				final FreemarkerTemplateEngine this$0;

				public void write(char cbuf[], int off, int len)
					throws IOException
				{
					wrapped.write(cbuf, off, len);
				}

				public void flush()
					throws IOException
				{
				}

				public void close()
					throws IOException
				{
					wrapped.close();
				}

			
				throws IOException
			{
				this$0 = FreemarkerTemplateEngine.this;
				wrapped = writer;
				super();
			}
			};
		}
		stack.push(templateContext.getTag());
		template.process(model, writer);
		stack.pop();
		break MISSING_BLOCK_LABEL_456;
		Exception exception1;
		exception1;
		stack.pop();
		throw exception1;
	}

	protected String getSuffix()
	{
		return "ftl";
	}

	protected void addToMissingTemplateCache(String templateName)
	{
		synchronized (missingTemplates)
		{
			missingTemplates.add(templateName);
		}
	}

	protected boolean isTemplateMissing(String templateName)
	{
		HashSet hashset = missingTemplates;
		JVM INSTR monitorenter ;
		return missingTemplates.contains(templateName);
		Exception exception;
		exception;
		throw exception;
	}

	protected void addToCache(String templateName, Template template)
	{
		synchronized (templates)
		{
			templates.put(templateName, template);
		}
	}

	protected Template findInCache(String templateName)
	{
		HashMap hashmap = templates;
		JVM INSTR monitorenter ;
		return (Template)templates.get(templateName);
		Exception exception;
		exception;
		throw exception;
	}

	public void setCacheTemplates(String cacheTemplates)
	{
		freemarkerCaching = "true".equals(cacheTemplates);
	}

	static 
	{
		try
		{
			bodyContent = ClassLoaderUtil.loadClass("javax.servlet.jsp.tagext.BodyContent", org/apache/struts2/components/template/FreemarkerTemplateEngine);
		}
		catch (ClassNotFoundException e) { }
	}
}

⌨️ 快捷键说明

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