Ariel Constenla-Haile wrote:
Hello giancarlo,

[re-send, as it seems my client send its half-written back-up copy instead of the final versiopn]

On Friday 17 April 2009, 11:52, giancarlo wrote:
- The path of "repository" is found by this code:

public MyExtension(XComponentContext context) {
        String m_implementationName = MyExtension.class.getName();
        m_xContext = context;
        XPackageInformationProvider xPackageInformationProvider =
PackageInformationProvider.get(m_xContext);
        reposPath =
xPackageInformationProvider.getPackageLocation(m_implementationName);
        reposPath = reposPath.replaceFirst("file://", "");
        reposPath +="/repository";
       ...
       ...
}
*_The problem:_*

- When I try out the extension on OOo for MS Windows (both XP and Vista)
the path is wrong, I get things like this:

       \C:/ . . . /MyExtension.oxt/repository

IMO the problem is your code is not system independent.
You should use the OOo API way to get the extension location:

    /**
     * Provides an URL to the root of an installed package.
     *
     * @param xContext              XComponentContext
     * @param sExtensionIdentifier  the unique identifier of an extension.
     * @return          The service looks for an installed package with the
     * given id and returns the URL to the root of the package.
     * If the service can not find a matching package, an emty string will
     * be returned.
     */
    public static String getExtensionLocation(
                                                XComponentContext xContext,
                                                String sExtensionIdentifier)
    {
        String sPath = "";
        String sSingleton =
                
"/singletons/com.sun.star.deployment.PackageInformationProvider";
        try {
            com.sun.star.deployment.XPackageInformationProvider
                    xPackageInformationProvider =
                    (com.sun.star.deployment.XPackageInformationProvider)
                    UnoRuntime.queryInterface(
                    com.sun.star.deployment.XPackageInformationProvider.class,
                    xContext.getValueByName(sSingleton));
            sPath = xPackageInformationProvider.getPackageLocation(
                    sExtensionIdentifier);

        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            return sPath;
        }
    }

and then simply add "/repository" to the extension location.
You should always use URLs generated by OOo API (this also means you should use OOo IO API instead of Java's, I know it's more verbose, but this way your code is more portable).

For conversion between URL and system path you should always use the also more verbose OOo API instead of Java's; (I copy from http://api.openoffice.org/servlets/ReadMsg?list=dev&msgNo=19331
a Java version of convertToURL and convertFromURL)

     /**
      * 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;
         }
     }


(according to Stephan's commnet in http://api.openoffice.org/servlets/ReadMsg?list=dev&msgNo=19333 in some cases the Java API does not know anything about OOo representation).


Regards
PERFECT! This is the only one solution which worked for me! Many thanks to all :)

Regards,
Giancarlo Fringuello

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org

Reply via email to