diff options
Diffstat (limited to 'desktop/source/deployment/registry')
33 files changed, 3809 insertions, 1283 deletions
diff --git a/desktop/source/deployment/registry/component/dp_compbackenddb.cxx b/desktop/source/deployment/registry/component/dp_compbackenddb.cxx new file mode 100644 index 000000000000..898e7c931f6d --- /dev/null +++ b/desktop/source/deployment/registry/component/dp_compbackenddb.cxx @@ -0,0 +1,156 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "rtl/string.h" +#include "rtl/bootstrap.hxx" +#include "cppuhelper/exc_hlp.hxx" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "com/sun/star/xml/dom/XDocumentBuilder.hpp" +#include "com/sun/star/xml/xpath/XXPathAPI.hpp" +#include "dp_misc.h" + +#include "dp_compbackenddb.hxx" + + +namespace css = ::com::sun::star; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; + +#define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/component-registry/2010" +#define NS_PREFIX "comp" +#define ROOT_ELEMENT_NAME "component-backend-db" +#define KEY_ELEMENT_NAME "component" + +namespace dp_registry { +namespace backend { +namespace component { + +ComponentBackendDb::ComponentBackendDb( + Reference<XComponentContext> const & xContext, + ::rtl::OUString const & url):BackendDb(xContext, url) +{ + +} + +OUString ComponentBackendDb::getDbNSName() +{ + return OUSTR(EXTENSION_REG_NS); +} + +OUString ComponentBackendDb::getNSPrefix() +{ + return OUSTR(NS_PREFIX); +} + +OUString ComponentBackendDb::getRootElementName() +{ + return OUSTR(ROOT_ELEMENT_NAME); +} + +OUString ComponentBackendDb::getKeyElementName() +{ + return OUSTR(KEY_ELEMENT_NAME); +} + +void ComponentBackendDb::addEntry(::rtl::OUString const & url, Data const & data) +{ + try{ + Reference<css::xml::dom::XNode> componentNode = writeKeyElement(url); + writeSimpleElement(OUSTR("java-type-library"), + OUString::valueOf((sal_Bool) data.javaTypeLibrary), + componentNode); + + writeSimpleList( + data.implementationNames, + OUSTR("implementation-names"), + OUSTR("name"), + componentNode); + + writeVectorOfPair( + data.singletons, + OUSTR("singletons"), + OUSTR("item"), + OUSTR("key"), + OUSTR("value"), + componentNode); + + save(); + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to write data entry in backend db: ") + + m_urlDb, 0, exc); + } +} + +ComponentBackendDb::Data ComponentBackendDb::getEntry(::rtl::OUString const & url) +{ + try + { + ComponentBackendDb::Data retData; + Reference<css::xml::dom::XNode> aNode = getKeyElement(url); + if (aNode.is()) + { + bool bJava = readSimpleElement(OUSTR("java-type-library"), aNode) + .equals(OUSTR("true")) ? true : false; + retData.javaTypeLibrary = bJava; + + retData.implementationNames = + readList( + aNode, + OUSTR("implementation-names"), + OUSTR("name")); + + retData.singletons = + readVectorOfPair( + aNode, + OUSTR("singletons"), + OUSTR("item"), + OUSTR("key"), + OUSTR("value")); + } + return retData; + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to read data entry in backend db: ") + + m_urlDb, 0, exc); + } +} + + +} // namespace bundle +} // namespace backend +} // namespace dp_registry + diff --git a/desktop/source/deployment/registry/component/dp_compbackenddb.hxx b/desktop/source/deployment/registry/component/dp_compbackenddb.hxx new file mode 100644 index 000000000000..b9a5ed737b7c --- /dev/null +++ b/desktop/source/deployment/registry/component/dp_compbackenddb.hxx @@ -0,0 +1,120 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if ! defined INCLUDED_DP_COMPBACKENDDB_HXX +#define INCLUDED_DP_COMPBACKENDDB_HXX + +#include "rtl/ustring.hxx" +#include "rtl/string.hxx" +#include <vector> +#include <list> +#include "dp_backenddb.hxx" + +namespace css = ::com::sun::star; + +namespace com { namespace sun { namespace star { + namespace uno { + class XComponentContext; + } + namespace xml { namespace dom { + class XDocument; + class XNode; + }} + namespace xml { namespace xpath { + class XXPathAPI; + }} +}}} + +namespace dp_registry { +namespace backend { +namespace component { + +/* The XML file stores the extensions which are currently registered. + They will be removed when they are revoked. + The format looks like this: + +<?xml version="1.0"?> +<component-backend-db xmlns="http://openoffice.org/extensionmanager/component-registry/2010"> + <component url="vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE/uno_packages/5CD5.tmp_/leaves1.oxt/extensionoptions.jar"> + <name>FileName</name> + <java-type-library>true</java-type-library> + <implementation-names> + <name>com.sun.star.comp.extensionoptions.OptionsEventHandler$_OptionsEventHandler</name> + ... + </implementation-names> + <singletons> + <item> + <key>com.sun.star.java.theJavaVirtualMachine</key> + <value>com.sun.star.java.JavaVirtualMachine</value> + </item> + ... + </singletons> + </component> + + <component ...> + ... +</component-backend-db> + */ +class ComponentBackendDb: public dp_registry::backend::BackendDb +{ +protected: + virtual ::rtl::OUString getDbNSName(); + virtual ::rtl::OUString getNSPrefix(); + virtual ::rtl::OUString getRootElementName(); + virtual ::rtl::OUString getKeyElementName(); + +public: + struct Data + { + Data(): javaTypeLibrary(false) {}; + + ::std::list< ::rtl::OUString> implementationNames; + /* every singleton has a key and a value + */ + ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString> >singletons; + bool javaTypeLibrary; + }; + +public: + + ComponentBackendDb( css::uno::Reference<css::uno::XComponentContext> const & xContext, + ::rtl::OUString const & url); + + void addEntry(::rtl::OUString const & url, Data const & data); + + Data getEntry(::rtl::OUString const & url); + + +}; + + + +} +} +} +#endif + diff --git a/desktop/source/deployment/registry/component/dp_component.cxx b/desktop/source/deployment/registry/component/dp_component.cxx index e6781e2a1746..e0844c227669 100644 --- a/desktop/source/deployment/registry/component/dp_component.cxx +++ b/desktop/source/deployment/registry/component/dp_component.cxx @@ -58,7 +58,7 @@ #include <vector> #include <memory> #include <algorithm> - +#include "dp_compbackenddb.hxx" using namespace ::dp_misc; using namespace ::com::sun::star; @@ -74,6 +74,8 @@ namespace { typedef ::std::list<OUString> t_stringlist; typedef ::std::vector< ::std::pair<OUString, OUString> > t_stringpairvec; +#define IMPLEMENTATION_NAME "com.sun.star.comp.deployment.component.PackageRegistryBackend" + /** return a vector of bootstrap variables which have been provided as command arguments. */ @@ -119,7 +121,7 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend BackendImpl * getMyBackend() const; const OUString m_loader; - Reference<XComponentContext> m_xRemoteContext; + ComponentBackendDb::Data m_registeredComponentsDb; enum reg { REG_UNINIT, REG_VOID, REG_REGISTERED, REG_NOT_REGISTERED, REG_MAYBE_REGISTERED @@ -139,6 +141,7 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend virtual void processPackage_( ::osl::ResettableMutexGuard & guard, bool registerPackage, + bool startup, ::rtl::Reference<AbortChannel> const & abortChannel, Reference<XCommandEnvironment> const & xCmdEnv ); @@ -149,16 +152,12 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend const Reference<registry::XSimpleRegistry> getRDB_RO() const; public: - inline ComponentPackageImpl( + ComponentPackageImpl( ::rtl::Reference<PackageRegistryBackend> const & myBackend, OUString const & url, OUString const & name, Reference<deployment::XPackageTypeInfo> const & xPackageType, - OUString const & loader ) - : Package( myBackend, url, name, name /* display-name */, - xPackageType ), - m_loader( loader ), - m_registered( REG_UNINIT ) - {} + OUString const & loader, bool bRemoved, + OUString const & identifier); }; friend class ComponentPackageImpl; @@ -179,19 +178,17 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend virtual void processPackage_( ::osl::ResettableMutexGuard & guard, bool registerPackage, + bool startup, ::rtl::Reference<AbortChannel> const & abortChannel, Reference<XCommandEnvironment> const & xCmdEnv ); public: - inline TypelibraryPackageImpl( + TypelibraryPackageImpl( ::rtl::Reference<PackageRegistryBackend> const & myBackend, OUString const & url, OUString const & name, Reference<deployment::XPackageTypeInfo> const & xPackageType, - bool jarFile ) - : Package( myBackend, url, name, name /* display-name */, - xPackageType ), - m_jarFile( jarFile ) - {} + bool jarFile, bool bRemoved, + OUString const & identifier); }; friend class TypelibraryPackageImpl; @@ -212,6 +209,7 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend // PackageRegistryBackend virtual Reference<deployment::XPackage> bindPackage_( OUString const & url, OUString const & mediaType, + sal_Bool bRemoved, OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ); virtual void SAL_CALL disposing(); @@ -230,6 +228,13 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend OUString m_commonRDB_RO; OUString m_nativeRDB_RO; + std::auto_ptr<ComponentBackendDb> m_backendDb; + + void addDataToDb(OUString const & url, ComponentBackendDb::Data const & data); + void deleteDataFromDb(OUString const & url); + ComponentBackendDb::Data readDataFromDb(OUString const & url); + + //These rdbs are for writing new service entries. The rdb files are copies //which are created when services are added or removed. Reference<registry::XSimpleRegistry> m_xCommonRDB; @@ -275,6 +280,25 @@ public: }; //______________________________________________________________________________ + +BackendImpl::ComponentPackageImpl::ComponentPackageImpl( + ::rtl::Reference<PackageRegistryBackend> const & myBackend, + OUString const & url, OUString const & name, + Reference<deployment::XPackageTypeInfo> const & xPackageType, + OUString const & loader, bool bRemoved, + OUString const & identifier) + : Package( myBackend, url, name, name /* display-name */, + xPackageType, bRemoved, identifier), + m_loader( loader ), + m_registered( REG_UNINIT ) +{ + if (bRemoved) + { + m_registeredComponentsDb = getMyBackend()->readDataFromDb(url); + } +} + + const Reference<registry::XSimpleRegistry> BackendImpl::ComponentPackageImpl::getRDB() const { @@ -332,7 +356,7 @@ BackendImpl * BackendImpl::ComponentPackageImpl::getMyBackend() const //______________________________________________________________________________ void BackendImpl::ComponentPackageImpl::disposing() { - m_xRemoteContext.clear(); +// m_xRemoteContext.clear(); Package::disposing(); } @@ -371,59 +395,59 @@ void BackendImpl::disposing() } } + void BackendImpl::initServiceRdbFiles() { const Reference<XCommandEnvironment> xCmdEnv; - if (! m_readOnly) + + ::ucbhelper::Content cacheDir( getCachePath(), xCmdEnv ); + ::ucbhelper::Content oldRDB; + // switch common rdb: + if (m_commonRDB_RO.getLength() > 0) { - ::ucbhelper::Content cacheDir( getCachePath(), xCmdEnv ); - ::ucbhelper::Content oldRDB; - // switch common rdb: - if (m_commonRDB_RO.getLength() > 0) - { - create_ucb_content( - &oldRDB, makeURL( getCachePath(), m_commonRDB_RO), - xCmdEnv, false /* no throw */ ); - } - m_commonRDB = m_commonRDB_RO.equalsAsciiL( - RTL_CONSTASCII_STRINGPARAM("common.rdb") ) - ? OUSTR("common_.rdb") : OUSTR("common.rdb"); - if (oldRDB.get().is()) - { - if (! cacheDir.transferContent( + create_ucb_content( + &oldRDB, makeURL( getCachePath(), m_commonRDB_RO), + xCmdEnv, false /* no throw */ ); + } + m_commonRDB = m_commonRDB_RO.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("common.rdb") ) + ? OUSTR("common_.rdb") : OUSTR("common.rdb"); + if (oldRDB.get().is()) + { + if (! cacheDir.transferContent( oldRDB, ::ucbhelper::InsertOperation_COPY, m_commonRDB, NameClash::OVERWRITE )) - { - - throw RuntimeException( - OUSTR("UCB transferContent() failed!"), 0 ); - } - oldRDB = ::ucbhelper::Content(); - } - // switch native rdb: - if (m_nativeRDB_RO.getLength() > 0) { - create_ucb_content( - &oldRDB, makeURL(getCachePath(), m_nativeRDB_RO), - xCmdEnv, false /* no throw */ ); + + throw RuntimeException( + OUSTR("UCB transferContent() failed!"), 0 ); } - const OUString plt_rdb( getPlatformString() + OUSTR(".rdb") ); - const OUString plt_rdb_( getPlatformString() + OUSTR("_.rdb") ); - m_nativeRDB = m_nativeRDB_RO.equals( plt_rdb ) ? plt_rdb_ : plt_rdb; - if (oldRDB.get().is()) - { - if (! cacheDir.transferContent( + oldRDB = ::ucbhelper::Content(); + } + // switch native rdb: + if (m_nativeRDB_RO.getLength() > 0) + { + create_ucb_content( + &oldRDB, makeURL(getCachePath(), m_nativeRDB_RO), + xCmdEnv, false /* no throw */ ); + } + const OUString plt_rdb( getPlatformString() + OUSTR(".rdb") ); + const OUString plt_rdb_( getPlatformString() + OUSTR("_.rdb") ); + m_nativeRDB = m_nativeRDB_RO.equals( plt_rdb ) ? plt_rdb_ : plt_rdb; + if (oldRDB.get().is()) + { + if (! cacheDir.transferContent( oldRDB, ::ucbhelper::InsertOperation_COPY, m_nativeRDB, NameClash::OVERWRITE )) - throw RuntimeException( + throw RuntimeException( OUSTR("UCB transferContent() failed!"), 0 ); - } - - // UNO is bootstrapped, flush for next process start: - m_unorc_modified = true; - unorc_flush( Reference<XCommandEnvironment>() ); } + // UNO is bootstrapped, flush for next process start: + m_unorc_modified = true; + unorc_flush( Reference<XCommandEnvironment>() ); + + // common rdb for java, native rdb for shared lib components if (m_commonRDB.getLength() > 0) { m_xCommonRDB.set( @@ -433,7 +457,8 @@ void BackendImpl::initServiceRdbFiles() m_xComponentContext ), UNO_QUERY_THROW ); m_xCommonRDB->open( makeURL( expandUnoRcUrl(getCachePath()), m_commonRDB ), - m_readOnly, !m_readOnly ); +// m_readOnly, !m_readOnly ); + false, true); } if (m_nativeRDB.getLength() > 0) { m_xNativeRDB.set( @@ -443,7 +468,8 @@ void BackendImpl::initServiceRdbFiles() m_xComponentContext ), UNO_QUERY_THROW ); m_xNativeRDB->open( makeURL( expandUnoRcUrl(getCachePath()), m_nativeRDB ), - m_readOnly, !m_readOnly ); +// m_readOnly, !m_readOnly ); + false, true); } } @@ -562,9 +588,33 @@ BackendImpl::BackendImpl( initServiceRdbFiles_RO(); + OUString dbFile = makeURL(getCachePath(), OUSTR("backenddb.xml")); + m_backendDb.reset( + new ComponentBackendDb(getComponentContext(), dbFile)); } } +void BackendImpl::addDataToDb( + OUString const & url, ComponentBackendDb::Data const & data) +{ + if (m_backendDb.get()) + m_backendDb->addEntry(url, data); +} + +void BackendImpl::deleteDataFromDb(OUString const & url) +{ + if (m_backendDb.get()) + m_backendDb->removeEntry(url); +} + +ComponentBackendDb::Data BackendImpl::readDataFromDb(OUString const & url) +{ + ComponentBackendDb::Data data; + if (m_backendDb.get()) + data = m_backendDb->getEntry(url); + return data; +} + // XPackageRegistry //______________________________________________________________________________ Sequence< Reference<deployment::XPackageTypeInfo> > @@ -577,6 +627,7 @@ BackendImpl::getSupportedPackageTypes() throw (RuntimeException) //______________________________________________________________________________ Reference<deployment::XPackage> BackendImpl::bindPackage_( OUString const & url, OUString const & mediaType_, + sal_Bool bRemoved, OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ) { OUString mediaType(mediaType_); @@ -632,9 +683,14 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( { if (type.EqualsIgnoreCaseAscii("application")) { - ::ucbhelper::Content ucbContent( url, xCmdEnv ); - const OUString name( ucbContent.getPropertyValue( - StrTitle::get() ).get<OUString>() ); + OUString name; + if (!bRemoved) + { + ::ucbhelper::Content ucbContent( url, xCmdEnv ); + name = ucbContent.getPropertyValue( + StrTitle::get() ).get<OUString>(); + } + if (subType.EqualsIgnoreCaseAscii("vnd.sun.star.uno-component")) { // xxx todo: probe and evaluate component xml description @@ -649,17 +705,20 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( if (value.EqualsIgnoreCaseAscii("native")) { return new BackendImpl::ComponentPackageImpl( this, url, name, m_xDynComponentTypeInfo, - OUSTR("com.sun.star.loader.SharedLibrary") ); + OUSTR("com.sun.star.loader.SharedLibrary"), + bRemoved, identifier); } if (value.EqualsIgnoreCaseAscii("Java")) { return new BackendImpl::ComponentPackageImpl( this, url, name, m_xJavaComponentTypeInfo, - OUSTR("com.sun.star.loader.Java2") ); + OUSTR("com.sun.star.loader.Java2"), + bRemoved, identifier); } if (value.EqualsIgnoreCaseAscii("Python")) { return new BackendImpl::ComponentPackageImpl( this, url, name, m_xPythonComponentTypeInfo, - OUSTR("com.sun.star.loader.Python") ); + OUSTR("com.sun.star.loader.Python"), + bRemoved, identifier); } } } @@ -675,12 +734,12 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( { return new BackendImpl::TypelibraryPackageImpl( this, url, name, m_xRDBTypelibTypeInfo, - false /* rdb */ ); + false /* rdb */, bRemoved, identifier); } if (value.EqualsIgnoreCaseAscii("Java")) { return new BackendImpl::TypelibraryPackageImpl( this, url, name, m_xJavaTypelibTypeInfo, - true /* jar */ ); + true /* jar */, bRemoved, identifier); } } } @@ -717,16 +776,18 @@ void BackendImpl::unorc_verify_init( sal_Int32 index = sizeof ("UNO_JAVA_CLASSPATH=") - 1; do { OUString token( line.getToken( 0, ' ', index ).trim() ); - if (token.getLength() > 0) { - // cleanup, check if existing: + if (token.getLength() > 0) + { if (create_ucb_content( 0, expandUnoRcTerm(token), xCmdEnv, - false /* no throw */ )) { + false /* no throw */ )) + { + //The jar file may not exist anymore if a shared or bundled + //extension was removed, but it can still be in the unorc + //After running XExtensionManager::synchronize, the unorc is + //cleaned up m_jar_typelibs.push_back( token ); } - else - OSL_ENSURE( - 0, "### invalid UNO_JAVA_CLASSPATH entry!" ); } } while (index >= 0); @@ -736,17 +797,20 @@ void BackendImpl::unorc_verify_init( sal_Int32 index = sizeof ("UNO_TYPES=") - 1; do { OUString token( line.getToken( 0, ' ', index ).trim() ); - if (token.getLength() > 0) { + if (token.getLength() > 0) + { if (token[ 0 ] == '?') token = token.copy( 1 ); - // cleanup, check if existing: - if (create_ucb_content( - 0, expandUnoRcTerm(token), - xCmdEnv, false /* no throw */ )) { - m_rdb_typelibs.push_back( token ); - } - else - OSL_ENSURE( 0, "### invalid UNO_TYPES entry!" ); + if (create_ucb_content( + 0, expandUnoRcTerm(token), xCmdEnv, + false /* no throw */ )) + { + //The RDB file may not exist anymore if a shared or bundled + //extension was removed, but it can still be in the unorc. + //After running XExtensionManager::synchronize, the unorc is + //cleaned up + m_rdb_typelibs.push_back( token ); + } } } while (index >= 0); @@ -785,18 +849,11 @@ void BackendImpl::unorc_flush( Reference<XCommandEnvironment> const & xCmdEnv ) return; ::rtl::OStringBuffer buf; - // UNO_USER_PACKAGES_CACHE, UNO_SHARED_PACKAGES_CACHE have to be resolved - // locally: - if (m_eContext == CONTEXT_USER) { - buf.append( RTL_CONSTASCII_STRINGPARAM( - "UNO_USER_PACKAGES_CACHE=$ORIGIN/../..") ); - } - else if (m_eContext == CONTEXT_SHARED) { - buf.append( RTL_CONSTASCII_STRINGPARAM( - "UNO_SHARED_PACKAGES_CACHE=$ORIGIN/../..") ); - } - else - OSL_ASSERT(0); + + buf.append(RTL_CONSTASCII_STRINGPARAM("ORIGIN=")); + OUString sOrigin = dp_misc::makeRcTerm(m_cachePath); + ::rtl::OString osOrigin = ::rtl::OUStringToOString(sOrigin, RTL_TEXTENCODING_UTF8); + buf.append(osOrigin); buf.append(LF); if (! m_jar_typelibs.empty()) @@ -852,6 +909,9 @@ void BackendImpl::unorc_flush( Reference<XCommandEnvironment> const & xCmdEnv ) // write native rc: ::rtl::OStringBuffer buf2; + buf2.append(RTL_CONSTASCII_STRINGPARAM("ORIGIN=")); + buf2.append(osOrigin); + buf2.append(LF); buf2.append( RTL_CONSTASCII_STRINGPARAM("UNO_SERVICES=?$ORIGIN/") ); buf2.append( ::rtl::OUStringToOString( sNativeRDB, RTL_TEXTENCODING_ASCII_US ) ); @@ -882,28 +942,11 @@ void BackendImpl::unorc_flush( Reference<XCommandEnvironment> const & xCmdEnv ) m_unorc_modified = false; } -//------------------------------------------------------------------------------ -inline OUString makeRcTerm( OUString const & url ) -{ - OSL_ASSERT( url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( - "vnd.sun.star.expand:") ) ); - if (url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.expand:") )) { - // cut protocol: - OUString rcterm( url.copy( sizeof ("vnd.sun.star.expand:") - 1 ) ); - // decode uric class chars: - rcterm = ::rtl::Uri::decode( - rcterm, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); - return rcterm; - } - else - return url; -} - //______________________________________________________________________________ bool BackendImpl::addToUnoRc( bool jarFile, OUString const & url_, Reference<XCommandEnvironment> const & xCmdEnv ) { - const OUString rcterm( makeRcTerm(url_) ); + const OUString rcterm( dp_misc::makeRcTerm(url_) ); const ::osl::MutexGuard guard( getMutex() ); unorc_verify_init( xCmdEnv ); t_stringlist & rSet = getTypelibs(jarFile); @@ -923,7 +966,7 @@ bool BackendImpl::removeFromUnoRc( bool jarFile, OUString const & url_, Reference<XCommandEnvironment> const & xCmdEnv ) { - const OUString rcterm( makeRcTerm(url_) ); + const OUString rcterm( dp_misc::makeRcTerm(url_) ); const ::osl::MutexGuard guard( getMutex() ); unorc_verify_init( xCmdEnv ); getTypelibs(jarFile).remove( rcterm ); @@ -937,7 +980,7 @@ bool BackendImpl::removeFromUnoRc( bool BackendImpl::hasInUnoRc( bool jarFile, OUString const & url_ ) { - const OUString rcterm( makeRcTerm(url_) ); + const OUString rcterm( dp_misc::makeRcTerm(url_) ); const ::osl::MutexGuard guard( getMutex() ); t_stringlist const & rSet = getTypelibs(jarFile); return ::std::find( rSet.begin(), rSet.end(), rcterm ) != rSet.end(); @@ -1174,6 +1217,7 @@ BackendImpl::ComponentPackageImpl::isRegistered_( void BackendImpl::ComponentPackageImpl::processPackage_( ::osl::ResettableMutexGuard &, bool doRegisterPackage, + bool startup, ::rtl::Reference<AbortChannel> const & abortChannel, Reference<XCommandEnvironment> const & xCmdEnv ) { @@ -1183,16 +1227,25 @@ void BackendImpl::ComponentPackageImpl::processPackage_( const bool java = m_loader.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.loader.Java2") ); const OUString url( getURL() ); - bool isJavaTypelib = java && - !jarManifestHeaderPresent( url, OUSTR("UNO-Type-Path"), xCmdEnv ); + bool isJavaTypelib; + if (m_bRemoved) + isJavaTypelib = m_registeredComponentsDb.javaTypeLibrary; + else + isJavaTypelib = java && + !jarManifestHeaderPresent( url, OUSTR("UNO-Type-Path"), xCmdEnv ); + ComponentBackendDb::Data data; + data.javaTypeLibrary = isJavaTypelib; if (doRegisterPackage) { - if (! m_xRemoteContext.is()) { - m_xRemoteContext.set( + Reference <uno::XComponentContext> context(that->getComponentContext()); + if (! startup) + { + context.set( that->getObject( url ), UNO_QUERY ); - if (! m_xRemoteContext.is()) { - m_xRemoteContext.set( + + if (! context.is()) { + context.set( that->insertObject( url, raise_uno_process( that->getComponentContext(), abortChannel ) ), @@ -1202,147 +1255,170 @@ void BackendImpl::ComponentPackageImpl::processPackage_( const Reference<registry::XSimpleRegistry> xServicesRDB( getRDB() ); const Reference<registry::XImplementationRegistration> xImplReg( - m_xRemoteContext->getServiceManager()->createInstanceWithContext( + context->getServiceManager()->createInstanceWithContext( OUSTR("com.sun.star.registry.ImplementationRegistration"), - m_xRemoteContext ), UNO_QUERY_THROW ); + context ), UNO_QUERY_THROW ); xImplReg->registerImplementation( m_loader, url, xServicesRDB ); //only write to unorc if registration was successful. //It may fail if there is no suitable java. if (isJavaTypelib) + { that->addToUnoRc( java, url, xCmdEnv ); + data.javaTypeLibrary = true; + } t_stringlist implNames; t_stringpairvec singletons; - const Reference<loader::XImplementationLoader> xLoader( - getComponentInfo( &implNames, &singletons, m_xRemoteContext ) ); - - // factories live insertion: - const Reference<container::XSet> xSet( - that->getComponentContext()->getServiceManager(), UNO_QUERY_THROW ); - for ( t_stringlist::const_iterator iPos( implNames.begin() ); - iPos != implNames.end(); ++iPos ) + const Reference<loader::XImplementationLoader> xLoader( + getComponentInfo( &implNames, &singletons, context ) ); + data.implementationNames = implNames; + data.singletons = singletons; + + if (!startup) { - checkAborted( abortChannel ); - OUString const & implName = *iPos; - // activate factory: - const Reference<XInterface> xFactory( - xLoader->activate( - implName, OUString(), url, - xServicesRDB->getRootKey()->openKey( - OUSTR("/IMPLEMENTATIONS/") + implName ) ) ); - try { - xSet->insert( Any(xFactory) ); - } // ignore if factory has already been inserted: - catch (container::ElementExistException &) { - OSL_ENSURE( 0, "### factory already registered?" ); + // factories live insertion: + const Reference<container::XSet> xSet( + that->getComponentContext()->getServiceManager(), UNO_QUERY_THROW ); + for ( t_stringlist::const_iterator iPos( implNames.begin() ); + iPos != implNames.end(); ++iPos ) + { + checkAborted( abortChannel ); + OUString const & implName = *iPos; + // activate factory: + const Reference<XInterface> xFactory( + xLoader->activate( + implName, OUString(), url, + xServicesRDB->getRootKey()->openKey( + OUSTR("/IMPLEMENTATIONS/") + implName ) ) ); + try { + xSet->insert( Any(xFactory) ); + } // ignore if factory has already been inserted: + catch (container::ElementExistException &) { + OSL_ENSURE( 0, "### factory already registered?" ); + } } - } - if (! singletons.empty()) - { - // singletons live insertion: - const Reference<container::XNameContainer> xRootContext( - that->getComponentContext()->getValueByName( - OUSTR("_root") ), UNO_QUERY ); - if (xRootContext.is()) + if (! singletons.empty()) { - for ( t_stringpairvec::const_iterator iPos( - singletons.begin() ); - iPos != singletons.end(); ++iPos ) + // singletons live insertion: + const Reference<container::XNameContainer> xRootContext( + that->getComponentContext()->getValueByName( + OUSTR("_root") ), UNO_QUERY ); + if (xRootContext.is()) { - ::std::pair<OUString, OUString> const & sp = *iPos; - const OUString name( OUSTR("/singletons/") + sp.first ); - // assure no arguments: - try { - xRootContext->removeByName( name + OUSTR("/arguments")); - } catch (container::NoSuchElementException &) {} - // used service: - try { - xRootContext->insertByName( - name + OUSTR("/service"), Any(sp.second) ); - } catch (container::ElementExistException &) { - xRootContext->replaceByName( - name + OUSTR("/service"), Any(sp.second) ); - } - // singleton entry: - try { - xRootContext->insertByName( name, Any() ); - } catch (container::ElementExistException & exc) { - (void) exc; // avoid warnings - OSL_ENSURE( - 0, OUStringToOString( - exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); - xRootContext->replaceByName( name, Any() ); + for ( t_stringpairvec::const_iterator iPos( + singletons.begin() ); + iPos != singletons.end(); ++iPos ) + { + ::std::pair<OUString, OUString> const & sp = *iPos; + const OUString name( OUSTR("/singletons/") + sp.first ); + // assure no arguments: + try { + xRootContext->removeByName( name + OUSTR("/arguments")); + } catch (container::NoSuchElementException &) {} + // used service: + try { + xRootContext->insertByName( + name + OUSTR("/service"), Any(sp.second) ); + } catch (container::ElementExistException &) { + xRootContext->replaceByName( + name + OUSTR("/service"), Any(sp.second) ); + } + // singleton entry: + try { + xRootContext->insertByName( name, Any() ); + } catch (container::ElementExistException & exc) { + (void) exc; // avoid warnings + OSL_ENSURE( + 0, OUStringToOString( + exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); + xRootContext->replaceByName( name, Any() ); + } } } } } m_registered = REG_REGISTERED; + getMyBackend()->addDataToDb(url, data); } else // revokePackage() { // set to VOID during revocation process: m_registered = REG_VOID; - Reference<XComponentContext> xContext; - if (m_xRemoteContext.is()) // has been activated in this process - xContext = m_xRemoteContext; - else // has been deployed in former times + //get the remote context. If it does not exist then use the local one + Reference<XComponentContext> xContext( + that->getObject( url ), UNO_QUERY ); + bool bRemoteContext = false; + if (!xContext.is()) xContext = that->getComponentContext(); + else + bRemoteContext = true; t_stringlist implNames; t_stringpairvec singletons; - getComponentInfo( &implNames, &singletons, xContext ); - - // factories live removal: - const Reference<container::XSet> xSet( - that->getComponentContext()->getServiceManager(), UNO_QUERY_THROW ); - for ( t_stringlist::const_iterator iPos( implNames.begin() ); - iPos != implNames.end(); ++iPos ) + if (m_bRemoved) { - OUString const & implName = *iPos; - try { - xSet->remove( Any(implName) ); - } // ignore if factory has not been live deployed: - catch (container::NoSuchElementException &) { - } + implNames = m_registeredComponentsDb.implementationNames; + singletons = m_registeredComponentsDb.singletons; + } + else + { + getComponentInfo( &implNames, &singletons, xContext ); } - if (! singletons.empty()) + if (!startup) { - // singletons live removal: - const Reference<container::XNameContainer> xRootContext( - that->getComponentContext()->getValueByName( - OUSTR("_root") ), UNO_QUERY ); - if (xRootContext.is()) + // factories live removal: + const Reference<container::XSet> xSet( + that->getComponentContext()->getServiceManager(), UNO_QUERY_THROW ); + for ( t_stringlist::const_iterator iPos( implNames.begin() ); + iPos != implNames.end(); ++iPos ) + { + OUString const & implName = *iPos; + try { + xSet->remove( Any(implName) ); + } // ignore if factory has not been live deployed: + catch (container::NoSuchElementException &) { + } + } + + if (! singletons.empty()) { - for ( t_stringpairvec::const_iterator iPos( - singletons.begin() ); - iPos != singletons.end(); ++iPos ) + // singletons live removal: + const Reference<container::XNameContainer> xRootContext( + that->getComponentContext()->getValueByName( + OUSTR("_root") ), UNO_QUERY ); + if (xRootContext.is()) { - ::std::pair<OUString, OUString> const & sp = *iPos; - const OUString name( OUSTR("/singletons/") + sp.first ); - // arguments: - try { - xRootContext->removeByName( name + OUSTR("/arguments")); - } - catch (container::NoSuchElementException &) {} - // used service: - try { - xRootContext->removeByName( name + OUSTR("/service") ); - } - catch (container::NoSuchElementException &) {} - // singleton entry: - try { - xRootContext->removeByName( name ); - } - catch (container::NoSuchElementException & exc) { - (void) exc; // avoid warnings - OSL_ENSURE( - 0, OUStringToOString( - exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); + for ( t_stringpairvec::const_iterator iPos( + singletons.begin() ); + iPos != singletons.end(); ++iPos ) + { + ::std::pair<OUString, OUString> const & sp = *iPos; + const OUString name( OUSTR("/singletons/") + sp.first ); + // arguments: + try { + xRootContext->removeByName( name + OUSTR("/arguments")); + } + catch (container::NoSuchElementException &) {} + // used service: + try { + xRootContext->removeByName( name + OUSTR("/service") ); + } + catch (container::NoSuchElementException &) {} + // singleton entry: + try { + xRootContext->removeByName( name ); + } + catch (container::NoSuchElementException & exc) { + (void) exc; // avoid warnings + OSL_ENSURE( + 0, OUStringToOString( + exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); + } } } } @@ -1358,16 +1434,25 @@ void BackendImpl::ComponentPackageImpl::processPackage_( if (isJavaTypelib) that->removeFromUnoRc( java, url, xCmdEnv ); - if (m_xRemoteContext.is()) { + if (bRemoteContext) that->releaseObject( url ); - m_xRemoteContext.clear(); - } m_registered = REG_NOT_REGISTERED; + getMyBackend()->deleteDataFromDb(url); } } //############################################################################## +BackendImpl::TypelibraryPackageImpl::TypelibraryPackageImpl( + ::rtl::Reference<PackageRegistryBackend> const & myBackend, + OUString const & url, OUString const & name, + Reference<deployment::XPackageTypeInfo> const & xPackageType, + bool jarFile, bool bRemoved, OUString const & identifier) + : Package( myBackend, url, name, name /* display-name */, + xPackageType, bRemoved, identifier), + m_jarFile( jarFile ) +{ +} // Package BackendImpl * BackendImpl::TypelibraryPackageImpl::getMyBackend() const @@ -1403,6 +1488,7 @@ BackendImpl::TypelibraryPackageImpl::isRegistered_( void BackendImpl::TypelibraryPackageImpl::processPackage_( ::osl::ResettableMutexGuard &, bool doRegisterPackage, + bool /*startup*/, ::rtl::Reference<AbortChannel> const &, Reference<XCommandEnvironment> const & xCmdEnv ) { @@ -1490,7 +1576,7 @@ namespace sdecl = comphelper::service_decl; sdecl::class_<BackendImpl, sdecl::with_args<true> > serviceBI; extern sdecl::ServiceDecl const serviceDecl( serviceBI, - "com.sun.star.comp.deployment.component.PackageRegistryBackend", + IMPLEMENTATION_NAME, BACKEND_SERVICE_NAME ); } // namespace component diff --git a/desktop/source/deployment/registry/component/makefile.mk b/desktop/source/deployment/registry/component/makefile.mk index 4c4016f9bf6c..b7ee5c203cd5 100644 --- a/desktop/source/deployment/registry/component/makefile.mk +++ b/desktop/source/deployment/registry/component/makefile.mk @@ -40,7 +40,8 @@ SRC1FILES = \ INCPRE += ..$/..$/inc SLOFILES = \ - $(SLO)$/dp_component.obj + $(SLO)$/dp_component.obj \ + $(SLO)$/dp_compbackenddb.obj .INCLUDE : ..$/..$/target.pmk .INCLUDE : target.mk diff --git a/desktop/source/deployment/registry/configuration/dp_configuration.cxx b/desktop/source/deployment/registry/configuration/dp_configuration.cxx index 6cf6d4ff7818..9ea6e8227340 100644 --- a/desktop/source/deployment/registry/configuration/dp_configuration.cxx +++ b/desktop/source/deployment/registry/configuration/dp_configuration.cxx @@ -35,7 +35,6 @@ #include "dp_backend.h" #include "dp_persmap.h" #include "dp_ucb.h" -#include "dp_xml.h" #include "rtl/string.hxx" #include "rtl/ustrbuf.hxx" #include "rtl/uri.hxx" @@ -55,6 +54,7 @@ #include <list> #include <memory> +#include "dp_configurationbackenddb.hxx" using namespace ::dp_misc; using namespace ::com::sun::star; @@ -86,6 +86,7 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend virtual void processPackage_( ::osl::ResettableMutexGuard & guard, bool registerPackage, + bool startup, ::rtl::Reference<AbortChannel> const & abortChannel, Reference<XCommandEnvironment> const & xCmdEnv ); @@ -94,9 +95,9 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend ::rtl::Reference<PackageRegistryBackend> const & myBackend, OUString const & url, OUString const & name, Reference<deployment::XPackageTypeInfo> const & xPackageType, - bool isSchema ) + bool isSchema, bool bRemoved, OUString const & identifier) : Package( myBackend, url, name, name /* display-name */, - xPackageType ), + xPackageType, bRemoved, identifier), m_isSchema( isSchema ) {} }; @@ -110,10 +111,12 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend bool m_configmgrini_inited; bool m_configmgrini_modified; + std::auto_ptr<ConfigurationBackendDb> m_backendDb; // PackageRegistryBackend virtual Reference<deployment::XPackage> bindPackage_( - OUString const & url, OUString const & mediaType, + OUString const & url, OUString const & mediaType, sal_Bool bRemoved, + OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ); ::std::auto_ptr<PersistentMap> m_registeredPackages; @@ -133,7 +136,11 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend Reference<XCommandEnvironment> const & xCmdEnv ); bool removeFromConfigmgrIni( bool isSchema, OUString const & url, Reference<XCommandEnvironment> const & xCmdEnv ); - bool hasInConfigmgrIni( bool isSchema, OUString const & url ); + + void addDataToDb(OUString const & url, ConfigurationBackendDb::Data const & data); + ::boost::optional<ConfigurationBackendDb::Data> readDataFromDb(OUString const & url); + void deleteDataFromDb(OUString const & url); + ::std::list<OUString> getAllIniEntries(); public: BackendImpl( Sequence<Any> const & args, @@ -191,18 +198,64 @@ BackendImpl::BackendImpl( const Reference<XCommandEnvironment> xCmdEnv; - if (transientMode()) { + if (transientMode()) + { //TODO } - else { + else + { + OUString dbFile = makeURL(getCachePath(), OUSTR("backenddb.xml")); + m_backendDb.reset( + new ConfigurationBackendDb(getComponentContext(), dbFile)); + //clean up data folders which are no longer used. + //This must not be done in the same process where the help files + //are still registers. Only after revoking and restarting OOo the folders + //can be removed. This works now, because the extension manager is a singleton + //and the backends are only create once per process. + ::std::list<OUString> folders = m_backendDb->getAllDataUrls(); + deleteUnusedFolders(OUString(), folders); + + configmgrini_verify_init( xCmdEnv ); m_registeredPackages.reset( new PersistentMap( makeURL( getCachePath(), OUSTR("registered_packages.db") ), - m_readOnly ) ); - } + false ) ); + } } +void BackendImpl::addDataToDb( + OUString const & url, ConfigurationBackendDb::Data const & data) +{ + if (m_backendDb.get()) + m_backendDb->addEntry(url, data); +} + +::boost::optional<ConfigurationBackendDb::Data> BackendImpl::readDataFromDb( + OUString const & url) +{ + ::boost::optional<ConfigurationBackendDb::Data> data; + if (m_backendDb.get()) + data = m_backendDb->getEntry(url); + return data; +} + +void BackendImpl::deleteDataFromDb(OUString const & url) +{ + if (m_backendDb.get()) + m_backendDb->removeEntry(url); +} + +::std::list<OUString> BackendImpl::getAllIniEntries() +{ + if (m_backendDb.get()) + return m_backendDb->getAllIniEntries(); + else + return ::std::list<OUString>(); +} + + + // XPackageRegistry //______________________________________________________________________________ Sequence< Reference<deployment::XPackageTypeInfo> > @@ -215,6 +268,7 @@ BackendImpl::getSupportedPackageTypes() throw (RuntimeException) //______________________________________________________________________________ Reference<deployment::XPackage> BackendImpl::bindPackage_( OUString const & url, OUString const & mediaType_, + sal_Bool bRemoved, OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ) { OUString mediaType( mediaType_ ); @@ -249,20 +303,27 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( { if (type.EqualsIgnoreCaseAscii("application")) { + OUString name; + if (!bRemoved) + { + ::ucbhelper::Content ucbContent( url, xCmdEnv ); + name = ucbContent.getPropertyValue( + StrTitle::get() ).get<OUString>(); + } + ::ucbhelper::Content ucbContent( url, xCmdEnv ); if (subType.EqualsIgnoreCaseAscii( - "vnd.sun.star.configuration-data")) { + "vnd.sun.star.configuration-data")) + { return new PackageImpl( - this, url, ucbContent.getPropertyValue( - StrTitle::get() ).get<OUString>(), - m_xConfDataTypeInfo, false /* data file */ ); + this, url, name, m_xConfDataTypeInfo, false /* data file */, + bRemoved, identifier); } else if (subType.EqualsIgnoreCaseAscii( "vnd.sun.star.configuration-schema")) { return new PackageImpl( - this, url, ucbContent.getPropertyValue( - StrTitle::get() ).get<OUString>(), - m_xConfSchemaTypeInfo, true /* schema file */ ); + this, url, name, m_xConfSchemaTypeInfo, true /* schema file */, + bRemoved, identifier); } } } @@ -302,11 +363,12 @@ void BackendImpl::configmgrini_verify_init( if (create_ucb_content( 0, expandUnoRcTerm(token), xCmdEnv, false /* no throw */ )) { + //The file may not exist anymore if a shared or bundled + //extension was removed, but it can still be in the configmgrini. + //After running XExtensionManager::synchronize, the configmgrini is + //cleaned up m_xcs_files.push_back( token ); } - else - OSL_ENSURE( - 0, "### invalid SCHEMA entry!" ); } } while (index >= 0); @@ -323,10 +385,24 @@ void BackendImpl::configmgrini_verify_init( if (create_ucb_content( 0, expandUnoRcTerm(token), xCmdEnv, false /* no throw */ )) { + //The file may not exist anymore if a shared or bundled + //extension was removed, but it can still be in the configmgrini. + //After running XExtensionManager::synchronize, the configmgrini is + //cleaned up m_xcu_files.push_back( token ); } else - OSL_ENSURE( 0, "### invalid DATA entry!" ); + { + //Check if it was removed. Only when the file contained %origin, so that + //a new file was writen in the user installation (e.g. $BUNDLED_EXTENSIONS_USER) + //See also ConfigurationBackendDb.iniEntry + ::std::list<OUString> iniEntries = getAllIniEntries(); + if (::std::find(iniEntries.begin(), iniEntries.end(), token) + != iniEntries.end()) + m_xcu_files.push_back( token ); + else + OSL_ENSURE(0, "Extension manager: Invalid configmgr.ini entry."); + } } } while (index >= 0); @@ -347,20 +423,6 @@ void BackendImpl::configmgrini_flush( return; ::rtl::OStringBuffer buf; - // UNO_USER_PACKAGES_CACHE, UNO_SHARED_PACKAGES_CACHE have to be resolved - // locally: - if (m_eContext == CONTEXT_USER) { - buf.append( RTL_CONSTASCII_STRINGPARAM( - "UNO_USER_PACKAGES_CACHE=$ORIGIN/../..") ); - } - else if (m_eContext == CONTEXT_SHARED) { - buf.append( RTL_CONSTASCII_STRINGPARAM( - "UNO_SHARED_PACKAGES_CACHE=$ORIGIN/../..") ); - } - else - OSL_ASSERT(0); - buf.append(LF); - if (! m_xcs_files.empty()) { t_stringlist::const_iterator iPos( m_xcs_files.begin() ); @@ -407,28 +469,11 @@ void BackendImpl::configmgrini_flush( m_configmgrini_modified = false; } -//------------------------------------------------------------------------------ -inline OUString makeRcTerm( OUString const & url ) -{ - OSL_ASSERT( url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( - "vnd.sun.star.expand:") ) ); - if (url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.expand:") )) { - // cut protocol: - OUString rcterm( url.copy( sizeof ("vnd.sun.star.expand:") - 1 ) ); - // decode uric class chars: - rcterm = ::rtl::Uri::decode( - rcterm, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); - return rcterm; - } - else - return url; -} - //______________________________________________________________________________ bool BackendImpl::addToConfigmgrIni( bool isSchema, OUString const & url_, Reference<XCommandEnvironment> const & xCmdEnv ) { - const OUString rcterm( makeRcTerm(url_) ); + const OUString rcterm( dp_misc::makeRcTerm(url_) ); const ::osl::MutexGuard guard( getMutex() ); configmgrini_verify_init( xCmdEnv ); t_stringlist & rSet = getFiles(isSchema); @@ -448,15 +493,18 @@ bool BackendImpl::removeFromConfigmgrIni( bool isSchema, OUString const & url_, Reference<XCommandEnvironment> const & xCmdEnv ) { - const OUString rcterm( makeRcTerm(url_) ); + const OUString rcterm( dp_misc::makeRcTerm(url_) ); const ::osl::MutexGuard guard( getMutex() ); configmgrini_verify_init( xCmdEnv ); t_stringlist & rSet = getFiles(isSchema); t_stringlist::iterator i(std::find(rSet.begin(), rSet.end(), rcterm)); - if (i == rSet.end() && !isSchema) { //TODO: see replaceOrigin() - i = std::find( - rSet.begin(), rSet.end(), - rcterm + OUString(RTL_CONSTASCII_USTRINGPARAM(".mod"))); + if (i == rSet.end() && !isSchema) + { + //in case the xcu contained %origin% then the configmr.ini contains the + //url to the file in the user installation (e.g. $BUNDLED_EXTENSIONS_USER) + ::boost::optional<ConfigurationBackendDb::Data> data = readDataFromDb(url_); + if (data) + i = std::find(rSet.begin(), rSet.end(), data->iniEntry); } if (i == rSet.end()) { return false; @@ -468,21 +516,6 @@ bool BackendImpl::removeFromConfigmgrIni( return true; } -//______________________________________________________________________________ -bool BackendImpl::hasInConfigmgrIni( - bool isSchema, OUString const & url_ ) -{ - const OUString rcterm( makeRcTerm(url_) ); - const ::osl::MutexGuard guard( getMutex() ); - t_stringlist const & rSet = getFiles(isSchema); - return ::std::find( rSet.begin(), rSet.end(), rcterm ) != rSet.end() - || (!isSchema && //TODO: see replaceOrigin() - ::std::find( - rSet.begin(), rSet.end(), - rcterm + OUString(RTL_CONSTASCII_USTRINGPARAM(".mod"))) != - rSet.end()); -} - //############################################################################## // Package @@ -509,14 +542,18 @@ BackendImpl::PackageImpl::isRegistered_( Reference<XCommandEnvironment> const & ) { BackendImpl * that = getMyBackend(); - rtl::OUString url(getURL()); + const rtl::OUString url(getURL()); + + bool bReg = false; + if (that->readDataFromDb(getURL())) + bReg = true; + if (!bReg) + //fallback for user extension registered in berkeley DB + bReg = that->m_registeredPackages->has( + rtl::OUStringToOString( url, RTL_TEXTENCODING_UTF8 )); + return beans::Optional< beans::Ambiguous<sal_Bool> >( - true /* IsPresent */, - beans::Ambiguous<sal_Bool>( - that->hasInConfigmgrIni( m_isSchema, url ) || - that->m_registeredPackages->has( - rtl::OUStringToOString( url, RTL_TEXTENCODING_UTF8 ) ), - false /* IsAmbiguous */ ) ); + true, beans::Ambiguous<sal_Bool>( bReg, false ) ); } //------------------------------------------------------------------------------ @@ -554,7 +591,7 @@ OUString encodeForXml( OUString const & text ) //______________________________________________________________________________ OUString replaceOrigin( - OUString const & url, Reference< XCommandEnvironment > const & xCmdEnv ) + OUString const & url, OUString const & destFolder, Reference< XCommandEnvironment > const & xCmdEnv, bool & out_replaced) { // looking for %origin%: ::ucbhelper::Content ucb_content( url, xCmdEnv ); @@ -624,10 +661,17 @@ OUString replaceOrigin( return url; if (write_pos < filtered.getLength()) filtered.realloc( write_pos ); - rtl::OUString newUrl(url + OUString(RTL_CONSTASCII_USTRINGPARAM(".mod"))); - //TODO: unique name + rtl::OUString newUrl(url); + if (destFolder.getLength()) + { + //get the file name of the xcu and add it to the url of the temporary folder + sal_Int32 i = url.lastIndexOf('/'); + newUrl = destFolder + url.copy(i); + } + ucbhelper::Content(newUrl, xCmdEnv).writeStream( xmlscript::createInputStream(filtered), true); + out_replaced = true; return newUrl; } @@ -635,6 +679,7 @@ OUString replaceOrigin( void BackendImpl::PackageImpl::processPackage_( ::osl::ResettableMutexGuard &, bool doRegisterPackage, + bool startup, ::rtl::Reference<AbortChannel> const &, Reference<XCommandEnvironment> const & xCmdEnv ) { @@ -643,21 +688,38 @@ void BackendImpl::PackageImpl::processPackage_( if (doRegisterPackage) { - if (m_isSchema) + ConfigurationBackendDb::Data data; + if (!m_isSchema) { - com::sun::star::configuration::Update::get( - that->m_xComponentContext)->insertExtensionXcsFile( - that->m_eContext == CONTEXT_SHARED, expandUnoRcUrl(url)); + const OUString sModFolder = that->createFolder(OUString(), xCmdEnv); + bool out_replaced = false; + url = replaceOrigin(url, sModFolder, xCmdEnv, out_replaced); + if (out_replaced) + data.dataUrl = sModFolder; + else + deleteTempFolder(sModFolder); } - else + //No need for live-deployment for bundled extension, because OOo + //restarts after installation + if (that->m_eContext != CONTEXT_BUNDLED + && !startup) { - url = replaceOrigin(url, xCmdEnv); - com::sun::star::configuration::Update::get( - that->m_xComponentContext)->insertExtensionXcuFile( - that->m_eContext == CONTEXT_SHARED, expandUnoRcUrl(url)); + if (m_isSchema) + { + com::sun::star::configuration::Update::get( + that->m_xComponentContext)->insertExtensionXcsFile( + that->m_eContext == CONTEXT_SHARED, expandUnoRcUrl(url)); + } + else + { + com::sun::star::configuration::Update::get( + that->m_xComponentContext)->insertExtensionXcuFile( + that->m_eContext == CONTEXT_SHARED, expandUnoRcUrl(url)); + } } - that->addToConfigmgrIni( m_isSchema, url, xCmdEnv ); + data.iniEntry = dp_misc::makeRcTerm(url); + that->addDataToDb(getURL(), data); } else // revoke { @@ -667,15 +729,31 @@ void BackendImpl::PackageImpl::processPackage_( for (t_string2string_map::iterator i(entries.begin()); i != entries.end(); ++i) { + //If the xcu file was installed before the configmgr was chaned + //to use the configmgr.ini, one needed to rebuild to whole directory + //structur containing the xcu, xcs files from all extensions. Now, + //we just add all other xcu/xcs files to the configmgr.ini instead of + //rebuilding the directory structure. rtl::OUString url2( rtl::OStringToOUString(i->first, RTL_TEXTENCODING_UTF8)); + ConfigurationBackendDb::Data data; if (url2 != url) { - bool schema = i->second.equalsIgnoreAsciiCase( - "vnd.sun.star.configuration-schema"); - if (!schema) { - url2 = replaceOrigin(url2, xCmdEnv); - } - that->addToConfigmgrIni(schema, url2, xCmdEnv); + bool schema = i->second.equalsIgnoreAsciiCase( + "vnd.sun.star.configuration-schema"); + OUString url_replaced(url2); + if (!schema) + { + const OUString sModFolder = that->createFolder(OUString(), xCmdEnv); + bool out_replaced = false; + url_replaced = replaceOrigin( + url2, sModFolder, xCmdEnv, out_replaced); + if (out_replaced) + data.dataUrl = sModFolder; + else + deleteTempFolder(sModFolder); + } + that->addToConfigmgrIni(schema, url_replaced, xCmdEnv); + that->addDataToDb(url2, data); } that->m_registeredPackages->erase(i->first); } @@ -684,6 +762,7 @@ void BackendImpl::PackageImpl::processPackage_( xCmdEnv ).executeCommand( OUSTR("delete"), Any( true /* delete physically */ ) ); } + that->deleteDataFromDb(getURL()); //TODO: revoking at runtime, possible, sensible? } diff --git a/desktop/source/deployment/registry/configuration/dp_configurationbackenddb.cxx b/desktop/source/deployment/registry/configuration/dp_configurationbackenddb.cxx new file mode 100644 index 000000000000..845ba88cb813 --- /dev/null +++ b/desktop/source/deployment/registry/configuration/dp_configurationbackenddb.cxx @@ -0,0 +1,186 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dp_package.cxx,v $ + * $Revision: 1.34.16.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "rtl/string.h" +#include "rtl/bootstrap.hxx" +#include "cppuhelper/exc_hlp.hxx" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "com/sun/star/xml/dom/XDocumentBuilder.hpp" +#include "com/sun/star/xml/xpath/XXPathAPI.hpp" +#include "dp_misc.h" + +#include "dp_configurationbackenddb.hxx" + + +namespace css = ::com::sun::star; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; + +#define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/configuration-registry/2010" +#define NS_PREFIX "conf" +#define ROOT_ELEMENT_NAME "configuration-backend-db" +#define KEY_ELEMENT_NAME "configuration" + +namespace dp_registry { +namespace backend { +namespace configuration { + +ConfigurationBackendDb::ConfigurationBackendDb( + Reference<XComponentContext> const & xContext, + ::rtl::OUString const & url):BackendDb(xContext, url) +{ + +} + +OUString ConfigurationBackendDb::getDbNSName() +{ + return OUSTR(EXTENSION_REG_NS); +} + +OUString ConfigurationBackendDb::getNSPrefix() +{ + return OUSTR(NS_PREFIX); +} + +OUString ConfigurationBackendDb::getRootElementName() +{ + return OUSTR(ROOT_ELEMENT_NAME); +} + +OUString ConfigurationBackendDb::getKeyElementName() +{ + return OUSTR(KEY_ELEMENT_NAME); +} + + +void ConfigurationBackendDb::addEntry(::rtl::OUString const & url, Data const & data) +{ + try{ + Reference<css::xml::dom::XNode> helpNode + = writeKeyElement(url); + + writeSimpleElement(OUSTR("data-url"), data.dataUrl, helpNode); + writeSimpleElement(OUSTR("ini-entry"), data.iniEntry, helpNode); + save(); + } + catch (css::deployment::DeploymentException& ) + { + throw; + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to write data entry in configuration backend db: ") + + m_urlDb, 0, exc); + } +} + + +::boost::optional<ConfigurationBackendDb::Data> +ConfigurationBackendDb::getEntry(::rtl::OUString const & url) +{ + try + { + ConfigurationBackendDb::Data retData; + Reference<css::xml::dom::XNode> aNode = getKeyElement(url); + if (aNode.is()) + { + retData.dataUrl = readSimpleElement(OUSTR("data-url"), aNode); + retData.iniEntry = readSimpleElement(OUSTR("ini-entry"), aNode); + } + else + { + return ::boost::optional<Data>(); + } + return ::boost::optional<Data>(retData); + } + catch (css::deployment::DeploymentException& ) + { + throw; + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to read data entry in configuration backend db: ") + + m_urlDb, 0, exc); + } +} + +::std::list<OUString> ConfigurationBackendDb::getAllDataUrls() +{ + try + { + ::std::list<OUString> listRet; + Reference<css::xml::dom::XDocument> doc = getDocument(); + Reference<css::xml::dom::XNode> root = doc->getFirstChild(); + + Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI(); + const OUString sPrefix = getNSPrefix(); + OUString sExpression( + sPrefix + OUSTR(":configuration/") + sPrefix + OUSTR(":data-url/text()")); + Reference<css::xml::dom::XNodeList> nodes = + xpathApi->selectNodeList(root, sExpression); + if (nodes.is()) + { + sal_Int32 length = nodes->getLength(); + for (sal_Int32 i = 0; i < length; i++) + listRet.push_back(nodes->item(i)->getNodeValue()); + } + return listRet; + } + catch (css::deployment::DeploymentException& ) + { + throw; + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to read data entry in configuration backend db: ") + + m_urlDb, 0, exc); + } +} + +::std::list<OUString> ConfigurationBackendDb::getAllIniEntries() +{ + return getOneChildFromAllEntries(OUSTR("ini-entry")); +} + + + +} // namespace configuration +} // namespace backend +} // namespace dp_registry + diff --git a/desktop/source/deployment/registry/configuration/dp_configurationbackenddb.hxx b/desktop/source/deployment/registry/configuration/dp_configurationbackenddb.hxx new file mode 100644 index 000000000000..1b6c4f8973a4 --- /dev/null +++ b/desktop/source/deployment/registry/configuration/dp_configurationbackenddb.hxx @@ -0,0 +1,96 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dp_backend.h,v $ + * $Revision: 1.18 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if ! defined INCLUDED_DP_CONFIGURATIONBACKENDDB_HXX +#define INCLUDED_DP_CONFIGURATIONBACKENDDB_HXX + +#include "rtl/ustring.hxx" +#include "rtl/string.hxx" +#include <list> +#include "boost/optional.hpp" +#include "dp_backenddb.hxx" + +namespace css = ::com::sun::star; + +namespace com { namespace sun { namespace star { + namespace uno { + class XComponentContext; + } +}}} + +namespace dp_registry { +namespace backend { +namespace configuration { + +/* The XML file stores the extensions which are currently registered. + They will be removed when they are revoked. + */ +class ConfigurationBackendDb: public dp_registry::backend::BackendDb +{ +protected: + virtual ::rtl::OUString getDbNSName(); + + virtual ::rtl::OUString getNSPrefix(); + + virtual ::rtl::OUString getRootElementName(); + + virtual ::rtl::OUString getKeyElementName(); + +public: + struct Data + { + /* the URL to the folder containing the xcu or xcs files which contained + %origin% + */ + ::rtl::OUString dataUrl; + /* the URL of the xcu or xcs file which is written in to the configmgr.ini + */ + ::rtl::OUString iniEntry; + }; + +public: + + ConfigurationBackendDb( css::uno::Reference<css::uno::XComponentContext> const & xContext, + ::rtl::OUString const & url); + + void addEntry(::rtl::OUString const & url, Data const & data); + + ::boost::optional<Data> getEntry(::rtl::OUString const & url); + ::std::list< ::rtl::OUString> getAllDataUrls(); + ::std::list< ::rtl::OUString> getAllIniEntries(); +}; + + + +} +} +} +#endif + diff --git a/desktop/source/deployment/registry/configuration/makefile.mk b/desktop/source/deployment/registry/configuration/makefile.mk index f549b0e7b0f8..9bcbd50d4230 100644 --- a/desktop/source/deployment/registry/configuration/makefile.mk +++ b/desktop/source/deployment/registry/configuration/makefile.mk @@ -44,7 +44,8 @@ SRC1FILES = \ dp_configuration.src SLOFILES = \ - $(SLO)$/dp_configuration.obj + $(SLO)$/dp_configuration.obj \ + $(SLO)$/dp_configurationbackenddb.obj .INCLUDE : ..$/..$/target.pmk .INCLUDE : target.mk diff --git a/desktop/source/deployment/registry/dp_backend.cxx b/desktop/source/deployment/registry/dp_backend.cxx index c06b30be1669..d781ba9e40ef 100644 --- a/desktop/source/deployment/registry/dp_backend.cxx +++ b/desktop/source/deployment/registry/dp_backend.cxx @@ -31,12 +31,19 @@ #include "dp_backend.h" #include "dp_ucb.h" #include "rtl/uri.hxx" +#include "rtl/bootstrap.hxx" +#include "osl/file.hxx" #include "cppuhelper/exc_hlp.hxx" #include "comphelper/servicedecl.hxx" #include "comphelper/unwrapargs.hxx" #include "ucbhelper/content.hxx" #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp" +#include "com/sun/star/deployment/InvalidRemovedParameterException.hpp" +#include "com/sun/star/ucb/InteractiveAugmentedIOException.hpp" +#include "com/sun/star/ucb/IOErrorCode.hpp" #include "com/sun/star/beans/StringPair.hpp" +#include "com/sun/star/sdbc/XResultSet.hpp" +#include "com/sun/star/sdbc/XRow.hpp" using namespace ::dp_misc; @@ -88,6 +95,10 @@ PackageRegistryBackend::PackageRegistryBackend( m_eContext = CONTEXT_USER; else if (m_context.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("shared") )) m_eContext = CONTEXT_SHARED; + else if (m_context.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bundled") )) + m_eContext = CONTEXT_BUNDLED; + else if (m_context.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("tmp") )) + m_eContext = CONTEXT_TMP; else if (m_context.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.tdoc:/") )) m_eContext = CONTEXT_DOCUMENT; @@ -127,24 +138,41 @@ void PackageRegistryBackend::disposing() // XPackageRegistry //______________________________________________________________________________ Reference<deployment::XPackage> PackageRegistryBackend::bindPackage( - OUString const & url, OUString const & mediaType, - Reference<XCommandEnvironment> const & xCmdEnv ) - throw (deployment::DeploymentException, CommandFailedException, + OUString const & url, OUString const & mediaType, sal_Bool bRemoved, + OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ) + throw (deployment::DeploymentException, + deployment::InvalidRemovedParameterException, + ucb::CommandFailedException, lang::IllegalArgumentException, RuntimeException) { ::osl::ResettableMutexGuard guard( getMutex() ); check(); + t_string2ref::const_iterator const iFind( m_bound.find( url ) ); - if (iFind != m_bound.end()) { + if (iFind != m_bound.end()) + { Reference<deployment::XPackage> xPackage( iFind->second ); if (xPackage.is()) + { + if (mediaType.getLength() && + mediaType != xPackage->getPackageType()->getMediaType()) + throw lang::IllegalArgumentException + (OUSTR("XPackageRegistry::bindPackage: media type does not match"), + static_cast<OWeakObject*>(this), 1); + if (xPackage->isRemoved() != bRemoved) + throw deployment::InvalidRemovedParameterException( + OUSTR("XPackageRegistry::bindPackage: bRemoved parameter does not match"), + static_cast<OWeakObject*>(this), xPackage->isRemoved(), xPackage); return xPackage; + } } + guard.clear(); Reference<deployment::XPackage> xNewPackage; try { - xNewPackage = bindPackage_( url, mediaType, xCmdEnv ); + xNewPackage = bindPackage_( url, mediaType, bRemoved, + identifier, xCmdEnv ); } catch (RuntimeException &) { throw; @@ -166,6 +194,7 @@ Reference<deployment::XPackage> PackageRegistryBackend::bindPackage( } guard.reset(); + ::std::pair< t_string2ref::iterator, bool > insertion( m_bound.insert( t_string2ref::value_type( url, xNewPackage ) ) ); if (insertion.second) @@ -180,11 +209,105 @@ Reference<deployment::XPackage> PackageRegistryBackend::bindPackage( return xPackage; insertion.first->second = xNewPackage; } + guard.clear(); xNewPackage->addEventListener( this ); // listen for disposing events return xNewPackage; } +OUString PackageRegistryBackend::createFolder( + OUString const & relUrl, + Reference<ucb::XCommandEnvironment> const & xCmdEnv) +{ + OUString sDataFolder = makeURL(getCachePath(), relUrl); + //make sure the folder exist + ucbhelper::Content dataContent; + ::dp_misc::create_folder(&dataContent, sDataFolder, xCmdEnv); + + OUString sDataFolderURL = dp_misc::expandUnoRcUrl(sDataFolder); + + OUString tempEntry; + if (::osl::File::createTempFile( + &sDataFolderURL, 0, &tempEntry ) != ::osl::File::E_None) + throw RuntimeException( + OUSTR("::osl::File::createTempFile() failed!"), 0 ); + tempEntry = tempEntry.copy( tempEntry.lastIndexOf( '/' ) + 1 ); + OUString destFolder= makeURL(sDataFolder, tempEntry) + OUSTR("_"); + ::ucbhelper::Content destFolderContent; + dp_misc::create_folder( &destFolderContent, destFolder, xCmdEnv ); + + return destFolder; +} + +void PackageRegistryBackend::deleteTempFolder( + OUString const & folderUrl) +{ + OSL_ASSERT(folderUrl.getLength() + && folderUrl[folderUrl.getLength() - 1] == '_'); + if (folderUrl.getLength() + && folderUrl[folderUrl.getLength() - 1] == '_') + { + const OUString tempFile = folderUrl.copy(0, folderUrl.getLength() - 1); + erase_path( folderUrl, Reference<XCommandEnvironment>(), + false /* no throw: ignore errors */ ); + erase_path( tempFile, Reference<XCommandEnvironment>(), + false /* no throw: ignore errors */ ); + } +} + +void PackageRegistryBackend::deleteUnusedFolders( + OUString const & relUrl, + ::std::list< OUString> const & usedFolders) +{ + try + { + const OUString sDataFolder = makeURL(getCachePath(), relUrl); + ::ucbhelper::Content tempFolder( + sDataFolder, Reference<ucb::XCommandEnvironment>()); + Reference<sdbc::XResultSet> xResultSet( + tempFolder.createCursor( + Sequence<OUString>( &StrTitle::get(), 1 ), + ::ucbhelper::INCLUDE_DOCUMENTS_ONLY ) ); + // get all temp directories: + ::std::vector<OUString> tempEntries; + + char tmp[] = ".tmp"; + + while (xResultSet->next()) + { + OUString title( + Reference<sdbc::XRow>( + xResultSet, UNO_QUERY_THROW )->getString( + 1 /* Title */ ) ); + + if (title.endsWithAsciiL(tmp, sizeof(tmp) - 1)) + tempEntries.push_back( + makeURLAppendSysPathSegment(sDataFolder, title)); + } + + for ( ::std::size_t pos = 0; pos < tempEntries.size(); ++pos ) + { + //usedFolders contains the urls to the folders which have + //a trailing underscore + const OUString tempFolderName = tempEntries[ pos ] + OUSTR("_"); + + if (::std::find( usedFolders.begin(), usedFolders.end(), tempFolderName ) == + usedFolders.end()) + { + deleteTempFolder(tempFolderName); + } + } + } + catch (ucb::InteractiveAugmentedIOException& e) + { + //In case the folder containing all the data folder does not + //exist yet, we ignore the exception + if (e.Code != ucb::IOErrorCode_NOT_EXISTING) + throw e; + } + +} + //############################################################################## //______________________________________________________________________________ @@ -195,16 +318,30 @@ Package::~Package() //______________________________________________________________________________ Package::Package( ::rtl::Reference<PackageRegistryBackend> const & myBackend, OUString const & url, - OUString const & name, + OUString const & rName, OUString const & displayName, - Reference<deployment::XPackageTypeInfo> const & xPackageType ) + Reference<deployment::XPackageTypeInfo> const & xPackageType, + bool bRemoved, + OUString const & identifier) : t_PackageBase( getMutex() ), m_myBackend( myBackend ), m_url( url ), - m_name( name ), + m_name( rName ), m_displayName( displayName ), - m_xPackageType( xPackageType ) + m_xPackageType( xPackageType ), + m_bRemoved(bRemoved), + m_identifier(identifier) { + if (m_bRemoved) + { + //We use the last segment of the URL + OSL_ASSERT(m_name.getLength() == 0); + OUString name = m_url; + rtl::Bootstrap::expandMacros(name); + sal_Int32 index = name.lastIndexOf('/'); + if (index != -1 && index < name.getLength()) + m_name = name.copy(index + 1); + } } //______________________________________________________________________________ @@ -294,25 +431,31 @@ sal_Bool Package::isBundle() throw (RuntimeException) } //______________________________________________________________________________ -::sal_Bool Package::checkPrerequisites( +::sal_Int32 Package::checkPrerequisites( const css::uno::Reference< css::task::XAbortChannel >&, const css::uno::Reference< css::ucb::XCommandEnvironment >&, - sal_Bool, ::rtl::OUString const &) + sal_Bool) throw (css::deployment::DeploymentException, - css::ucb::CommandFailedException, - css::ucb::CommandAbortedException, - css::uno::RuntimeException) + css::deployment::ExtensionRemovedException, + css::ucb::CommandFailedException, + css::ucb::CommandAbortedException, + css::uno::RuntimeException) { - return true; + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); + return 0; } //______________________________________________________________________________ ::sal_Bool Package::checkDependencies( const css::uno::Reference< css::ucb::XCommandEnvironment >& ) throw (css::deployment::DeploymentException, - css::ucb::CommandFailedException, - css::uno::RuntimeException) + css::deployment::ExtensionRemovedException, + css::ucb::CommandFailedException, + css::uno::RuntimeException) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); return true; } @@ -336,12 +479,19 @@ OUString Package::getName() throw (RuntimeException) beans::Optional<OUString> Package::getIdentifier() throw (RuntimeException) { + if (m_bRemoved) + return beans::Optional<OUString>(true, m_identifier); + return beans::Optional<OUString>(); } //______________________________________________________________________________ -OUString Package::getVersion() throw (RuntimeException) +OUString Package::getVersion() throw ( + deployment::ExtensionRemovedException, + RuntimeException) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); return OUString(); } @@ -352,33 +502,49 @@ OUString Package::getURL() throw (RuntimeException) } //______________________________________________________________________________ -OUString Package::getDisplayName() throw (RuntimeException) +OUString Package::getDisplayName() throw ( + deployment::ExtensionRemovedException, RuntimeException) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); return m_displayName; } //______________________________________________________________________________ -OUString Package::getDescription() throw (RuntimeException) +OUString Package::getDescription() throw ( + deployment::ExtensionRemovedException,RuntimeException) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); return OUString(); } //______________________________________________________________________________ -Sequence<OUString> Package::getUpdateInformationURLs() throw (RuntimeException) +Sequence<OUString> Package::getUpdateInformationURLs() throw ( + deployment::ExtensionRemovedException, RuntimeException) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); return Sequence<OUString>(); } //______________________________________________________________________________ -css::beans::StringPair Package::getPublisherInfo() throw (RuntimeException) +css::beans::StringPair Package::getPublisherInfo() throw ( + deployment::ExtensionRemovedException, RuntimeException) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); css::beans::StringPair aEmptyPair; return aEmptyPair; } //______________________________________________________________________________ -uno::Reference< css::graphic::XGraphic > Package::getIcon( sal_Bool /*bHighContrast*/ ) throw ( RuntimeException ) +uno::Reference< css::graphic::XGraphic > Package::getIcon( sal_Bool /*bHighContrast*/ ) + throw (deployment::ExtensionRemovedException, RuntimeException ) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); + uno::Reference< css::graphic::XGraphic > aEmpty; return aEmpty; } @@ -394,8 +560,12 @@ Reference<deployment::XPackageTypeInfo> Package::getPackageType() void Package::exportTo( OUString const & destFolderURL, OUString const & newTitle, sal_Int32 nameClashAction, Reference<XCommandEnvironment> const & xCmdEnv ) - throw (CommandFailedException, CommandAbortedException, RuntimeException) + throw (deployment::ExtensionRemovedException, + CommandFailedException, CommandAbortedException, RuntimeException) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); + ::ucbhelper::Content destFolder( destFolderURL, xCmdEnv ); ::ucbhelper::Content sourceContent( getURL(), xCmdEnv ); if (! destFolder.transferContent( @@ -461,6 +631,7 @@ beans::Optional< beans::Ambiguous<sal_Bool> > Package::isRegistered( //______________________________________________________________________________ void Package::processPackage_impl( bool doRegisterPackage, + bool startup, Reference<task::XAbortChannel> const & xAbortChannel, Reference<XCommandEnvironment> const & xCmdEnv ) { @@ -478,7 +649,8 @@ void Package::processPackage_impl( (doRegisterPackage ? !option.Value.Value : option.Value.Value))); if (action) { - OUString displayName( getDisplayName() ); + + OUString displayName = isRemoved() ? getName() : getDisplayName(); ProgressLevel progress( xCmdEnv, (doRegisterPackage @@ -487,6 +659,7 @@ void Package::processPackage_impl( + displayName ); processPackage_( guard, doRegisterPackage, + startup, AbortChannel::get(xAbortChannel), xCmdEnv ); } @@ -524,13 +697,17 @@ void Package::processPackage_impl( //______________________________________________________________________________ void Package::registerPackage( + sal_Bool startup, Reference<task::XAbortChannel> const & xAbortChannel, Reference<XCommandEnvironment> const & xCmdEnv ) throw (deployment::DeploymentException, + deployment::ExtensionRemovedException, CommandFailedException, CommandAbortedException, lang::IllegalArgumentException, RuntimeException) { - processPackage_impl( true /* register */, xAbortChannel, xCmdEnv ); + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); + processPackage_impl( true /* register */, startup, xAbortChannel, xCmdEnv ); } //______________________________________________________________________________ @@ -541,7 +718,44 @@ void Package::revokePackage( CommandFailedException, CommandAbortedException, lang::IllegalArgumentException, RuntimeException) { - processPackage_impl( false /* revoke */, xAbortChannel, xCmdEnv ); + processPackage_impl( false /* revoke */, false, xAbortChannel, xCmdEnv ); + +} + +PackageRegistryBackend * Package::getMyBackend() const +{ + PackageRegistryBackend * pBackend = m_myBackend.get(); + if (NULL == pBackend) + { + //May throw a DisposedException + check(); + //We should never get here... + throw RuntimeException( + OUSTR("Failed to get the BackendImpl"), + static_cast<OWeakObject*>(const_cast<Package *>(this))); + } + return pBackend; +} +OUString Package::getRepositoryName() + throw (RuntimeException) +{ + PackageRegistryBackend * backEnd = getMyBackend(); + return backEnd->getContext(); +} + +beans::Optional< OUString > Package::getRegistrationDataURL() + throw (deployment::ExtensionRemovedException, + css::uno::RuntimeException) +{ + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); + return beans::Optional<OUString>(); +} + +sal_Bool Package::isRemoved() + throw (RuntimeException) +{ + return m_bRemoved; } //############################################################################## @@ -559,13 +773,15 @@ OUString Package::TypeInfo::getMediaType() throw (RuntimeException) } //______________________________________________________________________________ -OUString Package::TypeInfo::getDescription() throw (RuntimeException) +OUString Package::TypeInfo::getDescription() + throw (deployment::ExtensionRemovedException, RuntimeException) { return getShortDescription(); } //______________________________________________________________________________ -OUString Package::TypeInfo::getShortDescription() throw (RuntimeException) +OUString Package::TypeInfo::getShortDescription() + throw (deployment::ExtensionRemovedException, RuntimeException) { return m_shortDescr; } diff --git a/desktop/source/deployment/registry/dp_backenddb.cxx b/desktop/source/deployment/registry/dp_backenddb.cxx new file mode 100644 index 000000000000..14b4f2374c5b --- /dev/null +++ b/desktop/source/deployment/registry/dp_backenddb.cxx @@ -0,0 +1,649 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "rtl/string.h" +#include "rtl/strbuf.hxx" +#include "rtl/bootstrap.hxx" +#include "cppuhelper/exc_hlp.hxx" +#include "osl/file.hxx" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "com/sun/star/xml/dom/XDocumentBuilder.hpp" +#include "com/sun/star/xml/xpath/XXPathAPI.hpp" +#include "com/sun/star/io/XActiveDataSource.hpp" +#include "com/sun/star/io/XActiveDataControl.hpp" +#include "dp_ucb.h" +#include "dp_misc.h" +#include "ucbhelper/content.hxx" +#include "xmlscript/xml_helper.hxx" +#include "dp_backenddb.hxx" + + +namespace css = ::com::sun::star; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; + + +namespace dp_registry { +namespace backend { + +BackendDb::BackendDb( + Reference<css::uno::XComponentContext> const & xContext, + ::rtl::OUString const & url): + m_xContext(xContext) +{ + m_urlDb = dp_misc::expandUnoRcUrl(url); +} + +void BackendDb::save() +{ + const Reference<css::io::XActiveDataSource> xDataSource(m_doc,css::uno::UNO_QUERY_THROW); + ::rtl::ByteSequence bytes; + xDataSource->setOutputStream(::xmlscript::createOutputStream(&bytes)); + const Reference<css::io::XActiveDataControl> xDataControl(m_doc,css::uno::UNO_QUERY_THROW); + xDataControl->start(); + + const Reference<css::io::XInputStream> xData( + ::xmlscript::createInputStream(bytes)); + ::ucbhelper::Content ucbDb(m_urlDb, 0); + ucbDb.writeStream(xData, true /*replace existing*/); +} + +css::uno::Reference<css::xml::dom::XDocument> BackendDb::getDocument() +{ + if (!m_doc.is()) + { + const Reference<css::xml::dom::XDocumentBuilder> xDocBuilder( + m_xContext->getServiceManager()->createInstanceWithContext( + OUSTR("com.sun.star.xml.dom.DocumentBuilder"), + m_xContext ), css::uno::UNO_QUERY); + if (!xDocBuilder.is()) + throw css::uno::RuntimeException( + OUSTR(" Could not create service com.sun.star.xml.dom.DocumentBuilder"), 0); + + ::osl::DirectoryItem item; + ::osl::File::RC err = ::osl::DirectoryItem::get(m_urlDb, item); + if (err == ::osl::File::E_None) + { + m_doc = xDocBuilder->parseURI(m_urlDb); + } + else if (err == ::osl::File::E_NOENT) + { + //Create a new document and insert some basic stuff + m_doc = xDocBuilder->newDocument(); + const Reference<css::xml::dom::XElement> rootNode = + m_doc->createElementNS(getDbNSName(), getNSPrefix() + + OUSTR(":") + getRootElementName()); + + m_doc->appendChild(Reference<css::xml::dom::XNode>( + rootNode, UNO_QUERY_THROW)); + save(); + } + else + throw css::uno::RuntimeException( + OUSTR("Extension manager could not access database file:" ) + + m_urlDb, 0); + + if (!m_doc.is()) + throw css::uno::RuntimeException( + OUSTR("Extension manager could not get root node of data base file: ") + + m_urlDb, 0); + } + + return m_doc; +} + +Reference<css::xml::xpath::XXPathAPI> BackendDb::getXPathAPI() +{ + if (!m_xpathApi.is()) + { + m_xpathApi = Reference< css::xml::xpath::XXPathAPI >( + m_xContext->getServiceManager()->createInstanceWithContext( + OUSTR("com.sun.star.xml.xpath.XPathAPI"), + m_xContext), css::uno::UNO_QUERY); + + if (!m_xpathApi.is()) + throw css::uno::RuntimeException( + OUSTR(" Could not create service com.sun.star.xml.xpath.XPathAPI"), 0); + + m_xpathApi->registerNS( + getNSPrefix(), getDbNSName()); + } + + return m_xpathApi; +} + +void BackendDb::removeElement(::rtl::OUString const & sXPathExpression) +{ + try + { + const Reference<css::xml::dom::XDocument> doc = getDocument(); + const Reference<css::xml::dom::XNode> root = doc->getFirstChild(); + const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI(); + //find the extension element that is to be removed + const Reference<css::xml::dom::XNode> aNode = + xpathApi->selectSingleNode(root, sXPathExpression); + + if (aNode.is()) + { + root->removeChild(aNode); + save(); + } + +#if OSL_DEBUG_LEVEL > 0 + //There must not be any other entry with the same url + const Reference<css::xml::dom::XNode> nextNode = + xpathApi->selectSingleNode(root, sXPathExpression); + OSL_ASSERT(! nextNode.is()); +#endif + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to write data entry in backend db: ") + + m_urlDb, 0, exc); + } +} + +void BackendDb::removeEntry(::rtl::OUString const & url) +{ + const OUString sKeyElement = getKeyElementName(); + const OUString sPrefix = getNSPrefix(); + ::rtl::OUStringBuffer sExpression(500); + sExpression.append(sPrefix); + sExpression.appendAscii(":"); + sExpression.append(sKeyElement); + sExpression.append(OUSTR("[@url = \"")); + sExpression.append(url); + sExpression.appendAscii("\"]"); + + removeElement(sExpression.makeStringAndClear()); +} + +Reference<css::xml::dom::XNode> BackendDb::getKeyElement( + ::rtl::OUString const & url) +{ + try + { + const OUString sPrefix = getNSPrefix(); + const OUString sKeyElement = getKeyElementName(); + ::rtl::OUStringBuffer sExpression(500); + sExpression.append(sPrefix); + sExpression.appendAscii(":"); + sExpression.append(sKeyElement); + sExpression.append(OUSTR("[@url = \"")); + sExpression.append(url); + sExpression.appendAscii("\"]"); + + const Reference<css::xml::dom::XDocument> doc = getDocument(); + const Reference<css::xml::dom::XNode> root = doc->getFirstChild(); + const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI(); + return xpathApi->selectSingleNode(root, sExpression.makeStringAndClear()); + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to read key element in backend db: ") + + m_urlDb, 0, exc); + } +} + +//Only writes the data if there is at least one entry +void BackendDb::writeVectorOfPair( + ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > > const & vecPairs, + OUString const & sVectorTagName, + OUString const & sPairTagName, + OUString const & sFirstTagName, + OUString const & sSecondTagName, + css::uno::Reference<css::xml::dom::XNode> const & xParent) +{ + try{ + if (vecPairs.size() == 0) + return; + const OUString sNameSpace = getDbNSName(); + OSL_ASSERT(sNameSpace.getLength()); + const OUString sPrefix(getNSPrefix() + OUSTR(":")); + const Reference<css::xml::dom::XDocument> doc = getDocument(); + const Reference<css::xml::dom::XNode> root = doc->getFirstChild(); + + const Reference<css::xml::dom::XElement> vectorNode( + doc->createElementNS(sNameSpace, sPrefix + sVectorTagName)); + + xParent->appendChild( + Reference<css::xml::dom::XNode>( + vectorNode, css::uno::UNO_QUERY_THROW)); + typedef ::std::vector< ::std::pair< OUString, OUString > >::const_iterator CIT; + for (CIT i = vecPairs.begin(); i != vecPairs.end(); i++) + { + const Reference<css::xml::dom::XElement> pairNode( + doc->createElementNS(sNameSpace, sPrefix + sPairTagName)); + + vectorNode->appendChild( + Reference<css::xml::dom::XNode>( + pairNode, css::uno::UNO_QUERY_THROW)); + + const Reference<css::xml::dom::XElement> firstNode( + doc->createElementNS(sNameSpace, sPrefix + sFirstTagName)); + + pairNode->appendChild( + Reference<css::xml::dom::XNode>( + firstNode, css::uno::UNO_QUERY_THROW)); + + const Reference<css::xml::dom::XText> firstTextNode( + doc->createTextNode( i->first)); + + firstNode->appendChild( + Reference<css::xml::dom::XNode>( + firstTextNode, css::uno::UNO_QUERY_THROW)); + + const Reference<css::xml::dom::XElement> secondNode( + doc->createElementNS(sNameSpace, sPrefix + sSecondTagName)); + + pairNode->appendChild( + Reference<css::xml::dom::XNode>( + secondNode, css::uno::UNO_QUERY_THROW)); + + const Reference<css::xml::dom::XText> secondTextNode( + doc->createTextNode( i->second)); + + secondNode->appendChild( + Reference<css::xml::dom::XNode>( + secondTextNode, css::uno::UNO_QUERY_THROW)); + } + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to write data entry in backend db: ") + + m_urlDb, 0, exc); + } +} + +::std::vector< ::std::pair< OUString, OUString > > +BackendDb::readVectorOfPair( + Reference<css::xml::dom::XNode> const & parent, + OUString const & sListTagName, + OUString const & sPairTagName, + OUString const & sFirstTagName, + OUString const & sSecondTagName) +{ + try + { + OSL_ASSERT(parent.is()); + const OUString sPrefix(getNSPrefix() + OUSTR(":")); + const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI(); + const OUString sExprPairs( + sPrefix + sListTagName + OUSTR("/") + sPrefix + sPairTagName); + const Reference<css::xml::dom::XNodeList> listPairs = + xpathApi->selectNodeList(parent, sExprPairs); + + ::std::vector< ::std::pair< OUString, OUString > > retVector; + sal_Int32 length = listPairs->getLength(); + for (sal_Int32 i = 0; i < length; i++) + { + const Reference<css::xml::dom::XNode> aPair = listPairs->item(i); + const OUString sExprFirst(sPrefix + sFirstTagName + OUSTR("/text()")); + const Reference<css::xml::dom::XNode> first = + xpathApi->selectSingleNode(aPair, sExprFirst); + + const OUString sExprSecond(sPrefix + sSecondTagName + OUSTR("/text()")); + const Reference<css::xml::dom::XNode> second = + xpathApi->selectSingleNode(aPair, sExprSecond); + OSL_ASSERT(first.is() && second.is()); + + retVector.push_back(::std::make_pair( + first->getNodeValue(), second->getNodeValue())); + } + return retVector; + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to read data entry in backend db: ") + + m_urlDb, 0, exc); + } +} + +//Only writes the data if there is at least one entry +void BackendDb::writeSimpleList( + ::std::list< ::rtl::OUString> const & list, + OUString const & sListTagName, + OUString const & sMemberTagName, + Reference<css::xml::dom::XNode> const & xParent) +{ + try + { + if (list.size() == 0) + return; + const OUString sNameSpace = getDbNSName(); + const OUString sPrefix(getNSPrefix() + OUSTR(":")); + const Reference<css::xml::dom::XDocument> doc = getDocument(); + + const Reference<css::xml::dom::XElement> listNode( + doc->createElementNS(sNameSpace, sPrefix + sListTagName)); + + xParent->appendChild( + Reference<css::xml::dom::XNode>( + listNode, css::uno::UNO_QUERY_THROW)); + + typedef ::std::list<OUString>::const_iterator ITC_ITEMS; + for (ITC_ITEMS i = list.begin(); i != list.end(); i++) + { + const Reference<css::xml::dom::XNode> memberNode( + doc->createElementNS(sNameSpace, sPrefix + sMemberTagName), css::uno::UNO_QUERY_THROW); + + listNode->appendChild(memberNode); + + const Reference<css::xml::dom::XNode> textNode( + doc->createTextNode( *i), css::uno::UNO_QUERY_THROW); + + memberNode->appendChild(textNode); + } + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to write data entry in backend db: ") + + m_urlDb, 0, exc); + } +} + +//Writes only the element if is has a value. +//The prefix is automatically added to the element name +void BackendDb::writeSimpleElement( + OUString const & sElementName, OUString const & value, + Reference<css::xml::dom::XNode> const & xParent) +{ + try + { + if (value.getLength() == 0) + return; + const OUString sPrefix = getNSPrefix(); + const Reference<css::xml::dom::XDocument> doc = getDocument(); + const OUString sNameSpace = getDbNSName(); + const Reference<css::xml::dom::XNode> dataNode( + doc->createElementNS(sNameSpace, sPrefix + OUSTR(":") + sElementName), + UNO_QUERY_THROW); + xParent->appendChild(dataNode); + + const Reference<css::xml::dom::XNode> dataValue( + doc->createTextNode(value), UNO_QUERY_THROW); + dataNode->appendChild(dataValue); + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to write data entry(writeSimpleElement) in backend db: ") + + m_urlDb, 0, exc); + } + +} + +/** The key elements have an url attribute and are always children of the root + element. +*/ +Reference<css::xml::dom::XNode> BackendDb::writeKeyElement( + ::rtl::OUString const & url) +{ + try + { + const OUString sNameSpace = getDbNSName(); + const OUString sPrefix = getNSPrefix(); + const OUString sElementName = getKeyElementName(); + const Reference<css::xml::dom::XDocument> doc = getDocument(); + const Reference<css::xml::dom::XNode> root = doc->getFirstChild(); + + //Check if there are an entry with the same url. This can be the case if the + //the status of an XPackage is ambiguous. In this case a call to activateExtension + //(dp_extensionmanager.cxx), will register the package again. See also + //Package::processPackage_impl in dp_backend.cxx. + //A package can become + //invalid after its successful registration, for example if a second extension with + //the same service is installed. + const OUString sExpression( + sPrefix + OUSTR(":") + sElementName + OUSTR("[@url = \"") + url + OUSTR("\"]")); + const Reference<css::xml::dom::XNode> existingNode = + getXPathAPI()->selectSingleNode(root, sExpression); + if (existingNode.is()) + { + OSL_ASSERT(0); + //replace the existing entry. + removeEntry(url); + } + + const Reference<css::xml::dom::XElement> keyElement( + doc->createElementNS(sNameSpace, sPrefix + OUSTR(":") + sElementName)); + + keyElement->setAttribute(OUSTR("url"), url); + + const Reference<css::xml::dom::XNode> keyNode( + keyElement, UNO_QUERY_THROW); + root->appendChild(keyNode); + return keyNode; + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to write key element in backend db: ") + + m_urlDb, 0, exc); + } +} + +OUString BackendDb::readSimpleElement( + OUString const & sElementName, Reference<css::xml::dom::XNode> const & xParent) +{ + try + { + const OUString sPrefix = getNSPrefix(); + const OUString sExpr(sPrefix + OUSTR(":") + sElementName + OUSTR("/text()")); + const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI(); + const Reference<css::xml::dom::XNode> val = + xpathApi->selectSingleNode(xParent, sExpr); + if (val.is()) + return val->getNodeValue(); + return OUString(); + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to read data (readSimpleElement) in backend db: ") + + m_urlDb, 0, exc); + } +} + + +::std::list< OUString> BackendDb::readList( + Reference<css::xml::dom::XNode> const & parent, + OUString const & sListTagName, + OUString const & sMemberTagName) +{ + try + { + OSL_ASSERT(parent.is()); + const OUString sPrefix(getNSPrefix() + OUSTR(":")); + const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI(); + const OUString sExprList( + sPrefix + sListTagName + OUSTR("/") + sPrefix + sMemberTagName + OUSTR("/text()")); + const Reference<css::xml::dom::XNodeList> list = + xpathApi->selectNodeList(parent, sExprList); + + ::std::list<OUString > retList; + sal_Int32 length = list->getLength(); + for (sal_Int32 i = 0; i < length; i++) + { + const Reference<css::xml::dom::XNode> member = list->item(i); + retList.push_back(member->getNodeValue()); + } + return retList; + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to read data entry in backend db: ") + + m_urlDb, 0, exc); + } +} + +::std::list<OUString> BackendDb::getOneChildFromAllEntries( + OUString const & name) +{ + try + { + ::std::list<OUString> listRet; + Reference<css::xml::dom::XDocument> doc = getDocument(); + Reference<css::xml::dom::XNode> root = doc->getFirstChild(); + + Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI(); + const OUString sPrefix = getNSPrefix(); + const OUString sKeyElement = getKeyElementName(); + ::rtl::OUStringBuffer buf(512); + buf.append(sPrefix); + buf.appendAscii(":"); + buf.append(sKeyElement); + buf.appendAscii("/"); + buf.append(sPrefix); + buf.appendAscii(":"); + buf.append(name); + buf.append(OUSTR("/text()")); + + Reference<css::xml::dom::XNodeList> nodes = + xpathApi->selectNodeList(root, buf.makeStringAndClear()); + if (nodes.is()) + { + sal_Int32 length = nodes->getLength(); + for (sal_Int32 i = 0; i < length; i++) + listRet.push_back(nodes->item(i)->getNodeValue()); + } + return listRet; + } + catch (css::deployment::DeploymentException& ) + { + throw; + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to read data entry in backend db: ") + + m_urlDb, 0, exc); + } +} + + + +//================================================================================ +RegisteredDb::RegisteredDb( + Reference<XComponentContext> const & xContext, + ::rtl::OUString const & url):BackendDb(xContext, url) +{ + +} + +void RegisteredDb::addEntry(::rtl::OUString const & url) +{ + try{ + + const OUString sNameSpace = getDbNSName(); + const OUString sPrefix = getNSPrefix(); + const OUString sEntry = getKeyElementName(); + + Reference<css::xml::dom::XDocument> doc = getDocument(); + Reference<css::xml::dom::XNode> root = doc->getFirstChild(); + +#if OSL_DEBUG_LEVEL > 0 + //There must not be yet an entry with the same url + OUString sExpression( + sPrefix + OUSTR(":") + sEntry + OUSTR("[@url = \"") + url + OUSTR("\"]")); + Reference<css::xml::dom::XNode> _extensionNode = + getXPathAPI()->selectSingleNode(root, sExpression); + OSL_ASSERT(! _extensionNode.is()); +#endif + Reference<css::xml::dom::XElement> helpElement( + doc->createElementNS(sNameSpace, sPrefix + OUSTR(":") + sEntry)); + + helpElement->setAttribute(OUSTR("url"), url); + + Reference<css::xml::dom::XNode> helpNode( + helpElement, UNO_QUERY_THROW); + root->appendChild(helpNode); + + save(); + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to write data entry in backend db: ") + + m_urlDb, 0, exc); + } +} + +bool RegisteredDb::getEntry(::rtl::OUString const & url) +{ + try + { + const OUString sPrefix = getNSPrefix(); + const OUString sEntry = getKeyElementName(); + const OUString sExpression( + sPrefix + OUSTR(":") + sEntry + OUSTR("[@url = \"") + url + OUSTR("\"]")); + Reference<css::xml::dom::XDocument> doc = getDocument(); + Reference<css::xml::dom::XNode> root = doc->getFirstChild(); + + Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI(); + //find the extension element that is to be removed + Reference<css::xml::dom::XNode> aNode = + xpathApi->selectSingleNode(root, sExpression); + if (!aNode.is()) + { + return false; + } + return true; + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to read data entry in backend db: ") + + m_urlDb, 0, exc); + } +} + + +} // namespace backend +} // namespace dp_registry + diff --git a/desktop/source/deployment/registry/dp_registry.cxx b/desktop/source/deployment/registry/dp_registry.cxx index c56131a1015c..c5e440a2a825 100644 --- a/desktop/source/deployment/registry/dp_registry.cxx +++ b/desktop/source/deployment/registry/dp_registry.cxx @@ -115,6 +115,7 @@ protected: virtual ~PackageRegistryImpl(); PackageRegistryImpl() : t_helper( getMutex() ) {} + public: static Reference<deployment::XPackageRegistry> create( OUString const & context, @@ -126,8 +127,8 @@ public: // XPackageRegistry virtual Reference<deployment::XPackage> SAL_CALL bindPackage( - OUString const & url, OUString const & mediaType, - Reference<XCommandEnvironment> const & xCmdEnv ) + OUString const & url, OUString const & mediaType, sal_Bool bRemoved, + OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ) throw (deployment::DeploymentException, CommandFailedException, lang::IllegalArgumentException, RuntimeException); virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL @@ -361,9 +362,24 @@ Reference<deployment::XPackageRegistry> PackageRegistryImpl::create( // Always register as last, because we want to add extensions also as folders // and as a default we accept every folder, which was not recognized by the other // backends. - that->insertBackend( + Reference<deployment::XPackageRegistry> extensionBackend = ::dp_registry::backend::bundle::create( - that, context, cachePath, readOnly, xComponentContext ) ); + that, context, cachePath, readOnly, xComponentContext); + that->insertBackend(extensionBackend); + + Reference<lang::XServiceInfo> xServiceInfo( + extensionBackend, UNO_QUERY_THROW ); + + OSL_ASSERT(xServiceInfo.is()); + OUString registryCachePath( + makeURL( cachePath, + ::rtl::Uri::encode( + xServiceInfo->getImplementationName(), + rtl_UriCharClassPchar, + rtl_UriEncodeIgnoreEscapes, + RTL_TEXTENCODING_UTF8 ) ) ); + create_folder( 0, registryCachePath, Reference<XCommandEnvironment>()); + #if OSL_DEBUG_LEVEL > 1 // dump tables: @@ -443,8 +459,8 @@ void PackageRegistryImpl::update() throw (RuntimeException) // XPackageRegistry //______________________________________________________________________________ Reference<deployment::XPackage> PackageRegistryImpl::bindPackage( - OUString const & url, OUString const & mediaType_, - Reference<XCommandEnvironment> const & xCmdEnv ) + OUString const & url, OUString const & mediaType_, sal_Bool bRemoved, + OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ) throw (deployment::DeploymentException, CommandFailedException, lang::IllegalArgumentException, RuntimeException) { @@ -482,7 +498,8 @@ Reference<deployment::XPackage> PackageRegistryImpl::bindPackage( for ( ; iPos != iEnd; ++iPos ) { try { - return (*iPos)->bindPackage( url, mediaType, xCmdEnv ); + return (*iPos)->bindPackage( url, mediaType, bRemoved, + identifier, xCmdEnv ); } catch (lang::IllegalArgumentException &) { } @@ -511,7 +528,8 @@ Reference<deployment::XPackage> PackageRegistryImpl::bindPackage( getResourceString(RID_STR_UNSUPPORTED_MEDIA_TYPE) + mediaType, static_cast<OWeakObject *>(this), static_cast<sal_Int16>(-1) ); } - return iFind->second->bindPackage( url, mediaType, xCmdEnv ); + return iFind->second->bindPackage( url, mediaType, bRemoved, + identifier, xCmdEnv ); } } @@ -521,7 +539,6 @@ PackageRegistryImpl::getSupportedPackageTypes() throw (RuntimeException) { return comphelper::containerToSequence(m_typesInfos); } - } // anon namespace //============================================================================== diff --git a/desktop/source/deployment/registry/executable/dp_executable.cxx b/desktop/source/deployment/registry/executable/dp_executable.cxx index 8c95d5874b4c..968ee7297b0f 100644 --- a/desktop/source/deployment/registry/executable/dp_executable.cxx +++ b/desktop/source/deployment/registry/executable/dp_executable.cxx @@ -28,6 +28,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_desktop.hxx" +#include "dp_misc.h" #include "dp_backend.h" #include "dp_ucb.h" #include "dp_interact.h" @@ -37,10 +38,12 @@ #include "comphelper/servicedecl.hxx" #include "svl/inettype.hxx" #include "cppuhelper/implbase1.hxx" +#include "dp_executablebackenddb.hxx" using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::ucb; +using namespace dp_misc; using ::rtl::OUString; namespace dp_registry { @@ -62,19 +65,20 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend virtual void processPackage_( ::osl::ResettableMutexGuard & guard, bool registerPackage, + bool startup, ::rtl::Reference<dp_misc::AbortChannel> const & abortChannel, Reference<XCommandEnvironment> const & xCmdEnv ); bool getFileAttributes(sal_uInt64& out_Attributes); bool isUrlTargetInExtension(); - public: inline ExecutablePackageImpl( ::rtl::Reference<PackageRegistryBackend> const & myBackend, OUString const & url, OUString const & name, - Reference<deployment::XPackageTypeInfo> const & xPackageType) + Reference<deployment::XPackageTypeInfo> const & xPackageType, + bool bRemoved, OUString const & identifier) : Package( myBackend, url, name, name /* display-name */, - xPackageType ) //, + xPackageType, bRemoved, identifier) {} }; friend class ExecutablePackageImpl; @@ -84,11 +88,15 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend // PackageRegistryBackend virtual Reference<deployment::XPackage> bindPackage_( - OUString const & url, OUString const & mediaType, - Reference<XCommandEnvironment> const & xCmdEnv ); + OUString const & url, OUString const & mediaType, sal_Bool bRemoved, + OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ); - Reference<deployment::XPackageTypeInfo> m_xExecutableTypeInfo; + void addDataToDb(OUString const & url); + bool isRegisteredInDb(OUString const & url); + void deleteDataFromDb(OUString const & url); + Reference<deployment::XPackageTypeInfo> m_xExecutableTypeInfo; + std::auto_ptr<ExecutableBackendDb> m_backendDb; public: BackendImpl( Sequence<Any> const & args, Reference<XComponentContext> const & xComponentContext ); @@ -112,7 +120,32 @@ BackendImpl::BackendImpl( RID_IMG_COMPONENT, RID_IMG_COMPONENT_HC ) ) { + if (!transientMode()) + { + OUString dbFile = makeURL(getCachePath(), OUSTR("backenddb.xml")); + m_backendDb.reset( + new ExecutableBackendDb(getComponentContext(), dbFile)); + } +} +void BackendImpl::addDataToDb(OUString const & url) +{ + if (m_backendDb.get()) + m_backendDb->addEntry(url); +} + +bool BackendImpl::isRegisteredInDb(OUString const & url) +{ + bool ret = false; + if (m_backendDb.get()) + ret = m_backendDb->getEntry(url); + return ret; +} + +void BackendImpl::deleteDataFromDb(OUString const & url) +{ + if (m_backendDb.get()) + m_backendDb->removeEntry(url); } // XPackageRegistry @@ -125,8 +158,8 @@ BackendImpl::getSupportedPackageTypes() throw (RuntimeException) // PackageRegistryBackend Reference<deployment::XPackage> BackendImpl::bindPackage_( - OUString const & url, OUString const & mediaType, - Reference<XCommandEnvironment> const & xCmdEnv ) + OUString const & url, OUString const & mediaType, sal_Bool bRemoved, + OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ) { if (mediaType.getLength() == 0) { @@ -141,13 +174,18 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( { if (type.EqualsIgnoreCaseAscii("application")) { - ::ucbhelper::Content ucbContent( url, xCmdEnv ); - const OUString name( ucbContent.getPropertyValue( - dp_misc::StrTitle::get() ).get<OUString>() ); + OUString name; + if (!bRemoved) + { + ::ucbhelper::Content ucbContent( url, xCmdEnv ); + name = ucbContent.getPropertyValue( + dp_misc::StrTitle::get() ).get<OUString>(); + } if (subType.EqualsIgnoreCaseAscii("vnd.sun.star.executable")) { return new BackendImpl::ExecutablePackageImpl( - this, url, name, m_xExecutableTypeInfo); + this, url, name, m_xExecutableTypeInfo, bRemoved, + identifier); } } } @@ -179,23 +217,17 @@ BackendImpl::ExecutablePackageImpl::isRegistered_( ::rtl::Reference<dp_misc::AbortChannel> const &, Reference<XCommandEnvironment> const & ) { - //We must return Optional.isPresent = true, otherwise - //processPackage is not called. - //The user shall not be able to enable/disable the executable. This is not needed since - //the executable does not affect the office. The best thing is to show no - //status at all. See also BackendImpl::PackageImpl::isRegistered_ (dp_package.cxx) - //On Windows there is no executable file attribute. One has to use security API for this. - //However, on Windows we do not have the problem, that after unzipping the file cannot be - //executed. + bool registered = getMyBackend()->isRegisteredInDb(getURL()); return beans::Optional< beans::Ambiguous<sal_Bool> >( sal_True /* IsPresent */, beans::Ambiguous<sal_Bool>( - sal_True, sal_True /* IsAmbiguous */ ) ); + registered, sal_False /* IsAmbiguous */ ) ); } void BackendImpl::ExecutablePackageImpl::processPackage_( ::osl::ResettableMutexGuard &, bool doRegisterPackage, + bool /*startup*/, ::rtl::Reference<dp_misc::AbortChannel> const & abortChannel, Reference<XCommandEnvironment> const & /*xCmdEnv*/ ) { @@ -216,19 +248,27 @@ void BackendImpl::ExecutablePackageImpl::processPackage_( else if (getMyBackend()->m_context.equals(OUSTR("shared"))) attributes |= (osl_File_Attribute_OwnExe | osl_File_Attribute_GrpExe | osl_File_Attribute_OthExe); - else + else if (!getMyBackend()->m_context.equals(OUSTR("bundled"))) + //Bundled extension are required to be in the properly + //installed. That is an executable must have the right flags OSL_ASSERT(0); //This won't have affect on Windows - if (osl::File::E_None != osl::File::setAttributes( - dp_misc::expandUnoRcUrl(m_url), attributes)) - OSL_ENSURE(0, "Extension Manager: Could not set executable file attribute."); + osl::File::setAttributes( + dp_misc::expandUnoRcUrl(m_url), attributes); } + getMyBackend()->addDataToDb(getURL()); + } + else + { + getMyBackend()->deleteDataFromDb(getURL()); } } -//We currently cannot check if this XPackage represents a content of a particular exension +//We currently cannot check if this XPackage represents a content of a particular extension //But we can check if we are within $UNO_USER_PACKAGES_CACHE etc. +//Done for security reasons. For example an extension manifest could contain a path to +//an executable outside the extension. bool BackendImpl::ExecutablePackageImpl::isUrlTargetInExtension() { bool bSuccess = false; @@ -237,6 +277,8 @@ bool BackendImpl::ExecutablePackageImpl::isUrlTargetInExtension() sExtensionDir = dp_misc::expandUnoRcTerm(OUSTR("$UNO_USER_PACKAGES_CACHE")); else if (getMyBackend()->m_context.equals(OUSTR("shared"))) sExtensionDir = dp_misc::expandUnoRcTerm(OUSTR("$UNO_SHARED_PACKAGES_CACHE")); + else if (getMyBackend()->m_context.equals(OUSTR("bundled"))) + sExtensionDir = dp_misc::expandUnoRcTerm(OUSTR("$BUNDLED_EXTENSIONS")); else OSL_ASSERT(0); //remove file ellipses diff --git a/desktop/source/deployment/registry/executable/dp_executablebackenddb.cxx b/desktop/source/deployment/registry/executable/dp_executablebackenddb.cxx new file mode 100644 index 000000000000..976a6281a2bd --- /dev/null +++ b/desktop/source/deployment/registry/executable/dp_executablebackenddb.cxx @@ -0,0 +1,84 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dp_package.cxx,v $ + * $Revision: 1.34.16.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "rtl/string.h" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "dp_misc.h" +#include "dp_executablebackenddb.hxx" + + +namespace css = ::com::sun::star; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; + +#define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/executable-registry/2010" +#define NS_PREFIX "exe" +#define ROOT_ELEMENT_NAME "executable-backend-db" +#define ENTRY_NAME "executable" + +namespace dp_registry { +namespace backend { +namespace executable { + +ExecutableBackendDb::ExecutableBackendDb( + Reference<XComponentContext> const & xContext, + ::rtl::OUString const & url):RegisteredDb(xContext, url) +{ + +} + +OUString ExecutableBackendDb::getDbNSName() +{ + return OUSTR(EXTENSION_REG_NS); +} + +OUString ExecutableBackendDb::getNSPrefix() +{ + return OUSTR(NS_PREFIX); +} + +OUString ExecutableBackendDb::getRootElementName() +{ + return OUSTR(ROOT_ELEMENT_NAME); +} + +OUString ExecutableBackendDb::getKeyElementName() +{ + return OUSTR(ENTRY_NAME); +} + + +} // namespace executable +} // namespace backend +} // namespace dp_registry + diff --git a/desktop/source/deployment/registry/executable/dp_executablebackenddb.hxx b/desktop/source/deployment/registry/executable/dp_executablebackenddb.hxx new file mode 100644 index 000000000000..4f17eeda24a6 --- /dev/null +++ b/desktop/source/deployment/registry/executable/dp_executablebackenddb.hxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dp_backend.h,v $ + * $Revision: 1.18 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if ! defined INCLUDED_DP_EXECUTABLEBACKENDDB_HXX +#define INCLUDED_DP_EXECUTABLEBACKENDDB_HXX + +#include "rtl/ustring.hxx" +#include "dp_backenddb.hxx" + +namespace css = ::com::sun::star; + +namespace com { namespace sun { namespace star { + namespace uno { + class XComponentContext; + } +}}} + +namespace dp_registry { +namespace backend { +namespace executable { + +/* The XML file stores the extensions which are currently registered. + They will be removed when they are revoked. + The format looks like this: + +<?xml version="1.0"?> + */ +class ExecutableBackendDb: public dp_registry::backend::RegisteredDb +{ +protected: + virtual ::rtl::OUString getDbNSName(); + + virtual ::rtl::OUString getNSPrefix(); + + virtual ::rtl::OUString getRootElementName(); + + virtual ::rtl::OUString getKeyElementName(); + +public: + + ExecutableBackendDb( css::uno::Reference<css::uno::XComponentContext> const & xContext, + ::rtl::OUString const & url); + +}; + + + +} +} +} +#endif + diff --git a/desktop/source/deployment/registry/executable/makefile.mk b/desktop/source/deployment/registry/executable/makefile.mk index 1e57f5ecf3b1..81b2baa44e5d 100644 --- a/desktop/source/deployment/registry/executable/makefile.mk +++ b/desktop/source/deployment/registry/executable/makefile.mk @@ -36,7 +36,8 @@ ENABLE_EXCEPTIONS = TRUE INCPRE += ..$/..$/inc SLOFILES = \ - $(SLO)$/dp_executable.obj + $(SLO)$/dp_executable.obj \ + $(SLO)$/dp_executablebackenddb.obj .INCLUDE : ..$/..$/target.pmk .INCLUDE : target.mk diff --git a/desktop/source/deployment/registry/help/dp_help.cxx b/desktop/source/deployment/registry/help/dp_help.cxx index 2b0d91250e4a..bc17a1f7163d 100644 --- a/desktop/source/deployment/registry/help/dp_help.cxx +++ b/desktop/source/deployment/registry/help/dp_help.cxx @@ -30,9 +30,11 @@ #include "dp_help.hrc" #include "dp_backend.h" +#include "dp_helpbackenddb.hxx" #include "dp_ucb.h" #include "rtl/uri.hxx" #include "osl/file.hxx" +#include "rtl/bootstrap.hxx" #include "ucbhelper/content.hxx" #include "comphelper/servicedecl.hxx" #include "svl/inettype.hxx" @@ -44,6 +46,7 @@ #include <com/sun/star/uri/XUriReferenceFactory.hpp> #include <com/sun/star/uri/XVndSunStarExpandUrl.hpp> #include <com/sun/star/script/XInvocation.hpp> +#include "boost/optional.hpp" using namespace ::dp_misc; using namespace ::com::sun::star; @@ -63,6 +66,8 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend { BackendImpl * getMyBackend() const; +// HelpBackendDb::Data m_dbData; + // Package virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_( ::osl::ResettableMutexGuard & guard, @@ -71,36 +76,44 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend virtual void processPackage_( ::osl::ResettableMutexGuard & guard, bool registerPackage, + bool startup, ::rtl::Reference<AbortChannel> const & abortChannel, Reference<XCommandEnvironment> const & xCmdEnv ); public: - inline PackageImpl( + PackageImpl( ::rtl::Reference<PackageRegistryBackend> const & myBackend, OUString const & url, OUString const & name, - Reference<deployment::XPackageTypeInfo> const & xPackageType ) - : Package( myBackend, url, name, name, xPackageType ) - {} + Reference<deployment::XPackageTypeInfo> const & xPackageType, + bool bRemoved, OUString const & identifier); + + //XPackage + virtual css::beans::Optional< ::rtl::OUString > SAL_CALL getRegistrationDataURL() + throw (deployment::ExtensionRemovedException, css::uno::RuntimeException); }; friend class PackageImpl; // PackageRegistryBackend virtual Reference<deployment::XPackage> bindPackage_( OUString const & url, OUString const & mediaType, + sal_Bool bRemoved, OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ); - void implProcessHelp( Reference< deployment::XPackage > xPackage, bool doRegisterPackage ); + void implProcessHelp( Reference< deployment::XPackage > xPackage, bool doRegisterPackage, + Reference<ucb::XCommandEnvironment> const & xCmdEnv); void implCollectXhpFiles( const rtl::OUString& aDir, std::vector< rtl::OUString >& o_rXhpFileVector ); - rtl::OUString getFlagFileURL( Reference< deployment::XPackage > xPackage, const char* pFlagStr ); - rtl::OUString getRegisteredFlagFileURL( Reference< deployment::XPackage > xPackage ); - rtl::OUString getCompiledFlagFileURL( Reference< deployment::XPackage > xPackage ); - rtl::OUString expandURL( const rtl::OUString& aURL ); + + void addDataToDb(OUString const & url, HelpBackendDb::Data const & data); + ::boost::optional<HelpBackendDb::Data> readDataFromDb(OUString const & url); + void deleteDataFromDb(OUString const & url); + Reference< ucb::XSimpleFileAccess > getFileAccess( void ); Reference< ucb::XSimpleFileAccess > m_xSFA; const Reference<deployment::XPackageTypeInfo> m_xHelpTypeInfo; Sequence< Reference<deployment::XPackageTypeInfo> > m_typeInfos; + std::auto_ptr<HelpBackendDb> m_backendDb; public: BackendImpl( Sequence<Any> const & args, @@ -124,6 +137,20 @@ BackendImpl::BackendImpl( m_typeInfos( 1 ) { m_typeInfos[ 0 ] = m_xHelpTypeInfo; + if (!transientMode()) + { + OUString dbFile = makeURL(getCachePath(), OUSTR("backenddb.xml")); + m_backendDb.reset( + new HelpBackendDb(getComponentContext(), dbFile)); + + //clean up data folders which are no longer used. + //This must not be done in the same process where the help files + //are still registers. Only after revoking and restarting OOo the folders + //can be removed. This works now, because the extension manager is a singleton + //and the backends are only create once per process. + ::std::list<OUString> folders = m_backendDb->getAllDataUrls(); + deleteUnusedFolders(OUString(), folders); + } } // XPackageRegistry @@ -138,6 +165,7 @@ BackendImpl::getSupportedPackageTypes() throw (RuntimeException) //______________________________________________________________________________ Reference<deployment::XPackage> BackendImpl::bindPackage_( OUString const & url, OUString const & mediaType_, + sal_Bool bRemoved, OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ) { // we don't support auto detection: @@ -152,12 +180,20 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( { if (type.EqualsIgnoreCaseAscii("application")) { - ::ucbhelper::Content ucbContent( url, xCmdEnv ); + OUString name; + if (!bRemoved) + { + ::ucbhelper::Content ucbContent( url, xCmdEnv ); + name = ucbContent.getPropertyValue( + StrTitle::get() ).get<OUString>(); + } + if (subType.EqualsIgnoreCaseAscii( "vnd.sun.star.help")) { - return new PackageImpl( this, url, - ucbContent.getPropertyValue( StrTitle::get() ).get<OUString>(), m_xHelpTypeInfo ); + return new PackageImpl( + this, url, name, m_xHelpTypeInfo, bRemoved, + identifier); } } } @@ -167,8 +203,45 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( static_cast<sal_Int16>(-1) ); } +void BackendImpl::addDataToDb( + OUString const & url, HelpBackendDb::Data const & data) +{ + if (m_backendDb.get()) + m_backendDb->addEntry(url, data); +} + +::boost::optional<HelpBackendDb::Data> BackendImpl::readDataFromDb( + OUString const & url) +{ + ::boost::optional<HelpBackendDb::Data> data; + if (m_backendDb.get()) + data = m_backendDb->getEntry(url); + return data; +} + +void BackendImpl::deleteDataFromDb(OUString const & url) +{ + if (m_backendDb.get()) + m_backendDb->removeEntry(url); +} //############################################################################## +BackendImpl::PackageImpl::PackageImpl( + ::rtl::Reference<PackageRegistryBackend> const & myBackend, + OUString const & url, OUString const & name, + Reference<deployment::XPackageTypeInfo> const & xPackageType, + bool bRemoved, OUString const & identifier) + : Package( myBackend, url, name, name, xPackageType, bRemoved, + identifier) +{ +// if (bRemoved) +// { +// ::boost::optional<HelpBackendDb::Data> opt = +// getMyBackend()->readDataFromDb(url); +// if (opt) +// m_dbData = *opt; +// } +} // Package BackendImpl * BackendImpl::PackageImpl::getMyBackend() const @@ -194,11 +267,10 @@ BackendImpl::PackageImpl::isRegistered_( Reference<XCommandEnvironment> const & ) { BackendImpl * that = getMyBackend(); - Reference< deployment::XPackage > xThisPackage( this ); - rtl::OUString aRegisteredFlagFile = that->getRegisteredFlagFileURL( xThisPackage ); - Reference< ucb::XSimpleFileAccess > xSFA = that->getFileAccess(); - bool bReg = xSFA->exists( aRegisteredFlagFile ); + bool bReg = false; + if (that->readDataFromDb(getURL())) + bReg = true; return beans::Optional< beans::Ambiguous<sal_Bool> >( true, beans::Ambiguous<sal_Bool>( bReg, false ) ); } @@ -207,6 +279,7 @@ BackendImpl::PackageImpl::isRegistered_( void BackendImpl::PackageImpl::processPackage_( ::osl::ResettableMutexGuard &, bool doRegisterPackage, + bool /* startup */, ::rtl::Reference<AbortChannel> const & abortChannel, Reference<XCommandEnvironment> const & xCmdEnv ) { @@ -216,39 +289,46 @@ void BackendImpl::PackageImpl::processPackage_( BackendImpl* that = getMyBackend(); Reference< deployment::XPackage > xThisPackage( this ); - that->implProcessHelp( xThisPackage, doRegisterPackage ); + that->implProcessHelp( xThisPackage, doRegisterPackage, xCmdEnv); } +beans::Optional< OUString > BackendImpl::PackageImpl::getRegistrationDataURL() + throw (deployment::ExtensionRemovedException, + css::uno::RuntimeException) +{ + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); + + ::boost::optional<HelpBackendDb::Data> data = + getMyBackend()->readDataFromDb(getURL()); + + if (data) + return beans::Optional<OUString>(true, data->dataUrl); + + return beans::Optional<OUString>(true, OUString()); +} + + //############################################################################## static rtl::OUString aSlash( rtl::OUString::createFromAscii( "/" ) ); static rtl::OUString aHelpStr( rtl::OUString::createFromAscii( "help" ) ); + void BackendImpl::implProcessHelp - ( Reference< deployment::XPackage > xPackage, bool doRegisterPackage ) +( Reference< deployment::XPackage > xPackage, bool doRegisterPackage, + Reference<ucb::XCommandEnvironment> const & xCmdEnv) { - if( !xPackage.is() ) - return; - - Reference< ucb::XSimpleFileAccess > xSFA = getFileAccess(); - - rtl::OUString aRegisteredFlagFile = getRegisteredFlagFileURL( xPackage ); - if( !doRegisterPackage ) + OSL_ASSERT(xPackage.is()); + if (doRegisterPackage) { - if( xSFA->exists( aRegisteredFlagFile ) ) - xSFA->kill( aRegisteredFlagFile ); - return; - } - - bool bCompile = true; - rtl::OUString aCompiledFlagFile = getCompiledFlagFileURL( xPackage ); - if( xSFA->exists( aCompiledFlagFile ) ) - bCompile = false; + HelpBackendDb::Data data; + const OUString sHelpFolder = createFolder(OUString(), xCmdEnv); + data.dataUrl = sHelpFolder; - if( bCompile ) - { + Reference< ucb::XSimpleFileAccess > xSFA = getFileAccess(); rtl::OUString aHelpURL = xPackage->getURL(); - rtl::OUString aExpandedHelpURL = expandURL( aHelpURL ); + rtl::OUString aExpandedHelpURL = dp_misc::expandUnoRcUrl( aHelpURL ); rtl::OUString aName = xPackage->getName(); if( !xSFA->isFolder( aExpandedHelpURL ) ) { @@ -256,7 +336,7 @@ void BackendImpl::implProcessHelp aErrStr += rtl::OUString::createFromAscii( "No help folder" ); OWeakObject* oWeakThis = static_cast<OWeakObject *>(this); throw deployment::DeploymentException( rtl::OUString(), oWeakThis, - makeAny( uno::Exception( aErrStr, oWeakThis ) ) ); + makeAny( uno::Exception( aErrStr, oWeakThis ) ) ); } Reference<XComponentContext> const & xContext = getComponentContext(); @@ -267,7 +347,7 @@ void BackendImpl::implProcessHelp { xInvocation = Reference< script::XInvocation >( xContext->getServiceManager()->createInstanceWithContext( rtl::OUString::createFromAscii( - "com.sun.star.help.HelpIndexer" ), xContext ) , UNO_QUERY ); + "com.sun.star.help.HelpIndexer" ), xContext ) , UNO_QUERY ); } catch (Exception &) { @@ -286,34 +366,30 @@ void BackendImpl::implProcessHelp { std::vector< rtl::OUString > aXhpFileVector; - // Delete (old) files in any case to allow compiler to be started every time - rtl::OUString aLangWithPureNameURL( aLangURL ); - aLangWithPureNameURL += aSlash; - aLangWithPureNameURL += aHelpStr; - rtl::OUString aDbFile( aLangWithPureNameURL ); - aDbFile += rtl::OUString::createFromAscii( ".db" ); - if( xSFA->exists( aDbFile ) ) - xSFA->kill( aDbFile ); - rtl::OUString aHtFile( aLangWithPureNameURL ); - aHtFile += rtl::OUString::createFromAscii( ".ht" ); - if( xSFA->exists( aHtFile ) ) - xSFA->kill( aHtFile ); - rtl::OUString aKeyFile( aLangWithPureNameURL ); - aKeyFile += rtl::OUString::createFromAscii( ".key" ); - if( xSFA->exists( aKeyFile ) ) - xSFA->kill( aKeyFile ); - // calculate jar file URL - rtl::OUString aJarFile( aLangURL ); - aJarFile += aSlash; - aJarFile += aHelpStr; - aJarFile += rtl::OUString::createFromAscii( ".jar" ); - // remove in any case to clean up - if( xSFA->exists( aJarFile ) ) - xSFA->kill( aJarFile ); - - rtl::OUString aEncodedJarFilePath = rtl::Uri::encode( aJarFile, - rtl_UriCharClassPchar, rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8 ); + sal_Int32 indexStartSegment = aLangURL.lastIndexOf('/'); + // for example "/en" + OUString langFolderURLSegment( + aLangURL.copy( + indexStartSegment + 1, aLangURL.getLength() - indexStartSegment - 1)); + + //create the folder in the "temporary folder" + ::ucbhelper::Content langFolderContent; + const OUString langFolderDest = makeURL(sHelpFolder, langFolderURLSegment); + const OUString langFolderDestExpanded = ::dp_misc::expandUnoRcUrl(langFolderDest); + ::dp_misc::create_folder( + &langFolderContent, + langFolderDest, xCmdEnv); + + rtl::OUString aJarFile( + makeURL(sHelpFolder, langFolderURLSegment + aSlash + aHelpStr + + OUSTR(".jar"))); + aJarFile = ::dp_misc::expandUnoRcUrl(aJarFile); + + rtl::OUString aEncodedJarFilePath = rtl::Uri::encode( + aJarFile, rtl_UriCharClassPchar, + rtl_UriEncodeIgnoreEscapes, + RTL_TEXTENCODING_UTF8 ); rtl::OUString aDestBasePath = rtl::OUString::createFromAscii( "vnd.sun.star.pkg://" ); aDestBasePath += aEncodedJarFilePath; aDestBasePath += rtl::OUString::createFromAscii( "/" ); @@ -353,8 +429,10 @@ void BackendImpl::implProcessHelp ::osl::File::getFileURLFromSystemPath( aOfficeHelpPath, aOfficeHelpPathFileURL ); HelpProcessingErrorInfo aErrorInfo; - bool bSuccess = compileExtensionHelp( aOfficeHelpPathFileURL, aHelpStr, aLangURL, - nXhpFileCount, pXhpFiles, aErrorInfo ); + bool bSuccess = compileExtensionHelp( + aOfficeHelpPathFileURL, aHelpStr, aLangURL, + nXhpFileCount, pXhpFiles, + langFolderDestExpanded, aErrorInfo ); if( bSuccess && xInvocation.is() ) { @@ -375,13 +453,14 @@ void BackendImpl::implProcessHelp aParamsSeq[4] = uno::makeAny( rtl::OUString::createFromAscii( "-zipdir" ) ); rtl::OUString aSystemPath; - osl::FileBase::getSystemPathFromFileURL( aLangURL, aSystemPath ); + osl::FileBase::getSystemPathFromFileURL( + langFolderDestExpanded, aSystemPath ); aParamsSeq[5] = uno::makeAny( aSystemPath ); Sequence< sal_Int16 > aOutParamIndex; Sequence< uno::Any > aOutParam; uno::Any aRet = xInvocation->invoke( rtl::OUString::createFromAscii( "createIndex" ), - aParamsSeq, aOutParamIndex, aOutParam ); + aParamsSeq, aOutParamIndex, aOutParam ); } if( !bSuccess ) @@ -389,10 +468,10 @@ void BackendImpl::implProcessHelp USHORT nErrStrId = 0; switch( aErrorInfo.m_eErrorClass ) { - case HELPPROCESSING_GENERAL_ERROR: - case HELPPROCESSING_INTERNAL_ERROR: nErrStrId = RID_STR_HELPPROCESSING_GENERAL_ERROR; break; - case HELPPROCESSING_XMLPARSING_ERROR: nErrStrId = RID_STR_HELPPROCESSING_XMLPARSING_ERROR; break; - default: ; + case HELPPROCESSING_GENERAL_ERROR: + case HELPPROCESSING_INTERNAL_ERROR: nErrStrId = RID_STR_HELPPROCESSING_GENERAL_ERROR; break; + case HELPPROCESSING_XMLPARSING_ERROR: nErrStrId = RID_STR_HELPPROCESSING_XMLPARSING_ERROR; break; + default: ; }; rtl::OUString aErrStr; @@ -423,7 +502,7 @@ void BackendImpl::implProcessHelp aErrStr += rtl::OUString::createFromAscii( " in " ); rtl::OUString aDecodedFile = rtl::Uri::decode( aErrorInfo.m_aXMLParsingFile, - rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); aErrStr += aDecodedFile; if( aErrorInfo.m_nXMLParsingLine != -1 ) { @@ -435,96 +514,21 @@ void BackendImpl::implProcessHelp OWeakObject* oWeakThis = static_cast<OWeakObject *>(this); throw deployment::DeploymentException( rtl::OUString(), oWeakThis, - makeAny( uno::Exception( aErrStr, oWeakThis ) ) ); + makeAny( uno::Exception( aErrStr, oWeakThis ) ) ); } } } - // Write compiled flag file (this code is only reached in case of success) - Reference< io::XOutputStream > xOutputStream = xSFA->openFileWrite( aCompiledFlagFile ); - if( xOutputStream.is() ) - xOutputStream->closeOutput(); - - } // if( bCompile ) - - // Write registered flag file (this code is only reached in case of success) - if( !xSFA->exists( aRegisteredFlagFile ) ) + //Writing the data entry replaces writing the flag file. If we got to this + //point the registration was successful. + addDataToDb(xPackage->getURL(), data); + } + else { - Reference< io::XOutputStream > xOutputStream = xSFA->openFileWrite( aRegisteredFlagFile ); - if( xOutputStream.is() ) - xOutputStream->closeOutput(); + deleteDataFromDb(xPackage->getURL()); } } -rtl::OUString BackendImpl::getFlagFileURL( Reference< deployment::XPackage > xPackage, const char* pFlagStr ) -{ - rtl::OUString aRetURL; - if( !xPackage.is() ) - return aRetURL; - rtl::OUString aHelpURL = xPackage->getURL(); - aRetURL = expandURL( aHelpURL ); - aRetURL += rtl::OUString::createFromAscii( pFlagStr ); - return aRetURL; -} - -rtl::OUString BackendImpl::getRegisteredFlagFileURL( Reference< deployment::XPackage > xPackage ) -{ - return getFlagFileURL( xPackage, "/RegisteredFlag" ); -} - -rtl::OUString BackendImpl::getCompiledFlagFileURL( Reference< deployment::XPackage > xPackage ) -{ - return getFlagFileURL( xPackage, "/CompiledFlag" ); -} - -rtl::OUString BackendImpl::expandURL( const rtl::OUString& aURL ) -{ - static Reference< util::XMacroExpander > xMacroExpander; - static Reference< uri::XUriReferenceFactory > xFac; - - if( !xMacroExpander.is() || !xFac.is() ) - { - Reference<XComponentContext> const & xContext = getComponentContext(); - if( xContext.is() ) - { - xFac = Reference< uri::XUriReferenceFactory >( - xContext->getServiceManager()->createInstanceWithContext( rtl::OUString::createFromAscii( - "com.sun.star.uri.UriReferenceFactory"), xContext ) , UNO_QUERY ); - } - if( !xFac.is() ) - { - throw RuntimeException( - ::rtl::OUString::createFromAscii( - "dp_registry::backend::help::BackendImpl::expandURL(), " - "could not instatiate UriReferenceFactory." ), - Reference< XInterface >() ); - } - - xMacroExpander = Reference< util::XMacroExpander >( - xContext->getValueByName( - ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ), - UNO_QUERY_THROW ); - } - - rtl::OUString aRetURL = aURL; - if( xMacroExpander.is() ) - { - Reference< uri::XUriReference > uriRef; - for (;;) - { - uriRef = Reference< uri::XUriReference >( xFac->parse( aRetURL ), UNO_QUERY ); - if ( uriRef.is() ) - { - Reference < uri::XVndSunStarExpandUrl > sxUri( uriRef, UNO_QUERY ); - if( !sxUri.is() ) - break; - - aRetURL = sxUri->expand( xMacroExpander ); - } - } - } - return aRetURL; -} void BackendImpl::implCollectXhpFiles( const rtl::OUString& aDir, std::vector< rtl::OUString >& o_rXhpFileVector ) diff --git a/desktop/source/deployment/registry/help/dp_helpbackenddb.cxx b/desktop/source/deployment/registry/help/dp_helpbackenddb.cxx new file mode 100644 index 000000000000..3bf67e0c050b --- /dev/null +++ b/desktop/source/deployment/registry/help/dp_helpbackenddb.cxx @@ -0,0 +1,178 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dp_package.cxx,v $ + * $Revision: 1.34.16.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "rtl/string.h" +#include "rtl/bootstrap.hxx" +#include "cppuhelper/exc_hlp.hxx" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "com/sun/star/xml/dom/XDocumentBuilder.hpp" +#include "com/sun/star/xml/xpath/XXPathAPI.hpp" +#include "dp_misc.h" + +#include "dp_helpbackenddb.hxx" + + +namespace css = ::com::sun::star; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; + +#define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/help-registry/2010" +#define NS_PREFIX "help" +#define ROOT_ELEMENT_NAME "help-backend-db" +#define KEY_ELEMENT_NAME "help" + +namespace dp_registry { +namespace backend { +namespace help { + +HelpBackendDb::HelpBackendDb( + Reference<XComponentContext> const & xContext, + ::rtl::OUString const & url):BackendDb(xContext, url) +{ + +} + +OUString HelpBackendDb::getDbNSName() +{ + return OUSTR(EXTENSION_REG_NS); +} + +OUString HelpBackendDb::getNSPrefix() +{ + return OUSTR(NS_PREFIX); +} + +OUString HelpBackendDb::getRootElementName() +{ + return OUSTR(ROOT_ELEMENT_NAME); +} + +OUString HelpBackendDb::getKeyElementName() +{ + return OUSTR(KEY_ELEMENT_NAME); +} + + +void HelpBackendDb::addEntry(::rtl::OUString const & url, Data const & data) +{ + try{ + Reference<css::xml::dom::XNode> helpNode + = writeKeyElement(url); + + writeSimpleElement(OUSTR("data-url"), data.dataUrl, helpNode); + save(); + } + catch (css::deployment::DeploymentException& ) + { + throw; + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to write data entry in help backend db: ") + + m_urlDb, 0, exc); + } +} + + +::boost::optional<HelpBackendDb::Data> +HelpBackendDb::getEntry(::rtl::OUString const & url) +{ + try + { + HelpBackendDb::Data retData; + Reference<css::xml::dom::XNode> aNode = getKeyElement(url); + if (aNode.is()) + { + retData.dataUrl = readSimpleElement(OUSTR("data-url"), aNode); + } + else + { + return ::boost::optional<Data>(); + } + return ::boost::optional<Data>(retData); + } + catch (css::deployment::DeploymentException& ) + { + throw; + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to read data entry in help backend db: ") + + m_urlDb, 0, exc); + } +} + +::std::list<OUString> HelpBackendDb::getAllDataUrls() +{ + try + { + ::std::list<OUString> listRet; + Reference<css::xml::dom::XDocument> doc = getDocument(); + Reference<css::xml::dom::XNode> root = doc->getFirstChild(); + + Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI(); + const OUString sPrefix = getNSPrefix(); + OUString sExpression( + sPrefix + OUSTR(":help/") + sPrefix + OUSTR(":data-url/text()")); + Reference<css::xml::dom::XNodeList> nodes = + xpathApi->selectNodeList(root, sExpression); + if (nodes.is()) + { + sal_Int32 length = nodes->getLength(); + for (sal_Int32 i = 0; i < length; i++) + listRet.push_back(nodes->item(i)->getNodeValue()); + } + return listRet; + } + catch (css::deployment::DeploymentException& ) + { + throw; + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to read data entry in help backend db: ") + + m_urlDb, 0, exc); + } +} + + +} // namespace help +} // namespace backend +} // namespace dp_registry + diff --git a/desktop/source/deployment/registry/help/dp_helpbackenddb.hxx b/desktop/source/deployment/registry/help/dp_helpbackenddb.hxx new file mode 100644 index 000000000000..edf7dfdfc284 --- /dev/null +++ b/desktop/source/deployment/registry/help/dp_helpbackenddb.hxx @@ -0,0 +1,92 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dp_backend.h,v $ + * $Revision: 1.18 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if ! defined INCLUDED_DP_HELPBACKENDDB_HXX +#define INCLUDED_DP_HELPBACKENDDB_HXX + +#include "rtl/ustring.hxx" +#include <list> +#include "boost/optional.hpp" +#include "dp_backenddb.hxx" + +namespace css = ::com::sun::star; + +namespace com { namespace sun { namespace star { + namespace uno { + class XComponentContext; + } +}}} + +namespace dp_registry { +namespace backend { +namespace help { + +/* The XML file stores the extensions which are currently registered. + They will be removed when they are revoked. + */ +class HelpBackendDb: public dp_registry::backend::BackendDb +{ +protected: + virtual ::rtl::OUString getDbNSName(); + + virtual ::rtl::OUString getNSPrefix(); + + virtual ::rtl::OUString getRootElementName(); + + virtual ::rtl::OUString getKeyElementName(); + +public: + struct Data + { + /* the URL to the folder containing the compiled help files, etc. + */ + ::rtl::OUString dataUrl; + + }; + +public: + + HelpBackendDb( css::uno::Reference<css::uno::XComponentContext> const & xContext, + ::rtl::OUString const & url); + + void addEntry(::rtl::OUString const & url, Data const & data); + + ::boost::optional<Data> getEntry(::rtl::OUString const & url); + ::std::list< ::rtl::OUString> getAllDataUrls(); + +}; + + + +} +} +} +#endif + diff --git a/desktop/source/deployment/registry/help/makefile.mk b/desktop/source/deployment/registry/help/makefile.mk index ba904bb7f28a..d4934f71a46f 100644 --- a/desktop/source/deployment/registry/help/makefile.mk +++ b/desktop/source/deployment/registry/help/makefile.mk @@ -44,7 +44,8 @@ SRC1FILES = \ dp_help.src SLOFILES = \ - $(SLO)$/dp_help.obj + $(SLO)$/dp_help.obj \ + $(SLO)$/dp_helpbackenddb.obj .INCLUDE : ..$/..$/target.pmk .INCLUDE : target.mk diff --git a/desktop/source/deployment/registry/inc/dp_backend.h b/desktop/source/deployment/registry/inc/dp_backend.h index fe52c8ffc7e3..3d3bf7cf912c 100644 --- a/desktop/source/deployment/registry/inc/dp_backend.h +++ b/desktop/source/deployment/registry/inc/dp_backend.h @@ -40,8 +40,10 @@ #include "com/sun/star/lang/XEventListener.hpp" #include "com/sun/star/deployment/XPackageRegistry.hpp" #include "com/sun/star/deployment/XPackageManager.hpp" +#include "com/sun/star/deployment/InvalidRemovedParameterException.hpp" #include <memory> #include <hash_map> +#include <list> #include "dp_registry.hrc" namespace dp_registry @@ -62,8 +64,10 @@ typedef ::cppu::WeakComponentImplHelper1< //============================================================================== class Package : protected ::dp_misc::MutexHolder, public t_PackageBase { + PackageRegistryBackend * getMyBackend() const; void processPackage_impl( bool registerPackage, + bool startup, css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ); @@ -73,6 +77,9 @@ protected: ::rtl::OUString m_name; ::rtl::OUString m_displayName; const css::uno::Reference<css::deployment::XPackageTypeInfo> m_xPackageType; + const bool m_bRemoved; + //Only set if m_bRemoved = true; + const ::rtl::OUString m_identifier; void check() const; void fireModified(); @@ -91,6 +98,7 @@ protected: virtual void processPackage_( ::osl::ResettableMutexGuard & guard, bool registerPackage, + bool startup, ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel, css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) = 0; @@ -101,7 +109,9 @@ protected: ::rtl::OUString const & name, ::rtl::OUString const & displayName, css::uno::Reference<css::deployment::XPackageTypeInfo> const & - xPackageType ); + xPackageType, + bool bRemoved, + ::rtl::OUString const & identifier); public: @@ -126,9 +136,11 @@ public: virtual ::rtl::OUString SAL_CALL getMediaType() throw (css::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getDescription() - throw (css::uno::RuntimeException); + throw (css::deployment::ExtensionRemovedException, + css::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getShortDescription() - throw (css::uno::RuntimeException); + throw (css::deployment::ExtensionRemovedException, + css::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getFileFilter() throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL getIcon( sal_Bool highContrast, @@ -165,25 +177,29 @@ public: css::ucb::CommandAbortedException, css::uno::RuntimeException); - virtual ::sal_Bool SAL_CALL checkPrerequisites( + virtual ::sal_Int32 SAL_CALL checkPrerequisites( const css::uno::Reference< css::task::XAbortChannel >& xAbortChannel, const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv, - sal_Bool bInstalled, ::rtl::OUString const & aContextName) + sal_Bool noLicenseChecking) throw (css::deployment::DeploymentException, - css::ucb::CommandFailedException, - css::ucb::CommandAbortedException, - css::uno::RuntimeException); + css::deployment::ExtensionRemovedException, + css::ucb::CommandFailedException, + css::ucb::CommandAbortedException, + css::uno::RuntimeException); virtual ::sal_Bool SAL_CALL checkDependencies( const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv ) throw (css::deployment::DeploymentException, - css::ucb::CommandFailedException, - css::uno::RuntimeException); + css::deployment::ExtensionRemovedException, + css::ucb::CommandFailedException, + css::uno::RuntimeException); virtual void SAL_CALL registerPackage( + sal_Bool startup, css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) throw (css::deployment::DeploymentException, + css::deployment::ExtensionRemovedException, css::ucb::CommandFailedException, css::ucb::CommandAbortedException, css::lang::IllegalArgumentException, css::uno::RuntimeException); @@ -211,19 +227,27 @@ public: virtual css::beans::Optional< ::rtl::OUString > SAL_CALL getIdentifier() throw (css::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getVersion() - throw (css::uno::RuntimeException); + throw (css::deployment::ExtensionRemovedException, + css::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getURL() throw (css::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getDisplayName() - throw (css::uno::RuntimeException); + throw (css::deployment::ExtensionRemovedException, + css::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getDescription() - throw (css::uno::RuntimeException); + throw (css::deployment::ExtensionRemovedException, + css::uno::RuntimeException); virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL - getUpdateInformationURLs() throw (css::uno::RuntimeException); - - virtual css::beans::StringPair SAL_CALL getPublisherInfo() throw (css::uno::RuntimeException); - virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL getIcon( sal_Bool bHighContrast ) throw (css::uno::RuntimeException); - + getUpdateInformationURLs() + throw (css::deployment::ExtensionRemovedException, + css::uno::RuntimeException); + virtual css::beans::StringPair SAL_CALL getPublisherInfo() + throw (css::deployment::ExtensionRemovedException, + css::uno::RuntimeException); + virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL + getIcon( sal_Bool bHighContrast ) + throw (css::deployment::ExtensionRemovedException, + css::uno::RuntimeException); virtual css::uno::Reference<css::deployment::XPackageTypeInfo> SAL_CALL getPackageType() throw (css::uno::RuntimeException); virtual void SAL_CALL exportTo( @@ -231,8 +255,17 @@ public: ::rtl::OUString const & newTitle, sal_Int32 nameClashAction, css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) - throw (css::ucb::CommandFailedException, + throw (css::deployment::ExtensionRemovedException, + css::ucb::CommandFailedException, css::ucb::CommandAbortedException, css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getRepositoryName() + throw (css::uno::RuntimeException); + virtual css::beans::Optional< ::rtl::OUString > SAL_CALL getRegistrationDataURL() + throw (css::deployment::ExtensionRemovedException, + css::uno::RuntimeException); + virtual sal_Bool SAL_CALL isRemoved() + throw (css::uno::RuntimeException); + }; typedef ::cppu::WeakComponentImplHelper2< @@ -243,7 +276,6 @@ typedef ::cppu::WeakComponentImplHelper2< class PackageRegistryBackend : protected ::dp_misc::MutexHolder, public t_BackendBase { - ::rtl::OUString m_cachePath; //The map held originally WeakReferences. The map entries are removed in the disposing //function, which is called when the XPackages are destructed or they are //explicitely disposed. The latter happens, for example, when a extension is @@ -257,13 +289,14 @@ class PackageRegistryBackend t_string2ref m_bound; protected: + ::rtl::OUString m_cachePath; css::uno::Reference<css::uno::XComponentContext> m_xComponentContext; ::rtl::OUString m_context; // currently only for library containers: enum context { CONTEXT_UNKNOWN, - CONTEXT_USER, CONTEXT_SHARED, + CONTEXT_USER, CONTEXT_SHARED,CONTEXT_BUNDLED, CONTEXT_TMP, CONTEXT_DOCUMENT } m_eContext; bool m_readOnly; @@ -276,6 +309,7 @@ protected: // @@@ to be implemented by specific backend: virtual css::uno::Reference<css::deployment::XPackage> bindPackage_( ::rtl::OUString const & url, ::rtl::OUString const & mediaType, + sal_Bool bRemoved, ::rtl::OUString const & identifier, css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) = 0; @@ -287,6 +321,28 @@ protected: css::uno::Sequence<css::uno::Any> const & args, css::uno::Reference<css::uno::XComponentContext> const & xContext ); + /* creates a folder with a unique name. + If url is empty then it is created in the the backend folder, otherwise + at a location relative to that folder specified by url. + */ + ::rtl::OUString createFolder( + ::rtl::OUString const & relUrl, + css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv); + /* deletes folders and files. + + All folder all files which end with ".tmp" or ".tmp_" and which are + not used are deleted. + */ + void deleteUnusedFolders( + ::rtl::OUString const & relUrl, + ::std::list< ::rtl::OUString> const & usedFolders); + /* deletes one folder with a "temporary" name and the corresponding + tmp file, which was used to derive the folder name. + */ + static void deleteTempFolder( + ::rtl::OUString const & folderUrl); + + public: struct StrRegisteringPackage : public ::dp_misc::StaticResourceString< StrRegisteringPackage, RID_STR_REGISTERING_PACKAGE> {}; @@ -299,6 +355,8 @@ public: inline ::rtl::OUString const & getCachePath() const { return m_cachePath; } inline bool transientMode() const { return m_cachePath.getLength() == 0; } + inline ::rtl::OUString getContext() const {return m_context; } + // XEventListener virtual void SAL_CALL disposing( css::lang::EventObject const & evt ) throw (css::uno::RuntimeException); @@ -306,13 +364,12 @@ public: // XPackageRegistry virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL bindPackage( ::rtl::OUString const & url, ::rtl::OUString const & mediaType, + sal_Bool bRemoved, ::rtl::OUString const & identifier, css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) throw (css::deployment::DeploymentException, + css::deployment::InvalidRemovedParameterException, css::ucb::CommandFailedException, css::lang::IllegalArgumentException, css::uno::RuntimeException); -// virtual css::uno::Sequence< -// css::uno::Reference<css::deployment::XPackageTypeInfo> > SAL_CALL -// getSupportedPackageTypes() throw (css::uno::RuntimeException); }; } diff --git a/desktop/source/deployment/registry/inc/dp_backenddb.hxx b/desktop/source/deployment/registry/inc/dp_backenddb.hxx new file mode 100644 index 000000000000..a0e477979f8c --- /dev/null +++ b/desktop/source/deployment/registry/inc/dp_backenddb.hxx @@ -0,0 +1,170 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if ! defined INCLUDED_DP_BACKENDDB_HXX +#define INCLUDED_DP_BACKENDDB_HXX + +#include "rtl/ustring.hxx" +#include <list> +#include <vector> + +namespace css = ::com::sun::star; + +namespace com { namespace sun { namespace star { + namespace uno { + class XComponentContext; + } + namespace xml { namespace dom { + class XDocument; + class XNode; + }} + namespace xml { namespace xpath { + class XXPathAPI; + }} +}}} + +namespace dp_registry { +namespace backend { + +class BackendDb +{ +private: + + css::uno::Reference<css::xml::dom::XDocument> m_doc; + css::uno::Reference<css::xml::xpath::XXPathAPI> m_xpathApi; + + BackendDb(BackendDb const &); + BackendDb & operator = (BackendDb const &); + +protected: + const css::uno::Reference<css::uno::XComponentContext> m_xContext; + ::rtl::OUString m_urlDb; + +protected: + + /* caller must make sure that only one thread accesses the function + */ + css::uno::Reference<css::xml::dom::XDocument> getDocument(); + + /* the namespace prefix is "reg" (without quotes) + */ + css::uno::Reference<css::xml::xpath::XXPathAPI> getXPathAPI(); + void save(); + void removeElement(::rtl::OUString const & sXPathExpression); + + css::uno::Reference<css::xml::dom::XNode> getKeyElement( + ::rtl::OUString const & url); + + void writeSimpleList( + ::std::list< ::rtl::OUString> const & list, + ::rtl::OUString const & sListTagName, + ::rtl::OUString const & sMemberTagName, + css::uno::Reference<css::xml::dom::XNode> const & xParent); + + void writeVectorOfPair( + ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > > const & vecPairs, + ::rtl::OUString const & sVectorTagName, + ::rtl::OUString const & sPairTagName, + ::rtl::OUString const & sFirstTagName, + ::rtl::OUString const & sSecondTagName, + css::uno::Reference<css::xml::dom::XNode> const & xParent); + + void writeSimpleElement( + ::rtl::OUString const & sElementName, ::rtl::OUString const & value, + css::uno::Reference<css::xml::dom::XNode> const & xParent); + + css::uno::Reference<css::xml::dom::XNode> writeKeyElement( + ::rtl::OUString const & url); + + ::rtl::OUString readSimpleElement( + ::rtl::OUString const & sElementName, + css::uno::Reference<css::xml::dom::XNode> const & xParent); + + ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > > + readVectorOfPair( + css::uno::Reference<css::xml::dom::XNode> const & parent, + ::rtl::OUString const & sListTagName, + ::rtl::OUString const & sPairTagName, + ::rtl::OUString const & sFirstTagName, + ::rtl::OUString const & sSecondTagName); + + ::std::list< ::rtl::OUString> readList( + css::uno::Reference<css::xml::dom::XNode> const & parent, + ::rtl::OUString const & sListTagName, + ::rtl::OUString const & sMemberTagName); + + /* returns the values of one particulary child element of all key elements. + */ + ::std::list< ::rtl::OUString> getOneChildFromAllEntries( + ::rtl::OUString const & sElementName); + + + /* returns the namespace which is to be written as xmlns attribute + into the root element. + */ + virtual ::rtl::OUString getDbNSName()=0; + /* return the namespace prefix which is to be registered with the XPath API. + + The prefix can then be used in XPath expressions. + */ + virtual ::rtl::OUString getNSPrefix()=0; + /* returns the name of the root element without any namespace prefix. + */ + virtual ::rtl::OUString getRootElementName()=0; + /* returns the name of xml element for each entry + */ + virtual ::rtl::OUString getKeyElementName()=0; + + + +public: + BackendDb(css::uno::Reference<css::uno::XComponentContext> const & xContext, + ::rtl::OUString const & url); + virtual ~BackendDb() {}; + + void removeEntry(::rtl::OUString const & url); +}; + +class RegisteredDb: public BackendDb +{ + +public: + RegisteredDb( css::uno::Reference<css::uno::XComponentContext> const & xContext, + ::rtl::OUString const & url); + virtual ~RegisteredDb() {}; + + + virtual void addEntry(::rtl::OUString const & url); + virtual bool getEntry(::rtl::OUString const & url); + +}; + + +} +} +#endif + diff --git a/desktop/source/deployment/registry/makefile.mk b/desktop/source/deployment/registry/makefile.mk index de0e943654d9..e45cec272ca7 100644 --- a/desktop/source/deployment/registry/makefile.mk +++ b/desktop/source/deployment/registry/makefile.mk @@ -41,7 +41,8 @@ INCPRE += inc SLOFILES = \ $(SLO)$/dp_backend.obj \ - $(SLO)$/dp_registry.obj + $(SLO)$/dp_registry.obj \ + $(SLO)$/dp_backenddb.obj .INCLUDE : ..$/target.pmk .INCLUDE : target.mk diff --git a/desktop/source/deployment/registry/package/dp_description.cxx b/desktop/source/deployment/registry/package/dp_description.cxx deleted file mode 100644 index 7c05bfd90a5b..000000000000 --- a/desktop/source/deployment/registry/package/dp_description.cxx +++ /dev/null @@ -1,205 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_desktop.hxx" - -#include "dp_description.hxx" - -#include "cppuhelper/exc_hlp.hxx" -#include "ucbhelper/content.hxx" -#include "com/sun/star/deployment/DeploymentException.hpp" -#include "com/sun/star/xml/dom/XDocumentBuilder.hpp" -#include "com/sun/star/uno/XComponentContext.hpp" -#include "com/sun/star/ucb/CommandFailedException.hpp" -#include "com/sun/star/ucb/InteractiveAugmentedIOException.hpp" -#include "com/sun/star/ucb/IOErrorCode.hpp" - -#include "com/sun/star/beans/PropertyValue.hpp" - - -#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) - -namespace css = com::sun::star; -namespace cssu = com::sun::star::uno; - -namespace dp_registry { -namespace backend { -namespace bundle { - -ExtensionDescription::ExtensionDescription( - const cssu::Reference<cssu::XComponentContext>& xContext, - const ::rtl::OUString& installDir, - const cssu::Reference< css::ucb::XCommandEnvironment >& xCmdEnv) -{ - try { - m_sExtensionRootUrl = installDir; - //may throw ::com::sun::star::ucb::ContentCreationException - //If there is no description.xml then ucb will start an interaction which - //brings up a dialog.We want to prevent this. Therefore we wrap the xCmdEnv - //and filter the respective exception out. - ::rtl::OUString sDescriptionUri(installDir + OUSTR("/description.xml")); - cssu::Reference<css::ucb::XCommandEnvironment> xFilter = - static_cast<css::ucb::XCommandEnvironment*>( - new FileDoesNotExistFilter(xCmdEnv)); - ::ucbhelper::Content descContent(sDescriptionUri, xFilter); - - //throws an com::sun::star::uno::Exception if the file is not available - cssu::Reference<css::io::XInputStream> xIn; - try - { //throws com.sun.star.ucb.InteractiveAugmentedIOException - xIn = descContent.openStream(); - } - catch (cssu::Exception& ) - { - if ( ! static_cast<FileDoesNotExistFilter*>(xFilter.get())->exist()) - throw NoDescriptionException(); - throw; - } - if (!xIn.is()) - { - throw cssu::Exception( - OUSTR("Could not get XInputStream for description.xml of extension ") + - sDescriptionUri, 0); - } - - //get root node of description.xml - cssu::Reference<css::xml::dom::XDocumentBuilder> xDocBuilder( - xContext->getServiceManager()->createInstanceWithContext( - OUSTR("com.sun.star.xml.dom.DocumentBuilder"), - xContext ), cssu::UNO_QUERY); - if (!xDocBuilder.is()) - throw css::uno::Exception(OUSTR(" Could not create service com.sun.star.xml.dom.DocumentBuilder"), 0); - - if (xDocBuilder->isNamespaceAware() == sal_False) - { - throw cssu::Exception( - OUSTR("Service com.sun.star.xml.dom.DocumentBuilder is not namespace aware."), 0); - } - - cssu::Reference<css::xml::dom::XDocument> xDoc = xDocBuilder->parse(xIn); - if (!xDoc.is()) - { - throw cssu::Exception(sDescriptionUri + OUSTR(" contains data which cannot be parsed. "), 0); - } - - //check for proper root element and namespace - cssu::Reference<css::xml::dom::XElement> xRoot = xDoc->getDocumentElement(); - if (!xRoot.is()) - { - throw cssu::Exception( - sDescriptionUri + OUSTR(" contains no root element."), 0); - } - - if ( ! xRoot->getTagName().equals(OUSTR("description"))) - { - throw cssu::Exception( - sDescriptionUri + OUSTR(" does not contain the root element <description>."), 0); - } - - m_xRoot = cssu::Reference<css::xml::dom::XNode>( - xRoot, cssu::UNO_QUERY_THROW); - ::rtl::OUString nsDescription = xRoot->getNamespaceURI(); - - //check if this namespace is supported - if ( ! nsDescription.equals(OUSTR("http://openoffice.org/extensions/description/2006"))) - { - throw cssu::Exception(sDescriptionUri + OUSTR(" contains a root element with an unsupported namespace. "), 0); - } - } catch (css::uno::RuntimeException &) { - throw; - } catch (css::deployment::DeploymentException &) { - throw; - } catch (css::uno::Exception & e) { - css::uno::Any a(cppu::getCaughtException()); - throw css::deployment::DeploymentException( - e.Message, css::uno::Reference< css::uno::XInterface >(), a); - } -} - -ExtensionDescription::~ExtensionDescription() -{ -} - -//====================================================================== -FileDoesNotExistFilter::FileDoesNotExistFilter( - const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv): - m_bExist(true), m_xCommandEnv(xCmdEnv) -{} - -FileDoesNotExistFilter::~FileDoesNotExistFilter() -{ -}; - -bool FileDoesNotExistFilter::exist() -{ - return m_bExist; -} - // XCommandEnvironment -cssu::Reference<css::task::XInteractionHandler > - FileDoesNotExistFilter::getInteractionHandler() throw (css::uno::RuntimeException) -{ - return static_cast<css::task::XInteractionHandler*>(this); -} - -cssu::Reference<css::ucb::XProgressHandler > - FileDoesNotExistFilter::getProgressHandler() throw (css::uno::RuntimeException) -{ - return m_xCommandEnv.is() - ? m_xCommandEnv->getProgressHandler() - : cssu::Reference<css::ucb::XProgressHandler>(); -} - -// XInteractionHandler -//If the interaction was caused by a non-existing file which is specified in the ctor -//of FileDoesNotExistFilter, then we do nothing -void FileDoesNotExistFilter::handle( - cssu::Reference<css::task::XInteractionRequest > const & xRequest ) - throw (css::uno::RuntimeException) -{ - cssu::Any request( xRequest->getRequest() ); - - css::ucb::InteractiveAugmentedIOException ioexc; - if ((request>>= ioexc) && ioexc.Code == css::ucb::IOErrorCode_NOT_EXISTING ) - { - m_bExist = false; - return; - } - css::uno::Reference<css::task::XInteractionHandler> xInteraction; - if (m_xCommandEnv.is()) { - xInteraction = m_xCommandEnv->getInteractionHandler(); - } - if (xInteraction.is()) { - xInteraction->handle(xRequest); - } -} - - -} // namespace bundle -} // namespace backend -} // namespace dp_registry - diff --git a/desktop/source/deployment/registry/package/dp_description.hxx b/desktop/source/deployment/registry/package/dp_description.hxx deleted file mode 100644 index eb74c454af75..000000000000 --- a/desktop/source/deployment/registry/package/dp_description.hxx +++ /dev/null @@ -1,125 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#if !defined INCLUDED_DESKTOP_EXTENSION_DESCRIPTION_HXX -#define INCLUDED_DESKTOP_EXTENSION_DESCRIPTION_HXX - - - -#include "com/sun/star/uno/Reference.hxx" - -#include "com/sun/star/ucb/XCommandEnvironment.hpp" -#include "com/sun/star/uno/XComponentContext.hpp" -#include "com/sun/star/xml/dom/XNode.hpp" -#include "com/sun/star/task/XInteractionHandler.hpp" -#include "cppuhelper/implbase2.hxx" - - -namespace css = ::com::sun::star; - -namespace dp_registry { -namespace backend { -namespace bundle { - -/**The class uses the UCB to access the description.xml file in an - extension. The UCB must have been initialized already. It also - requires that the extension has already be unzipped to a particular - location. - */ -class ExtensionDescription -{ -public: - /**throws an exception if the description.xml is not - available, cannot be read, does not contain the expected data, - or any other error occured. Therefore it shoult only be used with - new extensions. - - Throws com::sun::star::uno::RuntimeException, - com::sun::star::deployment::DeploymentException, - dp_registry::backend::bundle::NoDescriptionException. - */ - ExtensionDescription( - const css::uno::Reference<css::uno::XComponentContext>& xContext, - const ::rtl::OUString& installDir, - const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv); - - ~ExtensionDescription(); - - css::uno::Reference<css::xml::dom::XNode> getRootElement() const - { - return m_xRoot; - } - - ::rtl::OUString getExtensionRootUrl() const - { - return m_sExtensionRootUrl; - } - - -private: - css::uno::Reference<css::xml::dom::XNode> m_xRoot; - ::rtl::OUString m_sExtensionRootUrl; -}; - -class NoDescriptionException -{ -}; - -class FileDoesNotExistFilter - : public ::cppu::WeakImplHelper2< css::ucb::XCommandEnvironment, - css::task::XInteractionHandler > - -{ - //css::uno::Reference<css::task::XInteractionHandler> m_xHandler; - bool m_bExist; - css::uno::Reference< css::ucb::XCommandEnvironment > m_xCommandEnv; - -public: - virtual ~FileDoesNotExistFilter(); - FileDoesNotExistFilter( - const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv); - - bool exist(); - // XCommandEnvironment - virtual css::uno::Reference<css::task::XInteractionHandler > SAL_CALL - getInteractionHandler() throw (css::uno::RuntimeException); - virtual css::uno::Reference<css::ucb::XProgressHandler > - SAL_CALL getProgressHandler() throw (css::uno::RuntimeException); - - // XInteractionHandler - virtual void SAL_CALL handle( - css::uno::Reference<css::task::XInteractionRequest > const & xRequest ) - throw (css::uno::RuntimeException); -}; - - -} // namespace bundle -} // namespace backend -} // namespace dp_registry - - -#endif // INCLUDED_DESKTOP_LICENSE_INTERACT_HXX diff --git a/desktop/source/deployment/registry/package/dp_extbackenddb.cxx b/desktop/source/deployment/registry/package/dp_extbackenddb.cxx new file mode 100644 index 000000000000..2e92a907f8fb --- /dev/null +++ b/desktop/source/deployment/registry/package/dp_extbackenddb.cxx @@ -0,0 +1,135 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "rtl/string.h" +#include "rtl/bootstrap.hxx" +#include "cppuhelper/exc_hlp.hxx" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "com/sun/star/xml/dom/XDocumentBuilder.hpp" +#include "com/sun/star/xml/xpath/XXPathAPI.hpp" +#include "dp_misc.h" + +#include "dp_extbackenddb.hxx" + + +namespace css = ::com::sun::star; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; + +#define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/extension-registry/2010" +#define NS_PREFIX "ext" +#define ROOT_ELEMENT_NAME "extension-backend-db" +#define KEY_ELEMENT_NAME "extension" + +namespace dp_registry { +namespace backend { +namespace bundle { + +ExtensionBackendDb::ExtensionBackendDb( + Reference<XComponentContext> const & xContext, + ::rtl::OUString const & url):BackendDb(xContext, url) +{ + +} + +OUString ExtensionBackendDb::getDbNSName() +{ + return OUSTR(EXTENSION_REG_NS); +} + +OUString ExtensionBackendDb::getNSPrefix() +{ + return OUSTR(NS_PREFIX); +} + +OUString ExtensionBackendDb::getRootElementName() +{ + return OUSTR(ROOT_ELEMENT_NAME); +} + +OUString ExtensionBackendDb::getKeyElementName() +{ + return OUSTR(KEY_ELEMENT_NAME); +} + +void ExtensionBackendDb::addEntry(::rtl::OUString const & url, Data const & data) +{ + try{ + Reference<css::xml::dom::XNode> extensionNodeNode = writeKeyElement(url); + writeVectorOfPair( + data.items, + OUSTR("extension-items"), + OUSTR("item"), + OUSTR("url"), + OUSTR("media-type"), + extensionNodeNode); + save(); + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to write data entry in backend db: ") + + m_urlDb, 0, exc); + } +} + +ExtensionBackendDb::Data ExtensionBackendDb::getEntry(::rtl::OUString const & url) +{ + try + { + ExtensionBackendDb::Data retData; + Reference<css::xml::dom::XNode> aNode = getKeyElement(url); + + if (aNode.is()) + { + retData.items = + readVectorOfPair( + aNode, + OUSTR("extension-items"), + OUSTR("item"), + OUSTR("url"), + OUSTR("media-type")); + } + return retData; + } + catch(css::uno::Exception &) + { + Any exc( ::cppu::getCaughtException() ); + throw css::deployment::DeploymentException( + OUSTR("Extension Manager: failed to read data entry in backend db: ") + + m_urlDb, 0, exc); + } +} + +} // namespace bundle +} // namespace backend +} // namespace dp_registry + diff --git a/desktop/source/deployment/registry/package/dp_extbackenddb.hxx b/desktop/source/deployment/registry/package/dp_extbackenddb.hxx new file mode 100644 index 000000000000..d09fd0891a32 --- /dev/null +++ b/desktop/source/deployment/registry/package/dp_extbackenddb.hxx @@ -0,0 +1,96 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#if ! defined INCLUDED_DP_EXTBACKENDDB_HXX +#define INCLUDED_DP_EXTBACKENDDB_HXX + +#include "rtl/ustring.hxx" +#include "rtl/string.hxx" +#include <vector> +#include "dp_backenddb.hxx" + +namespace css = ::com::sun::star; + +namespace com { namespace sun { namespace star { + namespace uno { + class XComponentContext; + } + namespace xml { namespace dom { + class XDocument; + class XNode; + }} + namespace xml { namespace xpath { + class XXPathAPI; + }} +}}} + +namespace dp_registry { +namespace backend { +namespace bundle { + +/* The XML file stores the extensions which are currently registered. + They will be removed when they are revoked. + */ +class ExtensionBackendDb: public dp_registry::backend::BackendDb +{ +protected: + virtual ::rtl::OUString getDbNSName(); + virtual ::rtl::OUString getNSPrefix(); + virtual ::rtl::OUString getRootElementName(); + virtual ::rtl::OUString getKeyElementName(); + +public: + struct Data + { + /* every element consists of a pair of the url to the item (jar,rdb, etc) + and the media type + */ + ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString> > items; + typedef ::std::vector< + ::std::pair< ::rtl::OUString, ::rtl::OUString> >::const_iterator ITC_ITEMS; + + }; + +public: + + ExtensionBackendDb( css::uno::Reference<css::uno::XComponentContext> const & xContext, + ::rtl::OUString const & url); + + void addEntry(::rtl::OUString const & url, Data const & data); + + Data getEntry(::rtl::OUString const & url); + +}; + + + +} +} +} +#endif + diff --git a/desktop/source/deployment/registry/package/dp_package.cxx b/desktop/source/deployment/registry/package/dp_package.cxx index b0b4a918c7a3..2ad6478b665c 100644 --- a/desktop/source/deployment/registry/package/dp_package.cxx +++ b/desktop/source/deployment/registry/package/dp_package.cxx @@ -34,7 +34,6 @@ #include "dp_interact.h" #include "dp_dependencies.hxx" #include "dp_platform.hxx" -#include "dp_description.hxx" #include "dp_descriptioninfoset.hxx" #include "dp_identifier.hxx" #include "rtl/uri.hxx" @@ -65,8 +64,8 @@ #include "com/sun/star/packages/manifest/XManifestWriter.hpp" #include "com/sun/star/deployment/DependencyException.hpp" #include "com/sun/star/deployment/LicenseException.hpp" -#include "com/sun/star/deployment/LicenseIndividualAgreementException.hpp" #include "com/sun/star/deployment/PlatformException.hpp" +#include "com/sun/star/deployment/Prerequisites.hpp" #include "com/sun/star/xml/dom/XDocumentBuilder.hpp" #include "com/sun/star/xml/xpath/XXPathAPI.hpp" #include "com/sun/star/deployment/XPackageManager.hpp" @@ -74,13 +73,13 @@ #include <vector> #include <stdio.h> - +#include "dp_extbackenddb.hxx" using namespace ::dp_misc; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::ucb; + namespace css = ::com::sun::star; -namespace cssu = ::com::sun::star::uno; + using ::rtl::OUString; namespace dp_registry { @@ -106,44 +105,48 @@ class BackendImpl : public ImplBaseT Sequence< Reference<deployment::XPackage> > m_bundle; Sequence< Reference<deployment::XPackage> > * m_pBundle; + ExtensionBackendDb::Data m_dbData; + Reference<deployment::XPackage> bindBundleItem( OUString const & url, OUString const & mediaType, - Reference<XCommandEnvironment> const & xCmdEnv, + sal_Bool bRemoved, //that is, useing data base information + OUString const & identifier, + Reference<ucb::XCommandEnvironment> const & xCmdEnv, bool notifyDetectionError = true ); typedef ::std::vector< Reference<deployment::XPackage> > t_packagevec; void scanBundle( t_packagevec & bundle, ::rtl::Reference<AbortChannel> const & abortChannel, - Reference<XCommandEnvironment> const & xCmdEnv ); + Reference<ucb::XCommandEnvironment> const & xCmdEnv ); void scanLegacyBundle( t_packagevec & bundle, OUString const & url, ::rtl::Reference<AbortChannel> const & abortChannel, - Reference<XCommandEnvironment> const & xCmdEnv, + Reference<ucb::XCommandEnvironment> const & xCmdEnv, bool skip_registration = false ); - + ::std::vector<Reference<deployment::XPackage> > getPackagesFromDb( + Reference<ucb::XCommandEnvironment> const & xCmdEnv); bool checkPlatform( - css::uno::Reference< css::ucb::XCommandEnvironment > const & environment); + Reference<ucb::XCommandEnvironment > const & environment); bool checkDependencies( - css::uno::Reference< css::ucb::XCommandEnvironment > const & + Reference<ucb::XCommandEnvironment > const & environment, - ExtensionDescription const & description); + DescriptionInfoset const & description); // throws css::uno::RuntimeException, // css::deployment::DeploymentException ::sal_Bool checkLicense( - css::uno::Reference< css::ucb::XCommandEnvironment > const & xCmdEnv, - ExtensionDescription const& description, bool bInstalled, - OUString const & aContextName ) - throw (css::deployment::DeploymentException, - css::ucb::CommandFailedException, - css::ucb::CommandAbortedException, - css::uno::RuntimeException); + Reference< ucb::XCommandEnvironment > const & xCmdEnv, + DescriptionInfoset const & description, bool bNoLicenseChecking) + throw (deployment::DeploymentException, + ucb::CommandFailedException, + ucb::CommandAbortedException, + RuntimeException); // @throws DeploymentException OUString getTextFromURL( - const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv, + const Reference< ucb::XCommandEnvironment >& xCmdEnv, const OUString& licenseUrl); DescriptionInfoset getDescriptionInfoset(); @@ -152,12 +155,13 @@ class BackendImpl : public ImplBaseT virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_( ::osl::ResettableMutexGuard & guard, ::rtl::Reference<AbortChannel> const & abortChannel, - Reference<XCommandEnvironment> const & xCmdEnv ); + Reference<ucb::XCommandEnvironment> const & xCmdEnv ); virtual void processPackage_( ::osl::ResettableMutexGuard & guard, bool registerPackage, + bool startup, ::rtl::Reference<AbortChannel> const & abortChannel, - Reference<XCommandEnvironment> const & xCmdEnv ); + Reference<ucb::XCommandEnvironment> const & xCmdEnv ); virtual void SAL_CALL disposing(); @@ -169,57 +173,68 @@ class BackendImpl : public ImplBaseT OUString const & url, OUString const & name, Reference<deployment::XPackageTypeInfo> const & xPackageType, - bool legacyBundle ) - : Package( myBackend, url, name, name /* display-name */, - xPackageType ), - m_url_expanded( expandUnoRcUrl( url ) ), - m_legacyBundle( legacyBundle ), - m_pBundle( 0 ) - {} + bool legacyBundle, + bool bRemoved, + OUString const & identifier); // XPackage virtual sal_Bool SAL_CALL isBundle() throw (RuntimeException); + virtual Sequence< Reference<deployment::XPackage> > SAL_CALL getBundle( Reference<task::XAbortChannel> const & xAbortChannel, - Reference<XCommandEnvironment> const & xCmdEnv ) + Reference<ucb::XCommandEnvironment> const & xCmdEnv ) throw (deployment::DeploymentException, - CommandFailedException, CommandAbortedException, + ucb::CommandFailedException, + ucb::CommandAbortedException, lang::IllegalArgumentException, RuntimeException); - virtual OUString SAL_CALL getDescription() throw (RuntimeException); + virtual OUString SAL_CALL getDescription() + throw (deployment::ExtensionRemovedException, RuntimeException); + virtual void SAL_CALL exportTo( OUString const & destFolderURL, OUString const & newTitle, sal_Int32 nameClashAction, - Reference<XCommandEnvironment> const & xCmdEnv ) - throw (CommandFailedException, CommandAbortedException, + Reference<ucb::XCommandEnvironment> const & xCmdEnv ) + throw (deployment::ExtensionRemovedException, + ucb::CommandFailedException, + ucb::CommandAbortedException, RuntimeException); - virtual ::sal_Bool SAL_CALL checkPrerequisites( - const css::uno::Reference< css::task::XAbortChannel >& xAbortChannel, - const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv, - ::sal_Bool bInstalled, OUString const & aContextName) - throw (css::deployment::DeploymentException, - css::ucb::CommandFailedException, - css::ucb::CommandAbortedException, - css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL checkPrerequisites( + const Reference< task::XAbortChannel >& xAbortChannel, + const Reference< ucb::XCommandEnvironment >& xCmdEnv, + ::sal_Bool noLicenseChecking) + throw (deployment::ExtensionRemovedException, + deployment::DeploymentException, + ucb::CommandFailedException, + ucb::CommandAbortedException, + RuntimeException); virtual ::sal_Bool SAL_CALL checkDependencies( - const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv ) - throw (css::deployment::DeploymentException, - css::ucb::CommandFailedException, - css::uno::RuntimeException); + const Reference< ucb::XCommandEnvironment >& xCmdEnv ) + throw (deployment::DeploymentException, + deployment::ExtensionRemovedException, + ucb::CommandFailedException, + RuntimeException); virtual beans::Optional<OUString> SAL_CALL getIdentifier() throw (RuntimeException); - virtual OUString SAL_CALL getVersion() throw (RuntimeException); + virtual OUString SAL_CALL getVersion() + throw (deployment::ExtensionRemovedException, RuntimeException); virtual Sequence<OUString> SAL_CALL getUpdateInformationURLs() - throw (RuntimeException); + throw (deployment::ExtensionRemovedException, RuntimeException); - virtual css::beans::StringPair SAL_CALL getPublisherInfo() throw (css::uno::RuntimeException); + virtual beans::StringPair SAL_CALL getPublisherInfo() + throw (deployment::ExtensionRemovedException, RuntimeException); - virtual OUString SAL_CALL getDisplayName() throw (RuntimeException); - virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL getIcon( ::sal_Bool bHighContrast ) throw (css::uno::RuntimeException); + virtual OUString SAL_CALL getDisplayName() + throw (deployment::ExtensionRemovedException, RuntimeException); + + virtual Reference< graphic::XGraphic > SAL_CALL + getIcon( ::sal_Bool bHighContrast ) + throw (deployment::ExtensionRemovedException, + RuntimeException); }; friend class PackageImpl; @@ -228,10 +243,17 @@ class BackendImpl : public ImplBaseT const Reference<deployment::XPackageTypeInfo> m_xLegacyBundleTypeInfo; Sequence< Reference<deployment::XPackageTypeInfo> > m_typeInfos; + std::auto_ptr<ExtensionBackendDb> m_backendDb; + + void addDataToDb(OUString const & url, ExtensionBackendDb::Data const & data); + ExtensionBackendDb::Data readDataFromDb(OUString const & url); + void deleteDataFromDb(OUString const & url); + // PackageRegistryBackend virtual Reference<deployment::XPackage> bindPackage_( OUString const & url, OUString const & mediaType, - Reference<XCommandEnvironment> const & xCmdEnv ); + sal_Bool bRemoved, OUString const & identifier, + Reference<ucb::XCommandEnvironment> const & xCmdEnv ); virtual void SAL_CALL disposing(); @@ -291,6 +313,14 @@ BackendImpl::BackendImpl( { m_typeInfos[ 0 ] = m_xBundleTypeInfo; m_typeInfos[ 1 ] = m_xLegacyBundleTypeInfo; + + if (!transientMode()) + { + OUString dbFile = makeURL(getCachePath(), getImplementationName()); + dbFile = makeURL(dbFile, OUSTR("backenddb.xml")); + m_backendDb.reset( + new ExtensionBackendDb(getComponentContext(), dbFile)); + } } //______________________________________________________________________________ @@ -333,7 +363,8 @@ BackendImpl::getSupportedPackageTypes() throw (RuntimeException) //______________________________________________________________________________ Reference<deployment::XPackage> BackendImpl::bindPackage_( OUString const & url, OUString const & mediaType_, - Reference<XCommandEnvironment> const & xCmdEnv ) + sal_Bool bRemoved, OUString const & identifier, + Reference<ucb::XCommandEnvironment> const & xCmdEnv ) { OUString mediaType( mediaType_ ); if (mediaType.getLength() == 0) @@ -347,7 +378,7 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( //Every .oxt, uno.pkg file must contain a META-INF folder ::ucbhelper::Content metaInfContent; if (create_ucb_content( - &metaInfContent, makeURL( url, OUSTR("META-INF/manifest.xml") ), + &metaInfContent, makeURL( url, OUSTR("META-INF") ), xCmdEnv, false /* no throw */ )) { mediaType = OUSTR("application/vnd.sun.star.package-bundle"); @@ -381,19 +412,26 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( { if (type.EqualsIgnoreCaseAscii("application")) { - ::ucbhelper::Content ucbContent( url, xCmdEnv ); + + //In case a XPackage is created for a removed extension, we cannot + //obtain the name + OUString name; + if (!bRemoved) + { + ::ucbhelper::Content ucbContent( url, xCmdEnv ); + name = ucbContent.getPropertyValue( + StrTitle::get() ).get<OUString>(); + } if (subType.EqualsIgnoreCaseAscii("vnd.sun.star.package-bundle")) { return new PackageImpl( - this, url, ucbContent.getPropertyValue( - StrTitle::get() ).get<OUString>(), - m_xBundleTypeInfo, false ); + this, url, name, m_xBundleTypeInfo, false, bRemoved, + identifier); } else if (subType.EqualsIgnoreCaseAscii( "vnd.sun.star.legacy-package-bundle")) { return new PackageImpl( - this, url, ucbContent.getPropertyValue( - StrTitle::get() ).get<OUString>(), - m_xLegacyBundleTypeInfo, true ); + this, url, name, m_xLegacyBundleTypeInfo, true, bRemoved, + identifier); } } } @@ -403,8 +441,47 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( static_cast<sal_Int16>(-1) ); } +void BackendImpl::addDataToDb( + OUString const & url, ExtensionBackendDb::Data const & data) +{ + if (m_backendDb.get()) + m_backendDb->addEntry(url, data); +} + +ExtensionBackendDb::Data BackendImpl::readDataFromDb( + OUString const & url) +{ + ExtensionBackendDb::Data data; + if (m_backendDb.get()) + data = m_backendDb->getEntry(url); + return data; +} + +void BackendImpl::deleteDataFromDb(OUString const & url) +{ + if (m_backendDb.get()) + m_backendDb->removeEntry(url); +} + + //############################################################################## +BackendImpl::PackageImpl::PackageImpl( + ::rtl::Reference<PackageRegistryBackend> const & myBackend, + OUString const & url, + OUString const & name, + Reference<deployment::XPackageTypeInfo> const & xPackageType, + bool legacyBundle, bool bRemoved, OUString const & identifier) + : Package( myBackend, url, name, name /* display-name */, + xPackageType, bRemoved, identifier), + m_url_expanded( expandUnoRcUrl( url ) ), + m_legacyBundle( legacyBundle ), + m_pBundle( 0 ) +{ + if (bRemoved) + m_dbData = getMyBackend()->readDataFromDb(url); +} + BackendImpl * BackendImpl::PackageImpl::getMyBackend() const { BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get()); @@ -437,22 +514,23 @@ beans::Optional< beans::Ambiguous<sal_Bool> > BackendImpl::PackageImpl::isRegistered_( ::osl::ResettableMutexGuard &, ::rtl::Reference<AbortChannel> const & abortChannel, - Reference<XCommandEnvironment> const & xCmdEnv ) + Reference<ucb::XCommandEnvironment> const & xCmdEnv ) { + //In case the object was created for a removed extension (m_bRemoved = true) + //but the extension is not registered, then bundle will be empty. Then + //the return value will be Optional<...>.IsPresent= false. Althoug this is + //not true, this does not matter. Then registerPackage or revokePackage + //would never be called for the items. But since the extension is removed + //and not registered anyway, this does not matter. const Sequence< Reference<deployment::XPackage> > bundle( getBundle( abortChannel.get(), xCmdEnv ) ); + bool reg = false; bool present = false; bool ambig = false; for ( sal_Int32 pos = bundle.getLength(); pos--; ) { Reference<deployment::XPackage> const & xPackage = bundle[ pos ]; - //disregard executable (application/vnd.sun.star.executable) - //it will not be disabled/enabled. - OUString sType = xPackage->getPackageType()->getMediaType(); - if (sType.equals(OUSTR("application/vnd.sun.star.executable"))) - continue; - Reference<task::XAbortChannel> xSubAbortChannel( xPackage->createAbortChannel() ); AbortChannel::Chain chain( abortChannel, xSubAbortChannel ); @@ -510,23 +588,7 @@ OUString BackendImpl::PackageImpl::getTextFromURL( DescriptionInfoset BackendImpl::PackageImpl::getDescriptionInfoset() { - css::uno::Reference< css::xml::dom::XNode > root; - try { - root = - ExtensionDescription( - getMyBackend()->getComponentContext(), m_url_expanded, - css::uno::Reference< css::ucb::XCommandEnvironment >()). - getRootElement(); - } catch (NoDescriptionException &) { - } catch (css::deployment::DeploymentException & e) { - throw RuntimeException( - (OUString( - RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.deployment.DeploymentException: ")) + - e.Message), - static_cast< OWeakObject * >(this)); - } - return DescriptionInfoset(getMyBackend()->getComponentContext(), root); + return dp_misc::getDescriptionInfoset(m_url_expanded); } bool BackendImpl::PackageImpl::checkPlatform( @@ -561,14 +623,11 @@ bool BackendImpl::PackageImpl::checkPlatform( bool BackendImpl::PackageImpl::checkDependencies( css::uno::Reference< css::ucb::XCommandEnvironment > const & environment, - ExtensionDescription const & description) + DescriptionInfoset const & description) { css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > > - unsatisfied( - dp_misc::Dependencies::check( - DescriptionInfoset( - getMyBackend()->getComponentContext(), - description.getRootElement()))); + unsatisfied(dp_misc::Dependencies::check(description)); + if (unsatisfied.getLength() == 0) { return true; } else { @@ -590,7 +649,7 @@ bool BackendImpl::PackageImpl::checkDependencies( ::sal_Bool BackendImpl::PackageImpl::checkLicense( css::uno::Reference< css::ucb::XCommandEnvironment > const & xCmdEnv, - ExtensionDescription const & desc, bool bInstalled, OUString const & aContextName) + DescriptionInfoset const & info, bool alreadyInstalled) throw (css::deployment::DeploymentException, css::ucb::CommandFailedException, css::ucb::CommandAbortedException, @@ -598,7 +657,6 @@ bool BackendImpl::PackageImpl::checkDependencies( { try { - DescriptionInfoset info = getDescriptionInfoset(); ::boost::optional<SimpleLicenseAttributes> simplLicAttr = info.getSimpleLicenseAttributes(); if (! simplLicAttr) @@ -610,7 +668,7 @@ bool BackendImpl::PackageImpl::checkDependencies( if (sLic.getLength() == 0) throw css::deployment::DeploymentException( OUSTR("Could not obtain path to license. Possible error in description.xml"), 0, Any()); - OUString sHref = desc.getExtensionRootUrl() + OUSTR("/") + sLic; + OUString sHref = m_url_expanded + OUSTR("/") + sLic; OUString sLicense = getTextFromURL(xCmdEnv, sHref); ////determine who has to agree to the license //check correct value for attribute @@ -618,41 +676,21 @@ bool BackendImpl::PackageImpl::checkDependencies( throw css::deployment::DeploymentException( OUSTR("Could not obtain attribute simple-lincense@accept-by or it has no valid value"), 0, Any()); - //If if @accept-by="user" then every user needs to accept the license before it can be installed. - //Therefore we must prevent the installation as shared extension unless suppress-if-required="true" - OSL_ASSERT(aContextName.getLength()); - if (simplLicAttr->acceptBy.equals(OUSTR("user")) && aContextName.equals(OUSTR("shared"))) - { - css::deployment::LicenseIndividualAgreementException - exc = css::deployment::LicenseIndividualAgreementException( - OUString(), 0, m_name, simplLicAttr->suppressIfRequired); - - bool approve = false; - bool abort = false; - if (! interactContinuation( - Any(exc), task::XInteractionApprove::static_type(), xCmdEnv, &approve, &abort )) - throw css::deployment::DeploymentException( - OUSTR("Could not interact with user."), 0, Any()); - if (abort == true) - return false; - - //If the unopkg --suppress-license was used and simplLicAttr->suppressIfRequired == true, - //then the user implicitely accepts the license - } //Only use interaction if there is no version of this extension already installed //and the suppress-on-update flag is not set for the new extension - // bInstalled | bSuppressOnUpdate | show license + // alreadyInstalled | bSuppressOnUpdate | show license //---------------------------------------- // 0 | 0 | 1 // 0 | 1 | 1 // 1 | 0 | 1 // 1 | 1 | 0 - if ( !(bInstalled && simplLicAttr->suppressOnUpdate)) + if ( !(alreadyInstalled && simplLicAttr->suppressOnUpdate)) { css::deployment::LicenseException licExc( - OUString(), 0, m_name, sLicense, simplLicAttr->suppressIfRequired); + OUString(), 0, getDisplayName(), sLicense, + simplLicAttr->acceptBy); bool approve = false; bool abort = false; if (! interactContinuation( @@ -684,69 +722,88 @@ bool BackendImpl::PackageImpl::checkDependencies( } } -::sal_Bool BackendImpl::PackageImpl::checkPrerequisites( +::sal_Int32 BackendImpl::PackageImpl::checkPrerequisites( const css::uno::Reference< css::task::XAbortChannel >&, const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv, - sal_Bool bInstalled, OUString const & aContextName) + sal_Bool alreadyInstalled) throw (css::deployment::DeploymentException, - css::ucb::CommandFailedException, - css::ucb::CommandAbortedException, - css::uno::RuntimeException) + css::deployment::ExtensionRemovedException, + css::ucb::CommandFailedException, + css::ucb::CommandAbortedException, + css::uno::RuntimeException) { - std::auto_ptr<ExtensionDescription> spDescription; - try { - spDescription.reset( - new ExtensionDescription( - getMyBackend()->getComponentContext(), - m_url_expanded, - xCmdEnv)); - } catch (NoDescriptionException& ) { - return sal_True; - } - return checkPlatform(xCmdEnv) - && checkDependencies(xCmdEnv, *spDescription) - && checkLicense(xCmdEnv, *spDescription, bInstalled, aContextName); + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); + DescriptionInfoset info = getDescriptionInfoset(); + if (!info.hasDescription()) + return 0; + + //always return LICENSE as long as the user did not accept the license + //so that XExtensonManager::checkPrerequisitesAndEnable will again + //check the license + if (!checkPlatform(xCmdEnv)) + return deployment::Prerequisites::PLATFORM | + deployment::Prerequisites::LICENSE; + else if(!checkDependencies(xCmdEnv, info)) + return deployment::Prerequisites::DEPENDENCIES | + deployment::Prerequisites::LICENSE; + else if(!checkLicense(xCmdEnv, info, alreadyInstalled)) + return deployment::Prerequisites::LICENSE; + else + return 0; } ::sal_Bool BackendImpl::PackageImpl::checkDependencies( const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv ) - throw (css::deployment::DeploymentException, - css::ucb::CommandFailedException, - css::uno::RuntimeException) + throw (deployment::DeploymentException, + deployment::ExtensionRemovedException, + ucb::CommandFailedException, + RuntimeException) { - std::auto_ptr<ExtensionDescription> spDescription; - try { - spDescription.reset( - new ExtensionDescription( getMyBackend()->getComponentContext(), m_url_expanded, xCmdEnv )); - } catch (NoDescriptionException& ) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); + DescriptionInfoset info = getDescriptionInfoset(); + if (!info.hasDescription()) return sal_True; - } - return checkDependencies(xCmdEnv, *spDescription); + + return checkDependencies(xCmdEnv, info); } beans::Optional<OUString> BackendImpl::PackageImpl::getIdentifier() throw (RuntimeException) { + OUString identifier; + if (m_bRemoved) + identifier = m_identifier; + else + identifier = dp_misc::generateIdentifier( + getDescriptionInfoset().getIdentifier(), m_name); + return beans::Optional<OUString>( - true, - dp_misc::generateIdentifier( - getDescriptionInfoset().getIdentifier(), m_name)); + true, identifier); } -OUString BackendImpl::PackageImpl::getVersion() throw (RuntimeException) +OUString BackendImpl::PackageImpl::getVersion() + throw (deployment::ExtensionRemovedException, RuntimeException) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); return getDescriptionInfoset().getVersion(); } Sequence<OUString> BackendImpl::PackageImpl::getUpdateInformationURLs() - throw (RuntimeException) + throw (deployment::ExtensionRemovedException, RuntimeException) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); return getDescriptionInfoset().getUpdateInformationUrls(); } beans::StringPair BackendImpl::PackageImpl::getPublisherInfo() - throw (RuntimeException) + throw (deployment::ExtensionRemovedException, RuntimeException) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); ::std::pair< OUString, OUString > aInfo = getDescriptionInfoset().getLocalizedPublisherNameAndURL(); beans::StringPair aStrPair( aInfo.first, aInfo.second ); return aStrPair; @@ -754,8 +811,11 @@ beans::StringPair BackendImpl::PackageImpl::getPublisherInfo() //______________________________________________________________________________ uno::Reference< graphic::XGraphic > BackendImpl::PackageImpl::getIcon( sal_Bool bHighContrast ) - throw ( RuntimeException ) + throw (deployment::ExtensionRemovedException, RuntimeException ) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); + uno::Reference< graphic::XGraphic > xGraphic; OUString aIconURL = getDescriptionInfoset().getIconURL( bHighContrast ); @@ -785,14 +845,16 @@ uno::Reference< graphic::XGraphic > BackendImpl::PackageImpl::getIcon( sal_Bool void BackendImpl::PackageImpl::processPackage_( ::osl::ResettableMutexGuard &, bool doRegisterPackage, + bool startup, ::rtl::Reference<AbortChannel> const & abortChannel, - Reference<XCommandEnvironment> const & xCmdEnv ) + Reference<ucb::XCommandEnvironment> const & xCmdEnv ) { const Sequence< Reference<deployment::XPackage> > bundle( getBundle( abortChannel.get(), xCmdEnv ) ); if (doRegisterPackage) { + ExtensionBackendDb::Data data; const sal_Int32 len = bundle.getLength(); for ( sal_Int32 pos = 0; pos < len; ++pos ) { @@ -802,12 +864,12 @@ void BackendImpl::PackageImpl::processPackage_( xPackage->createAbortChannel() ); AbortChannel::Chain chain( abortChannel, xSubAbortChannel ); try { - xPackage->registerPackage( xSubAbortChannel, xCmdEnv ); + xPackage->registerPackage( startup, xSubAbortChannel, xCmdEnv ); } catch (RuntimeException &) { throw; } - catch (CommandAbortedException &) { + catch (ucb::CommandAbortedException &) { throw; } catch (Exception &) { @@ -845,7 +907,7 @@ void BackendImpl::PackageImpl::processPackage_( catch (RuntimeException &) { throw; } - catch (CommandAbortedException &) { + catch (ucb::CommandAbortedException &) { throw; } catch (Exception &) { @@ -862,7 +924,7 @@ void BackendImpl::PackageImpl::processPackage_( deployment::DeploymentException dpExc; if (exc >>= dpExc) { - throw CommandFailedException( + throw ucb::CommandFailedException( dpExc.Message, dpExc.Context, dpExc.Cause ); } else { @@ -870,7 +932,11 @@ void BackendImpl::PackageImpl::processPackage_( ::cppu::throwException(exc); } } + data.items.push_back( + ::std::make_pair(xPackage->getURL(), + xPackage->getPackageType()->getMediaType())); } + getMyBackend()->addDataToDb(getURL(), data); } else { @@ -888,7 +954,7 @@ void BackendImpl::PackageImpl::processPackage_( catch (RuntimeException &) { throw; } - catch (CommandAbortedException &) { + catch (ucb::CommandAbortedException &) { throw; } catch (Exception &) { @@ -914,12 +980,17 @@ void BackendImpl::PackageImpl::processPackage_( // selected } } + getMyBackend()->deleteDataFromDb(getURL()); } } //______________________________________________________________________________ -OUString BackendImpl::PackageImpl::getDescription() throw (RuntimeException) +OUString BackendImpl::PackageImpl::getDescription() + throw (deployment::ExtensionRemovedException, RuntimeException) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); + const OUString sRelativeURL(getDescriptionInfoset().getLocalizedDescriptionURL()); OUString sDescription; if (sRelativeURL.getLength()) @@ -940,9 +1011,14 @@ OUString BackendImpl::PackageImpl::getDescription() throw (RuntimeException) //______________________________________________________________________________ void BackendImpl::PackageImpl::exportTo( OUString const & destFolderURL, OUString const & newTitle, - sal_Int32 nameClashAction, Reference<XCommandEnvironment> const & xCmdEnv ) - throw (CommandFailedException, CommandAbortedException, RuntimeException) + sal_Int32 nameClashAction, Reference<ucb::XCommandEnvironment> const & xCmdEnv ) + throw (ucb::CommandFailedException, + deployment::ExtensionRemovedException, + ucb::CommandAbortedException, RuntimeException) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); + ::ucbhelper::Content sourceContent( m_url_expanded, xCmdEnv ); OUString title(newTitle); if (title.getLength() == 0) @@ -952,25 +1028,25 @@ void BackendImpl::PackageImpl::exportTo( rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8 ) ) ); - if (nameClashAction == NameClash::ASK) + if (nameClashAction == ucb::NameClash::ASK) { if (create_ucb_content( 0, destURL, xCmdEnv, false /* no throw */ )) { bool replace = false, abort = false; if (! interactContinuation( - Any( NameClashResolveRequest( + Any( ucb::NameClashResolveRequest( OUSTR("file already exists: ") + title, static_cast<OWeakObject *>(this), task::InteractionClassification_QUERY, destFolderURL, title, OUString() ) ), - XInteractionReplaceExistingData::static_type(), xCmdEnv, + ucb::XInteractionReplaceExistingData::static_type(), xCmdEnv, &replace, &abort ) || !replace) { return; } } } - else if (nameClashAction != NameClash::OVERWRITE) { - throw CommandFailedException( + else if (nameClashAction != ucb::NameClash::OVERWRITE) { + throw ucb::CommandFailedException( OUSTR("unsupported nameClashAction!"), static_cast<OWeakObject *>(this), Any() ); } @@ -996,11 +1072,11 @@ void BackendImpl::PackageImpl::exportTo( while (xResultSet->next()) { ::ucbhelper::Content subContent( - Reference<XContentAccess>( + Reference<ucb::XContentAccess>( xResultSet, UNO_QUERY_THROW )->queryContent(), xCmdEnv ); if (! destFolderContent.transferContent( subContent, ::ucbhelper::InsertOperation_COPY, - OUString(), NameClash::OVERWRITE )) + OUString(), ucb::NameClash::OVERWRITE )) throw RuntimeException( OUSTR("UCB transferContent() failed!"), static_cast<OWeakObject *>(this) ); progress.update( Any() ); // animating progress bar @@ -1108,7 +1184,7 @@ void BackendImpl::PackageImpl::exportTo( if (! metainfFolderContent.transferContent( manifestContent, ::ucbhelper::InsertOperation_COPY, - OUString(), NameClash::OVERWRITE )) + OUString(), ucb::NameClash::OVERWRITE )) throw RuntimeException( OUSTR("UCB transferContent() failed!"), static_cast<OWeakObject *>(this) ); } @@ -1117,7 +1193,7 @@ void BackendImpl::PackageImpl::exportTo( try { destFolderContent.executeCommand( OUSTR("flush"), Any() ); } - catch (UnsupportedCommandException &) { + catch (ucb::UnsupportedCommandException &) { } } @@ -1130,67 +1206,76 @@ sal_Bool BackendImpl::PackageImpl::isBundle() throw (RuntimeException) //______________________________________________________________________________ Sequence< Reference<deployment::XPackage> > BackendImpl::PackageImpl::getBundle( Reference<task::XAbortChannel> const & xAbortChannel, - Reference<XCommandEnvironment> const & xCmdEnv ) + Reference<ucb::XCommandEnvironment> const & xCmdEnv ) throw (deployment::DeploymentException, - CommandFailedException, CommandAbortedException, + ucb::CommandFailedException, ucb::CommandAbortedException, lang::IllegalArgumentException, RuntimeException) { Sequence< Reference<deployment::XPackage> > * pBundle = m_pBundle; if (pBundle == 0) { t_packagevec bundle; - try { - if (m_legacyBundle) - { - // .zip legacy packages allow script.xlb, dialog.xlb in bundle - // root folder: - OUString mediaType; - // probe for script.xlb: - if (create_ucb_content( - 0, makeURL( m_url_expanded, OUSTR("script.xlb") ), - xCmdEnv, false /* no throw */ )) { - mediaType = OUSTR("application/vnd.sun.star.basic-library"); + if (m_bRemoved) + { + bundle = getPackagesFromDb(xCmdEnv); + } + else + { + try { + if (m_legacyBundle) + { + // .zip legacy packages allow script.xlb, dialog.xlb in bundle + // root folder: + OUString mediaType; + // probe for script.xlb: + if (create_ucb_content( + 0, makeURL( m_url_expanded, OUSTR("script.xlb") ), + xCmdEnv, false /* no throw */ )) { + mediaType = OUSTR("application/vnd.sun.star.basic-library"); + } + // probe for dialog.xlb: + else if (create_ucb_content( + 0, makeURL( m_url_expanded, OUSTR("dialog.xlb") ), + xCmdEnv, false /* no throw */ )) + mediaType = OUSTR("application/vnd.sun.star." + "dialog-library"); + + if (mediaType.getLength() > 0) { + const Reference<deployment::XPackage> xPackage( + bindBundleItem( getURL(), mediaType, false, OUString(), + xCmdEnv ) ); + if (xPackage.is()) + bundle.push_back( xPackage ); + // continue scanning: + } + scanLegacyBundle( bundle, getURL(), + AbortChannel::get(xAbortChannel), xCmdEnv ); } - // probe for dialog.xlb: - else if (create_ucb_content( - 0, makeURL( m_url_expanded, OUSTR("dialog.xlb") ), - xCmdEnv, false /* no throw */ )) - mediaType = OUSTR("application/vnd.sun.star." - "dialog-library"); - - if (mediaType.getLength() > 0) { - const Reference<deployment::XPackage> xPackage( - bindBundleItem( getURL(), mediaType, xCmdEnv ) ); - if (xPackage.is()) - bundle.push_back( xPackage ); - // continue scanning: + else + { + // .oxt: + scanBundle( bundle, AbortChannel::get(xAbortChannel), xCmdEnv ); } - scanLegacyBundle( bundle, getURL(), - AbortChannel::get(xAbortChannel), xCmdEnv ); + } - else - { - // .oxt: - scanBundle( bundle, AbortChannel::get(xAbortChannel), xCmdEnv ); + catch (RuntimeException &) { + throw; + } + catch (ucb::CommandFailedException &) { + throw; + } + catch (ucb::CommandAbortedException &) { + throw; + } + catch (deployment::DeploymentException &) { + throw; + } + catch (Exception &) { + Any exc( ::cppu::getCaughtException() ); + throw deployment::DeploymentException( + OUSTR("error scanning bundle: ") + getURL(), + static_cast<OWeakObject *>(this), exc ); } - } - catch (RuntimeException &) { - throw; - } - catch (CommandFailedException &) { - throw; - } - catch (CommandAbortedException &) { - throw; - } - catch (deployment::DeploymentException &) { - throw; - } - catch (Exception &) { - Any exc( ::cppu::getCaughtException() ); - throw deployment::DeploymentException( - OUSTR("error scanning bundle: ") + getURL(), - static_cast<OWeakObject *>(this), exc ); } // sort: schema before config data, typelibs before components: @@ -1257,7 +1342,8 @@ inline bool isBundle_( OUString const & mediaType ) //______________________________________________________________________________ Reference<deployment::XPackage> BackendImpl::PackageImpl::bindBundleItem( OUString const & url, OUString const & mediaType, - Reference<XCommandEnvironment> const & xCmdEnv, + sal_Bool bRemoved, OUString const & identifier, + Reference<ucb::XCommandEnvironment> const & xCmdEnv, bool notifyDetectionError ) { // ignore any nested bundles: @@ -1267,13 +1353,13 @@ Reference<deployment::XPackage> BackendImpl::PackageImpl::bindBundleItem( Reference<deployment::XPackage>xPackage; try { xPackage.set( getMyBackend()->m_xRootRegistry->bindPackage( - url, mediaType, xCmdEnv ) ); + url, mediaType, bRemoved, identifier, xCmdEnv ) ); OSL_ASSERT( xPackage.is() ); } catch (RuntimeException &) { throw; } - catch (CommandFailedException &) { + catch (ucb::CommandFailedException &) { // ignore already handled error } catch (Exception &) { @@ -1306,7 +1392,7 @@ Reference<deployment::XPackage> BackendImpl::PackageImpl::bindBundleItem( void BackendImpl::PackageImpl::scanBundle( t_packagevec & bundle, ::rtl::Reference<AbortChannel> const & abortChannel, - Reference<XCommandEnvironment> const & xCmdEnv ) + Reference<ucb::XCommandEnvironment> const & xCmdEnv ) { OSL_ASSERT( !m_legacyBundle ); @@ -1403,7 +1489,7 @@ void BackendImpl::PackageImpl::scanBundle( if (bundle.end() == std::find_if(bundle.begin(), bundle.end(), XPackage_eq(url))) { const Reference<deployment::XPackage> xPackage( - bindBundleItem( url, mediaType, xCmdEnv ) ); + bindBundleItem( url, mediaType, false, OUString(), xCmdEnv ) ); if (xPackage.is()) bundle.push_back( xPackage ); } @@ -1442,7 +1528,7 @@ void BackendImpl::PackageImpl::scanLegacyBundle( t_packagevec & bundle, OUString const & url, ::rtl::Reference<AbortChannel> const & abortChannel, - Reference<XCommandEnvironment> const & xCmdEnv, + Reference<ucb::XCommandEnvironment> const & xCmdEnv, bool skip_registration ) { ::ucbhelper::Content ucbContent( url, xCmdEnv ); @@ -1478,8 +1564,8 @@ void BackendImpl::PackageImpl::scanLegacyBundle( OUString mediaType; const Reference<deployment::XPackage> xPackage( - bindBundleItem( path, OUString() /* detect */, xCmdEnv, - false /* ignore detection errors */ ) ); + bindBundleItem( path, OUString() /* detect */, false, OUString(), + xCmdEnv, false /* ignore detection errors */ ) ); if (xPackage.is()) { const Reference<deployment::XPackageTypeInfo> xPackageType( xPackage->getPackageType() ); @@ -1514,8 +1600,12 @@ void BackendImpl::PackageImpl::scanLegacyBundle( } } -OUString BackendImpl::PackageImpl::getDisplayName() throw (RuntimeException) +OUString BackendImpl::PackageImpl::getDisplayName() + throw (deployment::ExtensionRemovedException, RuntimeException) { + if (m_bRemoved) + throw deployment::ExtensionRemovedException(); + OUString sName = getDescriptionInfoset().getLocalizedDisplayName(); if (sName.getLength() == 0) return m_displayName; @@ -1523,6 +1613,24 @@ OUString BackendImpl::PackageImpl::getDisplayName() throw (RuntimeException) return sName; } +::std::vector<Reference<deployment::XPackage> > +BackendImpl::PackageImpl::getPackagesFromDb( + Reference<ucb::XCommandEnvironment> const & xCmdEnv) +{ + ::std::vector<Reference<deployment::XPackage> > retVector; + + typedef ::std::vector< ::std::pair<OUString, OUString> >::const_iterator ITC; + for (ITC i = m_dbData.items.begin(); i != m_dbData.items.end(); i++) + { + Reference<deployment::XPackage> xExtension = + bindBundleItem(i->first, i->second, true, m_identifier, xCmdEnv); + OSL_ASSERT(xExtension.is()); + retVector.push_back(xExtension); + } + + return retVector; +} + } // anon namespace //============================================================================== diff --git a/desktop/source/deployment/registry/package/makefile.mk b/desktop/source/deployment/registry/package/makefile.mk index ccadc2070301..203ce176d289 100644 --- a/desktop/source/deployment/registry/package/makefile.mk +++ b/desktop/source/deployment/registry/package/makefile.mk @@ -41,7 +41,7 @@ INCPRE += ..$/..$/inc SLOFILES = \ $(SLO)$/dp_package.obj \ - $(SLO)$/dp_description.obj + $(SLO)$/dp_extbackenddb.obj .INCLUDE : ..$/..$/target.pmk .INCLUDE : target.mk diff --git a/desktop/source/deployment/registry/script/dp_script.cxx b/desktop/source/deployment/registry/script/dp_script.cxx index 4af0cbb84130..edeae256cbaf 100644 --- a/desktop/source/deployment/registry/script/dp_script.cxx +++ b/desktop/source/deployment/registry/script/dp_script.cxx @@ -39,12 +39,12 @@ #include "comphelper/servicedecl.hxx" #include "svl/inettype.hxx" #include "com/sun/star/util/XUpdatable.hpp" -#include "com/sun/star/script/XLibraryContainer.hpp" +#include "com/sun/star/script/XLibraryContainer3.hpp" #include <com/sun/star/ucb/XSimpleFileAccess.hpp> #include <com/sun/star/util/XMacroExpander.hpp> #include <com/sun/star/uri/XUriReferenceFactory.hpp> -#include <com/sun/star/uri/XVndSunStarExpandUrl.hpp> #include <memory> +#include "dp_scriptbackenddb.hxx" using namespace ::dp_misc; using namespace ::com::sun::star; @@ -80,6 +80,7 @@ class BackendImpl : public t_helper virtual void processPackage_( ::osl::ResettableMutexGuard & guard, bool registerPackage, + bool startup, ::rtl::Reference<AbortChannel> const & abortChannel, Reference<XCommandEnvironment> const & xCmdEnv ); @@ -88,24 +89,30 @@ class BackendImpl : public t_helper ::rtl::Reference<BackendImpl> const & myBackend, OUString const & url, Reference<XCommandEnvironment> const &xCmdEnv, - OUString const & scriptURL, OUString const & dialogURL ); + OUString const & scriptURL, OUString const & dialogURL, + bool bRemoved, OUString const & identifier); }; friend class PackageImpl; // PackageRegistryBackend virtual Reference<deployment::XPackage> bindPackage_( OUString const & url, OUString const & mediaType, + sal_Bool bRemoved, OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ); - rtl::OUString getRegisteredFlagFileURL( Reference< deployment::XPackage > xPackage ); - rtl::OUString expandURL( const rtl::OUString& aURL ); - Reference< ucb::XSimpleFileAccess > getFileAccess( void ); - Reference< ucb::XSimpleFileAccess > m_xSFA; + void addDataToDb(OUString const & url); + void deleteDataFromDb(OUString const & url); + bool isRegisteredInDb(OUString const & url); + + + +// Reference< ucb::XSimpleFileAccess > getFileAccess( void ); +// Reference< ucb::XSimpleFileAccess > m_xSFA; const Reference<deployment::XPackageTypeInfo> m_xBasicLibTypeInfo; const Reference<deployment::XPackageTypeInfo> m_xDialogLibTypeInfo; Sequence< Reference<deployment::XPackageTypeInfo> > m_typeInfos; - + std::auto_ptr<ScriptBackendDb> m_backendDb; public: BackendImpl( Sequence<Any> const & args, Reference<XComponentContext> const & xComponentContext ); @@ -123,11 +130,12 @@ BackendImpl::PackageImpl::PackageImpl( ::rtl::Reference<BackendImpl> const & myBackend, OUString const & url, Reference<XCommandEnvironment> const &xCmdEnv, - OUString const & scriptURL, OUString const & dialogURL ) + OUString const & scriptURL, OUString const & dialogURL, bool bRemoved, + OUString const & identifier) : Package( myBackend.get(), url, OUString(), OUString(), // will be late-initialized scriptURL.getLength() > 0 ? myBackend->m_xBasicLibTypeInfo - : myBackend->m_xDialogLibTypeInfo ), + : myBackend->m_xDialogLibTypeInfo, bRemoved, identifier), m_scriptURL( scriptURL ), m_dialogURL( dialogURL ) { @@ -168,6 +176,33 @@ BackendImpl::BackendImpl( m_typeInfos[ 1 ] = m_xDialogLibTypeInfo; OSL_ASSERT( ! transientMode() ); + + if (!transientMode()) + { + OUString dbFile = makeURL(getCachePath(), OUSTR("backenddb.xml")); + m_backendDb.reset( + new ScriptBackendDb(getComponentContext(), dbFile)); + } + +} +void BackendImpl::addDataToDb(OUString const & url) +{ + if (m_backendDb.get()) + m_backendDb->addEntry(url); +} + +bool BackendImpl::isRegisteredInDb(OUString const & url) +{ + bool registered = false; + if (m_backendDb.get()) + registered = m_backendDb->getEntry(url); + return registered; +} + +void BackendImpl::deleteDataFromDb(OUString const & url) +{ + if (m_backendDb.get()) + m_backendDb->removeEntry(url); } // XUpdatable @@ -189,6 +224,7 @@ BackendImpl::getSupportedPackageTypes() throw (RuntimeException) //______________________________________________________________________________ Reference<deployment::XPackage> BackendImpl::bindPackage_( OUString const & url, OUString const & mediaType_, + sal_Bool bRemoved, OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ) { OUString mediaType( mediaType_ ); @@ -222,22 +258,31 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( { if (type.EqualsIgnoreCaseAscii("application")) { + OUString dialogURL( makeURL( url, OUSTR("dialog.xlb") ) ); + if (! create_ucb_content( + 0, dialogURL, xCmdEnv, false /* no throw */ )) { + dialogURL = OUString(); + } + if (subType.EqualsIgnoreCaseAscii("vnd.sun.star.basic-library")) { - OUString dialogURL( makeURL( url, OUSTR("dialog.xlb") ) ); + OUString scriptURL( makeURL( url, OUSTR("script.xlb"))); if (! create_ucb_content( - 0, dialogURL, xCmdEnv, false /* no throw */ )) { - dialogURL = OUString(); + 0, scriptURL, xCmdEnv, false /* no throw */ )) { + scriptURL = OUString(); } - return new PackageImpl( this, url, xCmdEnv, - makeURL( url, OUSTR("script.xlb") ), - dialogURL ); + + return new PackageImpl( + this, url, xCmdEnv, scriptURL, + dialogURL, bRemoved, identifier); } else if (subType.EqualsIgnoreCaseAscii( "vnd.sun.star.dialog-library")) { - return new PackageImpl( this, url, xCmdEnv, - OUString() /* no script lib */, - makeURL( url, OUSTR("dialog.xlb") ) ); + return new PackageImpl( + this, url, xCmdEnv, + OUString() /* no script lib */, + dialogURL, + bRemoved, identifier); } } } @@ -247,90 +292,6 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( static_cast<sal_Int16>(-1) ); } -rtl::OUString BackendImpl::getRegisteredFlagFileURL( Reference< deployment::XPackage > xPackage ) -{ - rtl::OUString aRetURL; - if( !xPackage.is() ) - return aRetURL; - rtl::OUString aHelpURL = xPackage->getURL(); - aRetURL = expandURL( aHelpURL ); - aRetURL += rtl::OUString::createFromAscii( "/RegisteredFlag" ); - return aRetURL; -} - -rtl::OUString BackendImpl::expandURL( const rtl::OUString& aURL ) -{ - static Reference< util::XMacroExpander > xMacroExpander; - static Reference< uri::XUriReferenceFactory > xFac; - - if( !xMacroExpander.is() || !xFac.is() ) - { - Reference<XComponentContext> const & xContext = getComponentContext(); - if( xContext.is() ) - { - xFac = Reference< uri::XUriReferenceFactory >( - xContext->getServiceManager()->createInstanceWithContext( rtl::OUString::createFromAscii( - "com.sun.star.uri.UriReferenceFactory"), xContext ) , UNO_QUERY ); - } - if( !xFac.is() ) - { - throw RuntimeException( - ::rtl::OUString::createFromAscii( - "dp_registry::backend::help::BackendImpl::expandURL(), " - "could not instatiate UriReferenceFactory." ), - Reference< XInterface >() ); - } - - xMacroExpander = Reference< util::XMacroExpander >( - xContext->getValueByName( - ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ), - UNO_QUERY_THROW ); - } - - rtl::OUString aRetURL = aURL; - if( xMacroExpander.is() ) - { - Reference< uri::XUriReference > uriRef; - for (;;) - { - uriRef = Reference< uri::XUriReference >( xFac->parse( aRetURL ), UNO_QUERY ); - if ( uriRef.is() ) - { - Reference < uri::XVndSunStarExpandUrl > sxUri( uriRef, UNO_QUERY ); - if( !sxUri.is() ) - break; - - aRetURL = sxUri->expand( xMacroExpander ); - } - } - } - return aRetURL; -} - -Reference< ucb::XSimpleFileAccess > BackendImpl::getFileAccess( void ) -{ - if( !m_xSFA.is() ) - { - Reference<XComponentContext> const & xContext = getComponentContext(); - if( xContext.is() ) - { - m_xSFA = Reference< ucb::XSimpleFileAccess >( - xContext->getServiceManager()->createInstanceWithContext( - rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), - xContext ), UNO_QUERY ); - } - if( !m_xSFA.is() ) - { - throw RuntimeException( - ::rtl::OUString::createFromAscii( - "dp_registry::backend::help::BackendImpl::getFileAccess(), " - "could not instatiate SimpleFileAccess." ), - Reference< XInterface >() ); - } - } - return m_xSFA; -} - //############################################################################## // Package @@ -359,20 +320,18 @@ BackendImpl::PackageImpl::isRegistered_( BackendImpl * that = getMyBackend(); Reference< deployment::XPackage > xThisPackage( this ); - rtl::OUString aRegisteredFlagFile = that->getRegisteredFlagFileURL( xThisPackage ); - - Reference< ucb::XSimpleFileAccess > xSFA = that->getFileAccess(); - bool bReg = xSFA->exists( aRegisteredFlagFile ); + bool registered = that->isRegisteredInDb(getURL()); return beans::Optional< beans::Ambiguous<sal_Bool> >( true /* IsPresent */, - beans::Ambiguous<sal_Bool>( bReg, false /* IsAmbiguous */ ) ); + beans::Ambiguous<sal_Bool>( registered, false /* IsAmbiguous */ ) ); } //______________________________________________________________________________ void BackendImpl::PackageImpl::processPackage_( ::osl::ResettableMutexGuard &, bool doRegisterPackage, + bool startup, ::rtl::Reference<AbortChannel> const &, Reference<XCommandEnvironment> const & xCmdEnv ) { @@ -381,15 +340,13 @@ void BackendImpl::PackageImpl::processPackage_( BackendImpl * that = getMyBackend(); Reference< deployment::XPackage > xThisPackage( this ); - rtl::OUString aRegisteredFlagFile = that->getRegisteredFlagFileURL( xThisPackage ); - Reference< ucb::XSimpleFileAccess > xSFA = that->getFileAccess(); Reference<XComponentContext> const & xComponentContext = that->getComponentContext(); bool bScript = (m_scriptURL.getLength() > 0); - Reference<css::script::XLibraryContainer> xScriptLibs; + Reference<css::script::XLibraryContainer3> xScriptLibs; bool bDialog = (m_dialogURL.getLength() > 0); - Reference<css::script::XLibraryContainer> xDialogLibs; + Reference<css::script::XLibraryContainer3> xDialogLibs; bool bRunning = office_is_running(); if( bRunning ) @@ -410,52 +367,121 @@ void BackendImpl::PackageImpl::processPackage_( xComponentContext ), UNO_QUERY_THROW ); } } - + bool bRegistered = getMyBackend()->isRegisteredInDb(getURL()); if( !doRegisterPackage ) { - if( xSFA->exists( aRegisteredFlagFile ) ) + //We cannot just call removeLibrary(name) because this could remove a + //script which was added by an extension in a different repository. For + //example, extension foo is contained in the bundled repository and then + //the user adds it it to the user repository. The extension manager will + //then register the new script and revoke the script from the bundled + //extension. removeLibrary(name) would now remove the script from the + //user repository. That is, the script of the newly added user extension does + //not work anymore. Therefore we must check if the currently active + //script comes in fact from the currently processed extension. + + if (bRegistered) { - xSFA->kill( aRegisteredFlagFile ); - - if( bScript && xScriptLibs.is() && xScriptLibs->hasByName( m_name ) ) - xScriptLibs->removeLibrary( m_name ); + //we also prevent and live deployment at startup + if (!isRemoved() && !startup) + { + if (bScript && xScriptLibs.is() && xScriptLibs->hasByName(m_name)) + { + const OUString sScriptUrl = xScriptLibs->getOriginalLibraryLinkURL(m_name); + if (sScriptUrl.equals(m_scriptURL)) + xScriptLibs->removeLibrary(m_name); + } - if( bDialog && xDialogLibs.is() && xDialogLibs->hasByName( m_dialogName ) ) - xDialogLibs->removeLibrary( m_dialogName ); + if (bDialog && xDialogLibs.is() && xDialogLibs->hasByName(m_dialogName)) + { + const OUString sDialogUrl = xDialogLibs->getOriginalLibraryLinkURL(m_dialogName); + if (sDialogUrl.equals(m_dialogURL)) + xDialogLibs->removeLibrary(m_dialogName); + } + } + getMyBackend()->deleteDataFromDb(getURL()); + return; } - return; } - - if( xSFA->exists( aRegisteredFlagFile ) ) + if (bRegistered) return; // Already registered // Update LibraryContainer bool bScriptSuccess = false; const bool bReadOnly = false; - if( bScript && xScriptLibs.is() && !xScriptLibs->hasByName( m_name ) ) - { - xScriptLibs->createLibraryLink( m_name, m_scriptURL, bReadOnly ); - bScriptSuccess = xScriptLibs->hasByName( m_name ); - } bool bDialogSuccess = false; - if( bDialog && xDialogLibs.is() && !xDialogLibs->hasByName( m_dialogName ) ) + if (!startup) { - xDialogLibs->createLibraryLink( m_dialogName, m_dialogURL, bReadOnly ); - bDialogSuccess = xDialogLibs->hasByName( m_dialogName ); - } + //If there is a bundled extension, and the user installes the same extension + //then the script from the bundled extension must be removed. If this does not work + //then live deployment does not work for scripts. + if (bScript && xScriptLibs.is()) + { + bool bCanAdd = true; + if (xScriptLibs->hasByName(m_name)) + { + const OUString sOriginalUrl = xScriptLibs->getOriginalLibraryLinkURL(m_name); + //We assume here that library names in extensions are unique, which may not be the case + //ToDo: If the script exist in another extension, then both extensions must have the + //same id + if (sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE")) + || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE")) + || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$BUNDLED_EXTENSIONS"))) + { + xScriptLibs->removeLibrary(m_name); + bCanAdd = true; + } + else + { + bCanAdd = false; + } + } + + if (bCanAdd) + { + xScriptLibs->createLibraryLink( m_name, m_scriptURL, bReadOnly ); + bScriptSuccess = xScriptLibs->hasByName( m_name ); + } + } + + + if (bDialog && xDialogLibs.is()) + { + bool bCanAdd = true; + if (xDialogLibs->hasByName(m_dialogName)) + { + const OUString sOriginalUrl = xDialogLibs->getOriginalLibraryLinkURL(m_dialogName); + //We assume here that library names in extensions are unique, which may not be the case + //ToDo: If the script exist in another extension, then both extensions must have the + //same id + if (sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE")) + || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE")) + || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$BUNDLED_EXTENSIONS"))) + { + xDialogLibs->removeLibrary(m_dialogName); + bCanAdd = true; + } + else + { + bCanAdd = false; + } + } + if (bCanAdd) + { + xDialogLibs->createLibraryLink( m_dialogName, m_dialogURL, bReadOnly ); + bDialogSuccess = xDialogLibs->hasByName(m_dialogName); + } + } + } bool bSuccess = bScript || bDialog; // Something must have happened - if( bRunning ) + if( bRunning && !startup) if( (bScript && !bScriptSuccess) || (bDialog && !bDialogSuccess) ) bSuccess = false; - if( bSuccess && !xSFA->exists( aRegisteredFlagFile ) ) - { - Reference< io::XOutputStream > xOutputStream = xSFA->openFileWrite( aRegisteredFlagFile ); - if( xOutputStream.is() ) - xOutputStream->closeOutput(); - } + if (bSuccess) + getMyBackend()->addDataToDb(getURL()); } } // anon namespace diff --git a/desktop/source/deployment/registry/script/dp_scriptbackenddb.cxx b/desktop/source/deployment/registry/script/dp_scriptbackenddb.cxx new file mode 100644 index 000000000000..ce0d3029084d --- /dev/null +++ b/desktop/source/deployment/registry/script/dp_scriptbackenddb.cxx @@ -0,0 +1,88 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dp_package.cxx,v $ + * $Revision: 1.34.16.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "rtl/string.h" +#include "cppuhelper/exc_hlp.hxx" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "com/sun/star/xml/dom/XDocument.hpp" +#include "com/sun/star/xml/xpath/XXPathAPI.hpp" +#include "dp_misc.h" +#include "dp_scriptbackenddb.hxx" + + +namespace css = ::com::sun::star; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; + +#define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/script-registry/2010" +#define NS_PREFIX "script" +#define ROOT_ELEMENT_NAME "script-backend-db" +#define KEY_ELEMENT_NAME "script" + +namespace dp_registry { +namespace backend { +namespace script { + +ScriptBackendDb::ScriptBackendDb( + Reference<XComponentContext> const & xContext, + ::rtl::OUString const & url):RegisteredDb(xContext, url) +{ + +} + +OUString ScriptBackendDb::getDbNSName() +{ + return OUSTR(EXTENSION_REG_NS); +} + +OUString ScriptBackendDb::getNSPrefix() +{ + return OUSTR(NS_PREFIX); +} + +OUString ScriptBackendDb::getRootElementName() +{ + return OUSTR(ROOT_ELEMENT_NAME); +} + +OUString ScriptBackendDb::getKeyElementName() +{ + return OUSTR(KEY_ELEMENT_NAME); +} + + + +} // namespace executable +} // namespace backend +} // namespace dp_registry + diff --git a/desktop/source/deployment/registry/script/dp_scriptbackenddb.hxx b/desktop/source/deployment/registry/script/dp_scriptbackenddb.hxx new file mode 100644 index 000000000000..9d227f8b64b8 --- /dev/null +++ b/desktop/source/deployment/registry/script/dp_scriptbackenddb.hxx @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dp_backend.h,v $ + * $Revision: 1.18 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if ! defined INCLUDED_DP_SCRIPTBACKENDDB_HXX +#define INCLUDED_DP_SCRIPTBACKENDDB_HXX + +#include "rtl/ustring.hxx" +#include "dp_backenddb.hxx" +#include "boost/optional.hpp" +namespace css = ::com::sun::star; + +namespace com { namespace sun { namespace star { + namespace uno { + class XComponentContext; + } +}}} + +namespace dp_registry { +namespace backend { +namespace script { + +/* The XML file stores the extensions which are currently registered. + They will be removed when they are revoked. + */ +class ScriptBackendDb: public dp_registry::backend::RegisteredDb +{ +protected: + virtual ::rtl::OUString getDbNSName(); + + virtual ::rtl::OUString getNSPrefix(); + + virtual ::rtl::OUString getRootElementName(); + + virtual ::rtl::OUString getKeyElementName(); + + +public: + + ScriptBackendDb( css::uno::Reference<css::uno::XComponentContext> const & xContext, + ::rtl::OUString const & url); +}; + + + +} +} +} +#endif + diff --git a/desktop/source/deployment/registry/script/makefile.mk b/desktop/source/deployment/registry/script/makefile.mk index ae159914a548..708def358021 100644 --- a/desktop/source/deployment/registry/script/makefile.mk +++ b/desktop/source/deployment/registry/script/makefile.mk @@ -41,7 +41,8 @@ INCPRE += ..$/..$/inc SLOFILES = \ $(SLO)$/dp_script.obj \ - $(SLO)$/dp_lib_container.obj + $(SLO)$/dp_lib_container.obj \ + $(SLO)$/dp_scriptbackenddb.obj .INCLUDE : ..$/..$/target.pmk .INCLUDE : target.mk diff --git a/desktop/source/deployment/registry/sfwk/dp_sfwk.cxx b/desktop/source/deployment/registry/sfwk/dp_sfwk.cxx index 52ced6908bd8..8a4ee1b45fbc 100644 --- a/desktop/source/deployment/registry/sfwk/dp_sfwk.cxx +++ b/desktop/source/deployment/registry/sfwk/dp_sfwk.cxx @@ -77,12 +77,15 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend virtual void processPackage_( ::osl::ResettableMutexGuard & guard, bool registerPackage, + bool startup, ::rtl::Reference<AbortChannel> const & abortChannel, Reference<XCommandEnvironment> const & xCmdEnv ); public: - PackageImpl( ::rtl::Reference<BackendImpl> const & myBackend, - OUString const & url, OUString const & libType ); + PackageImpl( + ::rtl::Reference<BackendImpl> const & myBackend, + OUString const & url, OUString const & libType, bool bRemoved, + OUString const & identifier); // XPackage virtual OUString SAL_CALL getDescription() throw (RuntimeException); }; @@ -91,6 +94,7 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend // PackageRegistryBackend virtual Reference<deployment::XPackage> bindPackage_( OUString const & url, OUString const & mediaType, + sal_Bool bRemoved, OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ); const Reference<deployment::XPackageTypeInfo> m_xTypeInfo; @@ -131,9 +135,10 @@ OUString BackendImpl::PackageImpl::getDescription() throw (RuntimeException) //______________________________________________________________________________ BackendImpl::PackageImpl::PackageImpl( ::rtl::Reference<BackendImpl> const & myBackend, - OUString const & url, OUString const & libType ) + OUString const & url, OUString const & libType, bool bRemoved, + OUString const & identifier) : Package( myBackend.get(), url, OUString(), OUString(), - myBackend->m_xTypeInfo ), + myBackend->m_xTypeInfo, bRemoved, identifier), m_descr(libType) { initPackageHandler(); @@ -217,8 +222,8 @@ BackendImpl::getSupportedPackageTypes() throw (RuntimeException) // PackageRegistryBackend //______________________________________________________________________________ Reference<deployment::XPackage> BackendImpl::bindPackage_( - OUString const & url, OUString const & mediaType_, - Reference<XCommandEnvironment> const & xCmdEnv ) + OUString const & url, OUString const & mediaType_, sal_Bool bRemoved, + OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv ) { OUString mediaType( mediaType_ ); if (mediaType.getLength() == 0) @@ -294,7 +299,7 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( dp_misc::TRACE(OUSTR(" BackEnd detected lang = ") + lang + OUSTR("\n")); dp_misc::TRACE(OUSTR(" for url ") + sParcelDescURL + OUSTR("\n") ); dp_misc::TRACE("******************************\n"); - return new PackageImpl( this, url, sfwkLibType ); + return new PackageImpl( this, url, sfwkLibType, bRemoved, identifier); } } } @@ -322,6 +327,10 @@ void BackendImpl::PackageImpl:: initPackageHandler() { aContext <<= OUSTR("share"); } + else if ( that->m_eContext == CONTEXT_BUNDLED ) + { + aContext <<= OUSTR("bundled"); + } else { OSL_ASSERT( 0 ); @@ -363,6 +372,7 @@ BackendImpl::PackageImpl::isRegistered_( void BackendImpl::PackageImpl::processPackage_( ::osl::ResettableMutexGuard &, bool doRegisterPackage, + bool /* startup */, ::rtl::Reference<AbortChannel> const &, Reference<XCommandEnvironment> const & ) { |