Class URL
- java.lang.Object
-
- de.uplanet.lucy.server.util.URL
-
@Scriptable public final class URL extends Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description String
asEntityEncodedString()
Encode this URL to the percent-encoding format using the UTF-8 charset, and the replace ampersand characters with the&
HTML character entity.String
asParamsEncodedString()
Deprecated.UseasPercentEncodedString()
instead.String
asPercentEncodedString()
Convert this URL in its string representation with proper percent encoding using the UTF-8 charset.String
asString()
Convert this URL in its string representation without percent encoding.String
asUrlEncodedString()
Encode the complete URL to the percent-encoding format using the UTF-8 charset.String
asUrlEncodedString(String p_strCharset)
Deprecated.UseasUrlEncodedString()
instead.void
clearParams()
Remove all querystring parameters.URL
cloneUrl()
String
getAuthority()
Get the authority.String
getFragment()
Get the URL's fragment.Object
getParam(String p_strParam)
Get a querystring parameter.Map<String,Object>
getParams()
Get all query parameters.String
getPath()
Get the path.String
getQueryAsPercentEncodedString()
Convert this URL's query to its string representation with proper percent encoding using the UTF-8 charset.String
getScheme()
Get the scheme.boolean
hasAuthority()
Check if this URL has an authority.boolean
hasFragment()
Determine if this URL has a fragment.boolean
hasParam(String p_strParam)
Test if the URL has the specified querystring parameter.boolean
hasParams()
Check if this URL has a parameters.boolean
hasPath()
Check if this URL has a path component.boolean
hasScheme()
Check if this URL has a scheme.boolean
isAbsolute()
Check if this URL is absolute, i.e.void
makeRelative()
Make this URL relative by discarding its scheme and authority part.void
putParam(String p_strParam, Object p_value)
Set a querystring parameter.void
removeFragment()
Remove the URL's fragment.boolean
removeParam(String p_strParam)
Remove the specified querystring parameter.void
removeScheme()
Remove the scheme from this URL.void
setAuthority(String p_strAuthority)
Set the authority.void
setFragment(String p_strFragment)
Set the URL#s fragment.void
setParams(Map<String,String> p_params)
Set the querystring parameters that are contained in the given map.void
setPath(String p_strPath)
Set the path.void
setScheme(String p_strScheme)
Set the scheme, e.g.void
writeEntityEncodedTo(Writer p_out)
Write the URL to the specifiedjava.io.Writer
, e.g.void
writeTo(Writer p_out)
Write the string representation of this URL without percent encoding to the specifiedjava.io.Writer
, e.g.
-
-
-
Constructor Detail
-
URL
public URL(String p_strUrl) throws MalformedURLException
- Throws:
MalformedURLException
-
-
Method Detail
-
cloneUrl
public URL cloneUrl()
-
hasScheme
public boolean hasScheme()
Check if this URL has a scheme.- Returns:
true
if this URL has a scheme, orfalse
otherwise.
-
getScheme
public String getScheme()
Get the scheme.- Returns:
- The scheme.
-
setScheme
public void setScheme(String p_strScheme)
Set the scheme, e.g.https
.- Parameters:
p_strScheme
- The scheme.- Throws:
IllegalArgumentException
- If the given scheme isnull
, or does not conform to the syntax specified in RFC 3986, 3.1.- See Also:
removeScheme()
-
removeScheme
public void removeScheme()
Remove the scheme from this URL.This can be usefull to create schema-less URLs.
-
hasAuthority
public boolean hasAuthority()
Check if this URL has an authority.- Returns:
true
if this URL has an authority, orfalse
otherwise.
-
getAuthority
public String getAuthority()
Get the authority.- Returns:
- The authority.
-
setAuthority
public void setAuthority(String p_strAuthority)
Set the authority.- Parameters:
p_strAuthority
- The authority.- Throws:
IllegalArgumentException
- If the given authority isnull
.- See Also:
removeScheme()
-
hasPath
public boolean hasPath()
Check if this URL has a path component.- Returns:
true
if this URL has a path component, orfalse
otherwise.
-
getPath
public String getPath()
Get the path.- Returns:
- The path.
-
setPath
public void setPath(String p_strPath)
Set the path.- Parameters:
p_strPath
- The path.
-
isAbsolute
public boolean isAbsolute()
Check if this URL is absolute, i.e. if it has both a scheme and an authority.This method does not check for the presence of a fragment identifier. Also note that a schema-less URL is considered to be a relative URL.
- Returns:
true
if this URL is absolute, orfalse
otherwise.
-
makeRelative
public void makeRelative()
Make this URL relative by discarding its scheme and authority part.
-
hasParams
public boolean hasParams()
Check if this URL has a parameters.- Returns:
true
if this URL has one or more parameters, orfalse
otherwise.
-
putParam
public void putParam(String p_strParam, Object p_value)
Set a querystring parameter.Parameters that start with
rq_
will be hex-encoded unless they are in the list of unencoded querystring parameters. All other parameters are not hex-encoded.- Parameters:
p_strParam
- The name of the querystring parameter.p_value
- The value of the querystring parameter.
-
getParam
public Object getParam(String p_strParam)
Get a querystring parameter.- Parameters:
p_strParam
- The name of the querystring parameter.- Returns:
- The value of the given querystring parameter,
or
null
if it does not exist.
-
getParams
public Map<String,Object> getParams()
Get all query parameters.- Returns:
- The query parameters.
-
hasParam
public boolean hasParam(String p_strParam)
Test if the URL has the specified querystring parameter.- Parameters:
p_strParam
- The querystring parameter.- Returns:
true
if the URL has the specified, querystring parameter, orfalse
otherwise.
-
removeParam
public boolean removeParam(String p_strParam)
Remove the specified querystring parameter.- Parameters:
p_strParam
- The The querystring parameter.- Returns:
true
if the specified querystring parameter was was removed, orfalse
if the URL did not contain the specified querystring parameter.
-
setParams
public void setParams(Map<String,String> p_params)
Set the querystring parameters that are contained in the given map.- Parameters:
p_params
- The querystring parameters to set.
-
clearParams
public void clearParams()
Remove all querystring parameters.
-
hasFragment
public boolean hasFragment()
Determine if this URL has a fragment.- Returns:
true
if the URL has a fragment, orfalse
otherwise.
-
getFragment
public String getFragment()
Get the URL's fragment.- Returns:
- The URL's fragment, not including the leading sharp sign,
or
null
if the URL has no fragment.
-
setFragment
public void setFragment(String p_strFragment)
Set the URL#s fragment.- Parameters:
p_strFragment
- The URL#s fragment.
-
removeFragment
public void removeFragment()
Remove the URL's fragment.
-
writeTo
public void writeTo(Writer p_out) throws IOException
Write the string representation of this URL without percent encoding to the specifiedjava.io.Writer
, e.g.$Response
.This method is mainly used to display human-readable URLs.
- Parameters:
p_out
- The output stream.- Throws:
IOException
- If an I/O error occurred or the character encoding could not be determined.- See Also:
asString()
-
asString
public String asString()
Convert this URL in its string representation without percent encoding.This method is mainly used to display human-readable URLs.
- Returns:
- The URL as a string.
-
asPercentEncodedString
public String asPercentEncodedString()
Convert this URL in its string representation with proper percent encoding using the UTF-8 charset.The resulting string will contain ASCII characters only.
- Returns:
- The percent-encoded URL.
-
asParamsEncodedString
@Deprecated public String asParamsEncodedString()
Deprecated.UseasPercentEncodedString()
instead.Same asasPercentEncodedString()
.- See Also:
asPercentEncodedString()
-
writeEntityEncodedTo
public void writeEntityEncodedTo(Writer p_out) throws IOException
Write the URL to the specifiedjava.io.Writer
, e.g.$Response
.- Parameters:
p_out
- The output stream.- Throws:
IOException
- If an I/O error occurred or the character encoding could not be determined.- See Also:
asEntityEncodedString()
-
asEntityEncodedString
public String asEntityEncodedString()
Encode this URL to the percent-encoding format using the UTF-8 charset, and the replace ampersand characters with the&
HTML character entity.- Returns:
- The percent- and entity-encoded URL.
-
asUrlEncodedString
public String asUrlEncodedString()
Encode the complete URL to the percent-encoding format using the UTF-8 charset.- Returns:
- The URL-encoded string.
-
asUrlEncodedString
@Deprecated public String asUrlEncodedString(String p_strCharset)
Deprecated.UseasUrlEncodedString()
instead.Encode the complete URL to the percent-encoding format using the UTF-8 charset.Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilites. So we ignore the charset parameter.
- Parameters:
p_strCharset
- Unused.- Returns:
- The URL-encoded string.
-
getQueryAsPercentEncodedString
public String getQueryAsPercentEncodedString()
Convert this URL's query to its string representation with proper percent encoding using the UTF-8 charset.The returned string does not start with the question mark delimiter.
The resulting string will contain ASCII characters only.
- Returns:
- The percent-encoded query string.
-
-