1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_ucb.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir /************************************************************************** 32*cdf0e10cSrcweir TODO 33*cdf0e10cSrcweir ************************************************************************** 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir *************************************************************************/ 36*cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx> 37*cdf0e10cSrcweir #include "webdavprovider.hxx" 38*cdf0e10cSrcweir #include "webdavcontent.hxx" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include "osl/mutex.hxx" 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir using namespace com::sun::star; 43*cdf0e10cSrcweir using namespace webdav_ucp; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir //========================================================================= 46*cdf0e10cSrcweir //========================================================================= 47*cdf0e10cSrcweir // 48*cdf0e10cSrcweir // ContentProvider Implementation. 49*cdf0e10cSrcweir // 50*cdf0e10cSrcweir //========================================================================= 51*cdf0e10cSrcweir //========================================================================= 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir ContentProvider::ContentProvider( 54*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rSMgr ) 55*cdf0e10cSrcweir : ::ucbhelper::ContentProviderImplHelper( rSMgr ), 56*cdf0e10cSrcweir m_xDAVSessionFactory( new DAVSessionFactory() ), 57*cdf0e10cSrcweir m_pProps( 0 ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir //========================================================================= 62*cdf0e10cSrcweir // virtual 63*cdf0e10cSrcweir ContentProvider::~ContentProvider() 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir delete m_pProps; 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir //========================================================================= 69*cdf0e10cSrcweir // 70*cdf0e10cSrcweir // XInterface methods. 71*cdf0e10cSrcweir // 72*cdf0e10cSrcweir //========================================================================= 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir XINTERFACE_IMPL_3( ContentProvider, 75*cdf0e10cSrcweir lang::XTypeProvider, 76*cdf0e10cSrcweir lang::XServiceInfo, 77*cdf0e10cSrcweir ucb::XContentProvider ); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir //========================================================================= 80*cdf0e10cSrcweir // 81*cdf0e10cSrcweir // XTypeProvider methods. 82*cdf0e10cSrcweir // 83*cdf0e10cSrcweir //========================================================================= 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( ContentProvider, 86*cdf0e10cSrcweir lang::XTypeProvider, 87*cdf0e10cSrcweir lang::XServiceInfo, 88*cdf0e10cSrcweir ucb::XContentProvider ); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir //========================================================================= 91*cdf0e10cSrcweir // 92*cdf0e10cSrcweir // XServiceInfo methods. 93*cdf0e10cSrcweir // 94*cdf0e10cSrcweir //========================================================================= 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir XSERVICEINFO_IMPL_1( ContentProvider, 97*cdf0e10cSrcweir rtl::OUString::createFromAscii( 98*cdf0e10cSrcweir "com.sun.star.comp.WebDAVContentProvider" ), 99*cdf0e10cSrcweir rtl::OUString::createFromAscii( 100*cdf0e10cSrcweir WEBDAV_CONTENT_PROVIDER_SERVICE_NAME ) ); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir //========================================================================= 103*cdf0e10cSrcweir // 104*cdf0e10cSrcweir // Service factory implementation. 105*cdf0e10cSrcweir // 106*cdf0e10cSrcweir //========================================================================= 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider ); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir //========================================================================= 111*cdf0e10cSrcweir // 112*cdf0e10cSrcweir // XContentProvider methods. 113*cdf0e10cSrcweir // 114*cdf0e10cSrcweir //========================================================================= 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir // virtual 117*cdf0e10cSrcweir uno::Reference< ucb::XContent > SAL_CALL 118*cdf0e10cSrcweir ContentProvider::queryContent( 119*cdf0e10cSrcweir const uno::Reference< 120*cdf0e10cSrcweir ucb::XContentIdentifier >& Identifier ) 121*cdf0e10cSrcweir throw( ucb::IllegalIdentifierException, 122*cdf0e10cSrcweir uno::RuntimeException ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir // Check URL scheme... 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir const rtl::OUString aScheme 127*cdf0e10cSrcweir = Identifier->getContentProviderScheme().toAsciiLowerCase(); 128*cdf0e10cSrcweir if ( !aScheme.equalsAsciiL( 129*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( HTTP_URL_SCHEME ) ) && 130*cdf0e10cSrcweir !aScheme.equalsAsciiL( 131*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( HTTPS_URL_SCHEME ) ) && 132*cdf0e10cSrcweir !aScheme.equalsAsciiL( 133*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_URL_SCHEME ) ) && 134*cdf0e10cSrcweir !aScheme.equalsAsciiL( 135*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAV_URL_SCHEME ) ) && 136*cdf0e10cSrcweir !aScheme.equalsAsciiL( 137*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAVS_URL_SCHEME ) ) && 138*cdf0e10cSrcweir !aScheme.equalsAsciiL( 139*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( FTP_URL_SCHEME ) ) ) 140*cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir // Normalize URL and create new Id, if nessacary. 143*cdf0e10cSrcweir rtl::OUString aURL = Identifier->getContentIdentifier(); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir // At least: <scheme> + "://" 146*cdf0e10cSrcweir if ( aURL.getLength() < ( aScheme.getLength() + 3 ) ) 147*cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir if ( ( aURL.getStr()[ aScheme.getLength() ] != sal_Unicode( ':' ) ) || 150*cdf0e10cSrcweir ( aURL.getStr()[ aScheme.getLength() + 1 ] != sal_Unicode( '/' ) ) || 151*cdf0e10cSrcweir ( aURL.getStr()[ aScheme.getLength() + 2 ] != sal_Unicode( '/' ) ) ) 152*cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xCanonicId; 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir bool bNewId = false; 157*cdf0e10cSrcweir if ( aScheme.equalsAsciiL( 158*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_URL_SCHEME ) ) ) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir aURL = aURL.replaceAt( 0, 161*cdf0e10cSrcweir WEBDAV_URL_SCHEME_LENGTH, 162*cdf0e10cSrcweir rtl::OUString::createFromAscii( 163*cdf0e10cSrcweir HTTP_URL_SCHEME ) ); 164*cdf0e10cSrcweir bNewId = true; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir else if ( aScheme.equalsAsciiL( 167*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAV_URL_SCHEME ) ) ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir aURL = aURL.replaceAt( 0, 170*cdf0e10cSrcweir DAV_URL_SCHEME_LENGTH, 171*cdf0e10cSrcweir rtl::OUString::createFromAscii( 172*cdf0e10cSrcweir HTTP_URL_SCHEME ) ); 173*cdf0e10cSrcweir bNewId = true; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir else if ( aScheme.equalsAsciiL( 176*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAVS_URL_SCHEME ) ) ) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir aURL = aURL.replaceAt( 0, 179*cdf0e10cSrcweir DAVS_URL_SCHEME_LENGTH, 180*cdf0e10cSrcweir rtl::OUString::createFromAscii( 181*cdf0e10cSrcweir HTTPS_URL_SCHEME ) ); 182*cdf0e10cSrcweir bNewId = true; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir sal_Int32 nPos = aURL.lastIndexOf( '/' ); 186*cdf0e10cSrcweir if ( nPos != aURL.getLength() - 1 ) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir // Find second slash in URL. 189*cdf0e10cSrcweir nPos = aURL.indexOf( '/', aURL.indexOf( '/' ) + 1 ); 190*cdf0e10cSrcweir if ( nPos == -1 ) 191*cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir nPos = aURL.indexOf( '/', nPos + 1 ); 194*cdf0e10cSrcweir if ( nPos == -1 ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" ); 197*cdf0e10cSrcweir bNewId = true; 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir if ( bNewId ) 202*cdf0e10cSrcweir xCanonicId = new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL ); 203*cdf0e10cSrcweir else 204*cdf0e10cSrcweir xCanonicId = Identifier; 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir // Check, if a content with given id already exists... 209*cdf0e10cSrcweir uno::Reference< ucb::XContent > xContent 210*cdf0e10cSrcweir = queryExistingContent( xCanonicId ).get(); 211*cdf0e10cSrcweir if ( xContent.is() ) 212*cdf0e10cSrcweir return xContent; 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir // Create a new content. 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir try 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir xContent = new ::webdav_ucp::Content( 219*cdf0e10cSrcweir m_xSMgr, this, xCanonicId, m_xDAVSessionFactory ); 220*cdf0e10cSrcweir registerNewContent( xContent ); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir catch ( ucb::ContentCreationException const & ) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir if ( !xContent->getIdentifier().is() ) 228*cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir return xContent; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir 233