this.ref = url.ref;
this.port = url.port;
}
public MultiProtocolURI(String url) throws MalformedURLException {
if (url == null) throw new MalformedURLException("url string is null");
// identify protocol
assert (url != null);
url = url.trim();
//url = patternSpace.matcher(url).replaceAll(" ");
if (url.startsWith("\\\\")) {
url = "smb://" + patternBackSlash.matcher(url.substring(2)).replaceAll("/");
}
if (url.length() > 1 && url.charAt(1) == ':') {
// maybe a DOS drive path
url = "file://" + url;
}
if (url.length() > 0 && url.charAt(0) == '/') {
// maybe a unix/linux absolute path
url = "file://" + url;
}
int p = url.indexOf(':');
if (p < 0) {
url = "http://" + url;
p = 4;
}
this.protocol = url.substring(0, p).toLowerCase().trim();
if (url.length() < p + 4) throw new MalformedURLException("URL not parseable: '" + url + "'");
if (!this.protocol.equals("file") && url.substring(p + 1, p + 3).equals("//")) {
// identify host, userInfo and file for http and ftp protocol
final int q = url.indexOf('/', p + 3);
int r;
if (q < 0) {
if ((r = url.indexOf('@', p + 3)) < 0) {
host = url.substring(p + 3);
userInfo = null;
} else {
host = url.substring(r + 1);
userInfo = url.substring(p + 3, r);
}
path = "/";
} else {
host = url.substring(p + 3, q).trim();
if ((r = host.indexOf('@')) < 0) {
userInfo = null;
} else {
userInfo = host.substring(0, r);
host = host.substring(r + 1);
}
path = url.substring(q);
}
if (host.length() < 4 && !protocol.equals("file")) throw new MalformedURLException("host too short: '" + host + "', url = " + url);
if (host.indexOf('&') >= 0) throw new MalformedURLException("invalid '&' in host");
path = resolveBackpath(path);
identPort(url, (isHTTP() ? 80 : (isHTTPS() ? 443 : (isFTP() ? 21 : (isSMB() ? 445 : -1)))));
identRef();
identQuest();
escape();
} else {
// this is not a http or ftp url
if (protocol.equals("mailto")) {
// parse email url
final int q = url.indexOf('@', p + 3);
if (q < 0) {
throw new MalformedURLException("wrong email address: " + url);
}
userInfo = url.substring(p + 1, q);
host = url.substring(q + 1);
path = null;
port = -1;
quest = null;
ref = null;
} else if (protocol.equals("file")) {
// parse file url
String h = url.substring(p + 1);
if (h.startsWith("//")) {
// no host given
host = null;
path = h.substring(2);
} else {
host = null;
if (h.length() > 0 && h.charAt(0) == '/') {
char c = h.charAt(2);
if (c == ':' || c == '|')
path = h.substring(1);
else
path = h;
} else {
char c = h.charAt(1);
if (c == ':' || c == '|')
path = h;
else
path = "/" + h;
}
}
userInfo = null;
port = -1;
quest = null;
ref = null;
} else {
throw new MalformedURLException("unknown protocol: " + url);
}
}
// handle international domains
if (!Punycode.isBasic(host)) try {