fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / ucb / source / ucp / webdav / webdavprovider.cxx
blob0d4d0916bd9d2fe58893d3b70afcdeadf1d78f1c
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 "webdavprovider.hxx"
22 #include "webdavcontent.hxx"
24 #include "osl/mutex.hxx"
26 using namespace com::sun::star;
27 using namespace http_dav_ucp;
29 //=========================================================================
30 //=========================================================================
32 // ContentProvider Implementation.
34 //=========================================================================
35 //=========================================================================
37 ContentProvider::ContentProvider(
38 const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
39 : ::ucbhelper::ContentProviderImplHelper( rSMgr ),
40 m_xDAVSessionFactory( new DAVSessionFactory() ),
41 m_pProps( 0 )
45 //=========================================================================
46 // virtual
47 ContentProvider::~ContentProvider()
49 delete m_pProps;
52 //=========================================================================
54 // XInterface methods.
56 //=========================================================================
58 XINTERFACE_IMPL_3( ContentProvider,
59 lang::XTypeProvider,
60 lang::XServiceInfo,
61 ucb::XContentProvider );
63 //=========================================================================
65 // XTypeProvider methods.
67 //=========================================================================
69 XTYPEPROVIDER_IMPL_3( ContentProvider,
70 lang::XTypeProvider,
71 lang::XServiceInfo,
72 ucb::XContentProvider );
74 //=========================================================================
76 // XServiceInfo methods.
78 //=========================================================================
80 XSERVICEINFO_IMPL_1( ContentProvider,
81 OUString::createFromAscii(
82 "com.sun.star.comp.WebDAVContentProvider" ),
83 OUString::createFromAscii(
84 WEBDAV_CONTENT_PROVIDER_SERVICE_NAME ) );
86 //=========================================================================
88 // Service factory implementation.
90 //=========================================================================
92 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
94 //=========================================================================
96 // XContentProvider methods.
98 //=========================================================================
100 // virtual
101 uno::Reference< ucb::XContent > SAL_CALL
102 ContentProvider::queryContent(
103 const uno::Reference<
104 ucb::XContentIdentifier >& Identifier )
105 throw( ucb::IllegalIdentifierException,
106 uno::RuntimeException )
108 // Check URL scheme...
110 const OUString aScheme
111 = Identifier->getContentProviderScheme().toAsciiLowerCase();
112 if ( aScheme != HTTP_URL_SCHEME && aScheme != HTTPS_URL_SCHEME &&
113 aScheme != WEBDAV_URL_SCHEME && aScheme != DAV_URL_SCHEME &&
114 aScheme != DAVS_URL_SCHEME )
115 throw ucb::IllegalIdentifierException();
117 // Normalize URL and create new Id, if nessacary.
118 OUString aURL = Identifier->getContentIdentifier();
120 // At least: <scheme> + "://"
121 if ( aURL.getLength() < ( aScheme.getLength() + 3 ) )
122 throw ucb::IllegalIdentifierException();
124 if ( ( aURL.getStr()[ aScheme.getLength() ] != sal_Unicode( ':' ) ) ||
125 ( aURL.getStr()[ aScheme.getLength() + 1 ] != sal_Unicode( '/' ) ) ||
126 ( aURL.getStr()[ aScheme.getLength() + 2 ] != sal_Unicode( '/' ) ) )
127 throw ucb::IllegalIdentifierException();
129 uno::Reference< ucb::XContentIdentifier > xCanonicId;
131 bool bNewId = false;
132 if ( aScheme == WEBDAV_URL_SCHEME )
134 aURL = aURL.replaceAt( 0,
135 WEBDAV_URL_SCHEME_LENGTH,
136 OUString::createFromAscii(
137 HTTP_URL_SCHEME ) );
138 bNewId = true;
140 else if ( aScheme == DAV_URL_SCHEME )
142 aURL = aURL.replaceAt( 0,
143 DAV_URL_SCHEME_LENGTH,
144 OUString::createFromAscii(
145 HTTP_URL_SCHEME ) );
146 bNewId = true;
148 else if ( aScheme == DAVS_URL_SCHEME )
150 aURL = aURL.replaceAt( 0,
151 DAVS_URL_SCHEME_LENGTH,
152 OUString::createFromAscii(
153 HTTPS_URL_SCHEME ) );
154 bNewId = true;
157 sal_Int32 nPos = aURL.lastIndexOf( '/' );
158 if ( nPos != aURL.getLength() - 1 )
160 // Find second slash in URL.
161 nPos = aURL.indexOf( '/', aURL.indexOf( '/' ) + 1 );
162 if ( nPos == -1 )
163 throw ucb::IllegalIdentifierException();
165 nPos = aURL.indexOf( '/', nPos + 1 );
166 if ( nPos == -1 )
168 aURL += OUString::createFromAscii( "/" );
169 bNewId = true;
173 if ( bNewId )
174 xCanonicId = new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL );
175 else
176 xCanonicId = Identifier;
178 osl::MutexGuard aGuard( m_aMutex );
180 // Check, if a content with given id already exists...
181 uno::Reference< ucb::XContent > xContent
182 = queryExistingContent( xCanonicId ).get();
183 if ( xContent.is() )
184 return xContent;
186 // Create a new content.
190 xContent = new ::http_dav_ucp::Content(
191 m_xSMgr, this, xCanonicId, m_xDAVSessionFactory );
192 registerNewContent( xContent );
194 catch ( ucb::ContentCreationException const & )
196 throw ucb::IllegalIdentifierException();
199 if ( !xContent->getIdentifier().is() )
200 throw ucb::IllegalIdentifierException();
202 return xContent;
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */