Added extractFullFilenameFromUrlPath to WebUtils
This commit is contained in:
@@ -653,6 +653,20 @@ public abstract class WebUtils {
|
||||
* @return the extracted URI filename (e.g. "index")
|
||||
*/
|
||||
public static String extractFilenameFromUrlPath(String urlPath) {
|
||||
String filename = extractFullFilenameFromUrlPath(urlPath);
|
||||
int dotIndex = filename.lastIndexOf('.');
|
||||
if (dotIndex != -1) {
|
||||
filename = filename.substring(0, dotIndex);
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
/**
|
||||
* Extract the full URL filename (including file extension) from the given request URL path.
|
||||
* Correctly resolves nested paths such as "/products/view.html" as well.
|
||||
* @param urlPath the request URL path (e.g. "/products/index.html")
|
||||
* @return the extracted URI filename (e.g. "index.html")
|
||||
*/
|
||||
public static String extractFullFilenameFromUrlPath(String urlPath) {
|
||||
int end = urlPath.indexOf(';');
|
||||
if (end == -1) {
|
||||
end = urlPath.indexOf('?');
|
||||
@@ -661,12 +675,7 @@ public abstract class WebUtils {
|
||||
}
|
||||
}
|
||||
int begin = urlPath.lastIndexOf('/', end) + 1;
|
||||
String filename = urlPath.substring(begin, end);
|
||||
int dotIndex = filename.lastIndexOf('.');
|
||||
if (dotIndex != -1) {
|
||||
filename = filename.substring(0, dotIndex);
|
||||
}
|
||||
return filename;
|
||||
return urlPath.substring(begin, end);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user