Servlet 4.0 getMappings rough implementation #746

This commit is contained in:
Greg Wilkins 2016-07-21 17:07:10 +10:00
parent b8b9d222eb
commit f3efded065
1 changed files with 45 additions and 21 deletions

View File

@ -2416,13 +2416,51 @@ public class Request implements HttpServletRequest
public Mapping getMapping() public Mapping getMapping()
{ {
final PathSpec pathSpec = _pathSpec; final PathSpec pathSpec = _pathSpec;
final String servletPath = _servletPath; final MappingMatch match;
final String mapping;
if (pathSpec instanceof ServletPathSpec)
{
switch(((ServletPathSpec)pathSpec).getGroup())
{
case ROOT:
match = MappingMatch.CONTEXT_ROOT;
mapping = "";
break;
case DEFAULT:
match = MappingMatch.DEFAULT;
mapping = "/";
break;
case EXACT:
match = MappingMatch.EXACT;
mapping = _servletPath;
break;
case SUFFIX_GLOB:
match = MappingMatch.EXTENSION;
int dot = _servletPath.lastIndexOf('.');
mapping = _servletPath.substring(0,dot);
break;
case PREFIX_GLOB:
match = MappingMatch.PATH;
mapping = _servletPath;
break;
default:
match = MappingMatch.UNKNOWN;
mapping = _servletPath;
break;
}
}
else
{
match = MappingMatch.UNKNOWN;
mapping = _servletPath;
}
return new Mapping() return new Mapping()
{ {
@Override @Override
public String getMatchValue() public String getMatchValue()
{ {
return servletPath; return mapping;
} }
@Override @Override
@ -2436,27 +2474,13 @@ public class Request implements HttpServletRequest
@Override @Override
public MappingMatch getMatchType() public MappingMatch getMatchType()
{ {
if (pathSpec instanceof ServletPathSpec) return match;
{
switch(((ServletPathSpec)pathSpec).getGroup())
{
case EXACT:
return MappingMatch.EXACT;
case ROOT:
return MappingMatch.CONTEXT_ROOT;
case PREFIX_GLOB:
return MappingMatch.PATH;
case SUFFIX_GLOB:
return MappingMatch.EXTENSION;
default:
return MappingMatch.UNKNOWN;
}
}
else
return MappingMatch.UNKNOWN;
} }
public String getServletName()
{
return null;
}
}; };
} }