Class UrlUtils

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

public class UrlUtils extends Object
  • Field Details

  • 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

    • normalizeUrl

    • 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 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 String setOfUrlsToHtmlList(List<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 String setOfUrlsToHtmlList(Collection<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 URL sanitizeLastSlash(URL in) throws MalformedURLException
      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

      public static String sanitizeLastSlash(String in)
    • 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 (or equal) to codebaseUrl. 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 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
    • notNullUrlEquals

      static boolean notNullUrlEquals(URL u1, URL u2)
    • compareNullableStrings

      static boolean compareNullableStrings(String s1, String s2, boolean ignore)
      Compare strings that can be null.
      Parameters:
      s1 - first string to compareNullableStrings with s2
      s2 - second string to compareNullableStrings with s1
      ignore - switch to ignore case
    • 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)
    • stripFileImp

      private static String stripFileImp(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
    • loadUrlWithInvalidHeader

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

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

      public static void writeRequest(OutputStream s, URL url) throws IOException
      Throws:
      IOException
    • createSocketFromUrl

      public static Socket createSocketFromUrl(URL url) throws IOException
      Throws:
      IOException
    • equalUrls

      public static boolean equalUrls(URL url1, URL url2)