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 
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 ).get();
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 
83 ContentProvider::ContentProvider(
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  throw()
96 {
97  OWeakObject::acquire();
98 }
99 
101  throw()
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 
122  "com.sun.star.comp.CmisContentProvider" )
124 static css::uno::Reference< css::uno::XInterface >
125 ContentProvider_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr )
126 {
127  css::lang::XServiceInfo* pX = new ContentProvider( ucbhelper::getComponentContext(rSMgr) );
128  return css::uno::Reference< css::uno::XInterface >::query( pX );
129 }
130 
131 css::uno::Sequence< OUString >
133 {
134  css::uno::Sequence< OUString > aSNS { "com.sun.star.ucb.CmisContentProvider" };
135  return aSNS;
136 }
137 
139 
140 }
141 
142 extern "C" SAL_DLLPUBLIC_EXPORT void * ucpcmis1_component_getFactory( const sal_Char *pImplName,
143  void *pServiceManager, void * )
144 {
145  void * pRet = nullptr;
146 
147  uno::Reference< lang::XMultiServiceFactory > xSMgr
148  (static_cast< lang::XMultiServiceFactory * >( pServiceManager ) );
149  uno::Reference< lang::XSingleServiceFactory > xFactory;
150 
151  if ( ::cmis::ContentProvider::getImplementationName_Static().equalsAscii( pImplName ) )
153 
154  if ( xFactory.is() )
155  {
156  xFactory->acquire();
157  pRet = xFactory.get();
158  }
159 
160  return pRet;
161 }
162 
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XSERVICEINFO_COMMOM_IMPL(ContentProvider,"com.sun.star.comp.CmisContentProvider") static css
SAL_DLLPUBLIC_EXPORT void * ucpcmis1_component_getFactory(const sal_Char *pImplName, void *pServiceManager, void *)
static css::uno::Reference< css::lang::XSingleServiceFactory > createServiceFactory(const css::uno::Reference< css::lang::XMultiServiceFactory > &rxServiceMgr)
ONE_INSTANCE_SERVICE_FACTORY_IMPL(ContentProvider)
UCBHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > getComponentContext(css::uno::Reference< css::lang::XMultiServiceFactory > const &factory)
char sal_Char
static css::uno::Sequence< OUString > getSupportedServiceNames_Static()
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual ~ContentProvider() override
static OUString getImplementationName_Static()
virtual void SAL_CALL release() override
XTYPEPROVIDER_IMPL_3(ContentProvider, lang::XTypeProvider, lang::XServiceInfo, css::ucb::XContentProvider)
virtual void SAL_CALL acquire() override
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)