As I'm usually using the OOo API from Basic code, I'm using the convertToUrl() and convertFromUrl() Basic functions to handle URLs. The problem is that I had to do the same in Java extension. Of course, the toExternalString() method of a Java URL object doesn't return an OOo internal URL usable in method like loadComponentFromUrl().

Hopefully, I found out the ExternalUriReferenceTranslator service which convert between OOo internal URLs and normal URLs. Here is a code sample which could help to see how it works.

public static String convertToUrl(String pFilePath, XComponentContext pComponentContext ) throws MalformedURLException {

    String internalUrl = null;

    URL externalUrl = new File(pFilePath).toURL();
    XExternalUriReferenceTranslator translator = ExternalUriReferenceTranslator.create(
         pComponentContext);
    internalUrl =  translator.translateToInternal(externalUrl.toExternalForm());

    return internalUrl;
}