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

📄 portletresult.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:   PortletResult.java

package org.apache.struts2.portlet.result;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.util.TextUtils;
import java.io.IOException;
import java.util.Map;
import java.util.StringTokenizer;
import javax.portlet.*;
import javax.servlet.*;
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.PortletActionConstants;
import org.apache.struts2.portlet.context.PortletActionContext;

public class PortletResult extends StrutsResultSupport
	implements PortletActionConstants
{
	static class IncludeTemplate
	{

		protected void include(PortletRequestDispatcher dispatcher, RenderRequest req, RenderResponse res)
			throws PortletException, IOException
		{
			try
			{
				dispatcher.include(req, res);
			}
			catch (PortletException e)
			{
				when(e);
				throw e;
			}
			catch (IOException e)
			{
				when(e);
				throw e;
			}
		}

		protected void when(PortletException portletexception)
		{
		}

		protected void when(IOException ioexception)
		{
		}

		IncludeTemplate()
		{
		}
	}


	private static final long serialVersionUID = 0x606c5578e302707L;
	private static final Log LOG = LogFactory.getLog(org/apache/struts2/portlet/result/PortletResult);
	private String contentType;
	private String title;

	public PortletResult()
	{
		contentType = "text/html";
	}

	public PortletResult(String location)
	{
		super(location);
		contentType = "text/html";
	}

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

	private void executeRegularServletResult(String finalLocation, ActionInvocation actionInvocation)
		throws ServletException, IOException
	{
		ServletContext ctx = ServletActionContext.getServletContext();
		javax.servlet.http.HttpServletRequest req = ServletActionContext.getRequest();
		javax.servlet.http.HttpServletResponse res = ServletActionContext.getResponse();
		try
		{
			ctx.getRequestDispatcher(finalLocation).include(req, res);
		}
		catch (ServletException e)
		{
			LOG.error((new StringBuilder()).append("ServletException including ").append(finalLocation).toString(), e);
			throw e;
		}
		catch (IOException e)
		{
			LOG.error((new StringBuilder()).append("IOException while including result '").append(finalLocation).append("'").toString(), e);
			throw e;
		}
	}

	protected void executeActionResult(String finalLocation, ActionInvocation invocation)
	{
		LOG.debug("Executing result in Event phase");
		ActionResponse res = PortletActionContext.getActionResponse();
		Map sessionMap = invocation.getInvocationContext().getSession();
		LOG.debug((new StringBuilder()).append("Setting event render parameter: ").append(finalLocation).toString());
		if (finalLocation.indexOf('?') != -1)
		{
			convertQueryParamsToRenderParams(res, finalLocation.substring(finalLocation.indexOf('?') + 1));
			finalLocation = finalLocation.substring(0, finalLocation.indexOf('?'));
		}
		if (finalLocation.endsWith(".action"))
		{
			finalLocation = finalLocation.substring(0, finalLocation.lastIndexOf("."));
			res.setRenderParameter("struts.portlet.action", finalLocation);
		} else
		{
			res.setRenderParameter("struts.portlet.action", "renderDirect");
			sessionMap.put("struts.portlet.renderDirectLocation", finalLocation);
		}
		res.setRenderParameter("struts.portlet.mode", PortletActionContext.getRequest().getPortletMode().toString());
	}

	protected static void convertQueryParamsToRenderParams(ActionResponse response, String queryParams)
	{
		String key;
		String value;
		for (StringTokenizer tok = new StringTokenizer(queryParams, "&"); tok.hasMoreTokens(); response.setRenderParameter(key, value))
		{
			String token = tok.nextToken();
			key = token.substring(0, token.indexOf('='));
			value = token.substring(token.indexOf('=') + 1);
		}

	}

	protected void executeRenderResult(final String finalLocation)
		throws PortletException, IOException
	{
		LOG.debug("Executing result in Render phase");
		PortletConfig cfg = PortletActionContext.getPortletConfig();
		RenderRequest req = PortletActionContext.getRenderRequest();
		RenderResponse res = PortletActionContext.getRenderResponse();
		LOG.debug((new StringBuilder()).append("PortletConfig: ").append(cfg).toString());
		LOG.debug((new StringBuilder()).append("RenderRequest: ").append(req).toString());
		LOG.debug((new StringBuilder()).append("RenderResponse: ").append(res).toString());
		res.setContentType(contentType);
		if (TextUtils.stringSet(title))
			res.setTitle(title);
		LOG.debug((new StringBuilder()).append("Location: ").append(finalLocation).toString());
		PortletRequestDispatcher dispatcher = cfg.getPortletContext().getRequestDispatcher(finalLocation);
		if (dispatcher == null)
		{
			throw new PortletException((new StringBuilder()).append("Could not locate dispatcher for '").append(finalLocation).append("'").toString());
		} else
		{
			(new IncludeTemplate() {

				final String val$finalLocation;
				final PortletResult this$0;

				protected void when(PortletException e)
				{
					PortletResult.LOG.error((new StringBuilder()).append("PortletException while dispatching to '").append(finalLocation).append("'").toString());
				}

				protected void when(IOException e)
				{
					PortletResult.LOG.error((new StringBuilder()).append("IOException while dispatching to '").append(finalLocation).append("'").toString());
				}

			
			{
				this$0 = PortletResult.this;
				finalLocation = s;
				super();
			}
			}).include(dispatcher, req, res);
			return;
		}
	}

	public void setContentType(String contentType)
	{
		this.contentType = contentType;
	}

	public void setTitle(String title)
	{
		this.title = title;
	}


}

⌨️ 快捷键说明

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