📄 restful2actionmapper.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: Restful2ActionMapper.java
package org.apache.struts2.dispatcher.mapper;
import com.opensymphony.xwork2.config.ConfigurationManager;
import java.net.URLDecoder;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
// Referenced classes of package org.apache.struts2.dispatcher.mapper:
// DefaultActionMapper, ActionMapping
public class Restful2ActionMapper extends DefaultActionMapper
{
protected static final Log LOG = LogFactory.getLog(org/apache/struts2/dispatcher/mapper/Restful2ActionMapper);
public static final String HTTP_METHOD_PARAM = "__http_method";
private String idParameterName;
public Restful2ActionMapper()
{
idParameterName = null;
setSlashesInActionNames("true");
}
public ActionMapping getMapping(HttpServletRequest request, ConfigurationManager configManager)
{
if (!isSlashesInActionNames())
throw new IllegalStateException("This action mapper requires the setting 'slashesInActionNames' to be set to 'true'");
ActionMapping mapping = super.getMapping(request, configManager);
if (mapping == null)
return null;
String actionName = mapping.getName();
if (actionName != null && actionName.length() > 0)
{
int lastSlashPos = actionName.lastIndexOf('/');
if (mapping.getMethod() == null)
{
if (lastSlashPos == actionName.length() - 1)
{
if (isGet(request))
mapping.setMethod("index");
else
if (isPost(request))
mapping.setMethod("create");
} else
if (lastSlashPos > -1)
{
String id = actionName.substring(lastSlashPos + 1);
if (isGet(request) && "new".equals(id))
mapping.setMethod("editNew");
else
if (isGet(request))
mapping.setMethod("view");
else
if (isDelete(request))
mapping.setMethod("remove");
else
if (isPut(request))
mapping.setMethod("update");
if (idParameterName != null)
{
if (mapping.getParams() == null)
mapping.setParams(new HashMap());
mapping.getParams().put(idParameterName, id);
}
}
if (idParameterName != null && lastSlashPos > -1)
actionName = actionName.substring(0, lastSlashPos);
}
int actionSlashPos = actionName.lastIndexOf('/', lastSlashPos - 1);
if (actionSlashPos > 0 && actionSlashPos < lastSlashPos)
{
String params = actionName.substring(0, actionSlashPos);
HashMap parameters = new HashMap();
try
{
StringTokenizer st = new StringTokenizer(params, "/");
boolean isNameTok = true;
String paramName = null;
while (st.hasMoreTokens())
if (isNameTok)
{
paramName = URLDecoder.decode(st.nextToken(), "UTF-8");
isNameTok = false;
} else
{
String paramValue = URLDecoder.decode(st.nextToken(), "UTF-8");
if (paramName != null && paramName.length() > 0)
parameters.put(paramName, paramValue);
isNameTok = true;
}
if (parameters.size() > 0)
{
if (mapping.getParams() == null)
mapping.setParams(new HashMap());
mapping.getParams().putAll(parameters);
}
}
catch (Exception e)
{
LOG.warn(e);
}
mapping.setName(actionName.substring(actionSlashPos + 1));
}
}
return mapping;
}
protected boolean isGet(HttpServletRequest request)
{
return "get".equalsIgnoreCase(request.getMethod());
}
protected boolean isPost(HttpServletRequest request)
{
return "post".equalsIgnoreCase(request.getMethod());
}
protected boolean isPut(HttpServletRequest request)
{
if ("put".equalsIgnoreCase(request.getMethod()))
return true;
else
return isPost(request) && "put".equalsIgnoreCase(request.getParameter("__http_method"));
}
protected boolean isDelete(HttpServletRequest request)
{
if ("delete".equalsIgnoreCase(request.getMethod()))
return true;
else
return isPost(request) && "delete".equalsIgnoreCase(request.getParameter("__http_method"));
}
public String getIdParameterName()
{
return idParameterName;
}
public void setIdParameterName(String idParameterName)
{
this.idParameterName = idParameterName;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -