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

📄 portletvelocityresult.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:   PortletVelocityResult.java

package org.apache.struts2.portlet.result;

import com.opensymphony.xwork2.*;
import com.opensymphony.xwork2.util.ValueStack;
import java.io.OutputStreamWriter;
import java.io.Writer;
import javax.portlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.PageContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.StrutsResultSupport;
import org.apache.struts2.portlet.context.PortletActionContext;
import org.apache.struts2.views.JspSupportServlet;
import org.apache.struts2.views.velocity.VelocityManager;
import org.apache.velocity.Template;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.Context;

public class PortletVelocityResult extends StrutsResultSupport
{

	private static final long serialVersionUID = 0x8da1c770c9fd4aceL;
	private static final Log log = LogFactory.getLog(org/apache/struts2/portlet/result/PortletVelocityResult);
	private String defaultEncoding;
	private VelocityManager velocityManager;

	public PortletVelocityResult()
	{
	}

	public PortletVelocityResult(String location)
	{
		super(location);
	}

	public void setVelocityManager(VelocityManager mgr)
	{
		velocityManager = mgr;
	}

	public void setDefaultEncoding(String encoding)
	{
		defaultEncoding = encoding;
	}

	public void doExecute(String location, ActionInvocation invocation)
		throws Exception
	{
		if (PortletActionContext.isEvent())
			executeActionResult(location, invocation);
		else
		if (PortletActionContext.isRender())
			executeRenderResult(location, invocation);
	}

	private void executeActionResult(String location, ActionInvocation invocation)
	{
		ActionResponse res = PortletActionContext.getActionResponse();
		res.setRenderParameter("struts.portlet.action", "freemarkerDirect");
		res.setRenderParameter("location", location);
		res.setRenderParameter("struts.portlet.mode", PortletActionContext.getRequest().getPortletMode().toString());
	}

	public void executeRenderResult(String finalLocation, ActionInvocation invocation)
		throws Exception
	{
		JspFactory jspFactory;
		PageContext pageContext;
		Exception exception;
		ValueStack stack = ActionContext.getContext().getValueStack();
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();
		jspFactory = null;
		javax.servlet.ServletContext servletContext = ServletActionContext.getServletContext();
		javax.servlet.Servlet servlet = JspSupportServlet.jspSupportServlet;
		velocityManager.init(servletContext);
		boolean usedJspFactory = false;
		pageContext = (PageContext)ActionContext.getContext().get("com.opensymphony.xwork2.dispatcher.PageContext");
		if (pageContext == null && servlet != null)
		{
			jspFactory = JspFactory.getDefaultFactory();
			pageContext = jspFactory.getPageContext(servlet, request, response, null, true, 8192, true);
			ActionContext.getContext().put("com.opensymphony.xwork2.dispatcher.PageContext", pageContext);
			usedJspFactory = true;
		}
		try
		{
			String encoding = getEncoding(finalLocation);
			String contentType = getContentType(finalLocation);
			if (encoding != null)
				contentType = (new StringBuilder()).append(contentType).append(";charset=").append(encoding).toString();
			response.setContentType(contentType);
			Template t = getTemplate(stack, velocityManager.getVelocityEngine(), invocation, finalLocation, encoding);
			Context context = createContext(velocityManager, stack, request, response, finalLocation);
			Writer writer = new OutputStreamWriter(response.getOutputStream(), encoding);
			t.merge(context, writer);
			writer.flush();
		}
		catch (Exception e)
		{
			log.error((new StringBuilder()).append("Unable to render Velocity Template, '").append(finalLocation).append("'").toString(), e);
			throw e;
		}
		finally
		{
			if (!usedJspFactory) goto _L0; else goto _L0
		}
		if (usedJspFactory)
			jspFactory.releasePageContext(pageContext);
		break MISSING_BLOCK_LABEL_294;
		jspFactory.releasePageContext(pageContext);
		throw exception;
	}

	protected String getContentType(String templateLocation)
	{
		return "text/html";
	}

	protected String getEncoding(String templateLocation)
	{
		String encoding = defaultEncoding;
		if (encoding == null)
			encoding = System.getProperty("file.encoding");
		if (encoding == null)
			encoding = "UTF-8";
		return encoding;
	}

	protected Template getTemplate(ValueStack stack, VelocityEngine velocity, ActionInvocation invocation, String location, String encoding)
		throws Exception
	{
		if (!location.startsWith("/"))
			location = (new StringBuilder()).append(invocation.getProxy().getNamespace()).append("/").append(location).toString();
		Template template = velocity.getTemplate(location, encoding);
		return template;
	}

	protected Context createContext(VelocityManager velocityManager, ValueStack stack, HttpServletRequest request, HttpServletResponse response, String location)
	{
		return velocityManager.createContext(stack, request, response);
	}

}

⌨️ 快捷键说明

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