public final class UrlMethods extends Object
Modifier and Type | Method and Description |
---|---|
static String |
asUrlPathSegment(String string)
Escapes the provided string such that they can be safely included in URL path segments.
|
static String |
constructUrl(HttpServletRequest request) |
static String |
constructUrl(HttpServletRequest request,
boolean includeContextPath) |
static String |
extractRemainder(String from,
String uri) |
static String |
filenameFromContentDisposition(String name)
Attempts to extract the
filename from a provided string. |
static String |
filenameFromUrl(String url)
Attempts to extract a filename based from the provided
url . |
static String |
getBaseUrl(HttpServletRequest req) |
static String |
getBaseUrl(HttpServletRequest req,
boolean withProtocol) |
public static String constructUrl(HttpServletRequest request)
public static String constructUrl(HttpServletRequest request, boolean includeContextPath)
public static String getBaseUrl(HttpServletRequest req)
public static String getBaseUrl(HttpServletRequest req, boolean withProtocol)
public static String filenameFromContentDisposition(String name)
filename
from a provided string. Possible values
are in the form of:
Content-Disposition: inline
Content-Disposition: attachment
Content-Disposition: attachment; filename="filename.jpg"
Content-Disposition: form-data
Content-Disposition: form-data; name="fieldName"
Content-Disposition: form-data; name="fieldName"; filename="filename.jpg"
The results for the above will then be:
filenameFromContentDisposition( "inline" ) => null
filenameFromContentDisposition( "attachment" ) => null
filenameFromContentDisposition( "attachment; filename=\"filename.jpg\"" ) => "filename.jpg"
filenameFromContentDisposition( "form-data" ) => null
filenameFromContentDisposition( "form-data; name="fieldName"" ) => null
filenameFromContentDisposition( "form-data; name="fieldName"; filename=\"filename.jpg\"" ) => "filename.jpg"
name
- the value of the Content-Disposition
headername
, or name
public static String filenameFromUrl(String url)
url
.
This method simply takes the last path segment of the URL, stripping
query parameters, if any.url
- the string-based URL to resolve a filenameurl
, or nullpublic static String asUrlPathSegment(String string)
When escaping a String, the following rules apply:
Copyright © 2019. All rights reserved.