DLESE Tools
v1.6.0

org.dlese.dpc.schemedit.url
Class UrlHelper

java.lang.Object
  extended by org.dlese.dpc.schemedit.url.UrlHelper

public class UrlHelper
extends Object

Utilities for manipulating and comparing URLs

Version:
$Id: UrlHelper.java,v 1.3 2009/03/20 23:33:58 jweather Exp $
Author:
ostwald

Constructor Summary
UrlHelper()
          Constructor for the UrlHelper object
 
Method Summary
static int deltaPath(URL url1, URL url2)
          Compute a "delta" between two URLs that serves as a measure of their similarity.
static int deltaPathLen(String urlStr1, String urlStr2)
          Returns the difference in path lengths of two urls represented as strings
static int deltaPathLen(URL url1, URL url2)
          Find the difference between the path lengths of two urls.
static URL getAncestor(String urlStr, int levels)
          Gets the specified ancestor (using the levels param) of a given url (represented as a string).
static URL getAncestor(URL url, int levels)
          Gets the ancestor of the given URL by calling getParent "level" times.
static String getParamValue(String paramName, String url)
          Gets the paramValue attribute of the UrlHelper class
static URL getParent(String urlStr)
          Gets the parent attribute of the UrlHelper class
static URL getParent(URL url)
          Gets the parent attribute of the UrlHelper class
static String getPathItem(String urlStr, int index)
          Gets the pathItem attribute of the UrlHelper class
static String getPathItem(URL url, int index)
          return the nth path item, empty string if nth item does not exist
static List getPathItems(URL url)
          Returns the segments of a url path split around the path separator ("/")
static int getPathLen(String s)
          Returns the length of the path component of a url represented as a string
static int getPathLen(URL url)
          Returns the length of the path component (URL.getPath()) of a url.
static Map getQueryArgs(String url)
          Gets the queryArgs attribute of the UrlHelper class
static String getSimilarUrlPath(String urlStr, int levels)
          Use wild cards to make a url that will retrieve all "ancestors" of the given url up to the specified level.
static URL getUrl(String urlStr)
          Converts a string into a URL instance, returning null in the case of a malformedUrl
static boolean isSimilar(String baseStr, String urlStr, int maxDelta)
          Checks whether two urls are similar within a variable "distance" that is a function of the respective lengths of the two urls.
static boolean isValid(URL url)
          A valid URL must have values for protocol and host.
static void main(String[] args)
          The main program for the UrlHelper class
static String normalize(String s)
          To be called on form input from metadata editor
static boolean validateUrl(String urlStr)
          Ensure that a urlStr contains a valid protocol and a host.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrlHelper

public UrlHelper()
Constructor for the UrlHelper object

Method Detail

normalize

public static String normalize(String s)
To be called on form input from metadata editor

Parameters:
s - NOT YET DOCUMENTED
Returns:
NOT YET DOCUMENTED
Throws:
URISyntaxException - NOT YET DOCUMENTED

isSimilar

public static boolean isSimilar(String baseStr,
                                String urlStr,
                                int maxDelta)
Checks whether two urls are similar within a variable "distance" that is a function of the respective lengths of the two urls.

assumes urlStr represents a valid URL, and that the protocol, host, and port match those of the baseURL. NOTE: the urls we want to check in DCS will already pass this test because they are retrieved by a query string that is built from a legal baseURL and include equal protocol, host and ports.

Parameters:
baseStr - A reference URL against which to check another url
urlStr - A url string to be checked for similarity against baseUrl
maxDelta - The maximum difference in url length (the length of the value returned by URL.getPath() split by "/")
Returns:
true if the urlStr is similar to baseUrl, false if the urls are not similar, or if either cannot be converted into a URL instance.

deltaPathLen

public static int deltaPathLen(URL url1,
                               URL url2)
Find the difference between the path lengths of two urls.

Parameters:
url1 - Description of the Parameter
url2 - Description of the Parameter
Returns:
Description of the Return Value

deltaPath

public static int deltaPath(URL url1,
                            URL url2)
Compute a "delta" between two URLs that serves as a measure of their similarity.

First find the portions of the two paths that are identical. Then sum the items in each url path items that are not found in the other.

Parameters:
url1 - Description of the Parameter
url2 - Description of the Parameter
Returns:
Description of the Return Value

deltaPathLen

public static int deltaPathLen(String urlStr1,
                               String urlStr2)
Returns the difference in path lengths of two urls represented as strings

Parameters:
urlStr1 - Description of the Parameter
urlStr2 - Description of the Parameter
Returns:
Description of the Return Value

getPathItem

public static String getPathItem(URL url,
                                 int index)
return the nth path item, empty string if nth item does not exist

Parameters:
url - Description of the Parameter
index - Description of the Parameter
Returns:
The pathItem value

getPathItem

public static String getPathItem(String urlStr,
                                 int index)
Gets the pathItem attribute of the UrlHelper class

Parameters:
urlStr - Description of the Parameter
index - Description of the Parameter
Returns:
The pathItem value

getPathItems

public static List getPathItems(URL url)
Returns the segments of a url path split around the path separator ("/")

Parameters:
url - A URL instance
Returns:
The pathItems as a List

getPathLen

public static int getPathLen(URL url)
Returns the length of the path component (URL.getPath()) of a url.

Parameters:
url - Description of the Parameter
Returns:
The pathLen value

getPathLen

public static int getPathLen(String s)
Returns the length of the path component of a url represented as a string

Parameters:
s - Description of the Parameter
Returns:
The path length, or 0 if the provided string could not be converted into a URL instance.

getUrl

public static URL getUrl(String urlStr)
Converts a string into a URL instance, returning null in the case of a malformedUrl

Parameters:
urlStr - Description of the Parameter
Returns:
A URL instance or null if the urlStr is malformed.

isValid

public static boolean isValid(URL url)
A valid URL must have values for protocol and host.

Parameters:
url - A URL instance
Returns:
true if the URL has both a protocal and host
See Also:
URL

validateUrl

public static boolean validateUrl(String urlStr)
                           throws MalformedURLException
Ensure that a urlStr contains a valid protocol and a host. Similar to isValid, but returns an exception containing an error msg that can be passed back to user.

Parameters:
urlStr - String representation of a URL
Returns:
true if valid
Throws:
MalformedURLException - if not valid

getSimilarUrlPath

public static String getSimilarUrlPath(String urlStr,
                                       int levels)
Use wild cards to make a url that will retrieve all "ancestors" of the given url up to the specified level.

Parameters:
urlStr - base url to be "generalized" using wildcard
levels - the number of levels up to generalize urlStr
Returns:
The similarUrlPath value

getAncestor

public static URL getAncestor(String urlStr,
                              int levels)
Gets the specified ancestor (using the levels param) of a given url (represented as a string).

Parameters:
urlStr - url represented as a String
levels - specifies how many levels "up" to go.
Returns:
The ancestor value

getAncestor

public static URL getAncestor(URL url,
                              int levels)
Gets the ancestor of the given URL by calling getParent "level" times.

Parameters:
url - Description of the Parameter
levels - Description of the Parameter
Returns:
The ancestor value

getParent

public static URL getParent(String urlStr)
Gets the parent attribute of the UrlHelper class

Parameters:
urlStr - Description of the Parameter
Returns:
The parent value

getParent

public static URL getParent(URL url)
Gets the parent attribute of the UrlHelper class

Parameters:
url - Description of the Parameter
Returns:
The parent value

getParamValue

public static String getParamValue(String paramName,
                                   String url)
Gets the paramValue attribute of the UrlHelper class

Parameters:
paramName - Description of the Parameter
url - Description of the Parameter
Returns:
The paramValue value

getQueryArgs

public static Map getQueryArgs(String url)
Gets the queryArgs attribute of the UrlHelper class

Parameters:
url - Description of the Parameter
Returns:
The queryArgs value

main

public static void main(String[] args)
The main program for the UrlHelper class

Parameters:
args - The command line arguments

DLESE Tools
v1.6.0