Package com.qfs

Class QfsWebUtils


  • public class QfsWebUtils
    extends Object
    Helper class containing methods to deal with URLs.
    Author:
    ActiveViam
    • Field Detail

      • SEPARATOR

        public static final char SEPARATOR
        The separator used to separate parts of an URI.
        See Also:
        Constant Field Values
    • Constructor Detail

      • QfsWebUtils

        public QfsWebUtils()
    • Method Detail

      • url

        public static String url​(String... parts)
        Build an url by joining the different given parts separated by SEPARATOR = 47.

        The url start with ROOT.

         E.g:  - url("a", "/b", "/c/") returns /a/b/c
               - url("http://localhost:9090", "a", "/b", "/c/") returns http://localhost:9090/a/b/c
         
        Parameters:
        parts - parts of the url.
        Returns:
        the url
      • url

        public static String url​(boolean withTrailingSlash,
                                 String... parts)
        Build an url by joining the different given parts separated by SEPARATOR.

        The url start with ROOT and may end with SEPARATOR.

         E.g:  - url("a", "/b", "/c") returns /a/b/c/
               - url("http://localhost:9090", "a", "/b", "/c") returns http://localhost:9090/a/b/c/
         
        Parameters:
        withTrailingSlash - true if the url need to end with "/", false otherwise.
        parts - parts of the url.
        Returns:
        the url
      • normalizeUrl

        public static String normalizeUrl​(String url,
                                          boolean withTrailingSlash)
        Normalize an URL, removing extra "/" characters.
        Parameters:
        url - the url to normalize.
        withTrailingSlash - true if the url wants to end with "/", false otherwise.

        If true and the trailing / is missing, it is added to the url. If false and present, it is removed.

        Returns:
        the normalized url.
      • getProtocol

        public static String getProtocol​(String url)
        Get the protocol used by the given url.
        Parameters:
        url - the url
        Returns:
        the protocol used (among http, https, ws, wss). null if there is no protocol in this url).