package com.stockvote.interceptor;


import java.util.Map;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class WebInfInterceptor implements Interceptor ...{
private static String PathPrefix = "/WEB-INF/";
private static final String LOCATION = "location";

public void destroy() ...{
}

public void init() ...{
if (PathPrefix.endsWith("/")) ...{
PathPrefix = PathPrefix.substring(0, PathPrefix.length() - 1);
}
}

public String intercept(ActionInvocation arg0) throws Exception ...{
Map map = arg0.getProxy().getConfig().getResults();

for (java.util.Iterator iter = map.values().iterator(); iter.hasNext();) ...{
ResultConfig rcg = (ResultConfig) iter.next();
transferLocation(rcg);
}
return arg0.invoke();
}

public void transferLocation(ResultConfig rcg) ...{
Map map = rcg.getParams();

if (!map.containsKey(LOCATION)) ...{
return;
}
// ////////////////////
String location = (String) map.get(LOCATION);

if (location.startsWith(PathPrefix)) ...{
return;
}

if (!location.startsWith("/")) ...{
location = "/" + location;
}
location = PathPrefix + location;
map.put(LOCATION, location);
}
}
下面是xml配置
<interceptor name="WebInfoPath" class="com.stockvote.interceptor.WebInfointerceptor"></interceptor>
<interceptor-stack name="defaultStack1">
<!--interceptor-ref name="log"></interceptor-ref!-->
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="WebInfoPath"></interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="defaultStack1"></default-interceptor-ref>
发表于 @ 2007年10月31日 22:49:00 | 评论( loading... ) | 举报| 收藏