public class UniformResourceLocator
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
protected static CollectionUtil |
CU |
protected static int |
DEFAULT_PORT |
protected static java.lang.String |
DEFAULT_SCHEME |
static int |
HTTP_DEFAULT_PORT |
static java.lang.String |
HTTP_SCHEME_PREFIX
"http://"
|
static int |
HTTPS_DEFAULT_PORT |
static java.lang.String |
HTTPS_SCHEME_PREFIX
"https://"
|
protected static NetUtil |
NU |
static java.lang.String |
SCHEME_HOST_SEPARATOR
"://"
|
static java.lang.String |
SCHEME_HTTP |
static java.lang.String |
SCHEME_HTTPS |
static java.lang.String |
SLASH
The character '/' that is used to separate naming elements of the URL
|
protected static StringUtil |
SU |
static java.lang.String |
URL_PARAM_ASSIGN
The character '=' that is used to separate name and value of query parameters
|
static java.lang.String |
URL_PARAM_SEPARATOR
The character '&' that is used to separate consecutive query parameters from each other
|
static java.lang.String |
URL_PORT_SEPARATOR
The character ':' that is used to separate hostname from the port
|
static java.lang.String |
URL_QUERY_SEPARATOR
The character '?' that is used to separate the query parameters from the URL
|
Constructor and Description |
---|
UniformResourceLocator()
Initialize the new instance with default values.
|
UniformResourceLocator(java.lang.String url)
Initialize the new instance with the given URL
|
UniformResourceLocator(java.lang.String scheme,
java.lang.String serverName,
int port,
java.lang.String requestURI,
java.lang.String... queryParams)
Initialize the new instance with the various parts of a URL.
|
UniformResourceLocator(java.lang.String scheme,
java.lang.String serverName,
java.lang.String requestURI,
java.lang.String... queryParams)
Initialize the new instance with the various parts of a URL.
|
Modifier and Type | Method and Description |
---|---|
void |
appendPath(java.lang.String path)
Appends the given path to the end of the current requestURI.
|
protected void |
appendServerNameAndPort(java.lang.StringBuffer buffer) |
protected void |
checkIfValidURL(java.lang.String urlStr) |
void |
clearParameters()
Remove all query parameters from this URL.
|
UniformResourceLocator |
copy()
Creates a copy of this object.
|
protected NamedTextList |
copyParameters() |
static int |
getDefaultPortForScheme(java.lang.String scheme)
Returns the default port for scheme HTTP (80) or HTTPS (443).
|
int |
getNumberOfParameters()
Returns the number of query parameters
|
java.lang.String |
getParameter(java.lang.String name)
Returns the value of the parameter with the given name or null.
|
java.util.Enumeration<java.lang.String> |
getParameterNames()
Returns the names of all parameters
|
protected NamedTextList |
getParameters() |
int |
getPort()
Return the defined port.
|
java.lang.String |
getQueryString()
Returns the query string, that is everything following the '?'.
|
java.lang.String |
getRequestURI()
Returns the request URI
|
java.lang.String |
getScheme() |
java.lang.String |
getServerName()
Return the server name
|
java.lang.String |
getServerNameAndPort()
Returns a string containing the server name and optionally the port number,
separated by a colon (':').
|
boolean |
hasQueryParameter()
Returns true if this URL contains at least one query parameter
|
boolean |
isAbsolute()
Returns true if this is an absolute URL
|
boolean |
isDefaultPort()
Returns true, if the port is not explicitly set which means the default
port has to be used.
|
boolean |
isRelative()
Returns true if this is a relative URL
|
protected boolean |
isRelativeToHost(java.lang.String urlStr) |
protected UniformResourceLocator |
newInstance() |
protected void |
parseQueryString(java.lang.String queryString) |
protected void |
parseURL(java.lang.String urlStr) |
protected int |
port() |
protected void |
port(int newValue) |
void |
removeParameter(java.lang.String name)
Remove the parameter with the given named from the list of query parameters.
|
protected java.lang.String |
requestURI() |
protected void |
requestURI(java.lang.String newValue) |
protected java.lang.String |
scheme() |
protected void |
scheme(java.lang.String newValue) |
protected java.lang.String |
serverName() |
protected void |
serverName(java.lang.String newValue) |
void |
setFilename(java.lang.String filename)
Sets the given filename to the end of the requestURI.
|
void |
setParameter(java.lang.String name,
java.lang.String value) |
protected void |
setParameters(NamedTextList newValue) |
void |
setPathRelative(java.lang.String path)
Sets the given path relative to the current requestURI.
|
void |
setPort(int newValue)
Set the port of the URL
|
void |
setQueryString(java.lang.String query) |
void |
setRequestURI(java.lang.String uri) |
void |
setScheme(java.lang.String scheme) |
void |
setServerName(java.lang.String name) |
java.lang.String |
toString()
Returns the full URL including parameters as its string representation
|
java.net.URI |
toURI() |
java.net.URL |
toURL() |
protected static final StringUtil SU
protected static final CollectionUtil CU
protected static final NetUtil NU
public static final java.lang.String SCHEME_HTTP
public static final java.lang.String SCHEME_HTTPS
public static final int HTTP_DEFAULT_PORT
public static final int HTTPS_DEFAULT_PORT
protected static final int DEFAULT_PORT
protected static final java.lang.String DEFAULT_SCHEME
public static final java.lang.String SCHEME_HOST_SEPARATOR
public static final java.lang.String HTTP_SCHEME_PREFIX
public static final java.lang.String HTTPS_SCHEME_PREFIX
public static final java.lang.String URL_QUERY_SEPARATOR
public static final java.lang.String URL_PARAM_SEPARATOR
public static final java.lang.String URL_PARAM_ASSIGN
public static final java.lang.String URL_PORT_SEPARATOR
public static final java.lang.String SLASH
public UniformResourceLocator(java.lang.String url) throws java.net.MalformedURLException
java.net.MalformedURLException
public UniformResourceLocator()
public UniformResourceLocator(java.lang.String scheme, java.lang.String serverName, int port, java.lang.String requestURI, java.lang.String... queryParams)
public UniformResourceLocator(java.lang.String scheme, java.lang.String serverName, java.lang.String requestURI, java.lang.String... queryParams)
protected NamedTextList getParameters()
protected void setParameters(NamedTextList newValue)
protected java.lang.String serverName()
protected void serverName(java.lang.String newValue)
protected java.lang.String requestURI()
protected void requestURI(java.lang.String newValue)
protected java.lang.String scheme()
protected void scheme(java.lang.String newValue)
protected int port()
protected void port(int newValue)
public static int getDefaultPortForScheme(java.lang.String scheme)
scheme
- The case-insensitive scheme name (must not be null).public boolean hasQueryParameter()
public java.lang.String getQueryString()
public void setQueryString(java.lang.String query)
public java.lang.String getServerName()
public void setServerName(java.lang.String name)
public int getPort()
public void setPort(int newValue)
public java.lang.String getRequestURI()
public void setRequestURI(java.lang.String uri)
public void setFilename(java.lang.String filename)
public void setPathRelative(java.lang.String path)
path
- The path to be set relative to the current path (may be null).public void appendPath(java.lang.String path)
path
- The path to be appended (may be null).public java.lang.String getScheme()
public void setScheme(java.lang.String scheme)
public java.util.Enumeration<java.lang.String> getParameterNames()
public int getNumberOfParameters()
public java.lang.String getParameter(java.lang.String name)
public void setParameter(java.lang.String name, java.lang.String value)
public void removeParameter(java.lang.String name)
public void clearParameters()
public boolean isDefaultPort()
public java.lang.String getServerNameAndPort()
public UniformResourceLocator copy()
public boolean isRelative()
public boolean isAbsolute()
public java.lang.String toString()
toString
in class java.lang.Object
public java.net.URL toURL()
public java.net.URI toURI()
protected void parseURL(java.lang.String urlStr) throws java.net.MalformedURLException
java.net.MalformedURLException
protected void parseQueryString(java.lang.String queryString)
protected void appendServerNameAndPort(java.lang.StringBuffer buffer)
protected NamedTextList copyParameters()
protected boolean isRelativeToHost(java.lang.String urlStr)
protected void checkIfValidURL(java.lang.String urlStr) throws java.net.MalformedURLException
java.net.MalformedURLException
protected UniformResourceLocator newInstance()