Я пытаюсь создать простой скрипт, который преобразует любую возможную HTML-ссылку в HTTP-URL, например
http://example.com //example.com /index.html ./index.html index.html
Я уже попробовал функцию, которую нашел в другом ответе:
public static Integer isAbsoluteURL (String url) throws java.net.MalformedURLException {
final URL baseHTTP = new URL("http://example.com");
final URL baseFILE = new URL("file:///");
if (url.length() > 0) {
if (url.substring(0, 1) == "/") {
return 0;
}
}
URL frelative;
URL hrelative;
try {
frelative = new URL(baseFILE, url);
hrelative = new URL(baseHTTP, url);
} catch (MalformedURLException e) {
System.out.println("MalformedURLException found");
return 3;
}
if (frelative.equals(hrelative)) {
return 0;
} else {
return 1;
}
}
Я хочу получить абсолютные ссылки, но код не работает для ./, // (без http [s]).
Спасибо.