Another attempt at generalizing the URI parsing so that it works with a
wider variety of file URIs and yet remains backwards compatible.
Merge in the latest changes from trunk.