summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2012-09-14 18:08:57 +0200
committerStephan Bergmann <sbergman@redhat.com>2012-09-14 18:24:49 +0200
commit9ac86f484b0c278aafbce685ed19d3ea005ee8f8 (patch)
treecf2fe16d76992bcbd1bd89a8693c5f4996cd55f2 /unotools
parent2e284203da7f9882842111265f5f68ea0a145065 (diff)
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
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/ucbhelper/localfilehelper.cxx103
-rw-r--r--unotools/source/ucbhelper/tempfile.cxx50
-rw-r--r--unotools/source/ucbhelper/ucbhelper.cxx27
-rw-r--r--unotools/source/ucbhelper/ucblockbytes.cxx10
-rw-r--r--unotools/source/ucbhelper/ucbstreamhelper.cxx147
5 files changed, 148 insertions, 189 deletions
diff --git a/unotools/source/ucbhelper/localfilehelper.cxx b/unotools/source/ucbhelper/localfilehelper.cxx
index d14d79c17e6f..ef0acbecde90 100644
--- a/unotools/source/ucbhelper/localfilehelper.cxx
+++ b/unotools/source/ucbhelper/localfilehelper.cxx
@@ -20,10 +20,10 @@
#include <com/sun/star/sdbc/XResultSet.hpp>
#include <com/sun/star/ucb/XContentAccess.hpp>
#include <com/sun/star/ucb/CommandAbortedException.hpp>
-
+#include <com/sun/star/ucb/UniversalContentBroker.hpp>
+#include <comphelper/processfactory.hxx>
#include <unotools/localfilehelper.hxx>
#include <ucbhelper/fileidentifierconverter.hxx>
-#include <ucbhelper/contentbroker.hxx>
#include <rtl/ustring.hxx>
#include <osl/file.hxx>
#include <tools/urlobj.hxx>
@@ -41,25 +41,16 @@ sal_Bool LocalFileHelper::ConvertSystemPathToURL( const String& rName, const Str
{
rReturn = ::rtl::OUString();
- ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
- if ( !pBroker )
+ Reference< XUniversalContentBroker > pBroker(
+ UniversalContentBroker::create(
+ comphelper::getProcessComponentContext() ) );
+ try
{
- rtl::OUString aRet;
- if ( FileBase::getFileURLFromSystemPath( rName, aRet ) == FileBase::E_None )
- rReturn = aRet;
+ rReturn = ::ucbhelper::getFileURLFromSystemPath( pBroker, rBaseURL, rName );
}
- else
+ catch ( ::com::sun::star::uno::RuntimeException& )
{
- ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProviderManager > xManager =
- pBroker->getContentProviderManagerInterface();
- try
- {
- rReturn = ::ucbhelper::getFileURLFromSystemPath( xManager, rBaseURL, rName );
- }
- catch ( ::com::sun::star::uno::RuntimeException& )
- {
- return sal_False;
- }
+ return sal_False;
}
return ( rReturn.Len() != 0 );
@@ -68,24 +59,15 @@ sal_Bool LocalFileHelper::ConvertSystemPathToURL( const String& rName, const Str
sal_Bool LocalFileHelper::ConvertURLToSystemPath( const String& rName, String& rReturn )
{
rReturn = ::rtl::OUString();
- ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
- if ( !pBroker )
+ Reference< XUniversalContentBroker > pBroker(
+ UniversalContentBroker::create(
+ comphelper::getProcessComponentContext() ) );
+ try
{
- rtl::OUString aRet;
- if( FileBase::getSystemPathFromFileURL( rName, aRet ) == FileBase::E_None )
- rReturn = aRet;
+ rReturn = ::ucbhelper::getSystemPathFromFileURL( pBroker, rName );
}
- else
+ catch ( ::com::sun::star::uno::RuntimeException& )
{
- ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProviderManager > xManager =
- pBroker->getContentProviderManagerInterface();
- try
- {
- rReturn = ::ucbhelper::getSystemPathFromFileURL( xManager, rName );
- }
- catch ( ::com::sun::star::uno::RuntimeException& )
- {
- }
}
return ( rReturn.Len() != 0 );
@@ -94,26 +76,16 @@ sal_Bool LocalFileHelper::ConvertURLToSystemPath( const String& rName, String& r
bool LocalFileHelper::ConvertPhysicalNameToURL(const rtl::OUString& rName, rtl::OUString& rReturn)
{
rReturn = ::rtl::OUString();
- ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
- if ( !pBroker )
+ Reference< XUniversalContentBroker > pBroker(
+ UniversalContentBroker::create(
+ comphelper::getProcessComponentContext() ) );
+ try
{
- rtl::OUString aRet;
- if ( FileBase::getFileURLFromSystemPath( rName, aRet ) == FileBase::E_None )
- rReturn = aRet;
+ rtl::OUString aBase( ::ucbhelper::getLocalFileURL() );
+ rReturn = ::ucbhelper::getFileURLFromSystemPath( pBroker, aBase, rName );
}
- else
+ catch (const ::com::sun::star::uno::RuntimeException&)
{
- ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProviderManager > xManager =
- pBroker->getContentProviderManagerInterface();
-
- try
- {
- rtl::OUString aBase( ::ucbhelper::getLocalFileURL() );
- rReturn = ::ucbhelper::getFileURLFromSystemPath( xManager, aBase, rName );
- }
- catch (const ::com::sun::star::uno::RuntimeException&)
- {
- }
}
return !rReturn.isEmpty();
@@ -122,27 +94,18 @@ bool LocalFileHelper::ConvertPhysicalNameToURL(const rtl::OUString& rName, rtl::
bool LocalFileHelper::ConvertURLToPhysicalName(const rtl::OUString& rName, rtl::OUString& rReturn)
{
rReturn = ::rtl::OUString();
- ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
- if ( !pBroker )
+ Reference< XUniversalContentBroker > pBroker(
+ UniversalContentBroker::create(
+ comphelper::getProcessComponentContext() ) );
+ try
{
- ::rtl::OUString aRet;
- if ( FileBase::getSystemPathFromFileURL( rName, aRet ) == FileBase::E_None )
- rReturn = aRet;
+ INetURLObject aObj( rName );
+ INetURLObject aLocal( ::ucbhelper::getLocalFileURL() );
+ if ( aObj.GetProtocol() == aLocal.GetProtocol() )
+ rReturn = ::ucbhelper::getSystemPathFromFileURL( pBroker, rName );
}
- else
+ catch (const ::com::sun::star::uno::RuntimeException&)
{
- ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProviderManager > xManager =
- pBroker->getContentProviderManagerInterface();
- try
- {
- INetURLObject aObj( rName );
- INetURLObject aLocal( ::ucbhelper::getLocalFileURL() );
- if ( aObj.GetProtocol() == aLocal.GetProtocol() )
- rReturn = ::ucbhelper::getSystemPathFromFileURL( xManager, rName );
- }
- catch (const ::com::sun::star::uno::RuntimeException&)
- {
- }
}
return !rReturn.isEmpty();
@@ -167,7 +130,9 @@ typedef ::std::vector< ::rtl::OUString* > StringList_Impl;
StringList_Impl* pFiles = NULL;
try
{
- ::ucbhelper::Content aCnt( rFolder, Reference< XCommandEnvironment > () );
+ ::ucbhelper::Content aCnt(
+ rFolder, Reference< XCommandEnvironment >(),
+ comphelper::getProcessComponentContext() );
Reference< ::com::sun::star::sdbc::XResultSet > xResultSet;
::com::sun::star::uno::Sequence< ::rtl::OUString > aProps(1);
::rtl::OUString* pProps = aProps.getArray();
diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index 60a82dc96f31..1782dcf6a011 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -17,13 +17,15 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include "sal/config.h"
+#include <com/sun/star/ucb/UniversalContentBroker.hpp>
+#include <comphelper/processfactory.hxx>
#include <unotools/tempfile.hxx>
#include <tools/tempfile.hxx>
#include <unotools/localfilehelper.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <ucbhelper/fileidentifierconverter.hxx>
-#include <ucbhelper/contentbroker.hxx>
#include <rtl/ustring.hxx>
#include <rtl/instance.hxx>
#include <osl/file.hxx>
@@ -128,34 +130,28 @@ String ConstructTempDir_Impl( const String* pParent )
String aName;
if ( pParent && pParent->Len() )
{
- ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
- if ( pBroker )
+ com::sun::star::uno::Reference<
+ com::sun::star::ucb::XUniversalContentBroker > pBroker(
+ com::sun::star::ucb::UniversalContentBroker::create(
+ comphelper::getProcessComponentContext() ) );
+
+ // if parent given try to use it
+ rtl::OUString aTmp( *pParent );
+
+ // test for valid filename
+ rtl::OUString aRet;
+ ::osl::FileBase::getFileURLFromSystemPath(
+ ::ucbhelper::getSystemPathFromFileURL( pBroker, aTmp ),
+ aRet );
+ if ( !aRet.isEmpty() )
{
- ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProviderManager > xManager =
- pBroker->getContentProviderManagerInterface();
-
- // if parent given try to use it
- rtl::OUString aTmp( *pParent );
-
- // test for valid filename
- rtl::OUString aRet;
- ::osl::FileBase::getFileURLFromSystemPath(
- ::ucbhelper::getSystemPathFromFileURL( xManager, aTmp ),
- aRet );
- if ( !aRet.isEmpty() )
- {
- ::osl::DirectoryItem aItem;
- sal_Int32 i = aRet.getLength();
- if ( aRet[i-1] == '/' )
- i--;
+ ::osl::DirectoryItem aItem;
+ sal_Int32 i = aRet.getLength();
+ if ( aRet[i-1] == '/' )
+ i--;
- if ( DirectoryItem::get( aRet.copy(0, i), aItem ) == FileBase::E_None )
- aName = aRet;
- }
- }
- else
- {
- DBG_WARNING( "::unotools::TempFile : UCB not present or not initialized!" );
+ if ( DirectoryItem::get( aRet.copy(0, i), aItem ) == FileBase::E_None )
+ aName = aRet;
}
}
diff --git a/unotools/source/ucbhelper/ucbhelper.cxx b/unotools/source/ucbhelper/ucbhelper.cxx
index 0709caa115e6..39e0835f6a19 100644
--- a/unotools/source/ucbhelper/ucbhelper.cxx
+++ b/unotools/source/ucbhelper/ucbhelper.cxx
@@ -31,11 +31,12 @@
#include "com/sun/star/ucb/IOErrorCode.hpp"
#include "com/sun/star/ucb/InteractiveIOException.hpp"
#include "com/sun/star/ucb/NameClashException.hpp"
+#include "com/sun/star/ucb/UniversalContentBroker.hpp"
#include "com/sun/star/ucb/XCommandEnvironment.hpp"
#include "com/sun/star/ucb/XContentAccess.hpp"
#include "com/sun/star/ucb/XContentIdentifier.hpp"
-#include "com/sun/star/ucb/XContentIdentifierFactory.hpp"
#include "com/sun/star/ucb/XProgressHandler.hpp"
+#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"
@@ -55,7 +56,6 @@
#include "tools/urlobj.hxx"
#include "ucbhelper/commandenvironment.hxx"
#include "ucbhelper/content.hxx"
-#include "ucbhelper/contentbroker.hxx"
#include "unotools/localfilehelper.hxx"
#include "unotools/ucbhelper.hxx"
@@ -72,13 +72,15 @@ rtl::OUString canonic(rtl::OUString const & url) {
ucbhelper::Content content(rtl::OUString const & url) {
return ucbhelper::Content(
canonic(url),
- css::uno::Reference<css::ucb::XCommandEnvironment>());
+ css::uno::Reference<css::ucb::XCommandEnvironment>(),
+ comphelper::getProcessComponentContext());
}
ucbhelper::Content content(INetURLObject const & url) {
return ucbhelper::Content(
url.GetMainURL(INetURLObject::NO_DECODE),
- css::uno::Reference<css::ucb::XCommandEnvironment>());
+ css::uno::Reference<css::ucb::XCommandEnvironment>(),
+ comphelper::getProcessComponentContext());
}
std::vector<rtl::OUString> getContents(rtl::OUString const & url) {
@@ -444,18 +446,13 @@ bool utl::UCBContentHelper::EqualURLs(
if (url1.isEmpty() || url2.isEmpty()) {
return false;
}
- ucbhelper::ContentBroker * broker = ucbhelper::ContentBroker::get();
- if (broker == 0) {
- throw css::uno::RuntimeException(
- rtl::OUString( "no ucbhelper::ContentBroker"),
- css::uno::Reference<css::uno::XInterface>());
- }
+ css::uno::Reference< css::ucb::XUniversalContentBroker > ucb(
+ css::ucb::UniversalContentBroker::create(
+ comphelper::getProcessComponentContext()));
return
- broker->getContentProviderInterface()->compareContentIds(
- (broker->getContentIdentifierFactoryInterface()->
- createContentIdentifier(canonic(url1))),
- (broker->getContentIdentifierFactoryInterface()->
- createContentIdentifier(canonic(url2))))
+ ucb->compareContentIds(
+ ucb->createContentIdentifier(canonic(url1)),
+ ucb->createContentIdentifier(canonic(url2)))
== 0;
}
diff --git a/unotools/source/ucbhelper/ucblockbytes.cxx b/unotools/source/ucbhelper/ucblockbytes.cxx
index e74c83d5df68..2b709a98c157 100644
--- a/unotools/source/ucbhelper/ucblockbytes.cxx
+++ b/unotools/source/ucbhelper/ucblockbytes.cxx
@@ -54,8 +54,6 @@
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <comphelper/storagehelper.hxx>
-
-#include <ucbhelper/contentbroker.hxx>
#include <ucbhelper/content.hxx>
using namespace ::com::sun::star::uno;
@@ -628,8 +626,8 @@ Moderator::Moderator(
xContent,
new UcbTaskEnvironment(
xInteract.is() ? new ModeratorsInteractionHandler(*this) : 0,
- xProgress.is() ? new ModeratorsProgressHandler(*this) : 0
- ))
+ xProgress.is() ? new ModeratorsProgressHandler(*this) : 0),
+ comphelper::getProcessComponentContext())
{
// now exchange the whole data sink stuff
// with a thread safe version
@@ -1149,7 +1147,9 @@ static sal_Bool _UCBOpenContentSync(
Reference < XProgressHandler > xProgress,
UcbLockBytesHandlerRef xHandler )
{
- ::ucbhelper::Content aContent( xContent, new UcbTaskEnvironment( xInteract, xProgress ) );
+ ::ucbhelper::Content aContent(
+ xContent, new UcbTaskEnvironment( xInteract, xProgress ),
+ comphelper::getProcessComponentContext() );
Reference < XContentIdentifier > xIdent = xContent->getIdentifier();
::rtl::OUString aScheme = xIdent->getContentProviderScheme();
diff --git a/unotools/source/ucbhelper/ucbstreamhelper.cxx b/unotools/source/ucbhelper/ucbstreamhelper.cxx
index 330b3d0bba73..67483f1904b0 100644
--- a/unotools/source/ucbhelper/ucbstreamhelper.cxx
+++ b/unotools/source/ucbhelper/ucbstreamhelper.cxx
@@ -22,12 +22,11 @@
#include <unotools/ucbstreamhelper.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/ucb/CommandAbortedException.hpp>
-
+#include <com/sun/star/ucb/UniversalContentBroker.hpp>
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
#include <com/sun/star/ucb/InsertCommandArgument.hpp>
#include <com/sun/star/io/XActiveDataStreamer.hpp>
-#include <ucbhelper/contentbroker.hxx>
#include <ucbhelper/content.hxx>
#include <unotools/streamwrap.hxx>
@@ -47,93 +46,95 @@ static SvStream* lcl_CreateStream( const String& rFileName, StreamMode eOpenMode
UcbLockBytesHandler* pHandler, sal_Bool bEnsureFileExists )
{
SvStream* pStream = NULL;
- ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
- if ( pBroker )
+ Reference< XUniversalContentBroker > ucb(
+ UniversalContentBroker::create(
+ comphelper::getProcessComponentContext() ) );
+ UcbLockBytesRef xLockBytes;
+ if ( eOpenMode & STREAM_WRITE )
{
- UcbLockBytesRef xLockBytes;
- if ( eOpenMode & STREAM_WRITE )
+ sal_Bool bTruncate = ( eOpenMode & STREAM_TRUNC ) != 0;
+ if ( bTruncate )
{
- sal_Bool bTruncate = ( eOpenMode & STREAM_TRUNC ) != 0;
- if ( bTruncate )
+ try
{
- try
- {
- // truncate is implemented with deleting the original file
- ::ucbhelper::Content aCnt( rFileName, Reference < XCommandEnvironment >() );
- aCnt.executeCommand( ::rtl::OUString("delete"), makeAny( sal_Bool( sal_True ) ) );
- }
-
- catch ( const CommandAbortedException& )
- {
- // couldn't truncate/delete
- }
- catch ( const ContentCreationException& )
- {
- }
- catch ( const Exception& )
- {
- }
+ // truncate is implemented with deleting the original file
+ ::ucbhelper::Content aCnt(
+ rFileName, Reference < XCommandEnvironment >(),
+ comphelper::getProcessComponentContext() );
+ aCnt.executeCommand( ::rtl::OUString("delete"), makeAny( sal_Bool( sal_True ) ) );
}
- if ( bEnsureFileExists || bTruncate )
+ catch ( const CommandAbortedException& )
+ {
+ // couldn't truncate/delete
+ }
+ catch ( const ContentCreationException& )
+ {
+ }
+ catch ( const Exception& )
{
- try
- {
- // make sure that the desired file exists before trying to open
- SvMemoryStream aStream(0,0);
- ::utl::OInputStreamWrapper* pInput = new ::utl::OInputStreamWrapper( aStream );
- Reference< XInputStream > xInput( pInput );
-
- ::ucbhelper::Content aContent( rFileName, Reference < XCommandEnvironment >() );
- InsertCommandArgument aInsertArg;
- aInsertArg.Data = xInput;
-
- aInsertArg.ReplaceExisting = sal_False;
- Any aCmdArg;
- aCmdArg <<= aInsertArg;
- aContent.executeCommand( ::rtl::OUString("insert"), aCmdArg );
- }
-
- // it is NOT an error when the stream already exists and no truncation was desired
- catch ( const CommandAbortedException& )
- {
- // currently never an error is detected !
- }
- catch ( const ContentCreationException& )
- {
- }
- catch ( const Exception& )
- {
- }
}
}
- try
+ if ( bEnsureFileExists || bTruncate )
{
- // create LockBytes using UCB
- ::ucbhelper::Content aContent( rFileName, Reference < XCommandEnvironment >() );
- xLockBytes = UcbLockBytes::CreateLockBytes( aContent.get(), Sequence < PropertyValue >(),
- eOpenMode, xInteractionHandler, pHandler );
- if ( xLockBytes.Is() )
+ try
+ {
+ // make sure that the desired file exists before trying to open
+ SvMemoryStream aStream(0,0);
+ ::utl::OInputStreamWrapper* pInput = new ::utl::OInputStreamWrapper( aStream );
+ Reference< XInputStream > xInput( pInput );
+
+ ::ucbhelper::Content aContent(
+ rFileName, Reference < XCommandEnvironment >(),
+ comphelper::getProcessComponentContext() );
+ InsertCommandArgument aInsertArg;
+ aInsertArg.Data = xInput;
+
+ aInsertArg.ReplaceExisting = sal_False;
+ Any aCmdArg;
+ aCmdArg <<= aInsertArg;
+ aContent.executeCommand( ::rtl::OUString("insert"), aCmdArg );
+ }
+
+ // it is NOT an error when the stream already exists and no truncation was desired
+ catch ( const CommandAbortedException& )
+ {
+ // currently never an error is detected !
+ }
+ catch ( const ContentCreationException& )
+ {
+ }
+ catch ( const Exception& )
{
- pStream = new SvStream( xLockBytes );
- pStream->SetBufferSize( 4096 );
- pStream->SetError( xLockBytes->GetError() );
}
}
- catch ( const CommandAbortedException& )
- {
- }
- catch ( const ContentCreationException& )
- {
- }
- catch ( const Exception& )
+ }
+
+ try
+ {
+ // create LockBytes using UCB
+ ::ucbhelper::Content aContent(
+ rFileName, Reference < XCommandEnvironment >(),
+ comphelper::getProcessComponentContext() );
+ xLockBytes = UcbLockBytes::CreateLockBytes( aContent.get(), Sequence < PropertyValue >(),
+ eOpenMode, xInteractionHandler, pHandler );
+ if ( xLockBytes.Is() )
{
+ pStream = new SvStream( xLockBytes );
+ pStream->SetBufferSize( 4096 );
+ pStream->SetError( xLockBytes->GetError() );
}
}
- else
- // if no UCB is present at least conventional file io is supported
- pStream = new SvFileStream( rFileName, eOpenMode );
+ catch ( const CommandAbortedException& )
+ {
+ }
+ catch ( const ContentCreationException& )
+ {
+ }
+ catch ( const Exception& )
+ {
+ }
return pStream;
}