📄 freemarkermanager.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: FreemarkerManager.java
package org.apache.struts2.views.freemarker;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.util.FileManager;
import com.opensymphony.xwork2.util.ValueStack;
import freemarker.cache.*;
import freemarker.ext.beans.BeansWrapper;
import freemarker.ext.jsp.TaglibFactory;
import freemarker.ext.servlet.*;
import freemarker.template.*;
import java.io.*;
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.JspSupportServlet;
import org.apache.struts2.views.TagLibrary;
import org.apache.struts2.views.util.ContextUtil;
// Referenced classes of package org.apache.struts2.views.freemarker:
// ScopesHashModel, StrutsBeanWrapper, StrutsClassTemplateLoader
public class FreemarkerManager
{
private static final Log LOG = LogFactory.getLog(org/apache/struts2/views/freemarker/FreemarkerManager);
public static final String CONFIG_SERVLET_CONTEXT_KEY = "freemarker.Configuration";
public static final String KEY_EXCEPTION = "exception";
private static final String ATTR_APPLICATION_MODEL = ".freemarker.Application";
private static final String ATTR_JSP_TAGLIBS_MODEL = ".freemarker.JspTaglibs";
private static final String ATTR_REQUEST_MODEL = ".freemarker.Request";
private static final String ATTR_REQUEST_PARAMETERS_MODEL = ".freemarker.RequestParameters";
public static final String KEY_APPLICATION = "Application";
public static final String KEY_REQUEST_MODEL = "Request";
public static final String KEY_SESSION_MODEL = "Session";
public static final String KEY_JSP_TAGLIBS = "JspTaglibs";
public static final String KEY_REQUEST_PARAMETER_MODEL = "Parameters";
private String encoding;
private boolean altMapWrapper;
private Map tagLibraries;
public FreemarkerManager()
{
}
public void setEncoding(String encoding)
{
this.encoding = encoding;
}
public void setWrapperAltMap(String val)
{
altMapWrapper = "true".equals(val);
}
public void setContainer(Container container)
{
Map map = new HashMap();
Set prefixes = container.getInstanceNames(org/apache/struts2/views/TagLibrary);
String prefix;
for (Iterator i$ = prefixes.iterator(); i$.hasNext(); map.put(prefix, container.getInstance(org/apache/struts2/views/TagLibrary, prefix)))
prefix = (String)i$.next();
tagLibraries = Collections.unmodifiableMap(map);
}
public final synchronized Configuration getConfiguration(ServletContext servletContext)
throws TemplateException
{
Configuration config = (Configuration)servletContext.getAttribute("freemarker.Configuration");
if (config == null)
{
config = createConfiguration(servletContext);
servletContext.setAttribute("freemarker.Configuration", config);
}
config.setWhitespaceStripping(true);
return config;
}
protected ScopesHashModel buildScopesHashModel(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, ObjectWrapper wrapper, ValueStack stack)
{
ScopesHashModel model = new ScopesHashModel(wrapper, servletContext, request, stack);
synchronized (servletContext)
{
ServletContextHashModel servletContextModel = (ServletContextHashModel)servletContext.getAttribute(".freemarker.Application");
if (servletContextModel == null)
{
javax.servlet.GenericServlet servlet = JspSupportServlet.jspSupportServlet;
if (servlet != null)
{
servletContextModel = new ServletContextHashModel(servlet, wrapper);
servletContext.setAttribute(".freemarker.Application", servletContextModel);
TaglibFactory taglibs = new TaglibFactory(servletContext);
servletContext.setAttribute(".freemarker.JspTaglibs", taglibs);
}
}
model.put("Application", servletContextModel);
model.put("JspTaglibs", (TemplateModel)servletContext.getAttribute(".freemarker.JspTaglibs"));
}
javax.servlet.http.HttpSession session = request.getSession(false);
if (session != null)
model.put("Session", new HttpSessionHashModel(session, wrapper));
HttpRequestHashModel requestModel = (HttpRequestHashModel)request.getAttribute(".freemarker.Request");
if (requestModel == null || requestModel.getRequest() != request)
{
requestModel = new HttpRequestHashModel(request, response, wrapper);
request.setAttribute(".freemarker.Request", requestModel);
}
model.put("Request", requestModel);
HttpRequestParametersHashModel reqParametersModel = (HttpRequestParametersHashModel)request.getAttribute(".freemarker.RequestParameters");
if (reqParametersModel == null || requestModel.getRequest() != request)
{
reqParametersModel = new HttpRequestParametersHashModel(request);
request.setAttribute(".freemarker.RequestParameters", reqParametersModel);
}
model.put("Parameters", reqParametersModel);
return model;
}
protected void populateContext(ScopesHashModel model, ValueStack stack, Object action, HttpServletRequest request, HttpServletResponse response)
{
Map standard = ContextUtil.getStandardContext(stack, request, response);
model.putAll(standard);
Throwable exception = (Throwable)request.getAttribute("javax.servlet.error.exception");
if (exception == null)
exception = (Throwable)request.getAttribute("javax.servlet.error.JspException");
if (exception != null)
model.put("exception", exception);
}
protected BeansWrapper getObjectWrapper()
{
return new StrutsBeanWrapper(altMapWrapper);
}
protected TemplateLoader getTemplateLoader(ServletContext servletContext)
{
FileTemplateLoader templatePathLoader = null;
String templatePath = servletContext.getInitParameter("TemplatePath");
if (templatePath == null)
templatePath = servletContext.getInitParameter("templatePath");
if (templatePath != null)
try
{
templatePathLoader = new FileTemplateLoader(new File(templatePath));
}
catch (IOException e)
{
LOG.error((new StringBuilder()).append("Invalid template path specified: ").append(e.getMessage()).toString(), e);
}
return templatePathLoader == null ? new MultiTemplateLoader(new TemplateLoader[] {
new WebappTemplateLoader(servletContext), new StrutsClassTemplateLoader()
}) : new MultiTemplateLoader(new TemplateLoader[] {
templatePathLoader, new WebappTemplateLoader(servletContext), new StrutsClassTemplateLoader()
});
}
protected Configuration createConfiguration(ServletContext servletContext)
throws TemplateException
{
Configuration configuration = new Configuration();
configuration.setTemplateLoader(getTemplateLoader(servletContext));
configuration.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
configuration.setObjectWrapper(getObjectWrapper());
if (encoding != null)
configuration.setDefaultEncoding(encoding);
loadSettings(servletContext, configuration);
return configuration;
}
protected void loadSettings(ServletContext servletContext, Configuration configuration)
{
InputStream in = null;
in = FileManager.loadFile("freemarker.properties", org/apache/struts2/views/freemarker/FreemarkerManager);
if (in != null)
{
Properties p = new Properties();
p.load(in);
configuration.setSettings(p);
}
if (in != null)
try
{
in.close();
}
catch (IOException io)
{
LOG.warn("Unable to close input stream", io);
}
break MISSING_BLOCK_LABEL_178;
IOException e;
e;
LOG.error("Error while loading freemarker settings from /freemarker.properties", e);
if (in != null)
try
{
in.close();
}
catch (IOException io)
{
LOG.warn("Unable to close input stream", io);
}
break MISSING_BLOCK_LABEL_178;
io;
LOG.error("Error while loading freemarker settings from /freemarker.properties", io);
if (in != null)
try
{
in.close();
}
catch (IOException io)
{
LOG.warn("Unable to close input stream", io);
}
break MISSING_BLOCK_LABEL_178;
Exception exception;
exception;
if (in != null)
try
{
in.close();
}
catch (IOException io)
{
LOG.warn("Unable to close input stream", io);
}
throw exception;
}
public SimpleHash buildTemplateModel(ValueStack stack, Object action, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, ObjectWrapper wrapper)
{
ScopesHashModel model = buildScopesHashModel(servletContext, request, response, wrapper, stack);
populateContext(model, stack, action, request, response);
String prefix;
for (Iterator i$ = tagLibraries.keySet().iterator(); i$.hasNext(); model.put(prefix, ((TagLibrary)tagLibraries.get(prefix)).getFreemarkerModels(stack, request, response)))
prefix = (String)i$.next();
return model;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -