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 10cdf0e10cSrcweir * 11*2f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 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 33cdf0e10cSrcweir #include <osl/diagnose.h> 34cdf0e10cSrcweir #include "osl/doublecheckedlocking.h" 35cdf0e10cSrcweir #include <rtl/uri.hxx> 36cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 37cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx> 38cdf0e10cSrcweir #include <ucbhelper/propertyvalueset.hxx> 39cdf0e10cSrcweir #include <ucbhelper/simpleinteractionrequest.hxx> 40cdf0e10cSrcweir #include <ucbhelper/cancelcommandexecution.hxx> 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 43cdf0e10cSrcweir #include <com/sun/star/beans/PropertySetInfoChange.hpp> 44cdf0e10cSrcweir #include <com/sun/star/beans/PropertySetInfoChangeEvent.hpp> 45cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 46cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp> 47cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 48cdf0e10cSrcweir #include <com/sun/star/lang/IllegalAccessException.hpp> 49cdf0e10cSrcweir #include <com/sun/star/task/PasswordContainerInteractionHandler.hpp> 50cdf0e10cSrcweir #include <com/sun/star/ucb/CommandEnvironment.hpp> 51cdf0e10cSrcweir #include <com/sun/star/ucb/CommandFailedException.hpp> 52cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfoAttribute.hpp> 53cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp> 54cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp> 55cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp> 56cdf0e10cSrcweir #include "com/sun/star/ucb/InteractiveLockingLockedException.hpp" 57cdf0e10cSrcweir #include "com/sun/star/ucb/InteractiveLockingLockExpiredException.hpp" 58cdf0e10cSrcweir #include "com/sun/star/ucb/InteractiveLockingNotLockedException.hpp" 59cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp> 60cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkGeneralException.hpp> 61cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkReadException.hpp> 62cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp> 63cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkWriteException.hpp> 64cdf0e10cSrcweir #include <com/sun/star/ucb/MissingInputStreamException.hpp> 65cdf0e10cSrcweir #include <com/sun/star/ucb/MissingPropertiesException.hpp> 66cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp> 67cdf0e10cSrcweir #include <com/sun/star/ucb/NameClashException.hpp> 68cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp> 69cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp> 70cdf0e10cSrcweir #include <com/sun/star/ucb/PostCommandArgument2.hpp> 71cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp> 72cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedCommandException.hpp> 73cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp> 74cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedNameClashException.hpp> 75cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp> 76cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp> 77cdf0e10cSrcweir #include <com/sun/star/ucb/XPersistentPropertySet.hpp> 78cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 79cdf0e10cSrcweir 80cdf0e10cSrcweir #include "webdavcontent.hxx" 81cdf0e10cSrcweir #include "webdavprovider.hxx" 82cdf0e10cSrcweir #include "webdavresultset.hxx" 83cdf0e10cSrcweir #include "ContentProperties.hxx" 84cdf0e10cSrcweir #include "NeonUri.hxx" 85cdf0e10cSrcweir #include "UCBDeadPropertyValue.hxx" 86cdf0e10cSrcweir 87cdf0e10cSrcweir using namespace com::sun::star; 88cdf0e10cSrcweir using namespace webdav_ucp; 89cdf0e10cSrcweir 90cdf0e10cSrcweir //========================================================================= 91cdf0e10cSrcweir //========================================================================= 92cdf0e10cSrcweir // 93cdf0e10cSrcweir // Content Implementation. 94cdf0e10cSrcweir // 95cdf0e10cSrcweir //========================================================================= 96cdf0e10cSrcweir //========================================================================= 97cdf0e10cSrcweir 98cdf0e10cSrcweir //========================================================================= 99cdf0e10cSrcweir // ctr for content on an existing webdav resource 100cdf0e10cSrcweir Content::Content( 101cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSMgr, 102cdf0e10cSrcweir ContentProvider* pProvider, 103cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& Identifier, 104cdf0e10cSrcweir rtl::Reference< DAVSessionFactory > const & rSessionFactory ) 105cdf0e10cSrcweir throw ( ucb::ContentCreationException ) 106cdf0e10cSrcweir : ContentImplHelper( rxSMgr, pProvider, Identifier ), 107cdf0e10cSrcweir m_eResourceType( UNKNOWN ), 108cdf0e10cSrcweir m_pProvider( pProvider ), 109cdf0e10cSrcweir m_bTransient( false ), 110cdf0e10cSrcweir m_bCollection( false ), 111cdf0e10cSrcweir m_bDidGetOrHead( false ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir try 114cdf0e10cSrcweir { 115cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( 116cdf0e10cSrcweir rxSMgr, 117cdf0e10cSrcweir rSessionFactory, 118cdf0e10cSrcweir Identifier->getContentIdentifier() ) ); 119cdf0e10cSrcweir 120cdf0e10cSrcweir NeonUri aURI( Identifier->getContentIdentifier() ); 121cdf0e10cSrcweir m_aEscapedTitle = aURI.GetPathBaseName(); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir catch ( DAVException const & ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir throw ucb::ContentCreationException(); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir //========================================================================= 130cdf0e10cSrcweir // ctr for content on an non-existing webdav resource 131cdf0e10cSrcweir Content::Content( 132cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSMgr, 133cdf0e10cSrcweir ContentProvider* pProvider, 134cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& Identifier, 135cdf0e10cSrcweir rtl::Reference< DAVSessionFactory > const & rSessionFactory, 136cdf0e10cSrcweir sal_Bool isCollection ) 137cdf0e10cSrcweir throw ( ucb::ContentCreationException ) 138cdf0e10cSrcweir : ContentImplHelper( rxSMgr, pProvider, Identifier ), 139cdf0e10cSrcweir m_eResourceType( UNKNOWN ), 140cdf0e10cSrcweir m_pProvider( pProvider ), 141cdf0e10cSrcweir m_bTransient( true ), 142cdf0e10cSrcweir m_bCollection( isCollection ), 143cdf0e10cSrcweir m_bDidGetOrHead( false ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir try 146cdf0e10cSrcweir { 147cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( 148cdf0e10cSrcweir rxSMgr, rSessionFactory, Identifier->getContentIdentifier() ) ); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir catch ( DAVException const & ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir throw ucb::ContentCreationException(); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir // Do not set m_aEscapedTitle here! Content::insert relays on this!!! 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir //========================================================================= 159cdf0e10cSrcweir // virtual 160cdf0e10cSrcweir Content::~Content() 161cdf0e10cSrcweir { 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir //========================================================================= 165cdf0e10cSrcweir // 166cdf0e10cSrcweir // XInterface methods. 167cdf0e10cSrcweir // 168cdf0e10cSrcweir //========================================================================= 169cdf0e10cSrcweir 170cdf0e10cSrcweir // virtual 171cdf0e10cSrcweir void SAL_CALL Content::acquire() 172cdf0e10cSrcweir throw( ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir ContentImplHelper::acquire(); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir //========================================================================= 178cdf0e10cSrcweir // virtual 179cdf0e10cSrcweir void SAL_CALL Content::release() 180cdf0e10cSrcweir throw( ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir ContentImplHelper::release(); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir //========================================================================= 186cdf0e10cSrcweir // virtual 187cdf0e10cSrcweir uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType ) 188cdf0e10cSrcweir throw ( uno::RuntimeException ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir // Note: isFolder may require network activities! So call it only 191cdf0e10cSrcweir // if it is really necessary!!! 192cdf0e10cSrcweir uno::Any aRet = cppu::queryInterface( 193cdf0e10cSrcweir rType, 194cdf0e10cSrcweir static_cast< ucb::XContentCreator * >( this ) ); 195cdf0e10cSrcweir if ( aRet.hasValue() ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir try 198cdf0e10cSrcweir { 199cdf0e10cSrcweir uno::Reference< beans::XPropertySet > const xProps( 200cdf0e10cSrcweir m_xSMgr, uno::UNO_QUERY_THROW ); 201cdf0e10cSrcweir uno::Reference< uno::XComponentContext > xCtx; 202cdf0e10cSrcweir xCtx.set( xProps->getPropertyValue( 203cdf0e10cSrcweir rtl::OUString( 204cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ), 205cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 206cdf0e10cSrcweir 207cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xIH( 208cdf0e10cSrcweir task::PasswordContainerInteractionHandler::create( xCtx ) ); 209cdf0e10cSrcweir 210cdf0e10cSrcweir // Supply a command env to isFolder() that contains an interaction 211cdf0e10cSrcweir // handler that uses the password container service to obtain 212cdf0e10cSrcweir // credentials without displaying a password gui. 213cdf0e10cSrcweir 214cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xCmdEnv( 215cdf0e10cSrcweir ucb::CommandEnvironment::create( 216cdf0e10cSrcweir xCtx, 217cdf0e10cSrcweir xIH, 218cdf0e10cSrcweir uno::Reference< ucb::XProgressHandler >() ) ); 219cdf0e10cSrcweir 220cdf0e10cSrcweir return isFolder( xCmdEnv ) ? aRet : uno::Any(); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir catch ( uno::RuntimeException const & ) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir throw; 225cdf0e10cSrcweir } 226cdf0e10cSrcweir catch ( uno::Exception const & ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir return uno::Any(); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir } 231cdf0e10cSrcweir return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType ); 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir //========================================================================= 235cdf0e10cSrcweir // 236cdf0e10cSrcweir // XTypeProvider methods. 237cdf0e10cSrcweir // 238cdf0e10cSrcweir //========================================================================= 239cdf0e10cSrcweir 240cdf0e10cSrcweir XTYPEPROVIDER_COMMON_IMPL( Content ); 241cdf0e10cSrcweir 242cdf0e10cSrcweir //========================================================================= 243cdf0e10cSrcweir // virtual 244cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL Content::getTypes() 245cdf0e10cSrcweir throw( uno::RuntimeException ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir sal_Bool bFolder = sal_False; 248cdf0e10cSrcweir try 249cdf0e10cSrcweir { 250cdf0e10cSrcweir bFolder 251cdf0e10cSrcweir = isFolder( uno::Reference< ucb::XCommandEnvironment >() ); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir catch ( uno::RuntimeException const & ) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir throw; 256cdf0e10cSrcweir } 257cdf0e10cSrcweir catch ( uno::Exception const & ) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir cppu::OTypeCollection * pCollection = 0; 262cdf0e10cSrcweir 263cdf0e10cSrcweir if ( bFolder ) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir static cppu::OTypeCollection* pFolderTypes = 0; 266cdf0e10cSrcweir 267cdf0e10cSrcweir pCollection = pFolderTypes; 268cdf0e10cSrcweir if ( !pCollection ) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 271cdf0e10cSrcweir 272cdf0e10cSrcweir pCollection = pFolderTypes; 273cdf0e10cSrcweir if ( !pCollection ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir static cppu::OTypeCollection aCollection( 276cdf0e10cSrcweir CPPU_TYPE_REF( lang::XTypeProvider ), 277cdf0e10cSrcweir CPPU_TYPE_REF( lang::XServiceInfo ), 278cdf0e10cSrcweir CPPU_TYPE_REF( lang::XComponent ), 279cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContent ), 280cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandProcessor ), 281cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ), 282cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ), 283cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertyContainer ), 284cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ), 285cdf0e10cSrcweir CPPU_TYPE_REF( container::XChild ), 286cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContentCreator ) ); // !! 287cdf0e10cSrcweir pCollection = &aCollection; 288cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 289cdf0e10cSrcweir pFolderTypes = pCollection; 290cdf0e10cSrcweir } 291cdf0e10cSrcweir } 292cdf0e10cSrcweir else { 293cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 294cdf0e10cSrcweir } 295cdf0e10cSrcweir } 296cdf0e10cSrcweir else 297cdf0e10cSrcweir { 298cdf0e10cSrcweir static cppu::OTypeCollection* pDocumentTypes = 0; 299cdf0e10cSrcweir 300cdf0e10cSrcweir pCollection = pDocumentTypes; 301cdf0e10cSrcweir if ( !pCollection ) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 304cdf0e10cSrcweir 305cdf0e10cSrcweir pCollection = pDocumentTypes; 306cdf0e10cSrcweir if ( !pCollection ) 307cdf0e10cSrcweir { 308cdf0e10cSrcweir static cppu::OTypeCollection aCollection( 309cdf0e10cSrcweir CPPU_TYPE_REF( lang::XTypeProvider ), 310cdf0e10cSrcweir CPPU_TYPE_REF( lang::XServiceInfo ), 311cdf0e10cSrcweir CPPU_TYPE_REF( lang::XComponent ), 312cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContent ), 313cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandProcessor ), 314cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ), 315cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ), 316cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertyContainer ), 317cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ), 318cdf0e10cSrcweir CPPU_TYPE_REF( container::XChild ) ); 319cdf0e10cSrcweir pCollection = &aCollection; 320cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 321cdf0e10cSrcweir pDocumentTypes = pCollection; 322cdf0e10cSrcweir } 323cdf0e10cSrcweir } 324cdf0e10cSrcweir else { 325cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 326cdf0e10cSrcweir } 327cdf0e10cSrcweir } 328cdf0e10cSrcweir 329cdf0e10cSrcweir return (*pCollection).getTypes(); 330cdf0e10cSrcweir } 331cdf0e10cSrcweir 332cdf0e10cSrcweir //========================================================================= 333cdf0e10cSrcweir // 334cdf0e10cSrcweir // XServiceInfo methods. 335cdf0e10cSrcweir // 336cdf0e10cSrcweir //========================================================================= 337cdf0e10cSrcweir 338cdf0e10cSrcweir // virtual 339cdf0e10cSrcweir rtl::OUString SAL_CALL Content::getImplementationName() 340cdf0e10cSrcweir throw( uno::RuntimeException ) 341cdf0e10cSrcweir { 342cdf0e10cSrcweir return rtl::OUString::createFromAscii( 343cdf0e10cSrcweir "com.sun.star.comp.ucb.WebDAVContent" ); 344cdf0e10cSrcweir } 345cdf0e10cSrcweir 346cdf0e10cSrcweir //========================================================================= 347cdf0e10cSrcweir // virtual 348cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL Content::getSupportedServiceNames() 349cdf0e10cSrcweir throw( uno::RuntimeException ) 350cdf0e10cSrcweir { 351cdf0e10cSrcweir uno::Sequence< rtl::OUString > aSNS( 1 ); 352cdf0e10cSrcweir aSNS.getArray()[ 0 ] 353cdf0e10cSrcweir = rtl::OUString::createFromAscii( WEBDAV_CONTENT_SERVICE_NAME ); 354cdf0e10cSrcweir return aSNS; 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir //========================================================================= 358cdf0e10cSrcweir // 359cdf0e10cSrcweir // XContent methods. 360cdf0e10cSrcweir // 361cdf0e10cSrcweir //========================================================================= 362cdf0e10cSrcweir 363cdf0e10cSrcweir // virtual 364cdf0e10cSrcweir rtl::OUString SAL_CALL Content::getContentType() 365cdf0e10cSrcweir throw( uno::RuntimeException ) 366cdf0e10cSrcweir { 367cdf0e10cSrcweir sal_Bool bFolder = sal_False; 368cdf0e10cSrcweir try 369cdf0e10cSrcweir { 370cdf0e10cSrcweir bFolder 371cdf0e10cSrcweir = isFolder( uno::Reference< ucb::XCommandEnvironment >() ); 372cdf0e10cSrcweir } 373cdf0e10cSrcweir catch ( uno::RuntimeException const & ) 374cdf0e10cSrcweir { 375cdf0e10cSrcweir throw; 376cdf0e10cSrcweir } 377cdf0e10cSrcweir catch ( uno::Exception const & ) 378cdf0e10cSrcweir { 379cdf0e10cSrcweir } 380cdf0e10cSrcweir 381cdf0e10cSrcweir if ( bFolder ) 382cdf0e10cSrcweir return rtl::OUString::createFromAscii( WEBDAV_COLLECTION_TYPE ); 383cdf0e10cSrcweir 384cdf0e10cSrcweir return rtl::OUString::createFromAscii( WEBDAV_CONTENT_TYPE ); 385cdf0e10cSrcweir } 386cdf0e10cSrcweir 387cdf0e10cSrcweir //========================================================================= 388cdf0e10cSrcweir // 389cdf0e10cSrcweir // XCommandProcessor methods. 390cdf0e10cSrcweir // 391cdf0e10cSrcweir //========================================================================= 392cdf0e10cSrcweir 393cdf0e10cSrcweir // virtual 394cdf0e10cSrcweir uno::Any SAL_CALL Content::execute( 395cdf0e10cSrcweir const ucb::Command& aCommand, 396cdf0e10cSrcweir sal_Int32 /*CommandId*/, 397cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& Environment ) 398cdf0e10cSrcweir throw( uno::Exception, 399cdf0e10cSrcweir ucb::CommandAbortedException, 400cdf0e10cSrcweir uno::RuntimeException ) 401cdf0e10cSrcweir { 402cdf0e10cSrcweir OSL_TRACE( ">>>>> Content::execute: start: command: %s, env: %s", 403cdf0e10cSrcweir rtl::OUStringToOString( aCommand.Name, 404cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ).getStr(), 405cdf0e10cSrcweir Environment.is() ? "present" : "missing" ); 406cdf0e10cSrcweir 407cdf0e10cSrcweir uno::Any aRet; 408cdf0e10cSrcweir 409cdf0e10cSrcweir if ( aCommand.Name.equalsAsciiL( 410cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "getPropertyValues" ) ) ) 411cdf0e10cSrcweir { 412cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 413cdf0e10cSrcweir // getPropertyValues 414cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 415cdf0e10cSrcweir 416cdf0e10cSrcweir uno::Sequence< beans::Property > Properties; 417cdf0e10cSrcweir if ( !( aCommand.Argument >>= Properties ) ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 420cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 421cdf0e10cSrcweir rtl::OUString::createFromAscii( 422cdf0e10cSrcweir "Wrong argument type!" ), 423cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 424cdf0e10cSrcweir -1 ) ), 425cdf0e10cSrcweir Environment ); 426cdf0e10cSrcweir // Unreachable 427cdf0e10cSrcweir } 428cdf0e10cSrcweir 429cdf0e10cSrcweir aRet <<= getPropertyValues( Properties, Environment ); 430cdf0e10cSrcweir } 431cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 432cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "setPropertyValues" ) ) ) 433cdf0e10cSrcweir { 434cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 435cdf0e10cSrcweir // setPropertyValues 436cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 437cdf0e10cSrcweir 438cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aProperties; 439cdf0e10cSrcweir if ( !( aCommand.Argument >>= aProperties ) ) 440cdf0e10cSrcweir { 441cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 442cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 443cdf0e10cSrcweir rtl::OUString::createFromAscii( 444cdf0e10cSrcweir "Wrong argument type!" ), 445cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 446cdf0e10cSrcweir -1 ) ), 447cdf0e10cSrcweir Environment ); 448cdf0e10cSrcweir // Unreachable 449cdf0e10cSrcweir } 450cdf0e10cSrcweir 451cdf0e10cSrcweir if ( !aProperties.getLength() ) 452cdf0e10cSrcweir { 453cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 454cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 455cdf0e10cSrcweir rtl::OUString::createFromAscii( 456cdf0e10cSrcweir "No properties!" ), 457cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 458cdf0e10cSrcweir -1 ) ), 459cdf0e10cSrcweir Environment ); 460cdf0e10cSrcweir // Unreachable 461cdf0e10cSrcweir } 462cdf0e10cSrcweir 463cdf0e10cSrcweir aRet <<= setPropertyValues( aProperties, Environment ); 464cdf0e10cSrcweir } 465cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 466cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "getPropertySetInfo" ) ) ) 467cdf0e10cSrcweir { 468cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 469cdf0e10cSrcweir // getPropertySetInfo 470cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 471cdf0e10cSrcweir 472cdf0e10cSrcweir // Note: Implemented by base class. 473cdf0e10cSrcweir aRet <<= getPropertySetInfo( Environment, 474cdf0e10cSrcweir sal_False /* don't cache data */ ); 475cdf0e10cSrcweir } 476cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 477cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "getCommandInfo" ) ) ) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 480cdf0e10cSrcweir // getCommandInfo 481cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 482cdf0e10cSrcweir 483cdf0e10cSrcweir // Note: Implemented by base class. 484cdf0e10cSrcweir aRet <<= getCommandInfo( Environment, sal_False ); 485cdf0e10cSrcweir } 486cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 487cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "open" ) ) ) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 490cdf0e10cSrcweir // open 491cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 492cdf0e10cSrcweir 493cdf0e10cSrcweir ucb::OpenCommandArgument2 aOpenCommand; 494cdf0e10cSrcweir if ( !( aCommand.Argument >>= aOpenCommand ) ) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 497cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 498cdf0e10cSrcweir rtl::OUString::createFromAscii( 499cdf0e10cSrcweir "Wrong argument type!" ), 500cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 501cdf0e10cSrcweir -1 ) ), 502cdf0e10cSrcweir Environment ); 503cdf0e10cSrcweir // Unreachable 504cdf0e10cSrcweir } 505cdf0e10cSrcweir 506cdf0e10cSrcweir aRet = open( aOpenCommand, Environment ); 507cdf0e10cSrcweir } 508cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 509cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "insert" ) ) ) 510cdf0e10cSrcweir { 511cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 512cdf0e10cSrcweir // insert 513cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 514cdf0e10cSrcweir 515cdf0e10cSrcweir ucb::InsertCommandArgument arg; 516cdf0e10cSrcweir if ( !( aCommand.Argument >>= arg ) ) 517cdf0e10cSrcweir { 518cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 519cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 520cdf0e10cSrcweir rtl::OUString::createFromAscii( 521cdf0e10cSrcweir "Wrong argument type!" ), 522cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 523cdf0e10cSrcweir -1 ) ), 524cdf0e10cSrcweir Environment ); 525cdf0e10cSrcweir // Unreachable 526cdf0e10cSrcweir } 527cdf0e10cSrcweir 528cdf0e10cSrcweir insert( arg.Data, arg.ReplaceExisting, Environment ); 529cdf0e10cSrcweir } 530cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 531cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "delete" ) ) ) 532cdf0e10cSrcweir { 533cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 534cdf0e10cSrcweir // delete 535cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 536cdf0e10cSrcweir 537cdf0e10cSrcweir sal_Bool bDeletePhysical = sal_False; 538cdf0e10cSrcweir aCommand.Argument >>= bDeletePhysical; 539cdf0e10cSrcweir 540cdf0e10cSrcweir // KSO: Ignore parameter and destroy the content, if you don't support 541cdf0e10cSrcweir // putting objects into trashcan. ( Since we do not have a trash can 542cdf0e10cSrcweir // service yet (src603), you actually have no other choice. ) 543cdf0e10cSrcweir // if ( bDeletePhysical ) 544cdf0e10cSrcweir // { 545cdf0e10cSrcweir try 546cdf0e10cSrcweir { 547cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 548cdf0e10cSrcweir { 549cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 550cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) ); 551cdf0e10cSrcweir } 552cdf0e10cSrcweir xResAccess->DESTROY( Environment ); 553cdf0e10cSrcweir { 554cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 555cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) ); 556cdf0e10cSrcweir } 557cdf0e10cSrcweir } 558cdf0e10cSrcweir catch ( DAVException const & e ) 559cdf0e10cSrcweir { 560cdf0e10cSrcweir cancelCommandExecution( e, Environment, sal_True ); 561cdf0e10cSrcweir // Unreachable 562cdf0e10cSrcweir } 563cdf0e10cSrcweir // } 564cdf0e10cSrcweir 565cdf0e10cSrcweir // Propagate destruction. 566cdf0e10cSrcweir destroy( bDeletePhysical ); 567cdf0e10cSrcweir 568cdf0e10cSrcweir // Remove own and all children's Additional Core Properties. 569cdf0e10cSrcweir removeAdditionalPropertySet( sal_True ); 570cdf0e10cSrcweir } 571cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 572cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "transfer" ) ) 573cdf0e10cSrcweir && isFolder( Environment ) ) 574cdf0e10cSrcweir { 575cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 576cdf0e10cSrcweir // transfer 577cdf0e10cSrcweir // ( Not available at documents ) 578cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 579cdf0e10cSrcweir 580cdf0e10cSrcweir ucb::TransferInfo transferArgs; 581cdf0e10cSrcweir if ( !( aCommand.Argument >>= transferArgs ) ) 582cdf0e10cSrcweir { 583cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 584cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 585cdf0e10cSrcweir rtl::OUString::createFromAscii( 586cdf0e10cSrcweir "Wrong argument type!" ), 587cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 588cdf0e10cSrcweir -1 ) ), 589cdf0e10cSrcweir Environment ); 590cdf0e10cSrcweir // Unreachable 591cdf0e10cSrcweir } 592cdf0e10cSrcweir 593cdf0e10cSrcweir transfer( transferArgs, Environment ); 594cdf0e10cSrcweir } 595cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 596cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "post" ) ) ) 597cdf0e10cSrcweir { 598cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 599cdf0e10cSrcweir // post 600cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 601cdf0e10cSrcweir 602cdf0e10cSrcweir ucb::PostCommandArgument2 aArg; 603cdf0e10cSrcweir if ( !( aCommand.Argument >>= aArg ) ) 604cdf0e10cSrcweir { 605cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 606cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 607cdf0e10cSrcweir rtl::OUString::createFromAscii( 608cdf0e10cSrcweir "Wrong argument type!" ), 609cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 610cdf0e10cSrcweir -1 ) ), 611cdf0e10cSrcweir Environment ); 612cdf0e10cSrcweir // Unreachable 613cdf0e10cSrcweir } 614cdf0e10cSrcweir 615cdf0e10cSrcweir post( aArg, Environment ); 616cdf0e10cSrcweir } 617cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 618cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "lock" ) ) && 619cdf0e10cSrcweir supportsExclusiveWriteLock( Environment ) ) 620cdf0e10cSrcweir { 621cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 622cdf0e10cSrcweir // lock 623cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 624cdf0e10cSrcweir 625cdf0e10cSrcweir lock( Environment ); 626cdf0e10cSrcweir } 627cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 628cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "unlock" ) ) && 629cdf0e10cSrcweir supportsExclusiveWriteLock( Environment ) ) 630cdf0e10cSrcweir { 631cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 632cdf0e10cSrcweir // unlock 633cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 634cdf0e10cSrcweir 635cdf0e10cSrcweir unlock( Environment ); 636cdf0e10cSrcweir } 637cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 638cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "createNewContent" ) ) && 639cdf0e10cSrcweir isFolder( Environment ) ) 640cdf0e10cSrcweir { 641cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 642cdf0e10cSrcweir // createNewContent 643cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 644cdf0e10cSrcweir 645cdf0e10cSrcweir ucb::ContentInfo aArg; 646cdf0e10cSrcweir if ( !( aCommand.Argument >>= aArg ) ) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 649cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 650cdf0e10cSrcweir rtl::OUString::createFromAscii( 651cdf0e10cSrcweir "Wrong argument type!" ), 652cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 653cdf0e10cSrcweir -1 ) ), 654cdf0e10cSrcweir Environment ); 655cdf0e10cSrcweir // Unreachable 656cdf0e10cSrcweir } 657cdf0e10cSrcweir 658cdf0e10cSrcweir aRet = uno::makeAny( createNewContent( aArg ) ); 659cdf0e10cSrcweir } 660cdf0e10cSrcweir else 661cdf0e10cSrcweir { 662cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 663cdf0e10cSrcweir // Unsupported command 664cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 665cdf0e10cSrcweir 666cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 667cdf0e10cSrcweir uno::makeAny( ucb::UnsupportedCommandException( 668cdf0e10cSrcweir aCommand.Name, 669cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ), 670cdf0e10cSrcweir Environment ); 671cdf0e10cSrcweir // Unreachable 672cdf0e10cSrcweir } 673cdf0e10cSrcweir 674cdf0e10cSrcweir OSL_TRACE( "<<<<< Content::execute: end: command: %s", 675cdf0e10cSrcweir rtl::OUStringToOString( aCommand.Name, 676cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ).getStr() ); 677cdf0e10cSrcweir 678cdf0e10cSrcweir return aRet; 679cdf0e10cSrcweir } 680cdf0e10cSrcweir 681cdf0e10cSrcweir //========================================================================= 682cdf0e10cSrcweir // virtual 683cdf0e10cSrcweir void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ ) 684cdf0e10cSrcweir throw( uno::RuntimeException ) 685cdf0e10cSrcweir { 686cdf0e10cSrcweir try 687cdf0e10cSrcweir { 688cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 689cdf0e10cSrcweir { 690cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 691cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) ); 692cdf0e10cSrcweir } 693cdf0e10cSrcweir xResAccess->abort(); 694cdf0e10cSrcweir { 695cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 696cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) ); 697cdf0e10cSrcweir } 698cdf0e10cSrcweir } 699cdf0e10cSrcweir catch ( DAVException const & ) 700cdf0e10cSrcweir { 701cdf0e10cSrcweir // abort failed! 702cdf0e10cSrcweir } 703cdf0e10cSrcweir } 704cdf0e10cSrcweir 705cdf0e10cSrcweir //========================================================================= 706cdf0e10cSrcweir // 707cdf0e10cSrcweir // XPropertyContainer methods. 708cdf0e10cSrcweir // 709cdf0e10cSrcweir //========================================================================= 710cdf0e10cSrcweir 711cdf0e10cSrcweir // virtual 712cdf0e10cSrcweir void SAL_CALL Content::addProperty( const rtl::OUString& Name, 713cdf0e10cSrcweir sal_Int16 Attributes, 714cdf0e10cSrcweir const uno::Any& DefaultValue ) 715cdf0e10cSrcweir throw( beans::PropertyExistException, 716cdf0e10cSrcweir beans::IllegalTypeException, 717cdf0e10cSrcweir lang::IllegalArgumentException, 718cdf0e10cSrcweir uno::RuntimeException ) 719cdf0e10cSrcweir { 720cdf0e10cSrcweir // if ( m_bTransient ) 721cdf0e10cSrcweir // @@@ ??? 722cdf0e10cSrcweir 723cdf0e10cSrcweir if ( !Name.getLength() ) 724cdf0e10cSrcweir throw lang::IllegalArgumentException(); 725cdf0e10cSrcweir 726cdf0e10cSrcweir // Check property type. 727cdf0e10cSrcweir if ( !UCBDeadPropertyValue::supportsType( DefaultValue.getValueType() ) ) 728cdf0e10cSrcweir { 729cdf0e10cSrcweir OSL_ENSURE( sal_False, 730cdf0e10cSrcweir "Content::addProperty - Unsupported property type!" ); 731cdf0e10cSrcweir throw beans::IllegalTypeException(); 732cdf0e10cSrcweir } 733cdf0e10cSrcweir 734cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 735cdf0e10cSrcweir // Make sure a property with the requested name does not already 736cdf0e10cSrcweir // exist in dynamic and static(!) properties. 737cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 738cdf0e10cSrcweir 739cdf0e10cSrcweir // @@@ Need real command environment here, but where to get it from? 740cdf0e10cSrcweir // XPropertyContainer interface should be replaced by 741cdf0e10cSrcweir // XCommandProcessor commands! 742cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xEnv; 743cdf0e10cSrcweir 744cdf0e10cSrcweir // Note: This requires network access! 745cdf0e10cSrcweir if ( getPropertySetInfo( xEnv, sal_False /* don't cache data */ ) 746cdf0e10cSrcweir ->hasPropertyByName( Name ) ) 747cdf0e10cSrcweir { 748cdf0e10cSrcweir // Property does already exist. 749cdf0e10cSrcweir throw beans::PropertyExistException(); 750cdf0e10cSrcweir } 751cdf0e10cSrcweir 752cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 753cdf0e10cSrcweir // Add a new dynamic property. 754cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 755cdf0e10cSrcweir 756cdf0e10cSrcweir ProppatchValue aValue( PROPSET, Name, DefaultValue ); 757cdf0e10cSrcweir 758cdf0e10cSrcweir std::vector< ProppatchValue > aProppatchValues; 759cdf0e10cSrcweir aProppatchValues.push_back( aValue ); 760cdf0e10cSrcweir 761cdf0e10cSrcweir try 762cdf0e10cSrcweir { 763cdf0e10cSrcweir // Set property value at server. 764cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 765cdf0e10cSrcweir { 766cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 767cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) ); 768cdf0e10cSrcweir } 769cdf0e10cSrcweir xResAccess->PROPPATCH( aProppatchValues, xEnv ); 770cdf0e10cSrcweir { 771cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 772cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) ); 773cdf0e10cSrcweir } 774cdf0e10cSrcweir 775cdf0e10cSrcweir // Notify propertyset info change listeners. 776cdf0e10cSrcweir beans::PropertySetInfoChangeEvent evt( 777cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 778cdf0e10cSrcweir Name, 779cdf0e10cSrcweir -1, // No handle available 780cdf0e10cSrcweir beans::PropertySetInfoChange::PROPERTY_INSERTED ); 781cdf0e10cSrcweir notifyPropertySetInfoChange( evt ); 782cdf0e10cSrcweir } 783cdf0e10cSrcweir catch ( DAVException const & e ) 784cdf0e10cSrcweir { 785cdf0e10cSrcweir if ( e.getStatus() == SC_FORBIDDEN ) 786cdf0e10cSrcweir { 787cdf0e10cSrcweir // Support for setting arbitrary dead properties is optional! 788cdf0e10cSrcweir 789cdf0e10cSrcweir // Store property locally. 790cdf0e10cSrcweir ContentImplHelper::addProperty( 791cdf0e10cSrcweir Name, Attributes, DefaultValue ); 792cdf0e10cSrcweir } 793cdf0e10cSrcweir else 794cdf0e10cSrcweir { 795cdf0e10cSrcweir if ( shouldAccessNetworkAfterException( e ) ) 796cdf0e10cSrcweir { 797cdf0e10cSrcweir try 798cdf0e10cSrcweir { 799cdf0e10cSrcweir const ResourceType & rType = getResourceType( xEnv ); 800cdf0e10cSrcweir switch ( rType ) 801cdf0e10cSrcweir { 802cdf0e10cSrcweir case UNKNOWN: 803cdf0e10cSrcweir case DAV: 804cdf0e10cSrcweir throw lang::IllegalArgumentException(); 805cdf0e10cSrcweir 806cdf0e10cSrcweir case FTP: 807cdf0e10cSrcweir case NON_DAV: 808cdf0e10cSrcweir // Store property locally. 809cdf0e10cSrcweir ContentImplHelper::addProperty( Name, 810cdf0e10cSrcweir Attributes, 811cdf0e10cSrcweir DefaultValue ); 812cdf0e10cSrcweir break; 813cdf0e10cSrcweir 814cdf0e10cSrcweir default: 815cdf0e10cSrcweir OSL_ENSURE( sal_False, 816cdf0e10cSrcweir "Content::addProperty - " 817cdf0e10cSrcweir "Unsupported resource type!" ); 818cdf0e10cSrcweir break; 819cdf0e10cSrcweir } 820cdf0e10cSrcweir } 821cdf0e10cSrcweir catch ( uno::Exception const & ) 822cdf0e10cSrcweir { 823cdf0e10cSrcweir OSL_ENSURE( sal_False, 824cdf0e10cSrcweir "Content::addProperty - " 825cdf0e10cSrcweir "Unable to determine resource type!" ); 826cdf0e10cSrcweir } 827cdf0e10cSrcweir } 828cdf0e10cSrcweir else 829cdf0e10cSrcweir { 830cdf0e10cSrcweir OSL_ENSURE( sal_False, 831cdf0e10cSrcweir "Content::addProperty - " 832cdf0e10cSrcweir "Unable to determine resource type!" ); 833cdf0e10cSrcweir } 834cdf0e10cSrcweir } 835cdf0e10cSrcweir } 836cdf0e10cSrcweir } 837cdf0e10cSrcweir 838cdf0e10cSrcweir //========================================================================= 839cdf0e10cSrcweir // virtual 840cdf0e10cSrcweir void SAL_CALL Content::removeProperty( const rtl::OUString& Name ) 841cdf0e10cSrcweir throw( beans::UnknownPropertyException, 842cdf0e10cSrcweir beans::NotRemoveableException, 843cdf0e10cSrcweir uno::RuntimeException ) 844cdf0e10cSrcweir { 845cdf0e10cSrcweir // @@@ Need real command environment here, but where to get it from? 846cdf0e10cSrcweir // XPropertyContainer interface should be replaced by 847cdf0e10cSrcweir // XCommandProcessor commands! 848cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xEnv; 849cdf0e10cSrcweir 850cdf0e10cSrcweir #if 0 851cdf0e10cSrcweir // @@@ REMOVEABLE z.Z. nicht richtig an der PropSetInfo gesetzt!!! 852cdf0e10cSrcweir try 853cdf0e10cSrcweir { 854cdf0e10cSrcweir beans::Property aProp 855cdf0e10cSrcweir = getPropertySetInfo( xEnv, sal_False /* don't cache data */ ) 856cdf0e10cSrcweir ->getPropertyByName( Name ); 857cdf0e10cSrcweir 858cdf0e10cSrcweir if ( !( aProp.Attributes & beans::PropertyAttribute::REMOVEABLE ) ) 859cdf0e10cSrcweir { 860cdf0e10cSrcweir // Not removeable! 861cdf0e10cSrcweir throw beans::NotRemoveableException(); 862cdf0e10cSrcweir } 863cdf0e10cSrcweir } 864cdf0e10cSrcweir catch ( beans::UnknownPropertyException const & ) 865cdf0e10cSrcweir { 866cdf0e10cSrcweir //OSL_ENSURE( sal_False, "removeProperty - Unknown property!" ); 867cdf0e10cSrcweir throw; 868cdf0e10cSrcweir } 869cdf0e10cSrcweir #endif 870cdf0e10cSrcweir 871cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 872cdf0e10cSrcweir // Try to remove property from server. 873cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 874cdf0e10cSrcweir 875cdf0e10cSrcweir try 876cdf0e10cSrcweir { 877cdf0e10cSrcweir std::vector< ProppatchValue > aProppatchValues; 878cdf0e10cSrcweir ProppatchValue aValue( PROPREMOVE, Name, uno::Any() ); 879cdf0e10cSrcweir aProppatchValues.push_back( aValue ); 880cdf0e10cSrcweir 881cdf0e10cSrcweir // Remove property value from server. 882cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 883cdf0e10cSrcweir { 884cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 885cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) ); 886cdf0e10cSrcweir } 887cdf0e10cSrcweir xResAccess->PROPPATCH( aProppatchValues, xEnv ); 888cdf0e10cSrcweir { 889cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 890cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) ); 891cdf0e10cSrcweir } 892cdf0e10cSrcweir 893cdf0e10cSrcweir // Notify propertyset info change listeners. 894cdf0e10cSrcweir beans::PropertySetInfoChangeEvent evt( 895cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 896cdf0e10cSrcweir Name, 897cdf0e10cSrcweir -1, // No handle available 898cdf0e10cSrcweir beans::PropertySetInfoChange::PROPERTY_REMOVED ); 899cdf0e10cSrcweir notifyPropertySetInfoChange( evt ); 900cdf0e10cSrcweir } 901cdf0e10cSrcweir catch ( DAVException const & e ) 902cdf0e10cSrcweir { 903cdf0e10cSrcweir if ( e.getStatus() == SC_FORBIDDEN ) 904cdf0e10cSrcweir { 905cdf0e10cSrcweir // Support for setting arbitrary dead properties is optional! 906cdf0e10cSrcweir 907cdf0e10cSrcweir // Try to remove property from local store. 908cdf0e10cSrcweir ContentImplHelper::removeProperty( Name ); 909cdf0e10cSrcweir } 910cdf0e10cSrcweir else 911cdf0e10cSrcweir { 912cdf0e10cSrcweir if ( shouldAccessNetworkAfterException( e ) ) 913cdf0e10cSrcweir { 914cdf0e10cSrcweir try 915cdf0e10cSrcweir { 916cdf0e10cSrcweir const ResourceType & rType = getResourceType( xEnv ); 917cdf0e10cSrcweir switch ( rType ) 918cdf0e10cSrcweir { 919cdf0e10cSrcweir case UNKNOWN: 920cdf0e10cSrcweir case DAV: 921cdf0e10cSrcweir throw beans::UnknownPropertyException(); 922cdf0e10cSrcweir 923cdf0e10cSrcweir case FTP: 924cdf0e10cSrcweir case NON_DAV: 925cdf0e10cSrcweir // Try to remove property from local store. 926cdf0e10cSrcweir ContentImplHelper::removeProperty( Name ); 927cdf0e10cSrcweir break; 928cdf0e10cSrcweir 929cdf0e10cSrcweir default: 930cdf0e10cSrcweir OSL_ENSURE( sal_False, 931cdf0e10cSrcweir "Content::removeProperty - " 932cdf0e10cSrcweir "Unsupported resource type!" ); 933cdf0e10cSrcweir break; 934cdf0e10cSrcweir } 935cdf0e10cSrcweir } 936cdf0e10cSrcweir catch ( uno::Exception const & ) 937cdf0e10cSrcweir { 938cdf0e10cSrcweir OSL_ENSURE( sal_False, 939cdf0e10cSrcweir "Content::removeProperty - " 940cdf0e10cSrcweir "Unable to determine resource type!" ); 941cdf0e10cSrcweir } 942cdf0e10cSrcweir } 943cdf0e10cSrcweir else 944cdf0e10cSrcweir { 945cdf0e10cSrcweir OSL_ENSURE( sal_False, 946cdf0e10cSrcweir "Content::removeProperty - " 947cdf0e10cSrcweir "Unable to determine resource type!" ); 948cdf0e10cSrcweir // throw beans::UnknownPropertyException(); 949cdf0e10cSrcweir } 950cdf0e10cSrcweir } 951cdf0e10cSrcweir } 952cdf0e10cSrcweir } 953cdf0e10cSrcweir 954cdf0e10cSrcweir //========================================================================= 955cdf0e10cSrcweir // 956cdf0e10cSrcweir // XContentCreator methods. 957cdf0e10cSrcweir // 958cdf0e10cSrcweir //========================================================================= 959cdf0e10cSrcweir 960cdf0e10cSrcweir // virtual 961cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > SAL_CALL 962cdf0e10cSrcweir Content::queryCreatableContentsInfo() 963cdf0e10cSrcweir throw( uno::RuntimeException ) 964cdf0e10cSrcweir { 965cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 966cdf0e10cSrcweir 967cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > aSeq( 2 ); 968cdf0e10cSrcweir 969cdf0e10cSrcweir // document. 970cdf0e10cSrcweir aSeq.getArray()[ 0 ].Type 971cdf0e10cSrcweir = rtl::OUString::createFromAscii( WEBDAV_CONTENT_TYPE ); 972cdf0e10cSrcweir aSeq.getArray()[ 0 ].Attributes 973cdf0e10cSrcweir = ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM 974cdf0e10cSrcweir | ucb::ContentInfoAttribute::KIND_DOCUMENT; 975cdf0e10cSrcweir 976cdf0e10cSrcweir beans::Property aProp; 977cdf0e10cSrcweir m_pProvider->getProperty( 978cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), aProp ); 979cdf0e10cSrcweir 980cdf0e10cSrcweir uno::Sequence< beans::Property > aDocProps( 1 ); 981cdf0e10cSrcweir aDocProps.getArray()[ 0 ] = aProp; 982cdf0e10cSrcweir aSeq.getArray()[ 0 ].Properties = aDocProps; 983cdf0e10cSrcweir 984cdf0e10cSrcweir // folder. 985cdf0e10cSrcweir aSeq.getArray()[ 1 ].Type 986cdf0e10cSrcweir = rtl::OUString::createFromAscii( WEBDAV_COLLECTION_TYPE ); 987cdf0e10cSrcweir aSeq.getArray()[ 1 ].Attributes 988cdf0e10cSrcweir = ucb::ContentInfoAttribute::KIND_FOLDER; 989cdf0e10cSrcweir 990cdf0e10cSrcweir uno::Sequence< beans::Property > aFolderProps( 1 ); 991cdf0e10cSrcweir aFolderProps.getArray()[ 0 ] = aProp; 992cdf0e10cSrcweir aSeq.getArray()[ 1 ].Properties = aFolderProps; 993cdf0e10cSrcweir return aSeq; 994cdf0e10cSrcweir } 995cdf0e10cSrcweir 996cdf0e10cSrcweir //========================================================================= 997cdf0e10cSrcweir // virtual 998cdf0e10cSrcweir uno::Reference< ucb::XContent > SAL_CALL 999cdf0e10cSrcweir Content::createNewContent( const ucb::ContentInfo& Info ) 1000cdf0e10cSrcweir throw( uno::RuntimeException ) 1001cdf0e10cSrcweir { 1002cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1003cdf0e10cSrcweir 1004cdf0e10cSrcweir if ( !Info.Type.getLength() ) 1005cdf0e10cSrcweir return uno::Reference< ucb::XContent >(); 1006cdf0e10cSrcweir 1007cdf0e10cSrcweir if ( ( !Info.Type.equalsAsciiL( 1008cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_COLLECTION_TYPE ) ) ) 1009cdf0e10cSrcweir && 1010cdf0e10cSrcweir ( !Info.Type.equalsAsciiL( 1011cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_CONTENT_TYPE ) ) ) ) 1012cdf0e10cSrcweir return uno::Reference< ucb::XContent >(); 1013cdf0e10cSrcweir 1014cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier(); 1015cdf0e10cSrcweir 1016cdf0e10cSrcweir OSL_ENSURE( aURL.getLength() > 0, 1017cdf0e10cSrcweir "WebdavContent::createNewContent - empty identifier!" ); 1018cdf0e10cSrcweir 1019cdf0e10cSrcweir if ( ( aURL.lastIndexOf( '/' ) + 1 ) != aURL.getLength() ) 1020cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" ); 1021cdf0e10cSrcweir 1022cdf0e10cSrcweir sal_Bool isCollection; 1023cdf0e10cSrcweir if ( Info.Type.equalsAsciiL( 1024cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_COLLECTION_TYPE ) ) ) 1025cdf0e10cSrcweir { 1026cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "New_Collection" ); 1027cdf0e10cSrcweir isCollection = sal_True; 1028cdf0e10cSrcweir } 1029cdf0e10cSrcweir else 1030cdf0e10cSrcweir { 1031cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "New_Content" ); 1032cdf0e10cSrcweir isCollection = sal_False; 1033cdf0e10cSrcweir } 1034cdf0e10cSrcweir 1035cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xId( 1036cdf0e10cSrcweir new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL ) ); 1037cdf0e10cSrcweir 1038cdf0e10cSrcweir // create the local content 1039cdf0e10cSrcweir try 1040cdf0e10cSrcweir { 1041cdf0e10cSrcweir return new ::webdav_ucp::Content( m_xSMgr, 1042cdf0e10cSrcweir m_pProvider, 1043cdf0e10cSrcweir xId, 1044cdf0e10cSrcweir m_xResAccess->getSessionFactory(), 1045cdf0e10cSrcweir isCollection ); 1046cdf0e10cSrcweir } 1047cdf0e10cSrcweir catch ( ucb::ContentCreationException & ) 1048cdf0e10cSrcweir { 1049cdf0e10cSrcweir return uno::Reference< ucb::XContent >(); 1050cdf0e10cSrcweir } 1051cdf0e10cSrcweir } 1052cdf0e10cSrcweir 1053cdf0e10cSrcweir //========================================================================= 1054cdf0e10cSrcweir // virtual 1055cdf0e10cSrcweir rtl::OUString Content::getParentURL() 1056cdf0e10cSrcweir { 1057cdf0e10cSrcweir // <scheme>:// -> "" 1058cdf0e10cSrcweir // <scheme>://foo -> "" 1059cdf0e10cSrcweir // <scheme>://foo/ -> "" 1060cdf0e10cSrcweir // <scheme>://foo/bar -> <scheme>://foo/ 1061cdf0e10cSrcweir // <scheme>://foo/bar/ -> <scheme>://foo/ 1062cdf0e10cSrcweir // <scheme>://foo/bar/abc -> <scheme>://foo/bar/ 1063cdf0e10cSrcweir 1064cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier(); 1065cdf0e10cSrcweir 1066cdf0e10cSrcweir sal_Int32 nPos = aURL.lastIndexOf( '/' ); 1067cdf0e10cSrcweir if ( nPos == ( aURL.getLength() - 1 ) ) 1068cdf0e10cSrcweir { 1069cdf0e10cSrcweir // Trailing slash found. Skip. 1070cdf0e10cSrcweir nPos = aURL.lastIndexOf( '/', nPos ); 1071cdf0e10cSrcweir } 1072cdf0e10cSrcweir 1073cdf0e10cSrcweir sal_Int32 nPos1 = aURL.lastIndexOf( '/', nPos ); 1074cdf0e10cSrcweir if ( nPos1 != -1 ) 1075cdf0e10cSrcweir nPos1 = aURL.lastIndexOf( '/', nPos1 ); 1076cdf0e10cSrcweir 1077cdf0e10cSrcweir if ( nPos1 == -1 ) 1078cdf0e10cSrcweir return rtl::OUString(); 1079cdf0e10cSrcweir 1080cdf0e10cSrcweir return rtl::OUString( aURL.copy( 0, nPos + 1 ) ); 1081cdf0e10cSrcweir } 1082cdf0e10cSrcweir 1083cdf0e10cSrcweir //========================================================================= 1084cdf0e10cSrcweir // 1085cdf0e10cSrcweir // Non-interface methods. 1086cdf0e10cSrcweir // 1087cdf0e10cSrcweir //========================================================================= 1088cdf0e10cSrcweir 1089cdf0e10cSrcweir // static 1090cdf0e10cSrcweir uno::Reference< sdbc::XRow > Content::getPropertyValues( 1091cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rSMgr, 1092cdf0e10cSrcweir const uno::Sequence< beans::Property >& rProperties, 1093cdf0e10cSrcweir const ContentProperties& rData, 1094cdf0e10cSrcweir const rtl::Reference< ::ucbhelper::ContentProviderImplHelper >& rProvider, 1095cdf0e10cSrcweir const rtl::OUString& rContentId ) 1096cdf0e10cSrcweir { 1097cdf0e10cSrcweir // Note: Empty sequence means "get values of all supported properties". 1098cdf0e10cSrcweir 1099cdf0e10cSrcweir rtl::Reference< ::ucbhelper::PropertyValueSet > xRow 1100cdf0e10cSrcweir = new ::ucbhelper::PropertyValueSet( rSMgr ); 1101cdf0e10cSrcweir 1102cdf0e10cSrcweir sal_Int32 nCount = rProperties.getLength(); 1103cdf0e10cSrcweir if ( nCount ) 1104cdf0e10cSrcweir { 1105cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xAdditionalPropSet; 1106cdf0e10cSrcweir sal_Bool bTriedToGetAdditonalPropSet = sal_False; 1107cdf0e10cSrcweir 1108cdf0e10cSrcweir const beans::Property* pProps = rProperties.getConstArray(); 1109cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) 1110cdf0e10cSrcweir { 1111cdf0e10cSrcweir const beans::Property& rProp = pProps[ n ]; 1112cdf0e10cSrcweir 1113cdf0e10cSrcweir // Process standard UCB, DAV and HTTP properties. 1114cdf0e10cSrcweir const uno::Any & rValue = rData.getValue( rProp.Name ); 1115cdf0e10cSrcweir if ( rValue.hasValue() ) 1116cdf0e10cSrcweir { 1117cdf0e10cSrcweir xRow->appendObject( rProp, rValue ); 1118cdf0e10cSrcweir } 1119cdf0e10cSrcweir else 1120cdf0e10cSrcweir { 1121cdf0e10cSrcweir // Process local Additional Properties. 1122cdf0e10cSrcweir if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() ) 1123cdf0e10cSrcweir { 1124cdf0e10cSrcweir xAdditionalPropSet 1125cdf0e10cSrcweir = uno::Reference< beans::XPropertySet >( 1126cdf0e10cSrcweir rProvider->getAdditionalPropertySet( rContentId, 1127cdf0e10cSrcweir sal_False ), 1128cdf0e10cSrcweir uno::UNO_QUERY ); 1129cdf0e10cSrcweir bTriedToGetAdditonalPropSet = sal_True; 1130cdf0e10cSrcweir } 1131cdf0e10cSrcweir 1132cdf0e10cSrcweir if ( !xAdditionalPropSet.is() || 1133cdf0e10cSrcweir !xRow->appendPropertySetValue( 1134cdf0e10cSrcweir xAdditionalPropSet, rProp ) ) 1135cdf0e10cSrcweir { 1136cdf0e10cSrcweir // Append empty entry. 1137cdf0e10cSrcweir xRow->appendVoid( rProp ); 1138cdf0e10cSrcweir } 1139cdf0e10cSrcweir } 1140cdf0e10cSrcweir } 1141cdf0e10cSrcweir } 1142cdf0e10cSrcweir else 1143cdf0e10cSrcweir { 1144cdf0e10cSrcweir // Append all standard UCB, DAV and HTTP properties. 1145cdf0e10cSrcweir 1146cdf0e10cSrcweir const std::auto_ptr< PropertyValueMap > & xProps = rData.getProperties(); 1147cdf0e10cSrcweir 1148cdf0e10cSrcweir PropertyValueMap::const_iterator it = xProps->begin(); 1149cdf0e10cSrcweir PropertyValueMap::const_iterator end = xProps->end(); 1150cdf0e10cSrcweir 1151cdf0e10cSrcweir ContentProvider * pProvider 1152cdf0e10cSrcweir = static_cast< ContentProvider * >( rProvider.get() ); 1153cdf0e10cSrcweir beans::Property aProp; 1154cdf0e10cSrcweir 1155cdf0e10cSrcweir while ( it != end ) 1156cdf0e10cSrcweir { 1157cdf0e10cSrcweir if ( pProvider->getProperty( (*it).first, aProp ) ) 1158cdf0e10cSrcweir xRow->appendObject( aProp, (*it).second.value() ); 1159cdf0e10cSrcweir 1160cdf0e10cSrcweir ++it; 1161cdf0e10cSrcweir } 1162cdf0e10cSrcweir 1163cdf0e10cSrcweir // Append all local Additional Properties. 1164cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xSet( 1165cdf0e10cSrcweir rProvider->getAdditionalPropertySet( rContentId, sal_False ), 1166cdf0e10cSrcweir uno::UNO_QUERY ); 1167cdf0e10cSrcweir xRow->appendPropertySet( xSet ); 1168cdf0e10cSrcweir } 1169cdf0e10cSrcweir 1170cdf0e10cSrcweir return uno::Reference< sdbc::XRow >( xRow.get() ); 1171cdf0e10cSrcweir } 1172cdf0e10cSrcweir 1173cdf0e10cSrcweir //========================================================================= 1174cdf0e10cSrcweir uno::Reference< sdbc::XRow > Content::getPropertyValues( 1175cdf0e10cSrcweir const uno::Sequence< beans::Property >& rProperties, 1176cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv ) 1177cdf0e10cSrcweir throw ( uno::Exception ) 1178cdf0e10cSrcweir { 1179cdf0e10cSrcweir std::auto_ptr< ContentProperties > xProps; 1180cdf0e10cSrcweir std::auto_ptr< ContentProperties > xCachedProps; 1181cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 1182cdf0e10cSrcweir rtl::OUString aUnescapedTitle; 1183cdf0e10cSrcweir bool bHasAll = false; 1184cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xSMgr; 1185cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xIdentifier; 1186cdf0e10cSrcweir rtl::Reference< ::ucbhelper::ContentProviderImplHelper > xProvider; 1187cdf0e10cSrcweir 1188cdf0e10cSrcweir { 1189cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1190cdf0e10cSrcweir 1191cdf0e10cSrcweir aUnescapedTitle = NeonUri::unescape( m_aEscapedTitle ); 1192cdf0e10cSrcweir xSMgr.set( m_xSMgr ); 1193cdf0e10cSrcweir xIdentifier.set( m_xIdentifier ); 1194cdf0e10cSrcweir xProvider.set( m_xProvider.get() ); 1195cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) ); 1196cdf0e10cSrcweir 1197cdf0e10cSrcweir // First, ask cache... 1198cdf0e10cSrcweir if ( m_xCachedProps.get() ) 1199cdf0e10cSrcweir { 1200cdf0e10cSrcweir xCachedProps.reset( new ContentProperties( *m_xCachedProps.get() ) ); 1201cdf0e10cSrcweir 1202cdf0e10cSrcweir std::vector< rtl::OUString > aMissingProps; 1203cdf0e10cSrcweir if ( xCachedProps->containsAllNames( rProperties, aMissingProps ) ) 1204cdf0e10cSrcweir { 1205cdf0e10cSrcweir // All properties are already in cache! No server access needed. 1206cdf0e10cSrcweir bHasAll = true; 1207cdf0e10cSrcweir } 1208cdf0e10cSrcweir 1209cdf0e10cSrcweir // use the cached ContentProperties instance 1210cdf0e10cSrcweir xProps.reset( new ContentProperties( *xCachedProps.get() ) ); 1211cdf0e10cSrcweir } 1212cdf0e10cSrcweir } 1213cdf0e10cSrcweir 1214cdf0e10cSrcweir if ( !m_bTransient && !bHasAll ) 1215cdf0e10cSrcweir { 1216cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////// 1217cdf0e10cSrcweir // Obtain values from server... 1218cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////// 1219cdf0e10cSrcweir 1220cdf0e10cSrcweir // First, identify whether resource is DAV or not 1221cdf0e10cSrcweir const ResourceType & rType = getResourceType( xEnv, xResAccess ); 1222cdf0e10cSrcweir 1223cdf0e10cSrcweir bool bNetworkAccessAllowed = true; 1224cdf0e10cSrcweir 1225cdf0e10cSrcweir if ( DAV == rType ) 1226cdf0e10cSrcweir { 1227cdf0e10cSrcweir // cache lookup... getResourceType may fill the props cache via 1228cdf0e10cSrcweir // PROPFIND! 1229cdf0e10cSrcweir if ( m_xCachedProps.get() ) 1230cdf0e10cSrcweir { 1231cdf0e10cSrcweir xCachedProps.reset( 1232cdf0e10cSrcweir new ContentProperties( *m_xCachedProps.get() ) ); 1233cdf0e10cSrcweir 1234cdf0e10cSrcweir std::vector< rtl::OUString > aMissingProps; 1235cdf0e10cSrcweir if ( xCachedProps->containsAllNames( 1236cdf0e10cSrcweir rProperties, aMissingProps ) ) 1237cdf0e10cSrcweir { 1238cdf0e10cSrcweir // All properties are already in cache! No server access 1239cdf0e10cSrcweir // needed. 1240cdf0e10cSrcweir bHasAll = true; 1241cdf0e10cSrcweir } 1242cdf0e10cSrcweir 1243cdf0e10cSrcweir // use the cached ContentProperties instance 1244cdf0e10cSrcweir xProps.reset( new ContentProperties( *xCachedProps.get() ) ); 1245cdf0e10cSrcweir } 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir if ( !bHasAll ) 1248cdf0e10cSrcweir { 1249cdf0e10cSrcweir // Only DAV resources support PROPFIND 1250cdf0e10cSrcweir std::vector< rtl::OUString > aPropNames; 1251cdf0e10cSrcweir 1252cdf0e10cSrcweir uno::Sequence< beans::Property > aProperties( 1253cdf0e10cSrcweir rProperties.getLength() ); 1254cdf0e10cSrcweir 1255cdf0e10cSrcweir if ( m_aFailedPropNames.size() > 0 ) 1256cdf0e10cSrcweir { 1257cdf0e10cSrcweir sal_Int32 nProps = 0; 1258cdf0e10cSrcweir sal_Int32 nCount = rProperties.getLength(); 1259cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) 1260cdf0e10cSrcweir { 1261cdf0e10cSrcweir const rtl::OUString & rName = rProperties[ n ].Name; 1262cdf0e10cSrcweir 1263cdf0e10cSrcweir std::vector< rtl::OUString >::const_iterator it 1264cdf0e10cSrcweir = m_aFailedPropNames.begin(); 1265cdf0e10cSrcweir std::vector< rtl::OUString >::const_iterator end 1266cdf0e10cSrcweir = m_aFailedPropNames.end(); 1267cdf0e10cSrcweir 1268cdf0e10cSrcweir while ( it != end ) 1269cdf0e10cSrcweir { 1270cdf0e10cSrcweir if ( *it == rName ) 1271cdf0e10cSrcweir break; 1272cdf0e10cSrcweir 1273cdf0e10cSrcweir ++it; 1274cdf0e10cSrcweir } 1275cdf0e10cSrcweir 1276cdf0e10cSrcweir if ( it == end ) 1277cdf0e10cSrcweir { 1278cdf0e10cSrcweir aProperties[ nProps ] = rProperties[ n ]; 1279cdf0e10cSrcweir nProps++; 1280cdf0e10cSrcweir } 1281cdf0e10cSrcweir } 1282cdf0e10cSrcweir 1283cdf0e10cSrcweir aProperties.realloc( nProps ); 1284cdf0e10cSrcweir } 1285cdf0e10cSrcweir else 1286cdf0e10cSrcweir { 1287cdf0e10cSrcweir aProperties = rProperties; 1288cdf0e10cSrcweir } 1289cdf0e10cSrcweir 1290cdf0e10cSrcweir if ( aProperties.getLength() > 0 ) 1291cdf0e10cSrcweir ContentProperties::UCBNamesToDAVNames( 1292cdf0e10cSrcweir aProperties, aPropNames ); 1293cdf0e10cSrcweir 1294cdf0e10cSrcweir if ( aPropNames.size() > 0 ) 1295cdf0e10cSrcweir { 1296cdf0e10cSrcweir std::vector< DAVResource > resources; 1297cdf0e10cSrcweir try 1298cdf0e10cSrcweir { 1299cdf0e10cSrcweir xResAccess->PROPFIND( 1300cdf0e10cSrcweir DAVZERO, aPropNames, resources, xEnv ); 1301cdf0e10cSrcweir 1302cdf0e10cSrcweir if ( 1 == resources.size() ) 1303cdf0e10cSrcweir { 1304cdf0e10cSrcweir if ( xProps.get()) 1305cdf0e10cSrcweir xProps->addProperties( 1306cdf0e10cSrcweir aPropNames, 1307cdf0e10cSrcweir ContentProperties( resources[ 0 ] )); 1308cdf0e10cSrcweir else 1309cdf0e10cSrcweir xProps.reset( 1310cdf0e10cSrcweir new ContentProperties( resources[ 0 ] ) ); 1311cdf0e10cSrcweir } 1312cdf0e10cSrcweir } 1313cdf0e10cSrcweir catch ( DAVException const & e ) 1314cdf0e10cSrcweir { 1315cdf0e10cSrcweir bNetworkAccessAllowed 1316cdf0e10cSrcweir = shouldAccessNetworkAfterException( e ); 1317cdf0e10cSrcweir 1318cdf0e10cSrcweir if ( !bNetworkAccessAllowed ) 1319cdf0e10cSrcweir { 1320cdf0e10cSrcweir cancelCommandExecution( e, xEnv ); 1321cdf0e10cSrcweir // unreachable 1322cdf0e10cSrcweir } 1323cdf0e10cSrcweir } 1324cdf0e10cSrcweir } 1325cdf0e10cSrcweir } 1326cdf0e10cSrcweir } 1327cdf0e10cSrcweir 1328cdf0e10cSrcweir if ( bNetworkAccessAllowed ) 1329cdf0e10cSrcweir { 1330cdf0e10cSrcweir // All properties obtained already? 1331cdf0e10cSrcweir std::vector< rtl::OUString > aMissingProps; 1332cdf0e10cSrcweir if ( !( xProps.get() 1333cdf0e10cSrcweir && xProps->containsAllNames( 1334cdf0e10cSrcweir rProperties, aMissingProps ) ) 1335cdf0e10cSrcweir && !m_bDidGetOrHead ) 1336cdf0e10cSrcweir { 1337cdf0e10cSrcweir // Possibly the missing props can be obtained using a HEAD 1338cdf0e10cSrcweir // request. 1339cdf0e10cSrcweir 1340cdf0e10cSrcweir std::vector< rtl::OUString > aHeaderNames; 1341cdf0e10cSrcweir ContentProperties::UCBNamesToHTTPNames( 1342cdf0e10cSrcweir rProperties, 1343cdf0e10cSrcweir aHeaderNames, 1344cdf0e10cSrcweir true /* bIncludeUnmatched */ ); 1345cdf0e10cSrcweir 1346cdf0e10cSrcweir if ( aHeaderNames.size() > 0 ) 1347cdf0e10cSrcweir { 1348cdf0e10cSrcweir try 1349cdf0e10cSrcweir { 1350cdf0e10cSrcweir DAVResource resource; 1351cdf0e10cSrcweir xResAccess->HEAD( aHeaderNames, resource, xEnv ); 1352cdf0e10cSrcweir m_bDidGetOrHead = true; 1353cdf0e10cSrcweir 1354cdf0e10cSrcweir if ( xProps.get() ) 1355cdf0e10cSrcweir xProps->addProperties( 1356cdf0e10cSrcweir aMissingProps, 1357cdf0e10cSrcweir ContentProperties( resource ) ); 1358cdf0e10cSrcweir else 1359cdf0e10cSrcweir xProps.reset ( new ContentProperties( resource ) ); 1360cdf0e10cSrcweir 1361cdf0e10cSrcweir if ( m_eResourceType == NON_DAV ) 1362cdf0e10cSrcweir xProps->addProperties( aMissingProps, 1363cdf0e10cSrcweir ContentProperties( 1364cdf0e10cSrcweir aUnescapedTitle, 1365cdf0e10cSrcweir false ) ); 1366cdf0e10cSrcweir } 1367cdf0e10cSrcweir catch ( DAVException const & e ) 1368cdf0e10cSrcweir { 1369cdf0e10cSrcweir bNetworkAccessAllowed 1370cdf0e10cSrcweir = shouldAccessNetworkAfterException( e ); 1371cdf0e10cSrcweir 1372cdf0e10cSrcweir if ( !bNetworkAccessAllowed ) 1373cdf0e10cSrcweir { 1374cdf0e10cSrcweir cancelCommandExecution( e, xEnv ); 1375cdf0e10cSrcweir // unreachable 1376cdf0e10cSrcweir } 1377cdf0e10cSrcweir } 1378cdf0e10cSrcweir } 1379cdf0e10cSrcweir } 1380cdf0e10cSrcweir } 1381cdf0e10cSrcweir 1382cdf0e10cSrcweir // might trigger HTTP redirect. 1383cdf0e10cSrcweir // Therefore, title must be updated here. 1384cdf0e10cSrcweir NeonUri aUri( xResAccess->getURL() ); 1385cdf0e10cSrcweir aUnescapedTitle = aUri.GetPathBaseNameUnescaped(); 1386cdf0e10cSrcweir 1387cdf0e10cSrcweir if ( rType == UNKNOWN ) 1388cdf0e10cSrcweir { 1389cdf0e10cSrcweir xProps.reset( new ContentProperties( aUnescapedTitle ) ); 1390cdf0e10cSrcweir } 1391cdf0e10cSrcweir 1392cdf0e10cSrcweir // For DAV resources we only know the Title, for non-DAV 1393cdf0e10cSrcweir // resources we additionally know that it is a document. 1394cdf0e10cSrcweir 1395cdf0e10cSrcweir if ( rType == DAV ) 1396cdf0e10cSrcweir { 1397cdf0e10cSrcweir //xProps.reset( 1398cdf0e10cSrcweir // new ContentProperties( aUnescapedTitle ) ); 1399cdf0e10cSrcweir xProps->addProperty( 1400cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), 1401cdf0e10cSrcweir uno::makeAny( aUnescapedTitle ), 1402cdf0e10cSrcweir true ); 1403cdf0e10cSrcweir } 1404cdf0e10cSrcweir else 1405cdf0e10cSrcweir { 1406cdf0e10cSrcweir if ( !xProps.get() ) 1407cdf0e10cSrcweir xProps.reset( new ContentProperties( aUnescapedTitle, false ) ); 1408cdf0e10cSrcweir else 1409cdf0e10cSrcweir xProps->addProperty( 1410cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), 1411cdf0e10cSrcweir uno::makeAny( aUnescapedTitle ), 1412cdf0e10cSrcweir true ); 1413cdf0e10cSrcweir 1414cdf0e10cSrcweir xProps->addProperty( 1415cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ), 1416cdf0e10cSrcweir uno::makeAny( false ), 1417cdf0e10cSrcweir true ); 1418cdf0e10cSrcweir xProps->addProperty( 1419cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ), 1420cdf0e10cSrcweir uno::makeAny( true ), 1421cdf0e10cSrcweir true ); 1422cdf0e10cSrcweir } 1423cdf0e10cSrcweir } 1424cdf0e10cSrcweir else 1425cdf0e10cSrcweir { 1426cdf0e10cSrcweir // No server access for just created (not yet committed) objects. 1427cdf0e10cSrcweir // Only a minimal set of properties supported at this stage. 1428cdf0e10cSrcweir if (m_bTransient) 1429cdf0e10cSrcweir xProps.reset( new ContentProperties( aUnescapedTitle, 1430cdf0e10cSrcweir m_bCollection ) ); 1431cdf0e10cSrcweir } 1432cdf0e10cSrcweir 1433cdf0e10cSrcweir sal_Int32 nCount = rProperties.getLength(); 1434cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) 1435cdf0e10cSrcweir { 1436cdf0e10cSrcweir const rtl::OUString rName = rProperties[ n ].Name; 1437cdf0e10cSrcweir if ( rName.equalsAsciiL( 1438cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "BaseURI" ) ) ) 1439cdf0e10cSrcweir { 1440cdf0e10cSrcweir // Add BaseURI property, if requested. 1441cdf0e10cSrcweir xProps->addProperty( 1442cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseURI" ) ), 1443cdf0e10cSrcweir uno::makeAny( getBaseURI( xResAccess ) ), 1444cdf0e10cSrcweir true ); 1445cdf0e10cSrcweir } 1446cdf0e10cSrcweir else if ( rName.equalsAsciiL( 1447cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) ) 1448cdf0e10cSrcweir { 1449cdf0e10cSrcweir // Add CreatableContentsInfo property, if requested. 1450cdf0e10cSrcweir sal_Bool bFolder = sal_False; 1451cdf0e10cSrcweir xProps->getValue( 1452cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ) ) 1453cdf0e10cSrcweir >>= bFolder; 1454cdf0e10cSrcweir xProps->addProperty( 1455cdf0e10cSrcweir rtl::OUString( 1456cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "CreatableContentsInfo" ) ), 1457cdf0e10cSrcweir uno::makeAny( bFolder 1458cdf0e10cSrcweir ? queryCreatableContentsInfo() 1459cdf0e10cSrcweir : uno::Sequence< ucb::ContentInfo >() ), 1460cdf0e10cSrcweir true ); 1461cdf0e10cSrcweir } 1462cdf0e10cSrcweir } 1463cdf0e10cSrcweir 1464cdf0e10cSrcweir uno::Reference< sdbc::XRow > xResultRow 1465cdf0e10cSrcweir = getPropertyValues( xSMgr, 1466cdf0e10cSrcweir rProperties, 1467cdf0e10cSrcweir *xProps, 1468cdf0e10cSrcweir xProvider, 1469cdf0e10cSrcweir xIdentifier->getContentIdentifier() ); 1470cdf0e10cSrcweir 1471cdf0e10cSrcweir { 1472cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1473cdf0e10cSrcweir 1474cdf0e10cSrcweir if ( !m_xCachedProps.get() ) 1475cdf0e10cSrcweir m_xCachedProps.reset( new CachableContentProperties( *xProps.get() ) ); 1476cdf0e10cSrcweir else 1477cdf0e10cSrcweir m_xCachedProps->addProperties( *xProps.get() ); 1478cdf0e10cSrcweir 1479cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) ); 1480cdf0e10cSrcweir m_aEscapedTitle = NeonUri::escapeSegment( aUnescapedTitle ); 1481cdf0e10cSrcweir } 1482cdf0e10cSrcweir 1483cdf0e10cSrcweir return xResultRow; 1484cdf0e10cSrcweir } 1485cdf0e10cSrcweir 1486cdf0e10cSrcweir //========================================================================= 1487cdf0e10cSrcweir uno::Sequence< uno::Any > Content::setPropertyValues( 1488cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& rValues, 1489cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv ) 1490cdf0e10cSrcweir throw ( uno::Exception ) 1491cdf0e10cSrcweir { 1492cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xSMgr; 1493cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xIdentifier; 1494cdf0e10cSrcweir rtl::Reference< ContentProvider > xProvider; 1495cdf0e10cSrcweir sal_Bool bTransient; 1496cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 1497cdf0e10cSrcweir 1498cdf0e10cSrcweir { 1499cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1500cdf0e10cSrcweir 1501cdf0e10cSrcweir xProvider.set( m_pProvider ); 1502cdf0e10cSrcweir xIdentifier.set( m_xIdentifier ); 1503cdf0e10cSrcweir bTransient = m_bTransient; 1504cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) ); 1505cdf0e10cSrcweir xSMgr.set( m_xSMgr ); 1506cdf0e10cSrcweir } 1507cdf0e10cSrcweir 1508cdf0e10cSrcweir uno::Sequence< uno::Any > aRet( rValues.getLength() ); 1509cdf0e10cSrcweir uno::Sequence< beans::PropertyChangeEvent > aChanges( rValues.getLength() ); 1510cdf0e10cSrcweir sal_Int32 nChanged = 0; 1511cdf0e10cSrcweir 1512cdf0e10cSrcweir beans::PropertyChangeEvent aEvent; 1513cdf0e10cSrcweir aEvent.Source = static_cast< cppu::OWeakObject * >( this ); 1514cdf0e10cSrcweir aEvent.Further = sal_False; 1515cdf0e10cSrcweir // aEvent.PropertyName = 1516cdf0e10cSrcweir aEvent.PropertyHandle = -1; 1517cdf0e10cSrcweir // aEvent.OldValue = 1518cdf0e10cSrcweir // aEvent.NewValue = 1519cdf0e10cSrcweir 1520cdf0e10cSrcweir std::vector< ProppatchValue > aProppatchValues; 1521cdf0e10cSrcweir std::vector< sal_Int32 > aProppatchPropsPositions; 1522cdf0e10cSrcweir 1523cdf0e10cSrcweir uno::Reference< ucb::XPersistentPropertySet > xAdditionalPropSet; 1524cdf0e10cSrcweir sal_Bool bTriedToGetAdditonalPropSet = sal_False; 1525cdf0e10cSrcweir 1526cdf0e10cSrcweir sal_Bool bExchange = sal_False; 1527cdf0e10cSrcweir rtl::OUString aNewTitle; 1528cdf0e10cSrcweir rtl::OUString aOldTitle; 1529cdf0e10cSrcweir sal_Int32 nTitlePos = -1; 1530cdf0e10cSrcweir 1531cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > xInfo; 1532cdf0e10cSrcweir 1533cdf0e10cSrcweir const beans::PropertyValue* pValues = rValues.getConstArray(); 1534cdf0e10cSrcweir sal_Int32 nCount = rValues.getLength(); 1535cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) 1536cdf0e10cSrcweir { 1537cdf0e10cSrcweir const beans::PropertyValue& rValue = pValues[ n ]; 1538cdf0e10cSrcweir const rtl::OUString & rName = rValue.Name; 1539cdf0e10cSrcweir 1540cdf0e10cSrcweir beans::Property aTmpProp; 1541cdf0e10cSrcweir xProvider->getProperty( rName, aTmpProp ); 1542cdf0e10cSrcweir 1543cdf0e10cSrcweir if ( aTmpProp.Attributes & beans::PropertyAttribute::READONLY ) 1544cdf0e10cSrcweir { 1545cdf0e10cSrcweir // Read-only property! 1546cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1547cdf0e10cSrcweir rtl::OUString::createFromAscii( 1548cdf0e10cSrcweir "Property is read-only!" ), 1549cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1550cdf0e10cSrcweir continue; 1551cdf0e10cSrcweir } 1552cdf0e10cSrcweir 1553cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 1554cdf0e10cSrcweir // Mandatory props. 1555cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 1556cdf0e10cSrcweir 1557cdf0e10cSrcweir if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) ) 1558cdf0e10cSrcweir { 1559cdf0e10cSrcweir // Read-only property! 1560cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1561cdf0e10cSrcweir rtl::OUString::createFromAscii( 1562cdf0e10cSrcweir "Property is read-only!" ), 1563cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1564cdf0e10cSrcweir } 1565cdf0e10cSrcweir else if ( rName.equalsAsciiL( 1566cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) ) 1567cdf0e10cSrcweir { 1568cdf0e10cSrcweir // Read-only property! 1569cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1570cdf0e10cSrcweir rtl::OUString::createFromAscii( 1571cdf0e10cSrcweir "Property is read-only!" ), 1572cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1573cdf0e10cSrcweir } 1574cdf0e10cSrcweir else if ( rName.equalsAsciiL( 1575cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) ) 1576cdf0e10cSrcweir { 1577cdf0e10cSrcweir // Read-only property! 1578cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1579cdf0e10cSrcweir rtl::OUString::createFromAscii( 1580cdf0e10cSrcweir "Property is read-only!" ), 1581cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1582cdf0e10cSrcweir } 1583cdf0e10cSrcweir else if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Title" ) ) ) 1584cdf0e10cSrcweir { 1585cdf0e10cSrcweir rtl::OUString aNewValue; 1586cdf0e10cSrcweir if ( rValue.Value >>= aNewValue ) 1587cdf0e10cSrcweir { 1588cdf0e10cSrcweir // No empty titles! 1589cdf0e10cSrcweir if ( aNewValue.getLength() > 0 ) 1590cdf0e10cSrcweir { 1591cdf0e10cSrcweir try 1592cdf0e10cSrcweir { 1593cdf0e10cSrcweir NeonUri aURI( xIdentifier->getContentIdentifier() ); 1594cdf0e10cSrcweir aOldTitle = aURI.GetPathBaseNameUnescaped(); 1595cdf0e10cSrcweir 1596cdf0e10cSrcweir if ( aNewValue != aOldTitle ) 1597cdf0e10cSrcweir { 1598cdf0e10cSrcweir // modified title -> modified URL -> exchange ! 1599cdf0e10cSrcweir if ( !bTransient ) 1600cdf0e10cSrcweir bExchange = sal_True; 1601cdf0e10cSrcweir 1602cdf0e10cSrcweir // new value will be set later... 1603cdf0e10cSrcweir aNewTitle = aNewValue; 1604cdf0e10cSrcweir 1605cdf0e10cSrcweir // remember position within sequence of values (for 1606cdf0e10cSrcweir // error handling). 1607cdf0e10cSrcweir nTitlePos = n; 1608cdf0e10cSrcweir } 1609cdf0e10cSrcweir } 1610cdf0e10cSrcweir catch ( DAVException const & ) 1611cdf0e10cSrcweir { 1612cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalArgumentException( 1613cdf0e10cSrcweir rtl::OUString::createFromAscii( 1614cdf0e10cSrcweir "Invalid content identifier!" ), 1615cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 1616cdf0e10cSrcweir -1 ); 1617cdf0e10cSrcweir } 1618cdf0e10cSrcweir } 1619cdf0e10cSrcweir else 1620cdf0e10cSrcweir { 1621cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalArgumentException( 1622cdf0e10cSrcweir rtl::OUString::createFromAscii( 1623cdf0e10cSrcweir "Empty title not allowed!" ), 1624cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 1625cdf0e10cSrcweir -1 ); 1626cdf0e10cSrcweir } 1627cdf0e10cSrcweir } 1628cdf0e10cSrcweir else 1629cdf0e10cSrcweir { 1630cdf0e10cSrcweir aRet[ n ] <<= beans::IllegalTypeException( 1631cdf0e10cSrcweir rtl::OUString::createFromAscii( 1632cdf0e10cSrcweir "Property value has wrong type!" ), 1633cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1634cdf0e10cSrcweir } 1635cdf0e10cSrcweir } 1636cdf0e10cSrcweir else 1637cdf0e10cSrcweir { 1638cdf0e10cSrcweir ////////////////////////////////////////////////////////////// 1639cdf0e10cSrcweir // Optional props. 1640cdf0e10cSrcweir ////////////////////////////////////////////////////////////// 1641cdf0e10cSrcweir 1642cdf0e10cSrcweir if ( !xInfo.is() ) 1643cdf0e10cSrcweir xInfo = getPropertySetInfo( xEnv, 1644cdf0e10cSrcweir sal_False /* don't cache data */ ); 1645cdf0e10cSrcweir 1646cdf0e10cSrcweir if ( !xInfo->hasPropertyByName( rName ) ) 1647cdf0e10cSrcweir { 1648cdf0e10cSrcweir // Check, whether property exists. Skip otherwise. 1649cdf0e10cSrcweir // PROPPATCH::set would add the property automatically, which 1650cdf0e10cSrcweir // is not allowed for "setPropertyValues" command! 1651cdf0e10cSrcweir aRet[ n ] <<= beans::UnknownPropertyException( 1652cdf0e10cSrcweir rtl::OUString::createFromAscii( 1653cdf0e10cSrcweir "Property is unknown!" ), 1654cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1655cdf0e10cSrcweir continue; 1656cdf0e10cSrcweir } 1657cdf0e10cSrcweir 1658cdf0e10cSrcweir if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) 1659cdf0e10cSrcweir { 1660cdf0e10cSrcweir // Read-only property! 1661cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1662cdf0e10cSrcweir rtl::OUString::createFromAscii( 1663cdf0e10cSrcweir "Property is read-only!" ), 1664cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1665cdf0e10cSrcweir } 1666cdf0e10cSrcweir else if ( rName.equalsAsciiL( 1667cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "DateCreated" ) ) ) 1668cdf0e10cSrcweir { 1669cdf0e10cSrcweir // Read-only property! 1670cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1671cdf0e10cSrcweir rtl::OUString::createFromAscii( 1672cdf0e10cSrcweir "Property is read-only!" ), 1673cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1674cdf0e10cSrcweir } 1675cdf0e10cSrcweir else if ( rName.equalsAsciiL( 1676cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "DateModified" ) ) ) 1677cdf0e10cSrcweir { 1678cdf0e10cSrcweir // Read-only property! 1679cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1680cdf0e10cSrcweir rtl::OUString::createFromAscii( 1681cdf0e10cSrcweir "Property is read-only!" ), 1682cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1683cdf0e10cSrcweir } 1684cdf0e10cSrcweir else if ( rName.equalsAsciiL( 1685cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) 1686cdf0e10cSrcweir { 1687cdf0e10cSrcweir // Read-only property! 1688cdf0e10cSrcweir // (but could be writable, if 'getcontenttype' would be) 1689cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1690cdf0e10cSrcweir rtl::OUString::createFromAscii( 1691cdf0e10cSrcweir "Property is read-only!" ), 1692cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1693cdf0e10cSrcweir } 1694cdf0e10cSrcweir if ( rName.equalsAsciiL( 1695cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) ) 1696cdf0e10cSrcweir { 1697cdf0e10cSrcweir // Read-only property! 1698cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1699cdf0e10cSrcweir rtl::OUString::createFromAscii( 1700cdf0e10cSrcweir "Property is read-only!" ), 1701cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1702cdf0e10cSrcweir } 1703cdf0e10cSrcweir else 1704cdf0e10cSrcweir { 1705cdf0e10cSrcweir if ( getResourceType( xEnv, xResAccess ) == DAV ) 1706cdf0e10cSrcweir { 1707cdf0e10cSrcweir // Property value will be set on server. 1708cdf0e10cSrcweir ProppatchValue aValue( PROPSET, rName, rValue.Value ); 1709cdf0e10cSrcweir aProppatchValues.push_back( aValue ); 1710cdf0e10cSrcweir 1711cdf0e10cSrcweir // remember position within sequence of values (for 1712cdf0e10cSrcweir // error handling). 1713cdf0e10cSrcweir aProppatchPropsPositions.push_back( n ); 1714cdf0e10cSrcweir } 1715cdf0e10cSrcweir else 1716cdf0e10cSrcweir { 1717cdf0e10cSrcweir // Property value will be stored in local property store. 1718cdf0e10cSrcweir if ( !bTriedToGetAdditonalPropSet && 1719cdf0e10cSrcweir !xAdditionalPropSet.is() ) 1720cdf0e10cSrcweir { 1721cdf0e10cSrcweir xAdditionalPropSet 1722cdf0e10cSrcweir = getAdditionalPropertySet( sal_False ); 1723cdf0e10cSrcweir bTriedToGetAdditonalPropSet = sal_True; 1724cdf0e10cSrcweir } 1725cdf0e10cSrcweir 1726cdf0e10cSrcweir if ( xAdditionalPropSet.is() ) 1727cdf0e10cSrcweir { 1728cdf0e10cSrcweir try 1729cdf0e10cSrcweir { 1730cdf0e10cSrcweir uno::Any aOldValue 1731cdf0e10cSrcweir = xAdditionalPropSet->getPropertyValue( rName ); 1732cdf0e10cSrcweir if ( aOldValue != rValue.Value ) 1733cdf0e10cSrcweir { 1734cdf0e10cSrcweir xAdditionalPropSet->setPropertyValue( 1735cdf0e10cSrcweir rName, rValue.Value ); 1736cdf0e10cSrcweir 1737cdf0e10cSrcweir aEvent.PropertyName = rName; 1738cdf0e10cSrcweir aEvent.OldValue = aOldValue; 1739cdf0e10cSrcweir aEvent.NewValue = rValue.Value; 1740cdf0e10cSrcweir 1741cdf0e10cSrcweir aChanges.getArray()[ nChanged ] = aEvent; 1742cdf0e10cSrcweir nChanged++; 1743cdf0e10cSrcweir } 1744cdf0e10cSrcweir } 1745cdf0e10cSrcweir catch ( beans::UnknownPropertyException const & e ) 1746cdf0e10cSrcweir { 1747cdf0e10cSrcweir aRet[ n ] <<= e; 1748cdf0e10cSrcweir } 1749cdf0e10cSrcweir catch ( lang::WrappedTargetException const & e ) 1750cdf0e10cSrcweir { 1751cdf0e10cSrcweir aRet[ n ] <<= e; 1752cdf0e10cSrcweir } 1753cdf0e10cSrcweir catch ( beans::PropertyVetoException const & e ) 1754cdf0e10cSrcweir { 1755cdf0e10cSrcweir aRet[ n ] <<= e; 1756cdf0e10cSrcweir } 1757cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & e ) 1758cdf0e10cSrcweir { 1759cdf0e10cSrcweir aRet[ n ] <<= e; 1760cdf0e10cSrcweir } 1761cdf0e10cSrcweir } 1762cdf0e10cSrcweir else 1763cdf0e10cSrcweir { 1764cdf0e10cSrcweir aRet[ n ] <<= uno::Exception( 1765cdf0e10cSrcweir rtl::OUString::createFromAscii( 1766cdf0e10cSrcweir "No property set for storing the value!" ), 1767cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1768cdf0e10cSrcweir } 1769cdf0e10cSrcweir } 1770cdf0e10cSrcweir } 1771cdf0e10cSrcweir } 1772cdf0e10cSrcweir } // for 1773cdf0e10cSrcweir 1774cdf0e10cSrcweir if ( !bTransient && aProppatchValues.size() ) 1775cdf0e10cSrcweir { 1776cdf0e10cSrcweir try 1777cdf0e10cSrcweir { 1778cdf0e10cSrcweir // Set property values at server. 1779cdf0e10cSrcweir xResAccess->PROPPATCH( aProppatchValues, xEnv ); 1780cdf0e10cSrcweir 1781cdf0e10cSrcweir std::vector< ProppatchValue >::const_iterator it 1782cdf0e10cSrcweir = aProppatchValues.begin(); 1783cdf0e10cSrcweir std::vector< ProppatchValue >::const_iterator end 1784cdf0e10cSrcweir = aProppatchValues.end(); 1785cdf0e10cSrcweir 1786cdf0e10cSrcweir while ( it != end ) 1787cdf0e10cSrcweir { 1788cdf0e10cSrcweir aEvent.PropertyName = (*it).name; 1789cdf0e10cSrcweir aEvent.OldValue = uno::Any(); // @@@ to expensive to obtain! 1790cdf0e10cSrcweir aEvent.NewValue = (*it).value; 1791cdf0e10cSrcweir 1792cdf0e10cSrcweir aChanges.getArray()[ nChanged ] = aEvent; 1793cdf0e10cSrcweir nChanged++; 1794cdf0e10cSrcweir 1795cdf0e10cSrcweir ++it; 1796cdf0e10cSrcweir } 1797cdf0e10cSrcweir } 1798cdf0e10cSrcweir catch ( DAVException const & e ) 1799cdf0e10cSrcweir { 1800cdf0e10cSrcweir // OSL_ENSURE( sal_False, 1801cdf0e10cSrcweir // "Content::setPropertyValues - PROPPATCH failed!" ); 1802cdf0e10cSrcweir 1803cdf0e10cSrcweir #if 1 1804cdf0e10cSrcweir cancelCommandExecution( e, xEnv ); 1805cdf0e10cSrcweir // unreachable 1806cdf0e10cSrcweir #else 1807cdf0e10cSrcweir // Note: PROPPATCH either sets ALL property values OR NOTHING. 1808cdf0e10cSrcweir 1809cdf0e10cSrcweir std::vector< sal_Int32 >::const_iterator it 1810cdf0e10cSrcweir = aProppatchPropsPositions.begin(); 1811cdf0e10cSrcweir std::vector< sal_Int32 >::const_iterator end 1812cdf0e10cSrcweir = aProppatchPropsPositions.end(); 1813cdf0e10cSrcweir 1814cdf0e10cSrcweir while ( it != end ) 1815cdf0e10cSrcweir { 1816cdf0e10cSrcweir // Set error. 1817cdf0e10cSrcweir aRet[ (*it) ] <<= MapDAVException( e, sal_True ); 1818cdf0e10cSrcweir ++it; 1819cdf0e10cSrcweir } 1820cdf0e10cSrcweir #endif 1821cdf0e10cSrcweir } 1822cdf0e10cSrcweir } 1823cdf0e10cSrcweir 1824cdf0e10cSrcweir if ( bExchange ) 1825cdf0e10cSrcweir { 1826cdf0e10cSrcweir // Assemble new content identifier... 1827cdf0e10cSrcweir 1828cdf0e10cSrcweir rtl::OUString aNewURL = getParentURL(); 1829cdf0e10cSrcweir if ( aNewURL.lastIndexOf( '/' ) != ( aNewURL.getLength() - 1 ) ) 1830cdf0e10cSrcweir aNewURL += rtl::OUString::createFromAscii( "/" ); 1831cdf0e10cSrcweir 1832cdf0e10cSrcweir aNewURL += NeonUri::escapeSegment( aNewTitle ); 1833cdf0e10cSrcweir 1834cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xNewId 1835cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( xSMgr, aNewURL ); 1836cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xOldId = xIdentifier; 1837cdf0e10cSrcweir 1838cdf0e10cSrcweir try 1839cdf0e10cSrcweir { 1840cdf0e10cSrcweir NeonUri sourceURI( xOldId->getContentIdentifier() ); 1841cdf0e10cSrcweir NeonUri targetURI( xNewId->getContentIdentifier() ); 1842cdf0e10cSrcweir targetURI.SetScheme( sourceURI.GetScheme() ); 1843cdf0e10cSrcweir 1844cdf0e10cSrcweir xResAccess->MOVE( 1845cdf0e10cSrcweir sourceURI.GetPath(), targetURI.GetURI(), sal_False, xEnv ); 1846cdf0e10cSrcweir // @@@ Should check for resources that could not be moved 1847cdf0e10cSrcweir // (due to source access or target overwrite) and send 1848cdf0e10cSrcweir // this information through the interaction handler. 1849cdf0e10cSrcweir 1850cdf0e10cSrcweir // @@@ Existing content should be checked to see if it needs 1851cdf0e10cSrcweir // to be deleted at the source 1852cdf0e10cSrcweir 1853cdf0e10cSrcweir // @@@ Existing content should be checked to see if it has 1854cdf0e10cSrcweir // been overwritten at the target 1855cdf0e10cSrcweir 1856cdf0e10cSrcweir if ( exchangeIdentity( xNewId ) ) 1857cdf0e10cSrcweir { 1858cdf0e10cSrcweir xResAccess->setURL( aNewURL ); 1859cdf0e10cSrcweir 1860cdf0e10cSrcweir // DAV resources store all additional props on server! 1861cdf0e10cSrcweir // // Adapt Additional Core Properties. 1862cdf0e10cSrcweir // renameAdditionalPropertySet( xOldId->getContentIdentifier(), 1863cdf0e10cSrcweir // xNewId->getContentIdentifier(), 1864cdf0e10cSrcweir // sal_True ); 1865cdf0e10cSrcweir } 1866cdf0e10cSrcweir else 1867cdf0e10cSrcweir { 1868cdf0e10cSrcweir // Do not set new title! 1869cdf0e10cSrcweir aNewTitle = rtl::OUString(); 1870cdf0e10cSrcweir 1871cdf0e10cSrcweir // Set error . 1872cdf0e10cSrcweir aRet[ nTitlePos ] <<= uno::Exception( 1873cdf0e10cSrcweir rtl::OUString::createFromAscii( "Exchange failed!" ), 1874cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1875cdf0e10cSrcweir } 1876cdf0e10cSrcweir } 1877cdf0e10cSrcweir catch ( DAVException const & e ) 1878cdf0e10cSrcweir { 1879cdf0e10cSrcweir // Do not set new title! 1880cdf0e10cSrcweir aNewTitle = rtl::OUString(); 1881cdf0e10cSrcweir 1882cdf0e10cSrcweir // Set error . 1883cdf0e10cSrcweir aRet[ nTitlePos ] <<= MapDAVException( e, sal_True ); 1884cdf0e10cSrcweir } 1885cdf0e10cSrcweir } 1886cdf0e10cSrcweir 1887cdf0e10cSrcweir if ( aNewTitle.getLength() ) 1888cdf0e10cSrcweir { 1889cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1890cdf0e10cSrcweir 1891cdf0e10cSrcweir aEvent.PropertyName = rtl::OUString::createFromAscii( "Title" ); 1892cdf0e10cSrcweir aEvent.OldValue = uno::makeAny( aOldTitle ); 1893cdf0e10cSrcweir aEvent.NewValue = uno::makeAny( aNewTitle ); 1894cdf0e10cSrcweir 1895cdf0e10cSrcweir m_aEscapedTitle = NeonUri::escapeSegment( aNewTitle ); 1896cdf0e10cSrcweir 1897cdf0e10cSrcweir aChanges.getArray()[ nChanged ] = aEvent; 1898cdf0e10cSrcweir nChanged++; 1899cdf0e10cSrcweir } 1900cdf0e10cSrcweir 1901cdf0e10cSrcweir if ( nChanged > 0 ) 1902cdf0e10cSrcweir { 1903cdf0e10cSrcweir aChanges.realloc( nChanged ); 1904cdf0e10cSrcweir notifyPropertiesChange( aChanges ); 1905cdf0e10cSrcweir } 1906cdf0e10cSrcweir 1907cdf0e10cSrcweir { 1908cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1909cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) ); 1910cdf0e10cSrcweir } 1911cdf0e10cSrcweir 1912cdf0e10cSrcweir return aRet; 1913cdf0e10cSrcweir } 1914cdf0e10cSrcweir 1915cdf0e10cSrcweir //========================================================================= 1916cdf0e10cSrcweir uno::Any Content::open( 1917cdf0e10cSrcweir const ucb::OpenCommandArgument2 & rArg, 1918cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 1919cdf0e10cSrcweir throw( uno::Exception ) 1920cdf0e10cSrcweir { 1921cdf0e10cSrcweir uno::Any aRet; 1922cdf0e10cSrcweir 1923cdf0e10cSrcweir sal_Bool bOpenFolder = ( ( rArg.Mode == ucb::OpenMode::ALL ) || 1924cdf0e10cSrcweir ( rArg.Mode == ucb::OpenMode::FOLDERS ) || 1925cdf0e10cSrcweir ( rArg.Mode == ucb::OpenMode::DOCUMENTS ) ); 1926cdf0e10cSrcweir if ( bOpenFolder ) 1927cdf0e10cSrcweir { 1928cdf0e10cSrcweir if ( isFolder( xEnv ) ) 1929cdf0e10cSrcweir { 1930cdf0e10cSrcweir // Open collection. 1931cdf0e10cSrcweir 1932cdf0e10cSrcweir uno::Reference< ucb::XDynamicResultSet > xSet 1933cdf0e10cSrcweir = new DynamicResultSet( m_xSMgr, this, rArg, xEnv ); 1934cdf0e10cSrcweir aRet <<= xSet; 1935cdf0e10cSrcweir } 1936cdf0e10cSrcweir else 1937cdf0e10cSrcweir { 1938cdf0e10cSrcweir // Error: Not a folder! 1939cdf0e10cSrcweir 1940cdf0e10cSrcweir rtl::OUStringBuffer aMsg; 1941cdf0e10cSrcweir if ( getResourceType( xEnv ) == FTP ) 1942cdf0e10cSrcweir { 1943cdf0e10cSrcweir // #114653# 1944cdf0e10cSrcweir aMsg.appendAscii( "FTP over HTTP proxy: resource cannot " 1945cdf0e10cSrcweir "be opened as folder! Wrong Open Mode!" ); 1946cdf0e10cSrcweir } 1947cdf0e10cSrcweir else 1948cdf0e10cSrcweir { 1949cdf0e10cSrcweir aMsg.appendAscii( "Non-folder resource cannot be " 1950cdf0e10cSrcweir "opened as folder! Wrong Open Mode!" ); 1951cdf0e10cSrcweir } 1952cdf0e10cSrcweir 1953cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1954cdf0e10cSrcweir uno::makeAny( 1955cdf0e10cSrcweir lang::IllegalArgumentException( 1956cdf0e10cSrcweir aMsg.makeStringAndClear(), 1957cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 1958cdf0e10cSrcweir -1 ) ), 1959cdf0e10cSrcweir xEnv ); 1960cdf0e10cSrcweir // Unreachable 1961cdf0e10cSrcweir } 1962cdf0e10cSrcweir } 1963cdf0e10cSrcweir 1964cdf0e10cSrcweir if ( rArg.Sink.is() ) 1965cdf0e10cSrcweir { 1966cdf0e10cSrcweir // Open document. 1967cdf0e10cSrcweir 1968cdf0e10cSrcweir if ( ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) || 1969cdf0e10cSrcweir ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE ) ) 1970cdf0e10cSrcweir { 1971cdf0e10cSrcweir // Currently(?) unsupported. 1972cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1973cdf0e10cSrcweir uno::makeAny( 1974cdf0e10cSrcweir ucb::UnsupportedOpenModeException( 1975cdf0e10cSrcweir rtl::OUString(), 1976cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 1977cdf0e10cSrcweir sal_Int16( rArg.Mode ) ) ), 1978cdf0e10cSrcweir xEnv ); 1979cdf0e10cSrcweir // Unreachable 1980cdf0e10cSrcweir } 1981cdf0e10cSrcweir 1982cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier(); 1983cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOut 1984cdf0e10cSrcweir = uno::Reference< io::XOutputStream >( rArg.Sink, uno::UNO_QUERY ); 1985cdf0e10cSrcweir if ( xOut.is() ) 1986cdf0e10cSrcweir { 1987cdf0e10cSrcweir // PUSH: write data 1988cdf0e10cSrcweir try 1989cdf0e10cSrcweir { 1990cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 1991cdf0e10cSrcweir 1992cdf0e10cSrcweir { 1993cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 1994cdf0e10cSrcweir 1995cdf0e10cSrcweir xResAccess.reset( 1996cdf0e10cSrcweir new DAVResourceAccess( *m_xResAccess.get() ) ); 1997cdf0e10cSrcweir } 1998cdf0e10cSrcweir 1999cdf0e10cSrcweir DAVResource aResource; 2000cdf0e10cSrcweir std::vector< rtl::OUString > aHeaders; 2001cdf0e10cSrcweir 2002cdf0e10cSrcweir xResAccess->GET( xOut, aHeaders, aResource, xEnv ); 2003cdf0e10cSrcweir m_bDidGetOrHead = true; 2004cdf0e10cSrcweir 2005cdf0e10cSrcweir { 2006cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 2007cdf0e10cSrcweir 2008cdf0e10cSrcweir // cache headers. 2009cdf0e10cSrcweir if ( !m_xCachedProps.get()) 2010cdf0e10cSrcweir m_xCachedProps.reset( 2011cdf0e10cSrcweir new CachableContentProperties( aResource ) ); 2012cdf0e10cSrcweir else 2013cdf0e10cSrcweir m_xCachedProps->addProperties( aResource ); 2014cdf0e10cSrcweir 2015cdf0e10cSrcweir m_xResAccess.reset( 2016cdf0e10cSrcweir new DAVResourceAccess( *xResAccess.get() ) ); 2017cdf0e10cSrcweir } 2018cdf0e10cSrcweir } 2019cdf0e10cSrcweir catch ( DAVException const & e ) 2020cdf0e10cSrcweir { 2021cdf0e10cSrcweir cancelCommandExecution( e, xEnv ); 2022cdf0e10cSrcweir // Unreachable 2023cdf0e10cSrcweir } 2024cdf0e10cSrcweir } 2025cdf0e10cSrcweir else 2026cdf0e10cSrcweir { 2027cdf0e10cSrcweir uno::Reference< io::XActiveDataSink > xDataSink 2028cdf0e10cSrcweir = uno::Reference< io::XActiveDataSink >( rArg.Sink, 2029cdf0e10cSrcweir uno::UNO_QUERY ); 2030cdf0e10cSrcweir if ( xDataSink.is() ) 2031cdf0e10cSrcweir { 2032cdf0e10cSrcweir // PULL: wait for client read 2033cdf0e10cSrcweir try 2034cdf0e10cSrcweir { 2035cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 2036cdf0e10cSrcweir { 2037cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 2038cdf0e10cSrcweir 2039cdf0e10cSrcweir xResAccess.reset( 2040cdf0e10cSrcweir new DAVResourceAccess( *m_xResAccess.get() ) ); 2041cdf0e10cSrcweir } 2042cdf0e10cSrcweir 2043cdf0e10cSrcweir // fill inputsream sync; return if all data present 2044cdf0e10cSrcweir DAVResource aResource; 2045cdf0e10cSrcweir std::vector< rtl::OUString > aHeaders; 2046cdf0e10cSrcweir 2047cdf0e10cSrcweir uno::Reference< io::XInputStream > xIn 2048cdf0e10cSrcweir = xResAccess->GET( aHeaders, aResource, xEnv ); 2049cdf0e10cSrcweir m_bDidGetOrHead = true; 2050cdf0e10cSrcweir 2051cdf0e10cSrcweir { 2052cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 2053cdf0e10cSrcweir 2054cdf0e10cSrcweir // cache headers. 2055cdf0e10cSrcweir if ( !m_xCachedProps.get()) 2056cdf0e10cSrcweir m_xCachedProps.reset( 2057cdf0e10cSrcweir new CachableContentProperties( aResource ) ); 2058cdf0e10cSrcweir else 2059cdf0e10cSrcweir m_xCachedProps->addProperties( 2060cdf0e10cSrcweir aResource.properties ); 2061cdf0e10cSrcweir 2062cdf0e10cSrcweir m_xResAccess.reset( 2063cdf0e10cSrcweir new DAVResourceAccess( *xResAccess.get() ) ); 2064cdf0e10cSrcweir } 2065cdf0e10cSrcweir 2066cdf0e10cSrcweir xDataSink->setInputStream( xIn ); 2067cdf0e10cSrcweir } 2068cdf0e10cSrcweir catch ( DAVException const & e ) 2069cdf0e10cSrcweir { 2070cdf0e10cSrcweir cancelCommandExecution( e, xEnv ); 2071cdf0e10cSrcweir // Unreachable 2072cdf0e10cSrcweir } 2073cdf0e10cSrcweir } 2074cdf0e10cSrcweir else 2075cdf0e10cSrcweir { 2076cdf0e10cSrcweir // Note: aOpenCommand.Sink may contain an XStream 2077cdf0e10cSrcweir // implementation. Support for this type of 2078cdf0e10cSrcweir // sink is optional... 2079cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2080cdf0e10cSrcweir uno::makeAny( 2081cdf0e10cSrcweir ucb::UnsupportedDataSinkException( 2082cdf0e10cSrcweir rtl::OUString(), 2083cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 2084cdf0e10cSrcweir rArg.Sink ) ), 2085cdf0e10cSrcweir xEnv ); 2086cdf0e10cSrcweir // Unreachable 2087cdf0e10cSrcweir } 2088cdf0e10cSrcweir } 2089cdf0e10cSrcweir } 2090cdf0e10cSrcweir 2091cdf0e10cSrcweir return aRet; 2092cdf0e10cSrcweir } 2093cdf0e10cSrcweir 2094cdf0e10cSrcweir //========================================================================= 2095cdf0e10cSrcweir void Content::post( 2096cdf0e10cSrcweir const ucb::PostCommandArgument2 & rArg, 2097cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 2098cdf0e10cSrcweir throw( uno::Exception ) 2099cdf0e10cSrcweir { 2100cdf0e10cSrcweir uno::Reference< io::XActiveDataSink > xSink( rArg.Sink, uno::UNO_QUERY ); 2101cdf0e10cSrcweir if ( xSink.is() ) 2102cdf0e10cSrcweir { 2103cdf0e10cSrcweir try 2104cdf0e10cSrcweir { 2105cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 2106cdf0e10cSrcweir { 2107cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 2108cdf0e10cSrcweir xResAccess.reset( 2109cdf0e10cSrcweir new DAVResourceAccess( *m_xResAccess.get() ) ); 2110cdf0e10cSrcweir } 2111cdf0e10cSrcweir 2112cdf0e10cSrcweir uno::Reference< io::XInputStream > xResult 2113cdf0e10cSrcweir = xResAccess->POST( rArg.MediaType, 2114cdf0e10cSrcweir rArg.Referer, 2115cdf0e10cSrcweir rArg.Source, 2116cdf0e10cSrcweir xEnv ); 2117cdf0e10cSrcweir 2118cdf0e10cSrcweir { 2119cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 2120cdf0e10cSrcweir m_xResAccess.reset( 2121cdf0e10cSrcweir new DAVResourceAccess( *xResAccess.get() ) ); 2122cdf0e10cSrcweir } 2123cdf0e10cSrcweir 2124cdf0e10cSrcweir xSink->setInputStream( xResult ); 2125cdf0e10cSrcweir } 2126cdf0e10cSrcweir catch ( DAVException const & e ) 2127cdf0e10cSrcweir { 2128cdf0e10cSrcweir cancelCommandExecution( e, xEnv, sal_True ); 2129cdf0e10cSrcweir // Unreachable 2130cdf0e10cSrcweir } 2131cdf0e10cSrcweir } 2132cdf0e10cSrcweir else 2133cdf0e10cSrcweir { 2134cdf0e10cSrcweir uno::Reference< io::XOutputStream > xResult( rArg.Sink, uno::UNO_QUERY ); 2135cdf0e10cSrcweir if ( xResult.is() ) 2136cdf0e10cSrcweir { 2137cdf0e10cSrcweir try 2138cdf0e10cSrcweir { 2139cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 2140cdf0e10cSrcweir { 2141cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 2142cdf0e10cSrcweir xResAccess.reset( 2143cdf0e10cSrcweir new DAVResourceAccess( *m_xResAccess.get() ) ); 2144cdf0e10cSrcweir } 2145cdf0e10cSrcweir 2146cdf0e10cSrcweir xResAccess->POST( rArg.MediaType, 2147cdf0e10cSrcweir rArg.Referer, 2148cdf0e10cSrcweir rArg.Source, 2149cdf0e10cSrcweir xResult, 2150cdf0e10cSrcweir xEnv ); 2151cdf0e10cSrcweir 2152cdf0e10cSrcweir { 2153cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 2154cdf0e10cSrcweir m_xResAccess.reset( 2155cdf0e10cSrcweir new DAVResourceAccess( *xResAccess.get() ) ); 2156cdf0e10cSrcweir } 2157cdf0e10cSrcweir } 2158cdf0e10cSrcweir catch ( DAVException const & e ) 2159cdf0e10cSrcweir { 2160cdf0e10cSrcweir cancelCommandExecution( e, xEnv, sal_True ); 2161cdf0e10cSrcweir // Unreachable 2162cdf0e10cSrcweir } 2163cdf0e10cSrcweir } 2164cdf0e10cSrcweir else 2165cdf0e10cSrcweir { 2166cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2167cdf0e10cSrcweir uno::makeAny( 2168cdf0e10cSrcweir ucb::UnsupportedDataSinkException( 2169cdf0e10cSrcweir rtl::OUString(), 2170cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 2171cdf0e10cSrcweir rArg.Sink ) ), 2172cdf0e10cSrcweir xEnv ); 2173cdf0e10cSrcweir // Unreachable 2174cdf0e10cSrcweir } 2175cdf0e10cSrcweir } 2176cdf0e10cSrcweir } 2177cdf0e10cSrcweir 2178cdf0e10cSrcweir //========================================================================= 2179cdf0e10cSrcweir void Content::queryChildren( ContentRefList& rChildren ) 2180cdf0e10cSrcweir { 2181cdf0e10cSrcweir // Obtain a list with a snapshot of all currently instanciated contents 2182cdf0e10cSrcweir // from provider and extract the contents which are direct children 2183cdf0e10cSrcweir // of this content. 2184cdf0e10cSrcweir 2185cdf0e10cSrcweir ::ucbhelper::ContentRefList aAllContents; 2186cdf0e10cSrcweir m_xProvider->queryExistingContents( aAllContents ); 2187cdf0e10cSrcweir 2188cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier(); 2189cdf0e10cSrcweir sal_Int32 nURLPos = aURL.lastIndexOf( '/' ); 2190cdf0e10cSrcweir 2191cdf0e10cSrcweir if ( nURLPos != ( aURL.getLength() - 1 ) ) 2192cdf0e10cSrcweir { 2193cdf0e10cSrcweir // No trailing slash found. Append. 2194cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" ); 2195cdf0e10cSrcweir } 2196cdf0e10cSrcweir 2197cdf0e10cSrcweir sal_Int32 nLen = aURL.getLength(); 2198cdf0e10cSrcweir 2199cdf0e10cSrcweir ::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin(); 2200cdf0e10cSrcweir ::ucbhelper::ContentRefList::const_iterator end = aAllContents.end(); 2201cdf0e10cSrcweir 2202cdf0e10cSrcweir while ( it != end ) 2203cdf0e10cSrcweir { 2204cdf0e10cSrcweir ::ucbhelper::ContentImplHelperRef xChild = (*it); 2205cdf0e10cSrcweir rtl::OUString aChildURL 2206cdf0e10cSrcweir = xChild->getIdentifier()->getContentIdentifier(); 2207cdf0e10cSrcweir 2208cdf0e10cSrcweir // Is aURL a prefix of aChildURL? 2209cdf0e10cSrcweir if ( ( aChildURL.getLength() > nLen ) && 2210cdf0e10cSrcweir ( aChildURL.compareTo( aURL, nLen ) == 0 ) ) 2211cdf0e10cSrcweir { 2212cdf0e10cSrcweir sal_Int32 nPos = nLen; 2213cdf0e10cSrcweir nPos = aChildURL.indexOf( '/', nPos ); 2214cdf0e10cSrcweir 2215cdf0e10cSrcweir if ( ( nPos == -1 ) || 2216cdf0e10cSrcweir ( nPos == ( aChildURL.getLength() - 1 ) ) ) 2217cdf0e10cSrcweir { 2218cdf0e10cSrcweir // No further slashes / only a final slash. It's a child! 2219cdf0e10cSrcweir rChildren.push_back( 2220cdf0e10cSrcweir ::webdav_ucp::Content::ContentRef( 2221cdf0e10cSrcweir static_cast< ::webdav_ucp::Content * >( 2222cdf0e10cSrcweir xChild.get() ) ) ); 2223cdf0e10cSrcweir } 2224cdf0e10cSrcweir } 2225cdf0e10cSrcweir ++it; 2226cdf0e10cSrcweir } 2227cdf0e10cSrcweir } 2228cdf0e10cSrcweir 2229cdf0e10cSrcweir //========================================================================= 2230cdf0e10cSrcweir void Content::insert( 2231cdf0e10cSrcweir const uno::Reference< io::XInputStream > & xInputStream, 2232cdf0e10cSrcweir sal_Bool bReplaceExisting, 2233cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& Environment ) 2234cdf0e10cSrcweir throw( uno::Exception ) 2235cdf0e10cSrcweir { 2236cdf0e10cSrcweir sal_Bool bTransient, bCollection; 2237cdf0e10cSrcweir rtl::OUString aEscapedTitle; 2238cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 2239cdf0e10cSrcweir 2240cdf0e10cSrcweir { 2241cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2242cdf0e10cSrcweir 2243cdf0e10cSrcweir bTransient = m_bTransient; 2244cdf0e10cSrcweir bCollection = m_bCollection; 2245cdf0e10cSrcweir aEscapedTitle = m_aEscapedTitle; 2246cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) ); 2247cdf0e10cSrcweir } 2248cdf0e10cSrcweir 2249cdf0e10cSrcweir // Check, if all required properties are present. 2250cdf0e10cSrcweir 2251cdf0e10cSrcweir if ( aEscapedTitle.getLength() == 0 ) 2252cdf0e10cSrcweir { 2253cdf0e10cSrcweir OSL_ENSURE( sal_False, "Content::insert - Title missing!" ); 2254cdf0e10cSrcweir 2255cdf0e10cSrcweir uno::Sequence< rtl::OUString > aProps( 1 ); 2256cdf0e10cSrcweir aProps[ 0 ] = rtl::OUString::createFromAscii( "Title" ); 2257cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2258cdf0e10cSrcweir uno::makeAny( ucb::MissingPropertiesException( 2259cdf0e10cSrcweir rtl::OUString(), 2260cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 2261cdf0e10cSrcweir aProps ) ), 2262cdf0e10cSrcweir Environment ); 2263cdf0e10cSrcweir // Unreachable 2264cdf0e10cSrcweir } 2265cdf0e10cSrcweir 2266cdf0e10cSrcweir if ( !bReplaceExisting ) 2267cdf0e10cSrcweir { 2268cdf0e10cSrcweir /* [RFC 2616] - HTTP 2269cdf0e10cSrcweir 2270cdf0e10cSrcweir The PUT method requests that the enclosed entity be stored under the 2271cdf0e10cSrcweir supplied Request-URI. If the Request-URI refers to an already 2272cdf0e10cSrcweir existing resource, the enclosed entity SHOULD be considered as a 2273cdf0e10cSrcweir modified version of the one residing on the origin server. 2274cdf0e10cSrcweir */ 2275cdf0e10cSrcweir 2276cdf0e10cSrcweir /* [RFC 2518] - WebDAV 2277cdf0e10cSrcweir 2278cdf0e10cSrcweir MKCOL creates a new collection resource at the location specified by 2279cdf0e10cSrcweir the Request-URI. If the resource identified by the Request-URI is 2280cdf0e10cSrcweir non-null then the MKCOL MUST fail. 2281cdf0e10cSrcweir */ 2282cdf0e10cSrcweir 2283cdf0e10cSrcweir // ==> Complain on PUT, continue on MKCOL. 2284cdf0e10cSrcweir if ( !bTransient || ( bTransient && !bCollection ) ) 2285cdf0e10cSrcweir { 2286cdf0e10cSrcweir ucb::UnsupportedNameClashException aEx( 2287cdf0e10cSrcweir rtl::OUString::createFromAscii( 2288cdf0e10cSrcweir "Unable to write without overwrite!" ), 2289cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 2290cdf0e10cSrcweir ucb::NameClash::ERROR ); 2291cdf0e10cSrcweir 2292cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xIH; 2293cdf0e10cSrcweir 2294cdf0e10cSrcweir if ( Environment.is() ) 2295cdf0e10cSrcweir xIH = Environment->getInteractionHandler(); 2296cdf0e10cSrcweir 2297cdf0e10cSrcweir if ( xIH.is() ) 2298cdf0e10cSrcweir { 2299cdf0e10cSrcweir uno::Any aExAsAny( uno::makeAny( aEx ) ); 2300cdf0e10cSrcweir 2301cdf0e10cSrcweir rtl::Reference< ucbhelper::SimpleInteractionRequest > xRequest 2302cdf0e10cSrcweir = new ucbhelper::SimpleInteractionRequest( 2303cdf0e10cSrcweir aExAsAny, 2304cdf0e10cSrcweir ucbhelper::CONTINUATION_APPROVE 2305cdf0e10cSrcweir | ucbhelper::CONTINUATION_DISAPPROVE ); 2306cdf0e10cSrcweir xIH->handle( xRequest.get() ); 2307cdf0e10cSrcweir 2308cdf0e10cSrcweir const sal_Int32 nResp = xRequest->getResponse(); 2309cdf0e10cSrcweir 2310cdf0e10cSrcweir switch ( nResp ) 2311cdf0e10cSrcweir { 2312cdf0e10cSrcweir case ucbhelper::CONTINUATION_UNKNOWN: 2313cdf0e10cSrcweir // Not handled; throw. 2314cdf0e10cSrcweir throw aEx; 2315cdf0e10cSrcweir // break; 2316cdf0e10cSrcweir 2317cdf0e10cSrcweir case ucbhelper::CONTINUATION_APPROVE: 2318cdf0e10cSrcweir // Continue -> Overwrite. 2319cdf0e10cSrcweir bReplaceExisting = sal_True; 2320cdf0e10cSrcweir break; 2321cdf0e10cSrcweir 2322cdf0e10cSrcweir case ucbhelper::CONTINUATION_DISAPPROVE: 2323cdf0e10cSrcweir // Abort. 2324cdf0e10cSrcweir throw ucb::CommandFailedException( 2325cdf0e10cSrcweir rtl::OUString(), 2326cdf0e10cSrcweir uno::Reference< uno::XInterface >(), 2327cdf0e10cSrcweir aExAsAny ); 2328cdf0e10cSrcweir // break; 2329cdf0e10cSrcweir 2330cdf0e10cSrcweir default: 2331cdf0e10cSrcweir OSL_ENSURE( sal_False, 2332cdf0e10cSrcweir "Content::insert - " 2333cdf0e10cSrcweir "Unknown interaction selection!" ); 2334cdf0e10cSrcweir throw ucb::CommandFailedException( 2335cdf0e10cSrcweir rtl::OUString::createFromAscii( 2336cdf0e10cSrcweir "Unknown interaction selection!" ), 2337cdf0e10cSrcweir uno::Reference< uno::XInterface >(), 2338cdf0e10cSrcweir aExAsAny ); 2339cdf0e10cSrcweir // break; 2340cdf0e10cSrcweir } 2341cdf0e10cSrcweir } 2342cdf0e10cSrcweir else 2343cdf0e10cSrcweir { 2344cdf0e10cSrcweir // No IH; throw. 2345cdf0e10cSrcweir throw aEx; 2346cdf0e10cSrcweir } 2347cdf0e10cSrcweir } 2348cdf0e10cSrcweir } 2349cdf0e10cSrcweir 2350cdf0e10cSrcweir if ( bTransient ) 2351cdf0e10cSrcweir { 2352cdf0e10cSrcweir // Assemble new content identifier... 2353cdf0e10cSrcweir rtl::OUString aURL = getParentURL(); 2354cdf0e10cSrcweir if ( aURL.lastIndexOf( '/' ) != ( aURL.getLength() - 1 ) ) 2355cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" ); 2356cdf0e10cSrcweir 2357cdf0e10cSrcweir aURL += aEscapedTitle; 2358cdf0e10cSrcweir 2359cdf0e10cSrcweir try 2360cdf0e10cSrcweir { 2361cdf0e10cSrcweir xResAccess->setURL( aURL ); 2362cdf0e10cSrcweir 2363cdf0e10cSrcweir if ( bCollection ) 2364cdf0e10cSrcweir xResAccess->MKCOL( Environment ); 2365cdf0e10cSrcweir else 2366cdf0e10cSrcweir xResAccess->PUT( xInputStream, Environment ); 2367cdf0e10cSrcweir } 2368cdf0e10cSrcweir catch ( DAVException const & except ) 2369cdf0e10cSrcweir { 2370cdf0e10cSrcweir if ( bCollection ) 2371cdf0e10cSrcweir { 2372cdf0e10cSrcweir if ( except.getStatus() == SC_METHOD_NOT_ALLOWED ) 2373cdf0e10cSrcweir { 2374cdf0e10cSrcweir // [RFC 2518] - WebDAV 2375cdf0e10cSrcweir // 405 (Method Not Allowed) - MKCOL can only be 2376cdf0e10cSrcweir // executed on a deleted/non-existent resource. 2377cdf0e10cSrcweir 2378cdf0e10cSrcweir if ( bReplaceExisting ) 2379cdf0e10cSrcweir { 2380cdf0e10cSrcweir // Destroy old resource. 2381cdf0e10cSrcweir try 2382cdf0e10cSrcweir { 2383cdf0e10cSrcweir xResAccess->DESTROY( Environment ); 2384cdf0e10cSrcweir } 2385cdf0e10cSrcweir catch ( DAVException const & e ) 2386cdf0e10cSrcweir { 2387cdf0e10cSrcweir cancelCommandExecution( e, Environment, sal_True ); 2388cdf0e10cSrcweir // Unreachable 2389cdf0e10cSrcweir } 2390cdf0e10cSrcweir 2391cdf0e10cSrcweir // Insert (recursion!). 2392cdf0e10cSrcweir insert( xInputStream, bReplaceExisting, Environment ); 2393cdf0e10cSrcweir 2394cdf0e10cSrcweir { 2395cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2396cdf0e10cSrcweir m_xResAccess.reset( 2397cdf0e10cSrcweir new DAVResourceAccess( *xResAccess.get() ) ); 2398cdf0e10cSrcweir } 2399cdf0e10cSrcweir 2400cdf0e10cSrcweir // Success! 2401cdf0e10cSrcweir return; 2402cdf0e10cSrcweir } 2403cdf0e10cSrcweir else 2404cdf0e10cSrcweir { 2405cdf0e10cSrcweir rtl::OUString aTitle; 2406cdf0e10cSrcweir try 2407cdf0e10cSrcweir { 2408cdf0e10cSrcweir NeonUri aURI( aURL ); 2409cdf0e10cSrcweir aTitle = aURI.GetPathBaseNameUnescaped(); 2410cdf0e10cSrcweir } 2411cdf0e10cSrcweir catch ( DAVException const & ) 2412cdf0e10cSrcweir { 2413cdf0e10cSrcweir } 2414cdf0e10cSrcweir 2415cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2416cdf0e10cSrcweir uno::makeAny( 2417cdf0e10cSrcweir ucb::NameClashException( 2418cdf0e10cSrcweir rtl::OUString(), 2419cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 2420cdf0e10cSrcweir task::InteractionClassification_ERROR, 2421cdf0e10cSrcweir aTitle ) ), 2422cdf0e10cSrcweir Environment ); 2423cdf0e10cSrcweir // Unreachable 2424cdf0e10cSrcweir } 2425cdf0e10cSrcweir } 2426cdf0e10cSrcweir } 2427cdf0e10cSrcweir 2428cdf0e10cSrcweir cancelCommandExecution( except, Environment, sal_True ); 2429cdf0e10cSrcweir // Unreachable 2430cdf0e10cSrcweir } 2431cdf0e10cSrcweir 2432cdf0e10cSrcweir { 2433cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2434cdf0e10cSrcweir m_xIdentifier 2435cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL ); 2436cdf0e10cSrcweir } 2437cdf0e10cSrcweir 2438cdf0e10cSrcweir inserted(); 2439cdf0e10cSrcweir 2440cdf0e10cSrcweir { 2441cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2442cdf0e10cSrcweir m_bTransient = sal_False; 2443cdf0e10cSrcweir } 2444cdf0e10cSrcweir } 2445cdf0e10cSrcweir else 2446cdf0e10cSrcweir { 2447cdf0e10cSrcweir if ( !xInputStream.is() ) 2448cdf0e10cSrcweir { 2449cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2450cdf0e10cSrcweir uno::makeAny( 2451cdf0e10cSrcweir ucb::MissingInputStreamException( 2452cdf0e10cSrcweir rtl::OUString(), 2453cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ), 2454cdf0e10cSrcweir Environment ); 2455cdf0e10cSrcweir // Unreachable 2456cdf0e10cSrcweir } 2457cdf0e10cSrcweir 2458cdf0e10cSrcweir try 2459cdf0e10cSrcweir { 2460cdf0e10cSrcweir xResAccess->PUT( xInputStream, Environment ); 2461cdf0e10cSrcweir } 2462cdf0e10cSrcweir catch ( DAVException const & e ) 2463cdf0e10cSrcweir { 2464cdf0e10cSrcweir cancelCommandExecution( e, Environment, sal_True ); 2465cdf0e10cSrcweir // Unreachable 2466cdf0e10cSrcweir } 2467cdf0e10cSrcweir } 2468cdf0e10cSrcweir 2469cdf0e10cSrcweir { 2470cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2471cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) ); 2472cdf0e10cSrcweir } 2473cdf0e10cSrcweir } 2474cdf0e10cSrcweir 2475cdf0e10cSrcweir //========================================================================= 2476cdf0e10cSrcweir void Content::transfer( 2477cdf0e10cSrcweir const ucb::TransferInfo & rArgs, 2478cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& Environment ) 2479cdf0e10cSrcweir throw( uno::Exception ) 2480cdf0e10cSrcweir { 2481cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xSMgr; 2482cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xIdentifier; 2483cdf0e10cSrcweir uno::Reference< ucb::XContentProvider > xProvider; 2484cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 2485cdf0e10cSrcweir 2486cdf0e10cSrcweir { 2487cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2488cdf0e10cSrcweir 2489cdf0e10cSrcweir xSMgr.set( m_xSMgr ); 2490cdf0e10cSrcweir xIdentifier.set( m_xIdentifier ); 2491cdf0e10cSrcweir xProvider.set( m_xProvider.get() ); 2492cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) ); 2493cdf0e10cSrcweir } 2494cdf0e10cSrcweir 2495cdf0e10cSrcweir rtl::OUString aTargetURI; 2496cdf0e10cSrcweir try 2497cdf0e10cSrcweir { 2498cdf0e10cSrcweir NeonUri sourceURI( rArgs.SourceURL ); 2499cdf0e10cSrcweir NeonUri targetURI( xIdentifier->getContentIdentifier() ); 2500cdf0e10cSrcweir aTargetURI = targetURI.GetPathBaseNameUnescaped(); 2501cdf0e10cSrcweir 2502cdf0e10cSrcweir // Check source's and target's URL scheme 2503cdf0e10cSrcweir // 2504cdf0e10cSrcweir const rtl::OUString aScheme = sourceURI.GetScheme().toAsciiLowerCase(); 2505cdf0e10cSrcweir if ( aScheme.equalsAsciiL( 2506cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_URL_SCHEME ) ) ) 2507cdf0e10cSrcweir { 2508cdf0e10cSrcweir sourceURI.SetScheme( 2509cdf0e10cSrcweir rtl::OUString::createFromAscii( HTTP_URL_SCHEME ) ); 2510cdf0e10cSrcweir } 2511cdf0e10cSrcweir else if ( aScheme.equalsAsciiL( 2512cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAV_URL_SCHEME ) ) ) 2513cdf0e10cSrcweir { 2514cdf0e10cSrcweir sourceURI.SetScheme( 2515cdf0e10cSrcweir rtl::OUString::createFromAscii( HTTP_URL_SCHEME ) ); 2516cdf0e10cSrcweir } 2517cdf0e10cSrcweir else if ( aScheme.equalsAsciiL( 2518cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAVS_URL_SCHEME ) ) ) 2519cdf0e10cSrcweir { 2520cdf0e10cSrcweir sourceURI.SetScheme( 2521cdf0e10cSrcweir rtl::OUString::createFromAscii( HTTPS_URL_SCHEME ) ); 2522cdf0e10cSrcweir } 2523cdf0e10cSrcweir else 2524cdf0e10cSrcweir { 2525cdf0e10cSrcweir if ( !aScheme.equalsAsciiL( 2526cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( HTTP_URL_SCHEME ) ) && 2527cdf0e10cSrcweir !aScheme.equalsAsciiL( 2528cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( HTTPS_URL_SCHEME ) ) ) 2529cdf0e10cSrcweir { 2530cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2531cdf0e10cSrcweir uno::makeAny( 2532cdf0e10cSrcweir ucb::InteractiveBadTransferURLException( 2533cdf0e10cSrcweir rtl::OUString::createFromAscii( 2534cdf0e10cSrcweir "Unsupported URL scheme!" ), 2535cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ), 2536cdf0e10cSrcweir Environment ); 2537cdf0e10cSrcweir // Unreachable 2538cdf0e10cSrcweir } 2539cdf0e10cSrcweir } 2540cdf0e10cSrcweir 2541cdf0e10cSrcweir if ( targetURI.GetScheme().toAsciiLowerCase().equalsAsciiL( 2542cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_URL_SCHEME ) ) ) 2543cdf0e10cSrcweir targetURI.SetScheme( 2544cdf0e10cSrcweir rtl::OUString::createFromAscii( HTTP_URL_SCHEME ) ); 2545cdf0e10cSrcweir else if ( targetURI.GetScheme().toAsciiLowerCase().equalsAsciiL( 2546cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAV_URL_SCHEME ) ) ) 2547cdf0e10cSrcweir targetURI.SetScheme( 2548cdf0e10cSrcweir rtl::OUString::createFromAscii( HTTP_URL_SCHEME ) ); 2549cdf0e10cSrcweir 2550cdf0e10cSrcweir // @@@ This implementation of 'transfer' only works 2551cdf0e10cSrcweir // if the source and target are located at same host. 2552cdf0e10cSrcweir // (Neon does not support cross-server copy/move) 2553cdf0e10cSrcweir 2554cdf0e10cSrcweir // Check for same host 2555cdf0e10cSrcweir // 2556cdf0e10cSrcweir if ( sourceURI.GetHost().getLength() && 2557cdf0e10cSrcweir ( sourceURI.GetHost() != targetURI.GetHost() ) ) 2558cdf0e10cSrcweir { 2559cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2560cdf0e10cSrcweir uno::makeAny( ucb::InteractiveBadTransferURLException( 2561cdf0e10cSrcweir rtl::OUString::createFromAscii( 2562cdf0e10cSrcweir "Different hosts!" ), 2563cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ), 2564cdf0e10cSrcweir Environment ); 2565cdf0e10cSrcweir // Unreachable 2566cdf0e10cSrcweir } 2567cdf0e10cSrcweir 2568cdf0e10cSrcweir rtl::OUString aTitle = rArgs.NewTitle; 2569cdf0e10cSrcweir 2570cdf0e10cSrcweir if ( !aTitle.getLength() ) 2571cdf0e10cSrcweir aTitle = sourceURI.GetPathBaseNameUnescaped(); 2572cdf0e10cSrcweir 2573cdf0e10cSrcweir if ( aTitle.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "/" ) ) ) 2574cdf0e10cSrcweir { 2575cdf0e10cSrcweir // kso: ??? 2576cdf0e10cSrcweir aTitle = rtl::OUString(); 2577cdf0e10cSrcweir } 2578cdf0e10cSrcweir 2579cdf0e10cSrcweir targetURI.AppendPath( aTitle ); 2580cdf0e10cSrcweir 2581cdf0e10cSrcweir rtl::OUString aTargetURL = xIdentifier->getContentIdentifier(); 2582cdf0e10cSrcweir if ( ( aTargetURL.lastIndexOf( '/' ) + 1 ) 2583cdf0e10cSrcweir != aTargetURL.getLength() ) 2584cdf0e10cSrcweir aTargetURL += rtl::OUString::createFromAscii( "/" ); 2585cdf0e10cSrcweir 2586cdf0e10cSrcweir aTargetURL += aTitle; 2587cdf0e10cSrcweir 2588cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xTargetId 2589cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( xSMgr, aTargetURL ); 2590cdf0e10cSrcweir 2591cdf0e10cSrcweir DAVResourceAccess aSourceAccess( xSMgr, 2592cdf0e10cSrcweir xResAccess->getSessionFactory(), 2593cdf0e10cSrcweir sourceURI.GetURI() ); 2594cdf0e10cSrcweir 2595cdf0e10cSrcweir if ( rArgs.MoveData == sal_True ) 2596cdf0e10cSrcweir { 2597cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xId 2598cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( xSMgr, rArgs.SourceURL ); 2599cdf0e10cSrcweir 2600cdf0e10cSrcweir // Note: The static cast is okay here, because its sure that 2601cdf0e10cSrcweir // xProvider is always the WebDAVContentProvider. 2602cdf0e10cSrcweir rtl::Reference< Content > xSource 2603cdf0e10cSrcweir = static_cast< Content * >( 2604cdf0e10cSrcweir xProvider->queryContent( xId ).get() ); 2605cdf0e10cSrcweir 2606cdf0e10cSrcweir // [RFC 2518] - WebDAV 2607cdf0e10cSrcweir // If a resource exists at the destination and the Overwrite 2608cdf0e10cSrcweir // header is "T" then prior to performing the move the server 2609cdf0e10cSrcweir // MUST perform a DELETE with "Depth: infinity" on the 2610cdf0e10cSrcweir // destination resource. If the Overwrite header is set to 2611cdf0e10cSrcweir // "F" then the operation will fail. 2612cdf0e10cSrcweir 2613cdf0e10cSrcweir aSourceAccess.MOVE( sourceURI.GetPath(), 2614cdf0e10cSrcweir targetURI.GetURI(), 2615cdf0e10cSrcweir rArgs.NameClash 2616cdf0e10cSrcweir == ucb::NameClash::OVERWRITE, 2617cdf0e10cSrcweir Environment ); 2618cdf0e10cSrcweir 2619cdf0e10cSrcweir if ( xSource.is() ) 2620cdf0e10cSrcweir { 2621cdf0e10cSrcweir // Propagate destruction to listeners. 2622cdf0e10cSrcweir xSource->destroy( sal_True ); 2623cdf0e10cSrcweir } 2624cdf0e10cSrcweir 2625cdf0e10cSrcweir // DAV resources store all additional props on server! 2626cdf0e10cSrcweir // // Rename own and all children's Additional Core Properties. 2627cdf0e10cSrcweir // renameAdditionalPropertySet( xId->getContentIdentifier(), 2628cdf0e10cSrcweir // xTargetId->getContentIdentifier(), 2629cdf0e10cSrcweir // sal_True ); 2630cdf0e10cSrcweir } 2631cdf0e10cSrcweir else 2632cdf0e10cSrcweir { 2633cdf0e10cSrcweir // [RFC 2518] - WebDAV 2634cdf0e10cSrcweir // If a resource exists at the destination and the Overwrite 2635cdf0e10cSrcweir // header is "T" then prior to performing the copy the server 2636cdf0e10cSrcweir // MUST perform a DELETE with "Depth: infinity" on the 2637cdf0e10cSrcweir // destination resource. If the Overwrite header is set to 2638cdf0e10cSrcweir // "F" then the operation will fail. 2639cdf0e10cSrcweir 2640cdf0e10cSrcweir aSourceAccess.COPY( sourceURI.GetPath(), 2641cdf0e10cSrcweir targetURI.GetURI(), 2642cdf0e10cSrcweir rArgs.NameClash 2643cdf0e10cSrcweir == ucb::NameClash::OVERWRITE, 2644cdf0e10cSrcweir Environment ); 2645cdf0e10cSrcweir 2646cdf0e10cSrcweir // DAV resources store all additional props on server! 2647cdf0e10cSrcweir // // Copy own and all children's Additional Core Properties. 2648cdf0e10cSrcweir // copyAdditionalPropertySet( xId->getContentIdentifier(), 2649cdf0e10cSrcweir // xTargetId->getContentIdentifier(), 2650cdf0e10cSrcweir // sal_True ); 2651cdf0e10cSrcweir } 2652cdf0e10cSrcweir 2653cdf0e10cSrcweir // Note: The static cast is okay here, because its sure that 2654cdf0e10cSrcweir // xProvider is always the WebDAVContentProvider. 2655cdf0e10cSrcweir rtl::Reference< Content > xTarget 2656cdf0e10cSrcweir = static_cast< Content * >( 2657cdf0e10cSrcweir xProvider->queryContent( xTargetId ).get() ); 2658cdf0e10cSrcweir 2659cdf0e10cSrcweir // Announce transfered content in its new folder. 2660cdf0e10cSrcweir xTarget->inserted(); 2661cdf0e10cSrcweir } 2662cdf0e10cSrcweir catch ( ucb::IllegalIdentifierException const & ) 2663cdf0e10cSrcweir { 2664cdf0e10cSrcweir // queryContent 2665cdf0e10cSrcweir } 2666cdf0e10cSrcweir catch ( DAVException const & e ) 2667cdf0e10cSrcweir { 2668cdf0e10cSrcweir // [RFC 2518] - WebDAV 2669cdf0e10cSrcweir // 412 (Precondition Failed) - The server was unable to maintain 2670cdf0e10cSrcweir // the liveness of the properties listed in the propertybehavior 2671cdf0e10cSrcweir // XML element or the Overwrite header is "F" and the state of 2672cdf0e10cSrcweir // the destination resource is non-null. 2673cdf0e10cSrcweir 2674cdf0e10cSrcweir if ( e.getStatus() == SC_PRECONDITION_FAILED ) 2675cdf0e10cSrcweir { 2676cdf0e10cSrcweir switch ( rArgs.NameClash ) 2677cdf0e10cSrcweir { 2678cdf0e10cSrcweir case ucb::NameClash::ERROR: 2679cdf0e10cSrcweir { 2680cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2681cdf0e10cSrcweir uno::makeAny( 2682cdf0e10cSrcweir ucb::NameClashException( 2683cdf0e10cSrcweir rtl::OUString(), 2684cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 2685cdf0e10cSrcweir task::InteractionClassification_ERROR, 2686cdf0e10cSrcweir aTargetURI ) ), 2687cdf0e10cSrcweir Environment ); 2688cdf0e10cSrcweir // Unreachable 2689cdf0e10cSrcweir } 2690cdf0e10cSrcweir 2691cdf0e10cSrcweir case ucb::NameClash::OVERWRITE: 2692cdf0e10cSrcweir break; 2693cdf0e10cSrcweir 2694cdf0e10cSrcweir case ucb::NameClash::KEEP: // deprecated 2695cdf0e10cSrcweir case ucb::NameClash::RENAME: 2696cdf0e10cSrcweir case ucb::NameClash::ASK: 2697cdf0e10cSrcweir default: 2698cdf0e10cSrcweir { 2699cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2700cdf0e10cSrcweir uno::makeAny( 2701cdf0e10cSrcweir ucb::UnsupportedNameClashException( 2702cdf0e10cSrcweir rtl::OUString(), 2703cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 2704cdf0e10cSrcweir rArgs.NameClash ) ), 2705cdf0e10cSrcweir Environment ); 2706cdf0e10cSrcweir // Unreachable 2707cdf0e10cSrcweir } 2708cdf0e10cSrcweir } 2709cdf0e10cSrcweir } 2710cdf0e10cSrcweir 2711cdf0e10cSrcweir cancelCommandExecution( e, Environment, sal_True ); 2712cdf0e10cSrcweir // Unreachable 2713cdf0e10cSrcweir } 2714cdf0e10cSrcweir 2715cdf0e10cSrcweir { 2716cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2717cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) ); 2718cdf0e10cSrcweir } 2719cdf0e10cSrcweir } 2720cdf0e10cSrcweir 2721cdf0e10cSrcweir //========================================================================= 2722cdf0e10cSrcweir void Content::destroy( sal_Bool bDeletePhysical ) 2723cdf0e10cSrcweir throw( uno::Exception ) 2724cdf0e10cSrcweir { 2725cdf0e10cSrcweir // @@@ take care about bDeletePhysical -> trashcan support 2726cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier(); 2727cdf0e10cSrcweir 2728cdf0e10cSrcweir uno::Reference< ucb::XContent > xThis = this; 2729cdf0e10cSrcweir 2730cdf0e10cSrcweir deleted(); 2731cdf0e10cSrcweir 2732cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2733cdf0e10cSrcweir 2734cdf0e10cSrcweir // Process instanciated children... 2735cdf0e10cSrcweir 2736cdf0e10cSrcweir ::webdav_ucp::Content::ContentRefList aChildren; 2737cdf0e10cSrcweir queryChildren( aChildren ); 2738cdf0e10cSrcweir 2739cdf0e10cSrcweir ContentRefList::const_iterator it = aChildren.begin(); 2740cdf0e10cSrcweir ContentRefList::const_iterator end = aChildren.end(); 2741cdf0e10cSrcweir 2742cdf0e10cSrcweir while ( it != end ) 2743cdf0e10cSrcweir { 2744cdf0e10cSrcweir (*it)->destroy( bDeletePhysical ); 2745cdf0e10cSrcweir ++it; 2746cdf0e10cSrcweir } 2747cdf0e10cSrcweir } 2748cdf0e10cSrcweir 2749cdf0e10cSrcweir //========================================================================= 2750cdf0e10cSrcweir bool Content::supportsExclusiveWriteLock( 2751cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& Environment ) 2752cdf0e10cSrcweir { 2753cdf0e10cSrcweir if ( getResourceType( Environment ) == DAV ) 2754cdf0e10cSrcweir { 2755cdf0e10cSrcweir if ( m_xCachedProps.get() ) 2756cdf0e10cSrcweir { 2757cdf0e10cSrcweir uno::Sequence< ucb::LockEntry > aSupportedLocks; 2758cdf0e10cSrcweir if ( m_xCachedProps->getValue( DAVProperties::SUPPORTEDLOCK ) 2759cdf0e10cSrcweir >>= aSupportedLocks ) 2760cdf0e10cSrcweir { 2761cdf0e10cSrcweir for ( sal_Int32 n = 0; n < aSupportedLocks.getLength(); ++n ) 2762cdf0e10cSrcweir { 2763cdf0e10cSrcweir if ( aSupportedLocks[ n ].Scope 2764cdf0e10cSrcweir == ucb::LockScope_EXCLUSIVE && 2765cdf0e10cSrcweir aSupportedLocks[ n ].Type 2766cdf0e10cSrcweir == ucb::LockType_WRITE ) 2767cdf0e10cSrcweir return true; 2768cdf0e10cSrcweir } 2769cdf0e10cSrcweir } 2770cdf0e10cSrcweir } 2771cdf0e10cSrcweir } 2772cdf0e10cSrcweir return false; 2773cdf0e10cSrcweir } 2774cdf0e10cSrcweir 2775cdf0e10cSrcweir //========================================================================= 2776cdf0e10cSrcweir void Content::lock( 2777cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& Environment ) 2778cdf0e10cSrcweir throw( uno::Exception ) 2779cdf0e10cSrcweir { 2780cdf0e10cSrcweir try 2781cdf0e10cSrcweir { 2782cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 2783cdf0e10cSrcweir { 2784cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2785cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) ); 2786cdf0e10cSrcweir } 2787cdf0e10cSrcweir 2788cdf0e10cSrcweir uno::Any aOwnerAny; 2789cdf0e10cSrcweir aOwnerAny 2790cdf0e10cSrcweir <<= rtl::OUString::createFromAscii( "http://ucb.openoffice.org" ); 2791cdf0e10cSrcweir 2792cdf0e10cSrcweir ucb::Lock aLock( 2793cdf0e10cSrcweir ucb::LockScope_EXCLUSIVE, 2794cdf0e10cSrcweir ucb::LockType_WRITE, 2795cdf0e10cSrcweir ucb::LockDepth_ZERO, 2796cdf0e10cSrcweir aOwnerAny, 2797cdf0e10cSrcweir 180, // lock timeout in secs 2798cdf0e10cSrcweir //-1, // infinite lock 2799cdf0e10cSrcweir uno::Sequence< ::rtl::OUString >() ); 2800cdf0e10cSrcweir 2801cdf0e10cSrcweir xResAccess->LOCK( aLock, Environment ); 2802cdf0e10cSrcweir 2803cdf0e10cSrcweir { 2804cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2805cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) ); 2806cdf0e10cSrcweir } 2807cdf0e10cSrcweir } 2808cdf0e10cSrcweir catch ( DAVException const & e ) 2809cdf0e10cSrcweir { 2810cdf0e10cSrcweir cancelCommandExecution( e, Environment, sal_False ); 2811cdf0e10cSrcweir // Unreachable 2812cdf0e10cSrcweir } 2813cdf0e10cSrcweir } 2814cdf0e10cSrcweir 2815cdf0e10cSrcweir //========================================================================= 2816cdf0e10cSrcweir void Content::unlock( 2817cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& Environment ) 2818cdf0e10cSrcweir throw( uno::Exception ) 2819cdf0e10cSrcweir { 2820cdf0e10cSrcweir try 2821cdf0e10cSrcweir { 2822cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 2823cdf0e10cSrcweir { 2824cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2825cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) ); 2826cdf0e10cSrcweir } 2827cdf0e10cSrcweir 2828cdf0e10cSrcweir xResAccess->UNLOCK( Environment ); 2829cdf0e10cSrcweir 2830cdf0e10cSrcweir { 2831cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2832cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) ); 2833cdf0e10cSrcweir } 2834cdf0e10cSrcweir } 2835cdf0e10cSrcweir catch ( DAVException const & e ) 2836cdf0e10cSrcweir { 2837cdf0e10cSrcweir cancelCommandExecution( e, Environment, sal_False ); 2838cdf0e10cSrcweir // Unreachable 2839cdf0e10cSrcweir } 2840cdf0e10cSrcweir } 2841cdf0e10cSrcweir 2842cdf0e10cSrcweir //========================================================================= 2843cdf0e10cSrcweir sal_Bool Content::exchangeIdentity( 2844cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& xNewId ) 2845cdf0e10cSrcweir { 2846cdf0e10cSrcweir if ( !xNewId.is() ) 2847cdf0e10cSrcweir return sal_False; 2848cdf0e10cSrcweir 2849cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); 2850cdf0e10cSrcweir 2851cdf0e10cSrcweir uno::Reference< ucb::XContent > xThis = this; 2852cdf0e10cSrcweir 2853cdf0e10cSrcweir // Already persistent? 2854cdf0e10cSrcweir if ( m_bTransient ) 2855cdf0e10cSrcweir { 2856cdf0e10cSrcweir OSL_ENSURE( sal_False, "Content::exchangeIdentity - Not persistent!" ); 2857cdf0e10cSrcweir return sal_False; 2858cdf0e10cSrcweir } 2859cdf0e10cSrcweir 2860cdf0e10cSrcweir // Exchange own identitity. 2861cdf0e10cSrcweir 2862cdf0e10cSrcweir // Fail, if a content with given id already exists. 2863cdf0e10cSrcweir // if ( !hasData( xNewId ) ) 2864cdf0e10cSrcweir { 2865cdf0e10cSrcweir rtl::OUString aOldURL = m_xIdentifier->getContentIdentifier(); 2866cdf0e10cSrcweir 2867cdf0e10cSrcweir aGuard.clear(); 2868cdf0e10cSrcweir if ( exchange( xNewId ) ) 2869cdf0e10cSrcweir { 2870cdf0e10cSrcweir // Process instanciated children... 2871cdf0e10cSrcweir 2872cdf0e10cSrcweir ContentRefList aChildren; 2873cdf0e10cSrcweir queryChildren( aChildren ); 2874cdf0e10cSrcweir 2875cdf0e10cSrcweir ContentRefList::const_iterator it = aChildren.begin(); 2876cdf0e10cSrcweir ContentRefList::const_iterator end = aChildren.end(); 2877cdf0e10cSrcweir 2878cdf0e10cSrcweir while ( it != end ) 2879cdf0e10cSrcweir { 2880cdf0e10cSrcweir ContentRef xChild = (*it); 2881cdf0e10cSrcweir 2882cdf0e10cSrcweir // Create new content identifier for the child... 2883cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > 2884cdf0e10cSrcweir xOldChildId = xChild->getIdentifier(); 2885cdf0e10cSrcweir rtl::OUString aOldChildURL 2886cdf0e10cSrcweir = xOldChildId->getContentIdentifier(); 2887cdf0e10cSrcweir rtl::OUString aNewChildURL 2888cdf0e10cSrcweir = aOldChildURL.replaceAt( 2889cdf0e10cSrcweir 0, 2890cdf0e10cSrcweir aOldURL.getLength(), 2891cdf0e10cSrcweir xNewId->getContentIdentifier() ); 2892cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xNewChildId 2893cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( 2894cdf0e10cSrcweir m_xSMgr, aNewChildURL ); 2895cdf0e10cSrcweir 2896cdf0e10cSrcweir if ( !xChild->exchangeIdentity( xNewChildId ) ) 2897cdf0e10cSrcweir return sal_False; 2898cdf0e10cSrcweir 2899cdf0e10cSrcweir ++it; 2900cdf0e10cSrcweir } 2901cdf0e10cSrcweir return sal_True; 2902cdf0e10cSrcweir } 2903cdf0e10cSrcweir } 2904cdf0e10cSrcweir 2905cdf0e10cSrcweir OSL_ENSURE( sal_False, 2906cdf0e10cSrcweir "Content::exchangeIdentity - " 2907cdf0e10cSrcweir "Panic! Cannot exchange identity!" ); 2908cdf0e10cSrcweir return sal_False; 2909cdf0e10cSrcweir } 2910cdf0e10cSrcweir 2911cdf0e10cSrcweir //========================================================================= 2912cdf0e10cSrcweir sal_Bool Content::isFolder( 2913cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv ) 2914cdf0e10cSrcweir throw( uno::Exception ) 2915cdf0e10cSrcweir { 2916cdf0e10cSrcweir { 2917cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 2918cdf0e10cSrcweir 2919cdf0e10cSrcweir if ( m_bTransient ) 2920cdf0e10cSrcweir return m_bCollection; 2921cdf0e10cSrcweir } 2922cdf0e10cSrcweir 2923cdf0e10cSrcweir uno::Sequence< beans::Property > aProperties( 1 ); 2924cdf0e10cSrcweir aProperties[ 0 ].Name = rtl::OUString::createFromAscii( "IsFolder" ); 2925cdf0e10cSrcweir aProperties[ 0 ].Handle = -1; 2926cdf0e10cSrcweir uno::Reference< sdbc::XRow > xRow( getPropertyValues( aProperties, xEnv ) ); 2927cdf0e10cSrcweir if ( xRow.is() ) 2928cdf0e10cSrcweir { 2929cdf0e10cSrcweir try 2930cdf0e10cSrcweir { 2931cdf0e10cSrcweir return xRow->getBoolean( 1 ); 2932cdf0e10cSrcweir } 2933cdf0e10cSrcweir catch ( sdbc::SQLException const & ) 2934cdf0e10cSrcweir { 2935cdf0e10cSrcweir } 2936cdf0e10cSrcweir } 2937cdf0e10cSrcweir 2938cdf0e10cSrcweir return sal_False; 2939cdf0e10cSrcweir } 2940cdf0e10cSrcweir 2941cdf0e10cSrcweir //========================================================================= 2942cdf0e10cSrcweir uno::Any Content::MapDAVException( const DAVException & e, sal_Bool bWrite ) 2943cdf0e10cSrcweir { 2944cdf0e10cSrcweir // Map DAVException... 2945cdf0e10cSrcweir uno::Any aException; 2946cdf0e10cSrcweir 2947cdf0e10cSrcweir rtl::OUString aURL; 2948cdf0e10cSrcweir if ( m_bTransient ) 2949cdf0e10cSrcweir { 2950cdf0e10cSrcweir aURL = getParentURL(); 2951cdf0e10cSrcweir if ( aURL.lastIndexOf( '/' ) != ( aURL.getLength() - 1 ) ) 2952cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" ); 2953cdf0e10cSrcweir 2954cdf0e10cSrcweir aURL += m_aEscapedTitle; 2955cdf0e10cSrcweir } 2956cdf0e10cSrcweir else 2957cdf0e10cSrcweir { 2958cdf0e10cSrcweir aURL = m_xIdentifier->getContentIdentifier(); 2959cdf0e10cSrcweir } 2960cdf0e10cSrcweir 2961cdf0e10cSrcweir switch ( e.getStatus() ) 2962cdf0e10cSrcweir { 2963cdf0e10cSrcweir case SC_NOT_FOUND: 2964cdf0e10cSrcweir { 2965cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 1 ); 2966cdf0e10cSrcweir aArgs[ 0 ] <<= beans::PropertyValue( 2967cdf0e10cSrcweir rtl::OUString::createFromAscii("Uri"), -1, 2968cdf0e10cSrcweir uno::makeAny(aURL), 2969cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE); 2970cdf0e10cSrcweir 2971cdf0e10cSrcweir aException <<= 2972cdf0e10cSrcweir ucb::InteractiveAugmentedIOException( 2973cdf0e10cSrcweir rtl::OUString::createFromAscii( "Not found!" ), 2974cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 2975cdf0e10cSrcweir task::InteractionClassification_ERROR, 2976cdf0e10cSrcweir ucb::IOErrorCode_NOT_EXISTING, 2977cdf0e10cSrcweir aArgs ); 2978cdf0e10cSrcweir return aException; 2979cdf0e10cSrcweir } 2980cdf0e10cSrcweir default: 2981cdf0e10cSrcweir break; 2982cdf0e10cSrcweir } 2983cdf0e10cSrcweir 2984cdf0e10cSrcweir switch ( e.getError() ) 2985cdf0e10cSrcweir { 2986cdf0e10cSrcweir case DAVException::DAV_HTTP_ERROR: 2987cdf0e10cSrcweir { 2988cdf0e10cSrcweir if ( bWrite ) 2989cdf0e10cSrcweir aException <<= 2990cdf0e10cSrcweir ucb::InteractiveNetworkWriteException( 2991cdf0e10cSrcweir e.getData(), 2992cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 2993cdf0e10cSrcweir task::InteractionClassification_ERROR, 2994cdf0e10cSrcweir e.getData() ); 2995cdf0e10cSrcweir else 2996cdf0e10cSrcweir aException <<= 2997cdf0e10cSrcweir ucb::InteractiveNetworkReadException( 2998cdf0e10cSrcweir e.getData(), 2999cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 3000cdf0e10cSrcweir task::InteractionClassification_ERROR, 3001cdf0e10cSrcweir e.getData() ); 3002cdf0e10cSrcweir break; 3003cdf0e10cSrcweir } 3004cdf0e10cSrcweir 3005cdf0e10cSrcweir case DAVException::DAV_HTTP_LOOKUP: 3006cdf0e10cSrcweir aException <<= 3007cdf0e10cSrcweir ucb::InteractiveNetworkResolveNameException( 3008cdf0e10cSrcweir rtl::OUString(), 3009cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 3010cdf0e10cSrcweir task::InteractionClassification_ERROR, 3011cdf0e10cSrcweir e.getData() ); 3012cdf0e10cSrcweir break; 3013cdf0e10cSrcweir 3014cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception 3015cdf0e10cSrcweir // case DAVException::DAV_HTTP_AUTH: 3016cdf0e10cSrcweir // break; 3017cdf0e10cSrcweir 3018cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception 3019cdf0e10cSrcweir // case DAVException::DAV_HTTP_AUTHPROXY: 3020cdf0e10cSrcweir // break; 3021cdf0e10cSrcweir 3022cdf0e10cSrcweir case DAVException::DAV_HTTP_CONNECT: 3023cdf0e10cSrcweir aException <<= 3024cdf0e10cSrcweir ucb::InteractiveNetworkConnectException( 3025cdf0e10cSrcweir rtl::OUString(), 3026cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 3027cdf0e10cSrcweir task::InteractionClassification_ERROR, 3028cdf0e10cSrcweir e.getData() ); 3029cdf0e10cSrcweir break; 3030cdf0e10cSrcweir 3031cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception 3032cdf0e10cSrcweir // case DAVException::DAV_HTTP_TIMEOUT: 3033cdf0e10cSrcweir // break; 3034cdf0e10cSrcweir 3035cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception 3036cdf0e10cSrcweir // case DAVException::DAV_HTTP_REDIRECT: 3037cdf0e10cSrcweir // break; 3038cdf0e10cSrcweir 3039cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception 3040cdf0e10cSrcweir // case DAVException::DAV_SESSION_CREATE: 3041cdf0e10cSrcweir // break; 3042cdf0e10cSrcweir 3043cdf0e10cSrcweir case DAVException::DAV_INVALID_ARG: 3044cdf0e10cSrcweir aException <<= 3045cdf0e10cSrcweir lang::IllegalArgumentException( 3046cdf0e10cSrcweir rtl::OUString(), 3047cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 3048cdf0e10cSrcweir -1 ); 3049cdf0e10cSrcweir break; 3050cdf0e10cSrcweir 3051cdf0e10cSrcweir case DAVException::DAV_LOCKED: 3052cdf0e10cSrcweir #if 1 3053cdf0e10cSrcweir aException <<= 3054cdf0e10cSrcweir ucb::InteractiveLockingLockedException( 3055cdf0e10cSrcweir rtl::OUString::createFromAscii( "Locked!" ), 3056cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 3057cdf0e10cSrcweir task::InteractionClassification_ERROR, 3058cdf0e10cSrcweir aURL, 3059cdf0e10cSrcweir sal_False ); // not SelfOwned 3060cdf0e10cSrcweir #else 3061cdf0e10cSrcweir { 3062cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 1 ); 3063cdf0e10cSrcweir aArgs[ 0 ] <<= beans::PropertyValue( 3064cdf0e10cSrcweir rtl::OUString::createFromAscii("Uri"), -1, 3065cdf0e10cSrcweir uno::makeAny(aURL), 3066cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE); 3067cdf0e10cSrcweir 3068cdf0e10cSrcweir aException <<= 3069cdf0e10cSrcweir ucb::InteractiveAugmentedIOException( 3070cdf0e10cSrcweir rtl::OUString::createFromAscii( "Locked!" ), 3071cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 3072cdf0e10cSrcweir task::InteractionClassification_ERROR, 3073cdf0e10cSrcweir ucb::IOErrorCode_LOCKING_VIOLATION, 3074cdf0e10cSrcweir aArgs ); 3075cdf0e10cSrcweir } 3076cdf0e10cSrcweir #endif 3077cdf0e10cSrcweir break; 3078cdf0e10cSrcweir 3079cdf0e10cSrcweir case DAVException::DAV_LOCKED_SELF: 3080cdf0e10cSrcweir aException <<= 3081cdf0e10cSrcweir ucb::InteractiveLockingLockedException( 3082cdf0e10cSrcweir rtl::OUString::createFromAscii( "Locked (self)!" ), 3083cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 3084cdf0e10cSrcweir task::InteractionClassification_ERROR, 3085cdf0e10cSrcweir aURL, 3086cdf0e10cSrcweir sal_True ); // SelfOwned 3087cdf0e10cSrcweir break; 3088cdf0e10cSrcweir 3089cdf0e10cSrcweir case DAVException::DAV_NOT_LOCKED: 3090cdf0e10cSrcweir aException <<= 3091cdf0e10cSrcweir ucb::InteractiveLockingNotLockedException( 3092cdf0e10cSrcweir rtl::OUString::createFromAscii( "Not locked!" ), 3093cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 3094cdf0e10cSrcweir task::InteractionClassification_ERROR, 3095cdf0e10cSrcweir aURL ); 3096cdf0e10cSrcweir break; 3097cdf0e10cSrcweir 3098cdf0e10cSrcweir case DAVException::DAV_LOCK_EXPIRED: 3099cdf0e10cSrcweir aException <<= 3100cdf0e10cSrcweir ucb::InteractiveLockingLockExpiredException( 3101cdf0e10cSrcweir rtl::OUString::createFromAscii( "Lock expired!" ), 3102cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 3103cdf0e10cSrcweir task::InteractionClassification_ERROR, 3104cdf0e10cSrcweir aURL ); 3105cdf0e10cSrcweir break; 3106cdf0e10cSrcweir 3107cdf0e10cSrcweir default: 3108cdf0e10cSrcweir aException <<= 3109cdf0e10cSrcweir ucb::InteractiveNetworkGeneralException( 3110cdf0e10cSrcweir rtl::OUString(), 3111cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 3112cdf0e10cSrcweir task::InteractionClassification_ERROR ); 3113cdf0e10cSrcweir break; 3114cdf0e10cSrcweir } 3115cdf0e10cSrcweir 3116cdf0e10cSrcweir return aException; 3117cdf0e10cSrcweir } 3118cdf0e10cSrcweir 3119cdf0e10cSrcweir //========================================================================= 3120cdf0e10cSrcweir // static 3121cdf0e10cSrcweir bool Content::shouldAccessNetworkAfterException( const DAVException & e ) 3122cdf0e10cSrcweir { 3123cdf0e10cSrcweir if ( ( e.getStatus() == SC_NOT_FOUND ) || 3124cdf0e10cSrcweir ( e.getError() == DAVException::DAV_HTTP_LOOKUP ) || 3125cdf0e10cSrcweir ( e.getError() == DAVException::DAV_HTTP_CONNECT ) || 3126cdf0e10cSrcweir ( e.getError() == DAVException::DAV_HTTP_AUTH ) || 3127cdf0e10cSrcweir ( e.getError() == DAVException::DAV_HTTP_AUTHPROXY ) ) 3128cdf0e10cSrcweir return false; 3129cdf0e10cSrcweir 3130cdf0e10cSrcweir return true; 3131cdf0e10cSrcweir } 3132cdf0e10cSrcweir 3133cdf0e10cSrcweir //========================================================================= 3134cdf0e10cSrcweir void Content::cancelCommandExecution( 3135cdf0e10cSrcweir const DAVException & e, 3136cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv, 3137cdf0e10cSrcweir sal_Bool bWrite /* = sal_False */ ) 3138cdf0e10cSrcweir throw ( uno::Exception ) 3139cdf0e10cSrcweir { 3140cdf0e10cSrcweir ucbhelper::cancelCommandExecution( MapDAVException( e, bWrite ), xEnv ); 3141cdf0e10cSrcweir // Unreachable 3142cdf0e10cSrcweir } 3143cdf0e10cSrcweir 3144cdf0e10cSrcweir //========================================================================= 3145cdf0e10cSrcweir const rtl::OUString 3146cdf0e10cSrcweir Content::getBaseURI( const std::auto_ptr< DAVResourceAccess > & rResAccess ) 3147cdf0e10cSrcweir { 3148cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 3149cdf0e10cSrcweir 3150cdf0e10cSrcweir // First, try to obtain value of response header "Content-Location". 3151cdf0e10cSrcweir if ( m_xCachedProps.get() ) 3152cdf0e10cSrcweir { 3153cdf0e10cSrcweir rtl::OUString aLocation; 3154cdf0e10cSrcweir m_xCachedProps->getValue( rtl::OUString( 3155cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 3156cdf0e10cSrcweir "Content-Location" ) ) ) >>= aLocation; 3157cdf0e10cSrcweir if ( aLocation.getLength() ) 3158cdf0e10cSrcweir { 3159cdf0e10cSrcweir try 3160cdf0e10cSrcweir { 3161cdf0e10cSrcweir // Do not use m_xIdentifier->getContentIdentifier() because it 3162cdf0e10cSrcweir // for example does not reflect redirects applied to requests 3163cdf0e10cSrcweir // done using the original URI but m_xResAccess' URI does. 3164cdf0e10cSrcweir return rtl::Uri::convertRelToAbs( rResAccess->getURL(), 3165cdf0e10cSrcweir aLocation ); 3166cdf0e10cSrcweir } 3167cdf0e10cSrcweir catch ( rtl::MalformedUriException const & ) 3168cdf0e10cSrcweir { 3169cdf0e10cSrcweir } 3170cdf0e10cSrcweir } 3171cdf0e10cSrcweir } 3172cdf0e10cSrcweir 3173cdf0e10cSrcweir return rtl::OUString( rResAccess->getURL() ); 3174cdf0e10cSrcweir } 3175cdf0e10cSrcweir 3176cdf0e10cSrcweir //========================================================================= 3177cdf0e10cSrcweir const Content::ResourceType & Content::getResourceType( 3178cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv, 3179cdf0e10cSrcweir const std::auto_ptr< DAVResourceAccess > & rResAccess ) 3180cdf0e10cSrcweir throw ( uno::Exception ) 3181cdf0e10cSrcweir { 3182cdf0e10cSrcweir if ( m_eResourceType == UNKNOWN ) 3183cdf0e10cSrcweir { 3184cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 3185cdf0e10cSrcweir 3186cdf0e10cSrcweir ResourceType eResourceType; 3187cdf0e10cSrcweir eResourceType = m_eResourceType; 3188cdf0e10cSrcweir 3189cdf0e10cSrcweir const rtl::OUString & rURL = rResAccess->getURL(); 3190cdf0e10cSrcweir const rtl::OUString aScheme( 3191cdf0e10cSrcweir rURL.copy( 0, rURL.indexOf( ':' ) ).toAsciiLowerCase() ); 3192cdf0e10cSrcweir 3193cdf0e10cSrcweir if ( aScheme.equalsAsciiL( 3194cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( FTP_URL_SCHEME ) ) ) 3195cdf0e10cSrcweir { 3196cdf0e10cSrcweir eResourceType = FTP; 3197cdf0e10cSrcweir } 3198cdf0e10cSrcweir else 3199cdf0e10cSrcweir { 3200cdf0e10cSrcweir try 3201cdf0e10cSrcweir { 3202cdf0e10cSrcweir // Try to fetch some frequently used property value, e.g. those 3203cdf0e10cSrcweir // used when loading documents... along with identifying whether 3204cdf0e10cSrcweir // this is a DAV resource. 3205cdf0e10cSrcweir std::vector< DAVResource > resources; 3206cdf0e10cSrcweir std::vector< rtl::OUString > aPropNames; 3207cdf0e10cSrcweir uno::Sequence< beans::Property > aProperties( 5 ); 3208cdf0e10cSrcweir aProperties[ 0 ].Name 3209cdf0e10cSrcweir = rtl::OUString::createFromAscii( "IsFolder" ); 3210cdf0e10cSrcweir aProperties[ 1 ].Name 3211cdf0e10cSrcweir = rtl::OUString::createFromAscii( "IsDocument" ); 3212cdf0e10cSrcweir aProperties[ 2 ].Name 3213cdf0e10cSrcweir = rtl::OUString::createFromAscii( "IsReadOnly" ); 3214cdf0e10cSrcweir aProperties[ 3 ].Name 3215cdf0e10cSrcweir = rtl::OUString::createFromAscii( "MediaType" ); 3216cdf0e10cSrcweir aProperties[ 4 ].Name 3217cdf0e10cSrcweir = DAVProperties::SUPPORTEDLOCK; 3218cdf0e10cSrcweir 3219cdf0e10cSrcweir ContentProperties::UCBNamesToDAVNames( 3220cdf0e10cSrcweir aProperties, aPropNames ); 3221cdf0e10cSrcweir 3222cdf0e10cSrcweir rResAccess->PROPFIND( 3223cdf0e10cSrcweir DAVZERO, aPropNames, resources, xEnv ); 3224cdf0e10cSrcweir 3225cdf0e10cSrcweir if ( resources.size() == 1 ) 3226cdf0e10cSrcweir { 3227cdf0e10cSrcweir m_xCachedProps.reset( 3228cdf0e10cSrcweir new CachableContentProperties( resources[ 0 ] ) ); 3229cdf0e10cSrcweir m_xCachedProps->containsAllNames( 3230cdf0e10cSrcweir aProperties, m_aFailedPropNames ); 3231cdf0e10cSrcweir } 3232cdf0e10cSrcweir 3233cdf0e10cSrcweir eResourceType = DAV; 3234cdf0e10cSrcweir } 3235cdf0e10cSrcweir catch ( DAVException const & e ) 3236cdf0e10cSrcweir { 3237cdf0e10cSrcweir rResAccess->resetUri(); 3238cdf0e10cSrcweir 3239cdf0e10cSrcweir if ( e.getStatus() == SC_METHOD_NOT_ALLOWED ) 3240cdf0e10cSrcweir { 3241cdf0e10cSrcweir // Status SC_METHOD_NOT_ALLOWED is a safe indicator that the 3242cdf0e10cSrcweir // resource is NON_DAV 3243cdf0e10cSrcweir eResourceType = NON_DAV; 3244cdf0e10cSrcweir } 3245cdf0e10cSrcweir } 3246cdf0e10cSrcweir } 3247cdf0e10cSrcweir m_eResourceType = eResourceType; 3248cdf0e10cSrcweir } 3249cdf0e10cSrcweir return m_eResourceType; 3250cdf0e10cSrcweir } 3251cdf0e10cSrcweir 3252cdf0e10cSrcweir //========================================================================= 3253cdf0e10cSrcweir const Content::ResourceType & Content::getResourceType( 3254cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv ) 3255cdf0e10cSrcweir throw ( uno::Exception ) 3256cdf0e10cSrcweir { 3257cdf0e10cSrcweir return getResourceType( xEnv, m_xResAccess ); 3258cdf0e10cSrcweir } 3259