LibreOffice Module ucb (master) 1
cmis_provider.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
12#include <cppuhelper/weak.hxx>
13#include <ucbhelper/macros.hxx>
14#include <com/sun/star/ucb/ContentCreationException.hpp>
15#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
16
17#include "cmis_content.hxx"
18#include "cmis_provider.hxx"
19#include "cmis_repo_content.hxx"
20
21using namespace com::sun::star;
22
23namespace cmis
24{
25uno::Reference< css::ucb::XContent > SAL_CALL
27 const uno::Reference< css::ucb::XContentIdentifier >& Identifier )
28{
29 osl::MutexGuard aGuard( m_aMutex );
30
31 // Check, if a content with given id already exists...
32 uno::Reference< ucb::XContent > xContent = queryExistingContent( Identifier );
33 if ( xContent.is() )
34 return xContent;
35
36 try
37 {
38 URL aUrl( Identifier->getContentIdentifier( ) );
39 if ( aUrl.getRepositoryId( ).isEmpty( ) )
40 {
41 xContent = new RepoContent( m_xContext, this, Identifier );
42 registerNewContent( xContent );
43 }
44 else
45 {
46 xContent = new Content( m_xContext, this, Identifier );
47 registerNewContent( xContent );
48 }
49 }
50 catch ( css::ucb::ContentCreationException const & )
51 {
52 throw css::ucb::IllegalIdentifierException();
53 }
54
55 if ( !xContent->getIdentifier().is() )
56 throw css::ucb::IllegalIdentifierException();
57
58 return xContent;
59}
60
61libcmis::Session* ContentProvider::getSession( const OUString& sBindingUrl, const OUString& sUsername )
62{
63 libcmis::Session* pSession = nullptr;
64 std::map< std::pair< OUString, OUString >, libcmis::Session* >::iterator it
65 = m_aSessionCache.find( std::pair< OUString, OUString >( sBindingUrl, sUsername ) );
66 if ( it != m_aSessionCache.end( ) )
67 {
68 pSession = it->second;
69 }
70 return pSession;
71}
72
73void ContentProvider::registerSession( const OUString& sBindingUrl, const OUString& sUsername, libcmis::Session* pSession )
74{
75 m_aSessionCache.insert( std::pair< std::pair< OUString, OUString >, libcmis::Session* >
76 (
77 std::pair< OUString, OUString >( sBindingUrl, sUsername ),
78 pSession
79 ) );
80}
81
83 const uno::Reference< uno::XComponentContext >& rxContext )
84: ::ucbhelper::ContentProviderImplHelper( rxContext )
85{
86}
87
89{
90}
91
92//XInterface
94 noexcept
95{
96 OWeakObject::acquire();
97}
98
100 noexcept
101{
102 OWeakObject::release();
103}
104
105css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & rType )
106{
107 css::uno::Any aRet = cppu::queryInterface( rType,
108 static_cast< lang::XTypeProvider* >(this),
109 static_cast< lang::XServiceInfo* >(this),
110 static_cast< css::ucb::XContentProvider* >(this)
111 );
112 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
113}
114
116 lang::XTypeProvider,
117 lang::XServiceInfo,
118 css::ucb::XContentProvider );
119
120sal_Bool ContentProvider::supportsService(const OUString& sServiceName)
121{
123}
125{
126 return "com.sun.star.comp.CmisContentProvider";
127}
128css::uno::Sequence< OUString > ContentProvider::getSupportedServiceNames()
129{
130 return { "com.sun.star.ucb.CmisContentProvider" };
131}
132
133}
134
135extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
137 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
138{
139 return cppu::acquire(new cmis::ContentProvider(context));
140}
141
142/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sServiceName
ContentProvider(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
void registerSession(const OUString &sBindingUrl, const OUString &sUsername, libcmis::Session *pSession)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
std::map< std::pair< OUString, OUString >, libcmis::Session * > m_aSessionCache
virtual void SAL_CALL acquire() noexcept override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
libcmis::Session * getSession(const OUString &sBindingUrl, const OUString &sUsername)
virtual void SAL_CALL release() noexcept override
virtual ~ContentProvider() override
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
rtl::Reference< ContentImplHelper > queryExistingContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
void registerNewContent(const css::uno::Reference< css::ucb::XContent > &xContent)
css::uno::Reference< css::uno::XComponentContext > m_xContext
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ucb_cmis_ContentProvider_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
XTYPEPROVIDER_IMPL_3(ContentProvider, lang::XTypeProvider, lang::XServiceInfo, css::ucb::XContentProvider)
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool