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 |
---|---|
protected void |
addAllQueryParameterDefinitions(java.lang.String[] queryParams) |
UniformResourceLocator |
addToParameter(IStringRepresentation name,
IStringRepresentation... values)
Adds the given value to the parameter with the specified name.
|
UniformResourceLocator |
addToParameter(IStringRepresentation name,
java.lang.String... values)
Adds the given value to the parameter with the specified name.
|
UniformResourceLocator |
addToParameter(java.lang.String name,
java.lang.String... values)
Adds the given value to the parameter with the specified name.
|
protected void |
addValuesToParameter(NamedValue<java.util.List<java.lang.String>> param,
java.lang.String... values) |
UniformResourceLocator |
appendPath(java.lang.String path)
Appends the given path to the end of the current requestURI.
|
protected void |
appendServerNameAndPort(java.lang.StringBuffer buffer) |
java.lang.String |
asString()
Returns the full URL including parameters as string representation.
|
protected void |
checkIfValidURL(java.lang.String urlStr) |
UniformResourceLocator |
clearParameters()
Remove all query parameters from this URL.
|
UniformResourceLocator |
copy()
Creates a copy of this object.
|
protected NamedValue<java.util.List<java.lang.String>>[] |
copyParameters() |
static UniformResourceLocator |
create()
Creates a new instance.
|
static UniformResourceLocator |
create(java.lang.String url)
Creates a new instance on the given URL string.
|
static UniformResourceLocator |
create(java.net.URI uri)
Creates a new instance on the given URI.
|
static UniformResourceLocator |
create(java.net.URL url)
Creates a new instance on the given URL.
|
protected NamedValue<java.util.List<java.lang.String>> |
createParameter(java.lang.String name) |
protected NamedValue<java.util.List<java.lang.String>> |
createParameterObject(java.lang.String name) |
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
|
protected NamedValue<java.util.List<java.lang.String>> |
getOrCreateParameter(java.lang.String name) |
java.lang.String |
getParameter(IStringRepresentation name)
Returns the (first) value of the parameter with the given name or null.
|
java.lang.String |
getParameter(java.lang.String name)
Returns the (first) value of the parameter with the given name or null.
|
java.util.Enumeration<java.lang.String> |
getParameterNames()
Returns the names of all query parameters as Enumeration.
|
protected NamedValueList<java.util.List<java.lang.String>> |
getParameters() |
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getParametersMap()
Returns all query parameters or this URL in a map.
|
java.util.List<java.lang.String> |
getParameterValues(IStringRepresentation name)
Returns the values of the parameter with the given name or null
if the parameter is not present.
|
java.util.List<java.lang.String> |
getParameterValues(java.lang.String name)
Returns the values of the parameter with the given name or null
if the parameter is not present.
|
int |
getPort()
Return the defined port.
|
java.util.List<java.lang.String> |
getQueryParameterNames()
Returns the names of all query parameters as List.
|
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 (':').
|
protected void |
handleException(java.lang.Exception ex) |
boolean |
hasQueryParameter()
Returns true if this URL contains at least one query parameter
|
boolean |
hasQueryParameter(IStringRepresentation name)
Returns true if this URL contains the query parameter with the given name.
|
boolean |
hasQueryParameter(java.lang.String name)
Returns true if this URL contains the query parameter with the given name.
|
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) |
UniformResourceLocator |
removeParameter(IStringRepresentation name)
Remove the parameter with the given named from the list of query parameters.
|
UniformResourceLocator |
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) |
UniformResourceLocator |
setFilename(java.lang.String filename)
Sets the given filename to the end of the requestURI.
|
UniformResourceLocator |
setParameter(IStringRepresentation name,
IStringRepresentation... values)
Sets the parameter with the given name to the specified value.
|
UniformResourceLocator |
setParameter(IStringRepresentation name,
java.lang.String... values)
Sets the parameter with the given name to the specified value.
|
UniformResourceLocator |
setParameter(java.lang.String name,
java.lang.String... values)
Sets the parameter with the given name to the specified value.
|
UniformResourceLocator |
setPathRelative(java.lang.String path)
Sets the given path relative to the current requestURI.
|
UniformResourceLocator |
setPort(int newValue)
Set the port of the URL
|
UniformResourceLocator |
setQueryString(java.lang.String query) |
UniformResourceLocator |
setRequestURI(java.lang.String uri) |
UniformResourceLocator |
setScheme(java.lang.String scheme) |
UniformResourceLocator |
setServerName(java.lang.String name) |
java.lang.String |
toString()
Returns the full URL including parameters as 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)
public static int getDefaultPortForScheme(java.lang.String scheme)
scheme
- The case-insensitive scheme name (must not be null).public static UniformResourceLocator create()
public static UniformResourceLocator create(java.lang.String url)
url
- The URL string (must not be null).InvalidUrlException
- if the given string is not a valid URL.public static UniformResourceLocator create(java.net.URL url)
url
- The URL (must not be null).public static UniformResourceLocator create(java.net.URI uri)
uri
- The URI (must not be null).public boolean hasQueryParameter()
public boolean hasQueryParameter(java.lang.String name)
public boolean hasQueryParameter(IStringRepresentation name)
public java.lang.String getQueryString()
public UniformResourceLocator setQueryString(java.lang.String query)
public java.lang.String getServerName()
public UniformResourceLocator setServerName(java.lang.String name)
public int getPort()
public UniformResourceLocator setPort(int newValue)
public java.lang.String getRequestURI()
public UniformResourceLocator setRequestURI(java.lang.String uri)
public UniformResourceLocator setFilename(java.lang.String filename)
public UniformResourceLocator setPathRelative(java.lang.String path)
path
- The path to be set relative to the current path (may be null).public UniformResourceLocator appendPath(java.lang.String path)
path
- The path to be appended (may be null).public java.lang.String getScheme()
public UniformResourceLocator setScheme(java.lang.String scheme)
public java.util.Enumeration<java.lang.String> getParameterNames()
public java.util.List<java.lang.String> getQueryParameterNames()
public int getNumberOfParameters()
public java.lang.String getParameter(IStringRepresentation name)
public java.lang.String getParameter(java.lang.String name)
public java.util.List<java.lang.String> getParameterValues(IStringRepresentation name)
public java.util.List<java.lang.String> getParameterValues(java.lang.String name)
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getParametersMap()
public UniformResourceLocator setParameter(IStringRepresentation name, java.lang.String... values)
public UniformResourceLocator setParameter(IStringRepresentation name, IStringRepresentation... values)
public UniformResourceLocator setParameter(java.lang.String name, java.lang.String... values)
public UniformResourceLocator addToParameter(IStringRepresentation name, java.lang.String... values)
public UniformResourceLocator addToParameter(IStringRepresentation name, IStringRepresentation... values)
public UniformResourceLocator addToParameter(java.lang.String name, java.lang.String... values)
public UniformResourceLocator removeParameter(IStringRepresentation name)
public UniformResourceLocator removeParameter(java.lang.String name)
public UniformResourceLocator 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.lang.String asString()
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 addValuesToParameter(NamedValue<java.util.List<java.lang.String>> param, java.lang.String... values)
protected void parseQueryString(java.lang.String queryString)
protected void appendServerNameAndPort(java.lang.StringBuffer buffer)
protected NamedValue<java.util.List<java.lang.String>>[] copyParameters()
protected boolean isRelativeToHost(java.lang.String urlStr)
protected void checkIfValidURL(java.lang.String urlStr) throws java.net.MalformedURLException
java.net.MalformedURLException
protected void addAllQueryParameterDefinitions(java.lang.String[] queryParams)
protected NamedValue<java.util.List<java.lang.String>> getOrCreateParameter(java.lang.String name)
protected NamedValue<java.util.List<java.lang.String>> createParameter(java.lang.String name)
protected NamedValue<java.util.List<java.lang.String>> createParameterObject(java.lang.String name)
protected UniformResourceLocator newInstance()
protected void handleException(java.lang.Exception ex)
protected NamedValueList<java.util.List<java.lang.String>> getParameters()
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)