Debian Codegraph @

ucb/source/ucp/cmis/cmis_provider.cxx

raw
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
10 #include <comphelper/processfactory.hxx>
11 #include <cppuhelper/queryinterface.hxx>
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
21 using namespace com::sun::star;
22
23 namespace cmis
24 {
25 uno::Reference< css::ucb::XContent > SAL_CALL
26 ContentProvider::queryContent(
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
61 libcmis::Session* ContentProvider::getSession( const OUString& sBindingUrl, const OUString& sUsername )
62 {
63 auto it = m_aSessionCache.find(std::make_pair(sBindingUrl, sUsername));
64 if ( it != m_aSessionCache.end( ) )
65 {
66 return it->second;
67 }
68 return nullptr;
69 }
70
71 void ContentProvider::registerSession( const OUString& sBindingUrl, const OUString& sUsername, libcmis::Session* pSession )
72 {
73 m_aSessionCache.emplace(std::make_pair(sBindingUrl, sUsername), pSession);
74 }
75
76 ContentProvider::ContentProvider(
77 const uno::Reference< uno::XComponentContext >& rxContext )
78 : ::ucbhelper::ContentProviderImplHelper( rxContext )
79 {
80 }
81
82 ContentProvider::~ContentProvider()
83 {
84 }
85
86 //XInterface
87 void SAL_CALL ContentProvider::acquire()
88 noexcept
89 {
90 OWeakObject::acquire();
91 }
92
93 void SAL_CALL ContentProvider::release()
94 noexcept
95 {
96 OWeakObject::release();
97 }
98
99 css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & rType )
100 {
101 css::uno::Any aRet = cppu::queryInterface( rType,
102 static_cast< lang::XTypeProvider* >(this),
103 static_cast< lang::XServiceInfo* >(this),
104 static_cast< css::ucb::XContentProvider* >(this)
105 );
106 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
107 }
108
109 XTYPEPROVIDER_IMPL_3( ContentProvider,
110 lang::XTypeProvider,
111 lang::XServiceInfo,
112 css::ucb::XContentProvider );
113
114 sal_Bool ContentProvider::supportsService(const OUString& sServiceName)
115 {
116 return cppu::supportsService(this, sServiceName);
117 }
118 OUString ContentProvider::getImplementationName()
119 {
120 return u"com.sun.star.comp.CmisContentProvider"_ustr;
121 }
122 css::uno::Sequence< OUString > ContentProvider::getSupportedServiceNames()
123 {
124 return { u"com.sun.star.ucb.CmisContentProvider"_ustr };
125 }
126
127 }
128
129 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
130 ucb_cmis_ContentProvider_get_implementation(
131 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
132 {
133 return cppu::acquire(new cmis::ContentProvider(context));
134 }
135
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */