Java Reference
In-Depth Information
Resolution
Resolution
istheprocessofresolvingoneURIagainstanotherURI,whichisknownas
thebase.TheresultingURIisconstructedfromcomponentsofbothURIsinthemanner
components from the
base URI
for those not specified in the
original URI.
For hier-
archicalURIs,thepathoftheoriginalisresolvedagainstthepathofthebaseandthen
normalized.
Forexample, theresultofresolvingoriginal URI
docs/guide/collections/
is result URI
http://java.sun.com/j2se/1.3/docs/guide/collec-
../../demo/jfc/SwingSet2/src/SwingSet2.java
against this result
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