Class HTTPUtil
- java.lang.Object
-
- ch.supertomcat.supertomcatutils.http.HTTPUtil
-
public final class HTTPUtil extends Object
This class provides methods for working with URL's
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringconvertURLFromRelativeToAbsolute(String referrer, String urlToConvert)static StringdecodeURL(String url)Decodes the given URL.static StringencodeURL(String url)Encodes the given URL.static StringencodeURL(String url, boolean checkForPercentCharacter)Encodes the given URL.static StringgetBaseURL(String url)static String[]getDomainAndPathFromURL(String url)Returns the domain and path part of a URL If the url could not be splitted, null is returnedstatic StringgetDomainFromURL(String url)Returns the domain of a URL If the domain could not be found an empty String is returnedstatic StringgetFilenameFromURL(String url, String defaultValue)Returns the filename from the url if possible or otherwise the defaultValuestatic StringgetTLDName(String domain)Returns only the name of a TLDstatic booleanisURL(String url)Checks if the given String is an URLstatic StringtrimURL(String url)Trims an url
-
-
-
Method Detail
-
isURL
public static boolean isURL(String url)
Checks if the given String is an URL- Parameters:
url- URL- Returns:
- True if the given String is an URL, false otherwise
-
trimURL
public static String trimURL(String url)
Trims an url- Parameters:
url- URL- Returns:
- Trimmed URL
-
encodeURL
public static String encodeURL(String url, boolean checkForPercentCharacter)
Encodes the given URL. If the method fails to encode the URL the given URL is returned. If the checkForPercentCharacter is true and a percent character is found in the URL, then the URL will not be encoded and just returned.- Parameters:
url- Decoded URLcheckForPercentCharacter- Flag if URL should be checked for percent character to prevent double encoding- Returns:
- Encoded URL
-
encodeURL
public static String encodeURL(String url)
Encodes the given URL. If the method fails to encode the URL the given URL is returned. Only unencoded/decoded URLs should be passed to this method, because encoded URLs would be encoded again!- Parameters:
url- Decoded URL- Returns:
- Encoded URL
-
decodeURL
public static String decodeURL(String url)
Decodes the given URL. If the method fails to decode the URL the given URL is returned.- Parameters:
url- Encoded URL- Returns:
- Decoded URL
-
getDomainFromURL
public static String getDomainFromURL(String url)
Returns the domain of a URL If the domain could not be found an empty String is returned- Parameters:
url- URL- Returns:
- Domain
-
getDomainAndPathFromURL
public static String[] getDomainAndPathFromURL(String url)
Returns the domain and path part of a URL If the url could not be splitted, null is returned- Parameters:
url- URL- Returns:
- String-Array
-
getTLDName
public static String getTLDName(String domain)
Returns only the name of a TLD- Parameters:
domain- Domain- Returns:
- TLD-Name
-
getFilenameFromURL
public static String getFilenameFromURL(String url, String defaultValue)
Returns the filename from the url if possible or otherwise the defaultValue- Parameters:
url- URLdefaultValue- DefaultValue- Returns:
- Filename
-
-