1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/processfactory.hxx>
21 #include <ucbhelper/contentidentifier.hxx>
22 #include <ucbhelper/macros.hxx>
23 #include "webdavprovider.hxx"
24 #include "webdavcontent.hxx"
26 #include <cppuhelper/queryinterface.hxx>
27 #include <osl/mutex.hxx>
28 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
30 #include <tools/urlobj.hxx>
32 using namespace com::sun::star
;
33 using namespace http_dav_ucp
;
36 // ContentProvider Implementation.
39 ContentProvider::ContentProvider(
40 const uno::Reference
< uno::XComponentContext
>& rContext
)
41 : ::ucbhelper::ContentProviderImplHelper( rContext
),
42 m_xDAVSessionFactory( new DAVSessionFactory
)
48 ContentProvider::~ContentProvider()
52 // XInterface methods.
53 void SAL_CALL
ContentProvider::acquire() noexcept
55 OWeakObject::acquire();
58 void SAL_CALL
ContentProvider::release() noexcept
60 OWeakObject::release();
63 css::uno::Any SAL_CALL
ContentProvider::queryInterface( const css::uno::Type
& rType
)
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)
70 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
73 // XTypeProvider methods.
76 XTYPEPROVIDER_IMPL_3( ContentProvider
,
79 ucb::XContentProvider
);
82 // XServiceInfo methods.
85 ContentProvider::getImplementationName()
87 return "com.sun.star.comp.WebDAVContentProvider";
90 css::uno::Sequence
< OUString
>
91 ContentProvider::getSupportedServiceNames()
93 return { WEBDAV_CONTENT_PROVIDER_SERVICE_NAME
};
97 ContentProvider::supportsService(const OUString
& s
)
99 return cppu::supportsService(this, s
);
102 // XContentProvider methods.
106 uno::Reference
< ucb::XContent
> SAL_CALL
107 ContentProvider::queryContent(
108 const uno::Reference
<
109 ucb::XContentIdentifier
>& Identifier
)
111 // Check URL scheme...
112 INetURLObject
aURL(Identifier
->getContentIdentifier());
114 if (aURL
.isSchemeEqualTo(INetProtocol::NotValid
))
115 throw ucb::IllegalIdentifierException();
117 if (!aURL
.isAnyKnownWebDAVScheme())
118 throw ucb::IllegalIdentifierException();
120 uno::Reference
< ucb::XContentIdentifier
> xCanonicId
;
122 if (aURL
.isSchemeEqualTo(INetProtocol::VndSunStarWebdav
) ||
123 aURL
.isSchemeEqualTo(DAV_URL_SCHEME
) ||
124 aURL
.isSchemeEqualTo(WEBDAV_URL_SCHEME
))
126 aURL
.changeScheme(INetProtocol::Http
);
127 xCanonicId
= new ::ucbhelper::ContentIdentifier( aURL
.getExternalURL() );
129 else if (aURL
.isSchemeEqualTo(VNDSUNSTARWEBDAVS_URL_SCHEME
) ||
130 aURL
.isSchemeEqualTo(DAVS_URL_SCHEME
) ||
131 aURL
.isSchemeEqualTo(WEBDAVS_URL_SCHEME
))
133 aURL
.changeScheme(INetProtocol::Https
);
134 xCanonicId
= new ::ucbhelper::ContentIdentifier( aURL
.getExternalURL() );
138 xCanonicId
= Identifier
;
141 osl::MutexGuard
aGuard( m_aMutex
);
143 // Check, if a content with given id already exists...
144 uno::Reference
<ucb::XContent
> xContent
= queryExistingContent(xCanonicId
);
148 // Create a new content.
152 xContent
= new ::http_dav_ucp::Content(
153 m_xContext
, this, xCanonicId
, m_xDAVSessionFactory
);
154 registerNewContent( xContent
);
156 catch ( ucb::ContentCreationException
const & )
158 throw ucb::IllegalIdentifierException();
161 if ( !xContent
->getIdentifier().is() )
162 throw ucb::IllegalIdentifierException();
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&)
171 return cppu::acquire(new ContentProvider(context
));
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */