Class UrlUtils
java.lang.Object
net.sourceforge.jnlp.util.UrlUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final intstatic final Stringstatic final Stringprivate static final Stringstatic final Stringstatic final Stringstatic final Stringprivate static final Stringprivate static final Loggerstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static booleancompareNullableStrings(String s1, String s2, boolean ignore) Compare strings that can benull.static SocketcreateSocketFromUrl(URL url) static FiledecodeUrlAsFile(URL url) static URLdecodeUrlQuietly(URL url) static Stringstatic URLstatic booleanstatic 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 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) (package private) static booleannotNullUrlEquals(URL u1, URL u2) 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 slashes are supported.private static StringsetOfUrlsToHtmlList(Collection<URL> remoteUrls, int max) Small utility function creating li list from collection of urlsstatic StringsetOfUrlsToHtmlList(List<URL> remoteUrls) Small utility function creating li list from collection of urlsstatic Stringprivate static StringstripFileImp(URL documentbase) static booleanCompares a URL using string compareNullableStrings of its protocol, host, port, path, query, and anchor.static booleanurlRelativeTo(URL url, URL codebaseUrl) Checks whetherurlis relative (or equal) tocodebaseUrl.static voidwriteRequest(OutputStream s, URL url)
-
Field Details
-
LOG
-
FILE_PROTOCOL
- See Also:
-
JAR_PROTOCOL
- See Also:
-
HTTP_PROTOCOL
- See Also:
-
HTTPS_PROTOCOL
- See Also:
-
SLASH
- See Also:
-
BACKSLASH
- See Also:
-
UL_TAG_OPEN
- See Also:
-
LI_TAG_OPEN
- See Also:
-
LI_TAG_CLOSE
- See Also:
-
UL_TAG_CLOSE
- See Also:
-
HTTP_STATUS_200
public static final int HTTP_STATUS_200- See Also:
-
BACKSLASH_REGEX
- See Also:
-
HTTPS
- See Also:
-
BACKSLASH_N
- See Also:
-
PARENT_DIR
- See Also:
-
LOCALHOST
- See Also:
-
IPV4_LOOPBACK_PREFIX
- See Also:
-
-
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 protocol://som.url/some/path/file.suff Then output will bee protocol://som.url/some/path Be aware of input like protocol://som.url/some/path/ then input will be just protocol://som.url/some/path You can use sanitizeLastSlash and see also unit tests Both unix and windows slashes are supported- Parameters:
src- src to be stripped- Returns:
- src without file
-
setOfUrlsToHtmlList
-
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 slashes are supported. See tests for valid and invalid inputs/outputs Shortly protocol://som.url/some/path/ or protocol://som.url/some/path//// (and same for windows protocol://som.url/some\path\\) will become protocol://som.url/some/path Even protocol://som.url/ is reduced to protocol://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
-
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 (or equal) tocodebaseUrl. both urls are processed by sanitizeLastSlash before actual equals. So protocol://som.url/some/path/ is same as protocol://som.url/some/path. Even protocol://som.url/some/path\ is same as protocol://som.url/some/path/ 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
-
notNullUrlEquals
-
compareNullableStrings
-
getSanitizedPort
-
getPort
-
getHostAndPort
-
ensureSlashTail
-
ensureSlashTail
-
stripFile
-
stripFileImp
-
loadUrl
- Throws:
IOException
-
loadUrl
- Throws:
IOException
-
loadUrlWithInvalidHeader
- Throws:
IOException
-
loadUrlWithInvalidHeader
- Throws:
IOException
-
writeRequest
- Throws:
IOException
-
createSocketFromUrl
- Throws:
IOException
-
equalUrls
-