bump product version to 4.1.6.2
[LibreOffice.git] / ucb / source / ucp / cmis / cmis_provider.cxx
blob9938bb5875a850a4abccb6150553928c61906ec9
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/.
8 */
10 #include <stdio.h>
12 #include <comphelper/processfactory.hxx>
13 #include <ucbhelper/contentidentifier.hxx>
14 #include <ucbhelper/contenthelper.hxx>
15 #include <com/sun/star/ucb/ContentCreationException.hpp>
17 #include "cmis_content.hxx"
18 #include "cmis_provider.hxx"
19 #include "cmis_repo_content.hxx"
21 using namespace com::sun::star;
23 namespace cmis
25 uno::Reference< com::sun::star::ucb::XContent > SAL_CALL
26 ContentProvider::queryContent(
27 const uno::Reference<
28 com::sun::star::ucb::XContentIdentifier >& Identifier )
29 throw( com::sun::star::ucb::IllegalIdentifierException,
30 uno::RuntimeException )
32 osl::MutexGuard aGuard( m_aMutex );
34 // Check, if a content with given id already exists...
35 uno::Reference< ucb::XContent > xContent = queryExistingContent( Identifier ).get();
36 if ( xContent.is() )
37 return xContent;
39 try
41 URL aUrl( Identifier->getContentIdentifier( ) );
42 if ( aUrl.getRepositoryId( ).isEmpty( ) )
44 xContent = new RepoContent( m_xContext, this, Identifier );
45 registerNewContent( xContent );
47 else
49 xContent = new Content( m_xContext, this, Identifier );
50 registerNewContent( xContent );
53 catch ( com::sun::star::ucb::ContentCreationException const & )
55 throw com::sun::star::ucb::IllegalIdentifierException();
58 if ( !xContent->getIdentifier().is() )
59 throw com::sun::star::ucb::IllegalIdentifierException();
61 return xContent;
64 libcmis::Session* ContentProvider::getSession( const OUString& sBindingUrl )
66 libcmis::Session* pSession = NULL;
67 std::map< OUString, libcmis::Session* >::iterator it = m_aSessionCache.find( sBindingUrl );
68 if ( it != m_aSessionCache.end( ) )
70 pSession = it->second;
72 return pSession;
75 void ContentProvider::registerSession( const OUString& sBindingUrl, libcmis::Session* pSession )
77 m_aSessionCache.insert( std::pair< OUString, libcmis::Session* >( sBindingUrl, pSession ) );
80 ContentProvider::ContentProvider(
81 const uno::Reference< uno::XComponentContext >& rxContext )
82 : ::ucbhelper::ContentProviderImplHelper( rxContext )
86 ContentProvider::~ContentProvider()
90 XINTERFACE_IMPL_3( ContentProvider,
91 lang::XTypeProvider,
92 lang::XServiceInfo,
93 com::sun::star::ucb::XContentProvider );
95 XTYPEPROVIDER_IMPL_3( ContentProvider,
96 lang::XTypeProvider,
97 lang::XServiceInfo,
98 com::sun::star::ucb::XContentProvider );
100 XSERVICEINFO_IMPL_1_CTX( ContentProvider,
101 OUString("com.sun.star.comp.CmisContentProvider"),
102 OUString("com.sun.star.ucb.CmisContentProvider") );
104 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
108 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL ucpcmis1_component_getFactory( const sal_Char *pImplName,
109 void *pServiceManager, void * )
111 void * pRet = 0;
113 uno::Reference< lang::XMultiServiceFactory > xSMgr
114 (reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) );
115 uno::Reference< lang::XSingleServiceFactory > xFactory;
117 if ( !::cmis::ContentProvider::getImplementationName_Static().compareToAscii( pImplName ) )
118 xFactory = ::cmis::ContentProvider::createServiceFactory( xSMgr );
120 if ( xFactory.is() )
122 xFactory->acquire();
123 pRet = xFactory.get();
126 return pRet;
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */