Oliver Brinzing wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,


Both URLs are wrong, local file URLs start with three slashes. OOo1
accepted the wrong ULRs but this was a bug that prevented other things
to work correctly and so it needed to be fixed.


I had a look at my java code, and noticed, that

file.toURL().toExternalForm();

returns a "file:/E:/"... url, so i think for oo i should be converted
to the new format, for example:

            try {
                com.sun.star.util.URL[] url = new com.sun.star.util.URL[1];
                url[0] = new com.sun.star.util.URL();
                // java net url ... (e.g. from file.toURL().toExternalForm();)
                url[0].Complete = "file:/E:/Data/home/file.sxw";

                System.out.println("before: " + url[0].Complete);

                Object obj = xComponentContext.getServiceManager()
                        .createInstanceWithContext(
                                "com.sun.star.util.URLTransformer",
                                xComponentContext);

                XURLTransformer transform = (XURLTransformer) UnoRuntime
                        .queryInterface(XURLTransformer.class, obj);

                transform.parseStrict(url);
                System.out.println("after: " + url[0].Complete);

            } catch (Exception e1) {
                e1.printStackTrace();
            }

is this correct ?

Not quite. OOo distinguishes between _internal_ and _external_ (file) URLs, and you generally need to convert between those two formats at OOo's edges (i.e., when passing a URL obtained from some Java functionality into a UNO method). An added benefit is that the translation service (com.sun.star.uri.ExternalUriReferenceTranslator) also understands the broken Java file URLs that lack the authority part, and converts them into valid ones:

  com.sun.star.uno.XComponentContext context = ...;
  java.net.URL before = ...;
  String s = before.toExternalForm();
  String after =  com.sun.star.uri.XExternalUriReferenceTranslator
    .create(context)
    .translateToInternal(s);
  if (after.length() == 0 && s.length() != 0) {
    ...translateToInternal failed...
  }

-Stephan

regards

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to