public class UrlHelper
extends java.lang.Object
Constructor and Description |
---|
UrlHelper()
Constructor for the UrlHelper object
|
Modifier and Type | Method and Description |
---|---|
static int |
deltaPath(java.net.URL url1,
java.net.URL url2)
Compute a "delta" between two URLs that serves as a measure of their
similarity.
|
static int |
deltaPathLen(java.lang.String urlStr1,
java.lang.String urlStr2)
Returns the difference in path lengths of two urls represented as strings
|
static int |
deltaPathLen(java.net.URL url1,
java.net.URL url2)
Find the difference between the path lengths of two urls.
|
static java.net.URL |
getAncestor(java.lang.String urlStr,
int levels)
Gets the specified ancestor (using the levels param) of a given url
(represented as a string).
|
static java.net.URL |
getAncestor(java.net.URL url,
int levels)
Gets the ancestor of the given URL by calling getParent "level" times.
|
static java.lang.String |
getParamValue(java.lang.String paramName,
java.lang.String url)
Gets the paramValue attribute of the UrlHelper class
|
static java.net.URL |
getParent(java.lang.String urlStr)
Gets the parent attribute of the UrlHelper class
|
static java.net.URL |
getParent(java.net.URL url)
Gets the parent attribute of the UrlHelper class
|
static java.lang.String |
getPathItem(java.lang.String urlStr,
int index)
Gets the pathItem attribute of the UrlHelper class
|
static java.lang.String |
getPathItem(java.net.URL url,
int index)
return the nth path item, empty string if nth item does not exist
|
static java.util.List |
getPathItems(java.net.URL url)
Returns the segments of a url path split around the path separator ("/")
|
static int |
getPathLen(java.lang.String s)
Returns the length of the path component of a url represented as a string
|
static int |
getPathLen(java.net.URL url)
Returns the length of the path component (URL.getPath()) of a url.
|
static java.util.Map |
getQueryArgs(java.lang.String url)
Gets the queryArgs attribute of the UrlHelper class
|
static java.lang.String |
getSimilarUrlPath(java.lang.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 java.net.URL |
getUrl(java.lang.String urlStr)
Converts a string into a URL instance, returning null in the case of a
malformedUrl
|
static boolean |
isSimilar(java.lang.String baseStr,
java.lang.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(java.net.URL url)
A valid URL must have values for protocol and host.
|
static void |
main(java.lang.String[] args)
The main program for the UrlHelper class
|
static java.lang.String |
normalize(java.lang.String s)
To be called on form input from metadata editor
|
static boolean |
validateUrl(java.lang.String urlStr)
Ensure that a urlStr contains a valid protocol and a host.
|
public static java.lang.String normalize(java.lang.String s)
s
- NOT YET DOCUMENTEDjava.net.URISyntaxException
- NOT YET DOCUMENTEDpublic static boolean isSimilar(java.lang.String baseStr, java.lang.String urlStr, int maxDelta)
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.
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 "/")public static int deltaPathLen(java.net.URL url1, java.net.URL url2)
url1
- Description of the Parameterurl2
- Description of the Parameterpublic static int deltaPath(java.net.URL url1, java.net.URL url2)
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.
url1
- Description of the Parameterurl2
- Description of the Parameterpublic static int deltaPathLen(java.lang.String urlStr1, java.lang.String urlStr2)
urlStr1
- Description of the ParameterurlStr2
- Description of the Parameterpublic static java.lang.String getPathItem(java.net.URL url, int index)
url
- Description of the Parameterindex
- Description of the Parameterpublic static java.lang.String getPathItem(java.lang.String urlStr, int index)
urlStr
- Description of the Parameterindex
- Description of the Parameterpublic static java.util.List getPathItems(java.net.URL url)
url
- A URL instancepublic static int getPathLen(java.net.URL url)
url
- Description of the Parameterpublic static int getPathLen(java.lang.String s)
s
- Description of the Parameterpublic static java.net.URL getUrl(java.lang.String urlStr)
urlStr
- Description of the Parameterpublic static boolean isValid(java.net.URL url)
url
- A URL instanceURL
public static boolean validateUrl(java.lang.String urlStr) throws java.net.MalformedURLException
urlStr
- String representation of a URLjava.net.MalformedURLException
- if not validpublic static java.lang.String getSimilarUrlPath(java.lang.String urlStr, int levels)
urlStr
- base url to be "generalized" using wildcardlevels
- the number of levels up to generalize urlStrpublic static java.net.URL getAncestor(java.lang.String urlStr, int levels)
urlStr
- url represented as a Stringlevels
- specifies how many levels "up" to go.public static java.net.URL getAncestor(java.net.URL url, int levels)
url
- Description of the Parameterlevels
- Description of the Parameterpublic static java.net.URL getParent(java.lang.String urlStr)
urlStr
- Description of the Parameterpublic static java.net.URL getParent(java.net.URL url)
url
- Description of the Parameterpublic static java.lang.String getParamValue(java.lang.String paramName, java.lang.String url)
paramName
- Description of the Parameterurl
- Description of the Parameterpublic static java.util.Map getQueryArgs(java.lang.String url)
url
- Description of the Parameterpublic static void main(java.lang.String[] args)
args
- The command line arguments