Package com.zfabrik.util.net
Class ParsedURL
java.lang.Object
com.zfabrik.util.net.ParsedURL
URI is a convenience class for manipulation of URLs based on the W3C RFC 2396
(see the World Wide Web Consortium pages).
In general a URI consists of the parts
- scheme, e.g. http, https, ftp,...etc
- user info
- host
- port
- path
- query
- fragment
- <scheme>:/<path>#<fragment>
- <scheme>://<user info>@<host>/<path>
- <scheme>://<user info>@<host>:<port>?<query>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addParameter(String name, String value)
Adds a parameter with value to the query part.Gets the scheme of the current URI.getHost()
Gets the Host of the current URI.Gets all parameters of the query part.getParameterValue(String name)
Gets the lone value assigned to a parameter from the query part.String[]
getParameterValues(String name)
Gets all values assigned to a parameter from the query part.getPath()
Gets the path of the current URI.getPort()
Gets the port of the current URI.getQuery()
Gets the query String.Gets the scheme of the current URI.Gets the UserInfo of the current URI.boolean
Gets wether this URI is absolute.protected void
parse a given URI.void
removeParameter(String name)
Removes the specified parameter from the query part.void
removeParameter(String name, String value)
Removes the specified name-value pair from the query part.void
Removes all parameters from the query part.void
setFragment(String fragment)
Sets the fragment of the URIvoid
Sets the Host of the URIvoid
setParameter(String name, String value)
Sets a parameter with value to the query part removing all previous valuesvoid
Sets the path of the URIvoid
Sets the port of the URIvoid
Sets the scheme of the URI, e.g.void
Sets the URI handled by this instance.void
setUserInfo(String userInfo)
Sets the User-info of the URItoRegEx()
constructs a regular expression that matches all valid url that would result into the same properties for all properties that are currently set - up to the last piece that has been set.toString()
toString(boolean absolute)
Gets a string representation of the URI.
-
Constructor Details
-
ParsedURL
public ParsedURL()Constructor. -
ParsedURL
Constructor with initial URL.- Parameters:
uri
- The URI to hanlde.
-
ParsedURL
Constructor with initial URL.- Parameters:
uri
- The URI to hanlde.
-
-
Method Details
-
setURI
Sets the URI handled by this instance.- Parameters:
uri
-
-
parse
parse a given URI. We try to parse a wide variety of not necessarily "correct" URIs.- Parameters:
uri
-
-
setScheme
Sets the scheme of the URI, e.g. http, https, file, ftp, ...etc.- Parameters:
scheme
-
-
getScheme
Gets the scheme of the current URI. -
isAbsolute
public boolean isAbsolute()Gets wether this URI is absolute. -
setFragment
Sets the fragment of the URI- Parameters:
fragment
-
-
getFragment
Gets the scheme of the current URI. -
setUserInfo
Sets the User-info of the URI- Parameters:
userInfo
-
-
getUserInfo
Gets the UserInfo of the current URI. -
setHost
Sets the Host of the URI- Parameters:
host
-
-
getHost
Gets the Host of the current URI. -
setPort
Sets the port of the URI- Parameters:
port
-
-
getPort
Gets the port of the current URI. -
setPath
Sets the path of the URI- Parameters:
path
-
-
getPath
Gets the path of the current URI. -
removeParameters
public void removeParameters()Removes all parameters from the query part. -
removeParameter
Removes the specified parameter from the query part.- Parameters:
name
- the name of the parameter to be removed
-
removeParameter
Removes the specified name-value pair from the query part.- Parameters:
name
- the name of the parameter to be removedvalue
-
-
addParameter
Adds a parameter with value to the query part.- Parameters:
name
- the name of the parameter to add.value
- the value of the parameter to add.
-
setParameter
Sets a parameter with value to the query part removing all previous values- Parameters:
name
- the name of the parameter to add.value
- the value of the parameter to add.
-
getParameterValues
Gets all values assigned to a parameter from the query part.- Parameters:
name
- the name of the parameter to get the values of.- Returns:
- a String Array containing all the values of the specified parameter.
-
getParameterValue
Gets the lone value assigned to a parameter from the query part. If the parameter is multi-valued, the result can be any of the values.- Parameters:
name
- the name of the parameter to get the values of.- Returns:
- a String containing one value of the specified parameter.
-
getParametersSet
Gets all parameters of the query part. -
getQuery
Gets the query String.- Returns:
- String representation of the query part of the URI
-
toRegEx
constructs a regular expression that matches all valid url that would result into the same properties for all properties that are currently set - up to the last piece that has been set. The address part of the URL vs. the resource path of the URL requires special handling. If there is no property relating to the address part, it will be completely omitted from the URL. So, if you have a URL with a host specified, all urls for that the host will be matched. If you only have a path, no host must be set and the regex stops at that path. If you have host and path, host must be set, scheme doesn't matter, path must be present, regex stops at path... and so on.- Returns:
-
toString
Gets a string representation of the URI.- Parameters:
absolute
- iftrue
the URI will be returned as absolute URL including protocol, host and port. If set tofalse
only the path will be taken into account- Returns:
- the URI as a String.
-
toString
- Overrides:
toString
in classObject
- See Also:
Object.toString()
-