Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / ucb / source / ucp / webdav / webdavprovider.cxx
blob9a78c0648ebe7506939de0b1fcc93b1826ff1843
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <ucbhelper/contentidentifier.hxx>
21 #include <ucbhelper/getcomponentcontext.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 )
47 // virtual
48 ContentProvider::~ContentProvider()
52 // XInterface methods.
53 void SAL_CALL ContentProvider::acquire()
54 throw()
56 OWeakObject::acquire();
59 void SAL_CALL ContentProvider::release()
60 throw()
62 OWeakObject::release();
65 css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & rType )
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)
72 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
75 // XTypeProvider methods.
78 XTYPEPROVIDER_IMPL_3( ContentProvider,
79 lang::XTypeProvider,
80 lang::XServiceInfo,
81 ucb::XContentProvider );
84 // XServiceInfo methods.
86 XSERVICEINFO_COMMOM_IMPL( ContentProvider,
87 OUString( "com.sun.star.comp.WebDAVContentProvider" ) )
88 /// @throws css::uno::Exception
89 static css::uno::Reference< css::uno::XInterface >
90 ContentProvider_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr )
92 css::lang::XServiceInfo* pX =
93 static_cast<css::lang::XServiceInfo*>(new ContentProvider( ucbhelper::getComponentContext(rSMgr) ));
94 return css::uno::Reference< css::uno::XInterface >::query( pX );
97 css::uno::Sequence< OUString >
98 ContentProvider::getSupportedServiceNames_Static()
100 css::uno::Sequence< OUString > aSNS { WEBDAV_CONTENT_PROVIDER_SERVICE_NAME };
101 return aSNS;
104 // Service factory implementation.
107 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
110 // XContentProvider methods.
113 // virtual
114 uno::Reference< ucb::XContent > SAL_CALL
115 ContentProvider::queryContent(
116 const uno::Reference<
117 ucb::XContentIdentifier >& Identifier )
119 // Check URL scheme...
120 INetURLObject aURL(Identifier->getContentIdentifier());
122 if (aURL.isSchemeEqualTo(INetProtocol::NotValid))
123 throw ucb::IllegalIdentifierException();
125 if (!aURL.isAnyKnownWebDAVScheme())
126 throw ucb::IllegalIdentifierException();
128 uno::Reference< ucb::XContentIdentifier > xCanonicId;
130 if (aURL.isSchemeEqualTo(INetProtocol::VndSunStarWebdav) ||
131 aURL.isSchemeEqualTo(DAV_URL_SCHEME) ||
132 aURL.isSchemeEqualTo(WEBDAV_URL_SCHEME))
134 aURL.changeScheme(INetProtocol::Http);
135 xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
137 else if (aURL.isSchemeEqualTo(VNDSUNSTARWEBDAVS_URL_SCHEME) ||
138 aURL.isSchemeEqualTo(DAVS_URL_SCHEME) ||
139 aURL.isSchemeEqualTo(WEBDAVS_URL_SCHEME))
141 aURL.changeScheme(INetProtocol::Https);
142 xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
144 else
146 xCanonicId = Identifier;
149 osl::MutexGuard aGuard( m_aMutex );
151 // Check, if a content with given id already exists...
152 uno::Reference< ucb::XContent > xContent
153 = queryExistingContent( xCanonicId ).get();
154 if ( xContent.is() )
155 return xContent;
157 // Create a new content.
161 xContent = new ::http_dav_ucp::Content(
162 m_xContext, this, xCanonicId, m_xDAVSessionFactory );
163 registerNewContent( xContent );
165 catch ( ucb::ContentCreationException const & )
167 throw ucb::IllegalIdentifierException();
170 if ( !xContent->getIdentifier().is() )
171 throw ucb::IllegalIdentifierException();
173 return xContent;
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */