bump product version to 5.0.4.1
[LibreOffice.git] / ucb / source / core / ucb.cxx
blobda620349accb21ef6f90e698baa029c6724ead0a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 /**************************************************************************
22 TODO
23 **************************************************************************
25 *************************************************************************/
26 #include <osl/diagnose.h>
27 #include <comphelper/processfactory.hxx>
28 #include <cppuhelper/interfacecontainer.hxx>
29 #include <com/sun/star/lang/IllegalArgumentException.hpp>
30 #include <com/sun/star/ucb/GlobalTransferCommandArgument2.hpp>
31 #include <com/sun/star/ucb/XCommandInfo.hpp>
32 #include <com/sun/star/ucb/XContentProvider.hpp>
33 #include <com/sun/star/ucb/XContentProviderSupplier.hpp>
34 #include <com/sun/star/ucb/XParameterizedContentProvider.hpp>
35 #include <com/sun/star/ucb/XContentProviderFactory.hpp>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <com/sun/star/configuration/theDefaultProvider.hpp>
38 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
39 #include <com/sun/star/container/XNameAccess.hpp>
40 #include <com/sun/star/uno/Any.hxx>
41 #include <ucbhelper/cancelcommandexecution.hxx>
42 #include "identify.hxx"
43 #include "ucbcmds.hxx"
45 #include "ucb.hxx"
47 using namespace cppu;
48 using namespace com::sun::star::uno;
49 using namespace com::sun::star::lang;
50 using namespace com::sun::star::ucb;
51 using namespace ucb_impl;
52 using namespace com::sun::star;
53 using namespace ucbhelper;
56 #define CONFIG_CONTENTPROVIDERS_KEY \
57 "/org.openoffice.ucb.Configuration/ContentProviders"
60 namespace {
62 bool fillPlaceholders(OUString const & rInput,
63 uno::Sequence< uno::Any > const & rReplacements,
64 OUString * pOutput)
66 sal_Unicode const * p = rInput.getStr();
67 sal_Unicode const * pEnd = p + rInput.getLength();
68 sal_Unicode const * pCopy = p;
69 OUStringBuffer aBuffer;
70 while (p != pEnd)
71 switch (*p++)
73 case '&':
74 if (pEnd - p >= 4
75 && p[0] == 'a' && p[1] == 'm' && p[2] == 'p'
76 && p[3] == ';')
78 aBuffer.append(pCopy, p - 1 - pCopy);
79 aBuffer.append('&');
80 p += 4;
81 pCopy = p;
83 else if (pEnd - p >= 3
84 && p[0] == 'l' && p[1] == 't' && p[2] == ';')
86 aBuffer.append(pCopy, p - 1 - pCopy);
87 aBuffer.append('<');
88 p += 3;
89 pCopy = p;
91 else if (pEnd - p >= 3
92 && p[0] == 'g' && p[1] == 't' && p[2] == ';')
94 aBuffer.append(pCopy, p - 1 - pCopy);
95 aBuffer.append('>');
96 p += 3;
97 pCopy = p;
99 break;
101 case '<':
102 sal_Unicode const * q = p;
103 while (q != pEnd && *q != '>')
104 ++q;
105 if (q == pEnd)
106 break;
107 OUString aKey(p, q - p);
108 OUString aValue;
109 bool bFound = false;
110 for (sal_Int32 i = 2; i + 1 < rReplacements.getLength();
111 i += 2)
113 OUString aReplaceKey;
114 if ((rReplacements[i] >>= aReplaceKey)
115 && aReplaceKey == aKey
116 && (rReplacements[i + 1] >>= aValue))
118 bFound = true;
119 break;
122 if (!bFound)
123 return false;
124 aBuffer.append(pCopy, p - 1 - pCopy);
125 aBuffer.append(aValue);
126 p = q + 1;
127 pCopy = p;
128 break;
130 aBuffer.append(pCopy, pEnd - pCopy);
131 *pOutput = aBuffer.makeStringAndClear();
132 return true;
135 void makeAndAppendXMLName(
136 OUStringBuffer & rBuffer, const OUString & rIn )
138 sal_Int32 nCount = rIn.getLength();
139 for ( sal_Int32 n = 0; n < nCount; ++n )
141 const sal_Unicode c = rIn[ n ];
142 switch ( c )
144 case '&':
145 rBuffer.appendAscii( "&amp;" );
146 break;
148 case '"':
149 rBuffer.appendAscii( "&quot;" );
150 break;
152 case '\'':
153 rBuffer.appendAscii( "&apos;" );
154 break;
156 case '<':
157 rBuffer.appendAscii( "&lt;" );
158 break;
160 case '>':
161 rBuffer.appendAscii( "&gt;" );
162 break;
164 default:
165 rBuffer.append( c );
166 break;
171 bool createContentProviderData(
172 const OUString & rProvider,
173 const uno::Reference< container::XHierarchicalNameAccess >& rxHierNameAccess,
174 ContentProviderData & rInfo)
176 // Obtain service name.
177 OUStringBuffer aKeyBuffer (rProvider);
178 aKeyBuffer.appendAscii( "/ServiceName" );
180 OUString aValue;
183 if ( !( rxHierNameAccess->getByHierarchicalName(
184 aKeyBuffer.makeStringAndClear() ) >>= aValue ) )
186 OSL_FAIL( "UniversalContentBroker::getContentProviderData - "
187 "Error getting item value!" );
190 catch (const container::NoSuchElementException&)
192 return false;
195 rInfo.ServiceName = aValue;
197 // Obtain URL Template.
198 aKeyBuffer.append(rProvider);
199 aKeyBuffer.appendAscii( "/URLTemplate" );
201 if ( !( rxHierNameAccess->getByHierarchicalName(
202 aKeyBuffer.makeStringAndClear() ) >>= aValue ) )
204 OSL_FAIL( "UniversalContentBroker::getContentProviderData - "
205 "Error getting item value!" );
208 rInfo.URLTemplate = aValue;
210 // Obtain Arguments.
211 aKeyBuffer.append(rProvider);
212 aKeyBuffer.appendAscii( "/Arguments" );
214 if ( !( rxHierNameAccess->getByHierarchicalName(
215 aKeyBuffer.makeStringAndClear() ) >>= aValue ) )
217 OSL_FAIL( "UniversalContentBroker::getContentProviderData - "
218 "Error getting item value!" );
221 rInfo.Arguments = aValue;
222 return true;
229 // UniversalContentBroker Implementation.
233 UniversalContentBroker::UniversalContentBroker(
234 const Reference< com::sun::star::uno::XComponentContext >& xContext )
235 : m_xContext( xContext ),
236 m_pDisposeEventListeners( NULL ),
237 m_nInitCount( 0 ), //@@@ see initialize() method
238 m_nCommandId( 0 )
240 OSL_ENSURE( m_xContext.is(),
241 "UniversalContentBroker ctor: No service manager" );
245 // virtual
246 UniversalContentBroker::~UniversalContentBroker()
248 delete m_pDisposeEventListeners;
253 // XInterface methods.
254 void SAL_CALL UniversalContentBroker::acquire()
255 throw()
257 OWeakObject::acquire();
260 void SAL_CALL UniversalContentBroker::release()
261 throw()
263 OWeakObject::release();
266 css::uno::Any SAL_CALL UniversalContentBroker::queryInterface( const css::uno::Type & rType )
267 throw( css::uno::RuntimeException, std::exception )
269 css::uno::Any aRet = cppu::queryInterface( rType,
270 (static_cast< XUniversalContentBroker* >(this)),
271 (static_cast< XTypeProvider* >(this)),
272 (static_cast< XComponent* >(this)),
273 (static_cast< XServiceInfo* >(this)),
274 (static_cast< XInitialization* >(this)),
275 (static_cast< XContentProviderManager* >(this)),
276 (static_cast< XContentProvider* >(this)),
277 (static_cast< XContentIdentifierFactory* >(this)),
278 (static_cast< XCommandProcessor* >(this))
280 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
283 // XTypeProvider methods.
287 XTYPEPROVIDER_IMPL_9( UniversalContentBroker,
288 XUniversalContentBroker,
289 XTypeProvider,
290 XComponent,
291 XServiceInfo,
292 XInitialization,
293 XContentProviderManager,
294 XContentProvider,
295 XContentIdentifierFactory,
296 XCommandProcessor );
300 // XComponent methods.
304 // virtual
305 void SAL_CALL UniversalContentBroker::dispose()
306 throw( com::sun::star::uno::RuntimeException, std::exception )
308 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
310 EventObject aEvt;
311 aEvt.Source = (static_cast< XComponent* >(this));
312 m_pDisposeEventListeners->disposeAndClear( aEvt );
315 if ( m_xNotifier.is() )
316 m_xNotifier->removeChangesListener( this );
320 // virtual
321 void SAL_CALL UniversalContentBroker::addEventListener(
322 const Reference< XEventListener >& Listener )
323 throw( com::sun::star::uno::RuntimeException, std::exception )
325 if ( !m_pDisposeEventListeners )
326 m_pDisposeEventListeners = new OInterfaceContainerHelper( m_aMutex );
328 m_pDisposeEventListeners->addInterface( Listener );
332 // virtual
333 void SAL_CALL UniversalContentBroker::removeEventListener(
334 const Reference< XEventListener >& Listener )
335 throw( com::sun::star::uno::RuntimeException, std::exception )
337 if ( m_pDisposeEventListeners )
338 m_pDisposeEventListeners->removeInterface( Listener );
340 // Note: Don't want to delete empty container here -> performance.
345 // XServiceInfo methods.
349 XSERVICEINFO_IMPL_1_CTX( UniversalContentBroker,
350 OUString( "com.sun.star.comp.ucb.UniversalContentBroker" ),
351 UCB_SERVICE_NAME );
355 // Service factory implementation.
359 ONE_INSTANCE_SERVICE_FACTORY_IMPL( UniversalContentBroker );
363 // XInitialization methods.
367 // virtual
368 void SAL_CALL UniversalContentBroker::initialize(
369 const com::sun::star::uno::Sequence< Any >& aArguments )
370 throw( com::sun::star::uno::Exception,
371 com::sun::star::uno::RuntimeException, std::exception )
374 osl::MutexGuard aGuard(m_aMutex);
375 if (m_aArguments.getLength() != 0)
377 if (aArguments.getLength() != 0
378 && !(m_aArguments.getLength() == 2
379 && aArguments.getLength() == 2
380 && m_aArguments[0] == aArguments[0]
381 && m_aArguments[1] == aArguments[1]))
383 throw IllegalArgumentException(
384 "UCB reinitialized with different arguments",
385 static_cast< cppu::OWeakObject * >(this), 0);
387 return;
389 if (aArguments.getLength() == 0)
391 m_aArguments.realloc(2);
392 m_aArguments[0] <<= OUString("Local");
393 m_aArguments[1] <<= OUString("Office");
395 else
397 m_aArguments = aArguments;
400 configureUcb();
405 // XContentProviderManager methods.
409 // virtual
410 Reference< XContentProvider > SAL_CALL
411 UniversalContentBroker::registerContentProvider(
412 const Reference< XContentProvider >& Provider,
413 const OUString& Scheme,
414 sal_Bool ReplaceExisting )
415 throw( DuplicateProviderException, com::sun::star::uno::RuntimeException, std::exception )
417 osl::MutexGuard aGuard(m_aMutex);
419 ProviderMap_Impl::iterator aIt;
422 aIt = m_aProviders.find(Scheme);
424 catch (const IllegalArgumentException&)
426 return 0; //@@@
429 Reference< XContentProvider > xPrevious;
430 if (aIt == m_aProviders.end())
432 ProviderList_Impl aList;
433 aList.push_front(Provider);
436 m_aProviders.add(Scheme, aList, false);
438 catch (const IllegalArgumentException&)
440 return 0; //@@@
443 else
445 if (!ReplaceExisting)
446 throw DuplicateProviderException();
448 ProviderList_Impl & rList = aIt->getValue();
449 xPrevious = rList.front().getProvider();
450 rList.push_front(Provider);
453 return xPrevious;
457 // virtual
458 void SAL_CALL UniversalContentBroker::deregisterContentProvider(
459 const Reference< XContentProvider >& Provider,
460 const OUString& Scheme )
461 throw( com::sun::star::uno::RuntimeException, std::exception )
463 osl::MutexGuard aGuard(m_aMutex);
465 ProviderMap_Impl::iterator aMapIt;
468 aMapIt = m_aProviders.find(Scheme);
470 catch (const IllegalArgumentException&)
472 return; //@@@
475 if (aMapIt != m_aProviders.end())
477 ProviderList_Impl & rList = aMapIt->getValue();
479 ProviderList_Impl::iterator aListEnd(rList.end());
480 for (ProviderList_Impl::iterator aListIt(rList.begin());
481 aListIt != aListEnd; ++aListIt)
483 if ((*aListIt).getProvider() == Provider)
485 rList.erase(aListIt);
486 break;
490 if (rList.empty())
491 m_aProviders.erase(aMapIt);
496 // virtual
497 com::sun::star::uno::Sequence< ContentProviderInfo > SAL_CALL
498 UniversalContentBroker::queryContentProviders()
499 throw( com::sun::star::uno::RuntimeException, std::exception )
501 // Return a list with information about active(!) content providers.
503 osl::MutexGuard aGuard(m_aMutex);
505 com::sun::star::uno::Sequence< ContentProviderInfo > aSeq(
506 m_aProviders.size() );
507 ContentProviderInfo* pInfo = aSeq.getArray();
509 ProviderMap_Impl::const_iterator end = m_aProviders.end();
510 for (ProviderMap_Impl::const_iterator it(m_aProviders.begin()); it != end;
511 ++it)
513 // Note: Active provider is always the first list element.
514 pInfo->ContentProvider = it->getValue().front().getProvider();
515 pInfo->Scheme = it->getRegexp();
516 ++pInfo;
519 return aSeq;
523 // virtual
524 Reference< XContentProvider > SAL_CALL
525 UniversalContentBroker::queryContentProvider( const OUString&
526 Identifier )
527 throw( com::sun::star::uno::RuntimeException, std::exception )
529 return queryContentProvider( Identifier, false );
534 // XContentProvider methods.
538 // virtual
539 Reference< XContent > SAL_CALL UniversalContentBroker::queryContent(
540 const Reference< XContentIdentifier >& Identifier )
541 throw( IllegalIdentifierException, com::sun::star::uno::RuntimeException, std::exception )
544 // Let the content provider for the scheme given with the content
545 // identifier create the XContent instance.
548 if ( !Identifier.is() )
549 return Reference< XContent >();
551 Reference< XContentProvider > xProv =
552 queryContentProvider( Identifier->getContentIdentifier(), true );
553 if ( xProv.is() )
554 return xProv->queryContent( Identifier );
556 return Reference< XContent >();
560 // virtual
561 sal_Int32 SAL_CALL UniversalContentBroker::compareContentIds(
562 const Reference< XContentIdentifier >& Id1,
563 const Reference< XContentIdentifier >& Id2 )
564 throw( com::sun::star::uno::RuntimeException, std::exception )
566 OUString aURI1( Id1->getContentIdentifier() );
567 OUString aURI2( Id2->getContentIdentifier() );
569 Reference< XContentProvider > xProv1
570 = queryContentProvider( aURI1, true );
571 Reference< XContentProvider > xProv2
572 = queryContentProvider( aURI2, true );
574 // When both identifiers belong to the same provider, let that provider
575 // compare them; otherwise, simply compare the URI strings (which must
576 // be different):
577 if ( xProv1.is() && ( xProv1 == xProv2 ) )
578 return xProv1->compareContentIds( Id1, Id2 );
579 else
580 return aURI1.compareTo( aURI2 );
585 // XContentIdentifierFactory methods.
589 // virtual
590 Reference< XContentIdentifier > SAL_CALL
591 UniversalContentBroker::createContentIdentifier(
592 const OUString& ContentId )
593 throw( com::sun::star::uno::RuntimeException, std::exception )
596 // Let the content provider for the scheme given with content
597 // identifier create the XContentIdentifier instance, if he supports
598 // the XContentIdentifierFactory interface. Otherwise create standard
599 // implementation object for XContentIdentifier.
602 Reference< XContentIdentifier > xIdentifier;
604 Reference< XContentProvider > xProv
605 = queryContentProvider( ContentId, true );
606 if ( xProv.is() )
608 Reference< XContentIdentifierFactory > xFac( xProv, UNO_QUERY );
609 if ( xFac.is() )
610 xIdentifier = xFac->createContentIdentifier( ContentId );
613 if ( !xIdentifier.is() )
614 xIdentifier = new ContentIdentifier( ContentId );
616 return xIdentifier;
621 // XCommandProcessor methods.
625 // virtual
626 sal_Int32 SAL_CALL UniversalContentBroker::createCommandIdentifier()
627 throw( RuntimeException, std::exception )
629 osl::MutexGuard aGuard( m_aMutex );
631 // Just increase counter on every call to generate an identifier.
632 return ++m_nCommandId;
636 // virtual
637 Any SAL_CALL UniversalContentBroker::execute(
638 const Command& aCommand,
639 sal_Int32,
640 const Reference< XCommandEnvironment >& Environment )
641 throw( Exception, CommandAbortedException, RuntimeException, std::exception )
643 Any aRet;
646 // Note: Don't forget to adapt ucb_commands::CommandProcessorInfo
647 // ctor in ucbcmds.cxx when adding new commands!
650 if ( ( aCommand.Handle == GETCOMMANDINFO_HANDLE ) || aCommand.Name == GETCOMMANDINFO_NAME )
653 // getCommandInfo
656 aRet <<= getCommandInfo();
658 else if ( ( aCommand.Handle == GLOBALTRANSFER_HANDLE ) || aCommand.Name == GLOBALTRANSFER_NAME )
661 // globalTransfer
664 GlobalTransferCommandArgument2 aTransferArg;
665 if ( !( aCommand.Argument >>= aTransferArg ) )
667 GlobalTransferCommandArgument aArg;
668 if ( !( aCommand.Argument >>= aArg ) )
670 ucbhelper::cancelCommandExecution(
671 makeAny( IllegalArgumentException(
672 OUString( "Wrong argument type!" ),
673 static_cast< cppu::OWeakObject * >( this ),
674 -1 ) ),
675 Environment );
676 // Unreachable
679 // Copy infos into the new structure
680 aTransferArg.Operation = aArg.Operation;
681 aTransferArg.SourceURL = aArg.SourceURL;
682 aTransferArg.TargetURL = aArg.TargetURL;
683 aTransferArg.NewTitle = aArg.NewTitle;
684 aTransferArg.NameClash = aArg.NameClash;
687 globalTransfer( aTransferArg, Environment );
689 else if ( ( aCommand.Handle == CHECKIN_HANDLE ) || aCommand.Name == CHECKIN_NAME )
691 ucb::CheckinArgument aCheckinArg;
692 if ( !( aCommand.Argument >>= aCheckinArg ) )
694 ucbhelper::cancelCommandExecution(
695 makeAny( IllegalArgumentException(
696 OUString( "Wrong argument type!" ),
697 static_cast< cppu::OWeakObject * >( this ),
698 -1 ) ),
699 Environment );
700 // Unreachable
702 aRet <<= checkIn( aCheckinArg, Environment );
704 else
707 // Unknown command
710 ucbhelper::cancelCommandExecution(
711 makeAny( UnsupportedCommandException(
712 OUString(),
713 static_cast< cppu::OWeakObject * >( this ) ) ),
714 Environment );
715 // Unreachable
718 return aRet;
723 // XCommandProcessor2 methods.
727 // virtual
728 void SAL_CALL UniversalContentBroker::releaseCommandIdentifier(sal_Int32 /*aCommandId*/)
729 throw( RuntimeException, std::exception )
731 // @@@ Not implemeted ( yet).
735 // virtual
736 void SAL_CALL UniversalContentBroker::abort( sal_Int32 )
737 throw( RuntimeException, std::exception )
739 // @@@ Not implemeted ( yet).
744 // XChangesListener methods
747 // virtual
748 void SAL_CALL UniversalContentBroker::changesOccurred( const util::ChangesEvent& Event )
749 throw( uno::RuntimeException, std::exception )
751 sal_Int32 nCount = Event.Changes.getLength();
752 if ( nCount )
754 uno::Reference< container::XHierarchicalNameAccess > xHierNameAccess;
755 Event.Base >>= xHierNameAccess;
757 OSL_ASSERT( xHierNameAccess.is() );
759 const util::ElementChange* pElementChanges
760 = Event.Changes.getConstArray();
762 ContentProviderDataList aData;
763 for ( sal_Int32 n = 0; n < nCount; ++n )
765 const util::ElementChange& rElem = pElementChanges[ n ];
766 OUString aKey;
767 rElem.Accessor >>= aKey;
769 ContentProviderData aInfo;
771 // Removal of UCPs from the configuration leads to changesOccurred
772 // notifications, too, but it is hard to tell for a given
773 // ElementChange whether it is an addition or a removal, so as a
774 // heuristic consider as removals those that cause a
775 // NoSuchElementException in createContentProviderData.
777 // For now, removal of UCPs from the configuration is simply ignored
778 // (and not reflected in the UCB's data structures):
779 if (createContentProviderData(aKey, xHierNameAccess, aInfo))
781 aData.push_back(aInfo);
785 prepareAndRegister(aData);
791 // XEventListener methods
794 // virtual
795 void SAL_CALL UniversalContentBroker::disposing(const lang::EventObject&)
796 throw( uno::RuntimeException, std::exception )
798 if ( m_xNotifier.is() )
800 osl::Guard< osl::Mutex > aGuard( m_aMutex );
802 if ( m_xNotifier.is() )
803 m_xNotifier.clear();
809 // Non-interface methods
813 Reference< XContentProvider > UniversalContentBroker::queryContentProvider(
814 const OUString& Identifier,
815 bool bResolved )
817 osl::MutexGuard aGuard( m_aMutex );
819 ProviderList_Impl const * pList = m_aProviders.map( Identifier );
820 return pList ? bResolved ? pList->front().getResolvedProvider()
821 : pList->front().getProvider()
822 : Reference< XContentProvider >();
825 bool UniversalContentBroker::configureUcb()
826 throw (uno::RuntimeException)
828 OUString aKey1;
829 OUString aKey2;
830 if (m_aArguments.getLength() < 2
831 || !(m_aArguments[0] >>= aKey1) || !(m_aArguments[1] >>= aKey2))
833 OSL_FAIL("UniversalContentBroker::configureUcb(): Bad arguments");
834 return false;
837 ContentProviderDataList aData;
838 if (!getContentProviderData(aKey1, aKey2, aData))
840 OSL_TRACE("UniversalContentBroker::configureUcb(): No configuration");
841 return false;
844 prepareAndRegister(aData);
846 return true;
849 void UniversalContentBroker::prepareAndRegister(
850 const ContentProviderDataList& rData)
852 ContentProviderDataList::const_iterator aEnd(rData.end());
853 for (ContentProviderDataList::const_iterator aIt(rData.begin());
854 aIt != aEnd; ++aIt)
856 OUString aProviderArguments;
857 if (fillPlaceholders(aIt->Arguments,
858 m_aArguments,
859 &aProviderArguments))
861 registerAtUcb(this,
862 m_xContext,
863 aIt->ServiceName,
864 aProviderArguments,
865 aIt->URLTemplate);
868 else
869 OSL_FAIL("UniversalContentBroker::prepareAndRegister(): Bad argument placeholders");
874 bool UniversalContentBroker::getContentProviderData(
875 const OUString & rKey1,
876 const OUString & rKey2,
877 ContentProviderDataList & rListToFill )
879 if ( !m_xContext.is() || rKey1.isEmpty() || rKey2.isEmpty() )
881 OSL_FAIL( "UniversalContentBroker::getContentProviderData - Invalid argument!" );
882 return false;
887 uno::Reference< lang::XMultiServiceFactory > xConfigProv =
888 configuration::theDefaultProvider::get( m_xContext );
890 OUStringBuffer aFullPath;
891 aFullPath.appendAscii( CONFIG_CONTENTPROVIDERS_KEY "/['" );
892 makeAndAppendXMLName( aFullPath, rKey1 );
893 aFullPath.appendAscii( "']/SecondaryKeys/['" );
894 makeAndAppendXMLName( aFullPath, rKey2 );
895 aFullPath.appendAscii( "']/ProviderData" );
897 uno::Sequence< uno::Any > aArguments( 1 );
898 beans::PropertyValue aProperty;
899 aProperty.Name = "nodepath";
900 aProperty.Value <<= aFullPath.makeStringAndClear();
901 aArguments[ 0 ] <<= aProperty;
903 uno::Reference< uno::XInterface > xInterface(
904 xConfigProv->createInstanceWithArguments(
905 OUString( "com.sun.star.configuration.ConfigurationAccess" ),
906 aArguments ) );
908 if ( !m_xNotifier.is() )
910 m_xNotifier = uno::Reference< util::XChangesNotifier >(
911 xInterface, uno::UNO_QUERY_THROW );
913 m_xNotifier->addChangesListener( this );
916 uno::Reference< container::XNameAccess > xNameAccess(
917 xInterface, uno::UNO_QUERY_THROW );
919 uno::Sequence< OUString > aElems = xNameAccess->getElementNames();
920 const OUString* pElems = aElems.getConstArray();
921 sal_Int32 nCount = aElems.getLength();
923 if ( nCount > 0 )
925 uno::Reference< container::XHierarchicalNameAccess >
926 xHierNameAccess( xInterface, uno::UNO_QUERY_THROW );
928 // Iterate over children.
929 for ( sal_Int32 n = 0; n < nCount; ++n )
935 ContentProviderData aInfo;
937 OUStringBuffer aElemBuffer;
938 aElemBuffer.appendAscii( "['" );
939 makeAndAppendXMLName( aElemBuffer, pElems[ n ] );
940 aElemBuffer.appendAscii( "']" );
942 OSL_VERIFY(
943 createContentProviderData(
944 aElemBuffer.makeStringAndClear(), xHierNameAccess,
945 aInfo));
947 rListToFill.push_back( aInfo );
949 catch (const container::NoSuchElementException&)
951 // getByHierarchicalName
952 OSL_FAIL( "UniversalContentBroker::getContentProviderData - "
953 "caught NoSuchElementException!" );
958 catch (const uno::RuntimeException&)
960 OSL_TRACE( "UniversalContentBroker::getContentProviderData - caught RuntimeException!" );
961 return false;
963 catch (const uno::Exception&)
965 // createInstance, createInstanceWithArguments
967 OSL_TRACE( "UniversalContentBroker::getContentProviderData - caught Exception!" );
968 return false;
971 return true;
976 // ProviderListEntry_Impl implementation.
980 Reference< XContentProvider > ProviderListEntry_Impl::resolveProvider() const
982 if ( !m_xResolvedProvider.is() )
984 Reference< XContentProviderSupplier > xSupplier(
985 m_xProvider, UNO_QUERY );
986 if ( xSupplier.is() )
987 m_xResolvedProvider = xSupplier->getContentProvider();
989 if ( !m_xResolvedProvider.is() )
990 m_xResolvedProvider = m_xProvider;
993 return m_xResolvedProvider;
996 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */