Class UrlUtils

java.lang.Object
org.craftercms.commons.lang.UrlUtils

public class UrlUtils extends Object
Utility methods for paths and URLs.
Author:
avasquez
  • Field Details

  • Method Details

    • concat

      public static String concat(String mainUrl, String relativeUrl)
      Concats two urls, adding any "/" needed between them.
      Parameters:
      mainUrl - the main url
      relativeUrl - the relative url
      Returns:
      mainPath + relativeUrl
    • concat

      public static String concat(String mainUrl, String... relativeUrls)
      Concats two or more urls, adding any "/" needed between them.
      Parameters:
      mainUrl - the main url
      relativeUrls - the array of relative urls
      Returns:
      mainPath + relativeUrls...
    • addParam

      public static String addParam(String url, String name, String value, String charset) throws UnsupportedEncodingException
      Adds a query string param to the URL, adding a '?' if there's no query string yet.
      Parameters:
      url - the URL
      name - the name of the param
      value - the value of the param
      charset - the charset to encode the param key/value with
      Returns:
      the URL with the query string param appended
      Throws:
      UnsupportedEncodingException
    • addQueryStringFragment

      public static String addQueryStringFragment(String url, String fragment)
      Adds a query string fragment to the URL, adding a '?' if there's no query string yet.
      Parameters:
      url - the URL
      fragment - the query string fragment
      Returns:
      the URL with the query string fragment appended
    • cleanUrlForLog

      public static String cleanUrlForLog(String url)
      Clean a url for logging purposes. It truncates the url to 2000 characters and removes any line feeds or carriage returns.
      Parameters:
      url - the url to clean
      Returns:
      the cleaned url