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