com.ibm.rational.rpe.common.utils
Class URLDataProvider

java.lang.Object
  extended by com.ibm.rational.rpe.common.utils.URLDataProvider

public class URLDataProvider
extends java.lang.Object

This class is a utility class for accessing remote resources. When instantiated, the URL and credentials of the Central Management component specified automatically for users in the preferences. Users can replace the values by using setter methods. This class includes common functions to set up a connection


Constructor Summary
URLDataProvider()
          WARNING: For use during RRDG document generations.
 
Method Summary
 long addRequestTime(long time)
          Registers the time spent for a data request outside of this instance
 java.lang.String cacheResource(java.lang.String url, Credential credential)
          Returns the path to a cached copy of the resource identified by the URL with the default connection parameters.
 java.lang.String cacheResource(java.lang.String url, Credential credential, ConnectionArguments connectionArgs)
          Returns the path to a cached copy of the resource referred by the URL with ConnectionArguments ConnectionArguments.
 void cleanup()
          Clears all cached data.
static java.io.InputStream doNone(java.lang.String url, ConnectionArguments connectionArgs)
          Downloads the content from the specified URL in the given path with the provided connection arguments
static java.lang.String downloadFile(java.net.URL url)
          Downloads the file from the URL specified and returns the local path where it was download to
static void downloadFile(java.net.URL url, java.lang.String localPath, ConnectionArguments connectionArgs)
          Downloads the content from the specified URL in the given path with the provided connection arguments
 java.lang.String expandLibraryURL(java.lang.String url)
          Returns the absolute URL for the relative URL passed
 IConnectionConfigurator getConnectionConfigurator()
          Returns the IConnectionConfigurator that is set.
 long getTotalRequestTime()
          Returns the total time taken by the request from complete.
 boolean isCached(java.lang.String url)
          Returns true if the URL is already cached locally
 java.io.InputStream openDataStream(java.lang.String url, Credential credential)
          Returns a stream to the desired resource with no caching.
 java.io.InputStream openDataStream(java.lang.String url, Credential credential, ConnectionArguments connectionArgs)
          Returns a stream to the desired resource with no caching.
 void registerFile(java.lang.String file)
          Adds the file to the cache
 void setConnectionConfigurator(IConnectionConfigurator connectionConfigurator)
          Sets the IConnectionConfigurator
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLDataProvider

public URLDataProvider()
WARNING: For use during RRDG document generations. Do NOT create new instances of this object. Use the instance from the engine to ensure that you get one fully configured by the provider

Method Detail

setConnectionConfigurator

public void setConnectionConfigurator(IConnectionConfigurator connectionConfigurator)
Sets the IConnectionConfigurator


getConnectionConfigurator

public IConnectionConfigurator getConnectionConfigurator()
Returns the IConnectionConfigurator that is set. The default value is null.

Returns:
connectionConfigurator

isCached

public boolean isCached(java.lang.String url)
                 throws AuthenticationException,
                        ConnectionException
Returns true if the URL is already cached locally

Returns:
boolean
Throws:
AuthenticationException
ConnectionException

getTotalRequestTime

public long getTotalRequestTime()
Returns the total time taken by the request from complete. The default value is 0.

Returns:
time in milliseconds

addRequestTime

public long addRequestTime(long time)
Registers the time spent for a data request outside of this instance

Parameters:
time - (in milliseconds) to be added
Returns:
total time (in milliseconds) including the input time

cacheResource

public java.lang.String cacheResource(java.lang.String url,
                                      Credential credential,
                                      ConnectionArguments connectionArgs)
                               throws AuthenticationException,
                                      ConnectionException
Returns the path to a cached copy of the resource referred by the URL with ConnectionArguments ConnectionArguments. If the resource was not cached, it is cached before it is returned.

Parameters:
url - Path of the resource - cannot be empty
credential - Credentials to access the resource, if any - cannot be null
acceptHeader - - the accept header to use
Returns:
an open stream for the data
Throws:
AuthenticationException
ConnectionException

cacheResource

public java.lang.String cacheResource(java.lang.String url,
                                      Credential credential)
                               throws AuthenticationException,
                                      ConnectionException
Returns the path to a cached copy of the resource identified by the URL with the default connection parameters. If the resource was not cached, it is cached before it is returned.

Parameters:
url - Path of the resource - cannot be empty
credential - Credentials to access the resource, if any - cannot be null
Returns:
an open stream for the data
Throws:
AuthenticationException
ConnectionException

openDataStream

public java.io.InputStream openDataStream(java.lang.String url,
                                          Credential credential)
                                   throws AuthenticationException,
                                          ConnectionException
Returns a stream to the desired resource with no caching.

Parameters:
url - Path of the resource - cannot be empty
credential - Credentials to access the resource, if any - cannot be null
Returns:
an open stream for the data
Throws:
AuthenticationException
ConnectionException

openDataStream

public java.io.InputStream openDataStream(java.lang.String url,
                                          Credential credential,
                                          ConnectionArguments connectionArgs)
                                   throws AuthenticationException,
                                          ConnectionException
Returns a stream to the desired resource with no caching.

Parameters:
url - Path of the resource - cannot be empty
credential - Credentials to access the resource. - cannot be null
acceptHeader - - the accept header to use
Returns:
an open stream for the data
Throws:
AuthenticationException
ConnectionException

doNone

public static java.io.InputStream doNone(java.lang.String url,
                                         ConnectionArguments connectionArgs)
                                  throws AuthenticationException,
                                         ConnectionException
Downloads the content from the specified URL in the given path with the provided connection arguments

Parameters:
url - - cannot be NULL
localPath - - cannot be NULL
connectionArgs - - cannot be NULL
Returns:
an open stream for the data
Throws:
AuthenticationException
ConnectionException

cleanup

public void cleanup()
Clears all cached data.


downloadFile

public static java.lang.String downloadFile(java.net.URL url)
                                     throws AuthenticationException,
                                            ConnectionException
Downloads the file from the URL specified and returns the local path where it was download to

Parameters:
URL - to download from
Returns:
path of locally stored file
Throws:
AuthenticationException
ConnectionException

downloadFile

public static void downloadFile(java.net.URL url,
                                java.lang.String localPath,
                                ConnectionArguments connectionArgs)
                         throws AuthenticationException,
                                ConnectionException
Downloads the content from the specified URL in the given path with the provided connection arguments

Parameters:
URL - to download from
local - path to which the file should be download to
connectionArgs - - cannot be NULL
Throws:
AuthenticationException
ConnectionException

registerFile

public void registerFile(java.lang.String file)
Adds the file to the cache

Parameters:
File - to be added to the cache

expandLibraryURL

public java.lang.String expandLibraryURL(java.lang.String url)
Returns the absolute URL for the relative URL passed

Parameters:
URL - to be converted to absolute URL
Returns:
Absolute URL