| 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 |
|
| 20 |
#include <comphelper/processfactory.hxx> |
| 21 |
#include <ucbhelper/contentidentifier.hxx> |
| 22 |
#include <ucbhelper/macros.hxx> |
| 23 |
#include "webdavprovider.hxx" |
| 24 |
#include "webdavcontent.hxx" |
| 25 |
|
| 26 |
#include <cppuhelper/queryinterface.hxx> |
| 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 |
|
| 39 |
ContentProvider::ContentProvider( |
| 40 |
const uno::Reference< uno::XComponentContext >& rContext ) |
| 41 |
: ::ucbhelper::ContentProviderImplHelper( rContext ), |
| 42 |
m_xDAVSessionFactory( new DAVSessionFactory ) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
// virtual |
| 48 |
ContentProvider::~ContentProvider() |
| 49 |
{} |
| 50 |
|
| 51 |
|
| 52 |
// XInterface methods. |
| 53 |
void SAL_CALL ContentProvider::acquire() noexcept |
| 54 |
{ |
| 55 |
OWeakObject::acquire(); |
| 56 |
} |
| 57 |
|
| 58 |
void SAL_CALL ContentProvider::release() noexcept |
| 59 |
{ |
| 60 |
OWeakObject::release(); |
| 61 |
} |
| 62 |
|
| 63 |
css::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 |
|
| 76 |
XTYPEPROVIDER_IMPL_3( ContentProvider, |
| 77 |
lang::XTypeProvider, |
| 78 |
lang::XServiceInfo, |
| 79 |
ucb::XContentProvider ); |
| 80 |
|
| 81 |
|
| 82 |
// XServiceInfo methods. |
| 83 |
|
| 84 |
OUString |
| 85 |
ContentProvider::getImplementationName() |
| 86 |
{ |
| 87 |
return u"com.sun.star.comp.WebDAVContentProvider"_ustr; |
| 88 |
} |
| 89 |
|
| 90 |
css::uno::Sequence< OUString > |
| 91 |
ContentProvider::getSupportedServiceNames() |
| 92 |
{ |
| 93 |
return { WEBDAV_CONTENT_PROVIDER_SERVICE_NAME }; |
| 94 |
} |
| 95 |
|
| 96 |
sal_Bool |
| 97 |
ContentProvider::supportsService(const OUString& s) |
| 98 |
{ |
| 99 |
return cppu::supportsService(this, s); |
| 100 |
} |
| 101 |
|
| 102 |
// XContentProvider methods. |
| 103 |
|
| 104 |
|
| 105 |
// virtual |
| 106 |
uno::Reference< ucb::XContent > SAL_CALL |
| 107 |
ContentProvider::queryContent( |
| 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 |
|
| 167 |
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
| 168 |
ucb_webdav_ContentProvider_get_implementation( |
| 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: */ |