public class URLTools extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
URLTools.PortReplacementGenerator |
static class |
URLTools.URLMatch |
static class |
URLTools.URLReplacementGenerator |
| Modifier and Type | Field and Description |
|---|---|
static String |
FILE_PREFIX |
static String |
FTP_PREFIX |
static String |
HTTP_PREFIX |
static String |
HTTPS_PREFIX |
static String |
PORT_END |
static String |
RE_EMAIL_VALIDATION |
static String |
SCH_END |
static String |
SLASH |
| Constructor and Description |
|---|
URLTools() |
| Modifier and Type | Method and Description |
|---|---|
static String |
decodeXWWWFormURL(String s) |
static String |
encodeXWWWFormURL(String s) |
static void |
enforceAbsoluteURL(String url)
Enforces that the given URL is absolute
|
static boolean |
exists(String stringURL,
boolean allowNull)
to remove : an API should not try to accomodate the client for that kind of situation, why not also something
like forbidStringLengthToDivisibleBy3 ?
|
static boolean |
exists(URL url)
Determines that the specified URL corresponds to an existing resource by trying to open a stream from it.
|
static boolean |
exists(URL url,
long waitForMillis)
Determines if the specified URL corresponds to an existing resource by trying to open a stream from it.
|
static URLTools.URLMatch[] |
extractURLsFrom(String markup) |
static byte[] |
getContent(URL url,
int soTimeoutMillis,
int connTimeoutMillis)
Fetches content from of the URL as a byte array or
null if a problem occurred. |
static InputStream |
getContentAsInputStream(URL url,
int soTimeoutMillis,
int connTimeoutMillis)
Fetches content from URL as an InputStream.
|
static String |
getFileExtensionOrNullFrom(URL url) |
static String |
getServerAddressFrom(javax.servlet.http.HttpServletRequest request)
Returns the server address that originated the request, without final /.
|
static int |
getURLCountIn(String markup) |
static boolean |
isEmailValid(String address)
Return true is the address is not null and matches the email validation regular expression.
|
static boolean |
isNetworkURL(String url) |
static boolean |
isURLAbsolute(String url) |
static String |
replaceServerPortInURL(String url,
int newPort) |
static String |
replaceURLsBy(String markup,
String[] replacements) |
static String |
replaceURLsBy(String markup,
URLTools.URLReplacementGenerator generator) |
static String |
safeDecodeForHTMLId(String value) |
static String |
safeEncodeForHTMLId(String value) |
public static final String RE_EMAIL_VALIDATION
public static final String HTTP_PREFIX
public static final String HTTPS_PREFIX
public static final String FTP_PREFIX
public static final String FILE_PREFIX
public static final String SCH_END
public static final String PORT_END
public static final String SLASH
public static boolean isURLAbsolute(String url)
public static String getServerAddressFrom(javax.servlet.http.HttpServletRequest request)
request - public static byte[] getContent(URL url, int soTimeoutMillis, int connTimeoutMillis) throws IllegalArgumentException
null if a problem occurred. The timeout values
must not be negative integers, when it is equals to zero it means that it does not setup a timeout and use the
default values.url - the URL the URL of the resourcesoTimeoutMillis - the socket connection timeout in millisconnTimeoutMillis - the connection timeout in millisIllegalArgumentException - if the URL is null or any time out value is negativepublic static InputStream getContentAsInputStream(URL url, int soTimeoutMillis, int connTimeoutMillis) throws IOException
url - the URL the URL of the resourcesoTimeoutMillis - the socket connection timeout in millisconnTimeoutMillis - the connection timeout in millisIllegalArgumentException - if the URL is null or any time out value is negativeIOExceptionpublic static boolean isNetworkURL(String url)
url - public static void enforceAbsoluteURL(String url) throws IllegalArgumentException
url - the String representation of the URL to be checkedIllegalArgumentException - if the given URL is not absolutepublic static boolean isEmailValid(String address)
public static boolean exists(URL url)
exists(url, 1000)url - public static boolean exists(URL url, long waitForMillis) throws IllegalArgumentException
url - the URL to be testedwaitForMillis - the number of milliseconds to wait before timing out, 0 meaning never timing out.IllegalArgumentException - if the url is null or the time out negativepublic static boolean exists(String stringURL, boolean allowNull)
stringURL - allowNull - true if passing null will be ignored and just return
false, false to throw an IllegalArgumentException is the given
URL is null.public static URLTools.URLMatch[] extractURLsFrom(String markup)
public static int getURLCountIn(String markup)
public static String replaceURLsBy(String markup, URLTools.URLReplacementGenerator generator)
public static String replaceServerPortInURL(String url, int newPort)
url - newPort - Copyright © 2025 JBoss by Red Hat. All Rights Reserved.