[Solved] Getting the path where an extension is located

The Application Programming Interface and the OASIS Open Document Format

[Solved] Getting the path where an extension is located

Postby Roland Piazzi » Thu Feb 24, 2011 5:50 pm


i would like to ask for help for the problem that is nominated in the subject. I post here because the solutions found with Google and on this page did not help.

Also I have to say that I'm almost new in Basic for OpenOffice and I think that the solution for the problem could be easy but I just can't find it.

The Problem is:
I want to get the path where an extension is located because the extension has to write and read some information from there.

I found that the downloaded extension will not be copied from the download folder into a directory of OpenOffice but I also found that there is a temporary representation of the extension in some directory like \user\appdata\roaming\OpenOffice.org2\user\uno_packages\cache\uno_packages\ (for my system).
Now I've tried different things:

Code: Select all   Expand viewCollapse view
oPMF = GetDefaultContext().getByName("/singletons/com.sun.star.deployment.thePackageManagerFactory")
PackageManager = oPMF.getPackageManager("user")
Package = PackageManager.getDeployedPackage("package_name",NULL)

But there is no way to get the path through a method or a property of the object Package

Then there is the possibility to do this:
Code: Select all   Expand viewCollapse view
oPackageInfoProvider = GetDefaultContext.getByName("/singletons/com.sun.star.deployment.PackageInformationProvider")
sPackageLocation = oPackageInfoProvider.getPackageLocation("extension_id")

When I do this there is always the error: Basic runtime error. Object variable not set.

I realized that
Code: Select all   Expand viewCollapse view
returns a value of the type Variant and thought that this is the reason why I can't call the method getPackagedLocation("extension_id"). Also a Problem is that the Interface XPackageInformationProvider is only available since the version 2.3 and I would like to make available the extension also for the version 2.1 of OpenOffice.

Also with the Function Environ("variable") there is - at least in Windows - no property or parameter that gives back the location of an extension in OpenOffice.

Finally i tried this:
Code: Select all   Expand viewCollapse view
oPathSettings = createUnoService("com.sun.star.util.PathSettings")
propertyvalue = oPathSettings.getPropertyValue("PropertyName")

With this code I get property-values that contain the first part of the path to this "temporary" representation (as mentioned above) of the extension. But in the second part (...\uno_packages\cache\uno_packages\Dir_with_extension) there are more than one possible directories for the extension and the directory name seems to change from time to time. So i didn't look how to find this specific directory name.

But there should be a more simple solution to this problem. Would be great if someone of you can give me the answer or at least a hint to it. :D

Thanks in advance.

Last edited by Roland Piazzi on Fri Feb 25, 2011 3:02 pm, edited 1 time in total.
OpenOffice 2.1 on Windows 7
Roland Piazzi
Posts: 2
Joined: Thu Feb 24, 2011 4:46 pm

Re: Problem with getting the path where an extension is loca

Postby B Marcelly » Thu Feb 24, 2011 8:13 pm

Using the singleton PackageInformationProvider is the method to use now. It works, if the extension is correctly created and contains an extension identifier.

The problem is your antiquated version of OpenOffice. Version 2.1 should not be used any more. Many extension features were added later. At least use the latest 2.4.x version.

The previous solution was more complex. Message from year 2006 :
Currently the only way is to deploy your own configuration file and use %ORIGIN% in any path url values for example. Later you use the MacroExpander service to expand the macro url.

I can't give you an example. Perhaps it is used in the extension BasicAddonBuilder.

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Problem with getting the path where an extension is loca

Postby Roland Piazzi » Fri Feb 25, 2011 3:00 pm

Thank you very much. I installed the newest version of OpenOffice and it worked (the issues for the older version at the moment I don't check)
OpenOffice 2.1 on Windows 7
Roland Piazzi
Posts: 2
Joined: Thu Feb 24, 2011 4:46 pm

Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 1 guest