|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.gargoylesoftware.htmlunit.util.UrlUtils
public final class UrlUtils
URL utilities class that makes it easy to create new URLs based off of old URLs without having to assemble or parse them yourself.
Method Summary | |
---|---|
static String |
decode(String escaped)
Unescapes and decodes the specified string. |
static String |
encodeAnchor(String anchor)
Encodes and escapes the specified URI anchor string. |
static URL |
encodeUrl(URL url,
boolean minimalQueryEncoding)
Encodes illegal characters in the specified URL's path, query string and anchor according to the URL encoding rules observed in real browsers. |
static URL |
getUrlWithNewHost(URL u,
String newHost)
Creates and returns a new URL identical to the specified URL, except using the specified host. |
static URL |
getUrlWithNewPath(URL u,
String newPath)
Creates and returns a new URL identical to the specified URL, except using the specified path. |
static URL |
getUrlWithNewPort(URL u,
int newPort)
Creates and returns a new URL identical to the specified URL, except using the specified port. |
static URL |
getUrlWithNewProtocol(URL u,
String newProtocol)
Creates and returns a new URL identical to the specified URL, except using the specified protocol. |
static URL |
getUrlWithNewQuery(URL u,
String newQuery)
Creates and returns a new URL identical to the specified URL, except using the specified query string. |
static URL |
getUrlWithNewRef(URL u,
String newRef)
Creates and returns a new URL identical to the specified URL, except using the specified reference. |
static String |
resolveUrl(String baseUrl,
String relativeUrl)
Resolves a given relative URL against a base URL. |
static String |
resolveUrl(URL baseUrl,
String relativeUrl)
Resolves a given relative URL against a base URL. |
static URL |
toUrlSafe(String url)
Constructs a URL instance based on the specified URL string, taking into account the fact that the specified URL string may represent an "about:..." URL, a "javascript:..." URL, or a data:... URL. |
static URL |
toUrlUnsafe(String url)
Constructs a URL instance based on the specified URL string, taking into account the fact that the specified URL string may represent an "about:..." URL, a "javascript:..." URL, or a data:... URL. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static URL toUrlSafe(String url)
Constructs a URL instance based on the specified URL string, taking into account the fact that the specified URL string may represent an "about:..." URL, a "javascript:..." URL, or a data:... URL.
The caller should be sure that URL strings passed to this method will parse correctly as URLs, as
this method never expects to have to handle MalformedURLException
s.
url
- the URL string to convert into a URL instance
public static URL toUrlUnsafe(String url) throws MalformedURLException
Constructs a URL instance based on the specified URL string, taking into account the fact that the specified URL string may represent an "about:..." URL, a "javascript:..." URL, or a data:... URL.
Unlike toUrlSafe(String)
, the caller need not be sure that URL strings passed to this
method will parse correctly as URLs.
url
- the URL string to convert into a URL instance
MalformedURLException
- if the URL string cannot be converted to a URL instancepublic static URL encodeUrl(URL url, boolean minimalQueryEncoding)
Encodes illegal characters in the specified URL's path, query string and anchor according to the URL encoding rules observed in real browsers.
For example, this method changes "http://first/?a=b c" to "http://first/?a=b%20c".
url
- the URL to encodeminimalQueryEncoding
- whether or not to perform minimal query encoding, like IE does
public static String encodeAnchor(String anchor)
anchor
- the anchor string to encode and escape
public static String decode(String escaped)
escaped
- the string to be unescaped and decoded
public static URL getUrlWithNewProtocol(URL u, String newProtocol) throws MalformedURLException
u
- the URL on which to base the returned URLnewProtocol
- the new protocol to use in the returned URL
MalformedURLException
- if there is a problem creating the new URLpublic static URL getUrlWithNewHost(URL u, String newHost) throws MalformedURLException
u
- the URL on which to base the returned URLnewHost
- the new host to use in the returned URL
MalformedURLException
- if there is a problem creating the new URLpublic static URL getUrlWithNewPort(URL u, int newPort) throws MalformedURLException
u
- the URL on which to base the returned URLnewPort
- the new port to use in the returned URL
MalformedURLException
- if there is a problem creating the new URLpublic static URL getUrlWithNewPath(URL u, String newPath) throws MalformedURLException
u
- the URL on which to base the returned URLnewPath
- the new path to use in the returned URL
MalformedURLException
- if there is a problem creating the new URLpublic static URL getUrlWithNewRef(URL u, String newRef) throws MalformedURLException
u
- the URL on which to base the returned URLnewRef
- the new reference to use in the returned URL
MalformedURLException
- if there is a problem creating the new URLpublic static URL getUrlWithNewQuery(URL u, String newQuery) throws MalformedURLException
u
- the URL on which to base the returned URLnewQuery
- the new query string to use in the returned URL
MalformedURLException
- if there is a problem creating the new URLpublic static String resolveUrl(String baseUrl, String relativeUrl)
baseUrl
- The base URL in which to resolve the specification.relativeUrl
- The relative URL to resolve against the base URL.
public static String resolveUrl(URL baseUrl, String relativeUrl)
baseUrl
- The base URL in which to resolve the specification.relativeUrl
- The relative URL to resolve against the base URL.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |