Class URLValidator

java.lang.Object
me.remigio07.chatplugin.api.server.util.URLValidator

public class URLValidator extends Object
Util class used to validate URLs.

Every method except stripProtocol(String) works only when ChatManager.isEnabled().

  • Field Details

    • DOMAIN_NAME_PATTERN

      public static final Pattern DOMAIN_NAME_PATTERN
      Pattern representing the allowed domains.

      Regex: "^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,6}$"

      See Also:
  • Constructor Details

    • URLValidator

      public URLValidator()
  • Method Details

    • getURLs

      public static List<String> getURLs(String input)
      Gets the list of the URLs contained in the input String.

      URLs' domain names are checked using getDomainName(String).

      You may modify the returned list.

      Parameters:
      input - Input containing URLs
      Returns:
      URLs contained in given input
    • stripProtocol

      public static String stripProtocol(String url)
      Strips the protocol from the specified URL.

      Will return url if the specified URL is invalid or if it does not start with a valid protocol ("http://", "https://").

      Parameters:
      url - URL to strip
      Returns:
      URL without its protocol
    • getDomainName

      public static String getDomainName(String url)
      Gets the specified URL's domain name.

      Will return null if the URL is invalid or if !ChatManager.isEnabled() or if ChatManager.getRecognizedTLDs() does not contain the URL's TLD.

      Parameters:
      url - Target URL
      Returns:
      Specified URL's domain name
      See Also: