Java Reference
In-Depth Information
System . err . println ( args [ i ] + " does not seem to be a URI." );
}
System . out . println ();
}
}
}
Here's the result of running this against three of the URI examples in this section:
% java URISplitter tel: + 1 - 800 - 9988 - 9938 \
http: //www.xml.com/pub/a/2003/09/17/stax.html#id=_hbc \
urn:isbn: 1 - 565 - 92870 - 9
The URI is tel: + 1 - 800 - 9988 - 9938
This is an opaque URI .
The scheme is tel
The scheme specific part is + 1 - 800 - 9988 - 9938
The fragment ID is null
The URI is http: //www.xml.com/pub/a/2003/09/17/stax.html#id=_hbc
This is a hierarchical URI .
The scheme is http
The host is www . xml . com
The user info is null
The port is - 1
The path is / pub / a / 2003 / 09 / 17 / stax . html
The query string is null
The fragment ID is id = _hbc
The URI is urn:isbn: 1 - 565 - 92870 - 9
This is an opaque URI .
The scheme is urn
The scheme specific part is isbn: 1 - 565 - 92870 - 9
The fragment ID is null </ programlisting >
Resolving Relative URIs
The URI class has three methods for converting back and forth between relative and
absolute URIs:
public URI resolve ( URI uri )
public URI resolve ( String uri )
public URI relativize ( URI uri )
The resolve() methods compare the uri argument to this URI and use it to construct
a new URI object that wraps an absolute URI. For example, consider these three lines of
code:
URI absolute = new URI ( "http://www.example.com/" );
URI relative = new URI ( "images/logo.png" );
URI resolved = absolute . resolve ( relative );
Search WWH ::




Custom Search