Package com.mastfrog.url
package com.mastfrog.url
URL API
This is a small library for parsing URLs, which provides an actual object model of the elements of URLs and their component objects. Unlikejava.net.url, URLs and all of their components can be invalid and provide human-friendly
localized messages as to what's wrong with them - no MalformedURLExceptions and nothing
that will unexpectedly make a network connection if you use it as a HashMap key.
URLs also do minimal self-normalizing when parsed (handling .. in paths, replacing
"localhost" with 127.0.0.1 or ::1, lower-casing host labels - very minimal, but sufficient to de-duplicate equivalent
URLs, and all standards-compliant. A lot of work went into reading RFCs to get things right here, and it has
an exhaustive test-suite. URLs can be parsed or built with builders.
java.net.URL was developed for HotJava in the 90s, and was probably
great for that use case - and that use case only. This is a library for doing
modern Java coding with URLs.
Usage
In the simplest form:
URL url = URL.parse("http://joe:password@foo.com:8080/foo/bar?baz=quux#hey");
assert "hey".equals(url.getAnchor());
assert "joe".equals(url.getUsername();
assert "password".equals(url.getPassword();
assert "bar".equals(url.getPath().getLastElement().toString());
assert Host.parse("foo.com").equals(url.getHost());
assert 8080 == url.getPort().intValue();
assert url.isValid();
-
ClassDescriptionAn internet host such as a host name or IP address.Aggregate object for a host and port.One Label in a
Host- i.e.A query delimiter in a URL.One key/value pair in the query portion of a URL.The Parameters portion of a URL, e.g.
http://timboudreau.com/foo.html?foo=bar&bar=baz#somethingThe path portion of a URL.One element of a URL's path.A TCP port.The protocol portion of a URL (e.g.Enum of standard URL protocols.Represents an internet URL.Factory class for constructing URL objects w/ validation.One element of a URL, such as a Host, Port, Password, Path, PathElement, Parameters or ParametersElement.