Class ConversionUtils
-
- All Implemented Interfaces:
public class ConversionUtilsGeneral purpose conversion utilities related to HTTP/HTML
-
-
Constructor Summary
Constructors Constructor Description ConversionUtils()
-
Method Summary
Modifier and Type Method Description static StringgetEncodingFromContentType(String contentType)Extract the encoding (charset) from the Content-Type, e.g. static StringpercentEncode(String value)Encodes the string according to RFC7578 and RFC3986. static URLmakeRelativeURL(URL baseURL, String location)Generate an absolute URL from a possibly relative location, allowing for extraneous leading "../" segments. static StringescapeIllegalURLCharacters(String url)static URIsanitizeUrl(URL url)Checks a URL and encodes it if necessary, i.e. static StringremoveSlashDotDot(String url)collapses absolute or relative URLs containing '/.. -
-
Method Detail
-
getEncodingFromContentType
static String getEncodingFromContentType(String contentType)
Extract the encoding (charset) from the Content-Type, e.g. "text/html; charset=utf-8".
- Parameters:
contentType- string from which the encoding should be extracted
-
percentEncode
@API(status = API.Status.MAINTAINED, since = "5.6") static String percentEncode(String value)
Encodes the string according to RFC7578 and RFC3986. The string is UTF-8 encoded, and non-ASCII bytes are represented as
%XX. It is close to UrlEncode, however,percentEncodedoes not replace space with +.- Parameters:
value- input value to convert
-
makeRelativeURL
static URL makeRelativeURL(URL baseURL, String location)
Generate an absolute URL from a possibly relative location, allowing for extraneous leading "../" segments. The Java URL constructor does not remove these.
- Parameters:
baseURL- the base URL which is used to resolve missing protocol/host in the locationlocation- the location, possibly with extraneous leading "..
-
escapeIllegalURLCharacters
static String escapeIllegalURLCharacters(String url)
- Parameters:
url- String Url to escape
-
sanitizeUrl
static URI sanitizeUrl(URL url)
Checks a URL and encodes it if necessary, i.e. if it is not currently correctly encoded. Warning: it may not work on all unencoded URLs.
- Parameters:
url- non-encoded URL
-
removeSlashDotDot
static String removeSlashDotDot(String url)
collapses absolute or relative URLs containing '/..' converting
http://host/path1/../path2tohttp://host/path2or/one/two/../threeto/one/three- Parameters:
url- in which the '/..
-
-
-
-