Java Reference
In-Depth Information
Resolution
Resolution istheprocessofresolvingoneURIagainstanotherURI,whichisknownas
thebase.TheresultingURIisconstructedfromcomponentsofbothURIsinthemanner
specifiedbyRFC2396(see http://tools.ietf.org/html/rfc2396 ) ,taking
components from the base URI for those not specified in the original URI. For hier-
archicalURIs,thepathoftheoriginalisresolvedagainstthepathofthebaseandthen
normalized.
Forexample, theresultofresolvingoriginal URI docs/guide/collections/
designfaq.html#28 againstbaseURI http://java.sun.com/j2se/1.3/
is result URI http://java.sun.com/j2se/1.3/docs/guide/collec-
tions/designfaq.html#28 . As a second example, resolving relative URI ../
../../demo/jfc/SwingSet2/src/SwingSet2.java against this result
yields http://java.sun.com/j2se/1.3/demo/jfc/SwingSet2/src/
SwingSet2.java .
ResolutionofbothabsoluteandrelativeURIs,andofbothabsoluteandrelativepaths
in the case of hierarchical URIs, is supported.
URI declares URI resolve(String str) and URI resolve(URI uri)
methods for resolving the original URI argument (passed to str or uri ) against the
baseURIcontainedinthecurrent URI object(onwhichthismethodwascalled).These
methods return either a new URI object containing the original URI or the URI argu-
mentwhentheoriginalURIisalreadyabsoluteoropaque.Otherwise,theyreturnanew
URI objectcontainingtheresolvedURI. NullPointerException isthrownwhen
str or uri is null . IllegalArgumentException isthrownwhen str violates
RFC 2396 syntax.
Listing 9-12 presents an application that lets you experiment with re-
solve(String) .
Listing 9-12. Resolving URIs
import java.net.URI;
import java.net.URISyntaxException;
class Resolve
{
public static void main(String[] args) throws URISyn-
taxException
Search WWH ::




Custom Search