com.metamatrix.common.protocol
Class URLHelper

java.lang.Object
  extended by com.metamatrix.common.protocol.URLHelper

public class URLHelper
extends java.lang.Object

Helper class to build the URL objects from the strings. Since as an application we do not know if we are embedded or we are in our own server, we can not install the "URLStreamHandlers" in the VM, as they can be only installed once per VM, as an alternative, the stream handler must be specified at the time URL it is constructed. This class will help us to this code at one place. Here inspect the given string and build the correct type of URL with correct handler.

Since:
4.4

Constructor Summary
URLHelper()
           
 
Method Summary
static java.net.URL buildURL(java.lang.String url)
          Construct the URL based on the String
static java.net.URL buildURL(java.net.URL url)
           
static java.net.URL buildURL(java.net.URL context, java.lang.String url)
           
static java.io.File createFileFromUrl(java.net.URL url, java.lang.String fileNamePrefix, java.lang.String fileNameSuffix)
          Build a File from a URL object.
static java.io.File createFileFromUrl(java.net.URL url, java.lang.String filePath, java.lang.String userName, java.lang.String password, boolean verifyHostname)
          Download the content from the given URL and save it into the specified file.
static boolean resolveUrl(java.net.URL url)
          Determines whether a URL object resolves to a valid url.
static boolean resolveUrl(java.net.URL url, boolean verifyHostname)
          Determines whether a URL object resolves to a valid url.
static boolean resolveUrl(java.net.URL url, java.lang.String userName, java.lang.String password, boolean verifyHostname)
          Determines whether a URL object resolves to a valid url.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLHelper

public URLHelper()
Method Detail

buildURL

public static java.net.URL buildURL(java.lang.String url)
                             throws java.net.MalformedURLException
Construct the URL based on the String

Parameters:
url -
Returns:
Throws:
java.net.MalformedURLException
Since:
4.4

buildURL

public static java.net.URL buildURL(java.net.URL context,
                                    java.lang.String url)
                             throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException

buildURL

public static java.net.URL buildURL(java.net.URL url)

resolveUrl

public static boolean resolveUrl(java.net.URL url,
                                 java.lang.String userName,
                                 java.lang.String password,
                                 boolean verifyHostname)
                          throws java.net.MalformedURLException,
                                 java.io.IOException
Determines whether a URL object resolves to a valid url. This will work for any protocol (file, HTTP, etc.).

Parameters:
url -
userName -
password -
verifyHostname - whether to verify hostname for HTTPS connection
Returns:
resolved boolean
Throws:
MalformedURLException, - IOException
java.net.MalformedURLException
java.io.IOException
Since:
5.1

resolveUrl

public static boolean resolveUrl(java.net.URL url)
                          throws java.net.MalformedURLException,
                                 java.io.IOException
Determines whether a URL object resolves to a valid url. This will work for any protocol (file, HTTP, etc.).

Parameters:
url -
Returns:
resolved boolean
Throws:
MalformedURLException, - IOException
java.net.MalformedURLException
java.io.IOException
Since:
5.1

resolveUrl

public static boolean resolveUrl(java.net.URL url,
                                 boolean verifyHostname)
                          throws java.net.MalformedURLException,
                                 java.io.IOException
Determines whether a URL object resolves to a valid url. This will work for any protocol (file, HTTP, etc.).

Parameters:
url -
verifyHostname - whether to verify hostname for HTTPS connection
Returns:
resolved boolean
Throws:
MalformedURLException, - IOException
java.net.MalformedURLException
java.io.IOException
Since:
5.5

createFileFromUrl

public static java.io.File createFileFromUrl(java.net.URL url,
                                             java.lang.String filePath,
                                             java.lang.String userName,
                                             java.lang.String password,
                                             boolean verifyHostname)
                                      throws java.net.MalformedURLException,
                                             java.io.IOException
Download the content from the given URL and save it into the specified file.

Parameters:
url - URL of the file to be saved
filePath - the full path of the file name
userName - user name if authentication is required
password - password if authentication is required
verifyHostname - whether to verify hostname for HTTPS connection
Returns:
the file created
Throws:
java.net.MalformedURLException
java.io.IOException
Since:
5.5

createFileFromUrl

public static java.io.File createFileFromUrl(java.net.URL url,
                                             java.lang.String fileNamePrefix,
                                             java.lang.String fileNameSuffix)
                                      throws java.net.MalformedURLException,
                                             java.io.IOException
Build a File from a URL object.

Parameters:
url -
fileNamePrefix -
fileNameSuffix -
Returns:
File
Throws:
java.net.MalformedURLException
java.io.IOException
Since:
5.1


Copyright © 2009. All Rights Reserved.