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