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.
85 
86 OUString
88 {
89  return "com.sun.star.comp.WebDAVContentProvider";
90 }
91 
92 css::uno::Sequence< OUString >
94 {
96 }
97 
100 {
101  return cppu::supportsService(this, s);
102 }
103 
104 // XContentProvider methods.
105 
106 
107 // virtual
108 uno::Reference< ucb::XContent > SAL_CALL
110  const uno::Reference<
111  ucb::XContentIdentifier >& Identifier )
112 {
113  // Check URL scheme...
114  INetURLObject aURL(Identifier->getContentIdentifier());
115 
116  if (aURL.isSchemeEqualTo(INetProtocol::NotValid))
117  throw ucb::IllegalIdentifierException();
118 
119  if (!aURL.isAnyKnownWebDAVScheme())
120  throw ucb::IllegalIdentifierException();
121 
122  uno::Reference< ucb::XContentIdentifier > xCanonicId;
123 
124  if (aURL.isSchemeEqualTo(INetProtocol::VndSunStarWebdav) ||
125  aURL.isSchemeEqualTo(DAV_URL_SCHEME) ||
126  aURL.isSchemeEqualTo(WEBDAV_URL_SCHEME))
127  {
128  aURL.changeScheme(INetProtocol::Http);
129  xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
130  }
131  else if (aURL.isSchemeEqualTo(VNDSUNSTARWEBDAVS_URL_SCHEME) ||
132  aURL.isSchemeEqualTo(DAVS_URL_SCHEME) ||
133  aURL.isSchemeEqualTo(WEBDAVS_URL_SCHEME))
134  {
135  aURL.changeScheme(INetProtocol::Https);
136  xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
137  }
138  else
139  {
140  xCanonicId = Identifier;
141  }
142 
143  osl::MutexGuard aGuard( m_aMutex );
144 
145  // Check, if a content with given id already exists...
146  uno::Reference< ucb::XContent > xContent
147  = queryExistingContent( xCanonicId ).get();
148  if ( xContent.is() )
149  return xContent;
150 
151  // Create a new content.
152 
153  try
154  {
155  xContent = new ::http_dav_ucp::Content(
156  m_xContext, this, xCanonicId, m_xDAVSessionFactory );
157  registerNewContent( xContent );
158  }
159  catch ( ucb::ContentCreationException const & )
160  {
161  throw ucb::IllegalIdentifierException();
162  }
163 
164  if ( !xContent->getIdentifier().is() )
165  throw ucb::IllegalIdentifierException();
166 
167  return xContent;
168 }
169 
170 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
172  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
173 {
174  return cppu::acquire(new ContentProvider(context));
175 }
176 
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
URL aURL
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL acquire() noexcept 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)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ucb_webdav_ContentProvider_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) 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
virtual void SAL_CALL release() noexcept override
css::uno::Reference< css::uno::XComponentContext > m_xContext
void registerNewContent(const css::uno::Reference< css::ucb::XContent > &xContent)
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