public class URLParser
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String[] |
ALL_SCHEMES
array of static Strings for all "known" schemes
|
static java.util.regex.Pattern |
ALL_SCHEMES_PATTERN |
static char |
COLON |
static java.lang.String |
COMMERCIAL_AT |
static java.lang.String |
DEFAULT_SCHEME
Default scheme to assume if unspecified.
|
static java.lang.String |
DNS_SCHEME
ARC/WARC specific DNS resolution record.
|
static java.lang.String |
FILEDESC_SCHEME
ARC header record.
|
static java.lang.String |
FTP_SCHEME
FTP
|
static java.lang.String |
HTTP_SCHEME
HTTP
|
static java.lang.String |
HTTPS_SCHEME
HTTPS
|
static java.lang.String |
MMS_SCHEME
MMS
|
static char |
PERCENT_SIGN |
static java.util.regex.Pattern |
RFC2396REGEX
RFC 2396-inspired regex.
|
static java.lang.String |
RTSP_SCHEME
RTSP
|
static java.lang.String |
STRAY_SPACING |
static java.lang.String |
WAIS_SCHEME
go brewster
|
static java.lang.String |
WARCINFO_SCHEME
WARC header record.
|
| Constructor and Description |
|---|
URLParser() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
addDefaultSchemeIfNeeded(java.lang.String urlString) |
static HandyURL |
parse(java.lang.String urlString) |
static java.lang.String |
urlToScheme(java.lang.String url)
Attempt to find the scheme (http://, https://, etc) from a given URL.
|
public static final java.util.regex.Pattern RFC2396REGEX
URI Generic Syntax August 1998 B. Parsing a URI Reference with a Regular Expression As described in Section 4.3, the generic URI syntax is not sufficient to disambiguate the components of some forms of URI. Since the "greedy algorithm" described in that section is identical to the disambiguation method used by POSIX regular expressions, it is natural and commonplace to use a regular expression for parsing the potential four components and fragment identifier of a URI reference. The following line is the regular expression for breaking-down a URI reference into its components. ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? 12 3 4 5 6 7 8 9 The numbers in the second line above are only to assist readability; they indicate the reference points for each subexpression (i.e., each paired parenthesis). We refer to the value matched for subexpression--as $ . For example, matching the above expression to http://www.ics.uci.edu/pub/ietf/uri/#Related results in the following subexpression matches: $1 = http: $2 = http $3 = //www.ics.uci.edu $4 = www.ics.uci.edu $5 = /pub/ietf/uri/ $6 = $7 = $8 = #Related $9 = Related where indicates that the component is not present, as is the case for the query component in the above example. Therefore, we can determine the value of the four components and fragment as scheme = $2 authority = $4 path = $5 query = $7 fragment = $9
Below differs from the rfc regex in that... (1) it has java escaping of regex characters (2) we allow a URI made of a fragment only (Added extra group so indexing is off by one after scheme). (3) scheme is limited to legal scheme characters
public static final java.lang.String COMMERCIAL_AT
public static final char PERCENT_SIGN
public static final char COLON
public static final java.lang.String STRAY_SPACING
public static final java.lang.String DNS_SCHEME
public static final java.lang.String FILEDESC_SCHEME
public static final java.lang.String WARCINFO_SCHEME
public static final java.lang.String HTTP_SCHEME
public static final java.lang.String HTTPS_SCHEME
public static final java.lang.String FTP_SCHEME
public static final java.lang.String MMS_SCHEME
public static final java.lang.String RTSP_SCHEME
public static final java.lang.String DEFAULT_SCHEME
public static final java.lang.String WAIS_SCHEME
public static final java.lang.String[] ALL_SCHEMES
public static final java.util.regex.Pattern ALL_SCHEMES_PATTERN
public static java.lang.String urlToScheme(java.lang.String url)
url - URL String to parse for a scheme.public static java.lang.String addDefaultSchemeIfNeeded(java.lang.String urlString)
public static HandyURL parse(java.lang.String urlString) throws java.net.URISyntaxException
java.net.URISyntaxExceptionCopyright © 2019 The International Internet Preservation Consortium. All Rights Reserved.