EchoPoint
1.0

echopoint.util
Class URLKit

java.lang.Object
  extended byechopoint.util.URLKit

public class URLKit
extends java.lang.Object

URLKit is a utility class for working with java.net.URLs.

URLKit.locate() allows you to use a 3 step strategy for creating URLS to load application data.

Step 1:

This method will first look for the existence of a file and if it exists then it will return that as an URL. The file name is defined as fileDirectoryPrefix + fileOrResourceName

Step 2:

Faling that, if you provide an non null EchoInstance, it will retrieve the javax.servlet.ServletContext from the instance and attempt to locate it using javax.servlet.ServletContext.getResource(java.lang.String) and the fileOrResourceName. This step allows you to access resources in your web application that are not under a class path directory.

Step 3:

If ServletContext.getResource() fails or the EchoIntance is null, it will then attempt to locate the URL as a class resource via Class.getResource(java.lang.String).

The URLKit.locate() method is useful when moving between development and production.

For example, in development your resources may reside in your web project source directory (probably under source control).

Then when you move to production, they will reside as class resources under the web application servlet context root directory or WEB-INF/classes directory of your web application.

URLKit.locate() will allow for easier resource changes during development and testing and then use servlet context and class loading in production.

You would use this class something like this :

 URL url = URLKit.locate(
 			"/java/myproject/finance/src",
 			"/com/bankwest/templates/login.html",
 			getEchoInstance());
 
In the above example URLKit.locate() will first look for the resource as a file called :
 "/java/myproject/finance/src/com/bankwest/templates/login.html"
 
Then if this file cannot be found it will locate the URL via ServletContext using the name :
 "/com/bankwest/templates/login.html"
 
Finally if this fails it will locate the URL the via Class resource loading using the name :
 "/com/bankwest/templates/login.html"
 


Method Summary
static java.net.URL locate(java.lang.String fileDirectoryPrefix, java.lang.String fileOrResourceName)
          Locates an URL using the following strategy Step 1 : Looks for a file called 'fileDirectoryPrefix + fileOrResourceName' Step 2 : failing that, it will a Class.getResource(fileOrResourceName)
static java.net.URL locate(java.lang.String fileDirectoryPrefix, java.lang.String fileOrResourceName, nextapp.echo.EchoInstance echoInstance)
          Locates an URL using the following strategy Step 1 : Looks for a file called 'fileDirectoryPrefix + fileOrResourceName' Step 2 : failing that, it uses the EchoInstance to locate the URL via ServletContext.getResource(fileOrResourceName) Step 3 : failing that, it will a Class.getResource(fileOrResourceName)
static java.net.URL locate(java.lang.String fileDirectoryPrefix, java.lang.String fileOrResourceName, nextapp.echo.EchoInstance echoInstance, java.lang.Class resourceClass)
          Locates an URL using the following strategy : Step 1 : Looks for a file called 'fileDirectoryPrefix + fileOrResourceName' Step 2 : failing that, it uses the EchoInstance to locate the URL via ServletContext.getResource(fileOrResourceName), if the EchoInstance is not null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

locate

public static java.net.URL locate(java.lang.String fileDirectoryPrefix,
                                  java.lang.String fileOrResourceName)
Locates an URL using the following strategy

Step 1 : Looks for a file called 'fileDirectoryPrefix + fileOrResourceName'

Step 2 : failing that, it will a Class.getResource(fileOrResourceName)

Parameters:
fileDirectoryPrefix - - the directory prefix to use when looking initially for the File. May be null.
fileOrResourceName - - the file or class resource name to use.

locate

public static java.net.URL locate(java.lang.String fileDirectoryPrefix,
                                  java.lang.String fileOrResourceName,
                                  nextapp.echo.EchoInstance echoInstance)
Locates an URL using the following strategy

Step 1 : Looks for a file called 'fileDirectoryPrefix + fileOrResourceName'

Step 2 : failing that, it uses the EchoInstance to locate the URL via ServletContext.getResource(fileOrResourceName)

Step 3 : failing that, it will a Class.getResource(fileOrResourceName)

Parameters:
fileDirectoryPrefix - - the directory prefix to use when looking initially for the File. May be null.
fileOrResourceName - - the file or class resource name to use.
echoInstance - - the EchoInstance to retreive the ServletContext from. This can be null, in which case ServletContext resource loading will not be used.

locate

public static java.net.URL locate(java.lang.String fileDirectoryPrefix,
                                  java.lang.String fileOrResourceName,
                                  nextapp.echo.EchoInstance echoInstance,
                                  java.lang.Class resourceClass)
Locates an URL using the following strategy :

Step 1 : Looks for a file called 'fileDirectoryPrefix + fileOrResourceName'

Step 2 : failing that, it uses the EchoInstance to locate the URL via ServletContext.getResource(fileOrResourceName), if the EchoInstance is not null.

Step 3 : failing that, it will a Class.getResource(fileOrResourceName)

Parameters:
fileDirectoryPrefix - - the directory prefix to use when looking initially for the File. May be null.
fileOrResourceName - - the file or class resource name to use.
echoInstance - - the EchoInstance to retreive the ServletContext from. This can be null, in which case ServletContext resource loading will not be used.
resourceClass - - the class to use when loading the resource data via Class.getResource(java.lang.String)
See Also:
Class.getResource(java.lang.String), ServletContext.getResource(java.lang.String)

EchoPoint
1.0