Class CSSURLHelper

java.lang.Object
com.helger.css.utils.CSSURLHelper

@Immutable public final class CSSURLHelper extends Object
Provides URL handling sanity methods.
Author:
Philip Helger
  • Field Details

    • DEFAULT_QUOTE_URLS

      public static final boolean DEFAULT_QUOTE_URLS
      For compatibility reasons, this is set to false
      See Also:
  • Method Details

    • isURLValue

      public static boolean isURLValue(@Nullable String sValue)
      Check if the passed CSS value is an URL value. This is either a URL starting with "url(" or it is the string "none".
      Parameters:
      sValue - The value to be checked.
      Returns:
      true if the passed value starts with "url(" and ends with ")" - false otherwise.
    • getURLValue

      @Nullable public static String getURLValue(@Nullable String sValue)
      Extract the real URL contained in a CSS URL value.
      Parameters:
      sValue - The value containing the CSS value
      Returns:
      null if the passed value is not an URL value
      See Also:
    • getAsCSSURL

      @Nonnull @Nonempty public static String getAsCSSURL(@Nonnull com.helger.commons.url.ISimpleURL aURL, boolean bQuoteURL)
      Surround the passed URL with the CSS "url(...)"
      Parameters:
      aURL - URL to be wrapped. May not be null.
      bQuoteURL - if true single quotes are added around the URL
      Returns:
      url(sURL) or url('sURL')
    • isValidCSSURLChar

      public static boolean isValidCSSURLChar(char c)
      Check if the passed character is a valid character inside a URL. Characters for which this method returns false must be escaped!
      Parameters:
      c - The character to be checked.
      Returns:
      true if the passed character can be directly contained inside a URL, false otherwise if the character needs to be escaped.
    • isCSSURLRequiringQuotes

      public static boolean isCSSURLRequiringQuotes(@Nonnull String sURL)
      Check if any character inside the passed URL needs escaping.
      Parameters:
      sURL - The URL to be checked. May not be null.
      Returns:
      true if any of the contained characters needs escaping, false if the URL can be used as is.
    • getEscapedCSSURL

      @Nonnull @Nonempty public static String getEscapedCSSURL(@Nonnull String sURL, char cQuoteChar)
      Internal method to escape a CSS URL. Because this method is only called for quoted URLs, only the quote character itself needs to be quoted.
      Parameters:
      sURL - The URL to be escaped. May not be null.
      cQuoteChar - The quote char that is used. Either single quote or double quote.
      Returns:
      The escaped string. Never null.
    • getAsCSSURL

      @Nonnull @Nonempty public static String getAsCSSURL(@Nonnull String sURL, boolean bForceQuoteURL)
      Surround the passed URL with the CSS "url(...)". When the passed URL contains characters that require quoting, quotes are automatically added!
      Parameters:
      sURL - URL to be wrapped. May not be null but maybe empty.
      bForceQuoteURL - if true single quotes are added around the URL
      Returns:
      url(sURL) or url('sURL')