Package net.sourceforge.jnlp.util
Class UrlUtils
java.lang.Object
net.sourceforge.jnlp.util.UrlUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FiledecodeUrlAsFile(URL url) static URLdecodeUrlQuietly(URL url) static Stringstatic URLstatic booleanequalsIgnoreLastSlash(URL u1, URL u2) both urls are processed by sanitizeLastSlash before actual equals.static StringgetHostAndPort(URL url) static intstatic intstatic URLguessCodeBase(JNLPFile file) static booleanisLocalFile(URL url) static booleanisValidRFC2396Url(URL url) static Stringstatic Stringstatic String[]static String[]loadUrlWithInvalidHeader(URL url, Charset ch) static Object[]static URLnormalizeUrl(URL url) static URLnormalizeUrl(URL url, boolean encodeFileUrls) static URLstatic URLnormalizeUrlAndStripParams(URL url, boolean encodeFileUrls) static URLnormalizeUrlQuietly(URL url) static URLnormalizeUrlQuietly(URL url, boolean encodeFileUrls) static URLremoveFileName(URL src) This function i striping part behind last path delimiter.static Stringstatic URLsanitizeLastSlash(URL in) This function is removing all tailing slashes of url and both unix and windows salshes are supported.static StringsetOfUrlsToHtmlList(Iterable<URL> remoteUrls) Small utility function creating li list from collection of urlsstatic Stringstatic booleanCompares a URL using string compareNullableStrings of its protocol, host, port, path, query, and anchor.static booleanurlRelativeTo(URL url, URL codebaseUrl) Checks whetherurlis 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 whetherurlis relative tocodebaseUrl. This method returns false in caseurlcontains 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
urlis relative tocodebaseUrl
-
getSanitizedPort
-
getPort
-
getHostAndPort
-
ensureSlashTail
-
ensureSlashTail
-
stripFile
-
loadUrl
- Throws:
IOException
-
loadUrl
- Throws:
IOException
-
loadUrlWithInvalidHeaderBytes
- Throws:
IOException
-
loadUrlWithInvalidHeader
- Throws:
IOException
-
loadUrlWithInvalidHeader
- Throws:
IOException
-