1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_ucb.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir /************************************************************************** 32*cdf0e10cSrcweir TODO 33*cdf0e10cSrcweir ************************************************************************** 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir *************************************************************************/ 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include "osl/diagnose.h" 38*cdf0e10cSrcweir #include "osl/doublecheckedlocking.h" 39*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx" 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include "com/sun/star/beans/PropertyAttribute.hpp" 42*cdf0e10cSrcweir #include "com/sun/star/beans/PropertyValue.hpp" 43*cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp" 44*cdf0e10cSrcweir #include "com/sun/star/embed/ElementModes.hpp" 45*cdf0e10cSrcweir #include "com/sun/star/embed/XStorage.hpp" 46*cdf0e10cSrcweir #include "com/sun/star/embed/XTransactedObject.hpp" 47*cdf0e10cSrcweir #include "com/sun/star/io/XActiveDataSink.hpp" 48*cdf0e10cSrcweir #include "com/sun/star/io/XActiveDataStreamer.hpp" 49*cdf0e10cSrcweir #include "com/sun/star/lang/IllegalAccessException.hpp" 50*cdf0e10cSrcweir #include "com/sun/star/sdbc/XRow.hpp" 51*cdf0e10cSrcweir #include "com/sun/star/ucb/ContentAction.hpp" 52*cdf0e10cSrcweir #include "com/sun/star/ucb/ContentInfoAttribute.hpp" 53*cdf0e10cSrcweir #include "com/sun/star/ucb/InsertCommandArgument.hpp" 54*cdf0e10cSrcweir #include "com/sun/star/ucb/InteractiveBadTransferURLException.hpp" 55*cdf0e10cSrcweir #include "com/sun/star/ucb/MissingInputStreamException.hpp" 56*cdf0e10cSrcweir #include "com/sun/star/ucb/MissingPropertiesException.hpp" 57*cdf0e10cSrcweir #include "com/sun/star/ucb/NameClash.hpp" 58*cdf0e10cSrcweir #include "com/sun/star/ucb/NameClashException.hpp" 59*cdf0e10cSrcweir #include "com/sun/star/ucb/OpenCommandArgument2.hpp" 60*cdf0e10cSrcweir #include "com/sun/star/ucb/OpenMode.hpp" 61*cdf0e10cSrcweir #include "com/sun/star/ucb/TransferInfo.hpp" 62*cdf0e10cSrcweir #include "com/sun/star/ucb/UnsupportedCommandException.hpp" 63*cdf0e10cSrcweir #include "com/sun/star/ucb/UnsupportedDataSinkException.hpp" 64*cdf0e10cSrcweir #include "com/sun/star/ucb/UnsupportedNameClashException.hpp" 65*cdf0e10cSrcweir #include "com/sun/star/ucb/UnsupportedOpenModeException.hpp" 66*cdf0e10cSrcweir #include "com/sun/star/ucb/XCommandInfo.hpp" 67*cdf0e10cSrcweir #include "com/sun/star/ucb/XPersistentPropertySet.hpp" 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir #include "ucbhelper/cancelcommandexecution.hxx" 70*cdf0e10cSrcweir #include "ucbhelper/contentidentifier.hxx" 71*cdf0e10cSrcweir #include "ucbhelper/propertyvalueset.hxx" 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir #include "tdoc_content.hxx" 74*cdf0e10cSrcweir #include "tdoc_resultset.hxx" 75*cdf0e10cSrcweir #include "tdoc_passwordrequest.hxx" 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir #include "../inc/urihelper.hxx" 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir using namespace com::sun::star; 80*cdf0e10cSrcweir using namespace tdoc_ucp; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir //========================================================================= 83*cdf0e10cSrcweir static ContentType lcl_getContentType( const rtl::OUString & rType ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir if ( rType.equalsAsciiL( 86*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( TDOC_ROOT_CONTENT_TYPE ) ) ) 87*cdf0e10cSrcweir return ROOT; 88*cdf0e10cSrcweir else if ( rType.equalsAsciiL( 89*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( TDOC_DOCUMENT_CONTENT_TYPE ) ) ) 90*cdf0e10cSrcweir return DOCUMENT; 91*cdf0e10cSrcweir else if ( rType.equalsAsciiL( 92*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( TDOC_FOLDER_CONTENT_TYPE ) ) ) 93*cdf0e10cSrcweir return FOLDER; 94*cdf0e10cSrcweir else if ( rType.equalsAsciiL( 95*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( TDOC_STREAM_CONTENT_TYPE ) ) ) 96*cdf0e10cSrcweir return STREAM; 97*cdf0e10cSrcweir else 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir OSL_ENSURE( sal_False, 100*cdf0e10cSrcweir "Content::Content - unsupported content type string" ); 101*cdf0e10cSrcweir return STREAM; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir //========================================================================= 106*cdf0e10cSrcweir //========================================================================= 107*cdf0e10cSrcweir // 108*cdf0e10cSrcweir // Content Implementation. 109*cdf0e10cSrcweir // 110*cdf0e10cSrcweir //========================================================================= 111*cdf0e10cSrcweir //========================================================================= 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // static ( "virtual" ctor ) 114*cdf0e10cSrcweir Content* Content::create( 115*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSMgr, 116*cdf0e10cSrcweir ContentProvider* pProvider, 117*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& Identifier ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir // Fail, if resource does not exist. 120*cdf0e10cSrcweir ContentProperties aProps; 121*cdf0e10cSrcweir if ( !Content::loadData( pProvider, 122*cdf0e10cSrcweir Uri( Identifier->getContentIdentifier() ), 123*cdf0e10cSrcweir aProps ) ) 124*cdf0e10cSrcweir return 0; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir return new Content( rxSMgr, pProvider, Identifier, aProps ); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir //========================================================================= 130*cdf0e10cSrcweir // static ( "virtual" ctor ) 131*cdf0e10cSrcweir Content* Content::create( 132*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSMgr, 133*cdf0e10cSrcweir ContentProvider* pProvider, 134*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& Identifier, 135*cdf0e10cSrcweir const ucb::ContentInfo& Info ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir if ( !Info.Type.getLength() ) 138*cdf0e10cSrcweir return 0; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir if ( !Info.Type.equalsAsciiL( 141*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( TDOC_FOLDER_CONTENT_TYPE ) ) && 142*cdf0e10cSrcweir !Info.Type.equalsAsciiL( 143*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( TDOC_STREAM_CONTENT_TYPE ) ) ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Content::create - unsupported content type!" ); 146*cdf0e10cSrcweir return 0; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir #if 0 150*cdf0e10cSrcweir // Fail, if content does exist. 151*cdf0e10cSrcweir if ( Content::hasData( pProvider, 152*cdf0e10cSrcweir Uri( Identifier->getContentIdentifier() ) ) ) 153*cdf0e10cSrcweir return 0; 154*cdf0e10cSrcweir #endif 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir return new Content( rxSMgr, pProvider, Identifier, Info ); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir //========================================================================= 160*cdf0e10cSrcweir Content::Content( 161*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory > & rxSMgr, 162*cdf0e10cSrcweir ContentProvider * pProvider, 163*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier > & Identifier, 164*cdf0e10cSrcweir const ContentProperties & rProps ) 165*cdf0e10cSrcweir : ContentImplHelper( rxSMgr, pProvider, Identifier ), 166*cdf0e10cSrcweir m_aProps( rProps ), 167*cdf0e10cSrcweir m_eState( PERSISTENT ), 168*cdf0e10cSrcweir m_pProvider( pProvider ) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir //========================================================================= 173*cdf0e10cSrcweir // ctor for a content just created via XContentCreator::createNewContent() 174*cdf0e10cSrcweir Content::Content( 175*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSMgr, 176*cdf0e10cSrcweir ContentProvider* pProvider, 177*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& Identifier, 178*cdf0e10cSrcweir const ucb::ContentInfo& Info ) 179*cdf0e10cSrcweir : ContentImplHelper( rxSMgr, pProvider, Identifier ), 180*cdf0e10cSrcweir m_aProps( lcl_getContentType( Info.Type ), rtl::OUString() ), // no Title (yet) 181*cdf0e10cSrcweir m_eState( TRANSIENT ), 182*cdf0e10cSrcweir m_pProvider( pProvider ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir //========================================================================= 187*cdf0e10cSrcweir // virtual 188*cdf0e10cSrcweir Content::~Content() 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir //========================================================================= 193*cdf0e10cSrcweir // 194*cdf0e10cSrcweir // XInterface methods. 195*cdf0e10cSrcweir // 196*cdf0e10cSrcweir //========================================================================= 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir // virtual 199*cdf0e10cSrcweir void SAL_CALL Content::acquire() 200*cdf0e10cSrcweir throw( ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir ContentImplHelper::acquire(); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir //========================================================================= 206*cdf0e10cSrcweir // virtual 207*cdf0e10cSrcweir void SAL_CALL Content::release() 208*cdf0e10cSrcweir throw( ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir ContentImplHelper::release(); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir //========================================================================= 214*cdf0e10cSrcweir // virtual 215*cdf0e10cSrcweir uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType ) 216*cdf0e10cSrcweir throw ( uno::RuntimeException ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir uno::Any aRet = ContentImplHelper::queryInterface( rType ); 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir if ( !aRet.hasValue() ) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir aRet = cppu::queryInterface( 223*cdf0e10cSrcweir rType, static_cast< ucb::XContentCreator * >( this ) ); 224*cdf0e10cSrcweir if ( aRet.hasValue() ) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir if ( !m_aProps.isContentCreator() ) 227*cdf0e10cSrcweir return uno::Any(); 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir return aRet; 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir //========================================================================= 235*cdf0e10cSrcweir // 236*cdf0e10cSrcweir // XTypeProvider methods. 237*cdf0e10cSrcweir // 238*cdf0e10cSrcweir //========================================================================= 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir XTYPEPROVIDER_COMMON_IMPL( Content ); 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir //========================================================================= 243*cdf0e10cSrcweir // virtual 244*cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL Content::getTypes() 245*cdf0e10cSrcweir throw( uno::RuntimeException ) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir cppu::OTypeCollection * pCollection = 0; 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir if ( m_aProps.isContentCreator() ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir static cppu::OTypeCollection* pFolderTypes = 0; 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir pCollection = pFolderTypes; 254*cdf0e10cSrcweir if ( !pCollection ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir pCollection = pFolderTypes; 259*cdf0e10cSrcweir if ( !pCollection ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir static cppu::OTypeCollection aCollection( 262*cdf0e10cSrcweir CPPU_TYPE_REF( lang::XTypeProvider ), 263*cdf0e10cSrcweir CPPU_TYPE_REF( lang::XServiceInfo ), 264*cdf0e10cSrcweir CPPU_TYPE_REF( lang::XComponent ), 265*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContent ), 266*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandProcessor ), 267*cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ), 268*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ), 269*cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertyContainer ), 270*cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ), 271*cdf0e10cSrcweir CPPU_TYPE_REF( container::XChild ), 272*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContentCreator ) ); // !! 273*cdf0e10cSrcweir pCollection = &aCollection; 274*cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 275*cdf0e10cSrcweir pFolderTypes = pCollection; 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir else { 279*cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir else 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir static cppu::OTypeCollection* pDocumentTypes = 0; 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir pCollection = pDocumentTypes; 287*cdf0e10cSrcweir if ( !pCollection ) 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir pCollection = pDocumentTypes; 292*cdf0e10cSrcweir if ( !pCollection ) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir static cppu::OTypeCollection aCollection( 295*cdf0e10cSrcweir CPPU_TYPE_REF( lang::XTypeProvider ), 296*cdf0e10cSrcweir CPPU_TYPE_REF( lang::XServiceInfo ), 297*cdf0e10cSrcweir CPPU_TYPE_REF( lang::XComponent ), 298*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContent ), 299*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandProcessor ), 300*cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ), 301*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ), 302*cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertyContainer ), 303*cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ), 304*cdf0e10cSrcweir CPPU_TYPE_REF( container::XChild ) ); 305*cdf0e10cSrcweir pCollection = &aCollection; 306*cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 307*cdf0e10cSrcweir pDocumentTypes = pCollection; 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir else { 311*cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir return (*pCollection).getTypes(); 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir //========================================================================= 319*cdf0e10cSrcweir // 320*cdf0e10cSrcweir // XServiceInfo methods. 321*cdf0e10cSrcweir // 322*cdf0e10cSrcweir //========================================================================= 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir // virtual 325*cdf0e10cSrcweir rtl::OUString SAL_CALL Content::getImplementationName() 326*cdf0e10cSrcweir throw( uno::RuntimeException ) 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir return rtl::OUString::createFromAscii( 329*cdf0e10cSrcweir "com.sun.star.comp.ucb.TransientDocumentsContent" ); 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir //========================================================================= 333*cdf0e10cSrcweir // virtual 334*cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL Content::getSupportedServiceNames() 335*cdf0e10cSrcweir throw( uno::RuntimeException ) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir uno::Sequence< rtl::OUString > aSNS( 1 ); 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir if ( m_aProps.getType() == STREAM ) 342*cdf0e10cSrcweir aSNS.getArray()[ 0 ] = rtl::OUString::createFromAscii( 343*cdf0e10cSrcweir TDOC_STREAM_CONTENT_SERVICE_NAME ); 344*cdf0e10cSrcweir else if ( m_aProps.getType() == FOLDER ) 345*cdf0e10cSrcweir aSNS.getArray()[ 0 ] = rtl::OUString::createFromAscii( 346*cdf0e10cSrcweir TDOC_FOLDER_CONTENT_SERVICE_NAME ); 347*cdf0e10cSrcweir else if ( m_aProps.getType() == DOCUMENT ) 348*cdf0e10cSrcweir aSNS.getArray()[ 0 ] = rtl::OUString::createFromAscii( 349*cdf0e10cSrcweir TDOC_DOCUMENT_CONTENT_SERVICE_NAME ); 350*cdf0e10cSrcweir else 351*cdf0e10cSrcweir aSNS.getArray()[ 0 ] = rtl::OUString::createFromAscii( 352*cdf0e10cSrcweir TDOC_ROOT_CONTENT_SERVICE_NAME ); 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir return aSNS; 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir //========================================================================= 358*cdf0e10cSrcweir // 359*cdf0e10cSrcweir // XContent methods. 360*cdf0e10cSrcweir // 361*cdf0e10cSrcweir //========================================================================= 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir // virtual 364*cdf0e10cSrcweir rtl::OUString SAL_CALL Content::getContentType() 365*cdf0e10cSrcweir throw( uno::RuntimeException ) 366*cdf0e10cSrcweir { 367*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 368*cdf0e10cSrcweir return m_aProps.getContentType(); 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir //========================================================================= 372*cdf0e10cSrcweir // virtual 373*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > SAL_CALL 374*cdf0e10cSrcweir Content::getIdentifier() 375*cdf0e10cSrcweir throw( uno::RuntimeException ) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir // Transient? 381*cdf0e10cSrcweir if ( m_eState == TRANSIENT ) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir // Transient contents have no identifier. 384*cdf0e10cSrcweir return uno::Reference< ucb::XContentIdentifier >(); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir return ContentImplHelper::getIdentifier(); 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir //========================================================================= 391*cdf0e10cSrcweir // 392*cdf0e10cSrcweir // XCommandProcessor methods. 393*cdf0e10cSrcweir // 394*cdf0e10cSrcweir //========================================================================= 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir // virtual 397*cdf0e10cSrcweir uno::Any SAL_CALL Content::execute( 398*cdf0e10cSrcweir const ucb::Command& aCommand, 399*cdf0e10cSrcweir sal_Int32 /*CommandId*/, 400*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& Environment ) 401*cdf0e10cSrcweir throw( uno::Exception, 402*cdf0e10cSrcweir ucb::CommandAbortedException, 403*cdf0e10cSrcweir uno::RuntimeException ) 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir uno::Any aRet; 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir if ( aCommand.Name.equalsAsciiL( 408*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "getPropertyValues" ) ) ) 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 411*cdf0e10cSrcweir // getPropertyValues 412*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir uno::Sequence< beans::Property > Properties; 415*cdf0e10cSrcweir if ( !( aCommand.Argument >>= Properties ) ) 416*cdf0e10cSrcweir { 417*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 418*cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 419*cdf0e10cSrcweir rtl::OUString::createFromAscii( 420*cdf0e10cSrcweir "Wrong argument type!" ), 421*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 422*cdf0e10cSrcweir -1 ) ), 423*cdf0e10cSrcweir Environment ); 424*cdf0e10cSrcweir // Unreachable 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir aRet <<= getPropertyValues( Properties ); 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 430*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "setPropertyValues" ) ) ) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 433*cdf0e10cSrcweir // setPropertyValues 434*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aProperties; 437*cdf0e10cSrcweir if ( !( aCommand.Argument >>= aProperties ) ) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 440*cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 441*cdf0e10cSrcweir rtl::OUString::createFromAscii( 442*cdf0e10cSrcweir "Wrong argument type!" ), 443*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 444*cdf0e10cSrcweir -1 ) ), 445*cdf0e10cSrcweir Environment ); 446*cdf0e10cSrcweir // Unreachable 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir if ( !aProperties.getLength() ) 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 452*cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 453*cdf0e10cSrcweir rtl::OUString::createFromAscii( 454*cdf0e10cSrcweir "No properties!" ), 455*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 456*cdf0e10cSrcweir -1 ) ), 457*cdf0e10cSrcweir Environment ); 458*cdf0e10cSrcweir // Unreachable 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir aRet <<= setPropertyValues( aProperties, Environment ); 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 464*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "getPropertySetInfo" ) ) ) 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 467*cdf0e10cSrcweir // getPropertySetInfo 468*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir aRet <<= getPropertySetInfo( Environment ); 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 473*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "getCommandInfo" ) ) ) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 476*cdf0e10cSrcweir // getCommandInfo 477*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir aRet <<= getCommandInfo( Environment ); 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 482*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "open" ) ) ) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 485*cdf0e10cSrcweir // open 486*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir ucb::OpenCommandArgument2 aOpenCommand; 489*cdf0e10cSrcweir if ( !( aCommand.Argument >>= aOpenCommand ) ) 490*cdf0e10cSrcweir { 491*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 492*cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 493*cdf0e10cSrcweir rtl::OUString::createFromAscii( 494*cdf0e10cSrcweir "Wrong argument type!" ), 495*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 496*cdf0e10cSrcweir -1 ) ), 497*cdf0e10cSrcweir Environment ); 498*cdf0e10cSrcweir // Unreachable 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir aRet = open( aOpenCommand, Environment ); 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 504*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "insert" ) ) ) 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 507*cdf0e10cSrcweir // insert ( Supported by folders and streams only ) 508*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 511*cdf0e10cSrcweir if ( ( eType != FOLDER ) && ( eType != STREAM ) ) 512*cdf0e10cSrcweir { 513*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 514*cdf0e10cSrcweir uno::makeAny( ucb::UnsupportedCommandException( 515*cdf0e10cSrcweir rtl::OUString( 516*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 517*cdf0e10cSrcweir "insert command only supported by " 518*cdf0e10cSrcweir "folders and streams!" ) ), 519*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ), 520*cdf0e10cSrcweir Environment ); 521*cdf0e10cSrcweir // Unreachable 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir #ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 525*cdf0e10cSrcweir if ( eType == STREAM ) 526*cdf0e10cSrcweir { 527*cdf0e10cSrcweir Uri aUri( m_xIdentifier->getContentIdentifier() ); 528*cdf0e10cSrcweir Uri aParentUri( aUri.getParentUri() ); 529*cdf0e10cSrcweir if ( aParentUri.isDocument() ) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 532*cdf0e10cSrcweir uno::makeAny( ucb::UnsupportedCommandException( 533*cdf0e10cSrcweir rtl::OUString( 534*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 535*cdf0e10cSrcweir "insert command not supported by " 536*cdf0e10cSrcweir "streams that are direct children " 537*cdf0e10cSrcweir "of document root!" ) ), 538*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( 539*cdf0e10cSrcweir this ) ) ), 540*cdf0e10cSrcweir Environment ); 541*cdf0e10cSrcweir // Unreachable 542*cdf0e10cSrcweir } 543*cdf0e10cSrcweir } 544*cdf0e10cSrcweir #endif 545*cdf0e10cSrcweir ucb::InsertCommandArgument aArg; 546*cdf0e10cSrcweir if ( !( aCommand.Argument >>= aArg ) ) 547*cdf0e10cSrcweir { 548*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 549*cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 550*cdf0e10cSrcweir rtl::OUString::createFromAscii( 551*cdf0e10cSrcweir "Wrong argument type!" ), 552*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 553*cdf0e10cSrcweir -1 ) ), 554*cdf0e10cSrcweir Environment ); 555*cdf0e10cSrcweir // Unreachable 556*cdf0e10cSrcweir } 557*cdf0e10cSrcweir 558*cdf0e10cSrcweir sal_Int32 nNameClash = aArg.ReplaceExisting 559*cdf0e10cSrcweir ? ucb::NameClash::OVERWRITE 560*cdf0e10cSrcweir : ucb::NameClash::ERROR; 561*cdf0e10cSrcweir insert( aArg.Data, nNameClash, Environment ); 562*cdf0e10cSrcweir } 563*cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 564*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "delete" ) ) ) 565*cdf0e10cSrcweir { 566*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 567*cdf0e10cSrcweir // delete ( Supported by folders and streams only ) 568*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir { 571*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 574*cdf0e10cSrcweir if ( ( eType != FOLDER ) && ( eType != STREAM ) ) 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 577*cdf0e10cSrcweir uno::makeAny( ucb::UnsupportedCommandException( 578*cdf0e10cSrcweir rtl::OUString( 579*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 580*cdf0e10cSrcweir "delete command only supported by " 581*cdf0e10cSrcweir "folders and streams!" ) ), 582*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( 583*cdf0e10cSrcweir this ) ) ), 584*cdf0e10cSrcweir Environment ); 585*cdf0e10cSrcweir // Unreachable 586*cdf0e10cSrcweir } 587*cdf0e10cSrcweir } 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir sal_Bool bDeletePhysical = sal_False; 590*cdf0e10cSrcweir aCommand.Argument >>= bDeletePhysical; 591*cdf0e10cSrcweir destroy( bDeletePhysical, Environment ); 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir // Remove own and all children's persistent data. 594*cdf0e10cSrcweir if ( !removeData() ) 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir uno::Any aProps 597*cdf0e10cSrcweir = uno::makeAny( 598*cdf0e10cSrcweir beans::PropertyValue( 599*cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 600*cdf0e10cSrcweir "Uri")), 601*cdf0e10cSrcweir -1, 602*cdf0e10cSrcweir uno::makeAny(m_xIdentifier-> 603*cdf0e10cSrcweir getContentIdentifier()), 604*cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE)); 605*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 606*cdf0e10cSrcweir ucb::IOErrorCode_CANT_WRITE, 607*cdf0e10cSrcweir uno::Sequence< uno::Any >(&aProps, 1), 608*cdf0e10cSrcweir Environment, 609*cdf0e10cSrcweir rtl::OUString::createFromAscii( 610*cdf0e10cSrcweir "Cannot remove persistent data!" ), 611*cdf0e10cSrcweir this ); 612*cdf0e10cSrcweir // Unreachable 613*cdf0e10cSrcweir } 614*cdf0e10cSrcweir 615*cdf0e10cSrcweir // Remove own and all children's Additional Core Properties. 616*cdf0e10cSrcweir removeAdditionalPropertySet( sal_True ); 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 619*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "transfer" ) ) ) 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 622*cdf0e10cSrcweir // transfer ( Supported by document and folders only ) 623*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir { 626*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 627*cdf0e10cSrcweir 628*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 629*cdf0e10cSrcweir if ( ( eType != FOLDER ) && ( eType != DOCUMENT ) ) 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 632*cdf0e10cSrcweir uno::makeAny( ucb::UnsupportedCommandException( 633*cdf0e10cSrcweir rtl::OUString( 634*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 635*cdf0e10cSrcweir "transfer command only supported " 636*cdf0e10cSrcweir "by folders and documents!" ) ), 637*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( 638*cdf0e10cSrcweir this ) ) ), 639*cdf0e10cSrcweir Environment ); 640*cdf0e10cSrcweir // Unreachable 641*cdf0e10cSrcweir } 642*cdf0e10cSrcweir } 643*cdf0e10cSrcweir 644*cdf0e10cSrcweir ucb::TransferInfo aInfo; 645*cdf0e10cSrcweir if ( !( aCommand.Argument >>= aInfo ) ) 646*cdf0e10cSrcweir { 647*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Wrong argument type!" ); 648*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 649*cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 650*cdf0e10cSrcweir rtl::OUString::createFromAscii( 651*cdf0e10cSrcweir "Wrong argument type!" ), 652*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 653*cdf0e10cSrcweir -1 ) ), 654*cdf0e10cSrcweir Environment ); 655*cdf0e10cSrcweir // Unreachable 656*cdf0e10cSrcweir } 657*cdf0e10cSrcweir 658*cdf0e10cSrcweir transfer( aInfo, Environment ); 659*cdf0e10cSrcweir } 660*cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL( 661*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "createNewContent" ) ) ) 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 664*cdf0e10cSrcweir // createNewContent ( Supported by document and folders only ) 665*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 666*cdf0e10cSrcweir 667*cdf0e10cSrcweir { 668*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 671*cdf0e10cSrcweir if ( ( eType != FOLDER ) && ( eType != DOCUMENT ) ) 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 674*cdf0e10cSrcweir uno::makeAny( ucb::UnsupportedCommandException( 675*cdf0e10cSrcweir rtl::OUString( 676*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 677*cdf0e10cSrcweir "createNewContent command only " 678*cdf0e10cSrcweir "supported by folders and " 679*cdf0e10cSrcweir "documents!" ) ), 680*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( 681*cdf0e10cSrcweir this ) ) ), 682*cdf0e10cSrcweir Environment ); 683*cdf0e10cSrcweir // Unreachable 684*cdf0e10cSrcweir } 685*cdf0e10cSrcweir } 686*cdf0e10cSrcweir 687*cdf0e10cSrcweir ucb::ContentInfo aInfo; 688*cdf0e10cSrcweir if ( !( aCommand.Argument >>= aInfo ) ) 689*cdf0e10cSrcweir { 690*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Wrong argument type!" ); 691*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 692*cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 693*cdf0e10cSrcweir rtl::OUString::createFromAscii( 694*cdf0e10cSrcweir "Wrong argument type!" ), 695*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 696*cdf0e10cSrcweir -1 ) ), 697*cdf0e10cSrcweir Environment ); 698*cdf0e10cSrcweir // Unreachable 699*cdf0e10cSrcweir } 700*cdf0e10cSrcweir 701*cdf0e10cSrcweir aRet <<= createNewContent( aInfo ); 702*cdf0e10cSrcweir } 703*cdf0e10cSrcweir else 704*cdf0e10cSrcweir { 705*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 706*cdf0e10cSrcweir // Unsupported command 707*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 708*cdf0e10cSrcweir 709*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 710*cdf0e10cSrcweir uno::makeAny( ucb::UnsupportedCommandException( 711*cdf0e10cSrcweir rtl::OUString(), 712*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ), 713*cdf0e10cSrcweir Environment ); 714*cdf0e10cSrcweir // Unreachable 715*cdf0e10cSrcweir } 716*cdf0e10cSrcweir 717*cdf0e10cSrcweir return aRet; 718*cdf0e10cSrcweir } 719*cdf0e10cSrcweir 720*cdf0e10cSrcweir //========================================================================= 721*cdf0e10cSrcweir // virtual 722*cdf0e10cSrcweir void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ ) 723*cdf0e10cSrcweir throw( uno::RuntimeException ) 724*cdf0e10cSrcweir { 725*cdf0e10cSrcweir } 726*cdf0e10cSrcweir 727*cdf0e10cSrcweir //========================================================================= 728*cdf0e10cSrcweir // 729*cdf0e10cSrcweir // XContentCreator methods. 730*cdf0e10cSrcweir // 731*cdf0e10cSrcweir //========================================================================= 732*cdf0e10cSrcweir 733*cdf0e10cSrcweir // virtual 734*cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > SAL_CALL 735*cdf0e10cSrcweir Content::queryCreatableContentsInfo() 736*cdf0e10cSrcweir throw( uno::RuntimeException ) 737*cdf0e10cSrcweir { 738*cdf0e10cSrcweir return m_aProps.getCreatableContentsInfo(); 739*cdf0e10cSrcweir } 740*cdf0e10cSrcweir 741*cdf0e10cSrcweir //========================================================================= 742*cdf0e10cSrcweir // virtual 743*cdf0e10cSrcweir uno::Reference< ucb::XContent > SAL_CALL 744*cdf0e10cSrcweir Content::createNewContent( const ucb::ContentInfo& Info ) 745*cdf0e10cSrcweir throw( uno::RuntimeException ) 746*cdf0e10cSrcweir { 747*cdf0e10cSrcweir if ( m_aProps.isContentCreator() ) 748*cdf0e10cSrcweir { 749*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 750*cdf0e10cSrcweir 751*cdf0e10cSrcweir if ( !Info.Type.getLength() ) 752*cdf0e10cSrcweir return uno::Reference< ucb::XContent >(); 753*cdf0e10cSrcweir 754*cdf0e10cSrcweir sal_Bool bCreateFolder = 755*cdf0e10cSrcweir Info.Type.equalsAsciiL( 756*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( TDOC_FOLDER_CONTENT_TYPE ) ); 757*cdf0e10cSrcweir 758*cdf0e10cSrcweir #ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 759*cdf0e10cSrcweir // streams cannot be created as direct children of document root 760*cdf0e10cSrcweir if ( !bCreateFolder && ( m_aProps.getType() == DOCUMENT ) ) 761*cdf0e10cSrcweir { 762*cdf0e10cSrcweir OSL_ENSURE( sal_False, 763*cdf0e10cSrcweir "Content::createNewContent - streams cannot be " 764*cdf0e10cSrcweir "created as direct children of document root!" ); 765*cdf0e10cSrcweir return uno::Reference< ucb::XContent >(); 766*cdf0e10cSrcweir } 767*cdf0e10cSrcweir #endif 768*cdf0e10cSrcweir if ( !bCreateFolder && 769*cdf0e10cSrcweir !Info.Type.equalsAsciiL( 770*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( TDOC_STREAM_CONTENT_TYPE ) ) ) 771*cdf0e10cSrcweir { 772*cdf0e10cSrcweir OSL_ENSURE( sal_False, 773*cdf0e10cSrcweir "Content::createNewContent - unsupported type!" ); 774*cdf0e10cSrcweir return uno::Reference< ucb::XContent >(); 775*cdf0e10cSrcweir } 776*cdf0e10cSrcweir 777*cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier(); 778*cdf0e10cSrcweir 779*cdf0e10cSrcweir OSL_ENSURE( aURL.getLength() > 0, 780*cdf0e10cSrcweir "Content::createNewContent - empty identifier!" ); 781*cdf0e10cSrcweir 782*cdf0e10cSrcweir if ( ( aURL.lastIndexOf( '/' ) + 1 ) != aURL.getLength() ) 783*cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" ); 784*cdf0e10cSrcweir 785*cdf0e10cSrcweir if ( bCreateFolder ) 786*cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "New_Folder" ); 787*cdf0e10cSrcweir else 788*cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "New_Stream" ); 789*cdf0e10cSrcweir 790*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xId 791*cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL ); 792*cdf0e10cSrcweir 793*cdf0e10cSrcweir return create( m_xSMgr, m_pProvider, xId, Info ); 794*cdf0e10cSrcweir } 795*cdf0e10cSrcweir else 796*cdf0e10cSrcweir { 797*cdf0e10cSrcweir OSL_ENSURE( sal_False, 798*cdf0e10cSrcweir "createNewContent called on non-contentcreator object!" ); 799*cdf0e10cSrcweir return uno::Reference< ucb::XContent >(); 800*cdf0e10cSrcweir } 801*cdf0e10cSrcweir } 802*cdf0e10cSrcweir 803*cdf0e10cSrcweir //========================================================================= 804*cdf0e10cSrcweir // virtual 805*cdf0e10cSrcweir rtl::OUString Content::getParentURL() 806*cdf0e10cSrcweir { 807*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 808*cdf0e10cSrcweir Uri aUri( m_xIdentifier->getContentIdentifier() ); 809*cdf0e10cSrcweir return aUri.getParentUri(); 810*cdf0e10cSrcweir } 811*cdf0e10cSrcweir 812*cdf0e10cSrcweir //========================================================================= 813*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > 814*cdf0e10cSrcweir Content::makeNewIdentifier( const rtl::OUString& rTitle ) 815*cdf0e10cSrcweir { 816*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 817*cdf0e10cSrcweir 818*cdf0e10cSrcweir // Assemble new content identifier... 819*cdf0e10cSrcweir Uri aUri( m_xIdentifier->getContentIdentifier() ); 820*cdf0e10cSrcweir rtl::OUStringBuffer aNewURL = aUri.getParentUri(); 821*cdf0e10cSrcweir aNewURL.append( ::ucb_impl::urihelper::encodeSegment( rTitle ) ); 822*cdf0e10cSrcweir 823*cdf0e10cSrcweir return 824*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier >( 825*cdf0e10cSrcweir new ::ucbhelper::ContentIdentifier( 826*cdf0e10cSrcweir m_xSMgr, aNewURL.makeStringAndClear() ) ); 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir 829*cdf0e10cSrcweir //========================================================================= 830*cdf0e10cSrcweir void Content::queryChildren( ContentRefList& rChildren ) 831*cdf0e10cSrcweir { 832*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 833*cdf0e10cSrcweir 834*cdf0e10cSrcweir // Only folders (root, documents, folders) have children. 835*cdf0e10cSrcweir if ( !m_aProps.getIsFolder() ) 836*cdf0e10cSrcweir return; 837*cdf0e10cSrcweir 838*cdf0e10cSrcweir // Obtain a list with a snapshot of all currently instanciated contents 839*cdf0e10cSrcweir // from provider and extract the contents which are direct children 840*cdf0e10cSrcweir // of this content. 841*cdf0e10cSrcweir 842*cdf0e10cSrcweir ::ucbhelper::ContentRefList aAllContents; 843*cdf0e10cSrcweir m_xProvider->queryExistingContents( aAllContents ); 844*cdf0e10cSrcweir 845*cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier(); 846*cdf0e10cSrcweir sal_Int32 nURLPos = aURL.lastIndexOf( '/' ); 847*cdf0e10cSrcweir 848*cdf0e10cSrcweir if ( nURLPos != ( aURL.getLength() - 1 ) ) 849*cdf0e10cSrcweir { 850*cdf0e10cSrcweir // No trailing slash found. Append. 851*cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" ); 852*cdf0e10cSrcweir } 853*cdf0e10cSrcweir 854*cdf0e10cSrcweir sal_Int32 nLen = aURL.getLength(); 855*cdf0e10cSrcweir 856*cdf0e10cSrcweir ::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin(); 857*cdf0e10cSrcweir ::ucbhelper::ContentRefList::const_iterator end = aAllContents.end(); 858*cdf0e10cSrcweir 859*cdf0e10cSrcweir while ( it != end ) 860*cdf0e10cSrcweir { 861*cdf0e10cSrcweir ::ucbhelper::ContentImplHelperRef xChild = (*it); 862*cdf0e10cSrcweir rtl::OUString aChildURL 863*cdf0e10cSrcweir = xChild->getIdentifier()->getContentIdentifier(); 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir // Is aURL a prefix of aChildURL? 866*cdf0e10cSrcweir if ( ( aChildURL.getLength() > nLen ) && 867*cdf0e10cSrcweir ( aChildURL.compareTo( aURL, nLen ) == 0 ) ) 868*cdf0e10cSrcweir { 869*cdf0e10cSrcweir sal_Int32 nPos = nLen; 870*cdf0e10cSrcweir nPos = aChildURL.indexOf( '/', nPos ); 871*cdf0e10cSrcweir 872*cdf0e10cSrcweir if ( ( nPos == -1 ) || 873*cdf0e10cSrcweir ( nPos == ( aChildURL.getLength() - 1 ) ) ) 874*cdf0e10cSrcweir { 875*cdf0e10cSrcweir // No further slashes / only a final slash. It's a child! 876*cdf0e10cSrcweir rChildren.push_back( 877*cdf0e10cSrcweir ContentRef( 878*cdf0e10cSrcweir static_cast< Content * >( xChild.get() ) ) ); 879*cdf0e10cSrcweir } 880*cdf0e10cSrcweir } 881*cdf0e10cSrcweir ++it; 882*cdf0e10cSrcweir } 883*cdf0e10cSrcweir } 884*cdf0e10cSrcweir 885*cdf0e10cSrcweir //========================================================================= 886*cdf0e10cSrcweir sal_Bool Content::exchangeIdentity( 887*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& xNewId ) 888*cdf0e10cSrcweir { 889*cdf0e10cSrcweir if ( !xNewId.is() ) 890*cdf0e10cSrcweir return sal_False; 891*cdf0e10cSrcweir 892*cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); 893*cdf0e10cSrcweir 894*cdf0e10cSrcweir uno::Reference< ucb::XContent > xThis = this; 895*cdf0e10cSrcweir 896*cdf0e10cSrcweir // Already persistent? 897*cdf0e10cSrcweir if ( m_eState != PERSISTENT ) 898*cdf0e10cSrcweir { 899*cdf0e10cSrcweir OSL_ENSURE( sal_False, 900*cdf0e10cSrcweir "Content::exchangeIdentity - Not persistent!" ); 901*cdf0e10cSrcweir return sal_False; 902*cdf0e10cSrcweir } 903*cdf0e10cSrcweir 904*cdf0e10cSrcweir // Only folders and streams can be renamed -> exchange identity. 905*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 906*cdf0e10cSrcweir if ( ( eType == ROOT ) || ( eType == DOCUMENT ) ) 907*cdf0e10cSrcweir { 908*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Content::exchangeIdentity - " 909*cdf0e10cSrcweir "Not supported by root or document!" ); 910*cdf0e10cSrcweir return sal_False; 911*cdf0e10cSrcweir } 912*cdf0e10cSrcweir 913*cdf0e10cSrcweir // Exchange own identitity. 914*cdf0e10cSrcweir 915*cdf0e10cSrcweir // Fail, if a content with given id already exists. 916*cdf0e10cSrcweir if ( !hasData( Uri( xNewId->getContentIdentifier() ) ) ) 917*cdf0e10cSrcweir { 918*cdf0e10cSrcweir rtl::OUString aOldURL = m_xIdentifier->getContentIdentifier(); 919*cdf0e10cSrcweir 920*cdf0e10cSrcweir aGuard.clear(); 921*cdf0e10cSrcweir if ( exchange( xNewId ) ) 922*cdf0e10cSrcweir { 923*cdf0e10cSrcweir if ( eType == FOLDER ) 924*cdf0e10cSrcweir { 925*cdf0e10cSrcweir // Process instanciated children... 926*cdf0e10cSrcweir 927*cdf0e10cSrcweir ContentRefList aChildren; 928*cdf0e10cSrcweir queryChildren( aChildren ); 929*cdf0e10cSrcweir 930*cdf0e10cSrcweir ContentRefList::const_iterator it = aChildren.begin(); 931*cdf0e10cSrcweir ContentRefList::const_iterator end = aChildren.end(); 932*cdf0e10cSrcweir 933*cdf0e10cSrcweir while ( it != end ) 934*cdf0e10cSrcweir { 935*cdf0e10cSrcweir ContentRef xChild = (*it); 936*cdf0e10cSrcweir 937*cdf0e10cSrcweir // Create new content identifier for the child... 938*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xOldChildId 939*cdf0e10cSrcweir = xChild->getIdentifier(); 940*cdf0e10cSrcweir rtl::OUString aOldChildURL 941*cdf0e10cSrcweir = xOldChildId->getContentIdentifier(); 942*cdf0e10cSrcweir rtl::OUString aNewChildURL 943*cdf0e10cSrcweir = aOldChildURL.replaceAt( 944*cdf0e10cSrcweir 0, 945*cdf0e10cSrcweir aOldURL.getLength(), 946*cdf0e10cSrcweir xNewId->getContentIdentifier() ); 947*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xNewChildId 948*cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( 949*cdf0e10cSrcweir m_xSMgr, aNewChildURL ); 950*cdf0e10cSrcweir 951*cdf0e10cSrcweir if ( !xChild->exchangeIdentity( xNewChildId ) ) 952*cdf0e10cSrcweir return sal_False; 953*cdf0e10cSrcweir 954*cdf0e10cSrcweir ++it; 955*cdf0e10cSrcweir } 956*cdf0e10cSrcweir } 957*cdf0e10cSrcweir return sal_True; 958*cdf0e10cSrcweir } 959*cdf0e10cSrcweir } 960*cdf0e10cSrcweir 961*cdf0e10cSrcweir OSL_ENSURE( sal_False, 962*cdf0e10cSrcweir "Content::exchangeIdentity - " 963*cdf0e10cSrcweir "Panic! Cannot exchange identity!" ); 964*cdf0e10cSrcweir return sal_False; 965*cdf0e10cSrcweir } 966*cdf0e10cSrcweir 967*cdf0e10cSrcweir //========================================================================= 968*cdf0e10cSrcweir // static 969*cdf0e10cSrcweir uno::Reference< sdbc::XRow > Content::getPropertyValues( 970*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rSMgr, 971*cdf0e10cSrcweir const uno::Sequence< beans::Property >& rProperties, 972*cdf0e10cSrcweir ContentProvider* pProvider, 973*cdf0e10cSrcweir const rtl::OUString& rContentId ) 974*cdf0e10cSrcweir { 975*cdf0e10cSrcweir ContentProperties aData; 976*cdf0e10cSrcweir if ( loadData( pProvider, rContentId, aData ) ) 977*cdf0e10cSrcweir { 978*cdf0e10cSrcweir return getPropertyValues( 979*cdf0e10cSrcweir rSMgr, rProperties, aData, pProvider, rContentId ); 980*cdf0e10cSrcweir } 981*cdf0e10cSrcweir else 982*cdf0e10cSrcweir { 983*cdf0e10cSrcweir rtl::Reference< ::ucbhelper::PropertyValueSet > xRow 984*cdf0e10cSrcweir = new ::ucbhelper::PropertyValueSet( rSMgr ); 985*cdf0e10cSrcweir 986*cdf0e10cSrcweir sal_Int32 nCount = rProperties.getLength(); 987*cdf0e10cSrcweir if ( nCount ) 988*cdf0e10cSrcweir { 989*cdf0e10cSrcweir const beans::Property* pProps = rProperties.getConstArray(); 990*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) 991*cdf0e10cSrcweir xRow->appendVoid( pProps[ n ] ); 992*cdf0e10cSrcweir } 993*cdf0e10cSrcweir 994*cdf0e10cSrcweir return uno::Reference< sdbc::XRow >( xRow.get() ); 995*cdf0e10cSrcweir } 996*cdf0e10cSrcweir } 997*cdf0e10cSrcweir 998*cdf0e10cSrcweir //========================================================================= 999*cdf0e10cSrcweir // static 1000*cdf0e10cSrcweir uno::Reference< sdbc::XRow > Content::getPropertyValues( 1001*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rSMgr, 1002*cdf0e10cSrcweir const uno::Sequence< beans::Property >& rProperties, 1003*cdf0e10cSrcweir const ContentProperties& rData, 1004*cdf0e10cSrcweir ContentProvider* pProvider, 1005*cdf0e10cSrcweir const rtl::OUString& rContentId ) 1006*cdf0e10cSrcweir { 1007*cdf0e10cSrcweir // Note: Empty sequence means "get values of all supported properties". 1008*cdf0e10cSrcweir 1009*cdf0e10cSrcweir rtl::Reference< ::ucbhelper::PropertyValueSet > xRow 1010*cdf0e10cSrcweir = new ::ucbhelper::PropertyValueSet( rSMgr ); 1011*cdf0e10cSrcweir 1012*cdf0e10cSrcweir sal_Int32 nCount = rProperties.getLength(); 1013*cdf0e10cSrcweir if ( nCount ) 1014*cdf0e10cSrcweir { 1015*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xAdditionalPropSet; 1016*cdf0e10cSrcweir sal_Bool bTriedToGetAdditonalPropSet = sal_False; 1017*cdf0e10cSrcweir 1018*cdf0e10cSrcweir const beans::Property* pProps = rProperties.getConstArray(); 1019*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) 1020*cdf0e10cSrcweir { 1021*cdf0e10cSrcweir const beans::Property& rProp = pProps[ n ]; 1022*cdf0e10cSrcweir 1023*cdf0e10cSrcweir // Process Core properties. 1024*cdf0e10cSrcweir 1025*cdf0e10cSrcweir if ( rProp.Name.equalsAsciiL( 1026*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) ) 1027*cdf0e10cSrcweir { 1028*cdf0e10cSrcweir xRow->appendString ( rProp, rData.getContentType() ); 1029*cdf0e10cSrcweir } 1030*cdf0e10cSrcweir else if ( rProp.Name.equalsAsciiL( 1031*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "Title" ) ) ) 1032*cdf0e10cSrcweir { 1033*cdf0e10cSrcweir xRow->appendString ( rProp, rData.getTitle() ); 1034*cdf0e10cSrcweir } 1035*cdf0e10cSrcweir else if ( rProp.Name.equalsAsciiL( 1036*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) ) 1037*cdf0e10cSrcweir { 1038*cdf0e10cSrcweir xRow->appendBoolean( rProp, rData.getIsDocument() ); 1039*cdf0e10cSrcweir } 1040*cdf0e10cSrcweir else if ( rProp.Name.equalsAsciiL( 1041*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) ) 1042*cdf0e10cSrcweir { 1043*cdf0e10cSrcweir xRow->appendBoolean( rProp, rData.getIsFolder() ); 1044*cdf0e10cSrcweir } 1045*cdf0e10cSrcweir else if ( rProp.Name.equalsAsciiL( 1046*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) ) 1047*cdf0e10cSrcweir { 1048*cdf0e10cSrcweir xRow->appendObject( 1049*cdf0e10cSrcweir rProp, uno::makeAny( rData.getCreatableContentsInfo() ) ); 1050*cdf0e10cSrcweir } 1051*cdf0e10cSrcweir else if ( rProp.Name.equalsAsciiL( 1052*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "Storage" ) ) ) 1053*cdf0e10cSrcweir { 1054*cdf0e10cSrcweir // Storage is only supported by folders. 1055*cdf0e10cSrcweir ContentType eType = rData.getType(); 1056*cdf0e10cSrcweir if ( eType == FOLDER ) 1057*cdf0e10cSrcweir xRow->appendObject( 1058*cdf0e10cSrcweir rProp, 1059*cdf0e10cSrcweir uno::makeAny( 1060*cdf0e10cSrcweir pProvider->queryStorageClone( rContentId ) ) ); 1061*cdf0e10cSrcweir else 1062*cdf0e10cSrcweir xRow->appendVoid( rProp ); 1063*cdf0e10cSrcweir } 1064*cdf0e10cSrcweir else if ( rProp.Name.equalsAsciiL( 1065*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "DocumentModel" ) ) ) 1066*cdf0e10cSrcweir { 1067*cdf0e10cSrcweir // DocumentModel is only supported by documents. 1068*cdf0e10cSrcweir ContentType eType = rData.getType(); 1069*cdf0e10cSrcweir if ( eType == DOCUMENT ) 1070*cdf0e10cSrcweir xRow->appendObject( 1071*cdf0e10cSrcweir rProp, 1072*cdf0e10cSrcweir uno::makeAny( 1073*cdf0e10cSrcweir pProvider->queryDocumentModel( rContentId ) ) ); 1074*cdf0e10cSrcweir else 1075*cdf0e10cSrcweir xRow->appendVoid( rProp ); 1076*cdf0e10cSrcweir } 1077*cdf0e10cSrcweir else 1078*cdf0e10cSrcweir { 1079*cdf0e10cSrcweir // Not a Core Property! Maybe it's an Additional Core Property?! 1080*cdf0e10cSrcweir 1081*cdf0e10cSrcweir if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() ) 1082*cdf0e10cSrcweir { 1083*cdf0e10cSrcweir xAdditionalPropSet 1084*cdf0e10cSrcweir = uno::Reference< beans::XPropertySet >( 1085*cdf0e10cSrcweir pProvider->getAdditionalPropertySet( rContentId, 1086*cdf0e10cSrcweir sal_False ), 1087*cdf0e10cSrcweir uno::UNO_QUERY ); 1088*cdf0e10cSrcweir bTriedToGetAdditonalPropSet = sal_True; 1089*cdf0e10cSrcweir } 1090*cdf0e10cSrcweir 1091*cdf0e10cSrcweir if ( xAdditionalPropSet.is() ) 1092*cdf0e10cSrcweir { 1093*cdf0e10cSrcweir if ( !xRow->appendPropertySetValue( 1094*cdf0e10cSrcweir xAdditionalPropSet, 1095*cdf0e10cSrcweir rProp ) ) 1096*cdf0e10cSrcweir { 1097*cdf0e10cSrcweir // Append empty entry. 1098*cdf0e10cSrcweir xRow->appendVoid( rProp ); 1099*cdf0e10cSrcweir } 1100*cdf0e10cSrcweir } 1101*cdf0e10cSrcweir else 1102*cdf0e10cSrcweir { 1103*cdf0e10cSrcweir // Append empty entry. 1104*cdf0e10cSrcweir xRow->appendVoid( rProp ); 1105*cdf0e10cSrcweir } 1106*cdf0e10cSrcweir } 1107*cdf0e10cSrcweir } 1108*cdf0e10cSrcweir } 1109*cdf0e10cSrcweir else 1110*cdf0e10cSrcweir { 1111*cdf0e10cSrcweir // Append all Core Properties. 1112*cdf0e10cSrcweir xRow->appendString ( 1113*cdf0e10cSrcweir beans::Property( rtl::OUString::createFromAscii( "ContentType" ), 1114*cdf0e10cSrcweir -1, 1115*cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 1116*cdf0e10cSrcweir beans::PropertyAttribute::BOUND 1117*cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ), 1118*cdf0e10cSrcweir rData.getContentType() ); 1119*cdf0e10cSrcweir 1120*cdf0e10cSrcweir ContentType eType = rData.getType(); 1121*cdf0e10cSrcweir 1122*cdf0e10cSrcweir xRow->appendString ( 1123*cdf0e10cSrcweir beans::Property( rtl::OUString::createFromAscii( "Title" ), 1124*cdf0e10cSrcweir -1, 1125*cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 1126*cdf0e10cSrcweir // Title is read-only for root and documents. 1127*cdf0e10cSrcweir beans::PropertyAttribute::BOUND || 1128*cdf0e10cSrcweir ( ( eType == ROOT ) || ( eType == DOCUMENT ) ) 1129*cdf0e10cSrcweir ? beans::PropertyAttribute::READONLY 1130*cdf0e10cSrcweir : 0 ), 1131*cdf0e10cSrcweir rData.getTitle() ); 1132*cdf0e10cSrcweir xRow->appendBoolean( 1133*cdf0e10cSrcweir beans::Property( rtl::OUString::createFromAscii( "IsDocument" ), 1134*cdf0e10cSrcweir -1, 1135*cdf0e10cSrcweir getCppuBooleanType(), 1136*cdf0e10cSrcweir beans::PropertyAttribute::BOUND 1137*cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ), 1138*cdf0e10cSrcweir rData.getIsDocument() ); 1139*cdf0e10cSrcweir xRow->appendBoolean( 1140*cdf0e10cSrcweir beans::Property( rtl::OUString::createFromAscii( "IsFolder" ), 1141*cdf0e10cSrcweir -1, 1142*cdf0e10cSrcweir getCppuBooleanType(), 1143*cdf0e10cSrcweir beans::PropertyAttribute::BOUND 1144*cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ), 1145*cdf0e10cSrcweir rData.getIsFolder() ); 1146*cdf0e10cSrcweir xRow->appendObject( 1147*cdf0e10cSrcweir beans::Property( 1148*cdf0e10cSrcweir rtl::OUString::createFromAscii( "CreatableContentsInfo" ), 1149*cdf0e10cSrcweir -1, 1150*cdf0e10cSrcweir getCppuType( static_cast< 1151*cdf0e10cSrcweir const uno::Sequence< ucb::ContentInfo > * >( 0 ) ), 1152*cdf0e10cSrcweir beans::PropertyAttribute::BOUND 1153*cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ), 1154*cdf0e10cSrcweir uno::makeAny( rData.getCreatableContentsInfo() ) ); 1155*cdf0e10cSrcweir 1156*cdf0e10cSrcweir // Storage is only supported by folders. 1157*cdf0e10cSrcweir if ( eType == FOLDER ) 1158*cdf0e10cSrcweir xRow->appendObject( 1159*cdf0e10cSrcweir beans::Property( rtl::OUString::createFromAscii( "Storage" ), 1160*cdf0e10cSrcweir -1, 1161*cdf0e10cSrcweir getCppuType( 1162*cdf0e10cSrcweir static_cast< 1163*cdf0e10cSrcweir const uno::Reference< embed::XStorage > * >( 0 ) ), 1164*cdf0e10cSrcweir beans::PropertyAttribute::BOUND 1165*cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ), 1166*cdf0e10cSrcweir uno::makeAny( pProvider->queryStorageClone( rContentId ) ) ); 1167*cdf0e10cSrcweir 1168*cdf0e10cSrcweir // DocumentModel is only supported by documents. 1169*cdf0e10cSrcweir if ( eType == DOCUMENT ) 1170*cdf0e10cSrcweir xRow->appendObject( 1171*cdf0e10cSrcweir beans::Property( rtl::OUString::createFromAscii( "DocumentModel" ), 1172*cdf0e10cSrcweir -1, 1173*cdf0e10cSrcweir getCppuType( 1174*cdf0e10cSrcweir static_cast< 1175*cdf0e10cSrcweir const uno::Reference< frame::XModel > * >( 0 ) ), 1176*cdf0e10cSrcweir beans::PropertyAttribute::BOUND 1177*cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ), 1178*cdf0e10cSrcweir uno::makeAny( 1179*cdf0e10cSrcweir pProvider->queryDocumentModel( rContentId ) ) ); 1180*cdf0e10cSrcweir 1181*cdf0e10cSrcweir // Append all Additional Core Properties. 1182*cdf0e10cSrcweir 1183*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xSet( 1184*cdf0e10cSrcweir pProvider->getAdditionalPropertySet( rContentId, sal_False ), 1185*cdf0e10cSrcweir uno::UNO_QUERY ); 1186*cdf0e10cSrcweir xRow->appendPropertySet( xSet ); 1187*cdf0e10cSrcweir } 1188*cdf0e10cSrcweir 1189*cdf0e10cSrcweir return uno::Reference< sdbc::XRow >( xRow.get() ); 1190*cdf0e10cSrcweir } 1191*cdf0e10cSrcweir 1192*cdf0e10cSrcweir //========================================================================= 1193*cdf0e10cSrcweir uno::Reference< sdbc::XRow > Content::getPropertyValues( 1194*cdf0e10cSrcweir const uno::Sequence< beans::Property >& rProperties ) 1195*cdf0e10cSrcweir { 1196*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1197*cdf0e10cSrcweir return getPropertyValues( m_xSMgr, 1198*cdf0e10cSrcweir rProperties, 1199*cdf0e10cSrcweir m_aProps, 1200*cdf0e10cSrcweir m_pProvider, 1201*cdf0e10cSrcweir m_xIdentifier->getContentIdentifier() ); 1202*cdf0e10cSrcweir } 1203*cdf0e10cSrcweir 1204*cdf0e10cSrcweir //========================================================================= 1205*cdf0e10cSrcweir uno::Sequence< uno::Any > Content::setPropertyValues( 1206*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& rValues, 1207*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 1208*cdf0e10cSrcweir throw( uno::Exception ) 1209*cdf0e10cSrcweir { 1210*cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); 1211*cdf0e10cSrcweir 1212*cdf0e10cSrcweir uno::Sequence< uno::Any > aRet( rValues.getLength() ); 1213*cdf0e10cSrcweir uno::Sequence< beans::PropertyChangeEvent > aChanges( rValues.getLength() ); 1214*cdf0e10cSrcweir sal_Int32 nChanged = 0; 1215*cdf0e10cSrcweir 1216*cdf0e10cSrcweir beans::PropertyChangeEvent aEvent; 1217*cdf0e10cSrcweir aEvent.Source = static_cast< cppu::OWeakObject * >( this ); 1218*cdf0e10cSrcweir aEvent.Further = sal_False; 1219*cdf0e10cSrcweir // aEvent.PropertyName = 1220*cdf0e10cSrcweir aEvent.PropertyHandle = -1; 1221*cdf0e10cSrcweir // aEvent.OldValue = 1222*cdf0e10cSrcweir // aEvent.NewValue = 1223*cdf0e10cSrcweir 1224*cdf0e10cSrcweir const beans::PropertyValue* pValues = rValues.getConstArray(); 1225*cdf0e10cSrcweir sal_Int32 nCount = rValues.getLength(); 1226*cdf0e10cSrcweir 1227*cdf0e10cSrcweir uno::Reference< ucb::XPersistentPropertySet > xAdditionalPropSet; 1228*cdf0e10cSrcweir sal_Bool bTriedToGetAdditonalPropSet = sal_False; 1229*cdf0e10cSrcweir 1230*cdf0e10cSrcweir sal_Bool bExchange = sal_False; 1231*cdf0e10cSrcweir rtl::OUString aOldTitle; 1232*cdf0e10cSrcweir sal_Int32 nTitlePos = -1; 1233*cdf0e10cSrcweir 1234*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) 1235*cdf0e10cSrcweir { 1236*cdf0e10cSrcweir const beans::PropertyValue& rValue = pValues[ n ]; 1237*cdf0e10cSrcweir 1238*cdf0e10cSrcweir if ( rValue.Name.equalsAsciiL( 1239*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) ) 1240*cdf0e10cSrcweir { 1241*cdf0e10cSrcweir // Read-only property! 1242*cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1243*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1244*cdf0e10cSrcweir "Property is read-only!" ), 1245*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1246*cdf0e10cSrcweir } 1247*cdf0e10cSrcweir else if ( rValue.Name.equalsAsciiL( 1248*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) ) 1249*cdf0e10cSrcweir { 1250*cdf0e10cSrcweir // Read-only property! 1251*cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1252*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1253*cdf0e10cSrcweir "Property is read-only!" ), 1254*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1255*cdf0e10cSrcweir } 1256*cdf0e10cSrcweir else if ( rValue.Name.equalsAsciiL( 1257*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) ) 1258*cdf0e10cSrcweir { 1259*cdf0e10cSrcweir // Read-only property! 1260*cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1261*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1262*cdf0e10cSrcweir "Property is read-only!" ), 1263*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1264*cdf0e10cSrcweir } 1265*cdf0e10cSrcweir else if ( rValue.Name.equalsAsciiL( 1266*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) ) 1267*cdf0e10cSrcweir { 1268*cdf0e10cSrcweir // Read-only property! 1269*cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1270*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1271*cdf0e10cSrcweir "Property is read-only!" ), 1272*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1273*cdf0e10cSrcweir } 1274*cdf0e10cSrcweir else if ( rValue.Name.equalsAsciiL( 1275*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "Title" ) ) ) 1276*cdf0e10cSrcweir { 1277*cdf0e10cSrcweir // Title is read-only for root and documents. 1278*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 1279*cdf0e10cSrcweir if ( ( eType == ROOT ) || ( eType == DOCUMENT ) ) 1280*cdf0e10cSrcweir { 1281*cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1282*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1283*cdf0e10cSrcweir "Property is read-only!" ), 1284*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1285*cdf0e10cSrcweir } 1286*cdf0e10cSrcweir else 1287*cdf0e10cSrcweir { 1288*cdf0e10cSrcweir rtl::OUString aNewValue; 1289*cdf0e10cSrcweir if ( rValue.Value >>= aNewValue ) 1290*cdf0e10cSrcweir { 1291*cdf0e10cSrcweir // No empty titles! 1292*cdf0e10cSrcweir if ( aNewValue.getLength() > 0 ) 1293*cdf0e10cSrcweir { 1294*cdf0e10cSrcweir if ( aNewValue != m_aProps.getTitle() ) 1295*cdf0e10cSrcweir { 1296*cdf0e10cSrcweir // modified title -> modified URL -> exchange ! 1297*cdf0e10cSrcweir if ( m_eState == PERSISTENT ) 1298*cdf0e10cSrcweir bExchange = sal_True; 1299*cdf0e10cSrcweir 1300*cdf0e10cSrcweir aOldTitle = m_aProps.getTitle(); 1301*cdf0e10cSrcweir m_aProps.setTitle( aNewValue ); 1302*cdf0e10cSrcweir 1303*cdf0e10cSrcweir // property change event will be sent later... 1304*cdf0e10cSrcweir 1305*cdf0e10cSrcweir // remember position within sequence of values 1306*cdf0e10cSrcweir // (for error handling). 1307*cdf0e10cSrcweir nTitlePos = n; 1308*cdf0e10cSrcweir } 1309*cdf0e10cSrcweir } 1310*cdf0e10cSrcweir else 1311*cdf0e10cSrcweir { 1312*cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalArgumentException( 1313*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1314*cdf0e10cSrcweir "Empty Title not allowed!" ), 1315*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 1316*cdf0e10cSrcweir -1 ); 1317*cdf0e10cSrcweir } 1318*cdf0e10cSrcweir } 1319*cdf0e10cSrcweir else 1320*cdf0e10cSrcweir { 1321*cdf0e10cSrcweir aRet[ n ] <<= beans::IllegalTypeException( 1322*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1323*cdf0e10cSrcweir "Title Property value has wrong type!" ), 1324*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1325*cdf0e10cSrcweir } 1326*cdf0e10cSrcweir } 1327*cdf0e10cSrcweir } 1328*cdf0e10cSrcweir else if ( rValue.Name.equalsAsciiL( 1329*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "Storage" ) ) ) 1330*cdf0e10cSrcweir { 1331*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 1332*cdf0e10cSrcweir if ( eType == FOLDER ) 1333*cdf0e10cSrcweir { 1334*cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1335*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1336*cdf0e10cSrcweir "Property is read-only!" ), 1337*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1338*cdf0e10cSrcweir } 1339*cdf0e10cSrcweir else 1340*cdf0e10cSrcweir { 1341*cdf0e10cSrcweir // Storage is only supported by folders. 1342*cdf0e10cSrcweir aRet[ n ] <<= beans::UnknownPropertyException( 1343*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1344*cdf0e10cSrcweir "Storage property only supported by folders" ), 1345*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1346*cdf0e10cSrcweir } 1347*cdf0e10cSrcweir } 1348*cdf0e10cSrcweir else if ( rValue.Name.equalsAsciiL( 1349*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "DocumentModel" ) ) ) 1350*cdf0e10cSrcweir { 1351*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 1352*cdf0e10cSrcweir if ( eType == DOCUMENT ) 1353*cdf0e10cSrcweir { 1354*cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException( 1355*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1356*cdf0e10cSrcweir "Property is read-only!" ), 1357*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1358*cdf0e10cSrcweir } 1359*cdf0e10cSrcweir else 1360*cdf0e10cSrcweir { 1361*cdf0e10cSrcweir // Storage is only supported by folders. 1362*cdf0e10cSrcweir aRet[ n ] <<= beans::UnknownPropertyException( 1363*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1364*cdf0e10cSrcweir "DocumentModel property only supported by " 1365*cdf0e10cSrcweir "documents" ), 1366*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1367*cdf0e10cSrcweir } 1368*cdf0e10cSrcweir } 1369*cdf0e10cSrcweir else 1370*cdf0e10cSrcweir { 1371*cdf0e10cSrcweir // Not a Core Property! Maybe it's an Additional Core Property?! 1372*cdf0e10cSrcweir 1373*cdf0e10cSrcweir if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() ) 1374*cdf0e10cSrcweir { 1375*cdf0e10cSrcweir xAdditionalPropSet = getAdditionalPropertySet( sal_False ); 1376*cdf0e10cSrcweir bTriedToGetAdditonalPropSet = sal_True; 1377*cdf0e10cSrcweir } 1378*cdf0e10cSrcweir 1379*cdf0e10cSrcweir if ( xAdditionalPropSet.is() ) 1380*cdf0e10cSrcweir { 1381*cdf0e10cSrcweir try 1382*cdf0e10cSrcweir { 1383*cdf0e10cSrcweir uno::Any aOldValue = xAdditionalPropSet->getPropertyValue( 1384*cdf0e10cSrcweir rValue.Name ); 1385*cdf0e10cSrcweir if ( aOldValue != rValue.Value ) 1386*cdf0e10cSrcweir { 1387*cdf0e10cSrcweir xAdditionalPropSet->setPropertyValue( 1388*cdf0e10cSrcweir rValue.Name, rValue.Value ); 1389*cdf0e10cSrcweir 1390*cdf0e10cSrcweir aEvent.PropertyName = rValue.Name; 1391*cdf0e10cSrcweir aEvent.OldValue = aOldValue; 1392*cdf0e10cSrcweir aEvent.NewValue = rValue.Value; 1393*cdf0e10cSrcweir 1394*cdf0e10cSrcweir aChanges.getArray()[ nChanged ] = aEvent; 1395*cdf0e10cSrcweir nChanged++; 1396*cdf0e10cSrcweir } 1397*cdf0e10cSrcweir } 1398*cdf0e10cSrcweir catch ( beans::UnknownPropertyException const & e ) 1399*cdf0e10cSrcweir { 1400*cdf0e10cSrcweir aRet[ n ] <<= e; 1401*cdf0e10cSrcweir } 1402*cdf0e10cSrcweir catch ( lang::WrappedTargetException const & e ) 1403*cdf0e10cSrcweir { 1404*cdf0e10cSrcweir aRet[ n ] <<= e; 1405*cdf0e10cSrcweir } 1406*cdf0e10cSrcweir catch ( beans::PropertyVetoException const & e ) 1407*cdf0e10cSrcweir { 1408*cdf0e10cSrcweir aRet[ n ] <<= e; 1409*cdf0e10cSrcweir } 1410*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & e ) 1411*cdf0e10cSrcweir { 1412*cdf0e10cSrcweir aRet[ n ] <<= e; 1413*cdf0e10cSrcweir } 1414*cdf0e10cSrcweir } 1415*cdf0e10cSrcweir else 1416*cdf0e10cSrcweir { 1417*cdf0e10cSrcweir aRet[ n ] <<= uno::Exception( 1418*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1419*cdf0e10cSrcweir "No property set for storing the value!" ), 1420*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1421*cdf0e10cSrcweir } 1422*cdf0e10cSrcweir } 1423*cdf0e10cSrcweir } 1424*cdf0e10cSrcweir 1425*cdf0e10cSrcweir if ( bExchange ) 1426*cdf0e10cSrcweir { 1427*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xOldId 1428*cdf0e10cSrcweir = m_xIdentifier; 1429*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xNewId 1430*cdf0e10cSrcweir = makeNewIdentifier( m_aProps.getTitle() ); 1431*cdf0e10cSrcweir 1432*cdf0e10cSrcweir aGuard.clear(); 1433*cdf0e10cSrcweir if ( exchangeIdentity( xNewId ) ) 1434*cdf0e10cSrcweir { 1435*cdf0e10cSrcweir // Adapt persistent data. 1436*cdf0e10cSrcweir renameData( xOldId, xNewId ); 1437*cdf0e10cSrcweir 1438*cdf0e10cSrcweir // Adapt Additional Core Properties. 1439*cdf0e10cSrcweir renameAdditionalPropertySet( xOldId->getContentIdentifier(), 1440*cdf0e10cSrcweir xNewId->getContentIdentifier(), 1441*cdf0e10cSrcweir sal_True ); 1442*cdf0e10cSrcweir } 1443*cdf0e10cSrcweir else 1444*cdf0e10cSrcweir { 1445*cdf0e10cSrcweir // Roll-back. 1446*cdf0e10cSrcweir m_aProps.setTitle( aOldTitle ); 1447*cdf0e10cSrcweir aOldTitle = rtl::OUString(); 1448*cdf0e10cSrcweir 1449*cdf0e10cSrcweir // Set error . 1450*cdf0e10cSrcweir aRet[ nTitlePos ] <<= uno::Exception( 1451*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Exchange failed!" ), 1452*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 1453*cdf0e10cSrcweir } 1454*cdf0e10cSrcweir } 1455*cdf0e10cSrcweir 1456*cdf0e10cSrcweir if ( aOldTitle.getLength() ) 1457*cdf0e10cSrcweir { 1458*cdf0e10cSrcweir aEvent.PropertyName = rtl::OUString::createFromAscii( "Title" ); 1459*cdf0e10cSrcweir aEvent.OldValue = uno::makeAny( aOldTitle ); 1460*cdf0e10cSrcweir aEvent.NewValue = uno::makeAny( m_aProps.getTitle() ); 1461*cdf0e10cSrcweir 1462*cdf0e10cSrcweir aChanges.getArray()[ nChanged ] = aEvent; 1463*cdf0e10cSrcweir nChanged++; 1464*cdf0e10cSrcweir } 1465*cdf0e10cSrcweir 1466*cdf0e10cSrcweir if ( nChanged > 0 ) 1467*cdf0e10cSrcweir { 1468*cdf0e10cSrcweir // Save changes, if content was already made persistent. 1469*cdf0e10cSrcweir if ( !bExchange && ( m_eState == PERSISTENT ) ) 1470*cdf0e10cSrcweir { 1471*cdf0e10cSrcweir if ( !storeData( uno::Reference< io::XInputStream >(), xEnv ) ) 1472*cdf0e10cSrcweir { 1473*cdf0e10cSrcweir uno::Any aProps 1474*cdf0e10cSrcweir = uno::makeAny( 1475*cdf0e10cSrcweir beans::PropertyValue( 1476*cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 1477*cdf0e10cSrcweir "Uri")), 1478*cdf0e10cSrcweir -1, 1479*cdf0e10cSrcweir uno::makeAny(m_xIdentifier-> 1480*cdf0e10cSrcweir getContentIdentifier()), 1481*cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE)); 1482*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1483*cdf0e10cSrcweir ucb::IOErrorCode_CANT_WRITE, 1484*cdf0e10cSrcweir uno::Sequence< uno::Any >(&aProps, 1), 1485*cdf0e10cSrcweir xEnv, 1486*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1487*cdf0e10cSrcweir "Cannot store persistent data!" ), 1488*cdf0e10cSrcweir this ); 1489*cdf0e10cSrcweir // Unreachable 1490*cdf0e10cSrcweir } 1491*cdf0e10cSrcweir } 1492*cdf0e10cSrcweir 1493*cdf0e10cSrcweir aChanges.realloc( nChanged ); 1494*cdf0e10cSrcweir 1495*cdf0e10cSrcweir aGuard.clear(); 1496*cdf0e10cSrcweir notifyPropertiesChange( aChanges ); 1497*cdf0e10cSrcweir } 1498*cdf0e10cSrcweir 1499*cdf0e10cSrcweir return aRet; 1500*cdf0e10cSrcweir } 1501*cdf0e10cSrcweir 1502*cdf0e10cSrcweir //========================================================================= 1503*cdf0e10cSrcweir uno::Any Content::open( 1504*cdf0e10cSrcweir const ucb::OpenCommandArgument2& rArg, 1505*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv ) 1506*cdf0e10cSrcweir throw( uno::Exception ) 1507*cdf0e10cSrcweir { 1508*cdf0e10cSrcweir if ( rArg.Mode == ucb::OpenMode::ALL || 1509*cdf0e10cSrcweir rArg.Mode == ucb::OpenMode::FOLDERS || 1510*cdf0e10cSrcweir rArg.Mode == ucb::OpenMode::DOCUMENTS ) 1511*cdf0e10cSrcweir { 1512*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 1513*cdf0e10cSrcweir // open command for a folder content 1514*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 1515*cdf0e10cSrcweir 1516*cdf0e10cSrcweir uno::Reference< ucb::XDynamicResultSet > xSet 1517*cdf0e10cSrcweir = new DynamicResultSet( m_xSMgr, this, rArg ); 1518*cdf0e10cSrcweir return uno::makeAny( xSet ); 1519*cdf0e10cSrcweir } 1520*cdf0e10cSrcweir else 1521*cdf0e10cSrcweir { 1522*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 1523*cdf0e10cSrcweir // open command for a document content 1524*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 1525*cdf0e10cSrcweir 1526*cdf0e10cSrcweir if ( ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) || 1527*cdf0e10cSrcweir ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE ) ) 1528*cdf0e10cSrcweir { 1529*cdf0e10cSrcweir // Currently(?) unsupported. 1530*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1531*cdf0e10cSrcweir uno::makeAny( ucb::UnsupportedOpenModeException( 1532*cdf0e10cSrcweir rtl::OUString(), 1533*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 1534*cdf0e10cSrcweir sal_Int16( rArg.Mode ) ) ), 1535*cdf0e10cSrcweir xEnv ); 1536*cdf0e10cSrcweir // Unreachable 1537*cdf0e10cSrcweir } 1538*cdf0e10cSrcweir 1539*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1540*cdf0e10cSrcweir 1541*cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier(); 1542*cdf0e10cSrcweir 1543*cdf0e10cSrcweir uno::Reference< io::XActiveDataStreamer > xDataStreamer( 1544*cdf0e10cSrcweir rArg.Sink, uno::UNO_QUERY ); 1545*cdf0e10cSrcweir if ( xDataStreamer.is() ) 1546*cdf0e10cSrcweir { 1547*cdf0e10cSrcweir // May throw CommandFailedException, DocumentPasswordRequest! 1548*cdf0e10cSrcweir uno::Reference< io::XStream > xStream = getStream( xEnv ); 1549*cdf0e10cSrcweir if ( !xStream.is() ) 1550*cdf0e10cSrcweir { 1551*cdf0e10cSrcweir // No interaction if we are not persistent! 1552*cdf0e10cSrcweir uno::Any aProps 1553*cdf0e10cSrcweir = uno::makeAny( 1554*cdf0e10cSrcweir beans::PropertyValue( 1555*cdf0e10cSrcweir rtl::OUString( 1556*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("Uri")), 1557*cdf0e10cSrcweir -1, 1558*cdf0e10cSrcweir uno::makeAny(m_xIdentifier-> 1559*cdf0e10cSrcweir getContentIdentifier()), 1560*cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE)); 1561*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1562*cdf0e10cSrcweir ucb::IOErrorCode_CANT_READ, 1563*cdf0e10cSrcweir uno::Sequence< uno::Any >(&aProps, 1), 1564*cdf0e10cSrcweir m_eState == PERSISTENT 1565*cdf0e10cSrcweir ? xEnv 1566*cdf0e10cSrcweir : uno::Reference< ucb::XCommandEnvironment >(), 1567*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1568*cdf0e10cSrcweir "Got no data stream!" ), 1569*cdf0e10cSrcweir this ); 1570*cdf0e10cSrcweir // Unreachable 1571*cdf0e10cSrcweir } 1572*cdf0e10cSrcweir 1573*cdf0e10cSrcweir // Done. 1574*cdf0e10cSrcweir xDataStreamer->setStream( xStream ); 1575*cdf0e10cSrcweir } 1576*cdf0e10cSrcweir else 1577*cdf0e10cSrcweir { 1578*cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOut( rArg.Sink, uno::UNO_QUERY ); 1579*cdf0e10cSrcweir if ( xOut.is() ) 1580*cdf0e10cSrcweir { 1581*cdf0e10cSrcweir // PUSH: write data into xOut 1582*cdf0e10cSrcweir 1583*cdf0e10cSrcweir // May throw CommandFailedException, DocumentPasswordRequest! 1584*cdf0e10cSrcweir uno::Reference< io::XInputStream > xIn = getInputStream( xEnv ); 1585*cdf0e10cSrcweir if ( !xIn.is() ) 1586*cdf0e10cSrcweir { 1587*cdf0e10cSrcweir // No interaction if we are not persistent! 1588*cdf0e10cSrcweir uno::Any aProps 1589*cdf0e10cSrcweir = uno::makeAny( 1590*cdf0e10cSrcweir beans::PropertyValue( 1591*cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 1592*cdf0e10cSrcweir "Uri")), 1593*cdf0e10cSrcweir -1, 1594*cdf0e10cSrcweir uno::makeAny(m_xIdentifier-> 1595*cdf0e10cSrcweir getContentIdentifier()), 1596*cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE)); 1597*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1598*cdf0e10cSrcweir ucb::IOErrorCode_CANT_READ, 1599*cdf0e10cSrcweir uno::Sequence< uno::Any >(&aProps, 1), 1600*cdf0e10cSrcweir m_eState == PERSISTENT 1601*cdf0e10cSrcweir ? xEnv 1602*cdf0e10cSrcweir : uno::Reference< ucb::XCommandEnvironment >(), 1603*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Got no data stream!" ), 1604*cdf0e10cSrcweir this ); 1605*cdf0e10cSrcweir // Unreachable 1606*cdf0e10cSrcweir } 1607*cdf0e10cSrcweir 1608*cdf0e10cSrcweir try 1609*cdf0e10cSrcweir { 1610*cdf0e10cSrcweir uno::Sequence< sal_Int8 > aBuffer; 1611*cdf0e10cSrcweir sal_Int32 nRead = xIn->readSomeBytes( aBuffer, 65536 ); 1612*cdf0e10cSrcweir 1613*cdf0e10cSrcweir while ( nRead > 0 ) 1614*cdf0e10cSrcweir { 1615*cdf0e10cSrcweir aBuffer.realloc( nRead ); 1616*cdf0e10cSrcweir xOut->writeBytes( aBuffer ); 1617*cdf0e10cSrcweir aBuffer.realloc( 0 ); 1618*cdf0e10cSrcweir nRead = xIn->readSomeBytes( aBuffer, 65536 ); 1619*cdf0e10cSrcweir } 1620*cdf0e10cSrcweir 1621*cdf0e10cSrcweir xOut->closeOutput(); 1622*cdf0e10cSrcweir } 1623*cdf0e10cSrcweir catch ( io::NotConnectedException const & ) 1624*cdf0e10cSrcweir { 1625*cdf0e10cSrcweir // closeOutput, readSomeBytes, writeBytes 1626*cdf0e10cSrcweir } 1627*cdf0e10cSrcweir catch ( io::BufferSizeExceededException const & ) 1628*cdf0e10cSrcweir { 1629*cdf0e10cSrcweir // closeOutput, readSomeBytes, writeBytes 1630*cdf0e10cSrcweir } 1631*cdf0e10cSrcweir catch ( io::IOException const & ) 1632*cdf0e10cSrcweir { 1633*cdf0e10cSrcweir // closeOutput, readSomeBytes, writeBytes 1634*cdf0e10cSrcweir } 1635*cdf0e10cSrcweir } 1636*cdf0e10cSrcweir else 1637*cdf0e10cSrcweir { 1638*cdf0e10cSrcweir uno::Reference< io::XActiveDataSink > xDataSink( 1639*cdf0e10cSrcweir rArg.Sink, uno::UNO_QUERY ); 1640*cdf0e10cSrcweir if ( xDataSink.is() ) 1641*cdf0e10cSrcweir { 1642*cdf0e10cSrcweir // PULL: wait for client read 1643*cdf0e10cSrcweir 1644*cdf0e10cSrcweir // May throw CommandFailedException, DocumentPasswordRequest! 1645*cdf0e10cSrcweir uno::Reference< io::XInputStream > xIn = getInputStream( xEnv ); 1646*cdf0e10cSrcweir if ( !xIn.is() ) 1647*cdf0e10cSrcweir { 1648*cdf0e10cSrcweir // No interaction if we are not persistent! 1649*cdf0e10cSrcweir uno::Any aProps 1650*cdf0e10cSrcweir = uno::makeAny( 1651*cdf0e10cSrcweir beans::PropertyValue( 1652*cdf0e10cSrcweir rtl::OUString( 1653*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("Uri")), 1654*cdf0e10cSrcweir -1, 1655*cdf0e10cSrcweir uno::makeAny(m_xIdentifier-> 1656*cdf0e10cSrcweir getContentIdentifier()), 1657*cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE)); 1658*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1659*cdf0e10cSrcweir ucb::IOErrorCode_CANT_READ, 1660*cdf0e10cSrcweir uno::Sequence< uno::Any >(&aProps, 1), 1661*cdf0e10cSrcweir m_eState == PERSISTENT 1662*cdf0e10cSrcweir ? xEnv 1663*cdf0e10cSrcweir : uno::Reference< 1664*cdf0e10cSrcweir ucb::XCommandEnvironment >(), 1665*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1666*cdf0e10cSrcweir "Got no data stream!" ), 1667*cdf0e10cSrcweir this ); 1668*cdf0e10cSrcweir // Unreachable 1669*cdf0e10cSrcweir } 1670*cdf0e10cSrcweir 1671*cdf0e10cSrcweir // Done. 1672*cdf0e10cSrcweir xDataSink->setInputStream( xIn ); 1673*cdf0e10cSrcweir } 1674*cdf0e10cSrcweir else 1675*cdf0e10cSrcweir { 1676*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1677*cdf0e10cSrcweir uno::makeAny( 1678*cdf0e10cSrcweir ucb::UnsupportedDataSinkException( 1679*cdf0e10cSrcweir rtl::OUString(), 1680*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 1681*cdf0e10cSrcweir rArg.Sink ) ), 1682*cdf0e10cSrcweir xEnv ); 1683*cdf0e10cSrcweir // Unreachable 1684*cdf0e10cSrcweir } 1685*cdf0e10cSrcweir } 1686*cdf0e10cSrcweir } 1687*cdf0e10cSrcweir } 1688*cdf0e10cSrcweir 1689*cdf0e10cSrcweir return uno::Any(); 1690*cdf0e10cSrcweir } 1691*cdf0e10cSrcweir 1692*cdf0e10cSrcweir //========================================================================= 1693*cdf0e10cSrcweir void Content::insert( const uno::Reference< io::XInputStream >& xData, 1694*cdf0e10cSrcweir sal_Int32 nNameClashResolve, 1695*cdf0e10cSrcweir const uno::Reference< 1696*cdf0e10cSrcweir ucb::XCommandEnvironment > & xEnv ) 1697*cdf0e10cSrcweir throw( uno::Exception ) 1698*cdf0e10cSrcweir { 1699*cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); 1700*cdf0e10cSrcweir 1701*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 1702*cdf0e10cSrcweir 1703*cdf0e10cSrcweir OSL_ENSURE( ( eType == FOLDER ) || ( eType == STREAM ), 1704*cdf0e10cSrcweir "insert command only supported by streams and folders!" ); 1705*cdf0e10cSrcweir 1706*cdf0e10cSrcweir Uri aUri( m_xIdentifier->getContentIdentifier() ); 1707*cdf0e10cSrcweir 1708*cdf0e10cSrcweir #ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 1709*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 1710*cdf0e10cSrcweir if ( eType == STREAM ) 1711*cdf0e10cSrcweir { 1712*cdf0e10cSrcweir Uri aParentUri( aUri.getParentUri() ); 1713*cdf0e10cSrcweir OSL_ENSURE( !aParentUri.isDocument(), 1714*cdf0e10cSrcweir "insert command not supported by streams that are direct " 1715*cdf0e10cSrcweir "children of document root!" ); 1716*cdf0e10cSrcweir } 1717*cdf0e10cSrcweir #endif 1718*cdf0e10cSrcweir #endif 1719*cdf0e10cSrcweir 1720*cdf0e10cSrcweir // Check, if all required properties were set. 1721*cdf0e10cSrcweir if ( eType == FOLDER ) 1722*cdf0e10cSrcweir { 1723*cdf0e10cSrcweir // Required: Title 1724*cdf0e10cSrcweir 1725*cdf0e10cSrcweir if ( m_aProps.getTitle().getLength() == 0 ) 1726*cdf0e10cSrcweir m_aProps.setTitle( aUri.getDecodedName() ); 1727*cdf0e10cSrcweir } 1728*cdf0e10cSrcweir else // stream 1729*cdf0e10cSrcweir { 1730*cdf0e10cSrcweir // Required: data 1731*cdf0e10cSrcweir 1732*cdf0e10cSrcweir if ( !xData.is() ) 1733*cdf0e10cSrcweir { 1734*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1735*cdf0e10cSrcweir uno::makeAny( ucb::MissingInputStreamException( 1736*cdf0e10cSrcweir rtl::OUString(), 1737*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ), 1738*cdf0e10cSrcweir xEnv ); 1739*cdf0e10cSrcweir // Unreachable 1740*cdf0e10cSrcweir } 1741*cdf0e10cSrcweir 1742*cdf0e10cSrcweir // Required: Title 1743*cdf0e10cSrcweir 1744*cdf0e10cSrcweir if ( m_aProps.getTitle().getLength() == 0 ) 1745*cdf0e10cSrcweir m_aProps.setTitle( aUri.getDecodedName() ); 1746*cdf0e10cSrcweir } 1747*cdf0e10cSrcweir 1748*cdf0e10cSrcweir rtl::OUStringBuffer aNewURL = aUri.getParentUri(); 1749*cdf0e10cSrcweir aNewURL.append( m_aProps.getTitle() ); 1750*cdf0e10cSrcweir Uri aNewUri( aNewURL.makeStringAndClear() ); 1751*cdf0e10cSrcweir 1752*cdf0e10cSrcweir // Handle possible name clash... 1753*cdf0e10cSrcweir switch ( nNameClashResolve ) 1754*cdf0e10cSrcweir { 1755*cdf0e10cSrcweir // fail. 1756*cdf0e10cSrcweir case ucb::NameClash::ERROR: 1757*cdf0e10cSrcweir if ( hasData( aNewUri ) ) 1758*cdf0e10cSrcweir { 1759*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1760*cdf0e10cSrcweir uno::makeAny( ucb::NameClashException( 1761*cdf0e10cSrcweir rtl::OUString(), 1762*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 1763*cdf0e10cSrcweir task::InteractionClassification_ERROR, 1764*cdf0e10cSrcweir m_aProps.getTitle() ) ), 1765*cdf0e10cSrcweir xEnv ); 1766*cdf0e10cSrcweir // Unreachable 1767*cdf0e10cSrcweir } 1768*cdf0e10cSrcweir break; 1769*cdf0e10cSrcweir 1770*cdf0e10cSrcweir // replace (possibly) existing object. 1771*cdf0e10cSrcweir case ucb::NameClash::OVERWRITE: 1772*cdf0e10cSrcweir break; 1773*cdf0e10cSrcweir 1774*cdf0e10cSrcweir // "invent" a new valid title. 1775*cdf0e10cSrcweir case ucb::NameClash::RENAME: 1776*cdf0e10cSrcweir if ( hasData( aNewUri ) ) 1777*cdf0e10cSrcweir { 1778*cdf0e10cSrcweir sal_Int32 nTry = 0; 1779*cdf0e10cSrcweir 1780*cdf0e10cSrcweir do 1781*cdf0e10cSrcweir { 1782*cdf0e10cSrcweir rtl::OUStringBuffer aNew = aNewUri.getUri(); 1783*cdf0e10cSrcweir aNew.appendAscii( "_" ); 1784*cdf0e10cSrcweir aNew.append( rtl::OUString::valueOf( ++nTry ) ); 1785*cdf0e10cSrcweir aNewUri.setUri( aNew.makeStringAndClear() ); 1786*cdf0e10cSrcweir } 1787*cdf0e10cSrcweir while ( hasData( aNewUri ) && ( nTry < 1000 ) ); 1788*cdf0e10cSrcweir 1789*cdf0e10cSrcweir if ( nTry == 1000 ) 1790*cdf0e10cSrcweir { 1791*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1792*cdf0e10cSrcweir uno::makeAny( 1793*cdf0e10cSrcweir ucb::UnsupportedNameClashException( 1794*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1795*cdf0e10cSrcweir "Unable to resolve name clash!" ), 1796*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 1797*cdf0e10cSrcweir nNameClashResolve ) ), 1798*cdf0e10cSrcweir xEnv ); 1799*cdf0e10cSrcweir // Unreachable 1800*cdf0e10cSrcweir } 1801*cdf0e10cSrcweir else 1802*cdf0e10cSrcweir { 1803*cdf0e10cSrcweir rtl::OUStringBuffer aNewTitle = m_aProps.getTitle(); 1804*cdf0e10cSrcweir aNewTitle.appendAscii( "_" ); 1805*cdf0e10cSrcweir aNewTitle.append( rtl::OUString::valueOf( ++nTry ) ); 1806*cdf0e10cSrcweir m_aProps.setTitle( aNewTitle.makeStringAndClear() ); 1807*cdf0e10cSrcweir } 1808*cdf0e10cSrcweir } 1809*cdf0e10cSrcweir break; 1810*cdf0e10cSrcweir 1811*cdf0e10cSrcweir case ucb::NameClash::KEEP: // deprecated 1812*cdf0e10cSrcweir case ucb::NameClash::ASK: 1813*cdf0e10cSrcweir default: 1814*cdf0e10cSrcweir if ( hasData( aNewUri ) ) 1815*cdf0e10cSrcweir { 1816*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1817*cdf0e10cSrcweir uno::makeAny( 1818*cdf0e10cSrcweir ucb::UnsupportedNameClashException( 1819*cdf0e10cSrcweir rtl::OUString(), 1820*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 1821*cdf0e10cSrcweir nNameClashResolve ) ), 1822*cdf0e10cSrcweir xEnv ); 1823*cdf0e10cSrcweir // Unreachable 1824*cdf0e10cSrcweir } 1825*cdf0e10cSrcweir break; 1826*cdf0e10cSrcweir } 1827*cdf0e10cSrcweir 1828*cdf0e10cSrcweir // Identifier changed? 1829*cdf0e10cSrcweir sal_Bool bNewId = ( aUri != aNewUri ); 1830*cdf0e10cSrcweir 1831*cdf0e10cSrcweir if ( bNewId ) 1832*cdf0e10cSrcweir { 1833*cdf0e10cSrcweir m_xIdentifier 1834*cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( m_xSMgr, aNewUri.getUri() ); 1835*cdf0e10cSrcweir } 1836*cdf0e10cSrcweir 1837*cdf0e10cSrcweir if ( !storeData( xData, xEnv ) ) 1838*cdf0e10cSrcweir { 1839*cdf0e10cSrcweir uno::Any aProps 1840*cdf0e10cSrcweir = uno::makeAny(beans::PropertyValue( 1841*cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 1842*cdf0e10cSrcweir "Uri")), 1843*cdf0e10cSrcweir -1, 1844*cdf0e10cSrcweir uno::makeAny(m_xIdentifier-> 1845*cdf0e10cSrcweir getContentIdentifier()), 1846*cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE)); 1847*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1848*cdf0e10cSrcweir ucb::IOErrorCode_CANT_WRITE, 1849*cdf0e10cSrcweir uno::Sequence< uno::Any >(&aProps, 1), 1850*cdf0e10cSrcweir xEnv, 1851*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Cannot store persistent data!" ), 1852*cdf0e10cSrcweir this ); 1853*cdf0e10cSrcweir // Unreachable 1854*cdf0e10cSrcweir } 1855*cdf0e10cSrcweir 1856*cdf0e10cSrcweir m_eState = PERSISTENT; 1857*cdf0e10cSrcweir 1858*cdf0e10cSrcweir if ( bNewId ) 1859*cdf0e10cSrcweir { 1860*cdf0e10cSrcweir //loadData( m_pProvider, m_aUri, m_aProps ); 1861*cdf0e10cSrcweir 1862*cdf0e10cSrcweir aGuard.clear(); 1863*cdf0e10cSrcweir inserted(); 1864*cdf0e10cSrcweir } 1865*cdf0e10cSrcweir } 1866*cdf0e10cSrcweir 1867*cdf0e10cSrcweir //========================================================================= 1868*cdf0e10cSrcweir void Content::destroy( sal_Bool bDeletePhysical, 1869*cdf0e10cSrcweir const uno::Reference< 1870*cdf0e10cSrcweir ucb::XCommandEnvironment > & xEnv ) 1871*cdf0e10cSrcweir throw( uno::Exception ) 1872*cdf0e10cSrcweir { 1873*cdf0e10cSrcweir // @@@ take care about bDeletePhysical -> trashcan support 1874*cdf0e10cSrcweir 1875*cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); 1876*cdf0e10cSrcweir 1877*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 1878*cdf0e10cSrcweir 1879*cdf0e10cSrcweir OSL_ENSURE( ( eType == FOLDER ) || ( eType == STREAM ), 1880*cdf0e10cSrcweir "delete command only supported by streams and folders!" ); 1881*cdf0e10cSrcweir 1882*cdf0e10cSrcweir uno::Reference< ucb::XContent > xThis = this; 1883*cdf0e10cSrcweir 1884*cdf0e10cSrcweir // Persistent? 1885*cdf0e10cSrcweir if ( m_eState != PERSISTENT ) 1886*cdf0e10cSrcweir { 1887*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 1888*cdf0e10cSrcweir uno::makeAny( ucb::UnsupportedCommandException( 1889*cdf0e10cSrcweir rtl::OUString::createFromAscii( 1890*cdf0e10cSrcweir "Not persistent!" ), 1891*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ), 1892*cdf0e10cSrcweir xEnv ); 1893*cdf0e10cSrcweir // Unreachable 1894*cdf0e10cSrcweir } 1895*cdf0e10cSrcweir 1896*cdf0e10cSrcweir m_eState = DEAD; 1897*cdf0e10cSrcweir 1898*cdf0e10cSrcweir aGuard.clear(); 1899*cdf0e10cSrcweir deleted(); 1900*cdf0e10cSrcweir 1901*cdf0e10cSrcweir if ( eType == FOLDER ) 1902*cdf0e10cSrcweir { 1903*cdf0e10cSrcweir // Process instanciated children... 1904*cdf0e10cSrcweir 1905*cdf0e10cSrcweir ContentRefList aChildren; 1906*cdf0e10cSrcweir queryChildren( aChildren ); 1907*cdf0e10cSrcweir 1908*cdf0e10cSrcweir ContentRefList::const_iterator it = aChildren.begin(); 1909*cdf0e10cSrcweir ContentRefList::const_iterator end = aChildren.end(); 1910*cdf0e10cSrcweir 1911*cdf0e10cSrcweir while ( it != end ) 1912*cdf0e10cSrcweir { 1913*cdf0e10cSrcweir (*it)->destroy( bDeletePhysical, xEnv ); 1914*cdf0e10cSrcweir ++it; 1915*cdf0e10cSrcweir } 1916*cdf0e10cSrcweir } 1917*cdf0e10cSrcweir } 1918*cdf0e10cSrcweir 1919*cdf0e10cSrcweir //========================================================================= 1920*cdf0e10cSrcweir void Content::notifyDocumentClosed() 1921*cdf0e10cSrcweir { 1922*cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); 1923*cdf0e10cSrcweir 1924*cdf0e10cSrcweir m_eState = DEAD; 1925*cdf0e10cSrcweir 1926*cdf0e10cSrcweir // @@@ anything else to reset or such? 1927*cdf0e10cSrcweir 1928*cdf0e10cSrcweir // callback follows! 1929*cdf0e10cSrcweir aGuard.clear(); 1930*cdf0e10cSrcweir 1931*cdf0e10cSrcweir // Propagate destruction to content event listeners 1932*cdf0e10cSrcweir // Remove this from provider's content list. 1933*cdf0e10cSrcweir deleted(); 1934*cdf0e10cSrcweir } 1935*cdf0e10cSrcweir 1936*cdf0e10cSrcweir //========================================================================= 1937*cdf0e10cSrcweir uno::Reference< ucb::XContent > 1938*cdf0e10cSrcweir Content::queryChildContent( const rtl::OUString & rRelativeChildUri ) 1939*cdf0e10cSrcweir { 1940*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1941*cdf0e10cSrcweir 1942*cdf0e10cSrcweir const rtl::OUString aMyId = getIdentifier()->getContentIdentifier(); 1943*cdf0e10cSrcweir rtl::OUStringBuffer aBuf( aMyId ); 1944*cdf0e10cSrcweir if ( aMyId.getStr()[ aMyId.getLength() - 1 ] != sal_Unicode( '/' ) ) 1945*cdf0e10cSrcweir aBuf.appendAscii( "/" ); 1946*cdf0e10cSrcweir if ( rRelativeChildUri.getStr()[ 0 ] != sal_Unicode( '/' ) ) 1947*cdf0e10cSrcweir aBuf.append( rRelativeChildUri ); 1948*cdf0e10cSrcweir else 1949*cdf0e10cSrcweir aBuf.append( rRelativeChildUri.copy( 1 ) ); 1950*cdf0e10cSrcweir 1951*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xChildId 1952*cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( 1953*cdf0e10cSrcweir m_xSMgr, aBuf.makeStringAndClear() ); 1954*cdf0e10cSrcweir 1955*cdf0e10cSrcweir uno::Reference< ucb::XContent > xChild; 1956*cdf0e10cSrcweir try 1957*cdf0e10cSrcweir { 1958*cdf0e10cSrcweir xChild = m_pProvider->queryContent( xChildId ); 1959*cdf0e10cSrcweir } 1960*cdf0e10cSrcweir catch ( ucb::IllegalIdentifierException const & ) 1961*cdf0e10cSrcweir { 1962*cdf0e10cSrcweir // handled below. 1963*cdf0e10cSrcweir } 1964*cdf0e10cSrcweir 1965*cdf0e10cSrcweir OSL_ENSURE( xChild.is(), 1966*cdf0e10cSrcweir "Content::queryChildContent - unable to create child content!" ); 1967*cdf0e10cSrcweir return xChild; 1968*cdf0e10cSrcweir } 1969*cdf0e10cSrcweir 1970*cdf0e10cSrcweir //========================================================================= 1971*cdf0e10cSrcweir void Content::notifyChildRemoved( const rtl::OUString & rRelativeChildUri ) 1972*cdf0e10cSrcweir { 1973*cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); 1974*cdf0e10cSrcweir 1975*cdf0e10cSrcweir // Ugly! Need to create child content object, just to fill event properly. 1976*cdf0e10cSrcweir uno::Reference< ucb::XContent > xChild 1977*cdf0e10cSrcweir = queryChildContent( rRelativeChildUri ); 1978*cdf0e10cSrcweir 1979*cdf0e10cSrcweir if ( xChild.is() ) 1980*cdf0e10cSrcweir { 1981*cdf0e10cSrcweir // callback follows! 1982*cdf0e10cSrcweir aGuard.clear(); 1983*cdf0e10cSrcweir 1984*cdf0e10cSrcweir // Notify "REMOVED" event. 1985*cdf0e10cSrcweir ucb::ContentEvent aEvt( 1986*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 1987*cdf0e10cSrcweir ucb::ContentAction::REMOVED, 1988*cdf0e10cSrcweir xChild, 1989*cdf0e10cSrcweir getIdentifier() ); 1990*cdf0e10cSrcweir notifyContentEvent( aEvt ); 1991*cdf0e10cSrcweir } 1992*cdf0e10cSrcweir } 1993*cdf0e10cSrcweir 1994*cdf0e10cSrcweir //========================================================================= 1995*cdf0e10cSrcweir void Content::notifyChildInserted( const rtl::OUString & rRelativeChildUri ) 1996*cdf0e10cSrcweir { 1997*cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); 1998*cdf0e10cSrcweir 1999*cdf0e10cSrcweir // Ugly! Need to create child content object, just to fill event properly. 2000*cdf0e10cSrcweir uno::Reference< ucb::XContent > xChild 2001*cdf0e10cSrcweir = queryChildContent( rRelativeChildUri ); 2002*cdf0e10cSrcweir 2003*cdf0e10cSrcweir if ( xChild.is() ) 2004*cdf0e10cSrcweir { 2005*cdf0e10cSrcweir // callback follows! 2006*cdf0e10cSrcweir aGuard.clear(); 2007*cdf0e10cSrcweir 2008*cdf0e10cSrcweir // Notify "INSERTED" event. 2009*cdf0e10cSrcweir ucb::ContentEvent aEvt( 2010*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 2011*cdf0e10cSrcweir ucb::ContentAction::INSERTED, 2012*cdf0e10cSrcweir xChild, 2013*cdf0e10cSrcweir getIdentifier() ); 2014*cdf0e10cSrcweir notifyContentEvent( aEvt ); 2015*cdf0e10cSrcweir } 2016*cdf0e10cSrcweir } 2017*cdf0e10cSrcweir 2018*cdf0e10cSrcweir //========================================================================= 2019*cdf0e10cSrcweir void Content::transfer( 2020*cdf0e10cSrcweir const ucb::TransferInfo& rInfo, 2021*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 2022*cdf0e10cSrcweir throw( uno::Exception ) 2023*cdf0e10cSrcweir { 2024*cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); 2025*cdf0e10cSrcweir 2026*cdf0e10cSrcweir // Persistent? 2027*cdf0e10cSrcweir if ( m_eState != PERSISTENT ) 2028*cdf0e10cSrcweir { 2029*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2030*cdf0e10cSrcweir uno::makeAny( ucb::UnsupportedCommandException( 2031*cdf0e10cSrcweir rtl::OUString::createFromAscii( 2032*cdf0e10cSrcweir "Not persistent!" ), 2033*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ), 2034*cdf0e10cSrcweir xEnv ); 2035*cdf0e10cSrcweir // Unreachable 2036*cdf0e10cSrcweir } 2037*cdf0e10cSrcweir 2038*cdf0e10cSrcweir // Does source URI scheme match? Only vnd.sun.star.tdoc is supported. 2039*cdf0e10cSrcweir 2040*cdf0e10cSrcweir if ( ( rInfo.SourceURL.getLength() < TDOC_URL_SCHEME_LENGTH + 2 ) ) 2041*cdf0e10cSrcweir { 2042*cdf0e10cSrcweir // Invaild length (to short). 2043*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2044*cdf0e10cSrcweir uno::makeAny( ucb::InteractiveBadTransferURLException( 2045*cdf0e10cSrcweir rtl::OUString(), 2046*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ), 2047*cdf0e10cSrcweir xEnv ); 2048*cdf0e10cSrcweir // Unreachable 2049*cdf0e10cSrcweir } 2050*cdf0e10cSrcweir 2051*cdf0e10cSrcweir rtl::OUString aScheme 2052*cdf0e10cSrcweir = rInfo.SourceURL.copy( 0, TDOC_URL_SCHEME_LENGTH + 2 ) 2053*cdf0e10cSrcweir .toAsciiLowerCase(); 2054*cdf0e10cSrcweir if ( !aScheme.equalsAsciiL( 2055*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( TDOC_URL_SCHEME ":/" ) ) ) 2056*cdf0e10cSrcweir { 2057*cdf0e10cSrcweir // Invalid scheme. 2058*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2059*cdf0e10cSrcweir uno::makeAny( ucb::InteractiveBadTransferURLException( 2060*cdf0e10cSrcweir rtl::OUString(), 2061*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ), 2062*cdf0e10cSrcweir xEnv ); 2063*cdf0e10cSrcweir // Unreachable 2064*cdf0e10cSrcweir } 2065*cdf0e10cSrcweir 2066*cdf0e10cSrcweir // Does source URI describe a tdoc folder or stream? 2067*cdf0e10cSrcweir Uri aSourceUri( rInfo.SourceURL ); 2068*cdf0e10cSrcweir if ( !aSourceUri.isValid() ) 2069*cdf0e10cSrcweir { 2070*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2071*cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 2072*cdf0e10cSrcweir rtl::OUString::createFromAscii( 2073*cdf0e10cSrcweir "Invalid source URI! Syntax!" ), 2074*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 2075*cdf0e10cSrcweir -1 ) ), 2076*cdf0e10cSrcweir xEnv ); 2077*cdf0e10cSrcweir // Unreachable 2078*cdf0e10cSrcweir } 2079*cdf0e10cSrcweir 2080*cdf0e10cSrcweir if ( aSourceUri.isRoot() || aSourceUri.isDocument() ) 2081*cdf0e10cSrcweir { 2082*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2083*cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 2084*cdf0e10cSrcweir rtl::OUString::createFromAscii( 2085*cdf0e10cSrcweir "Invalid source URI! " 2086*cdf0e10cSrcweir "Must describe a folder or stream!" ), 2087*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 2088*cdf0e10cSrcweir -1 ) ), 2089*cdf0e10cSrcweir xEnv ); 2090*cdf0e10cSrcweir // Unreachable 2091*cdf0e10cSrcweir } 2092*cdf0e10cSrcweir 2093*cdf0e10cSrcweir // Is source not a parent of me / not me? 2094*cdf0e10cSrcweir rtl::OUString aId = m_xIdentifier->getContentIdentifier(); 2095*cdf0e10cSrcweir sal_Int32 nPos = aId.lastIndexOf( '/' ); 2096*cdf0e10cSrcweir if ( nPos != ( aId.getLength() - 1 ) ) 2097*cdf0e10cSrcweir { 2098*cdf0e10cSrcweir // No trailing slash found. Append. 2099*cdf0e10cSrcweir aId += rtl::OUString::createFromAscii( "/" ); 2100*cdf0e10cSrcweir } 2101*cdf0e10cSrcweir 2102*cdf0e10cSrcweir if ( rInfo.SourceURL.getLength() <= aId.getLength() ) 2103*cdf0e10cSrcweir { 2104*cdf0e10cSrcweir if ( aId.compareTo( 2105*cdf0e10cSrcweir rInfo.SourceURL, rInfo.SourceURL.getLength() ) == 0 ) 2106*cdf0e10cSrcweir { 2107*cdf0e10cSrcweir uno::Any aProps 2108*cdf0e10cSrcweir = uno::makeAny(beans::PropertyValue( 2109*cdf0e10cSrcweir rtl::OUString( 2110*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("Uri")), 2111*cdf0e10cSrcweir -1, 2112*cdf0e10cSrcweir uno::makeAny( rInfo.SourceURL ), 2113*cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE)); 2114*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2115*cdf0e10cSrcweir ucb::IOErrorCode_RECURSIVE, 2116*cdf0e10cSrcweir uno::Sequence< uno::Any >(&aProps, 1), 2117*cdf0e10cSrcweir xEnv, 2118*cdf0e10cSrcweir rtl::OUString::createFromAscii( 2119*cdf0e10cSrcweir "Target is equal to or is a child of source!" ), 2120*cdf0e10cSrcweir this ); 2121*cdf0e10cSrcweir // Unreachable 2122*cdf0e10cSrcweir } 2123*cdf0e10cSrcweir } 2124*cdf0e10cSrcweir 2125*cdf0e10cSrcweir #ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 2126*cdf0e10cSrcweir if ( m_aProps.getType() == DOCUMENT ) 2127*cdf0e10cSrcweir { 2128*cdf0e10cSrcweir bool bOK = false; 2129*cdf0e10cSrcweir 2130*cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage 2131*cdf0e10cSrcweir = m_pProvider->queryStorage( 2132*cdf0e10cSrcweir aSourceUri.getParentUri(), READ_WRITE_NOCREATE ); 2133*cdf0e10cSrcweir if ( xStorage.is() ) 2134*cdf0e10cSrcweir { 2135*cdf0e10cSrcweir try 2136*cdf0e10cSrcweir { 2137*cdf0e10cSrcweir if ( xStorage->isStreamElement( aSourceUri.getDecodedName() ) ) 2138*cdf0e10cSrcweir { 2139*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2140*cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 2141*cdf0e10cSrcweir rtl::OUString::createFromAscii( 2142*cdf0e10cSrcweir "Invalid source URI! " 2143*cdf0e10cSrcweir "Streams cannot be created as " 2144*cdf0e10cSrcweir "children of document root!" ), 2145*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( 2146*cdf0e10cSrcweir this ), 2147*cdf0e10cSrcweir -1 ) ), 2148*cdf0e10cSrcweir xEnv ); 2149*cdf0e10cSrcweir // Unreachable 2150*cdf0e10cSrcweir } 2151*cdf0e10cSrcweir bOK = true; 2152*cdf0e10cSrcweir } 2153*cdf0e10cSrcweir catch ( container::NoSuchElementException const & ) 2154*cdf0e10cSrcweir { 2155*cdf0e10cSrcweir // handled below. 2156*cdf0e10cSrcweir } 2157*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 2158*cdf0e10cSrcweir { 2159*cdf0e10cSrcweir // handled below. 2160*cdf0e10cSrcweir } 2161*cdf0e10cSrcweir catch ( embed::InvalidStorageException const & ) 2162*cdf0e10cSrcweir { 2163*cdf0e10cSrcweir // handled below. 2164*cdf0e10cSrcweir } 2165*cdf0e10cSrcweir } 2166*cdf0e10cSrcweir 2167*cdf0e10cSrcweir if ( !bOK ) 2168*cdf0e10cSrcweir { 2169*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2170*cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException( 2171*cdf0e10cSrcweir rtl::OUString::createFromAscii( 2172*cdf0e10cSrcweir "Invalid source URI! " 2173*cdf0e10cSrcweir "Unabale to determine source type!" ), 2174*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 2175*cdf0e10cSrcweir -1 ) ), 2176*cdf0e10cSrcweir xEnv ); 2177*cdf0e10cSrcweir // Unreachable 2178*cdf0e10cSrcweir } 2179*cdf0e10cSrcweir } 2180*cdf0e10cSrcweir #endif 2181*cdf0e10cSrcweir 2182*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 2183*cdf0e10cSrcweir // Copy data. 2184*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 2185*cdf0e10cSrcweir 2186*cdf0e10cSrcweir rtl::OUString aNewName( rInfo.NewTitle.getLength() > 0 2187*cdf0e10cSrcweir ? rInfo.NewTitle 2188*cdf0e10cSrcweir : aSourceUri.getDecodedName() ); 2189*cdf0e10cSrcweir 2190*cdf0e10cSrcweir if ( !copyData( aSourceUri, aNewName ) ) 2191*cdf0e10cSrcweir { 2192*cdf0e10cSrcweir uno::Any aProps 2193*cdf0e10cSrcweir = uno::makeAny( 2194*cdf0e10cSrcweir beans::PropertyValue( 2195*cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 2196*cdf0e10cSrcweir "Uri")), 2197*cdf0e10cSrcweir -1, 2198*cdf0e10cSrcweir uno::makeAny( rInfo.SourceURL ), 2199*cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE)); 2200*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2201*cdf0e10cSrcweir ucb::IOErrorCode_CANT_WRITE, 2202*cdf0e10cSrcweir uno::Sequence< uno::Any >(&aProps, 1), 2203*cdf0e10cSrcweir xEnv, 2204*cdf0e10cSrcweir rtl::OUString( 2205*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "Cannot copy data!" ) ), 2206*cdf0e10cSrcweir this ); 2207*cdf0e10cSrcweir // Unreachable 2208*cdf0e10cSrcweir } 2209*cdf0e10cSrcweir 2210*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 2211*cdf0e10cSrcweir // Copy own and all children's Additional Core Properties. 2212*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 2213*cdf0e10cSrcweir 2214*cdf0e10cSrcweir rtl::OUString aTargetUri = m_xIdentifier->getContentIdentifier(); 2215*cdf0e10cSrcweir if ( ( aTargetUri.lastIndexOf( '/' ) + 1 ) != aTargetUri.getLength() ) 2216*cdf0e10cSrcweir aTargetUri += rtl::OUString::createFromAscii( "/" ); 2217*cdf0e10cSrcweir 2218*cdf0e10cSrcweir if ( rInfo.NewTitle.getLength() > 0 ) 2219*cdf0e10cSrcweir aTargetUri += ::ucb_impl::urihelper::encodeSegment( rInfo.NewTitle ); 2220*cdf0e10cSrcweir else 2221*cdf0e10cSrcweir aTargetUri += aSourceUri.getName(); 2222*cdf0e10cSrcweir 2223*cdf0e10cSrcweir if ( !copyAdditionalPropertySet( 2224*cdf0e10cSrcweir aSourceUri.getUri(), aTargetUri, sal_True ) ) 2225*cdf0e10cSrcweir { 2226*cdf0e10cSrcweir uno::Any aProps 2227*cdf0e10cSrcweir = uno::makeAny( 2228*cdf0e10cSrcweir beans::PropertyValue( 2229*cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 2230*cdf0e10cSrcweir "Uri")), 2231*cdf0e10cSrcweir -1, 2232*cdf0e10cSrcweir uno::makeAny( rInfo.SourceURL ), 2233*cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE)); 2234*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2235*cdf0e10cSrcweir ucb::IOErrorCode_CANT_WRITE, 2236*cdf0e10cSrcweir uno::Sequence< uno::Any >(&aProps, 1), 2237*cdf0e10cSrcweir xEnv, 2238*cdf0e10cSrcweir rtl::OUString( 2239*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 2240*cdf0e10cSrcweir "Cannot copy additional properties!" ) ), 2241*cdf0e10cSrcweir this ); 2242*cdf0e10cSrcweir // Unreachable 2243*cdf0e10cSrcweir } 2244*cdf0e10cSrcweir 2245*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 2246*cdf0e10cSrcweir // Propagate new content. 2247*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 2248*cdf0e10cSrcweir 2249*cdf0e10cSrcweir rtl::Reference< Content > xTarget; 2250*cdf0e10cSrcweir try 2251*cdf0e10cSrcweir { 2252*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xTargetId 2253*cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( m_xSMgr, aTargetUri ); 2254*cdf0e10cSrcweir 2255*cdf0e10cSrcweir // Note: The static cast is okay here, because its sure that 2256*cdf0e10cSrcweir // m_xProvider is always the WebDAVContentProvider. 2257*cdf0e10cSrcweir xTarget = static_cast< Content * >( 2258*cdf0e10cSrcweir m_pProvider->queryContent( xTargetId ).get() ); 2259*cdf0e10cSrcweir 2260*cdf0e10cSrcweir } 2261*cdf0e10cSrcweir catch ( ucb::IllegalIdentifierException const & ) 2262*cdf0e10cSrcweir { 2263*cdf0e10cSrcweir // queryContent 2264*cdf0e10cSrcweir } 2265*cdf0e10cSrcweir 2266*cdf0e10cSrcweir if ( !xTarget.is() ) 2267*cdf0e10cSrcweir { 2268*cdf0e10cSrcweir uno::Any aProps 2269*cdf0e10cSrcweir = uno::makeAny(beans::PropertyValue( 2270*cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 2271*cdf0e10cSrcweir "Uri")), 2272*cdf0e10cSrcweir -1, 2273*cdf0e10cSrcweir uno::makeAny( aTargetUri ), 2274*cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE)); 2275*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2276*cdf0e10cSrcweir ucb::IOErrorCode_CANT_READ, 2277*cdf0e10cSrcweir uno::Sequence< uno::Any >(&aProps, 1), 2278*cdf0e10cSrcweir xEnv, 2279*cdf0e10cSrcweir rtl::OUString::createFromAscii( 2280*cdf0e10cSrcweir "Cannot instanciate target object!" ), 2281*cdf0e10cSrcweir this ); 2282*cdf0e10cSrcweir // Unreachable 2283*cdf0e10cSrcweir } 2284*cdf0e10cSrcweir 2285*cdf0e10cSrcweir // Announce transfered content in its new folder. 2286*cdf0e10cSrcweir xTarget->inserted(); 2287*cdf0e10cSrcweir 2288*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 2289*cdf0e10cSrcweir // Remove source, if requested 2290*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 2291*cdf0e10cSrcweir 2292*cdf0e10cSrcweir if ( rInfo.MoveData ) 2293*cdf0e10cSrcweir { 2294*cdf0e10cSrcweir rtl::Reference< Content > xSource; 2295*cdf0e10cSrcweir try 2296*cdf0e10cSrcweir { 2297*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > 2298*cdf0e10cSrcweir xSourceId = new ::ucbhelper::ContentIdentifier( 2299*cdf0e10cSrcweir m_xSMgr, rInfo.SourceURL ); 2300*cdf0e10cSrcweir 2301*cdf0e10cSrcweir // Note: The static cast is okay here, because its sure 2302*cdf0e10cSrcweir // that m_xProvider is always the ContentProvider. 2303*cdf0e10cSrcweir xSource = static_cast< Content * >( 2304*cdf0e10cSrcweir m_xProvider->queryContent( xSourceId ).get() ); 2305*cdf0e10cSrcweir } 2306*cdf0e10cSrcweir catch ( ucb::IllegalIdentifierException const & ) 2307*cdf0e10cSrcweir { 2308*cdf0e10cSrcweir // queryContent 2309*cdf0e10cSrcweir } 2310*cdf0e10cSrcweir 2311*cdf0e10cSrcweir if ( !xSource.is() ) 2312*cdf0e10cSrcweir { 2313*cdf0e10cSrcweir uno::Any aProps 2314*cdf0e10cSrcweir = uno::makeAny(beans::PropertyValue( 2315*cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 2316*cdf0e10cSrcweir "Uri")), 2317*cdf0e10cSrcweir -1, 2318*cdf0e10cSrcweir uno::makeAny( rInfo.SourceURL ), 2319*cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE)); 2320*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2321*cdf0e10cSrcweir ucb::IOErrorCode_CANT_READ, 2322*cdf0e10cSrcweir uno::Sequence< uno::Any >(&aProps, 1), 2323*cdf0e10cSrcweir xEnv, 2324*cdf0e10cSrcweir rtl::OUString::createFromAscii( 2325*cdf0e10cSrcweir "Cannot instanciate target object!" ), 2326*cdf0e10cSrcweir this ); 2327*cdf0e10cSrcweir // Unreachable 2328*cdf0e10cSrcweir } 2329*cdf0e10cSrcweir 2330*cdf0e10cSrcweir // Propagate destruction (recursively). 2331*cdf0e10cSrcweir xSource->destroy( sal_True, xEnv ); 2332*cdf0e10cSrcweir 2333*cdf0e10cSrcweir // Remove all persistent data of source and its children. 2334*cdf0e10cSrcweir if ( !xSource->removeData() ) 2335*cdf0e10cSrcweir { 2336*cdf0e10cSrcweir uno::Any aProps 2337*cdf0e10cSrcweir = uno::makeAny( 2338*cdf0e10cSrcweir beans::PropertyValue( 2339*cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 2340*cdf0e10cSrcweir "Uri")), 2341*cdf0e10cSrcweir -1, 2342*cdf0e10cSrcweir uno::makeAny( rInfo.SourceURL ), 2343*cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE)); 2344*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2345*cdf0e10cSrcweir ucb::IOErrorCode_CANT_WRITE, 2346*cdf0e10cSrcweir uno::Sequence< uno::Any >(&aProps, 1), 2347*cdf0e10cSrcweir xEnv, 2348*cdf0e10cSrcweir rtl::OUString::createFromAscii( 2349*cdf0e10cSrcweir "Cannot remove persistent data of source object!" ), 2350*cdf0e10cSrcweir this ); 2351*cdf0e10cSrcweir // Unreachable 2352*cdf0e10cSrcweir } 2353*cdf0e10cSrcweir 2354*cdf0e10cSrcweir // Remove own and all children's Additional Core Properties. 2355*cdf0e10cSrcweir if ( !xSource->removeAdditionalPropertySet( sal_True ) ) 2356*cdf0e10cSrcweir { 2357*cdf0e10cSrcweir uno::Any aProps 2358*cdf0e10cSrcweir = uno::makeAny( 2359*cdf0e10cSrcweir beans::PropertyValue( 2360*cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 2361*cdf0e10cSrcweir "Uri")), 2362*cdf0e10cSrcweir -1, 2363*cdf0e10cSrcweir uno::makeAny( rInfo.SourceURL ), 2364*cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE)); 2365*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 2366*cdf0e10cSrcweir ucb::IOErrorCode_CANT_WRITE, 2367*cdf0e10cSrcweir uno::Sequence< uno::Any >(&aProps, 1), 2368*cdf0e10cSrcweir xEnv, 2369*cdf0e10cSrcweir rtl::OUString::createFromAscii( 2370*cdf0e10cSrcweir "Cannot remove additional properties of source object!" ), 2371*cdf0e10cSrcweir this ); 2372*cdf0e10cSrcweir // Unreachable 2373*cdf0e10cSrcweir } 2374*cdf0e10cSrcweir 2375*cdf0e10cSrcweir } // rInfo.MoveData 2376*cdf0e10cSrcweir } 2377*cdf0e10cSrcweir 2378*cdf0e10cSrcweir //========================================================================= 2379*cdf0e10cSrcweir //static 2380*cdf0e10cSrcweir bool Content::hasData( ContentProvider* pProvider, const Uri & rUri ) 2381*cdf0e10cSrcweir { 2382*cdf0e10cSrcweir if ( rUri.isRoot() ) 2383*cdf0e10cSrcweir { 2384*cdf0e10cSrcweir return true; // root has no storage 2385*cdf0e10cSrcweir } 2386*cdf0e10cSrcweir else if ( rUri.isDocument() ) 2387*cdf0e10cSrcweir { 2388*cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage 2389*cdf0e10cSrcweir = pProvider->queryStorage( rUri.getUri(), READ ); 2390*cdf0e10cSrcweir return xStorage.is(); 2391*cdf0e10cSrcweir } 2392*cdf0e10cSrcweir else 2393*cdf0e10cSrcweir { 2394*cdf0e10cSrcweir // folder or stream 2395*cdf0e10cSrcweir 2396*cdf0e10cSrcweir // Ask parent storage. In case that rUri describes a stream, 2397*cdf0e10cSrcweir // ContentProvider::queryStorage( rUri ) would return null. 2398*cdf0e10cSrcweir 2399*cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage 2400*cdf0e10cSrcweir = pProvider->queryStorage( rUri.getParentUri(), READ ); 2401*cdf0e10cSrcweir 2402*cdf0e10cSrcweir if ( !xStorage.is() ) 2403*cdf0e10cSrcweir return false; 2404*cdf0e10cSrcweir 2405*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xParentNA( 2406*cdf0e10cSrcweir xStorage, uno::UNO_QUERY ); 2407*cdf0e10cSrcweir 2408*cdf0e10cSrcweir OSL_ENSURE( xParentNA.is(), "Got no css.container.XNameAccess!" ); 2409*cdf0e10cSrcweir 2410*cdf0e10cSrcweir return xParentNA->hasByName( rUri.getDecodedName() ); 2411*cdf0e10cSrcweir } 2412*cdf0e10cSrcweir } 2413*cdf0e10cSrcweir 2414*cdf0e10cSrcweir //========================================================================= 2415*cdf0e10cSrcweir //static 2416*cdf0e10cSrcweir bool Content::loadData( ContentProvider* pProvider, 2417*cdf0e10cSrcweir const Uri & rUri, 2418*cdf0e10cSrcweir ContentProperties& rProps ) 2419*cdf0e10cSrcweir { 2420*cdf0e10cSrcweir if ( rUri.isRoot() ) // root has no storage, but can always be created 2421*cdf0e10cSrcweir { 2422*cdf0e10cSrcweir rProps 2423*cdf0e10cSrcweir = ContentProperties( 2424*cdf0e10cSrcweir ROOT, pProvider->queryStorageTitle( rUri.getUri() ) ); 2425*cdf0e10cSrcweir } 2426*cdf0e10cSrcweir else if ( rUri.isDocument() ) // document must have storage 2427*cdf0e10cSrcweir { 2428*cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage 2429*cdf0e10cSrcweir = pProvider->queryStorage( rUri.getUri(), READ ); 2430*cdf0e10cSrcweir 2431*cdf0e10cSrcweir if ( !xStorage.is() ) 2432*cdf0e10cSrcweir return false; 2433*cdf0e10cSrcweir 2434*cdf0e10cSrcweir rProps 2435*cdf0e10cSrcweir = ContentProperties( 2436*cdf0e10cSrcweir DOCUMENT, pProvider->queryStorageTitle( rUri.getUri() ) ); 2437*cdf0e10cSrcweir } 2438*cdf0e10cSrcweir else // stream or folder; stream has no storage; folder has storage 2439*cdf0e10cSrcweir { 2440*cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage 2441*cdf0e10cSrcweir = pProvider->queryStorage( rUri.getParentUri(), READ ); 2442*cdf0e10cSrcweir 2443*cdf0e10cSrcweir if ( !xStorage.is() ) 2444*cdf0e10cSrcweir return false; 2445*cdf0e10cSrcweir 2446*cdf0e10cSrcweir // Check whether exists at all, is stream or folder 2447*cdf0e10cSrcweir try 2448*cdf0e10cSrcweir { 2449*cdf0e10cSrcweir // return: true -> folder 2450*cdf0e10cSrcweir // return: false -> stream 2451*cdf0e10cSrcweir // NoSuchElementException -> neither folder nor stream 2452*cdf0e10cSrcweir bool bIsFolder 2453*cdf0e10cSrcweir = xStorage->isStorageElement( rUri.getDecodedName() ); 2454*cdf0e10cSrcweir 2455*cdf0e10cSrcweir rProps 2456*cdf0e10cSrcweir = ContentProperties( 2457*cdf0e10cSrcweir bIsFolder ? FOLDER : STREAM, 2458*cdf0e10cSrcweir pProvider->queryStorageTitle( rUri.getUri() ) ); 2459*cdf0e10cSrcweir } 2460*cdf0e10cSrcweir catch ( container::NoSuchElementException const & ) 2461*cdf0e10cSrcweir { 2462*cdf0e10cSrcweir // there is no element with such name 2463*cdf0e10cSrcweir //OSL_ENSURE( false, "Caught NoSuchElementException!" ); 2464*cdf0e10cSrcweir return false; 2465*cdf0e10cSrcweir } 2466*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 2467*cdf0e10cSrcweir { 2468*cdf0e10cSrcweir // an illegal argument is provided 2469*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IllegalArgumentException!" ); 2470*cdf0e10cSrcweir return false; 2471*cdf0e10cSrcweir } 2472*cdf0e10cSrcweir catch ( embed::InvalidStorageException const & ) 2473*cdf0e10cSrcweir { 2474*cdf0e10cSrcweir // this storage is in invalid state for any reason 2475*cdf0e10cSrcweir OSL_ENSURE( false, "Caught InvalidStorageException!" ); 2476*cdf0e10cSrcweir return false; 2477*cdf0e10cSrcweir } 2478*cdf0e10cSrcweir } 2479*cdf0e10cSrcweir return true; 2480*cdf0e10cSrcweir } 2481*cdf0e10cSrcweir 2482*cdf0e10cSrcweir //========================================================================= 2483*cdf0e10cSrcweir bool Content::storeData( const uno::Reference< io::XInputStream >& xData, 2484*cdf0e10cSrcweir const uno::Reference< 2485*cdf0e10cSrcweir ucb::XCommandEnvironment >& xEnv ) 2486*cdf0e10cSrcweir throw ( ucb::CommandFailedException, 2487*cdf0e10cSrcweir task::DocumentPasswordRequest ) 2488*cdf0e10cSrcweir { 2489*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2490*cdf0e10cSrcweir 2491*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 2492*cdf0e10cSrcweir if ( ( eType == ROOT ) || ( eType == DOCUMENT ) ) 2493*cdf0e10cSrcweir { 2494*cdf0e10cSrcweir OSL_ENSURE( false, "storeData not supported by root and documents!" ); 2495*cdf0e10cSrcweir return false; 2496*cdf0e10cSrcweir } 2497*cdf0e10cSrcweir 2498*cdf0e10cSrcweir Uri aUri( m_xIdentifier->getContentIdentifier() ); 2499*cdf0e10cSrcweir 2500*cdf0e10cSrcweir if ( eType == FOLDER ) 2501*cdf0e10cSrcweir { 2502*cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage 2503*cdf0e10cSrcweir = m_pProvider->queryStorage( aUri.getUri(), READ_WRITE_CREATE ); 2504*cdf0e10cSrcweir 2505*cdf0e10cSrcweir if ( !xStorage.is() ) 2506*cdf0e10cSrcweir return false; 2507*cdf0e10cSrcweir 2508*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( 2509*cdf0e10cSrcweir xStorage, uno::UNO_QUERY ); 2510*cdf0e10cSrcweir OSL_ENSURE( xPropSet.is(), 2511*cdf0e10cSrcweir "Content::storeData - Got no XPropertySet interface!" ); 2512*cdf0e10cSrcweir if ( !xPropSet.is() ) 2513*cdf0e10cSrcweir return false; 2514*cdf0e10cSrcweir 2515*cdf0e10cSrcweir try 2516*cdf0e10cSrcweir { 2517*cdf0e10cSrcweir // According to MBA, if no mediatype is set, folder and all 2518*cdf0e10cSrcweir // its contents will be lost on save of the document!!! 2519*cdf0e10cSrcweir xPropSet->setPropertyValue( 2520*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), 2521*cdf0e10cSrcweir uno::makeAny( 2522*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 2523*cdf0e10cSrcweir // @@@ better mediatype 2524*cdf0e10cSrcweir "application/binary" ) ) ) ); 2525*cdf0e10cSrcweir } 2526*cdf0e10cSrcweir catch ( beans::UnknownPropertyException const & ) 2527*cdf0e10cSrcweir { 2528*cdf0e10cSrcweir OSL_ENSURE( false, "Property MediaType not supported!" ); 2529*cdf0e10cSrcweir return false; 2530*cdf0e10cSrcweir } 2531*cdf0e10cSrcweir catch ( beans::PropertyVetoException const & ) 2532*cdf0e10cSrcweir { 2533*cdf0e10cSrcweir OSL_ENSURE( false, "Caught PropertyVetoException!" ); 2534*cdf0e10cSrcweir return false; 2535*cdf0e10cSrcweir } 2536*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 2537*cdf0e10cSrcweir { 2538*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IllegalArgumentException!" ); 2539*cdf0e10cSrcweir return false; 2540*cdf0e10cSrcweir } 2541*cdf0e10cSrcweir catch ( lang::WrappedTargetException const & ) 2542*cdf0e10cSrcweir { 2543*cdf0e10cSrcweir OSL_ENSURE( false, "Caught WrappedTargetException!" ); 2544*cdf0e10cSrcweir return false; 2545*cdf0e10cSrcweir } 2546*cdf0e10cSrcweir 2547*cdf0e10cSrcweir if ( !commitStorage( xStorage ) ) 2548*cdf0e10cSrcweir return false; 2549*cdf0e10cSrcweir } 2550*cdf0e10cSrcweir else if ( eType == STREAM ) 2551*cdf0e10cSrcweir { 2552*cdf0e10cSrcweir // stream 2553*cdf0e10cSrcweir 2554*cdf0e10cSrcweir // Important: Parent storage and output stream must be kept alive until 2555*cdf0e10cSrcweir // changes have been committed! 2556*cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage 2557*cdf0e10cSrcweir = m_pProvider->queryStorage( 2558*cdf0e10cSrcweir aUri.getParentUri(), READ_WRITE_CREATE ); 2559*cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOut; 2560*cdf0e10cSrcweir 2561*cdf0e10cSrcweir if ( !xStorage.is() ) 2562*cdf0e10cSrcweir return false; 2563*cdf0e10cSrcweir 2564*cdf0e10cSrcweir if ( xData.is() ) 2565*cdf0e10cSrcweir { 2566*cdf0e10cSrcweir // May throw CommandFailedException, DocumentPasswordRequest! 2567*cdf0e10cSrcweir xOut = getTruncatedOutputStream( xEnv ); 2568*cdf0e10cSrcweir 2569*cdf0e10cSrcweir OSL_ENSURE( xOut.is(), "No target data stream!" ); 2570*cdf0e10cSrcweir 2571*cdf0e10cSrcweir try 2572*cdf0e10cSrcweir { 2573*cdf0e10cSrcweir uno::Sequence< sal_Int8 > aBuffer; 2574*cdf0e10cSrcweir sal_Int32 nRead = xData->readSomeBytes( aBuffer, 65536 ); 2575*cdf0e10cSrcweir 2576*cdf0e10cSrcweir while ( nRead > 0 ) 2577*cdf0e10cSrcweir { 2578*cdf0e10cSrcweir aBuffer.realloc( nRead ); 2579*cdf0e10cSrcweir xOut->writeBytes( aBuffer ); 2580*cdf0e10cSrcweir aBuffer.realloc( 0 ); 2581*cdf0e10cSrcweir nRead = xData->readSomeBytes( aBuffer, 65536 ); 2582*cdf0e10cSrcweir } 2583*cdf0e10cSrcweir 2584*cdf0e10cSrcweir closeOutputStream( xOut ); 2585*cdf0e10cSrcweir } 2586*cdf0e10cSrcweir catch ( io::NotConnectedException const & ) 2587*cdf0e10cSrcweir { 2588*cdf0e10cSrcweir // readSomeBytes, writeBytes 2589*cdf0e10cSrcweir OSL_ENSURE( false, "Caught NotConnectedException!" ); 2590*cdf0e10cSrcweir closeOutputStream( xOut ); 2591*cdf0e10cSrcweir return false; 2592*cdf0e10cSrcweir } 2593*cdf0e10cSrcweir catch ( io::BufferSizeExceededException const & ) 2594*cdf0e10cSrcweir { 2595*cdf0e10cSrcweir // readSomeBytes, writeBytes 2596*cdf0e10cSrcweir OSL_ENSURE( false, "Caught BufferSizeExceededException!" ); 2597*cdf0e10cSrcweir closeOutputStream( xOut ); 2598*cdf0e10cSrcweir return false; 2599*cdf0e10cSrcweir } 2600*cdf0e10cSrcweir catch ( io::IOException const & ) 2601*cdf0e10cSrcweir { 2602*cdf0e10cSrcweir // readSomeBytes, writeBytes 2603*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IOException!" ); 2604*cdf0e10cSrcweir closeOutputStream( xOut ); 2605*cdf0e10cSrcweir return false; 2606*cdf0e10cSrcweir } 2607*cdf0e10cSrcweir catch ( ... ) 2608*cdf0e10cSrcweir { 2609*cdf0e10cSrcweir closeOutputStream( xOut ); 2610*cdf0e10cSrcweir throw; 2611*cdf0e10cSrcweir } 2612*cdf0e10cSrcweir } 2613*cdf0e10cSrcweir 2614*cdf0e10cSrcweir // Commit changes. 2615*cdf0e10cSrcweir if ( !commitStorage( xStorage ) ) 2616*cdf0e10cSrcweir return false; 2617*cdf0e10cSrcweir } 2618*cdf0e10cSrcweir else 2619*cdf0e10cSrcweir { 2620*cdf0e10cSrcweir OSL_ENSURE( false, "Unknown content type!" ); 2621*cdf0e10cSrcweir return false; 2622*cdf0e10cSrcweir } 2623*cdf0e10cSrcweir return true; 2624*cdf0e10cSrcweir } 2625*cdf0e10cSrcweir 2626*cdf0e10cSrcweir //========================================================================= 2627*cdf0e10cSrcweir bool Content::renameData( 2628*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& xOldId, 2629*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& xNewId ) 2630*cdf0e10cSrcweir { 2631*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2632*cdf0e10cSrcweir 2633*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 2634*cdf0e10cSrcweir if ( ( eType == ROOT ) || ( eType == DOCUMENT ) ) 2635*cdf0e10cSrcweir { 2636*cdf0e10cSrcweir OSL_ENSURE( false, "renameData not supported by root and documents!" ); 2637*cdf0e10cSrcweir return false; 2638*cdf0e10cSrcweir } 2639*cdf0e10cSrcweir 2640*cdf0e10cSrcweir Uri aOldUri( xOldId->getContentIdentifier() ); 2641*cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage 2642*cdf0e10cSrcweir = m_pProvider->queryStorage( 2643*cdf0e10cSrcweir aOldUri.getParentUri(), READ_WRITE_NOCREATE ); 2644*cdf0e10cSrcweir 2645*cdf0e10cSrcweir if ( !xStorage.is() ) 2646*cdf0e10cSrcweir return false; 2647*cdf0e10cSrcweir 2648*cdf0e10cSrcweir try 2649*cdf0e10cSrcweir { 2650*cdf0e10cSrcweir Uri aNewUri( xNewId->getContentIdentifier() ); 2651*cdf0e10cSrcweir xStorage->renameElement( 2652*cdf0e10cSrcweir aOldUri.getDecodedName(), aNewUri.getDecodedName() ); 2653*cdf0e10cSrcweir } 2654*cdf0e10cSrcweir catch ( embed::InvalidStorageException const & ) 2655*cdf0e10cSrcweir { 2656*cdf0e10cSrcweir // this storage is in invalid state for eny reason 2657*cdf0e10cSrcweir OSL_ENSURE( false, "Caught InvalidStorageException!" ); 2658*cdf0e10cSrcweir return false; 2659*cdf0e10cSrcweir } 2660*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 2661*cdf0e10cSrcweir { 2662*cdf0e10cSrcweir // an illegal argument is provided 2663*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IllegalArgumentException!" ); 2664*cdf0e10cSrcweir return false; 2665*cdf0e10cSrcweir } 2666*cdf0e10cSrcweir catch ( container::NoSuchElementException const & ) 2667*cdf0e10cSrcweir { 2668*cdf0e10cSrcweir // there is no element with old name in this storage 2669*cdf0e10cSrcweir OSL_ENSURE( false, "Caught NoSuchElementException!" ); 2670*cdf0e10cSrcweir return false; 2671*cdf0e10cSrcweir } 2672*cdf0e10cSrcweir catch ( container::ElementExistException const & ) 2673*cdf0e10cSrcweir { 2674*cdf0e10cSrcweir // an element with new name already exists in this storage 2675*cdf0e10cSrcweir OSL_ENSURE( false, "Caught ElementExistException!" ); 2676*cdf0e10cSrcweir return false; 2677*cdf0e10cSrcweir } 2678*cdf0e10cSrcweir catch ( io::IOException const & ) 2679*cdf0e10cSrcweir { 2680*cdf0e10cSrcweir // in case of io errors during renaming 2681*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IOException!" ); 2682*cdf0e10cSrcweir return false; 2683*cdf0e10cSrcweir } 2684*cdf0e10cSrcweir catch ( embed::StorageWrappedTargetException const & ) 2685*cdf0e10cSrcweir { 2686*cdf0e10cSrcweir // wraps other exceptions 2687*cdf0e10cSrcweir OSL_ENSURE( false, "Caught StorageWrappedTargetException!" ); 2688*cdf0e10cSrcweir return false; 2689*cdf0e10cSrcweir } 2690*cdf0e10cSrcweir 2691*cdf0e10cSrcweir return commitStorage( xStorage ); 2692*cdf0e10cSrcweir } 2693*cdf0e10cSrcweir 2694*cdf0e10cSrcweir //========================================================================= 2695*cdf0e10cSrcweir bool Content::removeData() 2696*cdf0e10cSrcweir { 2697*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2698*cdf0e10cSrcweir 2699*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 2700*cdf0e10cSrcweir if ( ( eType == ROOT ) || ( eType == DOCUMENT ) ) 2701*cdf0e10cSrcweir { 2702*cdf0e10cSrcweir OSL_ENSURE( false, "removeData not supported by root and documents!" ); 2703*cdf0e10cSrcweir return false; 2704*cdf0e10cSrcweir } 2705*cdf0e10cSrcweir 2706*cdf0e10cSrcweir Uri aUri( m_xIdentifier->getContentIdentifier() ); 2707*cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage 2708*cdf0e10cSrcweir = m_pProvider->queryStorage( 2709*cdf0e10cSrcweir aUri.getParentUri(), READ_WRITE_NOCREATE ); 2710*cdf0e10cSrcweir 2711*cdf0e10cSrcweir if ( !xStorage.is() ) 2712*cdf0e10cSrcweir return false; 2713*cdf0e10cSrcweir 2714*cdf0e10cSrcweir try 2715*cdf0e10cSrcweir { 2716*cdf0e10cSrcweir xStorage->removeElement( aUri.getDecodedName() ); 2717*cdf0e10cSrcweir } 2718*cdf0e10cSrcweir catch ( embed::InvalidStorageException const & ) 2719*cdf0e10cSrcweir { 2720*cdf0e10cSrcweir // this storage is in invalid state for eny reason 2721*cdf0e10cSrcweir OSL_ENSURE( false, "Caught InvalidStorageException!" ); 2722*cdf0e10cSrcweir return false; 2723*cdf0e10cSrcweir } 2724*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 2725*cdf0e10cSrcweir { 2726*cdf0e10cSrcweir // an illegal argument is provided 2727*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IllegalArgumentException!" ); 2728*cdf0e10cSrcweir return false; 2729*cdf0e10cSrcweir } 2730*cdf0e10cSrcweir catch ( container::NoSuchElementException const & ) 2731*cdf0e10cSrcweir { 2732*cdf0e10cSrcweir // there is no element with this name in this storage 2733*cdf0e10cSrcweir OSL_ENSURE( false, "Caught NoSuchElementException!" ); 2734*cdf0e10cSrcweir return false; 2735*cdf0e10cSrcweir } 2736*cdf0e10cSrcweir catch ( io::IOException const & ) 2737*cdf0e10cSrcweir { 2738*cdf0e10cSrcweir // in case of io errors during renaming 2739*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IOException!" ); 2740*cdf0e10cSrcweir return false; 2741*cdf0e10cSrcweir } 2742*cdf0e10cSrcweir catch ( embed::StorageWrappedTargetException const & ) 2743*cdf0e10cSrcweir { 2744*cdf0e10cSrcweir // wraps other exceptions 2745*cdf0e10cSrcweir OSL_ENSURE( false, "Caught StorageWrappedTargetException!" ); 2746*cdf0e10cSrcweir return false; 2747*cdf0e10cSrcweir } 2748*cdf0e10cSrcweir 2749*cdf0e10cSrcweir return commitStorage( xStorage ); 2750*cdf0e10cSrcweir } 2751*cdf0e10cSrcweir 2752*cdf0e10cSrcweir //========================================================================= 2753*cdf0e10cSrcweir bool Content::copyData( const Uri & rSourceUri, const rtl::OUString & rNewName ) 2754*cdf0e10cSrcweir { 2755*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2756*cdf0e10cSrcweir 2757*cdf0e10cSrcweir ContentType eType = m_aProps.getType(); 2758*cdf0e10cSrcweir if ( ( eType == ROOT ) || ( eType == STREAM ) ) 2759*cdf0e10cSrcweir { 2760*cdf0e10cSrcweir OSL_ENSURE( false, "copyData not supported by root and streams!" ); 2761*cdf0e10cSrcweir return false; 2762*cdf0e10cSrcweir } 2763*cdf0e10cSrcweir 2764*cdf0e10cSrcweir Uri aDestUri( m_xIdentifier->getContentIdentifier() ); 2765*cdf0e10cSrcweir uno::Reference< embed::XStorage > xDestStorage 2766*cdf0e10cSrcweir = m_pProvider->queryStorage( aDestUri.getUri(), READ_WRITE_NOCREATE ); 2767*cdf0e10cSrcweir 2768*cdf0e10cSrcweir if ( !xDestStorage.is() ) 2769*cdf0e10cSrcweir return false; 2770*cdf0e10cSrcweir 2771*cdf0e10cSrcweir uno::Reference< embed::XStorage > xSourceStorage 2772*cdf0e10cSrcweir = m_pProvider->queryStorage( rSourceUri.getParentUri(), READ ); 2773*cdf0e10cSrcweir 2774*cdf0e10cSrcweir if ( !xSourceStorage.is() ) 2775*cdf0e10cSrcweir return false; 2776*cdf0e10cSrcweir 2777*cdf0e10cSrcweir try 2778*cdf0e10cSrcweir { 2779*cdf0e10cSrcweir xSourceStorage->copyElementTo( rSourceUri.getDecodedName(), 2780*cdf0e10cSrcweir xDestStorage, 2781*cdf0e10cSrcweir rNewName ); 2782*cdf0e10cSrcweir } 2783*cdf0e10cSrcweir catch ( embed::InvalidStorageException const & ) 2784*cdf0e10cSrcweir { 2785*cdf0e10cSrcweir // this storage is in invalid state for eny reason 2786*cdf0e10cSrcweir OSL_ENSURE( false, "Caught InvalidStorageException!" ); 2787*cdf0e10cSrcweir return false; 2788*cdf0e10cSrcweir } 2789*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 2790*cdf0e10cSrcweir { 2791*cdf0e10cSrcweir // an illegal argument is provided 2792*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IllegalArgumentException!" ); 2793*cdf0e10cSrcweir return false; 2794*cdf0e10cSrcweir } 2795*cdf0e10cSrcweir catch ( container::NoSuchElementException const & ) 2796*cdf0e10cSrcweir { 2797*cdf0e10cSrcweir // there is no element with this name in this storage 2798*cdf0e10cSrcweir OSL_ENSURE( false, "Caught NoSuchElementException!" ); 2799*cdf0e10cSrcweir return false; 2800*cdf0e10cSrcweir } 2801*cdf0e10cSrcweir catch ( container::ElementExistException const & ) 2802*cdf0e10cSrcweir { 2803*cdf0e10cSrcweir // there is no element with this name in this storage 2804*cdf0e10cSrcweir OSL_ENSURE( false, "Caught ElementExistException!" ); 2805*cdf0e10cSrcweir return false; 2806*cdf0e10cSrcweir } 2807*cdf0e10cSrcweir catch ( io::IOException const & ) 2808*cdf0e10cSrcweir { 2809*cdf0e10cSrcweir // in case of io errors during renaming 2810*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IOException!" ); 2811*cdf0e10cSrcweir return false; 2812*cdf0e10cSrcweir } 2813*cdf0e10cSrcweir catch ( embed::StorageWrappedTargetException const & ) 2814*cdf0e10cSrcweir { 2815*cdf0e10cSrcweir // wraps other exceptions 2816*cdf0e10cSrcweir OSL_ENSURE( false, "Caught StorageWrappedTargetException!" ); 2817*cdf0e10cSrcweir return false; 2818*cdf0e10cSrcweir } 2819*cdf0e10cSrcweir 2820*cdf0e10cSrcweir return commitStorage( xDestStorage ); 2821*cdf0e10cSrcweir } 2822*cdf0e10cSrcweir 2823*cdf0e10cSrcweir //========================================================================= 2824*cdf0e10cSrcweir // static 2825*cdf0e10cSrcweir bool Content::commitStorage( const uno::Reference< embed::XStorage > & xStorage ) 2826*cdf0e10cSrcweir { 2827*cdf0e10cSrcweir // Commit changes 2828*cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xTO( xStorage, uno::UNO_QUERY ); 2829*cdf0e10cSrcweir 2830*cdf0e10cSrcweir OSL_ENSURE( xTO.is(), 2831*cdf0e10cSrcweir "Required interface css.embed.XTransactedObject missing!" ); 2832*cdf0e10cSrcweir try 2833*cdf0e10cSrcweir { 2834*cdf0e10cSrcweir xTO->commit(); 2835*cdf0e10cSrcweir } 2836*cdf0e10cSrcweir catch ( io::IOException const & ) 2837*cdf0e10cSrcweir { 2838*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IOException!" ); 2839*cdf0e10cSrcweir return false; 2840*cdf0e10cSrcweir } 2841*cdf0e10cSrcweir catch ( lang::WrappedTargetException const & ) 2842*cdf0e10cSrcweir { 2843*cdf0e10cSrcweir OSL_ENSURE( false, "Caught WrappedTargetException!" ); 2844*cdf0e10cSrcweir return false; 2845*cdf0e10cSrcweir } 2846*cdf0e10cSrcweir 2847*cdf0e10cSrcweir return true; 2848*cdf0e10cSrcweir } 2849*cdf0e10cSrcweir 2850*cdf0e10cSrcweir //========================================================================= 2851*cdf0e10cSrcweir // static 2852*cdf0e10cSrcweir bool Content::closeOutputStream( 2853*cdf0e10cSrcweir const uno::Reference< io::XOutputStream > & xOut ) 2854*cdf0e10cSrcweir { 2855*cdf0e10cSrcweir if ( xOut.is() ) 2856*cdf0e10cSrcweir { 2857*cdf0e10cSrcweir try 2858*cdf0e10cSrcweir { 2859*cdf0e10cSrcweir xOut->closeOutput(); 2860*cdf0e10cSrcweir return true; 2861*cdf0e10cSrcweir } 2862*cdf0e10cSrcweir catch ( io::NotConnectedException const & ) 2863*cdf0e10cSrcweir { 2864*cdf0e10cSrcweir OSL_ENSURE( false, "Caught NotConnectedException!" ); 2865*cdf0e10cSrcweir } 2866*cdf0e10cSrcweir catch ( io::BufferSizeExceededException const & ) 2867*cdf0e10cSrcweir { 2868*cdf0e10cSrcweir OSL_ENSURE( false, "Caught BufferSizeExceededException!" ); 2869*cdf0e10cSrcweir } 2870*cdf0e10cSrcweir catch ( io::IOException const & ) 2871*cdf0e10cSrcweir { 2872*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IOException!" ); 2873*cdf0e10cSrcweir } 2874*cdf0e10cSrcweir } 2875*cdf0e10cSrcweir return false; 2876*cdf0e10cSrcweir } 2877*cdf0e10cSrcweir 2878*cdf0e10cSrcweir //========================================================================= 2879*cdf0e10cSrcweir static rtl::OUString obtainPassword( 2880*cdf0e10cSrcweir const rtl::OUString & rName, 2881*cdf0e10cSrcweir task::PasswordRequestMode eMode, 2882*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 2883*cdf0e10cSrcweir throw ( ucb::CommandFailedException, 2884*cdf0e10cSrcweir task::DocumentPasswordRequest ) 2885*cdf0e10cSrcweir { 2886*cdf0e10cSrcweir rtl::Reference< DocumentPasswordRequest > xRequest 2887*cdf0e10cSrcweir = new DocumentPasswordRequest( eMode, rName ); 2888*cdf0e10cSrcweir 2889*cdf0e10cSrcweir if ( xEnv.is() ) 2890*cdf0e10cSrcweir { 2891*cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xIH 2892*cdf0e10cSrcweir = xEnv->getInteractionHandler(); 2893*cdf0e10cSrcweir if ( xIH.is() ) 2894*cdf0e10cSrcweir { 2895*cdf0e10cSrcweir xIH->handle( xRequest.get() ); 2896*cdf0e10cSrcweir 2897*cdf0e10cSrcweir rtl::Reference< ucbhelper::InteractionContinuation > xSelection 2898*cdf0e10cSrcweir = xRequest->getSelection(); 2899*cdf0e10cSrcweir 2900*cdf0e10cSrcweir if ( xSelection.is() ) 2901*cdf0e10cSrcweir { 2902*cdf0e10cSrcweir // Handler handled the request. 2903*cdf0e10cSrcweir uno::Reference< task::XInteractionAbort > xAbort( 2904*cdf0e10cSrcweir xSelection.get(), uno::UNO_QUERY ); 2905*cdf0e10cSrcweir if ( xAbort.is() ) 2906*cdf0e10cSrcweir { 2907*cdf0e10cSrcweir throw ucb::CommandFailedException( 2908*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 2909*cdf0e10cSrcweir "Abort requested by Interaction Handler." ) ), 2910*cdf0e10cSrcweir uno::Reference< uno::XInterface >(), 2911*cdf0e10cSrcweir xRequest->getRequest() ); 2912*cdf0e10cSrcweir } 2913*cdf0e10cSrcweir 2914*cdf0e10cSrcweir uno::Reference< task::XInteractionPassword > xPassword( 2915*cdf0e10cSrcweir xSelection.get(), uno::UNO_QUERY ); 2916*cdf0e10cSrcweir if ( xPassword.is() ) 2917*cdf0e10cSrcweir { 2918*cdf0e10cSrcweir return xPassword->getPassword(); 2919*cdf0e10cSrcweir } 2920*cdf0e10cSrcweir 2921*cdf0e10cSrcweir // Unknown selection. Should never happen. 2922*cdf0e10cSrcweir throw ucb::CommandFailedException( 2923*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 2924*cdf0e10cSrcweir "Interaction Handler selected unknown continuation!" ) ), 2925*cdf0e10cSrcweir uno::Reference< uno::XInterface >(), 2926*cdf0e10cSrcweir xRequest->getRequest() ); 2927*cdf0e10cSrcweir } 2928*cdf0e10cSrcweir } 2929*cdf0e10cSrcweir } 2930*cdf0e10cSrcweir 2931*cdf0e10cSrcweir // No IH or IH did not handle exception. 2932*cdf0e10cSrcweir task::DocumentPasswordRequest aRequest; 2933*cdf0e10cSrcweir xRequest->getRequest() >>= aRequest; 2934*cdf0e10cSrcweir throw aRequest; 2935*cdf0e10cSrcweir } 2936*cdf0e10cSrcweir 2937*cdf0e10cSrcweir //========================================================================= 2938*cdf0e10cSrcweir uno::Reference< io::XInputStream > Content::getInputStream( 2939*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 2940*cdf0e10cSrcweir throw ( ucb::CommandFailedException, 2941*cdf0e10cSrcweir task::DocumentPasswordRequest ) 2942*cdf0e10cSrcweir { 2943*cdf0e10cSrcweir rtl::OUString aUri; 2944*cdf0e10cSrcweir rtl::OUString aPassword; 2945*cdf0e10cSrcweir bool bPasswordRequested = false; 2946*cdf0e10cSrcweir 2947*cdf0e10cSrcweir { 2948*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2949*cdf0e10cSrcweir 2950*cdf0e10cSrcweir OSL_ENSURE( m_aProps.getType() == STREAM, 2951*cdf0e10cSrcweir "Content::getInputStream - content is no stream!" ); 2952*cdf0e10cSrcweir 2953*cdf0e10cSrcweir aUri = Uri( m_xIdentifier->getContentIdentifier() ).getUri(); 2954*cdf0e10cSrcweir } 2955*cdf0e10cSrcweir 2956*cdf0e10cSrcweir for ( ;; ) 2957*cdf0e10cSrcweir { 2958*cdf0e10cSrcweir try 2959*cdf0e10cSrcweir { 2960*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 2961*cdf0e10cSrcweir return uno::Reference< io::XInputStream >( 2962*cdf0e10cSrcweir m_pProvider->queryInputStream( aUri, aPassword ) ); 2963*cdf0e10cSrcweir } 2964*cdf0e10cSrcweir catch ( packages::WrongPasswordException const & ) 2965*cdf0e10cSrcweir { 2966*cdf0e10cSrcweir // Obtain (new) password. 2967*cdf0e10cSrcweir aPassword 2968*cdf0e10cSrcweir = obtainPassword( aUri, /* @@@ find better title */ 2969*cdf0e10cSrcweir bPasswordRequested 2970*cdf0e10cSrcweir ? task::PasswordRequestMode_PASSWORD_REENTER 2971*cdf0e10cSrcweir : task::PasswordRequestMode_PASSWORD_ENTER, 2972*cdf0e10cSrcweir xEnv ); 2973*cdf0e10cSrcweir bPasswordRequested = true; 2974*cdf0e10cSrcweir } 2975*cdf0e10cSrcweir } 2976*cdf0e10cSrcweir } 2977*cdf0e10cSrcweir 2978*cdf0e10cSrcweir //========================================================================= 2979*cdf0e10cSrcweir static uno::Reference< io::XOutputStream > lcl_getTruncatedOutputStream( 2980*cdf0e10cSrcweir const rtl::OUString & rUri, 2981*cdf0e10cSrcweir ContentProvider * pProvider, 2982*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 2983*cdf0e10cSrcweir throw ( ucb::CommandFailedException, 2984*cdf0e10cSrcweir task::DocumentPasswordRequest ) 2985*cdf0e10cSrcweir { 2986*cdf0e10cSrcweir rtl::OUString aPassword; 2987*cdf0e10cSrcweir bool bPasswordRequested = false; 2988*cdf0e10cSrcweir for ( ;; ) 2989*cdf0e10cSrcweir { 2990*cdf0e10cSrcweir try 2991*cdf0e10cSrcweir { 2992*cdf0e10cSrcweir return uno::Reference< io::XOutputStream >( 2993*cdf0e10cSrcweir pProvider->queryOutputStream( 2994*cdf0e10cSrcweir rUri, aPassword, true /* truncate */ ) ); 2995*cdf0e10cSrcweir } 2996*cdf0e10cSrcweir catch ( packages::WrongPasswordException const & ) 2997*cdf0e10cSrcweir { 2998*cdf0e10cSrcweir // Obtain (new) password. 2999*cdf0e10cSrcweir aPassword 3000*cdf0e10cSrcweir = obtainPassword( rUri, /* @@@ find better title */ 3001*cdf0e10cSrcweir bPasswordRequested 3002*cdf0e10cSrcweir ? task::PasswordRequestMode_PASSWORD_REENTER 3003*cdf0e10cSrcweir : task::PasswordRequestMode_PASSWORD_ENTER, 3004*cdf0e10cSrcweir xEnv ); 3005*cdf0e10cSrcweir bPasswordRequested = true; 3006*cdf0e10cSrcweir } 3007*cdf0e10cSrcweir } 3008*cdf0e10cSrcweir } 3009*cdf0e10cSrcweir 3010*cdf0e10cSrcweir //========================================================================= 3011*cdf0e10cSrcweir uno::Reference< io::XOutputStream > Content::getTruncatedOutputStream( 3012*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 3013*cdf0e10cSrcweir throw ( ucb::CommandFailedException, 3014*cdf0e10cSrcweir task::DocumentPasswordRequest ) 3015*cdf0e10cSrcweir { 3016*cdf0e10cSrcweir OSL_ENSURE( m_aProps.getType() == STREAM, 3017*cdf0e10cSrcweir "Content::getTruncatedOutputStream - content is no stream!" ); 3018*cdf0e10cSrcweir 3019*cdf0e10cSrcweir return lcl_getTruncatedOutputStream( 3020*cdf0e10cSrcweir Uri( m_xIdentifier->getContentIdentifier() ).getUri(), 3021*cdf0e10cSrcweir m_pProvider, 3022*cdf0e10cSrcweir xEnv ); 3023*cdf0e10cSrcweir } 3024*cdf0e10cSrcweir 3025*cdf0e10cSrcweir //========================================================================= 3026*cdf0e10cSrcweir uno::Reference< io::XStream > Content::getStream( 3027*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 3028*cdf0e10cSrcweir throw ( ucb::CommandFailedException, 3029*cdf0e10cSrcweir task::DocumentPasswordRequest ) 3030*cdf0e10cSrcweir { 3031*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 3032*cdf0e10cSrcweir 3033*cdf0e10cSrcweir OSL_ENSURE( m_aProps.getType() == STREAM, 3034*cdf0e10cSrcweir "Content::getStream - content is no stream!" ); 3035*cdf0e10cSrcweir 3036*cdf0e10cSrcweir rtl::OUString aUri( Uri( m_xIdentifier->getContentIdentifier() ).getUri() ); 3037*cdf0e10cSrcweir rtl::OUString aPassword; 3038*cdf0e10cSrcweir bool bPasswordRequested = false; 3039*cdf0e10cSrcweir for ( ;; ) 3040*cdf0e10cSrcweir { 3041*cdf0e10cSrcweir try 3042*cdf0e10cSrcweir { 3043*cdf0e10cSrcweir return uno::Reference< io::XStream >( 3044*cdf0e10cSrcweir m_pProvider->queryStream( 3045*cdf0e10cSrcweir aUri, aPassword, false /* no truncate */ ) ); 3046*cdf0e10cSrcweir } 3047*cdf0e10cSrcweir catch ( packages::WrongPasswordException const & ) 3048*cdf0e10cSrcweir { 3049*cdf0e10cSrcweir // Obtain (new) password. 3050*cdf0e10cSrcweir aPassword 3051*cdf0e10cSrcweir = obtainPassword( aUri, /* @@@ find better title */ 3052*cdf0e10cSrcweir bPasswordRequested 3053*cdf0e10cSrcweir ? task::PasswordRequestMode_PASSWORD_REENTER 3054*cdf0e10cSrcweir : task::PasswordRequestMode_PASSWORD_ENTER, 3055*cdf0e10cSrcweir xEnv ); 3056*cdf0e10cSrcweir bPasswordRequested = true; 3057*cdf0e10cSrcweir } 3058*cdf0e10cSrcweir } 3059*cdf0e10cSrcweir } 3060*cdf0e10cSrcweir 3061*cdf0e10cSrcweir //========================================================================= 3062*cdf0e10cSrcweir //========================================================================= 3063*cdf0e10cSrcweir // 3064*cdf0e10cSrcweir // ContentProperties Implementation. 3065*cdf0e10cSrcweir // 3066*cdf0e10cSrcweir //========================================================================= 3067*cdf0e10cSrcweir //========================================================================= 3068*cdf0e10cSrcweir 3069*cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > 3070*cdf0e10cSrcweir ContentProperties::getCreatableContentsInfo() const 3071*cdf0e10cSrcweir { 3072*cdf0e10cSrcweir if ( isContentCreator() ) 3073*cdf0e10cSrcweir { 3074*cdf0e10cSrcweir uno::Sequence< beans::Property > aProps( 1 ); 3075*cdf0e10cSrcweir aProps.getArray()[ 0 ] = beans::Property( 3076*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Title" ), 3077*cdf0e10cSrcweir -1, 3078*cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 3079*cdf0e10cSrcweir beans::PropertyAttribute::BOUND ); 3080*cdf0e10cSrcweir 3081*cdf0e10cSrcweir #ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 3082*cdf0e10cSrcweir if ( getType() == DOCUMENT ) 3083*cdf0e10cSrcweir { 3084*cdf0e10cSrcweir // streams cannot be created as direct children of document root 3085*cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > aSeq( 1 ); 3086*cdf0e10cSrcweir 3087*cdf0e10cSrcweir // Folder. 3088*cdf0e10cSrcweir aSeq.getArray()[ 0 ].Type 3089*cdf0e10cSrcweir = rtl::OUString::createFromAscii( TDOC_FOLDER_CONTENT_TYPE ); 3090*cdf0e10cSrcweir aSeq.getArray()[ 0 ].Attributes 3091*cdf0e10cSrcweir = ucb::ContentInfoAttribute::KIND_FOLDER; 3092*cdf0e10cSrcweir aSeq.getArray()[ 0 ].Properties = aProps; 3093*cdf0e10cSrcweir 3094*cdf0e10cSrcweir return aSeq; 3095*cdf0e10cSrcweir } 3096*cdf0e10cSrcweir else 3097*cdf0e10cSrcweir { 3098*cdf0e10cSrcweir #endif 3099*cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > aSeq( 2 ); 3100*cdf0e10cSrcweir 3101*cdf0e10cSrcweir // Folder. 3102*cdf0e10cSrcweir aSeq.getArray()[ 0 ].Type 3103*cdf0e10cSrcweir = rtl::OUString::createFromAscii( TDOC_FOLDER_CONTENT_TYPE ); 3104*cdf0e10cSrcweir aSeq.getArray()[ 0 ].Attributes 3105*cdf0e10cSrcweir = ucb::ContentInfoAttribute::KIND_FOLDER; 3106*cdf0e10cSrcweir aSeq.getArray()[ 0 ].Properties = aProps; 3107*cdf0e10cSrcweir 3108*cdf0e10cSrcweir // Stream. 3109*cdf0e10cSrcweir aSeq.getArray()[ 1 ].Type 3110*cdf0e10cSrcweir = rtl::OUString::createFromAscii( TDOC_STREAM_CONTENT_TYPE ); 3111*cdf0e10cSrcweir aSeq.getArray()[ 1 ].Attributes 3112*cdf0e10cSrcweir = ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM 3113*cdf0e10cSrcweir | ucb::ContentInfoAttribute::KIND_DOCUMENT; 3114*cdf0e10cSrcweir aSeq.getArray()[ 1 ].Properties = aProps; 3115*cdf0e10cSrcweir 3116*cdf0e10cSrcweir return aSeq; 3117*cdf0e10cSrcweir #ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 3118*cdf0e10cSrcweir } 3119*cdf0e10cSrcweir #endif 3120*cdf0e10cSrcweir } 3121*cdf0e10cSrcweir else 3122*cdf0e10cSrcweir { 3123*cdf0e10cSrcweir OSL_ENSURE( sal_False, 3124*cdf0e10cSrcweir "getCreatableContentsInfo called on non-contentcreator " 3125*cdf0e10cSrcweir "object!" ); 3126*cdf0e10cSrcweir 3127*cdf0e10cSrcweir return uno::Sequence< ucb::ContentInfo >( 0 ); 3128*cdf0e10cSrcweir } 3129*cdf0e10cSrcweir } 3130*cdf0e10cSrcweir 3131*cdf0e10cSrcweir //========================================================================= 3132*cdf0e10cSrcweir bool ContentProperties::isContentCreator() const 3133*cdf0e10cSrcweir { 3134*cdf0e10cSrcweir return ( getType() == FOLDER ) || ( getType() == DOCUMENT ); 3135*cdf0e10cSrcweir } 3136