org.jboss.portal.common.net
Class URLTools
java.lang.Object
org.jboss.portal.common.net.URLTools
public class URLTools
- extends java.lang.Object
- Since:
- 2.4 (May 26, 2006)
- Version:
- $Revision: 7686 $
- Author:
- Chris Laprun
Method Summary |
static java.lang.String |
decodeXWWWFormURL(java.lang.String s)
|
static java.lang.String |
encodeXWWWFormURL(java.lang.String s)
|
static void |
enforceAbsoluteURL(java.lang.String url)
Enforces that the given URL is absolute |
static boolean |
exists(java.lang.String urlAsString,
boolean allowNull)
|
static boolean |
exists(java.net.URL url)
Determines that the specified URL corresponds to an existing resource by trying to open a stream from it. |
static boolean |
exists(java.net.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(java.lang.String markup)
|
static int |
getURLCountIn(java.lang.String markup)
|
static boolean |
isEmailValid(java.lang.String address)
Return true is the address is not null and matches the email validation regular expression. |
static boolean |
isNetworkURL(java.lang.String url)
|
static boolean |
isURLAbsolute(java.lang.String url)
|
static byte[] |
performGET(java.net.URL url,
int soTimeoutMillis,
int connTimeoutMillis)
Fetches content from an HTTP server performing a GET operation. |
static java.lang.String |
replaceServerPortInURL(java.lang.String url,
int newPort)
|
static java.lang.String |
replaceURLsBy(java.lang.String markup,
java.lang.String[] replacements)
|
static java.lang.String |
replaceURLsBy(java.lang.String markup,
URLTools.URLReplacementGenerator generator)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RE_EMAIL_VALIDATION
public static final java.lang.String RE_EMAIL_VALIDATION
- See Also:
- Constant Field Values
HTTP_PREFIX
public static final java.lang.String HTTP_PREFIX
- See Also:
- Constant Field Values
HTTPS_PREFIX
public static final java.lang.String HTTPS_PREFIX
- See Also:
- Constant Field Values
FTP_PREFIX
public static final java.lang.String FTP_PREFIX
- See Also:
- Constant Field Values
FILE_PREFIX
public static final java.lang.String FILE_PREFIX
- See Also:
- Constant Field Values
PROXY_PORT
public static final int PROXY_PORT
PROXY_HOST
public static final java.lang.String PROXY_HOST
URLTools
public URLTools()
isURLAbsolute
public static boolean isURLAbsolute(java.lang.String url)
performGET
public static byte[] performGET(java.net.URL url,
int soTimeoutMillis,
int connTimeoutMillis)
throws java.lang.IllegalArgumentException,
java.io.IOException
- Fetches content from an HTTP server performing a GET operation. If the status code is 200 then it will return a
byte array of the body otherwise returns null. 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.
- Parameters:
url
- the URL the URL of the resourcesoTimeoutMillis
- the socket connection timeout in millisconnTimeoutMillis
- the connection timeout in millis
- Returns:
- the retrieved byte array
- Throws:
java.lang.IllegalArgumentException
java.io.IOException
isNetworkURL
public static boolean isNetworkURL(java.lang.String url)
- Parameters:
url
-
- Returns:
- Since:
- 2.4.2
enforceAbsoluteURL
public static void enforceAbsoluteURL(java.lang.String url)
throws java.lang.IllegalArgumentException
- Enforces that the given URL is absolute
- Parameters:
url
- the String representation of the URL to be checked
- Throws:
java.lang.IllegalArgumentException
- if the given URL is not absolute
encodeXWWWFormURL
public static java.lang.String encodeXWWWFormURL(java.lang.String s)
decodeXWWWFormURL
public static java.lang.String decodeXWWWFormURL(java.lang.String s)
isEmailValid
public static boolean isEmailValid(java.lang.String address)
- Return true is the address is not null and matches the email validation regular expression.
exists
public static boolean exists(java.net.URL url)
- Determines that the specified URL corresponds to an existing resource by trying to open a stream from it. Same as
exists(url, 1000)
- Parameters:
url
-
- Returns:
exists
public static boolean exists(java.net.URL url,
long waitForMillis)
- Determines if the specified URL corresponds to an existing resource by trying to open a stream from it. The
connection attempt is made from a different thread on which we wait for the specified amount of time before timing
out.
- Parameters:
url
- the URL to be testedwaitForMillis
- the number of milliseconds to wait before timing out, 0 meaning never timing out.
- Returns:
- Since:
- 2.4.2
exists
public static boolean exists(java.lang.String urlAsString,
boolean allowNull)
- Parameters:
urlAsString
- allowNull
- true
if passing null
will be ignored and just return
false
, false
to throw an IllegalArgumentException
is the
given URL is null
.
- Returns:
- Since:
- 2.4.2
extractURLsFrom
public static URLTools.URLMatch[] extractURLsFrom(java.lang.String markup)
getURLCountIn
public static int getURLCountIn(java.lang.String markup)
replaceURLsBy
public static java.lang.String replaceURLsBy(java.lang.String markup,
java.lang.String[] replacements)
replaceURLsBy
public static java.lang.String replaceURLsBy(java.lang.String markup,
URLTools.URLReplacementGenerator generator)
replaceServerPortInURL
public static java.lang.String replaceServerPortInURL(java.lang.String url,
int newPort)
- Parameters:
url
- newPort
-
- Returns:
- Since:
- 2.4.2