| java.lang.Object org.jaffa.util.URLHelper
URLHelper | public class URLHelper (Code) | | Utility class to manipulate URL's and provide some additional capability for using them.
author: PaulE version: 1.0 |
Method Summary | |
public static String | buildUrl(String url, HttpServletRequest req) Build up a valid URL string based on the supplied source URL string. | public static String | getBase(HttpServletRequest request) Based on a HttpRequest, this routine will ingure out the URL that represents the root of
the web application. | public static String | getFullUrl(HttpServletRequest request) | public static InputStream | getInputStream(String resourceName) This method will try to load the input resource off the classpath.
If its not found, then it will look for it in the filesystem.
A null will be returned, if the resource could not be located.
Parameters: resourceName - the resource to be located. throws: IOException - if any error occurs while opening the stream. | public static URL | getUrl(String resourceName) This method will try to load the input resource off the classpath.
If its not found, then it will look for it in the filesystem.
A null will be returned, if the resource could not be located.
This method merely invokes the newExtendedURL() method, returning a null if any exception is raised.
Parameters: resourceName - the resource to be located. | public static void | main(String[] args) | public static URL | newExtendedURL(String url) Create a URL object from a string, this can handle the two new Custom URL
protocols, 'classpath:///' and 'webroot:///'. |
DEFAULT_PAGE | final public static String DEFAULT_PAGE(Code) | | This is the default value for the initial page of the application
|
PROTOCOL_CLASSPATH | final public static String PROTOCOL_CLASSPATH(Code) | | This contains the name of the URL protocol that implies the resouce can be located in the classpath
|
PROTOCOL_WEBROOT | final public static String PROTOCOL_WEBROOT(Code) | | This contains the name of the URL protocol that implies the resource can be found relative to the location of the web-root on the local file system,
This assumes that you are running this inside a servlet, on a web server
|
buildUrl | public static String buildUrl(String url, HttpServletRequest req)(Code) | | Build up a valid URL string based on the supplied source URL string.
If the supplied string in null, use the string defined in DEFAULT_PAGE and
append this to web root ( using URLHelper.getBase() )
If the supplied string already is a valid url, leave it as is.
If it is currently invalid, see if it can be made valid by making it relative to
the web application base ( using URLHelper.getBase() ), if so return this value
If this still doesn't yield a valid url, assume it was null, and build it based on
DEFAULT_PAGE and getBase()
Parameters: url - The URL to build and validate Parameters: req - The httpRequest needed to derive the web app base A fully expressed valid URL |
getBase | public static String getBase(HttpServletRequest request)(Code) | | Based on a HttpRequest, this routine will ingure out the URL that represents the root of
the web application. It derives the URL protocol, host, port and application.
An example of a returned string may be http://www.example.org/myApp/
or https://www.example.com:888/SecureApp/
Parameters: request - A HttpRequest used to derive information about the root of the web applicatoin a string that represents the base URL for this web application |
getFullUrl | public static String getFullUrl(HttpServletRequest request)(Code) | | Get a complete string based representation of a request's source URL include query parameters
Parameters: request - HttpRequest containing the url to extracts string representation of URL |
getInputStream | public static InputStream getInputStream(String resourceName) throws IOException(Code) | | This method will try to load the input resource off the classpath.
If its not found, then it will look for it in the filesystem.
A null will be returned, if the resource could not be located.
Parameters: resourceName - the resource to be located. throws: IOException - if any error occurs while opening the stream. an input stream for reading from the resource. |
getUrl | public static URL getUrl(String resourceName)(Code) | | This method will try to load the input resource off the classpath.
If its not found, then it will look for it in the filesystem.
A null will be returned, if the resource could not be located.
This method merely invokes the newExtendedURL() method, returning a null if any exception is raised.
Parameters: resourceName - the resource to be located. a URL for reading from the resource. |
main | public static void main(String[] args)(Code) | | Test rig
Parameters: args - none required |
newExtendedURL | public static URL newExtendedURL(String url) throws MalformedURLException(Code) | | Create a URL object from a string, this can handle the two new Custom URL
protocols, 'classpath:///' and 'webroot:///'. If either of these new ones are
used they will be converted into the appropriate 'file://' format.
If no protocol is specified, then it'll try to load the input resource off the classpath.
If its not found, then it will look for the input resource in the filesystem.
Parameters: url - source URL that may use one of the new protocols throws: MalformedURLException - if the supplied URL is not valid, or can't be translated into something that is valid valid URL object, as these two new protocols are not really supported by the java.net.URL object |
|
|