With the following code fragment, if docurl = "about:blank", then I get a java.net.MalformedURLException thrown. I cant believe I am the first person to have to handle such urls so Im wondering if there is a different api than java.net I can use?
try {
URL url;
url = new URL(docurl);
docuri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
开发者_开发技巧 e.printStackTrace();
}
The issue is with the "about" protocol not having a valid handler.
The valid handlers for my jre6 installation are found in rt.jar
sun/net/www/protocol/ftp/Handler.class
sun/net/www/protocol/gopher/Handler.class
sun/net/www/protocol/http/NegotiateCallbackHandler.class
sun/net/www/protocol/mailto/Handler.class
sun/net/www/protocol/netdoc/Handler.class
sun/net/www/protocol/http/Handler.class
sun/net/www/protocol/jar/Handler.class
sun/net/www/protocol/file/Handler.class
You can make your own handler class by following the recipe at http://java.sun.com/developer/onlineTraining/protocolhandlers/
You can parse such URLs with java.net.URI.
Alternatively, I wrote a Java URL parsing library that offers a more general solution: galimatias.
精彩评论