12f86921cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 32f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 42f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file 52f86921cSAndrew Rist * distributed with this work for additional information 62f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 72f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the 82f86921cSAndrew Rist * "License"); you may not use this file except in compliance 92f86921cSAndrew Rist * with the License. You may obtain a copy of the License at 102f86921cSAndrew Rist * 112f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 122f86921cSAndrew Rist * 132f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing, 142f86921cSAndrew Rist * software distributed under the License is distributed on an 152f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 162f86921cSAndrew Rist * KIND, either express or implied. See the License for the 172f86921cSAndrew Rist * specific language governing permissions and limitations 182f86921cSAndrew Rist * under the License. 192f86921cSAndrew Rist * 202f86921cSAndrew Rist *************************************************************/ 212f86921cSAndrew Rist 222f86921cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_ucb.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir /************************************************************************** 28cdf0e10cSrcweir TODO 29cdf0e10cSrcweir ************************************************************************** 30cdf0e10cSrcweir 31cdf0e10cSrcweir *************************************************************************/ 32cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx> 33cdf0e10cSrcweir #include "webdavprovider.hxx" 34cdf0e10cSrcweir #include "webdavcontent.hxx" 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include "osl/mutex.hxx" 37cdf0e10cSrcweir 38cdf0e10cSrcweir using namespace com::sun::star; 39*59ddfc10SAndre Fischer using namespace http_dav_ucp; 40cdf0e10cSrcweir 41cdf0e10cSrcweir //========================================================================= 42cdf0e10cSrcweir //========================================================================= 43cdf0e10cSrcweir // 44cdf0e10cSrcweir // ContentProvider Implementation. 45cdf0e10cSrcweir // 46cdf0e10cSrcweir //========================================================================= 47cdf0e10cSrcweir //========================================================================= 48cdf0e10cSrcweir 49cdf0e10cSrcweir ContentProvider::ContentProvider( 50cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rSMgr ) 51cdf0e10cSrcweir : ::ucbhelper::ContentProviderImplHelper( rSMgr ), 52cdf0e10cSrcweir m_xDAVSessionFactory( new DAVSessionFactory() ), 53cdf0e10cSrcweir m_pProps( 0 ) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir } 56cdf0e10cSrcweir 57cdf0e10cSrcweir //========================================================================= 58cdf0e10cSrcweir // virtual 59cdf0e10cSrcweir ContentProvider::~ContentProvider() 60cdf0e10cSrcweir { 61cdf0e10cSrcweir delete m_pProps; 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir //========================================================================= 65cdf0e10cSrcweir // 66cdf0e10cSrcweir // XInterface methods. 67cdf0e10cSrcweir // 68cdf0e10cSrcweir //========================================================================= 69cdf0e10cSrcweir 70cdf0e10cSrcweir XINTERFACE_IMPL_3( ContentProvider, 71cdf0e10cSrcweir lang::XTypeProvider, 72cdf0e10cSrcweir lang::XServiceInfo, 73cdf0e10cSrcweir ucb::XContentProvider ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir //========================================================================= 76cdf0e10cSrcweir // 77cdf0e10cSrcweir // XTypeProvider methods. 78cdf0e10cSrcweir // 79cdf0e10cSrcweir //========================================================================= 80cdf0e10cSrcweir 81cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( ContentProvider, 82cdf0e10cSrcweir lang::XTypeProvider, 83cdf0e10cSrcweir lang::XServiceInfo, 84cdf0e10cSrcweir ucb::XContentProvider ); 85cdf0e10cSrcweir 86cdf0e10cSrcweir //========================================================================= 87cdf0e10cSrcweir // 88cdf0e10cSrcweir // XServiceInfo methods. 89cdf0e10cSrcweir // 90cdf0e10cSrcweir //========================================================================= 91cdf0e10cSrcweir 92cdf0e10cSrcweir XSERVICEINFO_IMPL_1( ContentProvider, 93cdf0e10cSrcweir rtl::OUString::createFromAscii( 94cdf0e10cSrcweir "com.sun.star.comp.WebDAVContentProvider" ), 95cdf0e10cSrcweir rtl::OUString::createFromAscii( 96cdf0e10cSrcweir WEBDAV_CONTENT_PROVIDER_SERVICE_NAME ) ); 97cdf0e10cSrcweir 98cdf0e10cSrcweir //========================================================================= 99cdf0e10cSrcweir // 100cdf0e10cSrcweir // Service factory implementation. 101cdf0e10cSrcweir // 102cdf0e10cSrcweir //========================================================================= 103cdf0e10cSrcweir 104cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider ); 105cdf0e10cSrcweir 106cdf0e10cSrcweir //========================================================================= 107cdf0e10cSrcweir // 108cdf0e10cSrcweir // XContentProvider methods. 109cdf0e10cSrcweir // 110cdf0e10cSrcweir //========================================================================= 111cdf0e10cSrcweir 112cdf0e10cSrcweir // virtual 113cdf0e10cSrcweir uno::Reference< ucb::XContent > SAL_CALL 114cdf0e10cSrcweir ContentProvider::queryContent( 115cdf0e10cSrcweir const uno::Reference< 116cdf0e10cSrcweir ucb::XContentIdentifier >& Identifier ) 117cdf0e10cSrcweir throw( ucb::IllegalIdentifierException, 118cdf0e10cSrcweir uno::RuntimeException ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir // Check URL scheme... 121cdf0e10cSrcweir 122cdf0e10cSrcweir const rtl::OUString aScheme 123cdf0e10cSrcweir = Identifier->getContentProviderScheme().toAsciiLowerCase(); 124cdf0e10cSrcweir if ( !aScheme.equalsAsciiL( 125cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( HTTP_URL_SCHEME ) ) && 126cdf0e10cSrcweir !aScheme.equalsAsciiL( 127cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( HTTPS_URL_SCHEME ) ) && 128cdf0e10cSrcweir !aScheme.equalsAsciiL( 129cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_URL_SCHEME ) ) && 130cdf0e10cSrcweir !aScheme.equalsAsciiL( 131cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAV_URL_SCHEME ) ) && 132cdf0e10cSrcweir !aScheme.equalsAsciiL( 133*59ddfc10SAndre Fischer RTL_CONSTASCII_STRINGPARAM( DAVS_URL_SCHEME ) ) ) 134cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 135cdf0e10cSrcweir 136cdf0e10cSrcweir // Normalize URL and create new Id, if nessacary. 137cdf0e10cSrcweir rtl::OUString aURL = Identifier->getContentIdentifier(); 138cdf0e10cSrcweir 139cdf0e10cSrcweir // At least: <scheme> + "://" 140cdf0e10cSrcweir if ( aURL.getLength() < ( aScheme.getLength() + 3 ) ) 141cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 142cdf0e10cSrcweir 143cdf0e10cSrcweir if ( ( aURL.getStr()[ aScheme.getLength() ] != sal_Unicode( ':' ) ) || 144cdf0e10cSrcweir ( aURL.getStr()[ aScheme.getLength() + 1 ] != sal_Unicode( '/' ) ) || 145cdf0e10cSrcweir ( aURL.getStr()[ aScheme.getLength() + 2 ] != sal_Unicode( '/' ) ) ) 146cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 147cdf0e10cSrcweir 148cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xCanonicId; 149cdf0e10cSrcweir 150cdf0e10cSrcweir bool bNewId = false; 151cdf0e10cSrcweir if ( aScheme.equalsAsciiL( 152cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_URL_SCHEME ) ) ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir aURL = aURL.replaceAt( 0, 155cdf0e10cSrcweir WEBDAV_URL_SCHEME_LENGTH, 156cdf0e10cSrcweir rtl::OUString::createFromAscii( 157cdf0e10cSrcweir HTTP_URL_SCHEME ) ); 158cdf0e10cSrcweir bNewId = true; 159cdf0e10cSrcweir } 160cdf0e10cSrcweir else if ( aScheme.equalsAsciiL( 161cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAV_URL_SCHEME ) ) ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir aURL = aURL.replaceAt( 0, 164cdf0e10cSrcweir DAV_URL_SCHEME_LENGTH, 165cdf0e10cSrcweir rtl::OUString::createFromAscii( 166cdf0e10cSrcweir HTTP_URL_SCHEME ) ); 167cdf0e10cSrcweir bNewId = true; 168cdf0e10cSrcweir } 169cdf0e10cSrcweir else if ( aScheme.equalsAsciiL( 170cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAVS_URL_SCHEME ) ) ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir aURL = aURL.replaceAt( 0, 173cdf0e10cSrcweir DAVS_URL_SCHEME_LENGTH, 174cdf0e10cSrcweir rtl::OUString::createFromAscii( 175cdf0e10cSrcweir HTTPS_URL_SCHEME ) ); 176cdf0e10cSrcweir bNewId = true; 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir sal_Int32 nPos = aURL.lastIndexOf( '/' ); 180cdf0e10cSrcweir if ( nPos != aURL.getLength() - 1 ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir // Find second slash in URL. 183cdf0e10cSrcweir nPos = aURL.indexOf( '/', aURL.indexOf( '/' ) + 1 ); 184cdf0e10cSrcweir if ( nPos == -1 ) 185cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 186cdf0e10cSrcweir 187cdf0e10cSrcweir nPos = aURL.indexOf( '/', nPos + 1 ); 188cdf0e10cSrcweir if ( nPos == -1 ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" ); 191cdf0e10cSrcweir bNewId = true; 192cdf0e10cSrcweir } 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir if ( bNewId ) 196cdf0e10cSrcweir xCanonicId = new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL ); 197cdf0e10cSrcweir else 198cdf0e10cSrcweir xCanonicId = Identifier; 199cdf0e10cSrcweir 200cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 201cdf0e10cSrcweir 202cdf0e10cSrcweir // Check, if a content with given id already exists... 203cdf0e10cSrcweir uno::Reference< ucb::XContent > xContent 204cdf0e10cSrcweir = queryExistingContent( xCanonicId ).get(); 205cdf0e10cSrcweir if ( xContent.is() ) 206cdf0e10cSrcweir return xContent; 207cdf0e10cSrcweir 208cdf0e10cSrcweir // Create a new content. 209cdf0e10cSrcweir 210cdf0e10cSrcweir try 211cdf0e10cSrcweir { 212*59ddfc10SAndre Fischer xContent = new ::http_dav_ucp::Content( 213cdf0e10cSrcweir m_xSMgr, this, xCanonicId, m_xDAVSessionFactory ); 214cdf0e10cSrcweir registerNewContent( xContent ); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir catch ( ucb::ContentCreationException const & ) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir if ( !xContent->getIdentifier().is() ) 222cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 223cdf0e10cSrcweir 224cdf0e10cSrcweir return xContent; 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227