From 9ac86f484b0c278aafbce685ed19d3ea005ee8f8 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 14 Sep 2012 18:08:57 +0200 Subject: Improvement on previous commit, UCB clean up * As UCB is only ever initialized with "Local"/"Office", remove this configuration vector completely. The "create" ctor creates an instance internally initialized with those "Local"/"Office" keys. Special (test) code can still instantiate an uninitialized one via plain createInstance. And for backwards compatilibity process startup still ensures to create an initialized instance early, in case there is still code out there (in extensions) that later calls plain createInstance and expects to get the already-initialized (single) instance. * XInitialization is an "implementation detail" of the UniversalContentBroker service, do not expose in XUniversalContentBroker. * ucbhelper/configurationkeys.hxx is no longer needed and is removed. * ucbhelper/contentbroker.hxx is an empty wrapper and is removed; however, that requires ucbhelper::Content constructors to take explicit XComponentContext arguments now. * The only remaining code in ucbhelper/source/client/contentbroker.cxx is Android-only InitUCBHelper. Is that relevant still? Change-Id: I3f7bddd0456bffbcd13590c66d9011915c760f28 --- svl/qa/unit/test_URIHelper.cxx | 16 +++------------- svl/source/fsstor/fsfactory.cxx | 9 +++++---- svl/source/fsstor/fsstorage.cxx | 31 +++++++++++++++--------------- svl/source/misc/documentlockfile.cxx | 8 ++++---- svl/source/misc/fstathelper.cxx | 10 +++++++--- svl/source/misc/sharecontrolfile.cxx | 2 +- svl/source/misc/urihelper.cxx | 37 +++++++----------------------------- 7 files changed, 42 insertions(+), 71 deletions(-) (limited to 'svl') diff --git a/svl/qa/unit/test_URIHelper.cxx b/svl/qa/unit/test_URIHelper.cxx index 9cb810b38beb..98c25a6d6eb8 100644 --- a/svl/qa/unit/test_URIHelper.cxx +++ b/svl/qa/unit/test_URIHelper.cxx @@ -22,21 +22,19 @@ #include "com/sun/star/lang/Locale.hpp" #include "com/sun/star/lang/XComponent.hpp" -#include "com/sun/star/lang/XMultiComponentFactory.hpp" #include "com/sun/star/lang/XMultiServiceFactory.hpp" #include "com/sun/star/ucb/Command.hpp" #include "com/sun/star/ucb/CommandAbortedException.hpp" #include "com/sun/star/ucb/IllegalIdentifierException.hpp" +#include "com/sun/star/ucb/UniversalContentBroker.hpp" #include "com/sun/star/ucb/XCommandProcessor.hpp" #include "com/sun/star/ucb/XContent.hpp" #include "com/sun/star/ucb/XContentIdentifier.hpp" #include "com/sun/star/ucb/XContentProvider.hpp" -#include "com/sun/star/ucb/XContentProviderManager.hpp" #include "com/sun/star/uno/Any.hxx" #include "com/sun/star/uno/Exception.hpp" #include "com/sun/star/uno/Reference.hxx" #include "com/sun/star/uno/RuntimeException.hpp" -#include "com/sun/star/uno/Sequence.hxx" #include "com/sun/star/uno/XComponentContext.hpp" #include "com/sun/star/uri/XUriReference.hpp" #include "cppuhelper/bootstrap.hxx" @@ -230,16 +228,8 @@ void Test::finish() { } void Test::testNormalizedMakeRelative() { - css::uno::Sequence< css::uno::Any > args(2); - args[0] <<= rtl::OUString("Local"); - args[1] <<= rtl::OUString("Office"); - css::uno::Reference< css::ucb::XContentProviderManager >( - (css::uno::Reference< css::lang::XMultiComponentFactory >( - m_context->getServiceManager(), css::uno::UNO_QUERY_THROW)-> - createInstanceWithArgumentsAndContext( - rtl::OUString("com.sun.star.ucb.UniversalContentBroker"), - args, m_context)), - css::uno::UNO_QUERY_THROW)->registerContentProvider( + css::ucb::UniversalContentBroker::create(m_context)-> + registerContentProvider( new Provider, rtl::OUString("test"), true); struct Data { diff --git a/svl/source/fsstor/fsfactory.cxx b/svl/source/fsstor/fsfactory.cxx index f11453c2f1a2..e76c7a645134 100644 --- a/svl/source/fsstor/fsfactory.cxx +++ b/svl/source/fsstor/fsfactory.cxx @@ -23,10 +23,9 @@ #include #include #include - +#include #include -#include #include #include @@ -72,7 +71,8 @@ uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstance() throw uno::RuntimeException(); // TODO: can not create tempfile ::ucbhelper::Content aResultContent( - aTempURL, uno::Reference< ucb::XCommandEnvironment >() ); + aTempURL, uno::Reference< ucb::XCommandEnvironment >(), + comphelper::getProcessComponentContext() ); return uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( @@ -148,7 +148,8 @@ uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstanceWithA throw io::IOException(); // there is no such folder ::ucbhelper::Content aResultContent( - aURL, uno::Reference< ucb::XCommandEnvironment >() ); + aURL, uno::Reference< ucb::XCommandEnvironment >(), + comphelper::getProcessComponentContext() ); // create storage based on source return uno::Reference< uno::XInterface >( diff --git a/svl/source/fsstor/fsstorage.cxx b/svl/source/fsstor/fsstorage.cxx index 03ad05bdfba8..00f93802562a 100644 --- a/svl/source/fsstor/fsstorage.cxx +++ b/svl/source/fsstor/fsstorage.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -55,7 +56,6 @@ #include #include #include -#include #include #include "fsstorage.hxx" @@ -70,15 +70,13 @@ using namespace ::com::sun::star; sal_Bool isLocalFile_Impl( ::rtl::OUString aURL ) { ::rtl::OUString aSystemPath; - ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get(); - if ( !pBroker ) - throw uno::RuntimeException(); - uno::Reference< ucb::XContentProviderManager > xManager = - pBroker->getContentProviderManagerInterface(); try { - aSystemPath = ::ucbhelper::getSystemPathFromFileURL( xManager, aURL ); + aSystemPath = ::ucbhelper::getSystemPathFromFileURL( + ucb::UniversalContentBroker::create( + comphelper::getProcessComponentContext() ), + aURL ); } catch ( uno::Exception& ) { @@ -182,6 +180,7 @@ sal_Bool FSStorage::MakeFolderNoUI( const ::rtl::OUString& rFolder ) if ( ::ucbhelper::Content::create( aURL.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >(), + comphelper::getProcessComponentContext(), aParent ) ) return ::utl::UCBContentHelper::MakeFolder( aParent, aTitle, aResultContent, sal_False ); @@ -198,7 +197,7 @@ sal_Bool FSStorage::MakeFolderNoUI( const ::rtl::OUString& rFolder ) try { - m_pImpl->m_pContent = new ::ucbhelper::Content( m_pImpl->m_aURL, xDummyEnv ); + m_pImpl->m_pContent = new ::ucbhelper::Content( m_pImpl->m_aURL, xDummyEnv, comphelper::getProcessComponentContext() ); } catch( uno::Exception& ) { @@ -217,7 +216,7 @@ void FSStorage::CopyStreamToSubStream( const ::rtl::OUString& aSourceURL, throw uno::RuntimeException(); uno::Reference< ucb::XCommandEnvironment > xDummyEnv; - ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv ); + ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv, comphelper::getProcessComponentContext() ); uno::Reference< io::XInputStream > xSourceInput = aSourceContent.openStream(); if ( !xSourceInput.is() ) @@ -276,7 +275,7 @@ void FSStorage::CopyContentToStorage_Impl( ::ucbhelper::Content* pContent, const throw uno::RuntimeException(); uno::Reference< ucb::XCommandEnvironment > xDummyEnv; - ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv ); + ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv, comphelper::getProcessComponentContext() ); CopyContentToStorage_Impl( &aSourceContent, xSubStorage ); } else @@ -509,7 +508,7 @@ uno::Reference< io::XStream > SAL_CALL FSStorage::openStreamElement( || !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) throw io::IOException(); // TODO: access denied - ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); + ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() ); uno::Reference< io::XInputStream > xInStream = aResultContent.openStream(); xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) ); } @@ -619,7 +618,7 @@ uno::Reference< embed::XStorage > SAL_CALL FSStorage::openStorageElement( if ( !bFolderExists ) throw io::IOException(); // there is no such folder - ::ucbhelper::Content aResultContent( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); + ::ucbhelper::Content aResultContent( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() ); xResult = uno::Reference< embed::XStorage >( static_cast< OWeakObject* >( new FSStorage( aResultContent, nStorageMode, @@ -682,7 +681,7 @@ uno::Reference< io::XStream > SAL_CALL FSStorage::cloneStreamElement( const ::rt try { uno::Reference< ucb::XCommandEnvironment > xDummyEnv; - ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); + ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() ); uno::Reference< io::XInputStream > xInStream = aResultContent.openStream(); xTempResult = uno::Reference < io::XStream >( @@ -883,7 +882,7 @@ void SAL_CALL FSStorage::renameElement( const ::rtl::OUString& aElementName, con try { uno::Reference< ucb::XCommandEnvironment > xDummyEnv; - ::ucbhelper::Content aSourceContent( aOldURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); + ::ucbhelper::Content aSourceContent( aOldURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() ); if ( !GetContent()->transferContent( aSourceContent, ::ucbhelper::InsertOperation_MOVE, @@ -962,7 +961,7 @@ void SAL_CALL FSStorage::copyElementTo( const ::rtl::OUString& aElementName, uno::Reference< ucb::XCommandEnvironment > xDummyEnv; if ( ::utl::UCBContentHelper::IsFolder( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) { - ::ucbhelper::Content aSourceContent( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); + ::ucbhelper::Content aSourceContent( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() ); uno::Reference< embed::XStorage > xDestSubStor( xDest->openStorageElement( aNewName, embed::ElementModes::READWRITE ), uno::UNO_QUERY_THROW ); @@ -1506,7 +1505,7 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openStreamEl || !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) throw io::IOException(); // TODO: access denied - ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); + ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() ); uno::Reference< io::XInputStream > xInStream = aResultContent.openStream(); xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) ); } diff --git a/svl/source/misc/documentlockfile.cxx b/svl/source/misc/documentlockfile.cxx index 17d9e7ca239e..119ebcdd6a1c 100644 --- a/svl/source/misc/documentlockfile.cxx +++ b/svl/source/misc/documentlockfile.cxx @@ -110,7 +110,7 @@ sal_Bool DocumentLockFile::CreateOwnLockFile() xSeekable->seek( 0 ); uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; - ::ucbhelper::Content aTargetContent( m_aURL, xEnv ); + ::ucbhelper::Content aTargetContent( m_aURL, xEnv, comphelper::getProcessComponentContext() ); ucb::InsertCommandArgument aInsertArg; aInsertArg.Data = xInput; @@ -162,7 +162,7 @@ uno::Reference< io::XInputStream > DocumentLockFile::OpenStream() ::osl::MutexGuard aGuard( m_aMutex ); uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; - ::ucbhelper::Content aSourceContent( m_aURL, xEnv ); + ::ucbhelper::Content aSourceContent( m_aURL, xEnv, comphelper::getProcessComponentContext() ); // the file can be opened readonly, no locking will be done return aSourceContent.openStream(); @@ -175,7 +175,7 @@ sal_Bool DocumentLockFile::OverwriteOwnLockFile() try { uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; - ::ucbhelper::Content aTargetContent( m_aURL, xEnv ); + ::ucbhelper::Content aTargetContent( m_aURL, xEnv, comphelper::getProcessComponentContext() ); uno::Sequence< ::rtl::OUString > aNewEntry = GenerateOwnEntry(); @@ -213,7 +213,7 @@ void DocumentLockFile::RemoveFile() throw io::IOException(); // not the owner, access denied uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; - ::ucbhelper::Content aCnt(m_aURL, xEnv); + ::ucbhelper::Content aCnt(m_aURL, xEnv, comphelper::getProcessComponentContext()); aCnt.executeCommand(rtl::OUString("delete"), uno::makeAny(sal_Bool(sal_True))); } diff --git a/svl/source/misc/fstathelper.cxx b/svl/source/misc/fstathelper.cxx index 94e13c81a5c5..3e0a08001ef8 100644 --- a/svl/source/misc/fstathelper.cxx +++ b/svl/source/misc/fstathelper.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include using namespace ::com::sun::star; @@ -36,7 +37,8 @@ sal_Bool FStatHelper::GetModifiedDateTimeOfFile( const rtl::OUString& rURL, try { ::ucbhelper::Content aTestContent( rURL, - uno::Reference< XCommandEnvironment > ()); + uno::Reference< XCommandEnvironment > (), + comphelper::getProcessComponentContext()); uno::Any aAny = aTestContent.getPropertyValue( OUString("DateModified") ); if( aAny.hasValue() ) @@ -63,7 +65,8 @@ sal_Bool FStatHelper::IsDocument( const rtl::OUString& rURL ) try { ::ucbhelper::Content aTestContent( rURL, - uno::Reference< XCommandEnvironment > ()); + uno::Reference< XCommandEnvironment > (), + comphelper::getProcessComponentContext()); bExist = aTestContent.isDocument(); } catch(...) @@ -78,7 +81,8 @@ sal_Bool FStatHelper::IsFolder( const rtl::OUString& rURL ) try { ::ucbhelper::Content aTestContent( rURL, - uno::Reference< XCommandEnvironment > ()); + uno::Reference< XCommandEnvironment > (), + comphelper::getProcessComponentContext()); bExist = aTestContent.isFolder(); } catch(...) diff --git a/svl/source/misc/sharecontrolfile.cxx b/svl/source/misc/sharecontrolfile.cxx index 95abae227dc2..2d2a4d93b418 100644 --- a/svl/source/misc/sharecontrolfile.cxx +++ b/svl/source/misc/sharecontrolfile.cxx @@ -81,7 +81,7 @@ void ShareControlFile::OpenStream() if ( !m_xStream.is() && !m_aURL.isEmpty() ) { uno::Reference< ucb::XCommandEnvironment > xDummyEnv; - ::ucbhelper::Content aContent = ::ucbhelper::Content( m_aURL, xDummyEnv ); + ::ucbhelper::Content aContent = ::ucbhelper::Content( m_aURL, xDummyEnv, comphelper::getProcessComponentContext() ); uno::Reference< ucb::XContentIdentifier > xContId( aContent.get().is() ? aContent.get()->getIdentifier() : 0 ); if ( !xContId.is() || xContId->getContentProviderScheme() != "file" ) diff --git a/svl/source/misc/urihelper.cxx b/svl/source/misc/urihelper.cxx index 23340841999c..ed96a698f48c 100644 --- a/svl/source/misc/urihelper.cxx +++ b/svl/source/misc/urihelper.cxx @@ -19,30 +19,23 @@ #include #include -#include "com/sun/star/lang/WrappedTargetRuntimeException.hpp" #include "com/sun/star/lang/XMultiComponentFactory.hpp" -#include "com/sun/star/ucb/UniversalContentBroker.hpp" #include "com/sun/star/ucb/Command.hpp" -#include #include "com/sun/star/ucb/IllegalIdentifierException.hpp" +#include "com/sun/star/ucb/UniversalContentBroker.hpp" #include "com/sun/star/ucb/UnsupportedCommandException.hpp" #include "com/sun/star/ucb/XCommandEnvironment.hpp" #include "com/sun/star/ucb/XCommandProcessor.hpp" #include "com/sun/star/ucb/XContent.hpp" -#include "com/sun/star/ucb/XContentIdentifierFactory.hpp" -#include "com/sun/star/ucb/XContentProvider.hpp" -#include +#include "com/sun/star/ucb/XUniversalContentBroker.hpp" #include "com/sun/star/uno/Any.hxx" #include "com/sun/star/uno/Exception.hpp" #include "com/sun/star/uno/Reference.hxx" #include "com/sun/star/uno/RuntimeException.hpp" -#include "com/sun/star/uno/Sequence.hxx" #include "com/sun/star/uno/XComponentContext.hpp" -#include "com/sun/star/uno/XInterface.hpp" #include "com/sun/star/uri/UriReferenceFactory.hpp" #include "com/sun/star/uri/XUriReference.hpp" #include "com/sun/star/uri/XUriReferenceFactory.hpp" -#include "cppuhelper/exc_hlp.hxx" #include "comphelper/processfactory.hxx" #include "osl/diagnose.h" #include "rtl/ustrbuf.hxx" @@ -50,7 +43,6 @@ #include "rtl/ustring.hxx" #include "sal/types.h" #include -#include #include #include "rtl/instance.hxx" @@ -159,16 +151,13 @@ bool isAbsoluteHierarchicalUriReference( enum Result { Success, GeneralFailure, SpecificFailure }; Result normalizePrefix( - css::uno::Reference< css::ucb::XContentProvider > const & broker, + css::uno::Reference< css::ucb::XUniversalContentBroker > const & broker, rtl::OUString const & uri, rtl::OUString * normalized) { OSL_ASSERT(broker.is() && normalized != 0); css::uno::Reference< css::ucb::XContent > content; try { - content = broker->queryContent( - css::uno::Reference< css::ucb::XContentIdentifierFactory >( - broker, css::uno::UNO_QUERY_THROW)->createContentIdentifier( - uri)); + content = broker->queryContent(broker->createContentIdentifier(uri)); } catch (css::ucb::IllegalIdentifierException &) {} if (!content.is()) { return GeneralFailure; @@ -196,7 +185,7 @@ Result normalizePrefix( } rtl::OUString normalize( - css::uno::Reference< css::ucb::XContentProvider > const & broker, + css::uno::Reference< css::ucb::XUniversalContentBroker > const & broker, css::uno::Reference< css::uri::XUriReferenceFactory > const & uriFactory, rtl::OUString const & uriReference) { @@ -287,20 +276,8 @@ URIHelper::normalizedMakeRelative( rtl::OUString const & baseUriReference, rtl::OUString const & uriReference) { OSL_ASSERT(context.is()); - css::uno::Reference< css::ucb::XContentProvider > broker; - try { - broker = css::uno::Reference< css::ucb::XContentProvider >( - css::ucb::UniversalContentBroker::createWithKeys(context, "Local", "Office"), - css::uno::UNO_QUERY_THROW); - } catch (css::uno::RuntimeException &) { - throw; - } catch (css::uno::Exception &) { - css::uno::Any exception(cppu::getCaughtException()); - throw css::lang::WrappedTargetRuntimeException( - "creating com.sun.star.ucb.UniversalContentBroker failed", - css::uno::Reference< css::uno::XInterface >(), - exception); - } + css::uno::Reference< css::ucb::XUniversalContentBroker > broker( + css::ucb::UniversalContentBroker::create(context)); css::uno::Reference< css::uri::XUriReferenceFactory > uriFactory( css::uri::UriReferenceFactory::create(context)); return uriFactory->makeRelative( -- cgit