gov.lanl.archive.rewrite
Class UrlOperations

java.lang.Object
  extended by gov.lanl.archive.rewrite.UrlOperations

public class UrlOperations
extends Object

Class containing common static URL methods. Primarily resolveUrl() and the (currently) unused isAuthority().

Version:
$Date: 2011-05-24 19:08:38 -0600 (Tue, 24 May 2011) $, $Revision: 3442 $
Author:
brad

Field Summary
static String[] ALL_SCHEMES
          array of static Strings for all "known" schemes
static String DEFAULT_SCHEME
          Default scheme to assume if unspecified.
static String DNS_SCHEME
          ARC/WARC specific DNS resolution record.
static String FTP_SCHEME
          FTP
static String HTTP_SCHEME
          HTTP
static String HTTPS_SCHEME
          HTTPS
static String MMS_SCHEME
          MMS
static char PATH_START
          character which delimits the path from the authority in a...
static char PORT_SEPARATOR
          character separating host from port within a URL authority
static String RTSP_SCHEME
          RTSP
static String WAIS_SCHEME
          go brewster
 
Constructor Summary
UrlOperations()
           
 
Method Summary
static String fixupHTTPUrlWithOneSlash(String orig)
           
static String getUrlParentDir(String url)
          Find and return the parent directory of the URL argument
static String getURLPath(String url)
          Attempt to extract the path component of a url String argument.
static boolean isAuthority(String authString)
          Tests if the String argument looks like it could be a legitimate authority fragment of a URL, that is, is it an IP address, or, are the characters legal in an authority, and does the string end with a legal TLD.
static String resolveUrl(String baseUrl, String url)
          Resolve a possibly relative url argument against a base URL.
static int schemeToDefaultPort(String scheme)
          Return the default port for the scheme String argument, if known.
static String stripDefaultPortFromUrl(String url)
          Attempt to strip default ports out of URL strings.
static String stripURLScheme(String url)
          Attempt to extract the path component of a url String argument.
static String urlToHost(String url)
          Attempt to extract the hostname component of an absolute URL argument.
static String urlToScheme(String url)
          Attempt to find the scheme (http://, https://, etc) from a given URL.
static String urlToUserInfo(String url)
          Extract userinfo from the absolute URL argument, that is, "username@", or "username:password@" if present.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DNS_SCHEME

public static final String DNS_SCHEME
ARC/WARC specific DNS resolution record.

See Also:
Constant Field Values

HTTP_SCHEME

public static final String HTTP_SCHEME
HTTP

See Also:
Constant Field Values

HTTPS_SCHEME

public static final String HTTPS_SCHEME
HTTPS

See Also:
Constant Field Values

FTP_SCHEME

public static final String FTP_SCHEME
FTP

See Also:
Constant Field Values

MMS_SCHEME

public static final String MMS_SCHEME
MMS

See Also:
Constant Field Values

RTSP_SCHEME

public static final String RTSP_SCHEME
RTSP

See Also:
Constant Field Values

DEFAULT_SCHEME

public static final String DEFAULT_SCHEME
Default scheme to assume if unspecified. No context implied...

See Also:
Constant Field Values

WAIS_SCHEME

public static final String WAIS_SCHEME
go brewster

See Also:
Constant Field Values

ALL_SCHEMES

public static final String[] ALL_SCHEMES
array of static Strings for all "known" schemes


PORT_SEPARATOR

public static final char PORT_SEPARATOR
character separating host from port within a URL authority

See Also:
Constant Field Values

PATH_START

public static final char PATH_START
character which delimits the path from the authority in a... in some URLs.

See Also:
Constant Field Values
Constructor Detail

UrlOperations

public UrlOperations()
Method Detail

isAuthority

public static boolean isAuthority(String authString)
Tests if the String argument looks like it could be a legitimate authority fragment of a URL, that is, is it an IP address, or, are the characters legal in an authority, and does the string end with a legal TLD.

Parameters:
authString - String representation of a fragment of a URL
Returns:
boolean indicating whether urlPart might be an Authority.

resolveUrl

public static String resolveUrl(String baseUrl,
                                String url)
Resolve a possibly relative url argument against a base URL.

Parameters:
baseUrl - the base URL against which the url should be resolved
url - the URL, possibly relative, to make absolute.
Returns:
url resolved against baseUrl, unless it is absolute already, and further transformed by whatever escaping normally takes place with a UURI.

urlToScheme

public static String urlToScheme(String url)
Attempt to find the scheme (http://, https://, etc) from a given URL.

Parameters:
url - URL String to parse for a scheme.
Returns:
the scheme, including trailing "://" if known, null otherwise.

schemeToDefaultPort

public static int schemeToDefaultPort(String scheme)
Return the default port for the scheme String argument, if known.

Parameters:
scheme - String scheme, including '://', as in, "http://", "ftp://"
Returns:
the default port for the scheme, or -1 if the scheme isn't known.

getURLPath

public static String getURLPath(String url)
Attempt to extract the path component of a url String argument.

Parameters:
url - the URL which may contain a path, sans scheme.
Returns:
the path component of the URL, or "" if it contains no path.

stripURLScheme

public static String stripURLScheme(String url)
Attempt to extract the path component of a url String argument.

Parameters:
url - the URL which may contain a path, sans scheme.
Returns:
the path component of the URL, or "" if it contains no path.

stripDefaultPortFromUrl

public static String stripDefaultPortFromUrl(String url)
Attempt to strip default ports out of URL strings.

Parameters:
url - the original URL possibly including a port
Returns:
the URL sans port, if the scheme was recognized and the default port was supplied, otherwise, the original URL.

fixupHTTPUrlWithOneSlash

public static String fixupHTTPUrlWithOneSlash(String orig)
Parameters:
orig - String containing a URL, possibly beginning with "http:/".
Returns:
original string if orig begins with "http://", or a new String with the extra slash, if orig only had one slash.

urlToHost

public static String urlToHost(String url)
Attempt to extract the hostname component of an absolute URL argument.

Parameters:
url - the url String from which to extract the hostname
Returns:
the hostname within the URL, or the url argument if the host cannot be found.

urlToUserInfo

public static String urlToUserInfo(String url)
Extract userinfo from the absolute URL argument, that is, "username@", or "username:password@" if present.

Parameters:
url - the URL from which to extract the userinfo
Returns:
the userinfo found, not including the "@", or null if no userinfo is found

getUrlParentDir

public static String getUrlParentDir(String url)
Find and return the parent directory of the URL argument

Parameters:
url - to find the parent directory of
Returns:
parent directory of URL, or null, if either the url argument is invalid, or if the url is the root of the authority.


Copyright © 2013. All Rights Reserved.