summaryrefslogtreecommitdiff
path: root/ucbhelper
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 /ucbhelper
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 'ucbhelper')
-rw-r--r--ucbhelper/Package_inc.mk2
-rw-r--r--ucbhelper/inc/ucbhelper/configurationkeys.hxx32
-rw-r--r--ucbhelper/inc/ucbhelper/content.hxx14
-rw-r--r--ucbhelper/inc/ucbhelper/contentbroker.hxx170
-rw-r--r--ucbhelper/inc/ucbhelper/fileidentifierconverter.hxx10
-rw-r--r--ucbhelper/source/client/content.cxx298
-rw-r--r--ucbhelper/source/client/contentbroker.cxx343
-rw-r--r--ucbhelper/source/client/fileidentifierconverter.cxx14
8 files changed, 125 insertions, 758 deletions
diff --git a/ucbhelper/Package_inc.mk b/ucbhelper/Package_inc.mk
index 7df94fef828e..2569a0487cbd 100644
--- a/ucbhelper/Package_inc.mk
+++ b/ucbhelper/Package_inc.mk
@@ -13,9 +13,7 @@ $(eval $(call gb_Package_add_file,ucbhelper_inc,inc/ucbhelper/activedatasink.hxx
$(eval $(call gb_Package_add_file,ucbhelper_inc,inc/ucbhelper/activedatastreamer.hxx,ucbhelper/activedatastreamer.hxx))
$(eval $(call gb_Package_add_file,ucbhelper_inc,inc/ucbhelper/cancelcommandexecution.hxx,ucbhelper/cancelcommandexecution.hxx))
$(eval $(call gb_Package_add_file,ucbhelper_inc,inc/ucbhelper/commandenvironment.hxx,ucbhelper/commandenvironment.hxx))
-$(eval $(call gb_Package_add_file,ucbhelper_inc,inc/ucbhelper/configurationkeys.hxx,ucbhelper/configurationkeys.hxx))
$(eval $(call gb_Package_add_file,ucbhelper_inc,inc/ucbhelper/content.hxx,ucbhelper/content.hxx))
-$(eval $(call gb_Package_add_file,ucbhelper_inc,inc/ucbhelper/contentbroker.hxx,ucbhelper/contentbroker.hxx))
$(eval $(call gb_Package_add_file,ucbhelper_inc,inc/ucbhelper/contenthelper.hxx,ucbhelper/contenthelper.hxx))
$(eval $(call gb_Package_add_file,ucbhelper_inc,inc/ucbhelper/contentidentifier.hxx,ucbhelper/contentidentifier.hxx))
$(eval $(call gb_Package_add_file,ucbhelper_inc,inc/ucbhelper/contentinfo.hxx,ucbhelper/contentinfo.hxx))
diff --git a/ucbhelper/inc/ucbhelper/configurationkeys.hxx b/ucbhelper/inc/ucbhelper/configurationkeys.hxx
deleted file mode 100644
index 2f7992047993..000000000000
--- a/ucbhelper/inc/ucbhelper/configurationkeys.hxx
+++ /dev/null
@@ -1,32 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef _UCBHELPER_CONFIGURATIONKEYS_HXX_
-#define _UCBHELPER_CONFIGURATIONKEYS_HXX_
-
-//============================================================================
-/** Various primary and secondary keys under which UCB configurations can be
- accessed in the configuration database.
- */
-#define UCB_CONFIGURATION_KEY1_LOCAL "Local"
-#define UCB_CONFIGURATION_KEY2_OFFICE "Office"
-
-#endif // _UCBHELPER_CONFIGURATIONKEYS_HXX_
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucbhelper/inc/ucbhelper/content.hxx b/ucbhelper/inc/ucbhelper/content.hxx
index 9667190944ed..9c06bf5366e7 100644
--- a/ucbhelper/inc/ucbhelper/content.hxx
+++ b/ucbhelper/inc/ucbhelper/content.hxx
@@ -53,6 +53,10 @@ namespace com { namespace sun { namespace star { namespace ucb {
struct NumberedSortingInfo;
} } } }
+namespace com { namespace sun { namespace star { namespace uno {
+ class XComponentContext;
+} } } }
+
namespace ucbhelper
{
@@ -118,7 +122,9 @@ public:
*/
Content( const rtl::OUString& rURL,
const ::com::sun::star::uno::Reference<
- ::com::sun::star::ucb::XCommandEnvironment >& rEnv )
+ ::com::sun::star::ucb::XCommandEnvironment >& rEnv,
+ const ::com::sun::star::uno::Reference<
+ ::com::sun::star::uno::XComponentContext >& rCtx )
throw ( ::com::sun::star::ucb::ContentCreationException,
::com::sun::star::uno::RuntimeException );
/**
@@ -133,7 +139,9 @@ public:
Content( const ::com::sun::star::uno::Reference<
::com::sun::star::ucb::XContent >& rContent,
const ::com::sun::star::uno::Reference<
- ::com::sun::star::ucb::XCommandEnvironment >& rEnv )
+ ::com::sun::star::ucb::XCommandEnvironment >& rEnv,
+ const ::com::sun::star::uno::Reference<
+ ::com::sun::star::uno::XComponentContext >& rCtx )
throw ( ::com::sun::star::ucb::ContentCreationException,
::com::sun::star::uno::RuntimeException );
/**
@@ -172,6 +180,8 @@ public:
create( const rtl::OUString& rURL,
const ::com::sun::star::uno::Reference<
::com::sun::star::ucb::XCommandEnvironment >& rEnv,
+ const ::com::sun::star::uno::Reference<
+ ::com::sun::star::uno::XComponentContext >& rCtx,
Content& rContent );
//////////////////////////////////////////////////////////////////////
diff --git a/ucbhelper/inc/ucbhelper/contentbroker.hxx b/ucbhelper/inc/ucbhelper/contentbroker.hxx
deleted file mode 100644
index 564b11e18b71..000000000000
--- a/ucbhelper/inc/ucbhelper/contentbroker.hxx
+++ /dev/null
@@ -1,170 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef _UCBHELPER_CONTENTBROKER_HXX
-#define _UCBHELPER_CONTENTBROKER_HXX
-
-#include <boost/noncopyable.hpp>
-#include <com/sun/star/uno/Reference.hxx>
-#include <com/sun/star/uno/Sequence.h>
-
-namespace com { namespace sun { namespace star { namespace lang {
- class XMultiServiceFactory;
-} } } }
-
-namespace com { namespace sun { namespace star { namespace ucb {
- class XContentIdentifierFactory;
- class XContentProvider;
- class XContentProviderManager;
- class XCommandProcessor;
-} } } }
-#include <ucbhelper/registerucb.hxx>
-#include "ucbhelper/ucbhelperdllapi.h"
-
-namespace ucbhelper
-{
-
-class ContentBroker_Impl;
-
-//=========================================================================
-
-/**
- * This class simplifies access to the Universal Content Broker (UCB).
- * Currently there can only be one UCB instance per process. This class can
- * be used to initialize and deinitialize the Broker and to access its
- * interfaces directly.
- */
-class UCBHELPER_DLLPUBLIC ContentBroker : private boost::noncopyable
-{
- ContentBroker_Impl* m_pImpl;
- // The "one and only" Broker.
- static ContentBroker* m_pTheBroker;
-
-private:
- /** Constructor.
- *
- * @param rxSMgr is a Service Manager.
- * @param rArguments are the arguments to pass to the
- * com.sun.star.ucb.UniversalContentBroker service when creating it.
- * Currently, this must be a sequence containing exactly two
- * strings, a primary and a secondary configuration key.
- * Refer to http://ucb.openoffice.org/docs/ucb-configuration.html
- * for more information on UCB configuration.
- */
- UCBHELPER_DLLPRIVATE ContentBroker( const ::com::sun::star::uno::Reference<
- ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
- const ::com::sun::star::uno::Sequence<
- ::com::sun::star::uno::Any >& rArguments );
-
-protected:
- /**
- * Destructor.
- */
- ~ContentBroker();
-
-public:
- /** Initialize "the one and only" Broker. This method must be called
- * exactly once, before the Broker is used in any way.
- *
- * @param rSMgr is a factory to create services needed in the Broker's
- * implementation.
- *
- * @param rArguments are the arguments to pass to the
- * com.sun.star.ucb.UniversalContentBroker service when creating
- * it. Currently, this must be a sequence containing exactly two
- * strings, a primary and a secondary configuration key.
- * Refer to http://ucb.openoffice.org/docs/ucb-configuration.html
- * for more information on UCB configuration.
- *
- * @return True if creation and possible configuration of the Broker
- * was successful.
- */
- static sal_Bool
- initialize( const::com::sun::star::uno::Reference<
- ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
- const ::com::sun::star::uno::Sequence<
- ::com::sun::star::uno::Any >& rArguments );
-
- /** Deinitialize "the one and only" Broker. Once this method has been
- * called, the Broker must not be used any longer.
- */
- static void
- deinitialize();
-
- /**
- * This method returns the Broker, if it was already initialized.
- *
- * @return the Broker or 0, if ContentBroker::initialize() was not yet
- * called or did fail.
- */
- static ContentBroker*
- get();
-
- /**
- * This method returns the Service Manager used to instanciate the Broker.
- *
- * @return a Service Manager.
- */
- ::com::sun::star::uno::Reference<
- ::com::sun::star::lang::XMultiServiceFactory >
- getServiceManager() const;
-
- /**
- * This method returns the XContentIdentifierFactory interface of the
- * Broker.
- *
- * @return a XContentIdentifierFactory interface.
- */
- ::com::sun::star::uno::Reference<
- ::com::sun::star::ucb::XContentIdentifierFactory >
- getContentIdentifierFactoryInterface() const;
-
- /**
- * This method returns the XContentProvider interface of the Broker.
- *
- * @return a XContentProvider interface.
- */
- ::com::sun::star::uno::Reference<
- ::com::sun::star::ucb::XContentProvider >
- getContentProviderInterface() const;
-
- /**
- * This method returns the XContentProviderManager interface of the Broker.
- *
- * @return a XContentProviderManager interface.
- */
- ::com::sun::star::uno::Reference<
- ::com::sun::star::ucb::XContentProviderManager >
- getContentProviderManagerInterface() const;
-
- /**
- * This method returns the XCommandProcessor interface of the Broker.
- *
- * @return a XCommandProcessor interface.
- */
- ::com::sun::star::uno::Reference<
- ::com::sun::star::ucb::XCommandProcessor >
- getCommandProcessorInterface() const;
-};
-
-} /* namespace ucbhelper */
-
-#endif /* !_UCBHELPER_CONTENTBROKER_HXX */
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucbhelper/inc/ucbhelper/fileidentifierconverter.hxx b/ucbhelper/inc/ucbhelper/fileidentifierconverter.hxx
index be7ce3b0c33e..b044c31db7c8 100644
--- a/ucbhelper/inc/ucbhelper/fileidentifierconverter.hxx
+++ b/ucbhelper/inc/ucbhelper/fileidentifierconverter.hxx
@@ -26,7 +26,7 @@
#include "ucbhelper/ucbhelperdllapi.h"
namespace com { namespace sun { namespace star { namespace ucb {
- class XContentProviderManager;
+ class XUniversalContentBroker;
} } } }
namespace rtl { class OUString; }
@@ -73,8 +73,8 @@ UCBHELPER_DLLPUBLIC rtl::OUString getLocalFileURL()
UCBHELPER_DLLPUBLIC rtl::OUString
getFileURLFromSystemPath(
com::sun::star::uno::Reference<
- com::sun::star::ucb::XContentProviderManager > const &
- rManager,
+ com::sun::star::ucb::XUniversalContentBroker > const &
+ rUcb,
rtl::OUString const & rBaseURL,
rtl::OUString const & rSystemPath)
SAL_THROW((com::sun::star::uno::RuntimeException));
@@ -103,8 +103,8 @@ getFileURLFromSystemPath(
UCBHELPER_DLLPUBLIC rtl::OUString
getSystemPathFromFileURL(
com::sun::star::uno::Reference<
- com::sun::star::ucb::XContentProviderManager > const &
- rManager,
+ com::sun::star::ucb::XUniversalContentBroker > const &
+ rUcb,
rtl::OUString const & rURL)
SAL_THROW((com::sun::star::uno::RuntimeException));
diff --git a/ucbhelper/source/client/content.cxx b/ucbhelper/source/client/content.cxx
index 95106abb64c3..ec3b4544d62c 100644
--- a/ucbhelper/source/client/content.cxx
+++ b/ucbhelper/source/client/content.cxx
@@ -17,12 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include "sal/config.h"
-/**************************************************************************
- TODO
- **************************************************************************
+#include <cassert>
- *************************************************************************/
#include <osl/diagnose.h>
#include <osl/mutex.hxx>
#include <salhelper/simplereferenceobject.hxx>
@@ -48,6 +46,8 @@
#include <com/sun/star/ucb/XContentProviderManager.hpp>
#include <com/sun/star/ucb/XDynamicResultSet.hpp>
#include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
+#include <com/sun/star/ucb/UniversalContentBroker.hpp>
+#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#include <com/sun/star/beans/Property.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
@@ -57,7 +57,6 @@
#include <com/sun/star/beans/UnknownPropertyException.hpp>
#include <ucbhelper/macros.hxx>
#include <ucbhelper/content.hxx>
-#include <ucbhelper/contentbroker.hxx>
#include <ucbhelper/activedatasink.hxx>
#include <ucbhelper/activedatastreamer.hxx>
#include <ucbhelper/interactionrequest.hxx>
@@ -167,7 +166,7 @@ class Content_Impl : public salhelper::SimpleReferenceObject
friend class ContentEventListener_Impl;
mutable rtl::OUString m_aURL;
- Reference< XMultiServiceFactory > m_xSMgr;
+ Reference< XComponentContext > m_xCtx;
Reference< XContent > m_xContent;
Reference< XCommandProcessor > m_xCommandProcessor;
Reference< XCommandEnvironment > m_xEnv;
@@ -181,7 +180,7 @@ private:
public:
Content_Impl() : m_nCommandId( 0 ) {};
- Content_Impl( const Reference< XMultiServiceFactory >& rSMgr,
+ Content_Impl( const Reference< XComponentContext >& rCtx,
const Reference< XContent >& rContent,
const Reference< XCommandEnvironment >& rEnv );
@@ -191,7 +190,8 @@ public:
Reference< XContent > getContent();
Reference< XCommandProcessor > getCommandProcessor();
sal_Int32 getCommandId();
- Reference< XMultiServiceFactory > getServiceManager() { return m_xSMgr; }
+ Reference< XComponentContext > getComponentContext()
+ { assert(m_xCtx.is()); return m_xCtx; }
Any executeCommand( const Command& rCommand );
@@ -206,109 +206,42 @@ public:
// Helpers.
//=========================================================================
-static void ensureContentProviderForURL( const ContentBroker & rBroker,
+static void ensureContentProviderForURL( const Reference< XUniversalContentBroker >& rBroker,
const rtl::OUString & rURL )
throw ( ContentCreationException, RuntimeException )
{
- Reference< XContentProviderManager > xMgr
- = rBroker.getContentProviderManagerInterface();
- if ( !xMgr.is() )
+ Reference< XContentProvider > xProv
+ = rBroker->queryContentProvider( rURL );
+ if ( !xProv.is() )
{
- throw RuntimeException(
- rtl::OUString(
- "UCB does not implement mandatory interface "
- "XContentProviderManager!" ),
- Reference< XInterface >() );
- }
- else
- {
- Reference< XContentProvider > xProv
- = xMgr->queryContentProvider( rURL );
- if ( !xProv.is() )
- {
- throw ContentCreationException(
- rtl::OUString(
- "No Content Provider available for URL: ") + rURL,
- Reference< XInterface >(),
- ContentCreationError_NO_CONTENT_PROVIDER );
- }
+ throw ContentCreationException(
+ "No Content Provider available for URL: " + rURL,
+ Reference< XInterface >(),
+ ContentCreationError_NO_CONTENT_PROVIDER );
}
}
//=========================================================================
-static ContentBroker* getContentBroker( bool bThrow )
- throw ( ContentCreationException, RuntimeException )
-{
- ContentBroker* pBroker = ContentBroker::get();
-
- if ( !pBroker )
- {
- if ( bThrow )
- throw RuntimeException(
- rtl::OUString("No Content Broker!"),
- Reference< XInterface >() );
- }
- else
- {
-#if OSL_DEBUG_LEVEL > 1
- Reference< XContentProviderManager > xMgr
- = pBroker->getContentProviderManagerInterface();
- if ( !xMgr.is() )
- {
- if ( bThrow )
- throw RuntimeException(
- rtl::OUString(
- "UCB does not implement mandatory interface "
- "XContentProviderManager!" ),
- Reference< XInterface >() );
- }
- else
- {
- OSL_ENSURE( xMgr->queryContentProviders().getLength(),
- "Content Broker not configured (no providers)!" );
- }
-#endif
- }
-
- return pBroker;
-}
-
-//=========================================================================
static Reference< XContentIdentifier > getContentIdentifier(
- const ContentBroker & rBroker,
+ const Reference< XUniversalContentBroker > & rBroker,
const rtl::OUString & rURL,
bool bThrow )
throw ( ContentCreationException, RuntimeException )
{
- Reference< XContentIdentifierFactory > xIdFac
- = rBroker.getContentIdentifierFactoryInterface();
- if ( xIdFac.is() )
- {
- Reference< XContentIdentifier > xId
- = xIdFac->createContentIdentifier( rURL );
-
- if ( xId.is() )
- return xId;
+ Reference< XContentIdentifier > xId
+ = rBroker->createContentIdentifier( rURL );
- if ( bThrow )
- {
- ensureContentProviderForURL( rBroker, rURL );
+ if ( xId.is() )
+ return xId;
- throw ContentCreationException(
- rtl::OUString(
- "Unable to create Content Identifier!" ),
- Reference< XInterface >(),
- ContentCreationError_IDENTIFIER_CREATION_FAILED );
- }
- }
- else
+ if ( bThrow )
{
- if ( bThrow )
- throw RuntimeException(
- rtl::OUString(
- "UCB does not implement mandatory interface "
- "XContentIdentifierFactory!" ),
- Reference< XInterface >() );
+ ensureContentProviderForURL( rBroker, rURL );
+
+ throw ContentCreationException(
+ "Unable to create Content Identifier!",
+ Reference< XInterface >(),
+ ContentCreationError_IDENTIFIER_CREATION_FAILED );
}
return Reference< XContentIdentifier >();
@@ -316,49 +249,34 @@ static Reference< XContentIdentifier > getContentIdentifier(
//=========================================================================
static Reference< XContent > getContent(
- const ContentBroker & rBroker,
+ const Reference< XUniversalContentBroker > & rBroker,
const Reference< XContentIdentifier > & xId,
bool bThrow )
throw ( ContentCreationException, RuntimeException )
{
- Reference< XContentProvider > xProvider
- = rBroker.getContentProviderInterface();
- if ( xProvider.is() )
+ Reference< XContent > xContent;
+ rtl::OUString msg;
+ try
{
- Reference< XContent > xContent;
- rtl::OUString msg;
- try
- {
- xContent = xProvider->queryContent( xId );
- }
- catch ( IllegalIdentifierException const & e )
- {
- msg = e.Message;
- // handled below.
- }
-
- if ( xContent.is() )
- return xContent;
+ xContent = rBroker->queryContent( xId );
+ }
+ catch ( IllegalIdentifierException const & e )
+ {
+ msg = e.Message;
+ // handled below.
+ }
- if ( bThrow )
- {
- ensureContentProviderForURL( rBroker, xId->getContentIdentifier() );
+ if ( xContent.is() )
+ return xContent;
- throw ContentCreationException(
- rtl::OUString(
- "Unable to create Content! " ) + msg,
- Reference< XInterface >(),
- ContentCreationError_CONTENT_CREATION_FAILED );
- }
- }
- else
+ if ( bThrow )
{
- if ( bThrow )
- throw RuntimeException(
- rtl::OUString(
- "UCB does not implement mandatory interface "
- "XContentProvider!" ),
- Reference< XInterface >() );
+ ensureContentProviderForURL( rBroker, xId->getContentIdentifier() );
+
+ throw ContentCreationException(
+ "Unable to create Content! " + msg,
+ Reference< XInterface >(),
+ ContentCreationError_CONTENT_CREATION_FAILED );
}
return Reference< XContent >();
@@ -379,27 +297,28 @@ Content::Content()
//=========================================================================
Content::Content( const rtl::OUString& rURL,
- const Reference< XCommandEnvironment >& rEnv )
+ const Reference< XCommandEnvironment >& rEnv,
+ const Reference< XComponentContext >& rCtx )
throw ( ContentCreationException, RuntimeException )
{
- ContentBroker* pBroker = getContentBroker( true );
+ Reference< XUniversalContentBroker > pBroker(
+ UniversalContentBroker::create( rCtx ) );
Reference< XContentIdentifier > xId
- = getContentIdentifier( *pBroker, rURL, true );
+ = getContentIdentifier( pBroker, rURL, true );
- Reference< XContent > xContent = getContent( *pBroker, xId, true );
+ Reference< XContent > xContent = getContent( pBroker, xId, true );
- m_xImpl = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
+ m_xImpl = new Content_Impl( rCtx, xContent, rEnv );
}
//=========================================================================
Content::Content( const Reference< XContent >& rContent,
- const Reference< XCommandEnvironment >& rEnv )
+ const Reference< XCommandEnvironment >& rEnv,
+ const Reference< XComponentContext >& rCtx )
throw ( ContentCreationException, RuntimeException )
{
- ContentBroker* pBroker = getContentBroker( true );
-
- m_xImpl = new Content_Impl( pBroker->getServiceManager(), rContent, rEnv );
+ m_xImpl = new Content_Impl( rCtx, rContent, rEnv );
}
//=========================================================================
@@ -412,23 +331,23 @@ Content::Content( const Content& rOther )
// static
sal_Bool Content::create( const rtl::OUString& rURL,
const Reference< XCommandEnvironment >& rEnv,
+ const Reference< XComponentContext >& rCtx,
Content& rContent )
{
- ContentBroker* pBroker = getContentBroker( false );
- if ( !pBroker )
- return sal_False;
+ Reference< XUniversalContentBroker > pBroker(
+ UniversalContentBroker::create( rCtx ) );
Reference< XContentIdentifier > xId
- = getContentIdentifier( *pBroker, rURL, false );
+ = getContentIdentifier( pBroker, rURL, false );
if ( !xId.is() )
return sal_False;
- Reference< XContent > xContent = getContent( *pBroker, xId, false );
+ Reference< XContent > xContent = getContent( pBroker, xId, false );
if ( !xContent.is() )
return sal_False;
rContent.m_xImpl
- = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
+ = new Content_Impl( rCtx, xContent, rEnv );
return sal_True;
}
@@ -738,12 +657,12 @@ Reference< XResultSet > Content::createSortedCursor(
if( aDynSet.is() )
{
Reference< XDynamicResultSet > aDynResult;
- Reference< XMultiServiceFactory > aServiceManager = m_xImpl->getServiceManager();
+ Reference< XMultiComponentFactory > aServiceManager = m_xImpl->getComponentContext()->getServiceManager();
if( aServiceManager.is() )
{
- Reference< XSortedDynamicResultSetFactory > aSortFactory( aServiceManager->createInstance(
- rtl::OUString("com.sun.star.ucb.SortedDynamicResultSetFactory")),
+ Reference< XSortedDynamicResultSetFactory > aSortFactory( aServiceManager->createInstanceWithContext(
+ "com.sun.star.ucb.SortedDynamicResultSetFactory", m_xImpl->getComponentContext()),
UNO_QUERY );
aDynResult = aSortFactory->createSortedDynamicResultSet( aDynSet,
@@ -1024,7 +943,8 @@ sal_Bool Content::insertNewContent( const rtl::OUString& rContentType,
return sal_False;
}
- Content aNewContent( xNew, m_xImpl->getEnvironment() );
+ Content aNewContent(
+ xNew, m_xImpl->getEnvironment(), m_xImpl->getComponentContext() );
aNewContent.setPropertyValues( rPropertyNames, rPropertyValues );
aNewContent.executeCommand( rtl::OUString("insert"),
makeAny(
@@ -1044,20 +964,8 @@ sal_Bool Content::transferContent( const Content& rSourceContent,
const sal_Int32 nNameClashAction )
throw( CommandAbortedException, RuntimeException, Exception )
{
- ContentBroker* pBroker = ContentBroker::get();
- if ( !pBroker )
- {
- OSL_FAIL( "Content::transferContent - No Content Broker!" );
- return sal_False;
- }
-
- Reference< XCommandProcessor > xCmdProc(
- pBroker->getCommandProcessorInterface() );
- if ( !xCmdProc.is() )
- {
- OSL_FAIL( "Content::transferContent - No XCommandProcessor!" );
- return sal_False;
- }
+ Reference< XUniversalContentBroker > pBroker(
+ UniversalContentBroker::create( m_xImpl->getComponentContext() ) );
// Execute command "globalTransfer" at UCB.
@@ -1098,7 +1006,7 @@ sal_Bool Content::transferContent( const Content& rSourceContent,
aCommand.Handle = -1; // n/a
aCommand.Argument <<= aTransferArg;
- xCmdProc->execute( aCommand, 0, m_xImpl->getEnvironment() );
+ pBroker->execute( aCommand, 0, m_xImpl->getEnvironment() );
return sal_True;
}
@@ -1152,14 +1060,15 @@ sal_Bool Content::isDocument()
//=========================================================================
//=========================================================================
-Content_Impl::Content_Impl( const Reference< XMultiServiceFactory >& rSMgr,
+Content_Impl::Content_Impl( const Reference< XComponentContext >& rCtx,
const Reference< XContent >& rContent,
const Reference< XCommandEnvironment >& rEnv )
-: m_xSMgr( rSMgr ),
+: m_xCtx( rCtx ),
m_xContent( rContent ),
m_xEnv( rEnv ),
m_nCommandId( 0 )
{
+ assert(rCtx.is());
if ( m_xContent.is() )
{
m_xContentEventListener = new ContentEventListener_Impl( *this );
@@ -1288,51 +1197,30 @@ Reference< XContent > Content_Impl::getContent()
if ( !m_xContent.is() && !m_aURL.isEmpty() )
{
- ContentBroker* pBroker = ContentBroker::get();
+ Reference< XUniversalContentBroker > pBroker(
+ UniversalContentBroker::create( getComponentContext() ) );
- OSL_ENSURE( pBroker, "No Content Broker!" );
-
- if ( pBroker )
- {
- OSL_ENSURE( pBroker->getContentProviderManagerInterface()
- ->queryContentProviders().getLength(),
- "Content Broker not configured (no providers)!" );
+ OSL_ENSURE( pBroker->queryContentProviders().getLength(),
+ "Content Broker not configured (no providers)!" );
- Reference< XContentIdentifierFactory > xIdFac
- = pBroker->getContentIdentifierFactoryInterface();
+ Reference< XContentIdentifier > xId
+ = pBroker->createContentIdentifier( m_aURL );
- OSL_ENSURE( xIdFac.is(), "No Content Identifier factory!" );
+ OSL_ENSURE( xId.is(), "No Content Identifier!" );
- if ( xIdFac.is() )
+ if ( xId.is() )
+ {
+ try
+ {
+ m_xContent = pBroker->queryContent( xId );
+ }
+ catch ( IllegalIdentifierException const & )
{
- Reference< XContentIdentifier > xId
- = xIdFac->createContentIdentifier( m_aURL );
-
- OSL_ENSURE( xId.is(), "No Content Identifier!" );
-
- if ( xId.is() )
- {
- Reference< XContentProvider > xProvider
- = pBroker->getContentProviderInterface();
-
- OSL_ENSURE( xProvider.is(), "No Content Provider!" );
-
- if ( xProvider.is() )
- {
- try
- {
- m_xContent = xProvider->queryContent( xId );
- }
- catch ( IllegalIdentifierException const & )
- {
- }
-
- if ( m_xContent.is() )
- m_xContent->addContentEventListener(
- m_xContentEventListener );
- }
- }
}
+
+ if ( m_xContent.is() )
+ m_xContent->addContentEventListener(
+ m_xContentEventListener );
}
}
}
diff --git a/ucbhelper/source/client/contentbroker.cxx b/ucbhelper/source/client/contentbroker.cxx
index 219a7a13d077..24cec09b7ea5 100644
--- a/ucbhelper/source/client/contentbroker.cxx
+++ b/ucbhelper/source/client/contentbroker.cxx
@@ -17,194 +17,25 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include "sal/config.h"
-/**************************************************************************
- TODO
- **************************************************************************
+#ifdef ANDROID
- *************************************************************************/
-#include <osl/diagnose.h>
-#include <osl/mutex.hxx>
-#include <rtl/instance.hxx>
-#include <com/sun/star/beans/XPropertySet.hpp>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/ucb/UniversalContentBroker.hpp>
-#include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
-#include <com/sun/star/ucb/XContentProvider.hpp>
-#include <com/sun/star/ucb/XContentProviderManager.hpp>
-#include <com/sun/star/ucb/XCommandProcessor.hpp>
-#include <ucbhelper/contentbroker.hxx>
-
-#ifdef ANDROID
-#include <cppuhelper/bootstrap.hxx>
#include <com/sun/star/uno/XComponentContext.hpp>
-#include <ucbhelper/configurationkeys.hxx>
-#endif
+#include <cppuhelper/bootstrap.hxx>
-using namespace com::sun::star::beans;
-using namespace com::sun::star::lang;
using namespace com::sun::star::ucb;
using namespace com::sun::star::uno;
-using ::rtl::OUString;
-
-namespace
-{
- struct theContentBrokerMutex : public rtl::Static< osl::Mutex, theContentBrokerMutex > {};
-} // namespace
-
-namespace ucbhelper
-{
-
-//=========================================================================
-//=========================================================================
-//
-// class ContentBroker_Impl.
-//
-//=========================================================================
-//=========================================================================
-
-class ContentBroker_Impl
-{
- Reference< XMultiServiceFactory > m_xSMgr;
- Reference< XContentIdentifierFactory > m_xIdFac;
- Reference< XContentProvider > m_xProvider;
- Reference< XContentProviderManager > m_xProviderMgr;
- Reference< XCommandProcessor > m_xCommandProc;
- osl::Mutex m_aMutex;
- Sequence< Any > m_aArguments;
- ContentProviderDataList m_aProvData;
- bool m_bInitDone;
-
-public:
- ContentBroker_Impl( const Reference< XMultiServiceFactory >& rSMgr,
- const Sequence< Any >& rArguments )
- : m_xSMgr( rSMgr ), m_aArguments( rArguments ), m_bInitDone( sal_False )
- {}
-
- ContentBroker_Impl( const Reference< XMultiServiceFactory >& rSMgr,
- const ContentProviderDataList & rData )
- : m_xSMgr( rSMgr ), m_aProvData( rData ), m_bInitDone( sal_False )
- {}
-
- ~ContentBroker_Impl();
-
- bool initialize();
-
- const Reference< XMultiServiceFactory >& getServiceManager() const
- { return m_xSMgr; }
-
- const Reference< XContentIdentifierFactory >& getIdFactory() const
- { return m_xIdFac; }
-
- const Reference< XContentProvider >& getProvider() const
- { return m_xProvider; }
-
- const Reference< XContentProviderManager >& getProviderManager() const
- { return m_xProviderMgr; }
-
- const Reference< XCommandProcessor >& getCommandProcessor() const
- { return m_xCommandProc; }
-};
-
-//=========================================================================
-//=========================================================================
-//
-// ContentBroker Implementation.
-//
-//=========================================================================
-//=========================================================================
-
-// static member!
-ContentBroker* ContentBroker::m_pTheBroker = 0;
-
-//=========================================================================
-ContentBroker::ContentBroker( const Reference< XMultiServiceFactory >& rSMgr,
- const Sequence< Any >& rArguments )
-{
- m_pImpl = new ContentBroker_Impl( rSMgr, rArguments );
-}
-
-//=========================================================================
-ContentBroker::~ContentBroker()
-{
- delete m_pImpl;
-}
-
-//=========================================================================
-Reference< XMultiServiceFactory > ContentBroker::getServiceManager() const
-{
- return m_pImpl->getServiceManager();
-}
-
-//=========================================================================
-Reference< XContentIdentifierFactory >
- ContentBroker::getContentIdentifierFactoryInterface() const
-{
- return m_pImpl->getIdFactory();
-}
-
-//=========================================================================
-Reference< XContentProvider >
- ContentBroker::getContentProviderInterface() const
-{
- return m_pImpl->getProvider();
-}
-
-//=========================================================================
-Reference< XContentProviderManager >
- ContentBroker::getContentProviderManagerInterface() const
-{
- return m_pImpl->getProviderManager();
-}
-
-//=========================================================================
-Reference< XCommandProcessor >
- ContentBroker::getCommandProcessorInterface() const
-{
- return m_pImpl->getCommandProcessor();
-}
-
-//=========================================================================
-// static
-sal_Bool ContentBroker::initialize(
- const Reference< XMultiServiceFactory >& rSMgr,
- const Sequence< Any >& rArguments )
-{
- OSL_ENSURE( !m_pTheBroker,
- "ContentBroker::initialize - already initialized!" );
-
- if ( !m_pTheBroker )
- {
- osl::Guard< osl::Mutex > aGuard( theContentBrokerMutex::get() );
-
- if ( !m_pTheBroker )
- {
- ContentBroker * pBroker = new ContentBroker( rSMgr, rArguments );
-
- // Force init to be able to detect UCB init trouble immediately.
- if ( pBroker->m_pImpl->initialize() )
- m_pTheBroker = pBroker;
- else
- delete pBroker;
- }
- }
-
- return m_pTheBroker != 0;
-}
-
-#ifdef ANDROID
-
+//TODO: Is this relevant still?
extern "C" __attribute__ ((visibility("default"))) void
InitUCBHelper()
{
- Reference< XMultiServiceFactory > xFactory;
+ Reference< XComponentContext > xCtx;
try
{
Reference< XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
- xFactory = Reference< XMultiServiceFactory >( xCtx->getServiceManager(),
- UNO_QUERY );
}
catch( Exception& )
{
@@ -217,169 +48,11 @@ InitUCBHelper()
exit( 1 );
}
- // Create UCB.
- Sequence< Any > aArgs( 2 );
- aArgs[ 0 ] <<= rtl::OUString( UCB_CONFIGURATION_KEY1_LOCAL );
- aArgs[ 1 ] <<= rtl::OUString( UCB_CONFIGURATION_KEY2_OFFICE );
- ::ucbhelper::ContentBroker::initialize( xFactory, aArgs );
+ // Create UCB (for backwards compatibility, in case some code still uses
+ // plain createInstance w/o args directly to obtain an instance):
+ UniversalContentBroker::create( xCtx );
}
#endif
-//=========================================================================
-// static
-void ContentBroker::deinitialize()
-{
- osl::MutexGuard aGuard( theContentBrokerMutex::get() );
-
- delete m_pTheBroker;
- m_pTheBroker = 0;
-}
-
-//=========================================================================
-// static
-ContentBroker* ContentBroker::get()
-{
- return m_pTheBroker;
-}
-
-//=========================================================================
-//=========================================================================
-//
-// ContentBroker_Impl Implementation.
-//
-//=========================================================================
-//=========================================================================
-
-ContentBroker_Impl::~ContentBroker_Impl()
-{
- Reference< XComponent > xComponent( m_xProvider, UNO_QUERY );
- if ( xComponent.is() )
- {
- m_xIdFac = 0;
- m_xProvider = 0;
- m_xProviderMgr = 0;
-
- xComponent->dispose();
- }
-}
-
-//=========================================================================
-bool ContentBroker_Impl::initialize()
-{
- if ( !m_bInitDone )
- {
- osl::MutexGuard aGuard( m_aMutex );
-
- if ( !m_bInitDone )
- {
- Reference< XInterface > xIfc;
-
- if ( m_aProvData.size() > 0 )
- {
- try
- {
- xIfc = m_xSMgr->createInstance(
- OUString(
- "com.sun.star.ucb.UniversalContentBroker" ) );
- }
- catch ( Exception const & )
- {
- }
-
- if ( xIfc.is() )
- {
- m_xProviderMgr
- = Reference< XContentProviderManager >( xIfc, UNO_QUERY );
-
- if ( m_xProviderMgr.is() )
- {
- ContentProviderDataList::const_iterator aEnd(m_aProvData.end());
- for (ContentProviderDataList::const_iterator aIt(m_aProvData.begin());
- aIt != aEnd; ++aIt)
- {
- registerAtUcb(m_xProviderMgr,
- m_xSMgr,
- aIt->ServiceName,
- aIt->Arguments,
- aIt->URLTemplate,
- 0);
- }
-
- }
- }
- }
- else
- {
- try
- {
- Reference< XPropertySet > xFactoryProperties( m_xSMgr, UNO_QUERY_THROW );
- Reference< XComponentContext > xContext( xFactoryProperties->getPropertyValue( "DefaultContext" ), UNO_QUERY_THROW );
- if( m_aArguments.getLength() == 0 )
- xIfc = UniversalContentBroker::createDefault(xContext);
- else
- {
- rtl::OUString aPrimaryConfigKey, aSecondaryConfigKey;
- m_aArguments[0] >>= aPrimaryConfigKey;
- m_aArguments[1] >>= aSecondaryConfigKey;
- xIfc = UniversalContentBroker::createWithKeys(xContext, aPrimaryConfigKey, aSecondaryConfigKey);
- }
- }
- catch ( const Exception & e)
- {
- SAL_WARN("ucbhelper", "exception while initialising UniversalContentBroker " << e.Message);
- }
- }
-
- OSL_ENSURE( xIfc.is(), "Error creating UCB service 'com.sun.star.ucb.UniversalContentBroker'" );
-
- if ( !xIfc.is() )
- return false;
-
-
- m_xIdFac
- = Reference< XContentIdentifierFactory >( xIfc, UNO_QUERY );
-
- OSL_ENSURE( m_xIdFac.is(),
- "UCB without required interface XContentIdentifierFactory!" );
-
- if ( !m_xIdFac.is() )
- return false;
-
- m_xProvider = Reference< XContentProvider >( xIfc, UNO_QUERY );
-
- OSL_ENSURE( m_xProvider.is(),
- "UCB without required interface XContentProvider!" );
-
- if ( !m_xProvider.is() )
- return false;
-
- if ( !m_xProviderMgr.is() )
- m_xProviderMgr
- = Reference< XContentProviderManager >( xIfc, UNO_QUERY );
-
- OSL_ENSURE( m_xProviderMgr.is(),
- "UCB without required interface XContentProviderManager!" );
-
- if ( !m_xProviderMgr.is() )
- return false;
-
- m_xCommandProc = Reference< XCommandProcessor >( xIfc, UNO_QUERY );
-
- OSL_ENSURE( m_xCommandProc.is(),
- "UCB without required interface XCommandProcessor!" );
-
- if ( !m_xCommandProc.is() )
- return false;
-
- // Everything okay.
- m_bInitDone = sal_True;
- }
- }
-
- return true;
-}
-
-} /* namespace ucbhelper */
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucbhelper/source/client/fileidentifierconverter.cxx b/ucbhelper/source/client/fileidentifierconverter.cxx
index 3771d0d3c20e..4e0e28850b03 100644
--- a/ucbhelper/source/client/fileidentifierconverter.cxx
+++ b/ucbhelper/source/client/fileidentifierconverter.cxx
@@ -19,8 +19,8 @@
#include <ucbhelper/fileidentifierconverter.hxx>
#include <com/sun/star/ucb/ContentProviderInfo.hpp>
-#include <com/sun/star/ucb/XContentProviderManager.hpp>
#include <com/sun/star/ucb/XFileIdentifierConverter.hpp>
+#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <osl/diagnose.h>
@@ -55,15 +55,15 @@ getLocalFileURL() SAL_THROW((uno::RuntimeException))
rtl::OUString
getFileURLFromSystemPath(
- uno::Reference< ucb::XContentProviderManager > const & rManager,
+ uno::Reference< ucb::XUniversalContentBroker > const & rUcb,
rtl::OUString const & rBaseURL,
rtl::OUString const & rSystemPath)
SAL_THROW((uno::RuntimeException))
{
- OSL_ASSERT(rManager.is());
+ OSL_ASSERT(rUcb.is());
uno::Reference< ucb::XFileIdentifierConverter >
- xConverter(rManager->queryContentProvider(rBaseURL), uno::UNO_QUERY);
+ xConverter(rUcb->queryContentProvider(rBaseURL), uno::UNO_QUERY);
if (xConverter.is())
return xConverter->getFileURLFromSystemPath(rBaseURL, rSystemPath);
else
@@ -78,14 +78,14 @@ getFileURLFromSystemPath(
rtl::OUString
getSystemPathFromFileURL(
- uno::Reference< ucb::XContentProviderManager > const & rManager,
+ uno::Reference< ucb::XUniversalContentBroker > const & rUcb,
rtl::OUString const & rURL)
SAL_THROW((uno::RuntimeException))
{
- OSL_ASSERT(rManager.is());
+ OSL_ASSERT(rUcb.is());
uno::Reference< ucb::XFileIdentifierConverter >
- xConverter(rManager->queryContentProvider(rURL), uno::UNO_QUERY);
+ xConverter(rUcb->queryContentProvider(rURL), uno::UNO_QUERY);
if (xConverter.is())
return xConverter->getSystemPathFromFileURL(rURL);
else