If a port is not explicitly specified in the URL it's set to -1. This means the default port.
If the ref doesn't exist, it's just null, so watch out
Better yet, test to see that it's non-null before using it.
If the file is left off completely, e.g. http://java.sun.com, then it's set to "/".