PackageDescription: URISupport

URI Support

Last published: August 8, 2008 by 'avalloud'

Defines 10 Classes
Extends 15 Classes

URISupport includes a framework for working with URIs (Uniform Resource Identifiers) and URLs (Universal Resource Locators). The framework provides an easy-to-use mechanism to create URL objects from a String, as well as a simple interface for performing some operations on the URL, such as reading and writing, if permitted by the resource.

A URI is a string that represents the address of a piece of information on the Internet. A URL is a type of URI that specifies the protocol type, such as FTP, HTTP, and MailTo. Additional packages may need to be loaded other URL types beyond FILE, for example, FTP, HTTP, HTTPS.

Creating a URI:

In VisualWorks, a URI is an object that is created by parsing a String specifying the URI. To parse the String, send it an asURI message:

'' asURI

The result in this case is an FtpURL object, which was determined from the protocol prefix. If the prefix had been “http:” the result would be an HttpURL. If the protocol were an unknown type, such as “MailTo:”, the result would be an UnknownURLType.

The protocol is determined by reading from the beginning of the string to the colon (FTP). The host is read immediately following the double slash (//) up to the first single slash ( Everything else is the path, query and fragment.

For local files, you can generate a URI from a Filename:
'' asFilename asURI

Likewise, file URLs can be turned in to Filenames:
'file:///./' asURI asFilename

A URI object can be turned back into a String by sending #asString to it.