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
32using namespace com::sun::star;
33using 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
48ContentProvider::~ContentProvider()
49{}
50
51
52// XInterface methods.
53void SAL_CALL ContentProvider::acquire() noexcept
54{
55 OWeakObject::acquire();
56}
57
58void SAL_CALL ContentProvider::release() noexcept
59{
60 OWeakObject::release();
61}
62
63css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & rType )
64{
65 css::uno::Any aRet = cppu::queryInterface( rType,
66 static_cast< lang::XTypeProvider* >(this),
67 static_cast< lang::XServiceInfo* >(this),
68 static_cast< ucb::XContentProvider* >(this)
69 );
70 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
71}
72
73// XTypeProvider methods.
74
75
77 lang::XTypeProvider,
78 lang::XServiceInfo,
79 ucb::XContentProvider );
80
81
82// XServiceInfo methods.
83
84OUString
86{
87 return "com.sun.star.comp.WebDAVContentProvider";
88}
89
90css::uno::Sequence< OUString >
92{
94}
95
98{
99 return cppu::supportsService(this, s);
100}
101
102// XContentProvider methods.
103
104
105// virtual
106uno::Reference< ucb::XContent > SAL_CALL
108 const uno::Reference<
109 ucb::XContentIdentifier >& Identifier )
110{
111 // Check URL scheme...
112 INetURLObject aURL(Identifier->getContentIdentifier());
113
114 if (aURL.isSchemeEqualTo(INetProtocol::NotValid))
115 throw ucb::IllegalIdentifierException();
116
117 if (!aURL.isAnyKnownWebDAVScheme())
118 throw ucb::IllegalIdentifierException();
119
120 uno::Reference< ucb::XContentIdentifier > xCanonicId;
121
122 if (aURL.isSchemeEqualTo(INetProtocol::VndSunStarWebdav) ||
123 aURL.isSchemeEqualTo(DAV_URL_SCHEME) ||
124 aURL.isSchemeEqualTo(WEBDAV_URL_SCHEME))
125 {
126 aURL.changeScheme(INetProtocol::Http);
127 xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
128 }
129 else if (aURL.isSchemeEqualTo(VNDSUNSTARWEBDAVS_URL_SCHEME) ||
130 aURL.isSchemeEqualTo(DAVS_URL_SCHEME) ||
131 aURL.isSchemeEqualTo(WEBDAVS_URL_SCHEME))
132 {
133 aURL.changeScheme(INetProtocol::Https);
134 xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
135 }
136 else
137 {
138 xCanonicId = Identifier;
139 }
140
141 osl::MutexGuard aGuard( m_aMutex );
142
143 // Check, if a content with given id already exists...
144 uno::Reference<ucb::XContent> xContent = queryExistingContent(xCanonicId);
145 if ( xContent.is() )
146 return xContent;
147
148 // Create a new content.
149
150 try
151 {
152 xContent = new ::http_dav_ucp::Content(
153 m_xContext, this, xCanonicId, m_xDAVSessionFactory );
154 registerNewContent( xContent );
155 }
156 catch ( ucb::ContentCreationException const & )
157 {
158 throw ucb::IllegalIdentifierException();
159 }
160
161 if ( !xContent->getIdentifier().is() )
162 throw ucb::IllegalIdentifierException();
163
164 return xContent;
165}
166
167extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
169 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
170{
171 return cppu::acquire(new ContentProvider(context));
172}
173
174/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
virtual void SAL_CALL release() noexcept override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL acquire() noexcept override
rtl::Reference< DAVSessionFactory > m_xDAVSessionFactory
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
rtl::Reference< ContentImplHelper > queryExistingContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
void registerNewContent(const css::uno::Reference< css::ucb::XContent > &xContent)
css::uno::Reference< css::uno::XComponentContext > m_xContext
URL aURL
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral WEBDAV_CONTENT_PROVIDER_SERVICE_NAME
friend ContentProvider
Definition: pkgprovider.cxx:54
unsigned char sal_Bool
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ucb_webdav_ContentProvider_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
XTYPEPROVIDER_IMPL_3(ContentProvider, lang::XTypeProvider, lang::XServiceInfo, ucb::XContentProvider)
#define DAV_URL_SCHEME
#define DAVS_URL_SCHEME
#define WEBDAV_URL_SCHEME
#define WEBDAVS_URL_SCHEME
#define VNDSUNSTARWEBDAVS_URL_SCHEME