Updated core
[LibreOffice.git] / ucb / source / core / ucb.cxx
blob324641dc6ce27e1e6d80d71b4ce17f9caf536e70
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 // Definitions for ProviderMap_Impl (Solaris wouldn't find explicit template
48 // instantiations for these in another compilation unit...):
49 #ifndef _UCB_REGEXPMAP_TPT_
50 #include <regexpmap.tpt>
51 #endif
53 using namespace cppu;
54 using namespace com::sun::star::uno;
55 using namespace com::sun::star::lang;
56 using namespace com::sun::star::ucb;
57 using namespace ucb_impl;
58 using namespace com::sun::star;
59 using namespace ucbhelper;
62 #define CONFIG_CONTENTPROVIDERS_KEY \
63 "/org.openoffice.ucb.Configuration/ContentProviders"
66 namespace {
68 bool fillPlaceholders(OUString const & rInput,
69 uno::Sequence< uno::Any > const & rReplacements,
70 OUString * pOutput)
72 sal_Unicode const * p = rInput.getStr();
73 sal_Unicode const * pEnd = p + rInput.getLength();
74 sal_Unicode const * pCopy = p;
75 OUStringBuffer aBuffer;
76 while (p != pEnd)
77 switch (*p++)
79 case '&':
80 if (pEnd - p >= 4
81 && p[0] == 'a' && p[1] == 'm' && p[2] == 'p'
82 && p[3] == ';')
84 aBuffer.append(pCopy, p - 1 - pCopy);
85 aBuffer.append(sal_Unicode('&'));
86 p += 4;
87 pCopy = p;
89 else if (pEnd - p >= 3
90 && p[0] == 'l' && p[1] == 't' && p[2] == ';')
92 aBuffer.append(pCopy, p - 1 - pCopy);
93 aBuffer.append(sal_Unicode('<'));
94 p += 3;
95 pCopy = p;
97 else if (pEnd - p >= 3
98 && p[0] == 'g' && p[1] == 't' && p[2] == ';')
100 aBuffer.append(pCopy, p - 1 - pCopy);
101 aBuffer.append(sal_Unicode('>'));
102 p += 3;
103 pCopy = p;
105 break;
107 case '<':
108 sal_Unicode const * q = p;
109 while (q != pEnd && *q != '>')
110 ++q;
111 if (q == pEnd)
112 break;
113 OUString aKey(p, q - p);
114 OUString aValue;
115 bool bFound = false;
116 for (sal_Int32 i = 2; i + 1 < rReplacements.getLength();
117 i += 2)
119 OUString aReplaceKey;
120 if ((rReplacements[i] >>= aReplaceKey)
121 && aReplaceKey == aKey
122 && (rReplacements[i + 1] >>= aValue))
124 bFound = true;
125 break;
128 if (!bFound)
129 return false;
130 aBuffer.append(pCopy, p - 1 - pCopy);
131 aBuffer.append(aValue);
132 p = q + 1;
133 pCopy = p;
134 break;
136 aBuffer.append(pCopy, pEnd - pCopy);
137 *pOutput = aBuffer.makeStringAndClear();
138 return true;
141 void makeAndAppendXMLName(
142 OUStringBuffer & rBuffer, const OUString & rIn )
144 sal_Int32 nCount = rIn.getLength();
145 for ( sal_Int32 n = 0; n < nCount; ++n )
147 const sal_Unicode c = rIn.getStr()[ n ];
148 switch ( c )
150 case '&':
151 rBuffer.appendAscii( "&amp;" );
152 break;
154 case '"':
155 rBuffer.appendAscii( "&quot;" );
156 break;
158 case '\'':
159 rBuffer.appendAscii( "&apos;" );
160 break;
162 case '<':
163 rBuffer.appendAscii( "&lt;" );
164 break;
166 case '>':
167 rBuffer.appendAscii( "&gt;" );
168 break;
170 default:
171 rBuffer.append( c );
172 break;
177 bool createContentProviderData(
178 const OUString & rProvider,
179 const uno::Reference< container::XHierarchicalNameAccess >& rxHierNameAccess,
180 ContentProviderData & rInfo)
182 // Obtain service name.
183 OUStringBuffer aKeyBuffer (rProvider);
184 aKeyBuffer.appendAscii( "/ServiceName" );
186 OUString aValue;
189 if ( !( rxHierNameAccess->getByHierarchicalName(
190 aKeyBuffer.makeStringAndClear() ) >>= aValue ) )
192 OSL_FAIL( "UniversalContentBroker::getContentProviderData - "
193 "Error getting item value!" );
196 catch (const container::NoSuchElementException&)
198 return false;
201 rInfo.ServiceName = aValue;
203 // Obtain URL Template.
204 aKeyBuffer.append(rProvider);
205 aKeyBuffer.appendAscii( "/URLTemplate" );
207 if ( !( rxHierNameAccess->getByHierarchicalName(
208 aKeyBuffer.makeStringAndClear() ) >>= aValue ) )
210 OSL_FAIL( "UniversalContentBroker::getContentProviderData - "
211 "Error getting item value!" );
214 rInfo.URLTemplate = aValue;
216 // Obtain Arguments.
217 aKeyBuffer.append(rProvider);
218 aKeyBuffer.appendAscii( "/Arguments" );
220 if ( !( rxHierNameAccess->getByHierarchicalName(
221 aKeyBuffer.makeStringAndClear() ) >>= aValue ) )
223 OSL_FAIL( "UniversalContentBroker::getContentProviderData - "
224 "Error getting item value!" );
227 rInfo.Arguments = aValue;
228 return true;
233 //=========================================================================
235 // UniversalContentBroker Implementation.
237 //=========================================================================
239 UniversalContentBroker::UniversalContentBroker(
240 const Reference< com::sun::star::lang::XMultiServiceFactory >& rXSMgr )
241 : m_xSMgr( rXSMgr ),
242 m_pDisposeEventListeners( NULL ),
243 m_nInitCount( 0 ), //@@@ see initialize() method
244 m_nCommandId( 0 )
246 OSL_ENSURE( m_xSMgr.is(),
247 "UniversalContentBroker ctor: No service manager" );
250 //=========================================================================
251 // virtual
252 UniversalContentBroker::~UniversalContentBroker()
254 delete m_pDisposeEventListeners;
257 //=========================================================================
259 // XInterface methods.
261 //=========================================================================
263 XINTERFACE_IMPL_9( UniversalContentBroker,
264 XUniversalContentBroker,
265 XTypeProvider,
266 XComponent,
267 XServiceInfo,
268 XInitialization,
269 XContentProviderManager,
270 XContentProvider,
271 XContentIdentifierFactory,
272 XCommandProcessor );
274 //=========================================================================
276 // XTypeProvider methods.
278 //=========================================================================
280 XTYPEPROVIDER_IMPL_9( UniversalContentBroker,
281 XUniversalContentBroker,
282 XTypeProvider,
283 XComponent,
284 XServiceInfo,
285 XInitialization,
286 XContentProviderManager,
287 XContentProvider,
288 XContentIdentifierFactory,
289 XCommandProcessor );
291 //=========================================================================
293 // XComponent methods.
295 //=========================================================================
297 // virtual
298 void SAL_CALL UniversalContentBroker::dispose()
299 throw( com::sun::star::uno::RuntimeException )
301 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
303 EventObject aEvt;
304 aEvt.Source = (static_cast< XComponent* >(this));
305 m_pDisposeEventListeners->disposeAndClear( aEvt );
308 if ( m_xNotifier.is() )
309 m_xNotifier->removeChangesListener( this );
312 //=========================================================================
313 // virtual
314 void SAL_CALL UniversalContentBroker::addEventListener(
315 const Reference< XEventListener >& Listener )
316 throw( com::sun::star::uno::RuntimeException )
318 if ( !m_pDisposeEventListeners )
319 m_pDisposeEventListeners = new OInterfaceContainerHelper( m_aMutex );
321 m_pDisposeEventListeners->addInterface( Listener );
324 //=========================================================================
325 // virtual
326 void SAL_CALL UniversalContentBroker::removeEventListener(
327 const Reference< XEventListener >& Listener )
328 throw( com::sun::star::uno::RuntimeException )
330 if ( m_pDisposeEventListeners )
331 m_pDisposeEventListeners->removeInterface( Listener );
333 // Note: Don't want to delete empty container here -> performance.
336 //=========================================================================
338 // XServiceInfo methods.
340 //=========================================================================
342 XSERVICEINFO_IMPL_1( UniversalContentBroker,
343 OUString( "com.sun.star.comp.ucb.UniversalContentBroker" ),
344 OUString( UCB_SERVICE_NAME ) );
346 //=========================================================================
348 // Service factory implementation.
350 //=========================================================================
352 ONE_INSTANCE_SERVICE_FACTORY_IMPL( UniversalContentBroker );
354 //=========================================================================
356 // XInitialization methods.
358 //=========================================================================
360 // virtual
361 void SAL_CALL UniversalContentBroker::initialize(
362 const com::sun::star::uno::Sequence< Any >& aArguments )
363 throw( com::sun::star::uno::Exception,
364 com::sun::star::uno::RuntimeException )
367 osl::MutexGuard aGuard(m_aMutex);
368 if (m_aArguments.getLength() != 0)
370 if (aArguments.getLength() != 0
371 && !(m_aArguments.getLength() == 2
372 && aArguments.getLength() == 2
373 && m_aArguments[0] == aArguments[0]
374 && m_aArguments[1] == aArguments[1]))
376 throw IllegalArgumentException(
377 "UCB reinitialized with different arguments",
378 static_cast< cppu::OWeakObject * >(this), 0);
380 return;
382 if (aArguments.getLength() == 0)
384 m_aArguments.realloc(2);
385 m_aArguments[0] <<= OUString("Local");
386 m_aArguments[1] <<= OUString("Office");
388 else
390 m_aArguments = aArguments;
393 configureUcb();
396 //=========================================================================
398 // XContentProviderManager methods.
400 //=========================================================================
402 // virtual
403 Reference< XContentProvider > SAL_CALL
404 UniversalContentBroker::registerContentProvider(
405 const Reference< XContentProvider >& Provider,
406 const OUString& Scheme,
407 sal_Bool ReplaceExisting )
408 throw( DuplicateProviderException, com::sun::star::uno::RuntimeException )
410 osl::MutexGuard aGuard(m_aMutex);
412 ProviderMap_Impl::iterator aIt;
415 aIt = m_aProviders.find(Scheme);
417 catch (const IllegalArgumentException&)
419 return 0; //@@@
422 Reference< XContentProvider > xPrevious;
423 if (aIt == m_aProviders.end())
425 ProviderList_Impl aList;
426 aList.push_front(Provider);
429 m_aProviders.add(Scheme, aList, false);
431 catch (const IllegalArgumentException&)
433 return 0; //@@@
436 else
438 if (!ReplaceExisting)
439 throw DuplicateProviderException();
441 ProviderList_Impl & rList = aIt->getValue();
442 xPrevious = rList.front().getProvider();
443 rList.push_front(Provider);
446 return xPrevious;
449 //=========================================================================
450 // virtual
451 void SAL_CALL UniversalContentBroker::deregisterContentProvider(
452 const Reference< XContentProvider >& Provider,
453 const OUString& Scheme )
454 throw( com::sun::star::uno::RuntimeException )
456 osl::MutexGuard aGuard(m_aMutex);
458 ProviderMap_Impl::iterator aMapIt;
461 aMapIt = m_aProviders.find(Scheme);
463 catch (const IllegalArgumentException&)
465 return; //@@@
468 if (aMapIt != m_aProviders.end())
470 ProviderList_Impl & rList = aMapIt->getValue();
472 ProviderList_Impl::iterator aListEnd(rList.end());
473 for (ProviderList_Impl::iterator aListIt(rList.begin());
474 aListIt != aListEnd; ++aListIt)
476 if ((*aListIt).getProvider() == Provider)
478 rList.erase(aListIt);
479 break;
483 if (rList.empty())
484 m_aProviders.erase(aMapIt);
488 //=========================================================================
489 // virtual
490 com::sun::star::uno::Sequence< ContentProviderInfo > SAL_CALL
491 UniversalContentBroker::queryContentProviders()
492 throw( com::sun::star::uno::RuntimeException )
494 // Return a list with information about active(!) content providers.
496 osl::MutexGuard aGuard(m_aMutex);
498 com::sun::star::uno::Sequence< ContentProviderInfo > aSeq(
499 m_aProviders.size() );
500 ContentProviderInfo* pInfo = aSeq.getArray();
502 ProviderMap_Impl::const_iterator end = m_aProviders.end();
503 for (ProviderMap_Impl::const_iterator it(m_aProviders.begin()); it != end;
504 ++it)
506 // Note: Active provider is always the first list element.
507 pInfo->ContentProvider = it->getValue().front().getProvider();
508 pInfo->Scheme = it->getRegexp();
509 ++pInfo;
512 return aSeq;
515 //=========================================================================
516 // virtual
517 Reference< XContentProvider > SAL_CALL
518 UniversalContentBroker::queryContentProvider( const OUString&
519 Identifier )
520 throw( com::sun::star::uno::RuntimeException )
522 return queryContentProvider( Identifier, sal_False );
525 //=========================================================================
527 // XContentProvider methods.
529 //=========================================================================
531 // virtual
532 Reference< XContent > SAL_CALL UniversalContentBroker::queryContent(
533 const Reference< XContentIdentifier >& Identifier )
534 throw( IllegalIdentifierException, com::sun::star::uno::RuntimeException )
536 //////////////////////////////////////////////////////////////////////
537 // Let the content provider for the scheme given with the content
538 // identifier create the XContent instance.
539 //////////////////////////////////////////////////////////////////////
541 if ( !Identifier.is() )
542 return Reference< XContent >();
544 Reference< XContentProvider > xProv =
545 queryContentProvider( Identifier->getContentIdentifier(), sal_True );
546 if ( xProv.is() )
547 return xProv->queryContent( Identifier );
549 return Reference< XContent >();
552 //=========================================================================
553 // virtual
554 sal_Int32 SAL_CALL UniversalContentBroker::compareContentIds(
555 const Reference< XContentIdentifier >& Id1,
556 const Reference< XContentIdentifier >& Id2 )
557 throw( com::sun::star::uno::RuntimeException )
559 OUString aURI1( Id1->getContentIdentifier() );
560 OUString aURI2( Id2->getContentIdentifier() );
562 Reference< XContentProvider > xProv1
563 = queryContentProvider( aURI1, sal_True );
564 Reference< XContentProvider > xProv2
565 = queryContentProvider( aURI2, sal_True );
567 // When both identifiers belong to the same provider, let that provider
568 // compare them; otherwise, simply compare the URI strings (which must
569 // be different):
570 if ( xProv1.is() && ( xProv1 == xProv2 ) )
571 return xProv1->compareContentIds( Id1, Id2 );
572 else
573 return aURI1.compareTo( aURI2 );
576 //=========================================================================
578 // XContentIdentifierFactory methods.
580 //=========================================================================
582 // virtual
583 Reference< XContentIdentifier > SAL_CALL
584 UniversalContentBroker::createContentIdentifier(
585 const OUString& ContentId )
586 throw( com::sun::star::uno::RuntimeException )
588 //////////////////////////////////////////////////////////////////////
589 // Let the content provider for the scheme given with content
590 // identifier create the XContentIdentifier instance, if he supports
591 // the XContentIdentifierFactory interface. Otherwise create standard
592 // implementation object for XContentIdentifier.
593 //////////////////////////////////////////////////////////////////////
595 Reference< XContentIdentifier > xIdentifier;
597 Reference< XContentProvider > xProv
598 = queryContentProvider( ContentId, sal_True );
599 if ( xProv.is() )
601 Reference< XContentIdentifierFactory > xFac( xProv, UNO_QUERY );
602 if ( xFac.is() )
603 xIdentifier = xFac->createContentIdentifier( ContentId );
606 if ( !xIdentifier.is() )
607 xIdentifier = new ContentIdentifier( m_xSMgr, ContentId );
609 return xIdentifier;
612 //=========================================================================
614 // XCommandProcessor methods.
616 //=========================================================================
618 // virtual
619 sal_Int32 SAL_CALL UniversalContentBroker::createCommandIdentifier()
620 throw( RuntimeException )
622 osl::MutexGuard aGuard( m_aMutex );
624 // Just increase counter on every call to generate an identifier.
625 return ++m_nCommandId;
628 //=========================================================================
629 // virtual
630 Any SAL_CALL UniversalContentBroker::execute(
631 const Command& aCommand,
632 sal_Int32,
633 const Reference< XCommandEnvironment >& Environment )
634 throw( Exception, CommandAbortedException, RuntimeException )
636 Any aRet;
638 //////////////////////////////////////////////////////////////////////
639 // Note: Don't forget to adapt ucb_commands::CommandProcessorInfo
640 // ctor in ucbcmds.cxx when adding new commands!
641 //////////////////////////////////////////////////////////////////////
643 if ( ( aCommand.Handle == GETCOMMANDINFO_HANDLE ) || aCommand.Name == GETCOMMANDINFO_NAME )
645 //////////////////////////////////////////////////////////////////
646 // getCommandInfo
647 //////////////////////////////////////////////////////////////////
649 aRet <<= getCommandInfo();
651 else if ( ( aCommand.Handle == GLOBALTRANSFER_HANDLE ) || aCommand.Name == GLOBALTRANSFER_NAME )
653 //////////////////////////////////////////////////////////////////
654 // globalTransfer
655 //////////////////////////////////////////////////////////////////
657 GlobalTransferCommandArgument2 aTransferArg;
658 if ( !( aCommand.Argument >>= aTransferArg ) )
660 GlobalTransferCommandArgument aArg;
661 if ( !( aCommand.Argument >>= aArg ) )
663 ucbhelper::cancelCommandExecution(
664 makeAny( IllegalArgumentException(
665 OUString( "Wrong argument type!" ),
666 static_cast< cppu::OWeakObject * >( this ),
667 -1 ) ),
668 Environment );
669 // Unreachable
672 // Copy infos into the new stucture
673 aTransferArg.Operation = aArg.Operation;
674 aTransferArg.SourceURL = aArg.SourceURL;
675 aTransferArg.TargetURL = aArg.TargetURL;
676 aTransferArg.NewTitle = aArg.NewTitle;
677 aTransferArg.NameClash = aArg.NameClash;
680 globalTransfer( aTransferArg, Environment );
682 else if ( ( aCommand.Handle == CHECKIN_HANDLE ) || aCommand.Name == CHECKIN_NAME )
684 ucb::CheckinArgument aCheckinArg;
685 if ( !( aCommand.Argument >>= aCheckinArg ) )
687 ucbhelper::cancelCommandExecution(
688 makeAny( IllegalArgumentException(
689 OUString( "Wrong argument type!" ),
690 static_cast< cppu::OWeakObject * >( this ),
691 -1 ) ),
692 Environment );
693 // Unreachable
695 aRet <<= checkIn( aCheckinArg, Environment );
697 else
699 //////////////////////////////////////////////////////////////////
700 // Unknown command
701 //////////////////////////////////////////////////////////////////
703 ucbhelper::cancelCommandExecution(
704 makeAny( UnsupportedCommandException(
705 OUString(),
706 static_cast< cppu::OWeakObject * >( this ) ) ),
707 Environment );
708 // Unreachable
711 return aRet;
714 //=========================================================================
716 // XCommandProcessor2 methods.
718 //=========================================================================
720 // virtual
721 void SAL_CALL UniversalContentBroker::releaseCommandIdentifier(sal_Int32 /*aCommandId*/)
722 throw( RuntimeException )
724 // @@@ Not implemeted ( yet).
727 //=========================================================================
728 // virtual
729 void SAL_CALL UniversalContentBroker::abort( sal_Int32 )
730 throw( RuntimeException )
732 // @@@ Not implemeted ( yet).
735 //=========================================================================
737 // XChangesListener methods
739 //=========================================================================
740 // virtual
741 void SAL_CALL UniversalContentBroker::changesOccurred( const util::ChangesEvent& Event )
742 throw( uno::RuntimeException )
744 sal_Int32 nCount = Event.Changes.getLength();
745 if ( nCount )
747 uno::Reference< container::XHierarchicalNameAccess > xHierNameAccess;
748 Event.Base >>= xHierNameAccess;
750 OSL_ASSERT( xHierNameAccess.is() );
752 const util::ElementChange* pElementChanges
753 = Event.Changes.getConstArray();
755 ContentProviderDataList aData;
756 for ( sal_Int32 n = 0; n < nCount; ++n )
758 const util::ElementChange& rElem = pElementChanges[ n ];
759 OUString aKey;
760 rElem.Accessor >>= aKey;
762 ContentProviderData aInfo;
764 // Removal of UCPs from the configuration leads to changesOccurred
765 // notifications, too, but it is hard to tell for a given
766 // ElementChange whether it is an addition or a removal, so as a
767 // heuristic consider as removals those that cause a
768 // NoSuchElementException in createContentProviderData.
770 // For now, removal of UCPs from the configuration is simply ignored
771 // (and not reflected in the UCB's data structures):
772 if (createContentProviderData(aKey, xHierNameAccess, aInfo))
774 aData.push_back(aInfo);
778 prepareAndRegister(aData);
782 //=========================================================================
784 // XEventListener methods
786 //=========================================================================
787 // virtual
788 void SAL_CALL UniversalContentBroker::disposing(const lang::EventObject&)
789 throw( uno::RuntimeException )
791 if ( m_xNotifier.is() )
793 osl::Guard< osl::Mutex > aGuard( m_aMutex );
795 if ( m_xNotifier.is() )
796 m_xNotifier.clear();
800 //=========================================================================
802 // Non-interface methods
804 //=========================================================================
806 Reference< XContentProvider > UniversalContentBroker::queryContentProvider(
807 const OUString& Identifier,
808 sal_Bool bResolved )
810 osl::MutexGuard aGuard( m_aMutex );
812 ProviderList_Impl const * pList = m_aProviders.map( Identifier );
813 return pList ? bResolved ? pList->front().getResolvedProvider()
814 : pList->front().getProvider()
815 : Reference< XContentProvider >();
818 bool UniversalContentBroker::configureUcb()
819 throw (uno::RuntimeException)
821 OUString aKey1;
822 OUString aKey2;
823 if (m_aArguments.getLength() < 2
824 || !(m_aArguments[0] >>= aKey1) || !(m_aArguments[1] >>= aKey2))
826 OSL_FAIL("UniversalContentBroker::configureUcb(): Bad arguments");
827 return false;
830 ContentProviderDataList aData;
831 if (!getContentProviderData(aKey1, aKey2, aData))
833 OSL_TRACE("UniversalContentBroker::configureUcb(): No configuration");
834 return false;
837 prepareAndRegister(aData);
839 return true;
842 void UniversalContentBroker::prepareAndRegister(
843 const ContentProviderDataList& rData)
845 ContentProviderDataList::const_iterator aEnd(rData.end());
846 for (ContentProviderDataList::const_iterator aIt(rData.begin());
847 aIt != aEnd; ++aIt)
849 OUString aProviderArguments;
850 if (fillPlaceholders(aIt->Arguments,
851 m_aArguments,
852 &aProviderArguments))
854 registerAtUcb(this,
855 m_xSMgr,
856 aIt->ServiceName,
857 aProviderArguments,
858 aIt->URLTemplate,
862 else
863 OSL_FAIL("UniversalContentBroker::prepareAndRegister(): Bad argument placeholders");
867 //=========================================================================
868 bool UniversalContentBroker::getContentProviderData(
869 const OUString & rKey1,
870 const OUString & rKey2,
871 ContentProviderDataList & rListToFill )
873 if ( !m_xSMgr.is() || rKey1.isEmpty() || rKey2.isEmpty() )
875 OSL_FAIL( "UniversalContentBroker::getContentProviderData - Invalid argument!" );
876 return false;
881 uno::Reference< lang::XMultiServiceFactory > xConfigProv =
882 configuration::theDefaultProvider::get( comphelper::getComponentContext(m_xSMgr) );
884 OUStringBuffer aFullPath;
885 aFullPath.appendAscii( CONFIG_CONTENTPROVIDERS_KEY "/['" );
886 makeAndAppendXMLName( aFullPath, rKey1 );
887 aFullPath.appendAscii( "']/SecondaryKeys/['" );
888 makeAndAppendXMLName( aFullPath, rKey2 );
889 aFullPath.appendAscii( "']/ProviderData" );
891 uno::Sequence< uno::Any > aArguments( 1 );
892 beans::PropertyValue aProperty;
893 aProperty.Name
894 = OUString( "nodepath" );
895 aProperty.Value <<= aFullPath.makeStringAndClear();
896 aArguments[ 0 ] <<= aProperty;
898 uno::Reference< uno::XInterface > xInterface(
899 xConfigProv->createInstanceWithArguments(
900 OUString( "com.sun.star.configuration.ConfigurationAccess" ),
901 aArguments ) );
903 if ( !m_xNotifier.is() )
905 m_xNotifier = uno::Reference< util::XChangesNotifier >(
906 xInterface, uno::UNO_QUERY_THROW );
908 m_xNotifier->addChangesListener( this );
911 uno::Reference< container::XNameAccess > xNameAccess(
912 xInterface, uno::UNO_QUERY_THROW );
914 uno::Sequence< OUString > aElems = xNameAccess->getElementNames();
915 const OUString* pElems = aElems.getConstArray();
916 sal_Int32 nCount = aElems.getLength();
918 if ( nCount > 0 )
920 uno::Reference< container::XHierarchicalNameAccess >
921 xHierNameAccess( xInterface, uno::UNO_QUERY_THROW );
923 // Iterate over children.
924 for ( sal_Int32 n = 0; n < nCount; ++n )
930 ContentProviderData aInfo;
932 OUStringBuffer aElemBuffer;
933 aElemBuffer.appendAscii( "['" );
934 makeAndAppendXMLName( aElemBuffer, pElems[ n ] );
935 aElemBuffer.appendAscii( "']" );
937 OSL_VERIFY(
938 createContentProviderData(
939 aElemBuffer.makeStringAndClear(), xHierNameAccess,
940 aInfo));
942 rListToFill.push_back( aInfo );
944 catch (const container::NoSuchElementException&)
946 // getByHierarchicalName
947 OSL_FAIL( "UniversalContentBroker::getContentProviderData - "
948 "caught NoSuchElementException!" );
953 catch (const uno::RuntimeException&)
955 OSL_TRACE( "UniversalContentBroker::getContentProviderData - caught RuntimeException!" );
956 return false;
958 catch (const uno::Exception&)
960 // createInstance, createInstanceWithArguments
962 OSL_TRACE( "UniversalContentBroker::getContentProviderData - caught Exception!" );
963 return false;
966 return true;
969 //=========================================================================
971 // ProviderListEntry_Impl implementation.
973 //=========================================================================
975 Reference< XContentProvider > ProviderListEntry_Impl::resolveProvider() const
977 if ( !m_xResolvedProvider.is() )
979 Reference< XContentProviderSupplier > xSupplier(
980 m_xProvider, UNO_QUERY );
981 if ( xSupplier.is() )
982 m_xResolvedProvider = xSupplier->getContentProvider();
984 if ( !m_xResolvedProvider.is() )
985 m_xResolvedProvider = m_xProvider;
988 return m_xResolvedProvider;
991 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */