javafx 2 webview custom url handler, não trabalhe com url relativo
Eu tenho aplicativo simples com código:
webView.getEngine().load("classpath:data/index.html");
URLStreamHandler personalizado:
public class Handler extends URLStreamHandler {
private final ClassLoader classLoader;
public Handler() {
this.classLoader = getClass().getClassLoader();
}
public Handler(ClassLoader classLoader) {
this.classLoader = classLoader;
}
@Override
protected URLConnection openConnection(URL u) throws IOException {
URL resourceUrl = classLoader.getResource(u.getPath());
if(resourceUrl == null)
throw new IOException("Resource not found: " + u);
return resourceUrl.openConnection();
}
}
instalado por:
URL.setURLStreamHandlerFactory(protocol -> {
if(protocol.equals("classpath")) {
return new Handler();
} else {
return null;
}
});
Ele carrega dados / index.html:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div>Hello, World!!!</div>
<img src="download.jpg">
</body>
</html>
mas no resultado a imagem não aparece.
O que fazer para permitir que o WebView resolva links relativos como "download.jpg"?