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 <ucbhelper/contentidentifier.hxx>
21 #include <ucbhelper/macros.hxx>
22 #include "webdavprovider.hxx"
23 #include "webdavcontent.hxx"
25 #include <cppuhelper/queryinterface.hxx>
26 #include <osl/mutex.hxx>
27 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
29 #include <tools/urlobj.hxx>
31 using namespace com::sun::star
;
32 using namespace http_dav_ucp
;
35 // ContentProvider Implementation.
38 ContentProvider::ContentProvider(
39 const uno::Reference
< uno::XComponentContext
>& rContext
)
40 : ::ucbhelper::ContentProviderImplHelper( rContext
),
41 m_xDAVSessionFactory( new DAVSessionFactory
)
47 ContentProvider::~ContentProvider()
51 // XInterface methods.
52 void SAL_CALL
ContentProvider::acquire()
55 OWeakObject::acquire();
58 void SAL_CALL
ContentProvider::release()
61 OWeakObject::release();
64 css::uno::Any SAL_CALL
ContentProvider::queryInterface( const css::uno::Type
& rType
)
66 css::uno::Any aRet
= cppu::queryInterface( rType
,
67 static_cast< lang::XTypeProvider
* >(this),
68 static_cast< lang::XServiceInfo
* >(this),
69 static_cast< ucb::XContentProvider
* >(this)
71 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
74 // XTypeProvider methods.
77 XTYPEPROVIDER_IMPL_3( ContentProvider
,
80 ucb::XContentProvider
);
83 // XServiceInfo methods.
84 OUString SAL_CALL
ContentProvider::getImplementationName()
86 return getImplementationName_Static();
89 OUString
ContentProvider::getImplementationName_Static()
91 return "com.sun.star.comp.WebDAVContentProvider";
94 sal_Bool SAL_CALL
ContentProvider::supportsService( const OUString
& ServiceName
)
96 return cppu::supportsService( this, ServiceName
);
99 css::uno::Sequence
< OUString
> SAL_CALL
ContentProvider::getSupportedServiceNames()
101 return getSupportedServiceNames_Static();
104 /// @throws css::uno::Exception
105 static css::uno::Reference
< css::uno::XInterface
>
106 ContentProvider_CreateInstance( const css::uno::Reference
< css::lang::XMultiServiceFactory
> & rSMgr
)
108 css::lang::XServiceInfo
* pX
=
109 static_cast<css::lang::XServiceInfo
*>(new ContentProvider( ucbhelper::getComponentContext(rSMgr
) ));
110 return css::uno::Reference
< css::uno::XInterface
>::query( pX
);
113 css::uno::Sequence
< OUString
>
114 ContentProvider::getSupportedServiceNames_Static()
116 css::uno::Sequence
< OUString
> aSNS
{ WEBDAV_CONTENT_PROVIDER_SERVICE_NAME
};
120 // Service factory implementation.
122 css::uno::Reference
< css::lang::XSingleServiceFactory
>
123 ContentProvider::createServiceFactory( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& rxServiceMgr
)
125 return cppu::createOneInstanceFactory(
127 ContentProvider::getImplementationName_Static(),
128 ContentProvider_CreateInstance
,
129 ContentProvider::getSupportedServiceNames_Static() );
134 // XContentProvider methods.
138 uno::Reference
< ucb::XContent
> SAL_CALL
139 ContentProvider::queryContent(
140 const uno::Reference
<
141 ucb::XContentIdentifier
>& Identifier
)
143 // Check URL scheme...
144 INetURLObject
aURL(Identifier
->getContentIdentifier());
146 if (aURL
.isSchemeEqualTo(INetProtocol::NotValid
))
147 throw ucb::IllegalIdentifierException();
149 if (!aURL
.isAnyKnownWebDAVScheme())
150 throw ucb::IllegalIdentifierException();
152 uno::Reference
< ucb::XContentIdentifier
> xCanonicId
;
154 if (aURL
.isSchemeEqualTo(INetProtocol::VndSunStarWebdav
) ||
155 aURL
.isSchemeEqualTo(DAV_URL_SCHEME
) ||
156 aURL
.isSchemeEqualTo(WEBDAV_URL_SCHEME
))
158 aURL
.changeScheme(INetProtocol::Http
);
159 xCanonicId
= new ::ucbhelper::ContentIdentifier( aURL
.getExternalURL() );
161 else if (aURL
.isSchemeEqualTo(VNDSUNSTARWEBDAVS_URL_SCHEME
) ||
162 aURL
.isSchemeEqualTo(DAVS_URL_SCHEME
) ||
163 aURL
.isSchemeEqualTo(WEBDAVS_URL_SCHEME
))
165 aURL
.changeScheme(INetProtocol::Https
);
166 xCanonicId
= new ::ucbhelper::ContentIdentifier( aURL
.getExternalURL() );
170 xCanonicId
= Identifier
;
173 osl::MutexGuard
aGuard( m_aMutex
);
175 // Check, if a content with given id already exists...
176 uno::Reference
< ucb::XContent
> xContent
177 = queryExistingContent( xCanonicId
).get();
181 // Create a new content.
185 xContent
= new ::http_dav_ucp::Content(
186 m_xContext
, this, xCanonicId
, m_xDAVSessionFactory
);
187 registerNewContent( xContent
);
189 catch ( ucb::ContentCreationException
const & )
191 throw ucb::IllegalIdentifierException();
194 if ( !xContent
->getIdentifier().is() )
195 throw ucb::IllegalIdentifierException();
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */