Package net.sourceforge.jnlp.util
Class UrlUtils
java.lang.Object
net.sourceforge.jnlp.util.UrlUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic File
decodeUrlAsFile
(URL url) static URL
decodeUrlQuietly
(URL url) static String
static URL
static boolean
equalsIgnoreLastSlash
(URL u1, URL u2) both urls are processed by sanitizeLastSlash before actual equals.static String
getHostAndPort
(URL url) static int
static int
static URL
guessCodeBase
(JNLPFile file) static boolean
isLocalFile
(URL url) static boolean
isValidRFC2396Url
(URL url) static String
static String
static String[]
static String[]
loadUrlWithInvalidHeader
(URL url, Charset ch) static Object[]
static URL
normalizeUrl
(URL url) static URL
normalizeUrl
(URL url, boolean encodeFileUrls) static URL
static URL
normalizeUrlAndStripParams
(URL url, boolean encodeFileUrls) static URL
normalizeUrlQuietly
(URL url) static URL
normalizeUrlQuietly
(URL url, boolean encodeFileUrls) static URL
removeFileName
(URL src) This function i striping part behind last path delimiter.static String
static URL
sanitizeLastSlash
(URL in) This function is removing all tailing slashes of url and both unix and windows salshes are supported.static String
setOfUrlsToHtmlList
(Iterable<URL> remoteUrls) Small utility function creating li list from collection of urlsstatic String
static boolean
Compares a URL using string compareNullableStrings of its protocol, host, port, path, query, and anchor.static boolean
urlRelativeTo
(URL url, URL codebaseUrl) Checks whetherurl
is relative tocodebaseUrl
.
-
Constructor Details
-
UrlUtils
public UrlUtils()
-
-
Method Details
-
normalizeUrlAndStripParams
-
normalizeUrlAndStripParams
-
isLocalFile
-
decodeUrlQuietly
-
isValidRFC2396Url
-
normalizeUrl
public static URL normalizeUrl(URL url, boolean encodeFileUrls) throws MalformedURLException, UnsupportedEncodingException, URISyntaxException -
normalizeUrl
public static URL normalizeUrl(URL url) throws MalformedURLException, UnsupportedEncodingException, URISyntaxException -
normalizeUrlQuietly
-
normalizeUrlQuietly
-
decodeUrlAsFile
-
removeFileName
This function i striping part behind last path delimiter. Expected is input like protcol://som.url/some/path/file.suff Then output will bee protcol://som.url/some/path Be aware of input like protcol://som.url/some/path/ then input will be just protcol://som.url/some/path You can use sanitizeLastSlash and see also unittests Both unix and windows salshes are supported- Parameters:
src
- src to be stripped- Returns:
- src without file
-
setOfUrlsToHtmlList
Small utility function creating li list from collection of urls- Parameters:
remoteUrls
- list of urls- Returns:
- String containing html item list of those urls
-
sanitizeLastSlash
This function is removing all tailing slashes of url and both unix and windows salshes are supported. See tests for valid and invalid inputs/outputs Shortly protcol://som.url/some/path/ or protcol://som.url/some/path//// (and same for windows protcol://som.url/some\path\\) will become protcol://som.url/some/path Even protcol://som.url/ is reduced to protcol://som.url When input is like- Parameters:
in
- url t be sanitized- Returns:
- url without trailing slash (if any)
- Throws:
MalformedURLException
- if original url was wrong
-
sanitizeLastSlash
-
equalsIgnoreLastSlash
both urls are processed by sanitizeLastSlash before actual equals. So protcol://som.url/some/path/ is same as protcol://som.url/some/path. Even protcol://som.url/some/path\ is same as protcol://som.url/some/path/- Parameters:
u1
- first url to comapreu2
- second- Returns:
- true if urls are equals no matter of trailing slash
-
guessCodeBase
-
urlEquals
Compares a URL using string compareNullableStrings of its protocol, host, port, path, query, and anchor. This method avoids the host name lookup that URL.equals does for http: protocol URLs. It may not return the same value as the URL.equals method (different hostnames that resolve to the same IP address, ie sourceforge.net and www.sourceforge.net).- Parameters:
u1
- first url to compareNullableStringsu2
- second url to compareNullableStrings- Returns:
- whether the u1 and u2 points to same resource or not
-
urlRelativeTo
Checks whetherurl
is relative tocodebaseUrl
. This method returns false in caseurl
contains parent directory notation "..". See JNLP specification version 9, 3.4: 'A relative URL cannot contain parent directory notations, such as "..". It must denote a file that is stored in a subdirectory of the codebase.'- Parameters:
url
- the url to checkcodebaseUrl
- the url to check against- Returns:
- true if
url
is relative tocodebaseUrl
-
getSanitizedPort
-
getPort
-
getHostAndPort
-
ensureSlashTail
-
ensureSlashTail
-
stripFile
-
loadUrl
- Throws:
IOException
-
loadUrl
- Throws:
IOException
-
loadUrlWithInvalidHeaderBytes
- Throws:
IOException
-
loadUrlWithInvalidHeader
- Throws:
IOException
-
loadUrlWithInvalidHeader
- Throws:
IOException
-