Hi Stephan,
finally, I would like to use the PackageManager from a script from a
commandline.
Some methods of "com.sun.star.deployment.XPackageManager" require a
"com.sun.star.ucb.XCommandEnvironment" as an argument. E.g.
"addPackage(string, string, XAbortChannel, XCommandEnvironment)",
"removePackage(string, XAbortChannel, XCommandEnvironment)",
"getDeployedPackages(XAbortChannel, XCommandEnvironment)".
Looking through the docs (dev-guide) and googling on the Internet
does not reveal, how one would be able to get to an object containing
the XCommandEnvironment interface. Also, the OOo WWW site is down
for two days :( so I am not able to research there.
Is there anyone who has an idea/hint or even code (snippets) ?
The XCommandEnvironment has to be implemented by the caller, there are
no services or factories that would give you one. The unopkg tool (in
CVS module desktop) can be used as a non-GUI application that uses the
XPackageManager, so if you search around there you should find some
example code how to implement an XCommandEnvironment for a commandline
scenario.
Thank you very much. Experimenting a little bit it turns out that the
XCommandEnvironment is optional, ie. one can supply <null> and it works,
which is very good!
Here is the ooRexx script to install the ooRexx package itself into OOo
from the command line. It first makes sure that an older installed
package is removed from both, the "user" context and the "shared" (=
global) context, before adding the new one to the "shared" context. At
the end it lists the status of the newly added package.
Hint w.r.t. the return Value of isRegistered(...):
isRegistered: [EMAIL PROTECTED] ~value ->
[EMAIL PROTECTED] -> value [Boolean]
Here's the code (".nil" is "null" in ooRexx, the tilde "~" is the
message operator):
-------------- cut here -------------
/* initialize connection to server, get XContext */
xContext = UNO.connect() -- connect to server and retrieve the XContext
object
XMcf = xContext~getServiceManager -- retrieve XMultiComponentFactory
packageName = "ScriptProviderForooRexx.jar"
mediaType = "application/vnd.sun.star.uno-component;type=Java"
tmpName = stream(packageName, "C", "QUERY EXISTS") -- get fully qualified
filename
if tmpName = "" then
do
.error~say("Cannot find" pp(packageName)", aborting...")
exit -1
end
urlName = ConvertToUrl(tmpName) -- turn into ucp compliant URL
-- get the pre-registered package manager factory singleton object
pmName="/singletons/com.sun.star.deployment.thePackageManagerFactory"
xpmf=xContext~getValueByName(pmName)~XPackageManagerFactory
-- make sure package is removed from "user" context
call removePackage xpmf~getPackageManager("user"), packageName
-- work on "shared" (global) package context
xpmShared=xpmf~getPackageManager("shared") -- get "shared" package manager
call removePackage xpmShared, packageName -- remove old package
xpmShared~addPackage(urlName, mediaType, .nil, .nil) -- add package
dp=getDeployedPackage(xpmShared, packageName) -- query package
if .nil<>dp then -- package object available?
say "Is ["packageName"] registered?"
"["dp~isRegistered(.nil,.nil)~value~value"]"
else
say "["packageName"] could not be added!"
::requires UNO.CLS -- get UNO support for ooRexx
::routine removePackage -- remove a given package
use arg xpmf, packageName
signal on any -- activate execption handling
xpmf~removePackage(packageName, .nil, .nil)
any: return -- just return
::routine getDeployedPackage -- get and return the deployed package object
use arg xpm, packageName
signal on any -- activate exception handling
return xpm~getDeployedPackage(packageName, .nil)
any: return .nil -- exception occurred return .nil
-------------- cut here -------------
Maybe that could also serve as a snippet (helping others to take
advantage of the researched sequence of statements and interfaces)?
Thanks also go to Daniel Bölzle who hinted at the PackageManager classes
in an e-mail last November!
Regards,
---rony
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]