org.jboss.portal.common.net
Class URLTools

java.lang.Object
  extended by 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

Nested Class Summary
static class URLTools.PortReplacementGenerator
           
static class URLTools.URLMatch
           
static class URLTools.URLReplacementGenerator
           
 
Field Summary
static java.lang.String FILE_PREFIX
           
static java.lang.String FTP_PREFIX
           
static java.lang.String HTTP_PREFIX
           
static java.lang.String HTTPS_PREFIX
           
static java.lang.String RE_EMAIL_VALIDATION
           
 
Constructor Summary
URLTools()
           
 
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 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(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 byte[] getContent(java.net.URL url, int soTimeoutMillis, int connTimeoutMillis)
          Fetches content from of the URL as a byte array or null if a problem occurred.
static java.io.InputStream getContentAsInputStream(java.net.URL url, int soTimeoutMillis, int connTimeoutMillis)
          Fetches content from URL as an InputStream.
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 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
 

Field Detail

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
Constructor Detail

URLTools

public URLTools()
Method Detail

isURLAbsolute

public static boolean isURLAbsolute(java.lang.String url)

getContent

public static byte[] getContent(java.net.URL url,
                                int soTimeoutMillis,
                                int connTimeoutMillis)
                         throws java.lang.IllegalArgumentException
Fetches content from of the URL as a byte array or 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.

Parameters:
url - the URL the URL of the resource
soTimeoutMillis - the socket connection timeout in millis
connTimeoutMillis - the connection timeout in millis
Returns:
the retrieved byte array
Throws:
java.lang.IllegalArgumentException - if the URL is null or any time out value is negative

getContentAsInputStream

public static java.io.InputStream getContentAsInputStream(java.net.URL url,
                                                          int soTimeoutMillis,
                                                          int connTimeoutMillis)
                                                   throws java.io.IOException
Fetches content from URL as an InputStream. 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 resource
soTimeoutMillis - the socket connection timeout in millis
connTimeoutMillis - the connection timeout in millis
Returns:
the buffered content for the URL
Throws:
java.lang.IllegalArgumentException - if the URL is null or any time out value is negative
java.io.IOException
Since:
1.1

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)
                      throws java.lang.IllegalArgumentException
Determines if the specified URL corresponds to an existing resource by trying to open a stream from it.

Parameters:
url - the URL to be tested
waitForMillis - the number of milliseconds to wait before timing out, 0 meaning never timing out.
Returns:
Throws:
java.lang.IllegalArgumentException - if the url is null or the time out negative
Since:
2.4.2

exists

public static boolean exists(java.lang.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 ?

Parameters:
stringURL -
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