com.pepper.platform.util
Class URLUtils

java.lang.Object
  extended by com.pepper.platform.util.URLUtils

public class URLUtils
extends Object

Utility methods for dealing with URLs.


Constructor Summary
URLUtils()
           
 
Method Summary
static URL checkURL(String location)
           
static File fileURLToFile(URL url)
          This routine converts an absolute File URL to a File representing the resource
static String getAttrValue(String queryString, String attribute)
          Searches the queryString of the URL for the specified attribute and will return it's value
static String getAttrValue(URL theURL, String attribute)
          Searches the queryString of the URL for the specified attribute and will return it's value
static String getExtension(String fileName)
          Get the file extension from the given file name
static String getExtension(URL u)
          Get the file extension from the given url
static String getFileNoExtension(URL u)
          Get the file name without the extension
static String insertBeforeExtension(URL pepperURL, String textToInsert)
          Inserts a string into the filename before the extension of the file.
static URL makeJarFileURL(String jarFilePath, String resourceName)
          Make a jar file url
static String makeJarFileURL(String jarFilePath, String jarFileName, String resourceName)
          Make a jar file url
static String normalize(String path)
          Return the canonical version of the given path by resolving ".." "." and "//" elements.
static HashMap parseQueryString(String queryString)
          Parse a URL query string, typically in the format atr1=value1&attr2=value2&attr3=value3.
static HashMap parseQueryString(URL theURL)
          Parse a URL query string, typically in the format http://foo.com? atr1=value1&attr2=value2&attr3=value3.
static File pepperURLToFile(URL url, String baseDir)
          This routine converts a relative pepperURL to a File representing the resource
static URL stripQueryString(URL theURL)
          Strip the query string from a URL and return the result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLUtils

public URLUtils()
Method Detail

stripQueryString

public static URL stripQueryString(URL theURL)
Strip the query string from a URL and return the result.

Parameters:
theURL - URL to process
Returns:
theURL, minus query string.

parseQueryString

public static HashMap parseQueryString(URL theURL)
Parse a URL query string, typically in the format http://foo.com? atr1=value1&attr2=value2&attr3=value3. This method will return a HashMap of attribute/value pairs found in the query string, and will URLDecode the values.

Parameters:
theURL - a String value
Returns:
a HashMap value

parseQueryString

public static HashMap parseQueryString(String queryString)
Parse a URL query string, typically in the format atr1=value1&attr2=value2&attr3=value3. This method will return a HashMap of attribute/value pairs found in the query string, and will URLDecode the values.

Parameters:
queryString - Either just the queryString portion or the entire URL (containing the query string) as a string
Returns:
a HashMap value

getAttrValue

public static String getAttrValue(URL theURL,
                                  String attribute)
Searches the queryString of the URL for the specified attribute and will return it's value

Parameters:
theURL - an URL value
attribute - a String value
Returns:
a String value

getAttrValue

public static String getAttrValue(String queryString,
                                  String attribute)
Searches the queryString of the URL for the specified attribute and will return it's value

Parameters:
queryString - The queryString typically in the form attr1=value1&attr2=value2
attribute - a String value
Returns:
a String value

normalize

public static String normalize(String path)
Return the canonical version of the given path by resolving ".." "." and "//" elements. Preserves the "://" element that separates the protocol and host of a URL.

Parameters:
path - the path to be normalized.
Returns:
the normalized path.

makeJarFileURL

public static URL makeJarFileURL(String jarFilePath,
                                 String resourceName)
Make a jar file url

Parameters:
jarFilePath - a String value
resourceName - a String value
Returns:
an URL value

makeJarFileURL

public static String makeJarFileURL(String jarFilePath,
                                    String jarFileName,
                                    String resourceName)
Make a jar file url

Parameters:
jarFilePath - a String value
jarFileName - a String value
resourceName - a String value
Returns:
a String value

checkURL

public static URL checkURL(String location)

getExtension

public static String getExtension(URL u)
Get the file extension from the given url

Parameters:
u - the url to search
Returns:
the file extension

getExtension

public static String getExtension(String fileName)
Get the file extension from the given file name

Parameters:
fileName - The name of the file
Returns:
the file extension

getFileNoExtension

public static String getFileNoExtension(URL u)
Get the file name without the extension

Parameters:
u - an URL value
Returns:
a String value

pepperURLToFile

public static File pepperURLToFile(URL url,
                                   String baseDir)
This routine converts a relative pepperURL to a File representing the resource

Parameters:
url - an URL value
baseDir - a String value
Returns:
a File value

fileURLToFile

public static File fileURLToFile(URL url)
This routine converts an absolute File URL to a File representing the resource

Parameters:
url - an URL value
Returns:
a File value

insertBeforeExtension

public static String insertBeforeExtension(URL pepperURL,
                                           String textToInsert)
Inserts a string into the filename before the extension of the file. For example if the URL is pepper://data/foo/bar.jpg, and we wanted to make a tmp file, the result would be data/foo/bar-TMP.jpg

Parameters:
pepperURL - an URL value
textToInsert - a String value
Returns:
a String representing the string of the path with the leading / removed


Copyright © 2006-2007 Pepper Computer, Inc. All Rights Reserved.