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

📄 tagutils.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:   TagUtils.java

package org.apache.struts2.views.jsp;

import com.opensymphony.xwork2.*;
import com.opensymphony.xwork2.config.ConfigurationException;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import org.apache.struts2.RequestUtils;
import org.apache.struts2.dispatcher.*;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.apache.struts2.util.AttributeMap;

public class TagUtils
{

	public TagUtils()
	{
	}

	public static ValueStack getStack(PageContext pageContext)
	{
		HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
		ValueStack stack = (ValueStack)req.getAttribute("struts.valueStack");
		if (stack == null)
		{
			stack = ValueStackFactory.getFactory().createValueStack();
			HttpServletResponse res = (HttpServletResponse)pageContext.getResponse();
			Dispatcher du = Dispatcher.getInstance();
			if (du == null)
				throw new ConfigurationException("The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.");
			Map extraContext = du.createContextMap(new RequestMap(req), req.getParameterMap(), new SessionMap(req), new ApplicationMap(pageContext.getServletContext()), req, res, pageContext.getServletContext());
			extraContext.put("com.opensymphony.xwork2.dispatcher.PageContext", pageContext);
			stack.getContext().putAll(extraContext);
			req.setAttribute("struts.valueStack", stack);
			ActionContext.setContext(new ActionContext(stack.getContext()));
		} else
		{
			Map context = stack.getContext();
			context.put("com.opensymphony.xwork2.dispatcher.PageContext", pageContext);
			AttributeMap attrMap = new AttributeMap(context);
			context.put("attr", attrMap);
		}
		return stack;
	}

	public static String buildNamespace(ActionMapper mapper, ValueStack stack, HttpServletRequest request)
	{
		ActionContext context = new ActionContext(stack.getContext());
		ActionInvocation invocation = context.getActionInvocation();
		if (invocation == null)
		{
			ActionMapping mapping = mapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
			if (mapping != null)
			{
				return mapping.getNamespace();
			} else
			{
				String path = RequestUtils.getServletPath(request);
				return path.substring(0, path.lastIndexOf("/"));
			}
		} else
		{
			return invocation.getProxy().getNamespace();
		}
	}
}

⌨️ 快捷键说明

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