1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_ucb.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir /************************************************************************** 32*cdf0e10cSrcweir TODO 33*cdf0e10cSrcweir ************************************************************************** 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir *************************************************************************/ 36*cdf0e10cSrcweir #include <osl/diagnose.h> 37*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 38*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/ucb/GlobalTransferCommandArgument.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProvider.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProviderSupplier.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/ucb/XParameterizedContentProvider.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProviderFactory.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 49*cdf0e10cSrcweir #include <ucbhelper/cancelcommandexecution.hxx> 50*cdf0e10cSrcweir #include "identify.hxx" 51*cdf0e10cSrcweir #include "ucbcmds.hxx" 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir #include "ucb.hxx" 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir // Definitions for ProviderMap_Impl (Solaris wouldn't find explicit template 56*cdf0e10cSrcweir // instantiations for these in another compilation unit...): 57*cdf0e10cSrcweir #ifndef _UCB_REGEXPMAP_TPT_ 58*cdf0e10cSrcweir #include <regexpmap.tpt> 59*cdf0e10cSrcweir #endif 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir using namespace rtl; 62*cdf0e10cSrcweir using namespace cppu; 63*cdf0e10cSrcweir using namespace com::sun::star::uno; 64*cdf0e10cSrcweir using namespace com::sun::star::lang; 65*cdf0e10cSrcweir using namespace com::sun::star::ucb; 66*cdf0e10cSrcweir using namespace ucb_impl; 67*cdf0e10cSrcweir using namespace com::sun::star; 68*cdf0e10cSrcweir using namespace ucbhelper; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir #define CONFIG_CONTENTPROVIDERS_KEY \ 72*cdf0e10cSrcweir "/org.openoffice.ucb.Configuration/ContentProviders" 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir namespace { 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir bool fillPlaceholders(rtl::OUString const & rInput, 78*cdf0e10cSrcweir uno::Sequence< uno::Any > const & rReplacements, 79*cdf0e10cSrcweir rtl::OUString * pOutput) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir sal_Unicode const * p = rInput.getStr(); 82*cdf0e10cSrcweir sal_Unicode const * pEnd = p + rInput.getLength(); 83*cdf0e10cSrcweir sal_Unicode const * pCopy = p; 84*cdf0e10cSrcweir rtl::OUStringBuffer aBuffer; 85*cdf0e10cSrcweir while (p != pEnd) 86*cdf0e10cSrcweir switch (*p++) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir case '&': 89*cdf0e10cSrcweir if (pEnd - p >= 4 90*cdf0e10cSrcweir && p[0] == 'a' && p[1] == 'm' && p[2] == 'p' 91*cdf0e10cSrcweir && p[3] == ';') 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir aBuffer.append(pCopy, p - 1 - pCopy); 94*cdf0e10cSrcweir aBuffer.append(sal_Unicode('&')); 95*cdf0e10cSrcweir p += 4; 96*cdf0e10cSrcweir pCopy = p; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir else if (pEnd - p >= 3 99*cdf0e10cSrcweir && p[0] == 'l' && p[1] == 't' && p[2] == ';') 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir aBuffer.append(pCopy, p - 1 - pCopy); 102*cdf0e10cSrcweir aBuffer.append(sal_Unicode('<')); 103*cdf0e10cSrcweir p += 3; 104*cdf0e10cSrcweir pCopy = p; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir else if (pEnd - p >= 3 107*cdf0e10cSrcweir && p[0] == 'g' && p[1] == 't' && p[2] == ';') 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir aBuffer.append(pCopy, p - 1 - pCopy); 110*cdf0e10cSrcweir aBuffer.append(sal_Unicode('>')); 111*cdf0e10cSrcweir p += 3; 112*cdf0e10cSrcweir pCopy = p; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir break; 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir case '<': 117*cdf0e10cSrcweir sal_Unicode const * q = p; 118*cdf0e10cSrcweir while (q != pEnd && *q != '>') 119*cdf0e10cSrcweir ++q; 120*cdf0e10cSrcweir if (q == pEnd) 121*cdf0e10cSrcweir break; 122*cdf0e10cSrcweir rtl::OUString aKey(p, q - p); 123*cdf0e10cSrcweir rtl::OUString aValue; 124*cdf0e10cSrcweir bool bFound = false; 125*cdf0e10cSrcweir for (sal_Int32 i = 2; i + 1 < rReplacements.getLength(); 126*cdf0e10cSrcweir i += 2) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir rtl::OUString aReplaceKey; 129*cdf0e10cSrcweir if ((rReplacements[i] >>= aReplaceKey) 130*cdf0e10cSrcweir && aReplaceKey == aKey 131*cdf0e10cSrcweir && (rReplacements[i + 1] >>= aValue)) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir bFound = true; 134*cdf0e10cSrcweir break; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir if (!bFound) 138*cdf0e10cSrcweir return false; 139*cdf0e10cSrcweir aBuffer.append(pCopy, p - 1 - pCopy); 140*cdf0e10cSrcweir aBuffer.append(aValue); 141*cdf0e10cSrcweir p = q + 1; 142*cdf0e10cSrcweir pCopy = p; 143*cdf0e10cSrcweir break; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir aBuffer.append(pCopy, pEnd - pCopy); 146*cdf0e10cSrcweir *pOutput = aBuffer.makeStringAndClear(); 147*cdf0e10cSrcweir return true; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir void makeAndAppendXMLName( 151*cdf0e10cSrcweir rtl::OUStringBuffer & rBuffer, const rtl::OUString & rIn ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir sal_Int32 nCount = rIn.getLength(); 154*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir const sal_Unicode c = rIn.getStr()[ n ]; 157*cdf0e10cSrcweir switch ( c ) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir case '&': 160*cdf0e10cSrcweir rBuffer.appendAscii( "&" ); 161*cdf0e10cSrcweir break; 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir case '"': 164*cdf0e10cSrcweir rBuffer.appendAscii( """ ); 165*cdf0e10cSrcweir break; 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir case '\'': 168*cdf0e10cSrcweir rBuffer.appendAscii( "'" ); 169*cdf0e10cSrcweir break; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir case '<': 172*cdf0e10cSrcweir rBuffer.appendAscii( "<" ); 173*cdf0e10cSrcweir break; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir case '>': 176*cdf0e10cSrcweir rBuffer.appendAscii( ">" ); 177*cdf0e10cSrcweir break; 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir default: 180*cdf0e10cSrcweir rBuffer.append( c ); 181*cdf0e10cSrcweir break; 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir bool createContentProviderData( 187*cdf0e10cSrcweir const rtl::OUString & rProvider, 188*cdf0e10cSrcweir const uno::Reference< container::XHierarchicalNameAccess >& rxHierNameAccess, 189*cdf0e10cSrcweir ContentProviderData & rInfo) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir // Obtain service name. 192*cdf0e10cSrcweir rtl::OUStringBuffer aKeyBuffer (rProvider); 193*cdf0e10cSrcweir aKeyBuffer.appendAscii( "/ServiceName" ); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir rtl::OUString aValue; 196*cdf0e10cSrcweir try 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir if ( !( rxHierNameAccess->getByHierarchicalName( 199*cdf0e10cSrcweir aKeyBuffer.makeStringAndClear() ) >>= aValue ) ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir OSL_ENSURE( false, 202*cdf0e10cSrcweir "UniversalContentBroker::getContentProviderData - " 203*cdf0e10cSrcweir "Error getting item value!" ); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir catch (container::NoSuchElementException &) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir return false; 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir rInfo.ServiceName = aValue; 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir // Obtain URL Template. 214*cdf0e10cSrcweir aKeyBuffer.append(rProvider); 215*cdf0e10cSrcweir aKeyBuffer.appendAscii( "/URLTemplate" ); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir if ( !( rxHierNameAccess->getByHierarchicalName( 218*cdf0e10cSrcweir aKeyBuffer.makeStringAndClear() ) >>= aValue ) ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir OSL_ENSURE( false, 221*cdf0e10cSrcweir "UniversalContentBroker::getContentProviderData - " 222*cdf0e10cSrcweir "Error getting item value!" ); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir rInfo.URLTemplate = aValue; 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir // Obtain Arguments. 228*cdf0e10cSrcweir aKeyBuffer.append(rProvider); 229*cdf0e10cSrcweir aKeyBuffer.appendAscii( "/Arguments" ); 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir if ( !( rxHierNameAccess->getByHierarchicalName( 232*cdf0e10cSrcweir aKeyBuffer.makeStringAndClear() ) >>= aValue ) ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir OSL_ENSURE( false, 235*cdf0e10cSrcweir "UniversalContentBroker::getContentProviderData - " 236*cdf0e10cSrcweir "Error getting item value!" ); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir rInfo.Arguments = aValue; 240*cdf0e10cSrcweir return true; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir //========================================================================= 246*cdf0e10cSrcweir // 247*cdf0e10cSrcweir // UniversalContentBroker Implementation. 248*cdf0e10cSrcweir // 249*cdf0e10cSrcweir //========================================================================= 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir UniversalContentBroker::UniversalContentBroker( 252*cdf0e10cSrcweir const Reference< com::sun::star::lang::XMultiServiceFactory >& rXSMgr ) 253*cdf0e10cSrcweir : m_xSMgr( rXSMgr ), 254*cdf0e10cSrcweir m_pDisposeEventListeners( NULL ), 255*cdf0e10cSrcweir m_nInitCount( 0 ), //@@@ see initialize() method 256*cdf0e10cSrcweir m_nCommandId( 0 ) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir OSL_ENSURE( m_xSMgr.is(), 259*cdf0e10cSrcweir "UniversalContentBroker ctor: No service manager" ); 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir //========================================================================= 263*cdf0e10cSrcweir // virtual 264*cdf0e10cSrcweir UniversalContentBroker::~UniversalContentBroker() 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir delete m_pDisposeEventListeners; 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir //========================================================================= 270*cdf0e10cSrcweir // 271*cdf0e10cSrcweir // XInterface methods. 272*cdf0e10cSrcweir // 273*cdf0e10cSrcweir //========================================================================= 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir XINTERFACE_IMPL_8( UniversalContentBroker, 276*cdf0e10cSrcweir XTypeProvider, 277*cdf0e10cSrcweir XComponent, 278*cdf0e10cSrcweir XServiceInfo, 279*cdf0e10cSrcweir XInitialization, 280*cdf0e10cSrcweir XContentProviderManager, 281*cdf0e10cSrcweir XContentProvider, 282*cdf0e10cSrcweir XContentIdentifierFactory, 283*cdf0e10cSrcweir XCommandProcessor ); 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir //========================================================================= 286*cdf0e10cSrcweir // 287*cdf0e10cSrcweir // XTypeProvider methods. 288*cdf0e10cSrcweir // 289*cdf0e10cSrcweir //========================================================================= 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir XTYPEPROVIDER_IMPL_8( UniversalContentBroker, 292*cdf0e10cSrcweir XTypeProvider, 293*cdf0e10cSrcweir XComponent, 294*cdf0e10cSrcweir XServiceInfo, 295*cdf0e10cSrcweir XInitialization, 296*cdf0e10cSrcweir XContentProviderManager, 297*cdf0e10cSrcweir XContentProvider, 298*cdf0e10cSrcweir XContentIdentifierFactory, 299*cdf0e10cSrcweir XCommandProcessor ); 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir //========================================================================= 302*cdf0e10cSrcweir // 303*cdf0e10cSrcweir // XComponent methods. 304*cdf0e10cSrcweir // 305*cdf0e10cSrcweir //========================================================================= 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir // virtual 308*cdf0e10cSrcweir void SAL_CALL UniversalContentBroker::dispose() 309*cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir EventObject aEvt; 314*cdf0e10cSrcweir aEvt.Source = SAL_STATIC_CAST( XComponent*, this ); 315*cdf0e10cSrcweir m_pDisposeEventListeners->disposeAndClear( aEvt ); 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir if ( m_xNotifier.is() ) 319*cdf0e10cSrcweir m_xNotifier->removeChangesListener( this ); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir //========================================================================= 323*cdf0e10cSrcweir // virtual 324*cdf0e10cSrcweir void SAL_CALL UniversalContentBroker::addEventListener( 325*cdf0e10cSrcweir const Reference< XEventListener >& Listener ) 326*cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ) 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir if ( !m_pDisposeEventListeners ) 329*cdf0e10cSrcweir m_pDisposeEventListeners = new OInterfaceContainerHelper( m_aMutex ); 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir m_pDisposeEventListeners->addInterface( Listener ); 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir //========================================================================= 335*cdf0e10cSrcweir // virtual 336*cdf0e10cSrcweir void SAL_CALL UniversalContentBroker::removeEventListener( 337*cdf0e10cSrcweir const Reference< XEventListener >& Listener ) 338*cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir if ( m_pDisposeEventListeners ) 341*cdf0e10cSrcweir m_pDisposeEventListeners->removeInterface( Listener ); 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir // Note: Don't want to delete empty container here -> performance. 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir //========================================================================= 347*cdf0e10cSrcweir // 348*cdf0e10cSrcweir // XServiceInfo methods. 349*cdf0e10cSrcweir // 350*cdf0e10cSrcweir //========================================================================= 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir XSERVICEINFO_IMPL_1( UniversalContentBroker, 353*cdf0e10cSrcweir OUString::createFromAscii( 354*cdf0e10cSrcweir "com.sun.star.comp.ucb.UniversalContentBroker" ), 355*cdf0e10cSrcweir OUString::createFromAscii( 356*cdf0e10cSrcweir UCB_SERVICE_NAME ) ); 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir //========================================================================= 359*cdf0e10cSrcweir // 360*cdf0e10cSrcweir // Service factory implementation. 361*cdf0e10cSrcweir // 362*cdf0e10cSrcweir //========================================================================= 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( UniversalContentBroker ); 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir //========================================================================= 367*cdf0e10cSrcweir // 368*cdf0e10cSrcweir // XInitialization methods. 369*cdf0e10cSrcweir // 370*cdf0e10cSrcweir //========================================================================= 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir // virtual 373*cdf0e10cSrcweir void SAL_CALL UniversalContentBroker::initialize( 374*cdf0e10cSrcweir const com::sun::star::uno::Sequence< Any >& aArguments ) 375*cdf0e10cSrcweir throw( com::sun::star::uno::Exception, 376*cdf0e10cSrcweir com::sun::star::uno::RuntimeException ) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir //@@@ At the moment, there's a problem when one (non-one-instance) factory 379*cdf0e10cSrcweir // 'wraps' another (one-instance) factory, causing this method to be 380*cdf0e10cSrcweir // called several times: 381*cdf0e10cSrcweir m_aArguments = aArguments; 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir oslInterlockedCount nCount = osl_incrementInterlockedCount(&m_nInitCount); 384*cdf0e10cSrcweir if (nCount == 1) 385*cdf0e10cSrcweir configureUcb(); 386*cdf0e10cSrcweir else 387*cdf0e10cSrcweir osl_decrementInterlockedCount(&m_nInitCount); 388*cdf0e10cSrcweir // make the possibility of overflow less likely... 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir //========================================================================= 392*cdf0e10cSrcweir // 393*cdf0e10cSrcweir // XContentProviderManager methods. 394*cdf0e10cSrcweir // 395*cdf0e10cSrcweir //========================================================================= 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir // virtual 398*cdf0e10cSrcweir Reference< XContentProvider > SAL_CALL 399*cdf0e10cSrcweir UniversalContentBroker::registerContentProvider( 400*cdf0e10cSrcweir const Reference< XContentProvider >& Provider, 401*cdf0e10cSrcweir const OUString& Scheme, 402*cdf0e10cSrcweir sal_Bool ReplaceExisting ) 403*cdf0e10cSrcweir throw( DuplicateProviderException, com::sun::star::uno::RuntimeException ) 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir ProviderMap_Impl::iterator aIt; 408*cdf0e10cSrcweir try 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir aIt = m_aProviders.find(Scheme); 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir catch (IllegalArgumentException const &) 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir return 0; //@@@ 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir Reference< XContentProvider > xPrevious; 418*cdf0e10cSrcweir if (aIt == m_aProviders.end()) 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir ProviderList_Impl aList; 421*cdf0e10cSrcweir aList.push_front(Provider); 422*cdf0e10cSrcweir try 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir m_aProviders.add(Scheme, aList, false); 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir catch (IllegalArgumentException const &) 427*cdf0e10cSrcweir { 428*cdf0e10cSrcweir return 0; //@@@ 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir else 432*cdf0e10cSrcweir { 433*cdf0e10cSrcweir if (!ReplaceExisting) 434*cdf0e10cSrcweir throw DuplicateProviderException(); 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir ProviderList_Impl & rList = aIt->getValue(); 437*cdf0e10cSrcweir xPrevious = rList.front().getProvider(); 438*cdf0e10cSrcweir rList.push_front(Provider); 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir return xPrevious; 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir //========================================================================= 445*cdf0e10cSrcweir // virtual 446*cdf0e10cSrcweir void SAL_CALL UniversalContentBroker::deregisterContentProvider( 447*cdf0e10cSrcweir const Reference< XContentProvider >& Provider, 448*cdf0e10cSrcweir const OUString& Scheme ) 449*cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ) 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir ProviderMap_Impl::iterator aMapIt; 454*cdf0e10cSrcweir try 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir aMapIt = m_aProviders.find(Scheme); 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir catch (IllegalArgumentException const &) 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir return; //@@@ 461*cdf0e10cSrcweir } 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir if (aMapIt != m_aProviders.end()) 464*cdf0e10cSrcweir { 465*cdf0e10cSrcweir ProviderList_Impl & rList = aMapIt->getValue(); 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir ProviderList_Impl::iterator aListEnd(rList.end()); 468*cdf0e10cSrcweir for (ProviderList_Impl::iterator aListIt(rList.begin()); 469*cdf0e10cSrcweir aListIt != aListEnd; ++aListIt) 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir if ((*aListIt).getProvider() == Provider) 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir rList.erase(aListIt); 474*cdf0e10cSrcweir break; 475*cdf0e10cSrcweir } 476*cdf0e10cSrcweir } 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir if (rList.empty()) 479*cdf0e10cSrcweir m_aProviders.erase(aMapIt); 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir //========================================================================= 484*cdf0e10cSrcweir // virtual 485*cdf0e10cSrcweir com::sun::star::uno::Sequence< ContentProviderInfo > SAL_CALL 486*cdf0e10cSrcweir UniversalContentBroker::queryContentProviders() 487*cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ) 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir // Return a list with information about active(!) content providers. 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir com::sun::star::uno::Sequence< ContentProviderInfo > aSeq( 494*cdf0e10cSrcweir m_aProviders.size() ); 495*cdf0e10cSrcweir ContentProviderInfo* pInfo = aSeq.getArray(); 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir ProviderMap_Impl::const_iterator end = m_aProviders.end(); 498*cdf0e10cSrcweir for (ProviderMap_Impl::const_iterator it(m_aProviders.begin()); it != end; 499*cdf0e10cSrcweir ++it) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir // Note: Active provider is always the first list element. 502*cdf0e10cSrcweir pInfo->ContentProvider = it->getValue().front().getProvider(); 503*cdf0e10cSrcweir pInfo->Scheme = it->getRegexp(); 504*cdf0e10cSrcweir ++pInfo; 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir return aSeq; 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir //========================================================================= 511*cdf0e10cSrcweir // virtual 512*cdf0e10cSrcweir Reference< XContentProvider > SAL_CALL 513*cdf0e10cSrcweir UniversalContentBroker::queryContentProvider( const OUString& 514*cdf0e10cSrcweir Identifier ) 515*cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ) 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir return queryContentProvider( Identifier, sal_False ); 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir //========================================================================= 521*cdf0e10cSrcweir // 522*cdf0e10cSrcweir // XContentProvider methods. 523*cdf0e10cSrcweir // 524*cdf0e10cSrcweir //========================================================================= 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir // virtual 527*cdf0e10cSrcweir Reference< XContent > SAL_CALL UniversalContentBroker::queryContent( 528*cdf0e10cSrcweir const Reference< XContentIdentifier >& Identifier ) 529*cdf0e10cSrcweir throw( IllegalIdentifierException, com::sun::star::uno::RuntimeException ) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 532*cdf0e10cSrcweir // Let the content provider for the scheme given with the content 533*cdf0e10cSrcweir // identifier create the XContent instance. 534*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir if ( !Identifier.is() ) 537*cdf0e10cSrcweir return Reference< XContent >(); 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir Reference< XContentProvider > xProv = 540*cdf0e10cSrcweir queryContentProvider( Identifier->getContentIdentifier(), sal_True ); 541*cdf0e10cSrcweir if ( xProv.is() ) 542*cdf0e10cSrcweir return xProv->queryContent( Identifier ); 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir return Reference< XContent >(); 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir //========================================================================= 548*cdf0e10cSrcweir // virtual 549*cdf0e10cSrcweir sal_Int32 SAL_CALL UniversalContentBroker::compareContentIds( 550*cdf0e10cSrcweir const Reference< XContentIdentifier >& Id1, 551*cdf0e10cSrcweir const Reference< XContentIdentifier >& Id2 ) 552*cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ) 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir OUString aURI1( Id1->getContentIdentifier() ); 555*cdf0e10cSrcweir OUString aURI2( Id2->getContentIdentifier() ); 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir Reference< XContentProvider > xProv1 558*cdf0e10cSrcweir = queryContentProvider( aURI1, sal_True ); 559*cdf0e10cSrcweir Reference< XContentProvider > xProv2 560*cdf0e10cSrcweir = queryContentProvider( aURI2, sal_True ); 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir // When both identifiers belong to the same provider, let that provider 563*cdf0e10cSrcweir // compare them; otherwise, simply compare the URI strings (which must 564*cdf0e10cSrcweir // be different): 565*cdf0e10cSrcweir if ( xProv1.is() && ( xProv1 == xProv2 ) ) 566*cdf0e10cSrcweir return xProv1->compareContentIds( Id1, Id2 ); 567*cdf0e10cSrcweir else 568*cdf0e10cSrcweir return aURI1.compareTo( aURI2 ); 569*cdf0e10cSrcweir } 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir //========================================================================= 572*cdf0e10cSrcweir // 573*cdf0e10cSrcweir // XContentIdentifierFactory methods. 574*cdf0e10cSrcweir // 575*cdf0e10cSrcweir //========================================================================= 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir // virtual 578*cdf0e10cSrcweir Reference< XContentIdentifier > SAL_CALL 579*cdf0e10cSrcweir UniversalContentBroker::createContentIdentifier( 580*cdf0e10cSrcweir const OUString& ContentId ) 581*cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ) 582*cdf0e10cSrcweir { 583*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 584*cdf0e10cSrcweir // Let the content provider for the scheme given with content 585*cdf0e10cSrcweir // identifier create the XContentIdentifier instance, if he supports 586*cdf0e10cSrcweir // the XContentIdentifierFactory interface. Otherwise create standard 587*cdf0e10cSrcweir // implementation object for XContentIdentifier. 588*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 589*cdf0e10cSrcweir 590*cdf0e10cSrcweir Reference< XContentIdentifier > xIdentifier; 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir Reference< XContentProvider > xProv 593*cdf0e10cSrcweir = queryContentProvider( ContentId, sal_True ); 594*cdf0e10cSrcweir if ( xProv.is() ) 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir Reference< XContentIdentifierFactory > xFac( xProv, UNO_QUERY ); 597*cdf0e10cSrcweir if ( xFac.is() ) 598*cdf0e10cSrcweir xIdentifier = xFac->createContentIdentifier( ContentId ); 599*cdf0e10cSrcweir } 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir if ( !xIdentifier.is() ) 602*cdf0e10cSrcweir xIdentifier = new ContentIdentifier( m_xSMgr, ContentId ); 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir return xIdentifier; 605*cdf0e10cSrcweir } 606*cdf0e10cSrcweir 607*cdf0e10cSrcweir //========================================================================= 608*cdf0e10cSrcweir // 609*cdf0e10cSrcweir // XCommandProcessor methods. 610*cdf0e10cSrcweir // 611*cdf0e10cSrcweir //========================================================================= 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir // virtual 614*cdf0e10cSrcweir sal_Int32 SAL_CALL UniversalContentBroker::createCommandIdentifier() 615*cdf0e10cSrcweir throw( RuntimeException ) 616*cdf0e10cSrcweir { 617*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir // Just increase counter on every call to generate an identifier. 620*cdf0e10cSrcweir return ++m_nCommandId; 621*cdf0e10cSrcweir } 622*cdf0e10cSrcweir 623*cdf0e10cSrcweir //========================================================================= 624*cdf0e10cSrcweir // virtual 625*cdf0e10cSrcweir Any SAL_CALL UniversalContentBroker::execute( 626*cdf0e10cSrcweir const Command& aCommand, 627*cdf0e10cSrcweir sal_Int32, 628*cdf0e10cSrcweir const Reference< XCommandEnvironment >& Environment ) 629*cdf0e10cSrcweir throw( Exception, CommandAbortedException, RuntimeException ) 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir Any aRet; 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 634*cdf0e10cSrcweir // Note: Don't forget to adapt ucb_commands::CommandProcessorInfo 635*cdf0e10cSrcweir // ctor in ucbcmds.cxx when adding new commands! 636*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 637*cdf0e10cSrcweir 638*cdf0e10cSrcweir if ( ( aCommand.Handle == GETCOMMANDINFO_HANDLE ) || 639*cdf0e10cSrcweir aCommand.Name.equalsAsciiL( 640*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( GETCOMMANDINFO_NAME ) ) ) 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 643*cdf0e10cSrcweir // getCommandInfo 644*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir aRet <<= getCommandInfo(); 647*cdf0e10cSrcweir } 648*cdf0e10cSrcweir else if ( ( aCommand.Handle == GLOBALTRANSFER_HANDLE ) || 649*cdf0e10cSrcweir aCommand.Name.equalsAsciiL( 650*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM(GLOBALTRANSFER_NAME ) ) ) 651*cdf0e10cSrcweir { 652*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 653*cdf0e10cSrcweir // globalTransfer 654*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir GlobalTransferCommandArgument aTransferArg; 657*cdf0e10cSrcweir if ( !( aCommand.Argument >>= aTransferArg ) ) 658*cdf0e10cSrcweir { 659*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 660*cdf0e10cSrcweir makeAny( IllegalArgumentException( 661*cdf0e10cSrcweir rtl::OUString::createFromAscii( 662*cdf0e10cSrcweir "Wrong argument type!" ), 663*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 664*cdf0e10cSrcweir -1 ) ), 665*cdf0e10cSrcweir Environment ); 666*cdf0e10cSrcweir // Unreachable 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir globalTransfer( aTransferArg, Environment ); 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir else 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 674*cdf0e10cSrcweir // Unknown command 675*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 676*cdf0e10cSrcweir 677*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 678*cdf0e10cSrcweir makeAny( UnsupportedCommandException( 679*cdf0e10cSrcweir rtl::OUString(), 680*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ), 681*cdf0e10cSrcweir Environment ); 682*cdf0e10cSrcweir // Unreachable 683*cdf0e10cSrcweir } 684*cdf0e10cSrcweir 685*cdf0e10cSrcweir return aRet; 686*cdf0e10cSrcweir } 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir //========================================================================= 689*cdf0e10cSrcweir // virtual 690*cdf0e10cSrcweir void SAL_CALL UniversalContentBroker::abort( sal_Int32 ) 691*cdf0e10cSrcweir throw( RuntimeException ) 692*cdf0e10cSrcweir { 693*cdf0e10cSrcweir // @@@ Not implemeted ( yet). 694*cdf0e10cSrcweir } 695*cdf0e10cSrcweir 696*cdf0e10cSrcweir //========================================================================= 697*cdf0e10cSrcweir // 698*cdf0e10cSrcweir // XChangesListener methods 699*cdf0e10cSrcweir // 700*cdf0e10cSrcweir //========================================================================= 701*cdf0e10cSrcweir // virtual 702*cdf0e10cSrcweir void SAL_CALL UniversalContentBroker::changesOccurred( const util::ChangesEvent& Event ) 703*cdf0e10cSrcweir throw( uno::RuntimeException ) 704*cdf0e10cSrcweir { 705*cdf0e10cSrcweir sal_Int32 nCount = Event.Changes.getLength(); 706*cdf0e10cSrcweir if ( nCount ) 707*cdf0e10cSrcweir { 708*cdf0e10cSrcweir uno::Reference< container::XHierarchicalNameAccess > xHierNameAccess; 709*cdf0e10cSrcweir Event.Base >>= xHierNameAccess; 710*cdf0e10cSrcweir 711*cdf0e10cSrcweir OSL_ASSERT( xHierNameAccess.is() ); 712*cdf0e10cSrcweir 713*cdf0e10cSrcweir const util::ElementChange* pElementChanges 714*cdf0e10cSrcweir = Event.Changes.getConstArray(); 715*cdf0e10cSrcweir 716*cdf0e10cSrcweir ContentProviderDataList aData; 717*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) 718*cdf0e10cSrcweir { 719*cdf0e10cSrcweir const util::ElementChange& rElem = pElementChanges[ n ]; 720*cdf0e10cSrcweir rtl::OUString aKey; 721*cdf0e10cSrcweir rElem.Accessor >>= aKey; 722*cdf0e10cSrcweir 723*cdf0e10cSrcweir ContentProviderData aInfo; 724*cdf0e10cSrcweir 725*cdf0e10cSrcweir // Removal of UCPs from the configuration leads to changesOccurred 726*cdf0e10cSrcweir // notifications, too, but it is hard to tell for a given 727*cdf0e10cSrcweir // ElementChange whether it is an addition or a removal, so as a 728*cdf0e10cSrcweir // heuristic consider as removals those that cause a 729*cdf0e10cSrcweir // NoSuchElementException in createContentProviderData. 730*cdf0e10cSrcweir // 731*cdf0e10cSrcweir // For now, removal of UCPs from the configuration is simply ignored 732*cdf0e10cSrcweir // (and not reflected in the UCB's data structures): 733*cdf0e10cSrcweir if (createContentProviderData(aKey, xHierNameAccess, aInfo)) 734*cdf0e10cSrcweir { 735*cdf0e10cSrcweir aData.push_back(aInfo); 736*cdf0e10cSrcweir } 737*cdf0e10cSrcweir } 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir prepareAndRegister(aData); 740*cdf0e10cSrcweir } 741*cdf0e10cSrcweir } 742*cdf0e10cSrcweir 743*cdf0e10cSrcweir //========================================================================= 744*cdf0e10cSrcweir // 745*cdf0e10cSrcweir // XEventListener methods 746*cdf0e10cSrcweir // 747*cdf0e10cSrcweir //========================================================================= 748*cdf0e10cSrcweir // virtual 749*cdf0e10cSrcweir void SAL_CALL UniversalContentBroker::disposing(const lang::EventObject&) 750*cdf0e10cSrcweir throw( uno::RuntimeException ) 751*cdf0e10cSrcweir { 752*cdf0e10cSrcweir if ( m_xNotifier.is() ) 753*cdf0e10cSrcweir { 754*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 755*cdf0e10cSrcweir 756*cdf0e10cSrcweir if ( m_xNotifier.is() ) 757*cdf0e10cSrcweir m_xNotifier.clear(); 758*cdf0e10cSrcweir } 759*cdf0e10cSrcweir } 760*cdf0e10cSrcweir 761*cdf0e10cSrcweir //========================================================================= 762*cdf0e10cSrcweir // 763*cdf0e10cSrcweir // Non-interface methods 764*cdf0e10cSrcweir // 765*cdf0e10cSrcweir //========================================================================= 766*cdf0e10cSrcweir 767*cdf0e10cSrcweir Reference< XContentProvider > UniversalContentBroker::queryContentProvider( 768*cdf0e10cSrcweir const OUString& Identifier, 769*cdf0e10cSrcweir sal_Bool bResolved ) 770*cdf0e10cSrcweir { 771*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir ProviderList_Impl const * pList = m_aProviders.map( Identifier ); 774*cdf0e10cSrcweir return pList ? bResolved ? pList->front().getResolvedProvider() 775*cdf0e10cSrcweir : pList->front().getProvider() 776*cdf0e10cSrcweir : Reference< XContentProvider >(); 777*cdf0e10cSrcweir } 778*cdf0e10cSrcweir 779*cdf0e10cSrcweir bool UniversalContentBroker::configureUcb() 780*cdf0e10cSrcweir throw (uno::RuntimeException) 781*cdf0e10cSrcweir { 782*cdf0e10cSrcweir rtl::OUString aKey1; 783*cdf0e10cSrcweir rtl::OUString aKey2; 784*cdf0e10cSrcweir if (m_aArguments.getLength() < 2 785*cdf0e10cSrcweir || !(m_aArguments[0] >>= aKey1) || !(m_aArguments[1] >>= aKey2)) 786*cdf0e10cSrcweir { 787*cdf0e10cSrcweir OSL_ENSURE(false, "UniversalContentBroker::configureUcb(): Bad arguments"); 788*cdf0e10cSrcweir return false; 789*cdf0e10cSrcweir } 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir ContentProviderDataList aData; 792*cdf0e10cSrcweir if (!getContentProviderData(aKey1, aKey2, aData)) 793*cdf0e10cSrcweir { 794*cdf0e10cSrcweir OSL_ENSURE(false, "UniversalContentBroker::configureUcb(): No configuration"); 795*cdf0e10cSrcweir return false; 796*cdf0e10cSrcweir } 797*cdf0e10cSrcweir 798*cdf0e10cSrcweir prepareAndRegister(aData); 799*cdf0e10cSrcweir 800*cdf0e10cSrcweir return true; 801*cdf0e10cSrcweir } 802*cdf0e10cSrcweir 803*cdf0e10cSrcweir void UniversalContentBroker::prepareAndRegister( 804*cdf0e10cSrcweir const ContentProviderDataList& rData) 805*cdf0e10cSrcweir { 806*cdf0e10cSrcweir ContentProviderDataList::const_iterator aEnd(rData.end()); 807*cdf0e10cSrcweir for (ContentProviderDataList::const_iterator aIt(rData.begin()); 808*cdf0e10cSrcweir aIt != aEnd; ++aIt) 809*cdf0e10cSrcweir { 810*cdf0e10cSrcweir rtl::OUString aProviderArguments; 811*cdf0e10cSrcweir if (fillPlaceholders(aIt->Arguments, 812*cdf0e10cSrcweir m_aArguments, 813*cdf0e10cSrcweir &aProviderArguments)) 814*cdf0e10cSrcweir { 815*cdf0e10cSrcweir registerAtUcb(this, 816*cdf0e10cSrcweir m_xSMgr, 817*cdf0e10cSrcweir aIt->ServiceName, 818*cdf0e10cSrcweir aProviderArguments, 819*cdf0e10cSrcweir aIt->URLTemplate, 820*cdf0e10cSrcweir 0); 821*cdf0e10cSrcweir 822*cdf0e10cSrcweir } 823*cdf0e10cSrcweir else 824*cdf0e10cSrcweir OSL_ENSURE(false, 825*cdf0e10cSrcweir "UniversalContentBroker::prepareAndRegister(): Bad argument placeholders"); 826*cdf0e10cSrcweir } 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir 829*cdf0e10cSrcweir //========================================================================= 830*cdf0e10cSrcweir bool UniversalContentBroker::getContentProviderData( 831*cdf0e10cSrcweir const rtl::OUString & rKey1, 832*cdf0e10cSrcweir const rtl::OUString & rKey2, 833*cdf0e10cSrcweir ContentProviderDataList & rListToFill ) 834*cdf0e10cSrcweir { 835*cdf0e10cSrcweir if ( !m_xSMgr.is() || !rKey1.getLength() || !rKey2.getLength() ) 836*cdf0e10cSrcweir { 837*cdf0e10cSrcweir OSL_ENSURE( false, 838*cdf0e10cSrcweir "UniversalContentBroker::getContentProviderData - Invalid argument!" ); 839*cdf0e10cSrcweir return false; 840*cdf0e10cSrcweir } 841*cdf0e10cSrcweir 842*cdf0e10cSrcweir try 843*cdf0e10cSrcweir { 844*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xConfigProv( 845*cdf0e10cSrcweir m_xSMgr->createInstance( 846*cdf0e10cSrcweir rtl::OUString::createFromAscii( 847*cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationProvider" ) ), 848*cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 849*cdf0e10cSrcweir 850*cdf0e10cSrcweir rtl::OUStringBuffer aFullPath; 851*cdf0e10cSrcweir aFullPath.appendAscii( CONFIG_CONTENTPROVIDERS_KEY "/['" ); 852*cdf0e10cSrcweir makeAndAppendXMLName( aFullPath, rKey1 ); 853*cdf0e10cSrcweir aFullPath.appendAscii( "']/SecondaryKeys/['" ); 854*cdf0e10cSrcweir makeAndAppendXMLName( aFullPath, rKey2 ); 855*cdf0e10cSrcweir aFullPath.appendAscii( "']/ProviderData" ); 856*cdf0e10cSrcweir 857*cdf0e10cSrcweir uno::Sequence< uno::Any > aArguments( 1 ); 858*cdf0e10cSrcweir beans::PropertyValue aProperty; 859*cdf0e10cSrcweir aProperty.Name 860*cdf0e10cSrcweir = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); 861*cdf0e10cSrcweir aProperty.Value <<= aFullPath.makeStringAndClear(); 862*cdf0e10cSrcweir aArguments[ 0 ] <<= aProperty; 863*cdf0e10cSrcweir 864*cdf0e10cSrcweir uno::Reference< uno::XInterface > xInterface( 865*cdf0e10cSrcweir xConfigProv->createInstanceWithArguments( 866*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 867*cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationAccess" ) ), 868*cdf0e10cSrcweir aArguments ) ); 869*cdf0e10cSrcweir 870*cdf0e10cSrcweir if ( !m_xNotifier.is() ) 871*cdf0e10cSrcweir { 872*cdf0e10cSrcweir m_xNotifier = uno::Reference< util::XChangesNotifier >( 873*cdf0e10cSrcweir xInterface, uno::UNO_QUERY_THROW ); 874*cdf0e10cSrcweir 875*cdf0e10cSrcweir m_xNotifier->addChangesListener( this ); 876*cdf0e10cSrcweir } 877*cdf0e10cSrcweir 878*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNameAccess( 879*cdf0e10cSrcweir xInterface, uno::UNO_QUERY_THROW ); 880*cdf0e10cSrcweir 881*cdf0e10cSrcweir uno::Sequence< rtl::OUString > aElems = xNameAccess->getElementNames(); 882*cdf0e10cSrcweir const rtl::OUString* pElems = aElems.getConstArray(); 883*cdf0e10cSrcweir sal_Int32 nCount = aElems.getLength(); 884*cdf0e10cSrcweir 885*cdf0e10cSrcweir if ( nCount > 0 ) 886*cdf0e10cSrcweir { 887*cdf0e10cSrcweir uno::Reference< container::XHierarchicalNameAccess > 888*cdf0e10cSrcweir xHierNameAccess( xInterface, uno::UNO_QUERY_THROW ); 889*cdf0e10cSrcweir 890*cdf0e10cSrcweir // Iterate over children. 891*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) 892*cdf0e10cSrcweir { 893*cdf0e10cSrcweir 894*cdf0e10cSrcweir try 895*cdf0e10cSrcweir { 896*cdf0e10cSrcweir 897*cdf0e10cSrcweir ContentProviderData aInfo; 898*cdf0e10cSrcweir 899*cdf0e10cSrcweir rtl::OUStringBuffer aElemBuffer; 900*cdf0e10cSrcweir aElemBuffer.appendAscii( "['" ); 901*cdf0e10cSrcweir makeAndAppendXMLName( aElemBuffer, pElems[ n ] ); 902*cdf0e10cSrcweir aElemBuffer.appendAscii( "']" ); 903*cdf0e10cSrcweir 904*cdf0e10cSrcweir OSL_VERIFY( 905*cdf0e10cSrcweir createContentProviderData( 906*cdf0e10cSrcweir aElemBuffer.makeStringAndClear(), xHierNameAccess, 907*cdf0e10cSrcweir aInfo)); 908*cdf0e10cSrcweir 909*cdf0e10cSrcweir rListToFill.push_back( aInfo ); 910*cdf0e10cSrcweir } 911*cdf0e10cSrcweir catch ( container::NoSuchElementException& ) 912*cdf0e10cSrcweir { 913*cdf0e10cSrcweir // getByHierarchicalName 914*cdf0e10cSrcweir OSL_ENSURE( false, 915*cdf0e10cSrcweir "UniversalContentBroker::getContentProviderData - " 916*cdf0e10cSrcweir "caught NoSuchElementException!" ); 917*cdf0e10cSrcweir } 918*cdf0e10cSrcweir } 919*cdf0e10cSrcweir } 920*cdf0e10cSrcweir } 921*cdf0e10cSrcweir catch ( uno::RuntimeException& ) 922*cdf0e10cSrcweir { 923*cdf0e10cSrcweir OSL_ENSURE( false, 924*cdf0e10cSrcweir "UniversalContentBroker::getContentProviderData - caught RuntimeException!" ); 925*cdf0e10cSrcweir return false; 926*cdf0e10cSrcweir } 927*cdf0e10cSrcweir catch ( uno::Exception& ) 928*cdf0e10cSrcweir { 929*cdf0e10cSrcweir // createInstance, createInstanceWithArguments 930*cdf0e10cSrcweir 931*cdf0e10cSrcweir OSL_ENSURE( false, 932*cdf0e10cSrcweir "UniversalContentBroker::getContentProviderData - caught Exception!" ); 933*cdf0e10cSrcweir return false; 934*cdf0e10cSrcweir } 935*cdf0e10cSrcweir 936*cdf0e10cSrcweir return true; 937*cdf0e10cSrcweir } 938*cdf0e10cSrcweir 939*cdf0e10cSrcweir //========================================================================= 940*cdf0e10cSrcweir // 941*cdf0e10cSrcweir // ProviderListEntry_Impl implementation. 942*cdf0e10cSrcweir // 943*cdf0e10cSrcweir //========================================================================= 944*cdf0e10cSrcweir 945*cdf0e10cSrcweir Reference< XContentProvider > ProviderListEntry_Impl::resolveProvider() const 946*cdf0e10cSrcweir { 947*cdf0e10cSrcweir if ( !m_xResolvedProvider.is() ) 948*cdf0e10cSrcweir { 949*cdf0e10cSrcweir Reference< XContentProviderSupplier > xSupplier( 950*cdf0e10cSrcweir m_xProvider, UNO_QUERY ); 951*cdf0e10cSrcweir if ( xSupplier.is() ) 952*cdf0e10cSrcweir m_xResolvedProvider = xSupplier->getContentProvider(); 953*cdf0e10cSrcweir 954*cdf0e10cSrcweir if ( !m_xResolvedProvider.is() ) 955*cdf0e10cSrcweir m_xResolvedProvider = m_xProvider; 956*cdf0e10cSrcweir } 957*cdf0e10cSrcweir 958*cdf0e10cSrcweir return m_xResolvedProvider; 959*cdf0e10cSrcweir } 960