Class UrlStringUtils


  • @ThreadSafe
    public final class UrlStringUtils
    extends java.lang.Object
    Author:
    Jeremy Long
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean containsUrl​(java.lang.String text)
      Tests if the text provided contains a URL.
      static java.util.List<java.lang.String> extractImportantUrlData​(java.lang.String text)
      Takes a URL, in String format, and adds the important parts of the URL to a list of strings.
      static boolean isUrl​(java.lang.String text)
      Tests if the given text is url.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • containsUrl

        public static boolean containsUrl​(java.lang.String text)
        Tests if the text provided contains a URL. This is somewhat limited search in that it only looks for (ftp|http|https)://
        Parameters:
        text - the text to search
        Returns:
        true if the text contains a url, otherwise false
      • isUrl

        public static boolean isUrl​(java.lang.String text)
        Tests if the given text is url.
        Parameters:
        text - the string to test
        Returns:
        returns true if the text is a url, otherwise false
      • extractImportantUrlData

        public static java.util.List<java.lang.String> extractImportantUrlData​(java.lang.String text)
                                                                        throws java.net.MalformedURLException

        Takes a URL, in String format, and adds the important parts of the URL to a list of strings.

        Example, given the following input:

        "https://www.somedomain.com/path1/path2/file.php?id=439"

        The function would return:

        {"some.domain", "path1", "path2", "file"}
        Parameters:
        text - a URL
        Returns:
        importantParts a list of the important parts of the URL
        Throws:
        java.net.MalformedURLException - thrown if the URL is malformed