1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_desktop.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "dp_script.hrc" 32*cdf0e10cSrcweir #include "dp_lib_container.h" 33*cdf0e10cSrcweir #include "dp_backend.h" 34*cdf0e10cSrcweir #include "dp_ucb.h" 35*cdf0e10cSrcweir #include "rtl/uri.hxx" 36*cdf0e10cSrcweir #include "ucbhelper/content.hxx" 37*cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx" 38*cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx" 39*cdf0e10cSrcweir #include "comphelper/servicedecl.hxx" 40*cdf0e10cSrcweir #include "svl/inettype.hxx" 41*cdf0e10cSrcweir #include "com/sun/star/util/XUpdatable.hpp" 42*cdf0e10cSrcweir #include "com/sun/star/script/XLibraryContainer3.hpp" 43*cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/util/XMacroExpander.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/uri/XUriReferenceFactory.hpp> 46*cdf0e10cSrcweir #include <memory> 47*cdf0e10cSrcweir #include "dp_scriptbackenddb.hxx" 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir using namespace ::dp_misc; 50*cdf0e10cSrcweir using namespace ::com::sun::star; 51*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 52*cdf0e10cSrcweir using namespace ::com::sun::star::ucb; 53*cdf0e10cSrcweir using ::rtl::OUString; 54*cdf0e10cSrcweir namespace css = ::com::sun::star; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir namespace dp_registry { 57*cdf0e10cSrcweir namespace backend { 58*cdf0e10cSrcweir namespace script { 59*cdf0e10cSrcweir namespace { 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir typedef ::cppu::ImplInheritanceHelper1< 62*cdf0e10cSrcweir ::dp_registry::backend::PackageRegistryBackend, util::XUpdatable > t_helper; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //============================================================================== 65*cdf0e10cSrcweir class BackendImpl : public t_helper 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir class PackageImpl : public ::dp_registry::backend::Package 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir BackendImpl * getMyBackend() const; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir const OUString m_scriptURL; 72*cdf0e10cSrcweir const OUString m_dialogURL; 73*cdf0e10cSrcweir OUString m_dialogName; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir // Package 76*cdf0e10cSrcweir virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_( 77*cdf0e10cSrcweir ::osl::ResettableMutexGuard & guard, 78*cdf0e10cSrcweir ::rtl::Reference<AbortChannel> const & abortChannel, 79*cdf0e10cSrcweir Reference<XCommandEnvironment> const & xCmdEnv ); 80*cdf0e10cSrcweir virtual void processPackage_( 81*cdf0e10cSrcweir ::osl::ResettableMutexGuard & guard, 82*cdf0e10cSrcweir bool registerPackage, 83*cdf0e10cSrcweir bool startup, 84*cdf0e10cSrcweir ::rtl::Reference<AbortChannel> const & abortChannel, 85*cdf0e10cSrcweir Reference<XCommandEnvironment> const & xCmdEnv ); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir public: 88*cdf0e10cSrcweir PackageImpl( 89*cdf0e10cSrcweir ::rtl::Reference<BackendImpl> const & myBackend, 90*cdf0e10cSrcweir OUString const & url, 91*cdf0e10cSrcweir Reference<XCommandEnvironment> const &xCmdEnv, 92*cdf0e10cSrcweir OUString const & scriptURL, OUString const & dialogURL, 93*cdf0e10cSrcweir bool bRemoved, OUString const & identifier); 94*cdf0e10cSrcweir }; 95*cdf0e10cSrcweir friend class PackageImpl; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // PackageRegistryBackend 98*cdf0e10cSrcweir virtual Reference<deployment::XPackage> bindPackage_( 99*cdf0e10cSrcweir OUString const & url, OUString const & mediaType, 100*cdf0e10cSrcweir sal_Bool bRemoved, OUString const & identifier, 101*cdf0e10cSrcweir Reference<XCommandEnvironment> const & xCmdEnv ); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir void addDataToDb(OUString const & url); 104*cdf0e10cSrcweir bool hasActiveEntry(OUString const & url); 105*cdf0e10cSrcweir void revokeEntryFromDb(OUString const & url); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir const Reference<deployment::XPackageTypeInfo> m_xBasicLibTypeInfo; 108*cdf0e10cSrcweir const Reference<deployment::XPackageTypeInfo> m_xDialogLibTypeInfo; 109*cdf0e10cSrcweir Sequence< Reference<deployment::XPackageTypeInfo> > m_typeInfos; 110*cdf0e10cSrcweir std::auto_ptr<ScriptBackendDb> m_backendDb; 111*cdf0e10cSrcweir public: 112*cdf0e10cSrcweir BackendImpl( Sequence<Any> const & args, 113*cdf0e10cSrcweir Reference<XComponentContext> const & xComponentContext ); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir // XUpdatable 116*cdf0e10cSrcweir virtual void SAL_CALL update() throw (RuntimeException); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir // XPackageRegistry 119*cdf0e10cSrcweir virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL 120*cdf0e10cSrcweir getSupportedPackageTypes() throw (RuntimeException); 121*cdf0e10cSrcweir virtual void SAL_CALL packageRemoved(OUString const & url, OUString const & mediaType) 122*cdf0e10cSrcweir throw (deployment::DeploymentException, 123*cdf0e10cSrcweir uno::RuntimeException); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir }; 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir //______________________________________________________________________________ 128*cdf0e10cSrcweir BackendImpl::PackageImpl::PackageImpl( 129*cdf0e10cSrcweir ::rtl::Reference<BackendImpl> const & myBackend, 130*cdf0e10cSrcweir OUString const & url, 131*cdf0e10cSrcweir Reference<XCommandEnvironment> const &xCmdEnv, 132*cdf0e10cSrcweir OUString const & scriptURL, OUString const & dialogURL, bool bRemoved, 133*cdf0e10cSrcweir OUString const & identifier) 134*cdf0e10cSrcweir : Package( myBackend.get(), url, 135*cdf0e10cSrcweir OUString(), OUString(), // will be late-initialized 136*cdf0e10cSrcweir scriptURL.getLength() > 0 ? myBackend->m_xBasicLibTypeInfo 137*cdf0e10cSrcweir : myBackend->m_xDialogLibTypeInfo, bRemoved, identifier), 138*cdf0e10cSrcweir m_scriptURL( scriptURL ), 139*cdf0e10cSrcweir m_dialogURL( dialogURL ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir // name, displayName: 142*cdf0e10cSrcweir if (dialogURL.getLength() > 0) { 143*cdf0e10cSrcweir m_dialogName = LibraryContainer::get_libname( 144*cdf0e10cSrcweir dialogURL, xCmdEnv, myBackend->getComponentContext() ); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir if (scriptURL.getLength() > 0) { 147*cdf0e10cSrcweir m_name = LibraryContainer::get_libname( 148*cdf0e10cSrcweir scriptURL, xCmdEnv, myBackend->getComponentContext() ); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir else 151*cdf0e10cSrcweir m_name = m_dialogName; 152*cdf0e10cSrcweir m_displayName = m_name; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir //______________________________________________________________________________ 156*cdf0e10cSrcweir BackendImpl::BackendImpl( 157*cdf0e10cSrcweir Sequence<Any> const & args, 158*cdf0e10cSrcweir Reference<XComponentContext> const & xComponentContext ) 159*cdf0e10cSrcweir : t_helper( args, xComponentContext ), 160*cdf0e10cSrcweir m_xBasicLibTypeInfo( new Package::TypeInfo( 161*cdf0e10cSrcweir OUSTR("application/" 162*cdf0e10cSrcweir "vnd.sun.star.basic-library"), 163*cdf0e10cSrcweir OUString() /* no file filter */, 164*cdf0e10cSrcweir getResourceString(RID_STR_BASIC_LIB), 165*cdf0e10cSrcweir RID_IMG_SCRIPTLIB, RID_IMG_SCRIPTLIB_HC ) ), 166*cdf0e10cSrcweir m_xDialogLibTypeInfo( new Package::TypeInfo( 167*cdf0e10cSrcweir OUSTR("application/" 168*cdf0e10cSrcweir "vnd.sun.star.dialog-library"), 169*cdf0e10cSrcweir OUString() /* no file filter */, 170*cdf0e10cSrcweir getResourceString(RID_STR_DIALOG_LIB), 171*cdf0e10cSrcweir RID_IMG_DIALOGLIB, RID_IMG_DIALOGLIB_HC ) ), 172*cdf0e10cSrcweir m_typeInfos( 2 ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir m_typeInfos[ 0 ] = m_xBasicLibTypeInfo; 175*cdf0e10cSrcweir m_typeInfos[ 1 ] = m_xDialogLibTypeInfo; 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir OSL_ASSERT( ! transientMode() ); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir if (!transientMode()) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir OUString dbFile = makeURL(getCachePath(), OUSTR("backenddb.xml")); 182*cdf0e10cSrcweir m_backendDb.reset( 183*cdf0e10cSrcweir new ScriptBackendDb(getComponentContext(), dbFile)); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir void BackendImpl::addDataToDb(OUString const & url) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir if (m_backendDb.get()) 190*cdf0e10cSrcweir m_backendDb->addEntry(url); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir bool BackendImpl::hasActiveEntry(OUString const & url) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir if (m_backendDb.get()) 196*cdf0e10cSrcweir return m_backendDb->hasActiveEntry(url); 197*cdf0e10cSrcweir return false; 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir // XUpdatable 201*cdf0e10cSrcweir //______________________________________________________________________________ 202*cdf0e10cSrcweir void BackendImpl::update() throw (RuntimeException) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir // Nothing to do here after fixing i70283!? 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir // XPackageRegistry 208*cdf0e10cSrcweir //______________________________________________________________________________ 209*cdf0e10cSrcweir Sequence< Reference<deployment::XPackageTypeInfo> > 210*cdf0e10cSrcweir BackendImpl::getSupportedPackageTypes() throw (RuntimeException) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir return m_typeInfos; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir void BackendImpl::revokeEntryFromDb(OUString const & url) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir if (m_backendDb.get()) 217*cdf0e10cSrcweir m_backendDb->revokeEntry(url); 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir void BackendImpl::packageRemoved(OUString const & url, OUString const & /*mediaType*/) 221*cdf0e10cSrcweir throw (deployment::DeploymentException, 222*cdf0e10cSrcweir uno::RuntimeException) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir if (m_backendDb.get()) 225*cdf0e10cSrcweir m_backendDb->removeEntry(url); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir // PackageRegistryBackend 229*cdf0e10cSrcweir //______________________________________________________________________________ 230*cdf0e10cSrcweir Reference<deployment::XPackage> BackendImpl::bindPackage_( 231*cdf0e10cSrcweir OUString const & url, OUString const & mediaType_, 232*cdf0e10cSrcweir sal_Bool bRemoved, OUString const & identifier, 233*cdf0e10cSrcweir Reference<XCommandEnvironment> const & xCmdEnv ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir OUString mediaType( mediaType_ ); 236*cdf0e10cSrcweir if (mediaType.getLength() == 0) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir // detect media-type: 239*cdf0e10cSrcweir ::ucbhelper::Content ucbContent; 240*cdf0e10cSrcweir if (create_ucb_content( &ucbContent, url, xCmdEnv ) && 241*cdf0e10cSrcweir ucbContent.isFolder()) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir // probe for script.xlb: 244*cdf0e10cSrcweir if (create_ucb_content( 245*cdf0e10cSrcweir 0, makeURL( url, OUSTR("script.xlb") ), 246*cdf0e10cSrcweir xCmdEnv, false /* no throw */ )) 247*cdf0e10cSrcweir mediaType = OUSTR("application/vnd.sun.star.basic-library"); 248*cdf0e10cSrcweir // probe for dialog.xlb: 249*cdf0e10cSrcweir else if (create_ucb_content( 250*cdf0e10cSrcweir 0, makeURL( url, OUSTR("dialog.xlb") ), 251*cdf0e10cSrcweir xCmdEnv, false /* no throw */ )) 252*cdf0e10cSrcweir mediaType = OUSTR("application/vnd.sun.star.dialog-library"); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir if (mediaType.getLength() == 0) 255*cdf0e10cSrcweir throw lang::IllegalArgumentException( 256*cdf0e10cSrcweir StrCannotDetectMediaType::get() + url, 257*cdf0e10cSrcweir static_cast<OWeakObject *>(this), static_cast<sal_Int16>(-1) ); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir String type, subType; 261*cdf0e10cSrcweir INetContentTypeParameterList params; 262*cdf0e10cSrcweir if (INetContentTypes::parse( mediaType, type, subType, ¶ms )) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir if (type.EqualsIgnoreCaseAscii("application")) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir OUString dialogURL( makeURL( url, OUSTR("dialog.xlb") ) ); 267*cdf0e10cSrcweir if (! create_ucb_content( 268*cdf0e10cSrcweir 0, dialogURL, xCmdEnv, false /* no throw */ )) { 269*cdf0e10cSrcweir dialogURL = OUString(); 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir if (subType.EqualsIgnoreCaseAscii("vnd.sun.star.basic-library")) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir OUString scriptURL( makeURL( url, OUSTR("script.xlb"))); 275*cdf0e10cSrcweir if (! create_ucb_content( 276*cdf0e10cSrcweir 0, scriptURL, xCmdEnv, false /* no throw */ )) { 277*cdf0e10cSrcweir scriptURL = OUString(); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir return new PackageImpl( 281*cdf0e10cSrcweir this, url, xCmdEnv, scriptURL, 282*cdf0e10cSrcweir dialogURL, bRemoved, identifier); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir else if (subType.EqualsIgnoreCaseAscii( 285*cdf0e10cSrcweir "vnd.sun.star.dialog-library")) { 286*cdf0e10cSrcweir return new PackageImpl( 287*cdf0e10cSrcweir this, url, xCmdEnv, 288*cdf0e10cSrcweir OUString() /* no script lib */, 289*cdf0e10cSrcweir dialogURL, 290*cdf0e10cSrcweir bRemoved, identifier); 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir throw lang::IllegalArgumentException( 295*cdf0e10cSrcweir StrUnsupportedMediaType::get() + mediaType, 296*cdf0e10cSrcweir static_cast<OWeakObject *>(this), 297*cdf0e10cSrcweir static_cast<sal_Int16>(-1) ); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir //############################################################################## 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir // Package 303*cdf0e10cSrcweir BackendImpl * BackendImpl::PackageImpl::getMyBackend() const 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get()); 306*cdf0e10cSrcweir if (NULL == pBackend) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir //May throw a DisposedException 309*cdf0e10cSrcweir check(); 310*cdf0e10cSrcweir //We should never get here... 311*cdf0e10cSrcweir throw RuntimeException( 312*cdf0e10cSrcweir OUSTR("Failed to get the BackendImpl"), 313*cdf0e10cSrcweir static_cast<OWeakObject*>(const_cast<PackageImpl *>(this))); 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir return pBackend; 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir //______________________________________________________________________________ 318*cdf0e10cSrcweir beans::Optional< beans::Ambiguous<sal_Bool> > 319*cdf0e10cSrcweir BackendImpl::PackageImpl::isRegistered_( 320*cdf0e10cSrcweir ::osl::ResettableMutexGuard &, 321*cdf0e10cSrcweir ::rtl::Reference<AbortChannel> const &, 322*cdf0e10cSrcweir Reference<XCommandEnvironment> const & xCmdEnv ) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir (void)xCmdEnv; 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir BackendImpl * that = getMyBackend(); 327*cdf0e10cSrcweir Reference< deployment::XPackage > xThisPackage( this ); 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir bool registered = that->hasActiveEntry(getURL()); 330*cdf0e10cSrcweir return beans::Optional< beans::Ambiguous<sal_Bool> >( 331*cdf0e10cSrcweir true /* IsPresent */, 332*cdf0e10cSrcweir beans::Ambiguous<sal_Bool>( registered, false /* IsAmbiguous */ ) ); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir //______________________________________________________________________________ 336*cdf0e10cSrcweir void BackendImpl::PackageImpl::processPackage_( 337*cdf0e10cSrcweir ::osl::ResettableMutexGuard &, 338*cdf0e10cSrcweir bool doRegisterPackage, 339*cdf0e10cSrcweir bool startup, 340*cdf0e10cSrcweir ::rtl::Reference<AbortChannel> const &, 341*cdf0e10cSrcweir Reference<XCommandEnvironment> const & xCmdEnv ) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir (void)xCmdEnv; 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir BackendImpl * that = getMyBackend(); 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir Reference< deployment::XPackage > xThisPackage( this ); 348*cdf0e10cSrcweir Reference<XComponentContext> const & xComponentContext = that->getComponentContext(); 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir bool bScript = (m_scriptURL.getLength() > 0); 351*cdf0e10cSrcweir Reference<css::script::XLibraryContainer3> xScriptLibs; 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir bool bDialog = (m_dialogURL.getLength() > 0); 354*cdf0e10cSrcweir Reference<css::script::XLibraryContainer3> xDialogLibs; 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir bool bRunning = office_is_running(); 357*cdf0e10cSrcweir if( bRunning ) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir if( bScript ) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir xScriptLibs.set( 362*cdf0e10cSrcweir xComponentContext->getServiceManager()->createInstanceWithContext( 363*cdf0e10cSrcweir OUSTR("com.sun.star.script.ApplicationScriptLibraryContainer"), 364*cdf0e10cSrcweir xComponentContext ), UNO_QUERY_THROW ); 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir if( bDialog ) 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir xDialogLibs.set( 370*cdf0e10cSrcweir xComponentContext->getServiceManager()->createInstanceWithContext( 371*cdf0e10cSrcweir OUSTR("com.sun.star.script.ApplicationDialogLibraryContainer"), 372*cdf0e10cSrcweir xComponentContext ), UNO_QUERY_THROW ); 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir bool bRegistered = getMyBackend()->hasActiveEntry(getURL()); 376*cdf0e10cSrcweir if( !doRegisterPackage ) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir //We cannot just call removeLibrary(name) because this could remove a 379*cdf0e10cSrcweir //script which was added by an extension in a different repository. For 380*cdf0e10cSrcweir //example, extension foo is contained in the bundled repository and then 381*cdf0e10cSrcweir //the user adds it it to the user repository. The extension manager will 382*cdf0e10cSrcweir //then register the new script and revoke the script from the bundled 383*cdf0e10cSrcweir //extension. removeLibrary(name) would now remove the script from the 384*cdf0e10cSrcweir //user repository. That is, the script of the newly added user extension does 385*cdf0e10cSrcweir //not work anymore. Therefore we must check if the currently active 386*cdf0e10cSrcweir //script comes in fact from the currently processed extension. 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir if (bRegistered) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir //we also prevent and live deployment at startup 391*cdf0e10cSrcweir if (!isRemoved() && !startup) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir if (bScript && xScriptLibs.is() && xScriptLibs->hasByName(m_name)) 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir const OUString sScriptUrl = xScriptLibs->getOriginalLibraryLinkURL(m_name); 396*cdf0e10cSrcweir if (sScriptUrl.equals(m_scriptURL)) 397*cdf0e10cSrcweir xScriptLibs->removeLibrary(m_name); 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir if (bDialog && xDialogLibs.is() && xDialogLibs->hasByName(m_dialogName)) 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir const OUString sDialogUrl = xDialogLibs->getOriginalLibraryLinkURL(m_dialogName); 403*cdf0e10cSrcweir if (sDialogUrl.equals(m_dialogURL)) 404*cdf0e10cSrcweir xDialogLibs->removeLibrary(m_dialogName); 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir getMyBackend()->revokeEntryFromDb(getURL()); 408*cdf0e10cSrcweir return; 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir if (bRegistered) 412*cdf0e10cSrcweir return; // Already registered 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir // Update LibraryContainer 415*cdf0e10cSrcweir bool bScriptSuccess = false; 416*cdf0e10cSrcweir const bool bReadOnly = false; 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir bool bDialogSuccess = false; 419*cdf0e10cSrcweir if (!startup) 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir //If there is a bundled extension, and the user installes the same extension 422*cdf0e10cSrcweir //then the script from the bundled extension must be removed. If this does not work 423*cdf0e10cSrcweir //then live deployment does not work for scripts. 424*cdf0e10cSrcweir if (bScript && xScriptLibs.is()) 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir bool bCanAdd = true; 427*cdf0e10cSrcweir if (xScriptLibs->hasByName(m_name)) 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir const OUString sOriginalUrl = xScriptLibs->getOriginalLibraryLinkURL(m_name); 430*cdf0e10cSrcweir //We assume here that library names in extensions are unique, which may not be the case 431*cdf0e10cSrcweir //ToDo: If the script exist in another extension, then both extensions must have the 432*cdf0e10cSrcweir //same id 433*cdf0e10cSrcweir if (sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE")) 434*cdf0e10cSrcweir || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE")) 435*cdf0e10cSrcweir || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$BUNDLED_EXTENSIONS"))) 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir xScriptLibs->removeLibrary(m_name); 438*cdf0e10cSrcweir bCanAdd = true; 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir else 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir bCanAdd = false; 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir if (bCanAdd) 447*cdf0e10cSrcweir { 448*cdf0e10cSrcweir xScriptLibs->createLibraryLink( m_name, m_scriptURL, bReadOnly ); 449*cdf0e10cSrcweir bScriptSuccess = xScriptLibs->hasByName( m_name ); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir if (bDialog && xDialogLibs.is()) 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir bool bCanAdd = true; 457*cdf0e10cSrcweir if (xDialogLibs->hasByName(m_dialogName)) 458*cdf0e10cSrcweir { 459*cdf0e10cSrcweir const OUString sOriginalUrl = xDialogLibs->getOriginalLibraryLinkURL(m_dialogName); 460*cdf0e10cSrcweir //We assume here that library names in extensions are unique, which may not be the case 461*cdf0e10cSrcweir //ToDo: If the script exist in another extension, then both extensions must have the 462*cdf0e10cSrcweir //same id 463*cdf0e10cSrcweir if (sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE")) 464*cdf0e10cSrcweir || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE")) 465*cdf0e10cSrcweir || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$BUNDLED_EXTENSIONS"))) 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir xDialogLibs->removeLibrary(m_dialogName); 468*cdf0e10cSrcweir bCanAdd = true; 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir else 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir bCanAdd = false; 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir if (bCanAdd) 477*cdf0e10cSrcweir { 478*cdf0e10cSrcweir xDialogLibs->createLibraryLink( m_dialogName, m_dialogURL, bReadOnly ); 479*cdf0e10cSrcweir bDialogSuccess = xDialogLibs->hasByName(m_dialogName); 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir bool bSuccess = bScript || bDialog; // Something must have happened 484*cdf0e10cSrcweir if( bRunning && !startup) 485*cdf0e10cSrcweir if( (bScript && !bScriptSuccess) || (bDialog && !bDialogSuccess) ) 486*cdf0e10cSrcweir bSuccess = false; 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir if (bSuccess) 489*cdf0e10cSrcweir getMyBackend()->addDataToDb(getURL()); 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir } // anon namespace 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir namespace sdecl = comphelper::service_decl; 495*cdf0e10cSrcweir sdecl::class_<BackendImpl, sdecl::with_args<true> > serviceBI; 496*cdf0e10cSrcweir extern sdecl::ServiceDecl const serviceDecl( 497*cdf0e10cSrcweir serviceBI, 498*cdf0e10cSrcweir "com.sun.star.comp.deployment.script.PackageRegistryBackend", 499*cdf0e10cSrcweir BACKEND_SERVICE_NAME ); 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir } // namespace script 502*cdf0e10cSrcweir } // namespace backend 503*cdf0e10cSrcweir } // namespace dp_registry 504*cdf0e10cSrcweir 505