Package net.sourceforge.jnlp.util
Class UrlUtils
- java.lang.Object
-
- net.sourceforge.jnlp.util.UrlUtils
-
public class UrlUtils extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBACKSLASHstatic java.lang.StringBACKSLASH_Nstatic java.lang.StringBACKSLASH_REGEXstatic java.lang.StringFILE_PROTOCOLstatic java.lang.StringHTTP_PROTOCOLstatic intHTTP_STATUS_200static java.lang.StringHTTPSstatic java.lang.StringHTTPS_PROTOCOLprivate static java.lang.StringIPV4_LOOPBACK_PREFIXstatic java.lang.StringJAR_PROTOCOLstatic java.lang.StringLI_TAG_CLOSEstatic java.lang.StringLI_TAG_OPENprivate static java.lang.StringLOCALHOSTprivate static LoggerLOGstatic java.lang.StringPARENT_DIRstatic java.lang.StringSLASHstatic java.lang.StringUL_TAG_CLOSEstatic java.lang.StringUL_TAG_OPEN
-
Constructor Summary
Constructors Constructor Description UrlUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static booleancompareNullableStrings(java.lang.String s1, java.lang.String s2, boolean ignore)Compare strings that can benull.static java.net.SocketcreateSocketFromUrl(java.net.URL url)static java.io.FiledecodeUrlAsFile(java.net.URL url)static java.net.URLdecodeUrlQuietly(java.net.URL url)static java.lang.StringensureSlashTail(java.lang.String s)static java.net.URLensureSlashTail(java.net.URL u)static booleanequalUrls(java.net.URL url1, java.net.URL url2)static java.lang.StringgetHostAndPort(java.net.URL url)static intgetPort(java.net.URL url)static intgetSanitizedPort(java.net.URL u)static java.net.URLguessCodeBase(JNLPFile file)static booleanisLocalFile(java.net.URL url)static booleanisValidRFC2396Url(java.net.URL url)static java.lang.StringloadUrl(java.net.URL url)static java.lang.StringloadUrl(java.net.URL url, java.nio.charset.Charset ch)static java.lang.String[]loadUrlWithInvalidHeader(java.net.URL url)static java.lang.String[]loadUrlWithInvalidHeader(java.net.URL url, java.nio.charset.Charset ch)static java.net.URLnormalizeUrl(java.net.URL url)static java.net.URLnormalizeUrl(java.net.URL url, boolean encodeFileUrls)static java.net.URLnormalizeUrlAndStripParams(java.net.URL url)static java.net.URLnormalizeUrlAndStripParams(java.net.URL url, boolean encodeFileUrls)static java.net.URLnormalizeUrlQuietly(java.net.URL url)static java.net.URLnormalizeUrlQuietly(java.net.URL url, boolean encodeFileUrls)(package private) static booleannotNullUrlEquals(java.net.URL u1, java.net.URL u2)static java.net.URLremoveFileName(java.net.URL src)This function i striping part behind last path delimiter.static java.lang.StringsanitizeLastSlash(java.lang.String in)static java.net.URLsanitizeLastSlash(java.net.URL in)This function is removing all tailing slashes of url and both unix and windows slashes are supported.private static java.lang.StringsetOfUrlsToHtmlList(java.util.Collection<java.net.URL> remoteUrls, int max)Small utility function creating li list from collection of urlsstatic java.lang.StringsetOfUrlsToHtmlList(java.util.List<java.net.URL> remoteUrls)Small utility function creating li list from collection of urlsstatic java.lang.StringstripFile(java.net.URL documentbase)private static java.lang.StringstripFileImp(java.net.URL documentbase)static booleanurlEquals(java.net.URL u1, java.net.URL u2)Compares a URL using string compareNullableStrings of its protocol, host, port, path, query, and anchor.static booleanurlRelativeTo(java.net.URL url, java.net.URL codebaseUrl)Checks whetherurlis relative (or equal) tocodebaseUrl.static voidwriteRequest(java.io.OutputStream s, java.net.URL url)
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
FILE_PROTOCOL
public static final java.lang.String FILE_PROTOCOL
- See Also:
- Constant Field Values
-
JAR_PROTOCOL
public static final java.lang.String JAR_PROTOCOL
- See Also:
- Constant Field Values
-
HTTP_PROTOCOL
public static final java.lang.String HTTP_PROTOCOL
- See Also:
- Constant Field Values
-
HTTPS_PROTOCOL
public static final java.lang.String HTTPS_PROTOCOL
- See Also:
- Constant Field Values
-
SLASH
public static final java.lang.String SLASH
- See Also:
- Constant Field Values
-
BACKSLASH
public static final java.lang.String BACKSLASH
- See Also:
- Constant Field Values
-
UL_TAG_OPEN
public static final java.lang.String UL_TAG_OPEN
- See Also:
- Constant Field Values
-
LI_TAG_OPEN
public static final java.lang.String LI_TAG_OPEN
- See Also:
- Constant Field Values
-
LI_TAG_CLOSE
public static final java.lang.String LI_TAG_CLOSE
- See Also:
- Constant Field Values
-
UL_TAG_CLOSE
public static final java.lang.String UL_TAG_CLOSE
- See Also:
- Constant Field Values
-
HTTP_STATUS_200
public static final int HTTP_STATUS_200
- See Also:
- Constant Field Values
-
BACKSLASH_REGEX
public static final java.lang.String BACKSLASH_REGEX
- See Also:
- Constant Field Values
-
HTTPS
public static final java.lang.String HTTPS
- See Also:
- Constant Field Values
-
BACKSLASH_N
public static final java.lang.String BACKSLASH_N
- See Also:
- Constant Field Values
-
PARENT_DIR
public static final java.lang.String PARENT_DIR
- See Also:
- Constant Field Values
-
LOCALHOST
private static final java.lang.String LOCALHOST
- See Also:
- Constant Field Values
-
IPV4_LOOPBACK_PREFIX
private static final java.lang.String IPV4_LOOPBACK_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
normalizeUrlAndStripParams
public static java.net.URL normalizeUrlAndStripParams(java.net.URL url, boolean encodeFileUrls)
-
normalizeUrlAndStripParams
public static java.net.URL normalizeUrlAndStripParams(java.net.URL url)
-
isLocalFile
public static boolean isLocalFile(java.net.URL url)
-
decodeUrlQuietly
public static java.net.URL decodeUrlQuietly(java.net.URL url)
-
isValidRFC2396Url
public static boolean isValidRFC2396Url(java.net.URL url)
-
normalizeUrl
public static java.net.URL normalizeUrl(java.net.URL url, boolean encodeFileUrls) throws java.net.MalformedURLException, java.io.UnsupportedEncodingException, java.net.URISyntaxException- Throws:
java.net.MalformedURLExceptionjava.io.UnsupportedEncodingExceptionjava.net.URISyntaxException
-
normalizeUrl
public static java.net.URL normalizeUrl(java.net.URL url) throws java.net.MalformedURLException, java.io.UnsupportedEncodingException, java.net.URISyntaxException- Throws:
java.net.MalformedURLExceptionjava.io.UnsupportedEncodingExceptionjava.net.URISyntaxException
-
normalizeUrlQuietly
public static java.net.URL normalizeUrlQuietly(java.net.URL url, boolean encodeFileUrls)
-
normalizeUrlQuietly
public static java.net.URL normalizeUrlQuietly(java.net.URL url)
-
decodeUrlAsFile
public static java.io.File decodeUrlAsFile(java.net.URL url)
-
removeFileName
public static java.net.URL removeFileName(java.net.URL src)
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
public static java.lang.String setOfUrlsToHtmlList(java.util.List<java.net.URL> remoteUrls)
Small utility function creating li list from collection of urls- Parameters:
remoteUrls- list of urls- Returns:
- String containing html item list of those urls
-
setOfUrlsToHtmlList
private static java.lang.String setOfUrlsToHtmlList(java.util.Collection<java.net.URL> remoteUrls, int max)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
public static java.net.URL sanitizeLastSlash(java.net.URL in) throws java.net.MalformedURLExceptionThis 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:
java.net.MalformedURLException- if original url was wrong
-
sanitizeLastSlash
public static java.lang.String sanitizeLastSlash(java.lang.String in)
-
guessCodeBase
public static java.net.URL guessCodeBase(JNLPFile file)
-
urlEquals
public static boolean urlEquals(java.net.URL u1, java.net.URL u2)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
public static boolean urlRelativeTo(java.net.URL url, java.net.URL codebaseUrl)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
static boolean notNullUrlEquals(java.net.URL u1, java.net.URL u2)
-
compareNullableStrings
static boolean compareNullableStrings(java.lang.String s1, java.lang.String s2, boolean ignore)Compare strings that can benull.- Parameters:
s1- first string to compareNullableStrings with s2s2- second string to compareNullableStrings with s1ignore- switch to ignore case
-
getSanitizedPort
public static int getSanitizedPort(java.net.URL u)
-
getPort
public static int getPort(java.net.URL url)
-
getHostAndPort
public static java.lang.String getHostAndPort(java.net.URL url)
-
ensureSlashTail
public static java.net.URL ensureSlashTail(java.net.URL u)
-
ensureSlashTail
public static java.lang.String ensureSlashTail(java.lang.String s)
-
stripFile
public static java.lang.String stripFile(java.net.URL documentbase)
-
stripFileImp
private static java.lang.String stripFileImp(java.net.URL documentbase)
-
loadUrl
public static java.lang.String loadUrl(java.net.URL url) throws java.io.IOException- Throws:
java.io.IOException
-
loadUrl
public static java.lang.String loadUrl(java.net.URL url, java.nio.charset.Charset ch) throws java.io.IOException- Throws:
java.io.IOException
-
loadUrlWithInvalidHeader
public static java.lang.String[] loadUrlWithInvalidHeader(java.net.URL url) throws java.io.IOException- Throws:
java.io.IOException
-
loadUrlWithInvalidHeader
public static java.lang.String[] loadUrlWithInvalidHeader(java.net.URL url, java.nio.charset.Charset ch) throws java.io.IOException- Throws:
java.io.IOException
-
writeRequest
public static void writeRequest(java.io.OutputStream s, java.net.URL url) throws java.io.IOException- Throws:
java.io.IOException
-
createSocketFromUrl
public static java.net.Socket createSocketFromUrl(java.net.URL url) throws java.io.IOException- Throws:
java.io.IOException
-
equalUrls
public static boolean equalUrls(java.net.URL url1, java.net.URL url2)
-
-