LibreOffice Module ucb (master)  1
webdavprovider.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  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
22 #include <ucbhelper/macros.hxx>
23 #include "webdavprovider.hxx"
24 #include "webdavcontent.hxx"
25 
27 #include <osl/mutex.hxx>
28 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
29 
30 #include <tools/urlobj.hxx>
31 
32 using namespace com::sun::star;
33 using namespace http_dav_ucp;
34 
35 
36 // ContentProvider Implementation.
37 
38 
40  const uno::Reference< uno::XComponentContext >& rContext )
41 : ::ucbhelper::ContentProviderImplHelper( rContext ),
42  m_xDAVSessionFactory( new DAVSessionFactory )
43 {
44 }
45 
46 
47 // virtual
49 {}
50 
51 
52 // XInterface methods.
53 void SAL_CALL ContentProvider::acquire()
54  throw()
55 {
56  OWeakObject::acquire();
57 }
58 
59 void SAL_CALL ContentProvider::release()
60  throw()
61 {
62  OWeakObject::release();
63 }
64 
65 css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & rType )
66 {
67  css::uno::Any aRet = cppu::queryInterface( rType,
68  static_cast< lang::XTypeProvider* >(this),
69  static_cast< lang::XServiceInfo* >(this),
70  static_cast< ucb::XContentProvider* >(this)
71  );
72  return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
73 }
74 
75 // XTypeProvider methods.
76 
77 
79  lang::XTypeProvider,
80  lang::XServiceInfo,
81  ucb::XContentProvider );
82 
83 
84 // XServiceInfo methods.
86 {
87  return getImplementationName_Static();
88 }
89 
90 OUString ContentProvider::getImplementationName_Static()
91 {
92  return "com.sun.star.comp.WebDAVContentProvider";
93 }
94 
95 sal_Bool SAL_CALL ContentProvider::supportsService( const OUString& ServiceName )
96 {
97  return cppu::supportsService( this, ServiceName );
98 }
99 
100 css::uno::Sequence< OUString > SAL_CALL ContentProvider::getSupportedServiceNames()
101 {
102  return getSupportedServiceNames_Static();
103 }
104 
106 static css::uno::Reference< css::uno::XInterface >
107 ContentProvider_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr )
108 {
109  css::lang::XServiceInfo* pX =
110  static_cast<css::lang::XServiceInfo*>(new ContentProvider( comphelper::getComponentContext(rSMgr) ));
111  return css::uno::Reference< css::uno::XInterface >::query( pX );
112 }
113 
114 css::uno::Sequence< OUString >
115 ContentProvider::getSupportedServiceNames_Static()
116 {
117  css::uno::Sequence< OUString > aSNS { WEBDAV_CONTENT_PROVIDER_SERVICE_NAME };
118  return aSNS;
119 }
120 
121 // Service factory implementation.
122 
123 css::uno::Reference< css::lang::XSingleServiceFactory >
124 ContentProvider::createServiceFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& rxServiceMgr )
125 {
127  rxServiceMgr,
128  ContentProvider::getImplementationName_Static(),
130  ContentProvider::getSupportedServiceNames_Static() );
131 }
132 
133 
134 
135 // XContentProvider methods.
136 
137 
138 // virtual
139 uno::Reference< ucb::XContent > SAL_CALL
141  const uno::Reference<
142  ucb::XContentIdentifier >& Identifier )
143 {
144  // Check URL scheme...
145  INetURLObject aURL(Identifier->getContentIdentifier());
146 
147  if (aURL.isSchemeEqualTo(INetProtocol::NotValid))
148  throw ucb::IllegalIdentifierException();
149 
150  if (!aURL.isAnyKnownWebDAVScheme())
151  throw ucb::IllegalIdentifierException();
152 
153  uno::Reference< ucb::XContentIdentifier > xCanonicId;
154 
155  if (aURL.isSchemeEqualTo(INetProtocol::VndSunStarWebdav) ||
156  aURL.isSchemeEqualTo(DAV_URL_SCHEME) ||
157  aURL.isSchemeEqualTo(WEBDAV_URL_SCHEME))
158  {
159  aURL.changeScheme(INetProtocol::Http);
160  xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
161  }
162  else if (aURL.isSchemeEqualTo(VNDSUNSTARWEBDAVS_URL_SCHEME) ||
163  aURL.isSchemeEqualTo(DAVS_URL_SCHEME) ||
164  aURL.isSchemeEqualTo(WEBDAVS_URL_SCHEME))
165  {
166  aURL.changeScheme(INetProtocol::Https);
167  xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
168  }
169  else
170  {
171  xCanonicId = Identifier;
172  }
173 
174  osl::MutexGuard aGuard( m_aMutex );
175 
176  // Check, if a content with given id already exists...
177  uno::Reference< ucb::XContent > xContent
178  = queryExistingContent( xCanonicId ).get();
179  if ( xContent.is() )
180  return xContent;
181 
182  // Create a new content.
183 
184  try
185  {
186  xContent = new ::http_dav_ucp::Content(
187  m_xContext, this, xCanonicId, m_xDAVSessionFactory );
188  registerNewContent( xContent );
189  }
190  catch ( ucb::ContentCreationException const & )
191  {
192  throw ucb::IllegalIdentifierException();
193  }
194 
195  if ( !xContent->getIdentifier().is() )
196  throw ucb::IllegalIdentifierException();
197 
198  return xContent;
199 }
200 
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
#define DAVS_URL_SCHEME
#define WEBDAV_CONTENT_PROVIDER_SERVICE_NAME
#define WEBDAV_URL_SCHEME
XTYPEPROVIDER_IMPL_3(ContentProvider, lang::XTypeProvider, lang::XServiceInfo, ucb::XContentProvider)
#define WEBDAVS_URL_SCHEME
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual void SAL_CALL acquire() override
static css::uno::Reference< css::uno::XInterface > ContentProvider_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory > &rSMgr)
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
virtual void SAL_CALL release() override
#define DAV_URL_SCHEME
unsigned char sal_Bool
rtl::Reference< ContentImplHelper > queryExistingContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
#define VNDSUNSTARWEBDAVS_URL_SCHEME
OUString aURL
css::uno::Reference< css::uno::XComponentContext > m_xContext
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
void registerNewContent(const css::uno::Reference< css::ucb::XContent > &xContent)
Reference< XSingleServiceFactory > SAL_CALL createOneInstanceFactory(const Reference< XMultiServiceFactory > &rServiceManager, const OUString &rImplementationName, ComponentInstantiation pCreateFunction, const Sequence< OUString > &rServiceNames, rtl_ModuleCount *)
virtual OUString SAL_CALL getImplementationName() override
rtl::Reference< DAVSessionFactory > m_xDAVSessionFactory
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
friend ContentProvider
Definition: pkgprovider.cxx:53
uno::Reference< ucb::XContent > xContent
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override