protected String getPath(Context context) {
ServletWebContext swcontext = (ServletWebContext) context;
HttpServletRequest request = swcontext.getRequest();
String path = null;
boolean extension = false;
// For prefix matching, match on the path info
path = (String) request.getAttribute(Constants.INCLUDE_PATH_INFO);
if (path == null) {
path = request.getPathInfo();
}
// For extension matching, match on the servlet path
if (path == null) {
path =
(String) request.getAttribute(Constants.INCLUDE_SERVLET_PATH);
if (path == null) {
path = request.getServletPath();
}
if (path == null) {
throw new IllegalArgumentException
("No path information in request");
}
extension = true;
}
// Strip the module prefix and extension (if any)
ModuleConfig moduleConfig = (ModuleConfig)
swcontext.get(getModuleConfigKey());
String prefix = moduleConfig.getPrefix();
if (!path.startsWith(prefix)) {
throw new IllegalArgumentException("Path does not start with '" +
prefix + "'");
}
path = path.substring(prefix.length());
if (extension) {
int slash = path.lastIndexOf("/");
int period = path.lastIndexOf(".");
if ((period >= 0) && (period > slash)) {
path = path.substring(0, period);
}
}
return (path);
}
|