Hello Rony,

On Saturday 20 March 2010, 13:04, Rony G. Flatscher wrote:
> Hi there,
> 
> it may be me, but I have not found an example/explanation of how to
> create and use a XCommandEnvironment.
> 
> Purpose: for an installation script, which is supposed to install/remove
> a package from OOo, I would like to use
> ""/singletons/com.sun.star.deployment.thePackageManagerFactory"" (which
> I was able to successfully exploit back in the pre 2.2 days; with OOo
> 2.2; my notes tell me that then an XCommandEnvironment object was
> mandatory to be passed to one of the methods, such that I switched to
> using the "unopkg" executable instead).
> 
> Thankful for any hints, pointers !

you have to pass to XPackageManager::add/removePackage a UNO object 
implementing XCommandEnvironment (== you must write this in a language 
supporting UNO objects implementation... well, sometimes OOo Basic listeners 
do the trick, but never tried this)

This can be a class implementing XCommandEnvironment, or invoking the 
CommandEnvironment service constructor's:
http://api.openoffice.org/docs/common/ref/com/sun/star/ucb/CommandEnvironment.html
 

First example I find is the unopkg implementation itself.
See for example 

http://svn.services.openoffice.org/opengrok/xref/DEV300_m75/desktop/source/pkgchk/unopkg/unopkg_app.cxx#366

366                         xPackageManager->removePackage(
367                             cmdPackage, cmdPackage,
368                             Reference<task::XAbortChannel>(), xCmdEnv );

here xCmdEnv is 

343         Reference< ::com::sun::star::ucb::XCommandEnvironment > xCmdEnv(
344             createCmdEnv( xComponentContext, logFile,
345                           option_force, option_verbose, option_bundled) );


where createCmdEnv instantiates a class implementing XCommandEnvironment 
(together with  task::XInteractionHandler and XProgressHandler)

http://svn.services.openoffice.org/opengrok/xref/DEV300_m75/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx#430
http://svn.services.openoffice.org/opengrok/xref/DEV300_m75/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx#80

As you see, this class implements all 3 required interfaces, so when 
XCommandEnvironment::getInteractionHandler() and 
XCommandEnvironment::getProgressHandler() are invoked, it returns itself.
http://svn.services.openoffice.org/opengrok/xref/DEV300_m75/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx#212

The implementation there is quite complex
http://svn.services.openoffice.org/opengrok/xref/DEV300_m75/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx#227
but, well, it's the OOo unopkg!
Depending on your purpose, you could try something more modest, like in
http://svn.services.openoffice.org/opengrok/xref/DEV300_m75/javaunohelper/com/sun/star/comp/juhtest/SmoketestCommandEnvironment.java


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to