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 "rtl/ustrbuf.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include "com/sun/star/container/XNameAccess.hpp" 40*cdf0e10cSrcweir #include "com/sun/star/embed/XStorage.hpp" 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include "ucbhelper/contentidentifier.hxx" 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include "tdoc_provider.hxx" 45*cdf0e10cSrcweir #include "tdoc_content.hxx" 46*cdf0e10cSrcweir #include "tdoc_uri.hxx" 47*cdf0e10cSrcweir #include "tdoc_docmgr.hxx" 48*cdf0e10cSrcweir #include "tdoc_storage.hxx" 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir using namespace com::sun::star; 51*cdf0e10cSrcweir using namespace tdoc_ucp; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir //========================================================================= 54*cdf0e10cSrcweir //========================================================================= 55*cdf0e10cSrcweir // 56*cdf0e10cSrcweir // ContentProvider Implementation. 57*cdf0e10cSrcweir // 58*cdf0e10cSrcweir //========================================================================= 59*cdf0e10cSrcweir //========================================================================= 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir ContentProvider::ContentProvider( 62*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& xSMgr ) 63*cdf0e10cSrcweir : ::ucbhelper::ContentProviderImplHelper( xSMgr ), 64*cdf0e10cSrcweir m_xDocsMgr( new OfficeDocumentsManager( xSMgr, this ) ), 65*cdf0e10cSrcweir m_xStgElemFac( new StorageElementFactory( xSMgr, m_xDocsMgr ) ) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir //========================================================================= 70*cdf0e10cSrcweir // virtual 71*cdf0e10cSrcweir ContentProvider::~ContentProvider() 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir if ( m_xDocsMgr.is() ) 74*cdf0e10cSrcweir m_xDocsMgr->destroy(); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir //========================================================================= 78*cdf0e10cSrcweir // 79*cdf0e10cSrcweir // XInterface methods. 80*cdf0e10cSrcweir // 81*cdf0e10cSrcweir //========================================================================= 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir XINTERFACE_IMPL_4( ContentProvider, 84*cdf0e10cSrcweir lang::XTypeProvider, 85*cdf0e10cSrcweir lang::XServiceInfo, 86*cdf0e10cSrcweir ucb::XContentProvider, 87*cdf0e10cSrcweir frame::XTransientDocumentsDocumentContentFactory ); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir //========================================================================= 90*cdf0e10cSrcweir // 91*cdf0e10cSrcweir // XTypeProvider methods. 92*cdf0e10cSrcweir // 93*cdf0e10cSrcweir //========================================================================= 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir XTYPEPROVIDER_IMPL_4( ContentProvider, 96*cdf0e10cSrcweir lang::XTypeProvider, 97*cdf0e10cSrcweir lang::XServiceInfo, 98*cdf0e10cSrcweir ucb::XContentProvider, 99*cdf0e10cSrcweir frame::XTransientDocumentsDocumentContentFactory ); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir //========================================================================= 102*cdf0e10cSrcweir // 103*cdf0e10cSrcweir // XServiceInfo methods. 104*cdf0e10cSrcweir // 105*cdf0e10cSrcweir //========================================================================= 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir XSERVICEINFO_IMPL_1( 108*cdf0e10cSrcweir ContentProvider, 109*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 110*cdf0e10cSrcweir "com.sun.star.comp.ucb.TransientDocumentsContentProvider" ) ), 111*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 112*cdf0e10cSrcweir TDOC_CONTENT_PROVIDER_SERVICE_NAME ) ) ); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir //========================================================================= 115*cdf0e10cSrcweir // 116*cdf0e10cSrcweir // Service factory implementation. 117*cdf0e10cSrcweir // 118*cdf0e10cSrcweir //========================================================================= 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider ); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir //========================================================================= 123*cdf0e10cSrcweir // 124*cdf0e10cSrcweir // XContentProvider methods. 125*cdf0e10cSrcweir // 126*cdf0e10cSrcweir //========================================================================= 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir // virtual 129*cdf0e10cSrcweir uno::Reference< ucb::XContent > SAL_CALL 130*cdf0e10cSrcweir ContentProvider::queryContent( 131*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& Identifier ) 132*cdf0e10cSrcweir throw( ucb::IllegalIdentifierException, uno::RuntimeException ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir Uri aUri( Identifier->getContentIdentifier() ); 135*cdf0e10cSrcweir if ( !aUri.isValid() ) 136*cdf0e10cSrcweir throw ucb::IllegalIdentifierException( 137*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid URL!" ) ), 138*cdf0e10cSrcweir Identifier ); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir // Normalize URI. 141*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xCanonicId 142*cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( m_xSMgr, aUri.getUri() ); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // Check, if a content with given id already exists... 147*cdf0e10cSrcweir uno::Reference< ucb::XContent > xContent 148*cdf0e10cSrcweir = queryExistingContent( xCanonicId ).get(); 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir if ( !xContent.is() ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir // Create a new content. 153*cdf0e10cSrcweir xContent = Content::create( m_xSMgr, this, xCanonicId ); 154*cdf0e10cSrcweir registerNewContent( xContent ); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir return xContent; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir //========================================================================= 161*cdf0e10cSrcweir // 162*cdf0e10cSrcweir // XTransientDocumentsDocumentContentFactory methods. 163*cdf0e10cSrcweir // 164*cdf0e10cSrcweir //========================================================================= 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir // virtual 167*cdf0e10cSrcweir uno::Reference< ucb::XContent > SAL_CALL 168*cdf0e10cSrcweir ContentProvider::createDocumentContent( 169*cdf0e10cSrcweir const uno::Reference< frame::XModel >& Model ) 170*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, uno::RuntimeException ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir // model -> id -> content identifier -> queryContent 173*cdf0e10cSrcweir if ( m_xDocsMgr.is() ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir rtl::OUString aDocId = m_xDocsMgr->queryDocumentId( Model ); 176*cdf0e10cSrcweir if ( aDocId.getLength() > 0 ) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir rtl::OUStringBuffer aBuffer; 179*cdf0e10cSrcweir aBuffer.appendAscii( TDOC_URL_SCHEME ":/" ); 180*cdf0e10cSrcweir aBuffer.append( aDocId ); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xId 183*cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( 184*cdf0e10cSrcweir m_xSMgr, aBuffer.makeStringAndClear() ); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir // Check, if a content with given id already exists... 189*cdf0e10cSrcweir uno::Reference< ucb::XContent > xContent 190*cdf0e10cSrcweir = queryExistingContent( xId ).get(); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir if ( !xContent.is() ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir // Create a new content. 195*cdf0e10cSrcweir xContent = Content::create( m_xSMgr, this, xId ); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir if ( xContent.is() ) 199*cdf0e10cSrcweir return xContent; 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir // no content. 202*cdf0e10cSrcweir throw lang::IllegalArgumentException( 203*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 204*cdf0e10cSrcweir "Illegal Content Identifier!" ) ), 205*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 206*cdf0e10cSrcweir 1 ); 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir else 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir throw lang::IllegalArgumentException( 211*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 212*cdf0e10cSrcweir "Unable to obtain document id from model!" ) ), 213*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 214*cdf0e10cSrcweir 1 ); 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir else 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir throw lang::IllegalArgumentException( 220*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 221*cdf0e10cSrcweir "No Document Manager!" ) ), 222*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), 223*cdf0e10cSrcweir 1 ); 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir //========================================================================= 228*cdf0e10cSrcweir // 229*cdf0e10cSrcweir // interface OfficeDocumentsEventListener 230*cdf0e10cSrcweir // 231*cdf0e10cSrcweir //========================================================================= 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir // virtual 234*cdf0e10cSrcweir void ContentProvider::notifyDocumentClosed( const rtl::OUString & rDocId ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir osl::MutexGuard aGuard( getContentListMutex() ); 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir ::ucbhelper::ContentRefList aAllContents; 239*cdf0e10cSrcweir queryExistingContents( aAllContents ); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir ::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin(); 242*cdf0e10cSrcweir ::ucbhelper::ContentRefList::const_iterator end = aAllContents.end(); 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir // Notify all content objects related to the closed doc. 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir bool bFoundDocumentContent = false; 247*cdf0e10cSrcweir rtl::Reference< Content > xRoot; 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir while ( it != end ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir Uri aUri( (*it)->getIdentifier()->getContentIdentifier() ); 252*cdf0e10cSrcweir OSL_ENSURE( aUri.isValid(), 253*cdf0e10cSrcweir "ContentProvider::notifyDocumentClosed - Invalid URI!" ); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir if ( !bFoundDocumentContent ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir if ( aUri.isRoot() ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir xRoot = static_cast< Content * >( (*it).get() ); 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir else if ( aUri.isDocument() ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir if ( aUri.getDocumentId() == rDocId ) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir bFoundDocumentContent = true; 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir // document content will notify removal of child itself; 268*cdf0e10cSrcweir // no need for the root to propagate this. 269*cdf0e10cSrcweir xRoot.clear(); 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir if ( aUri.getDocumentId() == rDocId ) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir // Inform content. 277*cdf0e10cSrcweir rtl::Reference< Content > xContent 278*cdf0e10cSrcweir = static_cast< Content * >( (*it).get() ); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir xContent->notifyDocumentClosed(); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir ++it; 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir if ( xRoot.is() ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir // No document content found for rDocId but root content 289*cdf0e10cSrcweir // instanciated. Root content must announce document removal 290*cdf0e10cSrcweir // to content event listeners. 291*cdf0e10cSrcweir xRoot->notifyChildRemoved( rDocId ); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir //========================================================================= 296*cdf0e10cSrcweir // virtual 297*cdf0e10cSrcweir void ContentProvider::notifyDocumentOpened( const rtl::OUString & rDocId ) 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir osl::MutexGuard aGuard( getContentListMutex() ); 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir ::ucbhelper::ContentRefList aAllContents; 302*cdf0e10cSrcweir queryExistingContents( aAllContents ); 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir ::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin(); 305*cdf0e10cSrcweir ::ucbhelper::ContentRefList::const_iterator end = aAllContents.end(); 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir // Find root content. If instanciated let it propagate document insertion. 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir while ( it != end ) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir Uri aUri( (*it)->getIdentifier()->getContentIdentifier() ); 312*cdf0e10cSrcweir OSL_ENSURE( aUri.isValid(), 313*cdf0e10cSrcweir "ContentProvider::notifyDocumentOpened - Invalid URI!" ); 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir if ( aUri.isRoot() ) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir rtl::Reference< Content > xRoot 318*cdf0e10cSrcweir = static_cast< Content * >( (*it).get() ); 319*cdf0e10cSrcweir xRoot->notifyChildInserted( rDocId ); 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir // Done. 322*cdf0e10cSrcweir break; 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir ++it; 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir //========================================================================= 330*cdf0e10cSrcweir // 331*cdf0e10cSrcweir // Non-UNO 332*cdf0e10cSrcweir // 333*cdf0e10cSrcweir //========================================================================= 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir uno::Reference< embed::XStorage > 336*cdf0e10cSrcweir ContentProvider::queryStorage( const rtl::OUString & rUri, 337*cdf0e10cSrcweir StorageAccessMode eMode ) const 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir if ( m_xStgElemFac.is() ) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir try 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir return m_xStgElemFac->createStorage( rUri, eMode ); 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir catch ( embed::InvalidStorageException const & ) 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir OSL_ENSURE( false, "Caught InvalidStorageException!" ); 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 350*cdf0e10cSrcweir { 351*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IllegalArgumentException!" ); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir catch ( io::IOException const & ) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir // Okay to happen, for instance when the storage does not exist. 356*cdf0e10cSrcweir //OSL_ENSURE( false, "Caught IOException!" ); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir catch ( embed::StorageWrappedTargetException const & ) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir OSL_ENSURE( false, "Caught embed::StorageWrappedTargetException!" ); 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir return uno::Reference< embed::XStorage >(); 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir //========================================================================= 367*cdf0e10cSrcweir uno::Reference< embed::XStorage > 368*cdf0e10cSrcweir ContentProvider::queryStorageClone( const rtl::OUString & rUri ) const 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir if ( m_xStgElemFac.is() ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir try 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir Uri aUri( rUri ); 375*cdf0e10cSrcweir uno::Reference< embed::XStorage > xParentStorage 376*cdf0e10cSrcweir = m_xStgElemFac->createStorage( aUri.getParentUri(), READ ); 377*cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage 378*cdf0e10cSrcweir = m_xStgElemFac->createTemporaryStorage(); 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir xParentStorage->copyStorageElementLastCommitTo( 381*cdf0e10cSrcweir aUri.getDecodedName(), xStorage ); 382*cdf0e10cSrcweir return xStorage; 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir catch ( embed::InvalidStorageException const & ) 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir OSL_ENSURE( false, "Caught InvalidStorageException!" ); 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IllegalArgumentException!" ); 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir catch ( io::IOException const & ) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir // Okay to happen, for instance when the storage does not exist. 395*cdf0e10cSrcweir //OSL_ENSURE( false, "Caught IOException!" ); 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir catch ( embed::StorageWrappedTargetException const & ) 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir OSL_ENSURE( false, "Caught embed::StorageWrappedTargetException!" ); 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir return uno::Reference< embed::XStorage >(); 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir //========================================================================= 407*cdf0e10cSrcweir uno::Reference< io::XInputStream > 408*cdf0e10cSrcweir ContentProvider::queryInputStream( const rtl::OUString & rUri, 409*cdf0e10cSrcweir const rtl::OUString & rPassword ) const 410*cdf0e10cSrcweir throw ( packages::WrongPasswordException ) 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir if ( m_xStgElemFac.is() ) 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir try 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir return m_xStgElemFac->createInputStream( rUri, rPassword ); 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir catch ( embed::InvalidStorageException const & ) 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir OSL_ENSURE( false, "Caught InvalidStorageException!" ); 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IllegalArgumentException!" ); 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir catch ( io::IOException const & ) 427*cdf0e10cSrcweir { 428*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IOException!" ); 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir catch ( embed::StorageWrappedTargetException const & ) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir OSL_ENSURE( false, "Caught embed::StorageWrappedTargetException!" ); 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir // catch ( packages::WrongPasswordException const & ) 435*cdf0e10cSrcweir // { 436*cdf0e10cSrcweir // // the key provided is wrong; rethrow; to be handled by caller. 437*cdf0e10cSrcweir // throw; 438*cdf0e10cSrcweir // } 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir return uno::Reference< io::XInputStream >(); 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir //========================================================================= 444*cdf0e10cSrcweir uno::Reference< io::XOutputStream > 445*cdf0e10cSrcweir ContentProvider::queryOutputStream( const rtl::OUString & rUri, 446*cdf0e10cSrcweir const rtl::OUString & rPassword, 447*cdf0e10cSrcweir bool bTruncate ) const 448*cdf0e10cSrcweir throw ( packages::WrongPasswordException ) 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir if ( m_xStgElemFac.is() ) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir try 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir return 455*cdf0e10cSrcweir m_xStgElemFac->createOutputStream( rUri, rPassword, bTruncate ); 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir catch ( embed::InvalidStorageException const & ) 458*cdf0e10cSrcweir { 459*cdf0e10cSrcweir OSL_ENSURE( false, "Caught InvalidStorageException!" ); 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IllegalArgumentException!" ); 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir catch ( io::IOException const & ) 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir // Okay to happen, for instance when the storage does not exist. 468*cdf0e10cSrcweir //OSL_ENSURE( false, "Caught IOException!" ); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir catch ( embed::StorageWrappedTargetException const & ) 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir OSL_ENSURE( false, "Caught embed::StorageWrappedTargetException!" ); 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir // catch ( packages::WrongPasswordException const & ) 475*cdf0e10cSrcweir // { 476*cdf0e10cSrcweir // // the key provided is wrong; rethrow; to be handled by caller. 477*cdf0e10cSrcweir // throw; 478*cdf0e10cSrcweir // } 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir return uno::Reference< io::XOutputStream >(); 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir //========================================================================= 484*cdf0e10cSrcweir uno::Reference< io::XStream > 485*cdf0e10cSrcweir ContentProvider::queryStream( const rtl::OUString & rUri, 486*cdf0e10cSrcweir const rtl::OUString & rPassword, 487*cdf0e10cSrcweir bool bTruncate ) const 488*cdf0e10cSrcweir throw ( packages::WrongPasswordException ) 489*cdf0e10cSrcweir { 490*cdf0e10cSrcweir if ( m_xStgElemFac.is() ) 491*cdf0e10cSrcweir { 492*cdf0e10cSrcweir try 493*cdf0e10cSrcweir { 494*cdf0e10cSrcweir return m_xStgElemFac->createStream( rUri, rPassword, bTruncate ); 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir catch ( embed::InvalidStorageException const & ) 497*cdf0e10cSrcweir { 498*cdf0e10cSrcweir OSL_ENSURE( false, "Caught InvalidStorageException!" ); 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IllegalArgumentException!" ); 503*cdf0e10cSrcweir } 504*cdf0e10cSrcweir catch ( io::IOException const & ) 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir // Okay to happen, for instance when the storage does not exist. 507*cdf0e10cSrcweir //OSL_ENSURE( false, "Caught IOException!" ); 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir catch ( embed::StorageWrappedTargetException const & ) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir OSL_ENSURE( false, "Caught embed::StorageWrappedTargetException!" ); 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir // catch ( packages::WrongPasswordException const & ) 514*cdf0e10cSrcweir // { 515*cdf0e10cSrcweir // // the key provided is wrong; rethrow; to be handled by caller. 516*cdf0e10cSrcweir // throw; 517*cdf0e10cSrcweir // } 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir return uno::Reference< io::XStream >(); 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir //========================================================================= 523*cdf0e10cSrcweir bool ContentProvider::queryNamesOfChildren( 524*cdf0e10cSrcweir const rtl::OUString & rUri, uno::Sequence< rtl::OUString > & rNames ) const 525*cdf0e10cSrcweir { 526*cdf0e10cSrcweir Uri aUri( rUri ); 527*cdf0e10cSrcweir if ( aUri.isRoot() ) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir // special handling for root, which has no storage, but children. 530*cdf0e10cSrcweir if ( m_xDocsMgr.is() ) 531*cdf0e10cSrcweir { 532*cdf0e10cSrcweir rNames = m_xDocsMgr->queryDocuments(); 533*cdf0e10cSrcweir return true; 534*cdf0e10cSrcweir } 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir else 537*cdf0e10cSrcweir { 538*cdf0e10cSrcweir if ( m_xStgElemFac.is() ) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir try 541*cdf0e10cSrcweir { 542*cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage 543*cdf0e10cSrcweir = m_xStgElemFac->createStorage( rUri, READ ); 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir OSL_ENSURE( xStorage.is(), "Got no Storage!" ); 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir if ( xStorage.is() ) 548*cdf0e10cSrcweir { 549*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNA( 550*cdf0e10cSrcweir xStorage, uno::UNO_QUERY ); 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir OSL_ENSURE( xNA.is(), "Got no css.container.XNameAccess!" ); 553*cdf0e10cSrcweir if ( xNA.is() ) 554*cdf0e10cSrcweir { 555*cdf0e10cSrcweir rNames = xNA->getElementNames(); 556*cdf0e10cSrcweir return true; 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir } 559*cdf0e10cSrcweir } 560*cdf0e10cSrcweir catch ( embed::InvalidStorageException const & ) 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir OSL_ENSURE( false, "Caught InvalidStorageException!" ); 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 565*cdf0e10cSrcweir { 566*cdf0e10cSrcweir OSL_ENSURE( false, "Caught IllegalArgumentException!" ); 567*cdf0e10cSrcweir } 568*cdf0e10cSrcweir catch ( io::IOException const & ) 569*cdf0e10cSrcweir { 570*cdf0e10cSrcweir // Okay to happen, for instance if the storage does not exist. 571*cdf0e10cSrcweir //OSL_ENSURE( false, "Caught IOException!" ); 572*cdf0e10cSrcweir } 573*cdf0e10cSrcweir catch ( embed::StorageWrappedTargetException const & ) 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir OSL_ENSURE( false, 576*cdf0e10cSrcweir "Caught embed::StorageWrappedTargetException!" ); 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir } 579*cdf0e10cSrcweir } 580*cdf0e10cSrcweir return false; 581*cdf0e10cSrcweir } 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir //========================================================================= 584*cdf0e10cSrcweir rtl::OUString 585*cdf0e10cSrcweir ContentProvider::queryStorageTitle( const rtl::OUString & rUri ) const 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir rtl::OUString aTitle; 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir Uri aUri( rUri ); 590*cdf0e10cSrcweir if ( aUri.isRoot() ) 591*cdf0e10cSrcweir { 592*cdf0e10cSrcweir // always empty. 593*cdf0e10cSrcweir aTitle = rtl::OUString(); 594*cdf0e10cSrcweir } 595*cdf0e10cSrcweir else if ( aUri.isDocument() ) 596*cdf0e10cSrcweir { 597*cdf0e10cSrcweir // for documents, title shall not be derived from URL. It shall 598*cdf0e10cSrcweir // be somethimg more 'speaking' than just the document UID. 599*cdf0e10cSrcweir if ( m_xDocsMgr.is() ) 600*cdf0e10cSrcweir aTitle = m_xDocsMgr->queryStorageTitle( aUri.getDocumentId() ); 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir else 603*cdf0e10cSrcweir { 604*cdf0e10cSrcweir // derive title from URL 605*cdf0e10cSrcweir aTitle = aUri.getDecodedName(); 606*cdf0e10cSrcweir } 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir OSL_ENSURE( ( aTitle.getLength() > 0 ) || aUri.isRoot(), 609*cdf0e10cSrcweir "ContentProvider::queryStorageTitle - empty title!" ); 610*cdf0e10cSrcweir return aTitle; 611*cdf0e10cSrcweir } 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir //========================================================================= 614*cdf0e10cSrcweir uno::Reference< frame::XModel > 615*cdf0e10cSrcweir ContentProvider::queryDocumentModel( const rtl::OUString & rUri ) const 616*cdf0e10cSrcweir { 617*cdf0e10cSrcweir uno::Reference< frame::XModel > xModel; 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir if ( m_xDocsMgr.is() ) 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir Uri aUri( rUri ); 622*cdf0e10cSrcweir xModel = m_xDocsMgr->queryDocumentModel( aUri.getDocumentId() ); 623*cdf0e10cSrcweir } 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir OSL_ENSURE( xModel.is(), 626*cdf0e10cSrcweir "ContentProvider::queryDocumentModel - no model!" ); 627*cdf0e10cSrcweir return xModel; 628*cdf0e10cSrcweir } 629*cdf0e10cSrcweir 630