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>
14 #include <ucbhelper/macros.hxx>
15 #include <com/sun/star/ucb/ContentCreationException.hpp>
16 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
17 
18 #include "cmis_content.hxx"
19 #include "cmis_provider.hxx"
20 #include "cmis_repo_content.hxx"
21 
22 using namespace com::sun::star;
23 
24 namespace cmis
25 {
26 uno::Reference< css::ucb::XContent > SAL_CALL
27 ContentProvider::queryContent(
28  const uno::Reference< css::ucb::XContentIdentifier >& Identifier )
29 {
30  osl::MutexGuard aGuard( m_aMutex );
31 
32  // Check, if a content with given id already exists...
33  uno::Reference< ucb::XContent > xContent = queryExistingContent( Identifier );
34  if ( xContent.is() )
35  return xContent;
36 
37  try
38  {
39  URL aUrl( Identifier->getContentIdentifier( ) );
40  if ( aUrl.getRepositoryId( ).isEmpty( ) )
41  {
42  xContent = new RepoContent( m_xContext, this, Identifier );
43  registerNewContent( xContent );
44  }
45  else
46  {
47  xContent = new Content( m_xContext, this, Identifier );
48  registerNewContent( xContent );
49  }
50  }
51  catch ( css::ucb::ContentCreationException const & )
52  {
53  throw css::ucb::IllegalIdentifierException();
54  }
55 
56  if ( !xContent->getIdentifier().is() )
57  throw css::ucb::IllegalIdentifierException();
58 
59  return xContent;
60 }
61 
62 libcmis::Session* ContentProvider::getSession( const OUString& sBindingUrl, const OUString& sUsername )
63 {
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( ) )
68  {
69  pSession = it->second;
70  }
71  return pSession;
72 }
73 
74 void ContentProvider::registerSession( const OUString& sBindingUrl, const OUString& sUsername, libcmis::Session* pSession )
75 {
76  m_aSessionCache.insert( std::pair< std::pair< OUString, OUString >, libcmis::Session* >
77  (
78  std::pair< OUString, OUString >( sBindingUrl, sUsername ),
79  pSession
80  ) );
81 }
82 
84  const uno::Reference< uno::XComponentContext >& rxContext )
85 : ::ucbhelper::ContentProviderImplHelper( rxContext )
86 {
87 }
88 
90 {
91 }
92 
93 //XInterface
94 void SAL_CALL ContentProvider::acquire()
95  noexcept
96 {
97  OWeakObject::acquire();
98 }
99 
101  noexcept
102 {
103  OWeakObject::release();
104 }
105 
106 css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & rType )
107 {
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)
112  );
113  return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
114 }
115 
117  lang::XTypeProvider,
118  lang::XServiceInfo,
119  css::ucb::XContentProvider );
120 
121 sal_Bool ContentProvider::supportsService(const OUString& sServiceName)
122 {
123  return cppu::supportsService(this, sServiceName);
124 }
126 {
127  return "com.sun.star.comp.CmisContentProvider";
128 }
129 css::uno::Sequence< OUString > ContentProvider::getSupportedServiceNames()
130 {
131  return { "com.sun.star.ucb.CmisContentProvider" };
132 }
133 
134 }
135 
136 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
138  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
139 {
140  return cppu::acquire(new cmis::ContentProvider(context));
141 }
142 
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL acquire() noexcept override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::mutex m_aMutex
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
unsigned char sal_Bool
virtual ~ContentProvider() override
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)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
friend ContentProvider
Definition: pkgprovider.cxx:53
virtual OUString SAL_CALL getImplementationName() override
::rtl::Reference< OContentHelper > xContent
virtual void SAL_CALL release() noexcept override
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)