public final class URL
extends java.lang.Object
implements java.io.Serializable
URL is designed to provide public APIs for parsing
and synthesizing Uniform Resource Locators as similar as possible to the
APIs of java.net.URL
, but without the ability to open a
stream or connection. One of the consequences of this is that you can
construct URLs for protocols for which a URLStreamHandler is not
available (such as an "https" URL when JSSE is not installed).
WARNING - This class assumes that the string
representation of a URL conforms to the spec
argument
as described in RFC 2396 "Uniform Resource Identifiers: Generic Syntax":
<scheme>//<authority><path>?<query>#<fragment>
FIXME - This class really ought to end up in a Commons package someplace.
Constructor and Description |
---|
URL(java.lang.String spec)
Create a URL object from the specified String representation.
|
URL(java.lang.String protocol,
java.lang.String host,
int port,
java.lang.String file)
Deprecated.
Unused. Will be removed in Tomcat 8.0.x
|
URL(java.lang.String protocol,
java.lang.String host,
java.lang.String file)
Deprecated.
Unused. Will be removed in Tomcat 8.0.x
|
URL(URL context,
java.lang.String spec)
Create a URL object by parsing a string representation relative
to a specified context.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj)
Compare two URLs for equality.
|
java.lang.String |
getAuthority()
Return the authority part of the URL.
|
java.lang.String |
getFile()
Return the filename part of the URL.
|
java.lang.String |
getHost()
Return the host name part of the URL.
|
java.lang.String |
getPath()
Return the path part of the URL.
|
int |
getPort()
Return the port number part of the URL.
|
java.lang.String |
getProtocol()
Return the protocol name part of the URL.
|
java.lang.String |
getQuery()
Return the query part of the URL.
|
java.lang.String |
getRef()
Return the reference part of the URL.
|
java.lang.String |
getUserInfo()
Return the user info part of the URL.
|
int |
hashCode() |
static boolean |
isSchemeChar(char c)
Determine if the character is allowed in the scheme of a URI.
|
void |
normalize()
Normalize the
path (and therefore file )
portions of this URL. |
boolean |
sameFile(URL other)
Compare two URLs, excluding the "ref" fields.
|
java.lang.String |
toExternalForm()
Deprecated.
Unused. Will be removed in Tomcat 8.0.x
|
java.lang.String |
toString()
Return a string representation of this object.
|
public URL(java.lang.String spec) throws java.net.MalformedURLException
spec
- String representation of the URLjava.net.MalformedURLException
- if the string representation
cannot be parsed successfullypublic URL(URL context, java.lang.String spec) throws java.net.MalformedURLException
java.net.URL
.context
- URL against which the relative representation
is resolvedspec
- String representation of the URL (usually relative)java.net.MalformedURLException
- if the string representation
cannot be parsed successfully@Deprecated public URL(java.lang.String protocol, java.lang.String host, java.lang.String file) throws java.net.MalformedURLException
protocol
- Name of the protocol to usehost
- Name of the host addressed by this protocolfile
- Filename on the specified hostjava.net.MalformedURLException
- is never thrown, but present for
compatible APIs@Deprecated public URL(java.lang.String protocol, java.lang.String host, int port, java.lang.String file) throws java.net.MalformedURLException
java.net.URL
.protocol
- Name of the protocol to usehost
- Name of the host addressed by this protocolport
- Port number, or -1 for the default port for this protocolfile
- Filename on the specified hostjava.net.MalformedURLException
- is never thrown, but present for
compatible APIspublic boolean equals(java.lang.Object obj)
true
if and
only if the argument is not null, and is a URL
object
that represents the same URL
as this object. Two
URLs
are equal if they have the same protocol and
reference the same host, the same port number on the host,
and the same file and anchor on the host.equals
in class java.lang.Object
obj
- The URL to compare againstpublic int hashCode()
hashCode
in class java.lang.Object
public java.lang.String getAuthority()
public java.lang.String getFile()
java.net.URL
, this value includes
the query string if there was one. For just the path portion,
call getPath()
instead.public java.lang.String getHost()
public java.lang.String getPath()
public int getPort()
public java.lang.String getProtocol()
public java.lang.String getQuery()
public java.lang.String getRef()
public java.lang.String getUserInfo()
public void normalize() throws java.net.MalformedURLException
path
(and therefore file
)
portions of this URL.
NOTE - This method is not part of the public API
of java.net.URL
, but is provided as a value added
service of this implementation.
java.net.MalformedURLException
- if a normalization error occurs,
such as trying to move about the hierarchical rootpublic boolean sameFile(URL other)
true
if this URL
and the other
argument both refer
to the same resource. The two URLs
might not both contain
the same anchor.@Deprecated public java.lang.String toExternalForm()
public java.lang.String toString()
toString
in class java.lang.Object
public static boolean isSchemeChar(char c)
Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.