📄 cookieinterceptor.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: CookieInterceptor.java
package org.apache.struts2.interceptor;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.TextParseUtil;
import com.opensymphony.xwork2.util.ValueStack;
import java.util.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
// Referenced classes of package org.apache.struts2.interceptor:
// CookiesAware
public class CookieInterceptor extends AbstractInterceptor
{
private static final long serialVersionUID = 0x39a2ed09d982fc29L;
private static final Log LOG = LogFactory.getLog(org/apache/struts2/interceptor/CookieInterceptor);
private Set cookiesNameSet;
private Set cookiesValueSet;
public CookieInterceptor()
{
cookiesNameSet = Collections.EMPTY_SET;
cookiesValueSet = Collections.EMPTY_SET;
}
public void setCookiesName(String cookiesName)
{
if (cookiesName != null)
cookiesNameSet = TextParseUtil.commaDelimitedStringToSet(cookiesName);
}
public void setCookiesValue(String cookiesValue)
{
if (cookiesValue != null)
cookiesValueSet = TextParseUtil.commaDelimitedStringToSet(cookiesValue);
}
public String intercept(ActionInvocation invocation)
throws Exception
{
if (LOG.isDebugEnabled())
LOG.debug("start interception");
ValueStack stack = ActionContext.getContext().getValueStack();
HttpServletRequest request = ServletActionContext.getRequest();
Map cookiesMap = new LinkedHashMap();
Cookie cookies[] = request.getCookies();
if (cookies != null)
{
for (int a = 0; a < cookies.length; a++)
{
String name = cookies[a].getName();
String value = cookies[a].getValue();
if (cookiesNameSet.contains("*"))
{
if (LOG.isDebugEnabled())
LOG.debug((new StringBuilder()).append("contains cookie name [*] in configured cookies name set, cookie with name [").append(name).append("] with value [").append(value).append("] will be injected").toString());
populateCookieValueIntoStack(name, value, cookiesMap, stack);
continue;
}
if (cookiesNameSet.contains(cookies[a].getName()))
populateCookieValueIntoStack(name, value, cookiesMap, stack);
}
}
injectIntoCookiesAwareAction(invocation.getAction(), cookiesMap);
return invocation.invoke();
}
protected void populateCookieValueIntoStack(String cookieName, String cookieValue, Map cookiesMap, ValueStack stack)
{
if (cookiesValueSet.isEmpty() || cookiesValueSet.contains("*"))
{
if (LOG.isDebugEnabled())
if (cookiesValueSet.isEmpty())
LOG.debug((new StringBuilder()).append("no cookie value is configured, cookie with name [").append(cookieName).append("] with value [").append(cookieValue).append("] will be injected").toString());
else
if (cookiesValueSet.contains("*"))
LOG.debug((new StringBuilder()).append("interceptor is configured to accept any value, cookie with name [").append(cookieName).append("] with value [").append(cookieValue).append("] will be injected").toString());
cookiesMap.put(cookieName, cookieValue);
stack.setValue(cookieName, cookieValue);
} else
if (cookiesValueSet.contains(cookieValue))
{
if (LOG.isDebugEnabled())
LOG.debug((new StringBuilder()).append("both configured cookie name and value matched, cookie [").append(cookieName).append("] with value [").append(cookieValue).append("] will be injected").toString());
cookiesMap.put(cookieName, cookieValue);
stack.setValue(cookieName, cookieValue);
}
}
protected void injectIntoCookiesAwareAction(Object action, Map cookiesMap)
{
if (action instanceof CookiesAware)
{
if (LOG.isDebugEnabled())
LOG.debug((new StringBuilder()).append("action [").append(action).append("] implements CookiesAware, injecting cookies map [").append(cookiesMap).append("]").toString());
((CookiesAware)action).setCookiesMap(cookiesMap);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -