Package org.dlese.dpc.schemedit.url
Class UrlHelper
java.lang.Object
org.dlese.dpc.schemedit.url.UrlHelper
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intCompute a "delta" between two URLs that serves as a measure of their similarity.static intdeltaPathLen(String urlStr1, String urlStr2) Returns the difference in path lengths of two urls represented as stringsstatic intdeltaPathLen(URL url1, URL url2) Find the difference between the path lengths of two urls.static URLgetAncestor(String urlStr, int levels) Gets the specified ancestor (using the levels param) of a given url (represented as a string).static URLgetAncestor(URL url, int levels) Gets the ancestor of the given URL by calling getParent "level" times.static StringgetParamValue(String paramName, String url) Gets the paramValue attribute of the UrlHelper classstatic URLGets the parent attribute of the UrlHelper classstatic URLGets the parent attribute of the UrlHelper classstatic StringgetPathItem(String urlStr, int index) Gets the pathItem attribute of the UrlHelper classstatic StringgetPathItem(URL url, int index) return the nth path item, empty string if nth item does not existstatic ListgetPathItems(URL url) Returns the segments of a url path split around the path separator ("/")static intgetPathLen(String s) Returns the length of the path component of a url represented as a stringstatic intgetPathLen(URL url) Returns the length of the path component (URL.getPath()) of a url.static MapgetQueryArgs(String url) Gets the queryArgs attribute of the UrlHelper classstatic StringgetSimilarUrlPath(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 URLConverts a string into a URL instance, returning null in the case of a malformedUrlstatic booleanChecks whether two urls are similar within a variable "distance" that is a function of the respective lengths of the two urls.static booleanA valid URL must have values for protocol and host.static voidThe main program for the UrlHelper classstatic StringTo be called on form input from metadata editorstatic booleanvalidateUrl(String urlStr) Ensure that a urlStr contains a valid protocol and a host.
-
Constructor Details
-
UrlHelper
public UrlHelper()Constructor for the UrlHelper object
-
-
Method Details
-
normalize
To be called on form input from metadata editor- Parameters:
s- NOT YET DOCUMENTED- Returns:
- NOT YET DOCUMENTED
- Throws:
URISyntaxException- NOT YET DOCUMENTED
-
isSimilar
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 urlurlStr- A url string to be checked for similarity against baseUrlmaxDelta- 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
Find the difference between the path lengths of two urls.- Parameters:
url1- Description of the Parameterurl2- Description of the Parameter- Returns:
- Description of the Return Value
-
deltaPath
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 Parameterurl2- Description of the Parameter- Returns:
- Description of the Return Value
-
deltaPathLen
Returns the difference in path lengths of two urls represented as strings- Parameters:
urlStr1- Description of the ParameterurlStr2- Description of the Parameter- Returns:
- Description of the Return Value
-
getPathItem
return the nth path item, empty string if nth item does not exist- Parameters:
url- Description of the Parameterindex- Description of the Parameter- Returns:
- The pathItem value
-
getPathItem
Gets the pathItem attribute of the UrlHelper class- Parameters:
urlStr- Description of the Parameterindex- Description of the Parameter- Returns:
- The pathItem value
-
getPathItems
Returns the segments of a url path split around the path separator ("/")- Parameters:
url- A URL instance- Returns:
- The pathItems as a List
-
getPathLen
Returns the length of the path component (URL.getPath()) of a url.- Parameters:
url- Description of the Parameter- Returns:
- The pathLen value
-
getPathLen
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
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
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:
-
validateUrl
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
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 wildcardlevels- the number of levels up to generalize urlStr- Returns:
- The similarUrlPath value
-
getAncestor
Gets the specified ancestor (using the levels param) of a given url (represented as a string).- Parameters:
urlStr- url represented as a Stringlevels- specifies how many levels "up" to go.- Returns:
- The ancestor value
-
getAncestor
Gets the ancestor of the given URL by calling getParent "level" times.- Parameters:
url- Description of the Parameterlevels- Description of the Parameter- Returns:
- The ancestor value
-
getParent
Gets the parent attribute of the UrlHelper class- Parameters:
urlStr- Description of the Parameter- Returns:
- The parent value
-
getParent
Gets the parent attribute of the UrlHelper class- Parameters:
url- Description of the Parameter- Returns:
- The parent value
-
getParamValue
Gets the paramValue attribute of the UrlHelper class- Parameters:
paramName- Description of the Parameterurl- Description of the Parameter- Returns:
- The paramValue value
-
getQueryArgs
Gets the queryArgs attribute of the UrlHelper class- Parameters:
url- Description of the Parameter- Returns:
- The queryArgs value
-
main
The main program for the UrlHelper class- Parameters:
args- The command line arguments
-