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 booleanDEFAULT_QUOTE_URLSFor compatibility reasons, this is set to false
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringgetAsCSSURL(com.helger.commons.url.ISimpleURL aURL, boolean bQuoteURL)Surround the passed URL with the CSS "url(...)"static StringgetAsCSSURL(String sURL, boolean bForceQuoteURL)Surround the passed URL with the CSS "url(...)".static StringgetEscapedCSSURL(String sURL, char cQuoteChar)Internal method to escape a CSS URL.static StringgetURLValue(String sValue)Extract the real URL contained in a CSS URL value.static booleanisCSSURLRequiringQuotes(String sURL)Check if any character inside the passed URL needs escaping.static booleanisURLValue(String sValue)Check if the passed CSS value is an URL value.static booleanisValidCSSURLChar(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:
trueif the passed value starts with "url(" and ends with ")" -falseotherwise.
-
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:
nullif 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- iftruesingle 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 returnsfalsemust be escaped!- Parameters:
c- The character to be checked.- Returns:
trueif the passed character can be directly contained inside a URL,falseotherwise 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:
trueif any of the contained characters needs escaping,falseif 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 benullbut maybe empty.bForceQuoteURL- iftruesingle quotes are added around the URL- Returns:
url(sURL)orurl('sURL')
-
-