Bump for 3.6-28
[LibreOffice.git] / ucb / source / ucp / webdav / webdavprovider.cxx
blobfd7371d7428d5555c194fd1df391aeb8f1e493a5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 /**************************************************************************
31 TODO
32 **************************************************************************
34 *************************************************************************/
35 #include <ucbhelper/contentidentifier.hxx>
36 #include "webdavprovider.hxx"
37 #include "webdavcontent.hxx"
39 #include "osl/mutex.hxx"
41 using namespace com::sun::star;
42 using namespace webdav_ucp;
44 //=========================================================================
45 //=========================================================================
47 // ContentProvider Implementation.
49 //=========================================================================
50 //=========================================================================
52 ContentProvider::ContentProvider(
53 const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
54 : ::ucbhelper::ContentProviderImplHelper( rSMgr ),
55 m_xDAVSessionFactory( new DAVSessionFactory() ),
56 m_pProps( 0 )
60 //=========================================================================
61 // virtual
62 ContentProvider::~ContentProvider()
64 delete m_pProps;
67 //=========================================================================
69 // XInterface methods.
71 //=========================================================================
73 XINTERFACE_IMPL_3( ContentProvider,
74 lang::XTypeProvider,
75 lang::XServiceInfo,
76 ucb::XContentProvider );
78 //=========================================================================
80 // XTypeProvider methods.
82 //=========================================================================
84 XTYPEPROVIDER_IMPL_3( ContentProvider,
85 lang::XTypeProvider,
86 lang::XServiceInfo,
87 ucb::XContentProvider );
89 //=========================================================================
91 // XServiceInfo methods.
93 //=========================================================================
95 XSERVICEINFO_IMPL_1( ContentProvider,
96 rtl::OUString( "com.sun.star.comp.WebDAVContentProvider" ),
97 rtl::OUString( WEBDAV_CONTENT_PROVIDER_SERVICE_NAME ) );
99 //=========================================================================
101 // Service factory implementation.
103 //=========================================================================
105 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
107 //=========================================================================
109 // XContentProvider methods.
111 //=========================================================================
113 // virtual
114 uno::Reference< ucb::XContent > SAL_CALL
115 ContentProvider::queryContent(
116 const uno::Reference<
117 ucb::XContentIdentifier >& Identifier )
118 throw( ucb::IllegalIdentifierException,
119 uno::RuntimeException )
121 // Check URL scheme...
123 const rtl::OUString aScheme
124 = Identifier->getContentProviderScheme().toAsciiLowerCase();
125 if ( aScheme != HTTP_URL_SCHEME && aScheme != HTTPS_URL_SCHEME && aScheme != WEBDAV_URL_SCHEME
126 && aScheme != DAV_URL_SCHEME && aScheme != DAVS_URL_SCHEME && aScheme != FTP_URL_SCHEME )
127 throw ucb::IllegalIdentifierException();
129 // Normalize URL and create new Id, if nessacary.
130 rtl::OUString aURL = Identifier->getContentIdentifier();
132 // At least: <scheme> + "://"
133 if ( aURL.getLength() < ( aScheme.getLength() + 3 ) )
134 throw ucb::IllegalIdentifierException();
136 if ( ( aURL.getStr()[ aScheme.getLength() ] != sal_Unicode( ':' ) ) ||
137 ( aURL.getStr()[ aScheme.getLength() + 1 ] != sal_Unicode( '/' ) ) ||
138 ( aURL.getStr()[ aScheme.getLength() + 2 ] != sal_Unicode( '/' ) ) )
139 throw ucb::IllegalIdentifierException();
141 uno::Reference< ucb::XContentIdentifier > xCanonicId;
143 bool bNewId = false;
144 if ( aScheme == WEBDAV_URL_SCHEME )
146 aURL = aURL.replaceAt( 0,
147 WEBDAV_URL_SCHEME_LENGTH,
148 rtl::OUString( HTTP_URL_SCHEME ) );
149 bNewId = true;
151 else if ( aScheme == DAV_URL_SCHEME )
153 aURL = aURL.replaceAt( 0,
154 DAV_URL_SCHEME_LENGTH,
155 rtl::OUString( HTTP_URL_SCHEME ) );
156 bNewId = true;
158 else if ( aScheme == DAVS_URL_SCHEME )
160 aURL = aURL.replaceAt( 0,
161 DAVS_URL_SCHEME_LENGTH,
162 rtl::OUString( HTTPS_URL_SCHEME ) );
163 bNewId = true;
166 sal_Int32 nPos = aURL.lastIndexOf( '/' );
167 if ( nPos != aURL.getLength() - 1 )
169 // Find second slash in URL.
170 nPos = aURL.indexOf( '/', aURL.indexOf( '/' ) + 1 );
171 if ( nPos == -1 )
172 throw ucb::IllegalIdentifierException();
174 nPos = aURL.indexOf( '/', nPos + 1 );
175 if ( nPos == -1 )
177 aURL += rtl::OUString("/");
178 bNewId = true;
182 if ( bNewId )
183 xCanonicId = new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL );
184 else
185 xCanonicId = Identifier;
187 osl::MutexGuard aGuard( m_aMutex );
189 // Check, if a content with given id already exists...
190 uno::Reference< ucb::XContent > xContent
191 = queryExistingContent( xCanonicId ).get();
192 if ( xContent.is() )
193 return xContent;
195 // Create a new content.
199 xContent = new ::webdav_ucp::Content(
200 m_xSMgr, this, xCanonicId, m_xDAVSessionFactory );
201 registerNewContent( xContent );
203 catch ( ucb::ContentCreationException const & )
205 throw ucb::IllegalIdentifierException();
208 if ( !xContent->getIdentifier().is() )
209 throw ucb::IllegalIdentifierException();
211 return xContent;
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */