1*2f86921cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2f86921cSAndrew Rist * distributed with this work for additional information 6*2f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2f86921cSAndrew Rist * "License"); you may not use this file except in compliance 9*2f86921cSAndrew Rist * with the License. You may obtain a copy of the License at 10*2f86921cSAndrew Rist * 11*2f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*2f86921cSAndrew Rist * 13*2f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2f86921cSAndrew Rist * software distributed under the License is distributed on an 15*2f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2f86921cSAndrew Rist * KIND, either express or implied. See the License for the 17*2f86921cSAndrew Rist * specific language governing permissions and limitations 18*2f86921cSAndrew Rist * under the License. 19*2f86921cSAndrew Rist * 20*2f86921cSAndrew Rist *************************************************************/ 21*2f86921cSAndrew Rist 22*2f86921cSAndrew 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; 39cdf0e10cSrcweir using namespace webdav_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( 133cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAVS_URL_SCHEME ) ) && 134cdf0e10cSrcweir !aScheme.equalsAsciiL( 135cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( FTP_URL_SCHEME ) ) ) 136cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 137cdf0e10cSrcweir 138cdf0e10cSrcweir // Normalize URL and create new Id, if nessacary. 139cdf0e10cSrcweir rtl::OUString aURL = Identifier->getContentIdentifier(); 140cdf0e10cSrcweir 141cdf0e10cSrcweir // At least: <scheme> + "://" 142cdf0e10cSrcweir if ( aURL.getLength() < ( aScheme.getLength() + 3 ) ) 143cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 144cdf0e10cSrcweir 145cdf0e10cSrcweir if ( ( aURL.getStr()[ aScheme.getLength() ] != sal_Unicode( ':' ) ) || 146cdf0e10cSrcweir ( aURL.getStr()[ aScheme.getLength() + 1 ] != sal_Unicode( '/' ) ) || 147cdf0e10cSrcweir ( aURL.getStr()[ aScheme.getLength() + 2 ] != sal_Unicode( '/' ) ) ) 148cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 149cdf0e10cSrcweir 150cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xCanonicId; 151cdf0e10cSrcweir 152cdf0e10cSrcweir bool bNewId = false; 153cdf0e10cSrcweir if ( aScheme.equalsAsciiL( 154cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_URL_SCHEME ) ) ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir aURL = aURL.replaceAt( 0, 157cdf0e10cSrcweir WEBDAV_URL_SCHEME_LENGTH, 158cdf0e10cSrcweir rtl::OUString::createFromAscii( 159cdf0e10cSrcweir HTTP_URL_SCHEME ) ); 160cdf0e10cSrcweir bNewId = true; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir else if ( aScheme.equalsAsciiL( 163cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAV_URL_SCHEME ) ) ) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir aURL = aURL.replaceAt( 0, 166cdf0e10cSrcweir DAV_URL_SCHEME_LENGTH, 167cdf0e10cSrcweir rtl::OUString::createFromAscii( 168cdf0e10cSrcweir HTTP_URL_SCHEME ) ); 169cdf0e10cSrcweir bNewId = true; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir else if ( aScheme.equalsAsciiL( 172cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAVS_URL_SCHEME ) ) ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir aURL = aURL.replaceAt( 0, 175cdf0e10cSrcweir DAVS_URL_SCHEME_LENGTH, 176cdf0e10cSrcweir rtl::OUString::createFromAscii( 177cdf0e10cSrcweir HTTPS_URL_SCHEME ) ); 178cdf0e10cSrcweir bNewId = true; 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir sal_Int32 nPos = aURL.lastIndexOf( '/' ); 182cdf0e10cSrcweir if ( nPos != aURL.getLength() - 1 ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir // Find second slash in URL. 185cdf0e10cSrcweir nPos = aURL.indexOf( '/', aURL.indexOf( '/' ) + 1 ); 186cdf0e10cSrcweir if ( nPos == -1 ) 187cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 188cdf0e10cSrcweir 189cdf0e10cSrcweir nPos = aURL.indexOf( '/', nPos + 1 ); 190cdf0e10cSrcweir if ( nPos == -1 ) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" ); 193cdf0e10cSrcweir bNewId = true; 194cdf0e10cSrcweir } 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir if ( bNewId ) 198cdf0e10cSrcweir xCanonicId = new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL ); 199cdf0e10cSrcweir else 200cdf0e10cSrcweir xCanonicId = Identifier; 201cdf0e10cSrcweir 202cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 203cdf0e10cSrcweir 204cdf0e10cSrcweir // Check, if a content with given id already exists... 205cdf0e10cSrcweir uno::Reference< ucb::XContent > xContent 206cdf0e10cSrcweir = queryExistingContent( xCanonicId ).get(); 207cdf0e10cSrcweir if ( xContent.is() ) 208cdf0e10cSrcweir return xContent; 209cdf0e10cSrcweir 210cdf0e10cSrcweir // Create a new content. 211cdf0e10cSrcweir 212cdf0e10cSrcweir try 213cdf0e10cSrcweir { 214cdf0e10cSrcweir xContent = new ::webdav_ucp::Content( 215cdf0e10cSrcweir m_xSMgr, this, xCanonicId, m_xDAVSessionFactory ); 216cdf0e10cSrcweir registerNewContent( xContent ); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir catch ( ucb::ContentCreationException const & ) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir if ( !xContent->getIdentifier().is() ) 224cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 225cdf0e10cSrcweir 226cdf0e10cSrcweir return xContent; 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229