Package com.helger.css.utils
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 Summary
Fields Modifier and Type Field Description static boolean
DEFAULT_QUOTE_URLS
For compatibility reasons, this is set to false
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
getAsCSSURL(com.helger.commons.url.ISimpleURL aURL, boolean bQuoteURL)
Surround the passed URL with the CSS "url(...)"static String
getAsCSSURL(String sURL, boolean bForceQuoteURL)
Surround the passed URL with the CSS "url(...)".static String
getEscapedCSSURL(String sURL, char cQuoteChar)
Internal method to escape a CSS URL.static String
getURLValue(String sValue)
Extract the real URL contained in a CSS URL value.static boolean
isCSSURLRequiringQuotes(String sURL)
Check if any character inside the passed URL needs escaping.static boolean
isURLValue(String sValue)
Check if the passed CSS value is an URL value.static boolean
isValidCSSURLChar(char c)
Check if the passed character is a valid character inside a URL.
-
-
-
Field Detail
-
DEFAULT_QUOTE_URLS
public static final boolean DEFAULT_QUOTE_URLS
For compatibility reasons, this is set to false- See Also:
- Constant Field Values
-
-
Method Detail
-
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:
isURLValue(java.lang.String)
-
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 benull
.bQuoteURL
- iftrue
single quotes are added around the URL- Returns:
url(sURL)
orurl('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 returnsfalse
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 benull
.- 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 benull
.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 benull
but maybe empty.bForceQuoteURL
- iftrue
single quotes are added around the URL- Returns:
url(sURL)
orurl('sURL')
-
-