Stop leaking all ScPostIt instances.
[LibreOffice.git] / ucb / source / core / ucb.cxx
blobeb8acce5b3cb6890d32e09a870503fce1bd93663
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;
227 //=========================================================================
229 // UniversalContentBroker Implementation.
231 //=========================================================================
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" );
244 //=========================================================================
245 // virtual
246 UniversalContentBroker::~UniversalContentBroker()
248 delete m_pDisposeEventListeners;
251 //=========================================================================
253 // XInterface methods.
255 //=========================================================================
257 XINTERFACE_IMPL_9( UniversalContentBroker,
258 XUniversalContentBroker,
259 XTypeProvider,
260 XComponent,
261 XServiceInfo,
262 XInitialization,
263 XContentProviderManager,
264 XContentProvider,
265 XContentIdentifierFactory,
266 XCommandProcessor );
268 //=========================================================================
270 // XTypeProvider methods.
272 //=========================================================================
274 XTYPEPROVIDER_IMPL_9( UniversalContentBroker,
275 XUniversalContentBroker,
276 XTypeProvider,
277 XComponent,
278 XServiceInfo,
279 XInitialization,
280 XContentProviderManager,
281 XContentProvider,
282 XContentIdentifierFactory,
283 XCommandProcessor );
285 //=========================================================================
287 // XComponent methods.
289 //=========================================================================
291 // virtual
292 void SAL_CALL UniversalContentBroker::dispose()
293 throw( com::sun::star::uno::RuntimeException )
295 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
297 EventObject aEvt;
298 aEvt.Source = (static_cast< XComponent* >(this));
299 m_pDisposeEventListeners->disposeAndClear( aEvt );
302 if ( m_xNotifier.is() )
303 m_xNotifier->removeChangesListener( this );
306 //=========================================================================
307 // virtual
308 void SAL_CALL UniversalContentBroker::addEventListener(
309 const Reference< XEventListener >& Listener )
310 throw( com::sun::star::uno::RuntimeException )
312 if ( !m_pDisposeEventListeners )
313 m_pDisposeEventListeners = new OInterfaceContainerHelper( m_aMutex );
315 m_pDisposeEventListeners->addInterface( Listener );
318 //=========================================================================
319 // virtual
320 void SAL_CALL UniversalContentBroker::removeEventListener(
321 const Reference< XEventListener >& Listener )
322 throw( com::sun::star::uno::RuntimeException )
324 if ( m_pDisposeEventListeners )
325 m_pDisposeEventListeners->removeInterface( Listener );
327 // Note: Don't want to delete empty container here -> performance.
330 //=========================================================================
332 // XServiceInfo methods.
334 //=========================================================================
336 XSERVICEINFO_IMPL_1_CTX( UniversalContentBroker,
337 OUString( "com.sun.star.comp.ucb.UniversalContentBroker" ),
338 OUString( UCB_SERVICE_NAME ) );
340 //=========================================================================
342 // Service factory implementation.
344 //=========================================================================
346 ONE_INSTANCE_SERVICE_FACTORY_IMPL( UniversalContentBroker );
348 //=========================================================================
350 // XInitialization methods.
352 //=========================================================================
354 // virtual
355 void SAL_CALL UniversalContentBroker::initialize(
356 const com::sun::star::uno::Sequence< Any >& aArguments )
357 throw( com::sun::star::uno::Exception,
358 com::sun::star::uno::RuntimeException )
361 osl::MutexGuard aGuard(m_aMutex);
362 if (m_aArguments.getLength() != 0)
364 if (aArguments.getLength() != 0
365 && !(m_aArguments.getLength() == 2
366 && aArguments.getLength() == 2
367 && m_aArguments[0] == aArguments[0]
368 && m_aArguments[1] == aArguments[1]))
370 throw IllegalArgumentException(
371 "UCB reinitialized with different arguments",
372 static_cast< cppu::OWeakObject * >(this), 0);
374 return;
376 if (aArguments.getLength() == 0)
378 m_aArguments.realloc(2);
379 m_aArguments[0] <<= OUString("Local");
380 m_aArguments[1] <<= OUString("Office");
382 else
384 m_aArguments = aArguments;
387 configureUcb();
390 //=========================================================================
392 // XContentProviderManager methods.
394 //=========================================================================
396 // virtual
397 Reference< XContentProvider > SAL_CALL
398 UniversalContentBroker::registerContentProvider(
399 const Reference< XContentProvider >& Provider,
400 const OUString& Scheme,
401 sal_Bool ReplaceExisting )
402 throw( DuplicateProviderException, com::sun::star::uno::RuntimeException )
404 osl::MutexGuard aGuard(m_aMutex);
406 ProviderMap_Impl::iterator aIt;
409 aIt = m_aProviders.find(Scheme);
411 catch (const IllegalArgumentException&)
413 return 0; //@@@
416 Reference< XContentProvider > xPrevious;
417 if (aIt == m_aProviders.end())
419 ProviderList_Impl aList;
420 aList.push_front(Provider);
423 m_aProviders.add(Scheme, aList, false);
425 catch (const IllegalArgumentException&)
427 return 0; //@@@
430 else
432 if (!ReplaceExisting)
433 throw DuplicateProviderException();
435 ProviderList_Impl & rList = aIt->getValue();
436 xPrevious = rList.front().getProvider();
437 rList.push_front(Provider);
440 return xPrevious;
443 //=========================================================================
444 // virtual
445 void SAL_CALL UniversalContentBroker::deregisterContentProvider(
446 const Reference< XContentProvider >& Provider,
447 const OUString& Scheme )
448 throw( com::sun::star::uno::RuntimeException )
450 osl::MutexGuard aGuard(m_aMutex);
452 ProviderMap_Impl::iterator aMapIt;
455 aMapIt = m_aProviders.find(Scheme);
457 catch (const IllegalArgumentException&)
459 return; //@@@
462 if (aMapIt != m_aProviders.end())
464 ProviderList_Impl & rList = aMapIt->getValue();
466 ProviderList_Impl::iterator aListEnd(rList.end());
467 for (ProviderList_Impl::iterator aListIt(rList.begin());
468 aListIt != aListEnd; ++aListIt)
470 if ((*aListIt).getProvider() == Provider)
472 rList.erase(aListIt);
473 break;
477 if (rList.empty())
478 m_aProviders.erase(aMapIt);
482 //=========================================================================
483 // virtual
484 com::sun::star::uno::Sequence< ContentProviderInfo > SAL_CALL
485 UniversalContentBroker::queryContentProviders()
486 throw( com::sun::star::uno::RuntimeException )
488 // Return a list with information about active(!) content providers.
490 osl::MutexGuard aGuard(m_aMutex);
492 com::sun::star::uno::Sequence< ContentProviderInfo > aSeq(
493 m_aProviders.size() );
494 ContentProviderInfo* pInfo = aSeq.getArray();
496 ProviderMap_Impl::const_iterator end = m_aProviders.end();
497 for (ProviderMap_Impl::const_iterator it(m_aProviders.begin()); it != end;
498 ++it)
500 // Note: Active provider is always the first list element.
501 pInfo->ContentProvider = it->getValue().front().getProvider();
502 pInfo->Scheme = it->getRegexp();
503 ++pInfo;
506 return aSeq;
509 //=========================================================================
510 // virtual
511 Reference< XContentProvider > SAL_CALL
512 UniversalContentBroker::queryContentProvider( const OUString&
513 Identifier )
514 throw( com::sun::star::uno::RuntimeException )
516 return queryContentProvider( Identifier, sal_False );
519 //=========================================================================
521 // XContentProvider methods.
523 //=========================================================================
525 // virtual
526 Reference< XContent > SAL_CALL UniversalContentBroker::queryContent(
527 const Reference< XContentIdentifier >& Identifier )
528 throw( IllegalIdentifierException, com::sun::star::uno::RuntimeException )
530 //////////////////////////////////////////////////////////////////////
531 // Let the content provider for the scheme given with the content
532 // identifier create the XContent instance.
533 //////////////////////////////////////////////////////////////////////
535 if ( !Identifier.is() )
536 return Reference< XContent >();
538 Reference< XContentProvider > xProv =
539 queryContentProvider( Identifier->getContentIdentifier(), sal_True );
540 if ( xProv.is() )
541 return xProv->queryContent( Identifier );
543 return Reference< XContent >();
546 //=========================================================================
547 // virtual
548 sal_Int32 SAL_CALL UniversalContentBroker::compareContentIds(
549 const Reference< XContentIdentifier >& Id1,
550 const Reference< XContentIdentifier >& Id2 )
551 throw( com::sun::star::uno::RuntimeException )
553 OUString aURI1( Id1->getContentIdentifier() );
554 OUString aURI2( Id2->getContentIdentifier() );
556 Reference< XContentProvider > xProv1
557 = queryContentProvider( aURI1, sal_True );
558 Reference< XContentProvider > xProv2
559 = queryContentProvider( aURI2, sal_True );
561 // When both identifiers belong to the same provider, let that provider
562 // compare them; otherwise, simply compare the URI strings (which must
563 // be different):
564 if ( xProv1.is() && ( xProv1 == xProv2 ) )
565 return xProv1->compareContentIds( Id1, Id2 );
566 else
567 return aURI1.compareTo( aURI2 );
570 //=========================================================================
572 // XContentIdentifierFactory methods.
574 //=========================================================================
576 // virtual
577 Reference< XContentIdentifier > SAL_CALL
578 UniversalContentBroker::createContentIdentifier(
579 const OUString& ContentId )
580 throw( com::sun::star::uno::RuntimeException )
582 //////////////////////////////////////////////////////////////////////
583 // Let the content provider for the scheme given with content
584 // identifier create the XContentIdentifier instance, if he supports
585 // the XContentIdentifierFactory interface. Otherwise create standard
586 // implementation object for XContentIdentifier.
587 //////////////////////////////////////////////////////////////////////
589 Reference< XContentIdentifier > xIdentifier;
591 Reference< XContentProvider > xProv
592 = queryContentProvider( ContentId, sal_True );
593 if ( xProv.is() )
595 Reference< XContentIdentifierFactory > xFac( xProv, UNO_QUERY );
596 if ( xFac.is() )
597 xIdentifier = xFac->createContentIdentifier( ContentId );
600 if ( !xIdentifier.is() )
601 xIdentifier = new ContentIdentifier( ContentId );
603 return xIdentifier;
606 //=========================================================================
608 // XCommandProcessor methods.
610 //=========================================================================
612 // virtual
613 sal_Int32 SAL_CALL UniversalContentBroker::createCommandIdentifier()
614 throw( RuntimeException )
616 osl::MutexGuard aGuard( m_aMutex );
618 // Just increase counter on every call to generate an identifier.
619 return ++m_nCommandId;
622 //=========================================================================
623 // virtual
624 Any SAL_CALL UniversalContentBroker::execute(
625 const Command& aCommand,
626 sal_Int32,
627 const Reference< XCommandEnvironment >& Environment )
628 throw( Exception, CommandAbortedException, RuntimeException )
630 Any aRet;
632 //////////////////////////////////////////////////////////////////////
633 // Note: Don't forget to adapt ucb_commands::CommandProcessorInfo
634 // ctor in ucbcmds.cxx when adding new commands!
635 //////////////////////////////////////////////////////////////////////
637 if ( ( aCommand.Handle == GETCOMMANDINFO_HANDLE ) || aCommand.Name == GETCOMMANDINFO_NAME )
639 //////////////////////////////////////////////////////////////////
640 // getCommandInfo
641 //////////////////////////////////////////////////////////////////
643 aRet <<= getCommandInfo();
645 else if ( ( aCommand.Handle == GLOBALTRANSFER_HANDLE ) || aCommand.Name == GLOBALTRANSFER_NAME )
647 //////////////////////////////////////////////////////////////////
648 // globalTransfer
649 //////////////////////////////////////////////////////////////////
651 GlobalTransferCommandArgument2 aTransferArg;
652 if ( !( aCommand.Argument >>= aTransferArg ) )
654 GlobalTransferCommandArgument aArg;
655 if ( !( aCommand.Argument >>= aArg ) )
657 ucbhelper::cancelCommandExecution(
658 makeAny( IllegalArgumentException(
659 OUString( "Wrong argument type!" ),
660 static_cast< cppu::OWeakObject * >( this ),
661 -1 ) ),
662 Environment );
663 // Unreachable
666 // Copy infos into the new stucture
667 aTransferArg.Operation = aArg.Operation;
668 aTransferArg.SourceURL = aArg.SourceURL;
669 aTransferArg.TargetURL = aArg.TargetURL;
670 aTransferArg.NewTitle = aArg.NewTitle;
671 aTransferArg.NameClash = aArg.NameClash;
674 globalTransfer( aTransferArg, Environment );
676 else if ( ( aCommand.Handle == CHECKIN_HANDLE ) || aCommand.Name == CHECKIN_NAME )
678 ucb::CheckinArgument aCheckinArg;
679 if ( !( aCommand.Argument >>= aCheckinArg ) )
681 ucbhelper::cancelCommandExecution(
682 makeAny( IllegalArgumentException(
683 OUString( "Wrong argument type!" ),
684 static_cast< cppu::OWeakObject * >( this ),
685 -1 ) ),
686 Environment );
687 // Unreachable
689 aRet <<= checkIn( aCheckinArg, Environment );
691 else
693 //////////////////////////////////////////////////////////////////
694 // Unknown command
695 //////////////////////////////////////////////////////////////////
697 ucbhelper::cancelCommandExecution(
698 makeAny( UnsupportedCommandException(
699 OUString(),
700 static_cast< cppu::OWeakObject * >( this ) ) ),
701 Environment );
702 // Unreachable
705 return aRet;
708 //=========================================================================
710 // XCommandProcessor2 methods.
712 //=========================================================================
714 // virtual
715 void SAL_CALL UniversalContentBroker::releaseCommandIdentifier(sal_Int32 /*aCommandId*/)
716 throw( RuntimeException )
718 // @@@ Not implemeted ( yet).
721 //=========================================================================
722 // virtual
723 void SAL_CALL UniversalContentBroker::abort( sal_Int32 )
724 throw( RuntimeException )
726 // @@@ Not implemeted ( yet).
729 //=========================================================================
731 // XChangesListener methods
733 //=========================================================================
734 // virtual
735 void SAL_CALL UniversalContentBroker::changesOccurred( const util::ChangesEvent& Event )
736 throw( uno::RuntimeException )
738 sal_Int32 nCount = Event.Changes.getLength();
739 if ( nCount )
741 uno::Reference< container::XHierarchicalNameAccess > xHierNameAccess;
742 Event.Base >>= xHierNameAccess;
744 OSL_ASSERT( xHierNameAccess.is() );
746 const util::ElementChange* pElementChanges
747 = Event.Changes.getConstArray();
749 ContentProviderDataList aData;
750 for ( sal_Int32 n = 0; n < nCount; ++n )
752 const util::ElementChange& rElem = pElementChanges[ n ];
753 OUString aKey;
754 rElem.Accessor >>= aKey;
756 ContentProviderData aInfo;
758 // Removal of UCPs from the configuration leads to changesOccurred
759 // notifications, too, but it is hard to tell for a given
760 // ElementChange whether it is an addition or a removal, so as a
761 // heuristic consider as removals those that cause a
762 // NoSuchElementException in createContentProviderData.
764 // For now, removal of UCPs from the configuration is simply ignored
765 // (and not reflected in the UCB's data structures):
766 if (createContentProviderData(aKey, xHierNameAccess, aInfo))
768 aData.push_back(aInfo);
772 prepareAndRegister(aData);
776 //=========================================================================
778 // XEventListener methods
780 //=========================================================================
781 // virtual
782 void SAL_CALL UniversalContentBroker::disposing(const lang::EventObject&)
783 throw( uno::RuntimeException )
785 if ( m_xNotifier.is() )
787 osl::Guard< osl::Mutex > aGuard( m_aMutex );
789 if ( m_xNotifier.is() )
790 m_xNotifier.clear();
794 //=========================================================================
796 // Non-interface methods
798 //=========================================================================
800 Reference< XContentProvider > UniversalContentBroker::queryContentProvider(
801 const OUString& Identifier,
802 sal_Bool bResolved )
804 osl::MutexGuard aGuard( m_aMutex );
806 ProviderList_Impl const * pList = m_aProviders.map( Identifier );
807 return pList ? bResolved ? pList->front().getResolvedProvider()
808 : pList->front().getProvider()
809 : Reference< XContentProvider >();
812 bool UniversalContentBroker::configureUcb()
813 throw (uno::RuntimeException)
815 OUString aKey1;
816 OUString aKey2;
817 if (m_aArguments.getLength() < 2
818 || !(m_aArguments[0] >>= aKey1) || !(m_aArguments[1] >>= aKey2))
820 OSL_FAIL("UniversalContentBroker::configureUcb(): Bad arguments");
821 return false;
824 ContentProviderDataList aData;
825 if (!getContentProviderData(aKey1, aKey2, aData))
827 OSL_TRACE("UniversalContentBroker::configureUcb(): No configuration");
828 return false;
831 prepareAndRegister(aData);
833 return true;
836 void UniversalContentBroker::prepareAndRegister(
837 const ContentProviderDataList& rData)
839 ContentProviderDataList::const_iterator aEnd(rData.end());
840 for (ContentProviderDataList::const_iterator aIt(rData.begin());
841 aIt != aEnd; ++aIt)
843 OUString aProviderArguments;
844 if (fillPlaceholders(aIt->Arguments,
845 m_aArguments,
846 &aProviderArguments))
848 registerAtUcb(this,
849 m_xContext,
850 aIt->ServiceName,
851 aProviderArguments,
852 aIt->URLTemplate);
855 else
856 OSL_FAIL("UniversalContentBroker::prepareAndRegister(): Bad argument placeholders");
860 //=========================================================================
861 bool UniversalContentBroker::getContentProviderData(
862 const OUString & rKey1,
863 const OUString & rKey2,
864 ContentProviderDataList & rListToFill )
866 if ( !m_xContext.is() || rKey1.isEmpty() || rKey2.isEmpty() )
868 OSL_FAIL( "UniversalContentBroker::getContentProviderData - Invalid argument!" );
869 return false;
874 uno::Reference< lang::XMultiServiceFactory > xConfigProv =
875 configuration::theDefaultProvider::get( m_xContext );
877 OUStringBuffer aFullPath;
878 aFullPath.appendAscii( CONFIG_CONTENTPROVIDERS_KEY "/['" );
879 makeAndAppendXMLName( aFullPath, rKey1 );
880 aFullPath.appendAscii( "']/SecondaryKeys/['" );
881 makeAndAppendXMLName( aFullPath, rKey2 );
882 aFullPath.appendAscii( "']/ProviderData" );
884 uno::Sequence< uno::Any > aArguments( 1 );
885 beans::PropertyValue aProperty;
886 aProperty.Name = "nodepath";
887 aProperty.Value <<= aFullPath.makeStringAndClear();
888 aArguments[ 0 ] <<= aProperty;
890 uno::Reference< uno::XInterface > xInterface(
891 xConfigProv->createInstanceWithArguments(
892 OUString( "com.sun.star.configuration.ConfigurationAccess" ),
893 aArguments ) );
895 if ( !m_xNotifier.is() )
897 m_xNotifier = uno::Reference< util::XChangesNotifier >(
898 xInterface, uno::UNO_QUERY_THROW );
900 m_xNotifier->addChangesListener( this );
903 uno::Reference< container::XNameAccess > xNameAccess(
904 xInterface, uno::UNO_QUERY_THROW );
906 uno::Sequence< OUString > aElems = xNameAccess->getElementNames();
907 const OUString* pElems = aElems.getConstArray();
908 sal_Int32 nCount = aElems.getLength();
910 if ( nCount > 0 )
912 uno::Reference< container::XHierarchicalNameAccess >
913 xHierNameAccess( xInterface, uno::UNO_QUERY_THROW );
915 // Iterate over children.
916 for ( sal_Int32 n = 0; n < nCount; ++n )
922 ContentProviderData aInfo;
924 OUStringBuffer aElemBuffer;
925 aElemBuffer.appendAscii( "['" );
926 makeAndAppendXMLName( aElemBuffer, pElems[ n ] );
927 aElemBuffer.appendAscii( "']" );
929 OSL_VERIFY(
930 createContentProviderData(
931 aElemBuffer.makeStringAndClear(), xHierNameAccess,
932 aInfo));
934 rListToFill.push_back( aInfo );
936 catch (const container::NoSuchElementException&)
938 // getByHierarchicalName
939 OSL_FAIL( "UniversalContentBroker::getContentProviderData - "
940 "caught NoSuchElementException!" );
945 catch (const uno::RuntimeException&)
947 OSL_TRACE( "UniversalContentBroker::getContentProviderData - caught RuntimeException!" );
948 return false;
950 catch (const uno::Exception&)
952 // createInstance, createInstanceWithArguments
954 OSL_TRACE( "UniversalContentBroker::getContentProviderData - caught Exception!" );
955 return false;
958 return true;
961 //=========================================================================
963 // ProviderListEntry_Impl implementation.
965 //=========================================================================
967 Reference< XContentProvider > ProviderListEntry_Impl::resolveProvider() const
969 if ( !m_xResolvedProvider.is() )
971 Reference< XContentProviderSupplier > xSupplier(
972 m_xProvider, UNO_QUERY );
973 if ( xSupplier.is() )
974 m_xResolvedProvider = xSupplier->getContentProvider();
976 if ( !m_xResolvedProvider.is() )
977 m_xResolvedProvider = m_xProvider;
980 return m_xResolvedProvider;
983 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */