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 StringasEntityEncodedString()Encode this URL to the percent-encoding format using the UTF-8 charset, and the replace ampersand characters with the&HTML character entity.StringasParamsEncodedString()Deprecated.UseasPercentEncodedString()instead.StringasPercentEncodedString()Convert this URL in its string representation with proper percent encoding using the UTF-8 charset.StringasString()Convert this URL in its string representation without percent encoding.StringasUrlEncodedString()Encode the complete URL to the percent-encoding format using the UTF-8 charset.StringasUrlEncodedString(String p_strCharset)Deprecated.UseasUrlEncodedString()instead.voidclearParams()Remove all querystring parameters.URLcloneUrl()StringgetAuthority()Get the authority.StringgetFragment()Get the URL's fragment.ObjectgetParam(String p_strParam)Get a querystring parameter.Map<String,Object>getParams()Get all query parameters.StringgetPath()Get the path.StringgetQueryAsPercentEncodedString()Convert this URL's query to its string representation with proper percent encoding using the UTF-8 charset.StringgetScheme()Get the scheme.booleanhasAuthority()Check if this URL has an authority.booleanhasFragment()Determine if this URL has a fragment.booleanhasParam(String p_strParam)Test if the URL has the specified querystring parameter.booleanhasParams()Check if this URL has a parameters.booleanhasPath()Check if this URL has a path component.booleanhasScheme()Check if this URL has a scheme.booleanisAbsolute()Check if this URL is absolute, i.e.voidmakeRelative()Make this URL relative by discarding its scheme and authority part.voidputParam(String p_strParam, Object p_value)Set a querystring parameter.voidremoveFragment()Remove the URL's fragment.booleanremoveParam(String p_strParam)Remove the specified querystring parameter.voidremoveScheme()Remove the scheme from this URL.voidsetAuthority(String p_strAuthority)Set the authority.voidsetFragment(String p_strFragment)Set the URL#s fragment.voidsetParams(Map<String,String> p_params)Set the querystring parameters that are contained in the given map.voidsetPath(String p_strPath)Set the path.voidsetScheme(String p_strScheme)Set the scheme, e.g.voidwriteEntityEncodedTo(Writer p_out)Write the URL to the specifiedjava.io.Writer, e.g.voidwriteTo(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:
trueif this URL has a scheme, orfalseotherwise.
-
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:
trueif this URL has an authority, orfalseotherwise.
-
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:
trueif this URL has a path component, orfalseotherwise.
-
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:
trueif this URL is absolute, orfalseotherwise.
-
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:
trueif this URL has one or more parameters, orfalseotherwise.
-
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
nullif 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:
trueif the URL has the specified, querystring parameter, orfalseotherwise.
-
removeParam
public boolean removeParam(String p_strParam)
Remove the specified querystring parameter.- Parameters:
p_strParam- The The querystring parameter.- Returns:
trueif the specified querystring parameter was was removed, orfalseif 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:
trueif the URL has a fragment, orfalseotherwise.
-
getFragment
public String getFragment()
Get the URL's fragment.- Returns:
- The URL's fragment, not including the leading sharp sign,
or
nullif 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.
-
-