1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <comphelper/processfactory.hxx>
11 #include <cppuhelper/queryinterface.hxx>
12 #include <cppuhelper/weak.hxx>
13 #include <ucbhelper/contenthelper.hxx>
14 #include <ucbhelper/macros.hxx>
15 #include <com/sun/star/ucb/ContentCreationException.hpp>
16 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
18 #include "cmis_content.hxx"
19 #include "cmis_provider.hxx"
20 #include "cmis_repo_content.hxx"
22 using namespace com::sun::star
;
26 uno::Reference
< css::ucb::XContent
> SAL_CALL
27 ContentProvider::queryContent(
28 const uno::Reference
< css::ucb::XContentIdentifier
>& Identifier
)
30 osl::MutexGuard
aGuard( m_aMutex
);
32 // Check, if a content with given id already exists...
33 uno::Reference
< ucb::XContent
> xContent
= queryExistingContent( Identifier
);
39 URL
aUrl( Identifier
->getContentIdentifier( ) );
40 if ( aUrl
.getRepositoryId( ).isEmpty( ) )
42 xContent
= new RepoContent( m_xContext
, this, Identifier
);
43 registerNewContent( xContent
);
47 xContent
= new Content( m_xContext
, this, Identifier
);
48 registerNewContent( xContent
);
51 catch ( css::ucb::ContentCreationException
const & )
53 throw css::ucb::IllegalIdentifierException();
56 if ( !xContent
->getIdentifier().is() )
57 throw css::ucb::IllegalIdentifierException();
62 libcmis::Session
* ContentProvider::getSession( const OUString
& sBindingUrl
, const OUString
& sUsername
)
64 libcmis::Session
* pSession
= nullptr;
65 std::map
< std::pair
< OUString
, OUString
>, libcmis::Session
* >::iterator it
66 = m_aSessionCache
.find( std::pair
< OUString
, OUString
>( sBindingUrl
, sUsername
) );
67 if ( it
!= m_aSessionCache
.end( ) )
69 pSession
= it
->second
;
74 void ContentProvider::registerSession( const OUString
& sBindingUrl
, const OUString
& sUsername
, libcmis::Session
* pSession
)
76 m_aSessionCache
.insert( std::pair
< std::pair
< OUString
, OUString
>, libcmis::Session
* >
78 std::pair
< OUString
, OUString
>( sBindingUrl
, sUsername
),
83 ContentProvider::ContentProvider(
84 const uno::Reference
< uno::XComponentContext
>& rxContext
)
85 : ::ucbhelper::ContentProviderImplHelper( rxContext
)
89 ContentProvider::~ContentProvider()
94 void SAL_CALL
ContentProvider::acquire()
97 OWeakObject::acquire();
100 void SAL_CALL
ContentProvider::release()
103 OWeakObject::release();
106 css::uno::Any SAL_CALL
ContentProvider::queryInterface( const css::uno::Type
& rType
)
108 css::uno::Any aRet
= cppu::queryInterface( rType
,
109 static_cast< lang::XTypeProvider
* >(this),
110 static_cast< lang::XServiceInfo
* >(this),
111 static_cast< css::ucb::XContentProvider
* >(this)
113 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
116 XTYPEPROVIDER_IMPL_3( ContentProvider
,
119 css::ucb::XContentProvider
);
121 sal_Bool
ContentProvider::supportsService(const OUString
& sServiceName
)
123 return cppu::supportsService(this, sServiceName
);
125 OUString
ContentProvider::getImplementationName()
127 return "com.sun.star.comp.CmisContentProvider";
129 css::uno::Sequence
< OUString
> ContentProvider::getSupportedServiceNames()
131 return { "com.sun.star.ucb.CmisContentProvider" };
136 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
137 ucb_cmis_ContentProvider_get_implementation(
138 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
140 return cppu::acquire(new cmis::ContentProvider(context
));
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */