Hi Ariel, Oliver,

well i didn't remember this UCB API when i have written my last comment on Olivers posting.

But Ariel pointed out that we have this API and that of course this API can be used to convert an URL into a system path. Advantage is that it can be used from Basic and other languages as well.

Thanks

Ariel

Ariel Constenla-Haile wrote:
Oliver Brinzing escribió:
Hi,

i noticed
PackageInformationProvider.get(xContext).getPackageLocation("MyExtension")

returns a string url, for example:
file:///c:/programs/soffice/OOo-dev%203/program/../share/uno_packages/cache/uno_packages/61.tmp_/myextension.oxt

How can one convert the url to an external one (for example replace the %20 with a space) ?

Is there a helper service ?


Hi Oliver

you can convert that URL to a system path:

    /**
     * Converts a (file) URL to a file path in system dependent notation.
     * @param sFileURL
     * @return
     */
    public static String convertFromURL(
                                        XComponentContext xContext,
                                        String sFileURL) {
        String sSystemPath = null;
        try {
            com.sun.star.ucb.XFileIdentifierConverter xFileConverter =
(com.sun.star.ucb.XFileIdentifierConverter) UnoRuntime.queryInterface(
                    com.sun.star.ucb.XFileIdentifierConverter.class,
                    xContext.getServiceManager().createInstanceWithContext(
                    "com.sun.star.ucb.FileContentProvider", xContext));
sSystemPath = xFileConverter.getSystemPathFromFileURL(sFileURL);
        } catch (java.lang.Exception e) {
            e.printStackTrace();
        } finally {
            return sSystemPath;
        }
    }

//*********************************************************************

    /**
     * Converts a system path into an URL using OOo API
     * @param sBase
     * @param sSystemPath
     * @return
     */
    public static String convertToURL(
                                        XComponentContext xContext,
                                        String sBase,
                                        String sSystemPath) {
        String sURL = null;
        try {
            com.sun.star.ucb.XFileIdentifierConverter xFileConverter =
(com.sun.star.ucb.XFileIdentifierConverter) UnoRuntime.queryInterface(
                    com.sun.star.ucb.XFileIdentifierConverter.class,
                    xContext.getServiceManager().createInstanceWithContext(
                    "com.sun.star.ucb.FileContentProvider", xContext));
            sURL = xFileConverter.getFileURLFromSystemPath(
                    sBase, sSystemPath);
        } catch (java.lang.Exception e) {
            e.printStackTrace();
        } finally {
            return sURL;
        }
    }

//**************************************************************************


In Linux, if I try with the following path with non ASCII chars /home/ariel/Música/Mozart/Die Zauberflöte, the results are


path    /home/ariel/Música/Mozart/Die Zauberflöte
to URL    file:///home/ariel/M%C3%BAsica/Mozart/Die%20Zauberfl%C3%B6te
from URL    /home/ariel/Música/Mozart/Die Zauberflöte


Of course there is a Java-API way to achieve the same (you will find it in [old/most/all] SKD examples), but let's use OOo API ;-)



Regards
Ariel.




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

Reply via email to