Class UrlUtils

java.lang.Object
net.sourceforge.jnlp.util.UrlUtils

public class UrlUtils extends Object
  • Constructor Details

    • UrlUtils

      public UrlUtils()
  • Method Details

    • normalizeUrlAndStripParams

      public static URL normalizeUrlAndStripParams(URL url, boolean encodeFileUrls)
    • normalizeUrlAndStripParams

      public static URL normalizeUrlAndStripParams(URL url)
    • isLocalFile

      public static boolean isLocalFile(URL url)
    • decodeUrlQuietly

      public static URL decodeUrlQuietly(URL url)
    • isValidRFC2396Url

      public static boolean isValidRFC2396Url(URL url)
    • normalizeUrl

      public static URL normalizeUrl(URL url, boolean encodeFileUrls) throws MalformedURLException, UnsupportedEncodingException, URISyntaxException
      Throws:
      MalformedURLException
      UnsupportedEncodingException
      URISyntaxException
    • normalizeUrl

      Throws:
      MalformedURLException
      UnsupportedEncodingException
      URISyntaxException
    • normalizeUrlQuietly

      public static URL normalizeUrlQuietly(URL url, boolean encodeFileUrls)
    • normalizeUrlQuietly

      public static URL normalizeUrlQuietly(URL url)
    • decodeUrlAsFile

      public static File decodeUrlAsFile(URL url)
    • removeFileName

      public static URL removeFileName(URL src)
      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

      public static String setOfUrlsToHtmlList(Iterable<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
    • sanitizeLastSlash

      public static URL sanitizeLastSlash(URL in) throws MalformedURLException
      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

      public static String sanitizeLastSlash(String in)
    • equalsIgnoreLastSlash

      public static boolean equalsIgnoreLastSlash(URL u1, URL u2)
      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 comapre
      u2 - second
      Returns:
      true if urls are equals no matter of trailing slash
    • guessCodeBase

      public static URL guessCodeBase(JNLPFile file)
    • urlEquals

      public static boolean urlEquals(URL u1, 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 compareNullableStrings
      u2 - second url to compareNullableStrings
      Returns:
      whether the u1 and u2 points to same resource or not
    • urlRelativeTo

      public static boolean urlRelativeTo(URL url, URL codebaseUrl)
      Checks whether url is relative to codebaseUrl. This method returns false in case url 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 check
      codebaseUrl - the url to check against
      Returns:
      true if url is relative to codebaseUrl
    • getSanitizedPort

      public static int getSanitizedPort(URL u)
    • getPort

      public static int getPort(URL url)
    • getHostAndPort

      public static String getHostAndPort(URL url)
    • ensureSlashTail

      public static URL ensureSlashTail(URL u)
    • ensureSlashTail

      public static String ensureSlashTail(String s)
    • stripFile

      public static String stripFile(URL documentbase)
    • loadUrl

      public static String loadUrl(URL url) throws IOException
      Throws:
      IOException
    • loadUrl

      public static String loadUrl(URL url, Charset ch) throws IOException
      Throws:
      IOException
    • loadUrlWithInvalidHeaderBytes

      public static Object[] loadUrlWithInvalidHeaderBytes(URL url) throws IOException
      Throws:
      IOException
    • loadUrlWithInvalidHeader

      public static String[] loadUrlWithInvalidHeader(URL url) throws IOException
      Throws:
      IOException
    • loadUrlWithInvalidHeader

      public static String[] loadUrlWithInvalidHeader(URL url, Charset ch) throws IOException
      Throws:
      IOException