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_embeddedobj.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <commonembobj.hxx> 32*cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/document/XStorageBasedDocument.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedVerbs.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/embed/EntryInitModes.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/embed/XOptimizedStorage.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedUpdateModes.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/frame/XLoadable.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/frame/XModule.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCEESS_HPP_ 52*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 53*cdf0e10cSrcweir #endif 54*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 55*cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp> 56*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 57*cdf0e10cSrcweir #include <com/sun/star/beans/IllegalTypeException.hpp> 58*cdf0e10cSrcweir #include <com/sun/star/chart2/XChartDocument.hpp> 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #include <comphelper/fileformat.h> 61*cdf0e10cSrcweir #include <comphelper/storagehelper.hxx> 62*cdf0e10cSrcweir #include <comphelper/mimeconfighelper.hxx> 63*cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx> 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir #include <rtl/logfile.hxx> 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir #define USE_STORAGEBASED_DOCUMENT 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir using namespace ::com::sun::star; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir //------------------------------------------------------ 75*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > GetValuableArgs_Impl( const uno::Sequence< beans::PropertyValue >& aMedDescr, 76*cdf0e10cSrcweir sal_Bool bCanUseDocumentBaseURL ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aResult; 79*cdf0e10cSrcweir sal_Int32 nResLen = 0; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aMedDescr.getLength(); nInd++ ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir if ( aMedDescr[nInd].Name.equalsAscii( "ComponentData" ) 84*cdf0e10cSrcweir || aMedDescr[nInd].Name.equalsAscii( "DocumentTitle" ) 85*cdf0e10cSrcweir || aMedDescr[nInd].Name.equalsAscii( "InteractionHandler" ) 86*cdf0e10cSrcweir || aMedDescr[nInd].Name.equalsAscii( "JumpMark" ) 87*cdf0e10cSrcweir // || aMedDescr[nInd].Name.equalsAscii( "Password" ) makes no sence for embedded objects 88*cdf0e10cSrcweir || aMedDescr[nInd].Name.equalsAscii( "Preview" ) 89*cdf0e10cSrcweir || aMedDescr[nInd].Name.equalsAscii( "ReadOnly" ) 90*cdf0e10cSrcweir || aMedDescr[nInd].Name.equalsAscii( "StartPresentation" ) 91*cdf0e10cSrcweir || aMedDescr[nInd].Name.equalsAscii( "RepairPackage" ) 92*cdf0e10cSrcweir || aMedDescr[nInd].Name.equalsAscii( "StatusIndicator" ) 93*cdf0e10cSrcweir || aMedDescr[nInd].Name.equalsAscii( "ViewData" ) 94*cdf0e10cSrcweir || aMedDescr[nInd].Name.equalsAscii( "ViewId" ) 95*cdf0e10cSrcweir || aMedDescr[nInd].Name.equalsAscii( "MacroExecutionMode" ) 96*cdf0e10cSrcweir || aMedDescr[nInd].Name.equalsAscii( "UpdateDocMode" ) 97*cdf0e10cSrcweir || (aMedDescr[nInd].Name.equalsAscii( "DocumentBaseURL" ) && bCanUseDocumentBaseURL) ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir aResult.realloc( ++nResLen ); 100*cdf0e10cSrcweir aResult[nResLen-1] = aMedDescr[nInd]; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir return aResult; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir //------------------------------------------------------ 108*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > addAsTemplate( const uno::Sequence< beans::PropertyValue >& aOrig ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir sal_Bool bAsTemplateSet = sal_False; 111*cdf0e10cSrcweir sal_Int32 nLength = aOrig.getLength(); 112*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aResult( nLength ); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < nLength; nInd++ ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir aResult[nInd].Name = aOrig[nInd].Name; 117*cdf0e10cSrcweir if ( aResult[nInd].Name.equalsAscii( "AsTemplate" ) ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir aResult[nInd].Value <<= sal_True; 120*cdf0e10cSrcweir bAsTemplateSet = sal_True; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir else 123*cdf0e10cSrcweir aResult[nInd].Value = aOrig[nInd].Value; 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir if ( !bAsTemplateSet ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir aResult.realloc( nLength + 1 ); 129*cdf0e10cSrcweir aResult[nLength].Name = ::rtl::OUString::createFromAscii( "AsTemplate" ); 130*cdf0e10cSrcweir aResult[nLength].Value <<= sal_True; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir return aResult; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir //------------------------------------------------------ 137*cdf0e10cSrcweir uno::Reference< io::XInputStream > createTempInpStreamFromStor( 138*cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 139*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& xFactory ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir OSL_ENSURE( xStorage.is(), "The storage can not be empty!" ); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir uno::Reference< io::XInputStream > xResult; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) ); 146*cdf0e10cSrcweir uno::Reference < io::XStream > xTempStream = uno::Reference < io::XStream > ( 147*cdf0e10cSrcweir xFactory->createInstance ( aServiceName ), 148*cdf0e10cSrcweir uno::UNO_QUERY ); 149*cdf0e10cSrcweir if ( xTempStream.is() ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir uno::Reference < lang::XSingleServiceFactory > xStorageFactory( 152*cdf0e10cSrcweir xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.embed.StorageFactory" ) ), 153*cdf0e10cSrcweir uno::UNO_QUERY ); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 2 ); 156*cdf0e10cSrcweir aArgs[0] <<= xTempStream; 157*cdf0e10cSrcweir aArgs[1] <<= embed::ElementModes::READWRITE; 158*cdf0e10cSrcweir uno::Reference< embed::XStorage > xTempStorage( xStorageFactory->createInstanceWithArguments( aArgs ), 159*cdf0e10cSrcweir uno::UNO_QUERY ); 160*cdf0e10cSrcweir if ( !xTempStorage.is() ) 161*cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir try 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir xStorage->copyToStorage( xTempStorage ); 166*cdf0e10cSrcweir } catch( uno::Exception& e ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir throw embed::StorageWrappedTargetException( 169*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Can't copy storage!" ), 170*cdf0e10cSrcweir uno::Reference< uno::XInterface >(), 171*cdf0e10cSrcweir uno::makeAny( e ) ); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir try { 175*cdf0e10cSrcweir uno::Reference< lang::XComponent > xComponent( xTempStorage, uno::UNO_QUERY ); 176*cdf0e10cSrcweir OSL_ENSURE( xComponent.is(), "Wrong storage implementation!" ); 177*cdf0e10cSrcweir if ( xComponent.is() ) 178*cdf0e10cSrcweir xComponent->dispose(); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir catch ( uno::Exception& ) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir try { 185*cdf0e10cSrcweir uno::Reference< io::XOutputStream > xTempOut = xTempStream->getOutputStream(); 186*cdf0e10cSrcweir if ( xTempOut.is() ) 187*cdf0e10cSrcweir xTempOut->closeOutput(); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir catch ( uno::Exception& ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir xResult = xTempStream->getInputStream(); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir return xResult; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir //------------------------------------------------------ 201*cdf0e10cSrcweir static void TransferMediaType( const uno::Reference< embed::XStorage >& i_rSource, const uno::Reference< embed::XStorage >& i_rTarget ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir try 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir const uno::Reference< beans::XPropertySet > xSourceProps( i_rSource, uno::UNO_QUERY_THROW ); 206*cdf0e10cSrcweir const uno::Reference< beans::XPropertySet > xTargetProps( i_rTarget, uno::UNO_QUERY_THROW ); 207*cdf0e10cSrcweir const ::rtl::OUString sMediaTypePropName( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); 208*cdf0e10cSrcweir xTargetProps->setPropertyValue( sMediaTypePropName, xSourceProps->getPropertyValue( sMediaTypePropName ) ); 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir catch( const uno::Exception& ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir //------------------------------------------------------ 217*cdf0e10cSrcweir static uno::Reference< util::XCloseable > CreateDocument( const uno::Reference< lang::XMultiServiceFactory >& _rxFactory, 218*cdf0e10cSrcweir const ::rtl::OUString& _rDocumentServiceName, bool _bEmbeddedScriptSupport, const bool i_bDocumentRecoverySupport ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir ::comphelper::NamedValueCollection aArguments; 221*cdf0e10cSrcweir aArguments.put( "EmbeddedObject", (sal_Bool)sal_True ); 222*cdf0e10cSrcweir aArguments.put( "EmbeddedScriptSupport", (sal_Bool)_bEmbeddedScriptSupport ); 223*cdf0e10cSrcweir aArguments.put( "DocumentRecoverySupport", (sal_Bool)i_bDocumentRecoverySupport ); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir uno::Reference< uno::XInterface > xDocument; 226*cdf0e10cSrcweir try 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir xDocument = _rxFactory->createInstanceWithArguments( _rDocumentServiceName, aArguments.getWrappedPropertyValues() ); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir catch( const uno::Exception& ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir // if an embedded object implementation does not support XInitialization, 233*cdf0e10cSrcweir // the default factory from cppuhelper will throw an 234*cdf0e10cSrcweir // IllegalArgumentException when we try to create the instance with arguments. 235*cdf0e10cSrcweir // Okay, so we fall back to creating the instance without any arguments. 236*cdf0e10cSrcweir OSL_ASSERT("Consider implementing interface XInitialization to avoid duplicate construction"); 237*cdf0e10cSrcweir xDocument = _rxFactory->createInstance( _rDocumentServiceName ); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir return uno::Reference< util::XCloseable >( xDocument, uno::UNO_QUERY ); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir //------------------------------------------------------ 244*cdf0e10cSrcweir static void SetDocToEmbedded( const uno::Reference< frame::XModel > xDocument, const ::rtl::OUString& aModuleName ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir if ( xDocument.is() ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aSeq( 1 ); 249*cdf0e10cSrcweir aSeq[0].Name = ::rtl::OUString::createFromAscii( "SetEmbedded" ); 250*cdf0e10cSrcweir aSeq[0].Value <<= sal_True; 251*cdf0e10cSrcweir xDocument->attachResource( ::rtl::OUString(), aSeq ); 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir if ( aModuleName.getLength() ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir try 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir uno::Reference< frame::XModule > xModule( xDocument, uno::UNO_QUERY_THROW ); 258*cdf0e10cSrcweir xModule->setIdentifier( aModuleName ); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir catch( uno::Exception& ) 261*cdf0e10cSrcweir {} 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir //------------------------------------------------------ 267*cdf0e10cSrcweir void OCommonEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage, 268*cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xNewObjectStorage, 269*cdf0e10cSrcweir const ::rtl::OUString& aNewName ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir if ( xNewParentStorage == m_xParentStorage && aNewName.equals( m_aEntryName ) ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir OSL_ENSURE( xNewObjectStorage == m_xObjectStorage, "The storage must be the same!\n" ); 274*cdf0e10cSrcweir return; 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir uno::Reference< lang::XComponent > xComponent( m_xObjectStorage, uno::UNO_QUERY ); 278*cdf0e10cSrcweir OSL_ENSURE( !m_xObjectStorage.is() || xComponent.is(), "Wrong storage implementation!" ); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir m_xObjectStorage = xNewObjectStorage; 281*cdf0e10cSrcweir m_xParentStorage = xNewParentStorage; 282*cdf0e10cSrcweir m_aEntryName = aNewName; 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir #ifdef USE_STORAGEBASED_DOCUMENT 285*cdf0e10cSrcweir // the linked document should not be switched 286*cdf0e10cSrcweir if ( !m_bIsLink ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir uno::Reference< document::XStorageBasedDocument > xDoc( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 289*cdf0e10cSrcweir if ( xDoc.is() ) 290*cdf0e10cSrcweir SwitchDocToStorage_Impl( xDoc, m_xObjectStorage ); 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir #endif 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir try { 295*cdf0e10cSrcweir if ( xComponent.is() ) 296*cdf0e10cSrcweir xComponent->dispose(); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir catch ( uno::Exception& ) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir //------------------------------------------------------ 304*cdf0e10cSrcweir void OCommonEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage, 305*cdf0e10cSrcweir const ::rtl::OUString& aNewName ) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir if ( xNewParentStorage == m_xParentStorage && aNewName.equals( m_aEntryName ) ) 308*cdf0e10cSrcweir return; 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE; 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir uno::Reference< embed::XStorage > xNewOwnStorage = xNewParentStorage->openStorageElement( aNewName, nStorageMode ); 313*cdf0e10cSrcweir OSL_ENSURE( xNewOwnStorage.is(), "The method can not return empty reference!" ); 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir SwitchOwnPersistence( xNewParentStorage, xNewOwnStorage, aNewName ); 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir //------------------------------------------------------ 319*cdf0e10cSrcweir void OCommonEmbeddedObject::EmbedAndReparentDoc_Impl( const uno::Reference< util::XCloseable >& i_rxDocument ) const 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir SetDocToEmbedded( uno::Reference< frame::XModel >( i_rxDocument, uno::UNO_QUERY ), m_aModuleName ); 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir try 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir uno::Reference < container::XChild > xChild( i_rxDocument, uno::UNO_QUERY ); 326*cdf0e10cSrcweir if ( xChild.is() ) 327*cdf0e10cSrcweir xChild->setParent( m_xParent ); 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir catch( const lang::NoSupportException & ) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir OSL_ENSURE( false, "OCommonEmbeddedObject::EmbedAndReparentDoc: cannot set parent at document!" ); 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir //------------------------------------------------------ 336*cdf0e10cSrcweir uno::Reference< util::XCloseable > OCommonEmbeddedObject::InitNewDocument_Impl() 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir uno::Reference< util::XCloseable > xDocument( CreateDocument( m_xFactory, GetDocumentServiceName(), 339*cdf0e10cSrcweir m_bEmbeddedScriptSupport, m_bDocumentRecoverySupport ) ); 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( xDocument, uno::UNO_QUERY ); 342*cdf0e10cSrcweir uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY ); 343*cdf0e10cSrcweir if ( !xLoadable.is() ) 344*cdf0e10cSrcweir throw uno::RuntimeException(); 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir try 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir // set the document mode to embedded as the first action on document!!! 349*cdf0e10cSrcweir EmbedAndReparentDoc_Impl( xDocument ); 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir // if we have a storage to recover the document from, do not use initNew, but instead load from that storage 352*cdf0e10cSrcweir bool bInitNew = true; 353*cdf0e10cSrcweir if ( m_xRecoveryStorage.is() ) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir uno::Reference< document::XStorageBasedDocument > xDoc( xLoadable, uno::UNO_QUERY ); 356*cdf0e10cSrcweir OSL_ENSURE( xDoc.is(), "OCommonEmbeddedObject::InitNewDocument_Impl: cannot recover from a storage when the document is not storage based!" ); 357*cdf0e10cSrcweir if ( xDoc.is() ) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir ::comphelper::NamedValueCollection aLoadArgs; 360*cdf0e10cSrcweir FillDefaultLoadArgs_Impl( m_xRecoveryStorage, aLoadArgs ); 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir xDoc->loadFromStorage( m_xRecoveryStorage, aLoadArgs.getPropertyValues() ); 363*cdf0e10cSrcweir SwitchDocToStorage_Impl( xDoc, m_xObjectStorage ); 364*cdf0e10cSrcweir bInitNew = false; 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir if ( bInitNew ) 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir // init document as a new 371*cdf0e10cSrcweir xLoadable->initNew(); 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir xModel->attachResource( xModel->getURL(), m_aDocMediaDescriptor ); 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir catch( uno::Exception& ) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir uno::Reference< util::XCloseable > xCloseable( xDocument, uno::UNO_QUERY ); 378*cdf0e10cSrcweir if ( xCloseable.is() ) 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir try 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir xCloseable->close( sal_True ); 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir catch( uno::Exception& ) 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir throw; // TODO 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir return xDocument; 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir //------------------------------------------------------ 396*cdf0e10cSrcweir uno::Reference< util::XCloseable > OCommonEmbeddedObject::LoadLink_Impl() 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir uno::Reference< util::XCloseable > xDocument( CreateDocument( m_xFactory, GetDocumentServiceName(), 399*cdf0e10cSrcweir m_bEmbeddedScriptSupport, m_bDocumentRecoverySupport ) ); 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY ); 402*cdf0e10cSrcweir if ( !xLoadable.is() ) 403*cdf0e10cSrcweir throw uno::RuntimeException(); 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir sal_Int32 nLen = 2; 406*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aArgs( nLen ); 407*cdf0e10cSrcweir aArgs[0].Name = ::rtl::OUString::createFromAscii( "URL" ); 408*cdf0e10cSrcweir aArgs[0].Value <<= m_aLinkURL; 409*cdf0e10cSrcweir aArgs[1].Name = ::rtl::OUString::createFromAscii( "FilterName" ); 410*cdf0e10cSrcweir aArgs[1].Value <<= m_aLinkFilterName; 411*cdf0e10cSrcweir if ( m_bLinkHasPassword ) 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir aArgs.realloc( ++nLen ); 414*cdf0e10cSrcweir aArgs[nLen-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ); 415*cdf0e10cSrcweir aArgs[nLen-1].Value <<= m_aLinkPassword; 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir aArgs.realloc( m_aDocMediaDescriptor.getLength() + nLen ); 419*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < m_aDocMediaDescriptor.getLength(); nInd++ ) 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir aArgs[nInd+nLen].Name = m_aDocMediaDescriptor[nInd].Name; 422*cdf0e10cSrcweir aArgs[nInd+nLen].Value = m_aDocMediaDescriptor[nInd].Value; 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir try 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir // the document is not really an embedded one, it is a link 428*cdf0e10cSrcweir EmbedAndReparentDoc_Impl( xDocument ); 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir // load the document 431*cdf0e10cSrcweir xLoadable->load( aArgs ); 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir if ( !m_bLinkHasPassword ) 434*cdf0e10cSrcweir { 435*cdf0e10cSrcweir // check if there is a password to cache 436*cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( xLoadable, uno::UNO_QUERY_THROW ); 437*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aProps = xModel->getArgs(); 438*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aProps.getLength(); nInd++ ) 439*cdf0e10cSrcweir if ( aProps[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ) ) 440*cdf0e10cSrcweir && ( aProps[nInd].Value >>= m_aLinkPassword ) ) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir m_bLinkHasPassword = sal_True; 443*cdf0e10cSrcweir break; 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir catch( uno::Exception& ) 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir uno::Reference< util::XCloseable > xCloseable( xDocument, uno::UNO_QUERY ); 450*cdf0e10cSrcweir if ( xCloseable.is() ) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir try 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir xCloseable->close( sal_True ); 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir catch( uno::Exception& ) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir throw; // TODO 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir return xDocument; 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir //------------------------------------------------------ 469*cdf0e10cSrcweir ::rtl::OUString OCommonEmbeddedObject::GetFilterName( sal_Int32 nVersion ) const 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir ::rtl::OUString aFilterName = GetPresetFilterName(); 472*cdf0e10cSrcweir if ( !aFilterName.getLength() ) 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir try { 475*cdf0e10cSrcweir ::comphelper::MimeConfigurationHelper aHelper( m_xFactory ); 476*cdf0e10cSrcweir aFilterName = aHelper.GetDefaultFilterFromServiceName( GetDocumentServiceName(), nVersion ); 477*cdf0e10cSrcweir } catch( uno::Exception& ) 478*cdf0e10cSrcweir {} 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir return aFilterName; 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir //------------------------------------------------------ 485*cdf0e10cSrcweir void OCommonEmbeddedObject::FillDefaultLoadArgs_Impl( const uno::Reference< embed::XStorage >& i_rxStorage, 486*cdf0e10cSrcweir ::comphelper::NamedValueCollection& o_rLoadArgs ) const 487*cdf0e10cSrcweir { 488*cdf0e10cSrcweir o_rLoadArgs.put( "DocumentBaseURL", GetBaseURL_Impl() ); 489*cdf0e10cSrcweir o_rLoadArgs.put( "HierarchicalDocumentName", m_aEntryName ); 490*cdf0e10cSrcweir o_rLoadArgs.put( "ReadOnly", m_bReadOnly ); 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir ::rtl::OUString aFilterName = GetFilterName( ::comphelper::OStorageHelper::GetXStorageFormat( i_rxStorage ) ); 493*cdf0e10cSrcweir OSL_ENSURE( aFilterName.getLength(), "OCommonEmbeddedObject::FillDefaultLoadArgs_Impl: Wrong document service name!" ); 494*cdf0e10cSrcweir if ( !aFilterName.getLength() ) 495*cdf0e10cSrcweir throw io::IOException(); // TODO: error message/code 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir o_rLoadArgs.put( "FilterName", aFilterName ); 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir //------------------------------------------------------ 501*cdf0e10cSrcweir uno::Reference< util::XCloseable > OCommonEmbeddedObject::LoadDocumentFromStorage_Impl() 502*cdf0e10cSrcweir { 503*cdf0e10cSrcweir ENSURE_OR_THROW( m_xObjectStorage.is(), "no object storage" ); 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir const uno::Reference< embed::XStorage > xSourceStorage( m_xRecoveryStorage.is() ? m_xRecoveryStorage : m_xObjectStorage ); 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir uno::Reference< util::XCloseable > xDocument( CreateDocument( m_xFactory, GetDocumentServiceName(), 508*cdf0e10cSrcweir m_bEmbeddedScriptSupport, m_bDocumentRecoverySupport ) ); 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir //#i103460# ODF: take the size given from the parent frame as default 511*cdf0e10cSrcweir uno::Reference< chart2::XChartDocument > xChart( xDocument, uno::UNO_QUERY ); 512*cdf0e10cSrcweir if( xChart.is() ) 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir uno::Reference< embed::XVisualObject > xChartVisualObject( xChart, uno::UNO_QUERY ); 515*cdf0e10cSrcweir if( xChartVisualObject.is() ) 516*cdf0e10cSrcweir xChartVisualObject->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, m_aDefaultSizeForChart_In_100TH_MM ); 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY ); 520*cdf0e10cSrcweir uno::Reference< document::XStorageBasedDocument > xDoc 521*cdf0e10cSrcweir #ifdef USE_STORAGEBASED_DOCUMENT 522*cdf0e10cSrcweir ( xDocument, uno::UNO_QUERY ) 523*cdf0e10cSrcweir #endif 524*cdf0e10cSrcweir ; 525*cdf0e10cSrcweir if ( !xDoc.is() && !xLoadable.is() ) ///BUG: This should be || instead of && ? 526*cdf0e10cSrcweir throw uno::RuntimeException(); 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir ::comphelper::NamedValueCollection aLoadArgs; 529*cdf0e10cSrcweir FillDefaultLoadArgs_Impl( xSourceStorage, aLoadArgs ); 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir uno::Reference< io::XInputStream > xTempInpStream; 532*cdf0e10cSrcweir if ( !xDoc.is() ) 533*cdf0e10cSrcweir { 534*cdf0e10cSrcweir xTempInpStream = createTempInpStreamFromStor( xSourceStorage, m_xFactory ); 535*cdf0e10cSrcweir if ( !xTempInpStream.is() ) 536*cdf0e10cSrcweir throw uno::RuntimeException(); 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir ::rtl::OUString aTempFileURL; 539*cdf0e10cSrcweir try 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir // no need to let the file stay after the stream is removed since the embedded document 542*cdf0e10cSrcweir // can not be stored directly 543*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xTempStreamProps( xTempInpStream, uno::UNO_QUERY_THROW ); 544*cdf0e10cSrcweir xTempStreamProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) ) >>= aTempFileURL; 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir catch( uno::Exception& ) 547*cdf0e10cSrcweir { 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir OSL_ENSURE( aTempFileURL.getLength(), "Coudn't retrieve temporary file URL!\n" ); 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir aLoadArgs.put( "URL", aTempFileURL ); 553*cdf0e10cSrcweir aLoadArgs.put( "InputStream", xTempInpStream ); 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir // aLoadArgs.put( "AsTemplate", sal_True ); 557*cdf0e10cSrcweir 558*cdf0e10cSrcweir aLoadArgs.merge( m_aDocMediaDescriptor, true ); 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir try 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir // set the document mode to embedded as the first step!!! 563*cdf0e10cSrcweir EmbedAndReparentDoc_Impl( xDocument ); 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir if ( xDoc.is() ) 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir xDoc->loadFromStorage( xSourceStorage, aLoadArgs.getPropertyValues() ); 568*cdf0e10cSrcweir if ( xSourceStorage != m_xObjectStorage ) 569*cdf0e10cSrcweir SwitchDocToStorage_Impl( xDoc, m_xObjectStorage ); 570*cdf0e10cSrcweir } 571*cdf0e10cSrcweir else 572*cdf0e10cSrcweir xLoadable->load( aLoadArgs.getPropertyValues() ); 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir catch( uno::Exception& ) 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir uno::Reference< util::XCloseable > xCloseable( xDocument, uno::UNO_QUERY ); 577*cdf0e10cSrcweir if ( xCloseable.is() ) 578*cdf0e10cSrcweir { 579*cdf0e10cSrcweir try 580*cdf0e10cSrcweir { 581*cdf0e10cSrcweir xCloseable->close( sal_True ); 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir catch( uno::Exception& ) 584*cdf0e10cSrcweir { 585*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 586*cdf0e10cSrcweir } 587*cdf0e10cSrcweir } 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir throw; // TODO 590*cdf0e10cSrcweir } 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir return xDocument; 593*cdf0e10cSrcweir } 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir //------------------------------------------------------ 596*cdf0e10cSrcweir uno::Reference< io::XInputStream > OCommonEmbeddedObject::StoreDocumentToTempStream_Impl( 597*cdf0e10cSrcweir sal_Int32 nStorageFormat, 598*cdf0e10cSrcweir const ::rtl::OUString& aBaseURL, 599*cdf0e10cSrcweir const ::rtl::OUString& aHierarchName ) 600*cdf0e10cSrcweir { 601*cdf0e10cSrcweir uno::Reference < io::XOutputStream > xTempOut( 602*cdf0e10cSrcweir m_xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ), 603*cdf0e10cSrcweir uno::UNO_QUERY ); 604*cdf0e10cSrcweir uno::Reference< io::XInputStream > aResult( xTempOut, uno::UNO_QUERY ); 605*cdf0e10cSrcweir 606*cdf0e10cSrcweir if ( !xTempOut.is() || !aResult.is() ) 607*cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir uno::Reference< frame::XStorable > xStorable; 610*cdf0e10cSrcweir { 611*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 612*cdf0e10cSrcweir if ( m_pDocHolder ) 613*cdf0e10cSrcweir xStorable = uno::Reference< frame::XStorable > ( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 614*cdf0e10cSrcweir } 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir if( !xStorable.is() ) 617*cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir ::rtl::OUString aFilterName = GetFilterName( nStorageFormat ); 620*cdf0e10cSrcweir 621*cdf0e10cSrcweir OSL_ENSURE( aFilterName.getLength(), "Wrong document service name!" ); 622*cdf0e10cSrcweir if ( !aFilterName.getLength() ) 623*cdf0e10cSrcweir throw io::IOException(); // TODO: 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aArgs( 4 ); 626*cdf0e10cSrcweir aArgs[0].Name = ::rtl::OUString::createFromAscii( "FilterName" ); 627*cdf0e10cSrcweir aArgs[0].Value <<= aFilterName; 628*cdf0e10cSrcweir aArgs[1].Name = ::rtl::OUString::createFromAscii( "OutputStream" ); 629*cdf0e10cSrcweir aArgs[1].Value <<= xTempOut; 630*cdf0e10cSrcweir aArgs[2].Name = ::rtl::OUString::createFromAscii( "DocumentBaseURL" ); 631*cdf0e10cSrcweir aArgs[2].Value <<= aBaseURL; 632*cdf0e10cSrcweir aArgs[3].Name = ::rtl::OUString::createFromAscii( "HierarchicalDocumentName" ); 633*cdf0e10cSrcweir aArgs[3].Value <<= aHierarchName; 634*cdf0e10cSrcweir 635*cdf0e10cSrcweir xStorable->storeToURL( ::rtl::OUString::createFromAscii( "private:stream" ), aArgs ); 636*cdf0e10cSrcweir try 637*cdf0e10cSrcweir { 638*cdf0e10cSrcweir xTempOut->closeOutput(); 639*cdf0e10cSrcweir } 640*cdf0e10cSrcweir catch( uno::Exception& ) 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Looks like stream was closed already" ); 643*cdf0e10cSrcweir } 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir return aResult; 646*cdf0e10cSrcweir } 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir //------------------------------------------------------ 649*cdf0e10cSrcweir void OCommonEmbeddedObject::SaveObject_Impl() 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir if ( m_xClientSite.is() ) 652*cdf0e10cSrcweir { 653*cdf0e10cSrcweir try 654*cdf0e10cSrcweir { 655*cdf0e10cSrcweir // check whether the component is modified, 656*cdf0e10cSrcweir // if not there is no need for storing 657*cdf0e10cSrcweir uno::Reference< util::XModifiable > xModifiable( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 658*cdf0e10cSrcweir if ( xModifiable.is() && !xModifiable->isModified() ) 659*cdf0e10cSrcweir return; 660*cdf0e10cSrcweir } 661*cdf0e10cSrcweir catch( uno::Exception& ) 662*cdf0e10cSrcweir {} 663*cdf0e10cSrcweir 664*cdf0e10cSrcweir try { 665*cdf0e10cSrcweir m_xClientSite->saveObject(); 666*cdf0e10cSrcweir } 667*cdf0e10cSrcweir catch( uno::Exception& ) 668*cdf0e10cSrcweir { 669*cdf0e10cSrcweir OSL_ENSURE( sal_False, "The object was not stored!\n" ); 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir } 672*cdf0e10cSrcweir } 673*cdf0e10cSrcweir 674*cdf0e10cSrcweir //------------------------------------------------------ 675*cdf0e10cSrcweir ::rtl::OUString OCommonEmbeddedObject::GetBaseURL_Impl() const 676*cdf0e10cSrcweir { 677*cdf0e10cSrcweir ::rtl::OUString aBaseURL; 678*cdf0e10cSrcweir sal_Int32 nInd = 0; 679*cdf0e10cSrcweir 680*cdf0e10cSrcweir if ( m_xClientSite.is() ) 681*cdf0e10cSrcweir { 682*cdf0e10cSrcweir try 683*cdf0e10cSrcweir { 684*cdf0e10cSrcweir uno::Reference< frame::XModel > xParentModel( m_xClientSite->getComponent(), uno::UNO_QUERY_THROW ); 685*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aModelProps = xParentModel->getArgs(); 686*cdf0e10cSrcweir for ( nInd = 0; nInd < aModelProps.getLength(); nInd++ ) 687*cdf0e10cSrcweir if ( aModelProps[nInd].Name.equals( 688*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentBaseURL" ) ) ) ) 689*cdf0e10cSrcweir { 690*cdf0e10cSrcweir aModelProps[nInd].Value >>= aBaseURL; 691*cdf0e10cSrcweir break; 692*cdf0e10cSrcweir } 693*cdf0e10cSrcweir 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir } 696*cdf0e10cSrcweir catch( uno::Exception& ) 697*cdf0e10cSrcweir {} 698*cdf0e10cSrcweir } 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir if ( !aBaseURL.getLength() ) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir for ( nInd = 0; nInd < m_aDocMediaDescriptor.getLength(); nInd++ ) 703*cdf0e10cSrcweir if ( m_aDocMediaDescriptor[nInd].Name.equals( 704*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentBaseURL" ) ) ) ) 705*cdf0e10cSrcweir { 706*cdf0e10cSrcweir m_aDocMediaDescriptor[nInd].Value >>= aBaseURL; 707*cdf0e10cSrcweir break; 708*cdf0e10cSrcweir } 709*cdf0e10cSrcweir } 710*cdf0e10cSrcweir 711*cdf0e10cSrcweir if ( !aBaseURL.getLength() ) 712*cdf0e10cSrcweir aBaseURL = m_aDefaultParentBaseURL; 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir return aBaseURL; 715*cdf0e10cSrcweir } 716*cdf0e10cSrcweir 717*cdf0e10cSrcweir //------------------------------------------------------ 718*cdf0e10cSrcweir ::rtl::OUString OCommonEmbeddedObject::GetBaseURLFrom_Impl( 719*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lArguments, 720*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 721*cdf0e10cSrcweir { 722*cdf0e10cSrcweir ::rtl::OUString aBaseURL; 723*cdf0e10cSrcweir sal_Int32 nInd = 0; 724*cdf0e10cSrcweir 725*cdf0e10cSrcweir for ( nInd = 0; nInd < lArguments.getLength(); nInd++ ) 726*cdf0e10cSrcweir if ( lArguments[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentBaseURL" ) ) ) ) 727*cdf0e10cSrcweir { 728*cdf0e10cSrcweir lArguments[nInd].Value >>= aBaseURL; 729*cdf0e10cSrcweir break; 730*cdf0e10cSrcweir } 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir if ( !aBaseURL.getLength() ) 733*cdf0e10cSrcweir { 734*cdf0e10cSrcweir for ( nInd = 0; nInd < lObjArgs.getLength(); nInd++ ) 735*cdf0e10cSrcweir if ( lObjArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultParentBaseURL" ) ) ) ) 736*cdf0e10cSrcweir { 737*cdf0e10cSrcweir lObjArgs[nInd].Value >>= aBaseURL; 738*cdf0e10cSrcweir break; 739*cdf0e10cSrcweir } 740*cdf0e10cSrcweir } 741*cdf0e10cSrcweir 742*cdf0e10cSrcweir return aBaseURL; 743*cdf0e10cSrcweir } 744*cdf0e10cSrcweir 745*cdf0e10cSrcweir 746*cdf0e10cSrcweir //------------------------------------------------------ 747*cdf0e10cSrcweir void OCommonEmbeddedObject::SwitchDocToStorage_Impl( const uno::Reference< document::XStorageBasedDocument >& xDoc, const uno::Reference< embed::XStorage >& xStorage ) 748*cdf0e10cSrcweir { 749*cdf0e10cSrcweir xDoc->switchToStorage( xStorage ); 750*cdf0e10cSrcweir 751*cdf0e10cSrcweir uno::Reference< util::XModifiable > xModif( xDoc, uno::UNO_QUERY ); 752*cdf0e10cSrcweir if ( xModif.is() ) 753*cdf0e10cSrcweir xModif->setModified( sal_False ); 754*cdf0e10cSrcweir 755*cdf0e10cSrcweir if ( m_xRecoveryStorage.is() ) 756*cdf0e10cSrcweir m_xRecoveryStorage.clear(); 757*cdf0e10cSrcweir } 758*cdf0e10cSrcweir 759*cdf0e10cSrcweir //------------------------------------------------------ 760*cdf0e10cSrcweir void OCommonEmbeddedObject::StoreDocToStorage_Impl( const uno::Reference< embed::XStorage >& xStorage, 761*cdf0e10cSrcweir sal_Int32 nStorageFormat, 762*cdf0e10cSrcweir const ::rtl::OUString& aBaseURL, 763*cdf0e10cSrcweir const ::rtl::OUString& aHierarchName, 764*cdf0e10cSrcweir sal_Bool bAttachToTheStorage ) 765*cdf0e10cSrcweir { 766*cdf0e10cSrcweir OSL_ENSURE( xStorage.is(), "No storage is provided for storing!" ); 767*cdf0e10cSrcweir 768*cdf0e10cSrcweir if ( !xStorage.is() ) 769*cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 770*cdf0e10cSrcweir 771*cdf0e10cSrcweir #ifdef USE_STORAGEBASED_DOCUMENT 772*cdf0e10cSrcweir uno::Reference< document::XStorageBasedDocument > xDoc; 773*cdf0e10cSrcweir { 774*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 775*cdf0e10cSrcweir if ( m_pDocHolder ) 776*cdf0e10cSrcweir xDoc = uno::Reference< document::XStorageBasedDocument >( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 777*cdf0e10cSrcweir } 778*cdf0e10cSrcweir 779*cdf0e10cSrcweir if ( xDoc.is() ) 780*cdf0e10cSrcweir { 781*cdf0e10cSrcweir ::rtl::OUString aFilterName = GetFilterName( nStorageFormat ); 782*cdf0e10cSrcweir 783*cdf0e10cSrcweir OSL_ENSURE( aFilterName.getLength(), "Wrong document service name!" ); 784*cdf0e10cSrcweir if ( !aFilterName.getLength() ) 785*cdf0e10cSrcweir throw io::IOException(); // TODO: 786*cdf0e10cSrcweir 787*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aArgs( 3 ); 788*cdf0e10cSrcweir aArgs[0].Name = ::rtl::OUString::createFromAscii( "FilterName" ); 789*cdf0e10cSrcweir aArgs[0].Value <<= aFilterName; 790*cdf0e10cSrcweir aArgs[2].Name = ::rtl::OUString::createFromAscii( "DocumentBaseURL" ); 791*cdf0e10cSrcweir aArgs[2].Value <<= aBaseURL; 792*cdf0e10cSrcweir aArgs[1].Name = ::rtl::OUString::createFromAscii( "HierarchicalDocumentName" ); 793*cdf0e10cSrcweir aArgs[1].Value <<= aHierarchName; 794*cdf0e10cSrcweir 795*cdf0e10cSrcweir xDoc->storeToStorage( xStorage, aArgs ); 796*cdf0e10cSrcweir if ( bAttachToTheStorage ) 797*cdf0e10cSrcweir SwitchDocToStorage_Impl( xDoc, xStorage ); 798*cdf0e10cSrcweir } 799*cdf0e10cSrcweir else 800*cdf0e10cSrcweir #endif 801*cdf0e10cSrcweir { 802*cdf0e10cSrcweir // store document to temporary stream based on temporary file 803*cdf0e10cSrcweir uno::Reference < io::XInputStream > xTempIn = StoreDocumentToTempStream_Impl( nStorageFormat, aBaseURL, aHierarchName ); 804*cdf0e10cSrcweir 805*cdf0e10cSrcweir OSL_ENSURE( xTempIn.is(), "The stream reference can not be empty!\n" ); 806*cdf0e10cSrcweir 807*cdf0e10cSrcweir // open storage based on document temporary file for reading 808*cdf0e10cSrcweir uno::Reference < lang::XSingleServiceFactory > xStorageFactory( 809*cdf0e10cSrcweir m_xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.embed.StorageFactory" ) ), 810*cdf0e10cSrcweir uno::UNO_QUERY ); 811*cdf0e10cSrcweir 812*cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs(1); 813*cdf0e10cSrcweir aArgs[0] <<= xTempIn; 814*cdf0e10cSrcweir uno::Reference< embed::XStorage > xTempStorage( xStorageFactory->createInstanceWithArguments( aArgs ), 815*cdf0e10cSrcweir uno::UNO_QUERY ); 816*cdf0e10cSrcweir if ( !xTempStorage.is() ) 817*cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 818*cdf0e10cSrcweir 819*cdf0e10cSrcweir // object storage must be commited automatically 820*cdf0e10cSrcweir xTempStorage->copyToStorage( xStorage ); 821*cdf0e10cSrcweir } 822*cdf0e10cSrcweir } 823*cdf0e10cSrcweir 824*cdf0e10cSrcweir //------------------------------------------------------ 825*cdf0e10cSrcweir uno::Reference< util::XCloseable > OCommonEmbeddedObject::CreateDocFromMediaDescr_Impl( 826*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& aMedDescr ) 827*cdf0e10cSrcweir { 828*cdf0e10cSrcweir uno::Reference< util::XCloseable > xDocument( CreateDocument( m_xFactory, GetDocumentServiceName(), 829*cdf0e10cSrcweir m_bEmbeddedScriptSupport, m_bDocumentRecoverySupport ) ); 830*cdf0e10cSrcweir 831*cdf0e10cSrcweir uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY ); 832*cdf0e10cSrcweir if ( !xLoadable.is() ) 833*cdf0e10cSrcweir throw uno::RuntimeException(); 834*cdf0e10cSrcweir 835*cdf0e10cSrcweir try 836*cdf0e10cSrcweir { 837*cdf0e10cSrcweir // set the document mode to embedded as the first action on the document!!! 838*cdf0e10cSrcweir EmbedAndReparentDoc_Impl( xDocument ); 839*cdf0e10cSrcweir 840*cdf0e10cSrcweir xLoadable->load( addAsTemplate( aMedDescr ) ); 841*cdf0e10cSrcweir } 842*cdf0e10cSrcweir catch( uno::Exception& ) 843*cdf0e10cSrcweir { 844*cdf0e10cSrcweir uno::Reference< util::XCloseable > xCloseable( xDocument, uno::UNO_QUERY ); 845*cdf0e10cSrcweir if ( xCloseable.is() ) 846*cdf0e10cSrcweir { 847*cdf0e10cSrcweir try 848*cdf0e10cSrcweir { 849*cdf0e10cSrcweir xCloseable->close( sal_True ); 850*cdf0e10cSrcweir } 851*cdf0e10cSrcweir catch( uno::Exception& ) 852*cdf0e10cSrcweir { 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir } 855*cdf0e10cSrcweir 856*cdf0e10cSrcweir throw; // TODO 857*cdf0e10cSrcweir } 858*cdf0e10cSrcweir 859*cdf0e10cSrcweir return xDocument; 860*cdf0e10cSrcweir } 861*cdf0e10cSrcweir 862*cdf0e10cSrcweir //------------------------------------------------------ 863*cdf0e10cSrcweir uno::Reference< util::XCloseable > OCommonEmbeddedObject::CreateTempDocFromLink_Impl() 864*cdf0e10cSrcweir { 865*cdf0e10cSrcweir uno::Reference< util::XCloseable > xResult; 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir OSL_ENSURE( m_bIsLink, "The object is not a linked one!\n" ); 868*cdf0e10cSrcweir 869*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aTempMediaDescr; 870*cdf0e10cSrcweir 871*cdf0e10cSrcweir sal_Int32 nStorageFormat = SOFFICE_FILEFORMAT_CURRENT; 872*cdf0e10cSrcweir try { 873*cdf0e10cSrcweir nStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( m_xParentStorage ); 874*cdf0e10cSrcweir } 875*cdf0e10cSrcweir catch ( beans::IllegalTypeException& ) 876*cdf0e10cSrcweir { 877*cdf0e10cSrcweir // the container just has an unknown type, use current file format 878*cdf0e10cSrcweir } 879*cdf0e10cSrcweir catch ( uno::Exception& ) 880*cdf0e10cSrcweir { 881*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Can not retrieve storage media type!\n" ); 882*cdf0e10cSrcweir } 883*cdf0e10cSrcweir 884*cdf0e10cSrcweir if ( m_pDocHolder->GetComponent().is() ) 885*cdf0e10cSrcweir { 886*cdf0e10cSrcweir aTempMediaDescr.realloc( 4 ); 887*cdf0e10cSrcweir 888*cdf0e10cSrcweir // TODO/LATER: may be private:stream should be used as target URL 889*cdf0e10cSrcweir ::rtl::OUString aTempFileURL; 890*cdf0e10cSrcweir uno::Reference< io::XInputStream > xTempStream = StoreDocumentToTempStream_Impl( SOFFICE_FILEFORMAT_CURRENT, 891*cdf0e10cSrcweir ::rtl::OUString(), 892*cdf0e10cSrcweir ::rtl::OUString() ); 893*cdf0e10cSrcweir try 894*cdf0e10cSrcweir { 895*cdf0e10cSrcweir // no need to let the file stay after the stream is removed since the embedded document 896*cdf0e10cSrcweir // can not be stored directly 897*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xTempStreamProps( xTempStream, uno::UNO_QUERY_THROW ); 898*cdf0e10cSrcweir xTempStreamProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) ) >>= aTempFileURL; 899*cdf0e10cSrcweir } 900*cdf0e10cSrcweir catch( uno::Exception& ) 901*cdf0e10cSrcweir { 902*cdf0e10cSrcweir } 903*cdf0e10cSrcweir 904*cdf0e10cSrcweir OSL_ENSURE( aTempFileURL.getLength(), "Coudn't retrieve temporary file URL!\n" ); 905*cdf0e10cSrcweir 906*cdf0e10cSrcweir aTempMediaDescr[0].Name = ::rtl::OUString::createFromAscii( "URL" ); 907*cdf0e10cSrcweir aTempMediaDescr[0].Value <<= aTempFileURL; 908*cdf0e10cSrcweir aTempMediaDescr[1].Name = ::rtl::OUString::createFromAscii( "InputStream" ); 909*cdf0e10cSrcweir aTempMediaDescr[1].Value <<= xTempStream; 910*cdf0e10cSrcweir aTempMediaDescr[2].Name = ::rtl::OUString::createFromAscii( "FilterName" ); 911*cdf0e10cSrcweir aTempMediaDescr[2].Value <<= GetFilterName( nStorageFormat ); 912*cdf0e10cSrcweir aTempMediaDescr[3].Name = ::rtl::OUString::createFromAscii( "AsTemplate" ); 913*cdf0e10cSrcweir aTempMediaDescr[3].Value <<= sal_True; 914*cdf0e10cSrcweir } 915*cdf0e10cSrcweir else 916*cdf0e10cSrcweir { 917*cdf0e10cSrcweir aTempMediaDescr.realloc( 2 ); 918*cdf0e10cSrcweir aTempMediaDescr[0].Name = ::rtl::OUString::createFromAscii( "URL" ); 919*cdf0e10cSrcweir aTempMediaDescr[0].Value <<= m_aLinkURL; 920*cdf0e10cSrcweir aTempMediaDescr[1].Name = ::rtl::OUString::createFromAscii( "FilterName" ); 921*cdf0e10cSrcweir aTempMediaDescr[1].Value <<= m_aLinkFilterName; 922*cdf0e10cSrcweir // aTempMediaDescr[2].Name = ::rtl::OUString::createFromAscii( "AsTemplate" ); 923*cdf0e10cSrcweir // aTempMediaDescr[2].Value <<= sal_True; 924*cdf0e10cSrcweir } 925*cdf0e10cSrcweir 926*cdf0e10cSrcweir xResult = CreateDocFromMediaDescr_Impl( aTempMediaDescr ); 927*cdf0e10cSrcweir 928*cdf0e10cSrcweir return xResult; 929*cdf0e10cSrcweir } 930*cdf0e10cSrcweir 931*cdf0e10cSrcweir //------------------------------------------------------ 932*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::setPersistentEntry( 933*cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 934*cdf0e10cSrcweir const ::rtl::OUString& sEntName, 935*cdf0e10cSrcweir sal_Int32 nEntryConnectionMode, 936*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lArguments, 937*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 938*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 939*cdf0e10cSrcweir embed::WrongStateException, 940*cdf0e10cSrcweir io::IOException, 941*cdf0e10cSrcweir uno::Exception, 942*cdf0e10cSrcweir uno::RuntimeException ) 943*cdf0e10cSrcweir { 944*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::setPersistentEntry" ); 945*cdf0e10cSrcweir 946*cdf0e10cSrcweir // the type of the object must be already set 947*cdf0e10cSrcweir // a kind of typedetection should be done in the factory 948*cdf0e10cSrcweir 949*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 950*cdf0e10cSrcweir if ( m_bDisposed ) 951*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 952*cdf0e10cSrcweir 953*cdf0e10cSrcweir if ( !xStorage.is() ) 954*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 955*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 956*cdf0e10cSrcweir 1 ); 957*cdf0e10cSrcweir 958*cdf0e10cSrcweir if ( !sEntName.getLength() ) 959*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 960*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 961*cdf0e10cSrcweir 2 ); 962*cdf0e10cSrcweir 963*cdf0e10cSrcweir // May be LOADED should be forbidden here ??? 964*cdf0e10cSrcweir if ( ( m_nObjectState != -1 || nEntryConnectionMode == embed::EntryInitModes::NO_INIT ) 965*cdf0e10cSrcweir && ( m_nObjectState == -1 || nEntryConnectionMode != embed::EntryInitModes::NO_INIT ) ) 966*cdf0e10cSrcweir { 967*cdf0e10cSrcweir // if the object is not loaded 968*cdf0e10cSrcweir // it can not get persistant representation without initialization 969*cdf0e10cSrcweir 970*cdf0e10cSrcweir // if the object is loaded 971*cdf0e10cSrcweir // it can switch persistant representation only without initialization 972*cdf0e10cSrcweir 973*cdf0e10cSrcweir throw embed::WrongStateException( 974*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Can't change persistant representation of activated object!\n" ), 975*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 976*cdf0e10cSrcweir } 977*cdf0e10cSrcweir 978*cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 979*cdf0e10cSrcweir { 980*cdf0e10cSrcweir if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT ) 981*cdf0e10cSrcweir { 982*cdf0e10cSrcweir // saveCompleted is expected, handle it accordingly 983*cdf0e10cSrcweir if ( m_xNewParentStorage == xStorage && m_aNewEntryName.equals( sEntName ) ) 984*cdf0e10cSrcweir { 985*cdf0e10cSrcweir saveCompleted( sal_True ); 986*cdf0e10cSrcweir return; 987*cdf0e10cSrcweir } 988*cdf0e10cSrcweir 989*cdf0e10cSrcweir // if a completely different entry is provided, switch first back to the old persistence in saveCompleted 990*cdf0e10cSrcweir // and then switch to the target persistence 991*cdf0e10cSrcweir sal_Bool bSwitchFurther = ( m_xParentStorage != xStorage || !m_aEntryName.equals( sEntName ) ); 992*cdf0e10cSrcweir saveCompleted( sal_False ); 993*cdf0e10cSrcweir if ( !bSwitchFurther ) 994*cdf0e10cSrcweir return; 995*cdf0e10cSrcweir } 996*cdf0e10cSrcweir else 997*cdf0e10cSrcweir throw embed::WrongStateException( 998*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 999*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1000*cdf0e10cSrcweir } 1001*cdf0e10cSrcweir 1002*cdf0e10cSrcweir // for now support of this interface is required to allow breaking of links and converting them to normal embedded 1003*cdf0e10cSrcweir // objects, so the persist name must be handled correctly ( althowgh no real persist entry is used ) 1004*cdf0e10cSrcweir // OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" ); 1005*cdf0e10cSrcweir if ( m_bIsLink ) 1006*cdf0e10cSrcweir { 1007*cdf0e10cSrcweir m_aEntryName = sEntName; 1008*cdf0e10cSrcweir return; 1009*cdf0e10cSrcweir } 1010*cdf0e10cSrcweir 1011*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY ); 1012*cdf0e10cSrcweir if ( !xNameAccess.is() ) 1013*cdf0e10cSrcweir throw uno::RuntimeException(); //TODO 1014*cdf0e10cSrcweir 1015*cdf0e10cSrcweir // detect entry existence 1016*cdf0e10cSrcweir sal_Bool bElExists = xNameAccess->hasByName( sEntName ); 1017*cdf0e10cSrcweir 1018*cdf0e10cSrcweir m_aDocMediaDescriptor = GetValuableArgs_Impl( lArguments, 1019*cdf0e10cSrcweir nEntryConnectionMode != embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT ); 1020*cdf0e10cSrcweir 1021*cdf0e10cSrcweir m_bReadOnly = sal_False; 1022*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ ) 1023*cdf0e10cSrcweir if ( lArguments[nInd].Name.equalsAscii( "ReadOnly" ) ) 1024*cdf0e10cSrcweir lArguments[nInd].Value >>= m_bReadOnly; 1025*cdf0e10cSrcweir 1026*cdf0e10cSrcweir // TODO: use lObjArgs for StoreVisualReplacement 1027*cdf0e10cSrcweir for ( sal_Int32 nObjInd = 0; nObjInd < lObjArgs.getLength(); nObjInd++ ) 1028*cdf0e10cSrcweir if ( lObjArgs[nObjInd].Name.equalsAscii( "OutplaceDispatchInterceptor" ) ) 1029*cdf0e10cSrcweir { 1030*cdf0e10cSrcweir uno::Reference< frame::XDispatchProviderInterceptor > xDispatchInterceptor; 1031*cdf0e10cSrcweir if ( lObjArgs[nObjInd].Value >>= xDispatchInterceptor ) 1032*cdf0e10cSrcweir m_pDocHolder->SetOutplaceDispatchInterceptor( xDispatchInterceptor ); 1033*cdf0e10cSrcweir } 1034*cdf0e10cSrcweir else if ( lObjArgs[nObjInd].Name.equalsAscii( "DefaultParentBaseURL" ) ) 1035*cdf0e10cSrcweir { 1036*cdf0e10cSrcweir lObjArgs[nObjInd].Value >>= m_aDefaultParentBaseURL; 1037*cdf0e10cSrcweir } 1038*cdf0e10cSrcweir else if ( lObjArgs[nObjInd].Name.equalsAscii( "Parent" ) ) 1039*cdf0e10cSrcweir { 1040*cdf0e10cSrcweir lObjArgs[nObjInd].Value >>= m_xParent; 1041*cdf0e10cSrcweir } 1042*cdf0e10cSrcweir else if ( lObjArgs[nObjInd].Name.equalsAscii( "IndividualMiscStatus" ) ) 1043*cdf0e10cSrcweir { 1044*cdf0e10cSrcweir sal_Int64 nMiscStatus=0; 1045*cdf0e10cSrcweir lObjArgs[nObjInd].Value >>= nMiscStatus; 1046*cdf0e10cSrcweir m_nMiscStatus |= nMiscStatus; 1047*cdf0e10cSrcweir } 1048*cdf0e10cSrcweir else if ( lObjArgs[nObjInd].Name.equalsAscii( "CloneFrom" ) ) 1049*cdf0e10cSrcweir { 1050*cdf0e10cSrcweir uno::Reference < embed::XEmbeddedObject > xObj; 1051*cdf0e10cSrcweir lObjArgs[nObjInd].Value >>= xObj; 1052*cdf0e10cSrcweir if ( xObj.is() ) 1053*cdf0e10cSrcweir { 1054*cdf0e10cSrcweir m_bHasClonedSize = sal_True; 1055*cdf0e10cSrcweir m_aClonedSize = xObj->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ); 1056*cdf0e10cSrcweir m_nClonedMapUnit = xObj->getMapUnit( embed::Aspects::MSOLE_CONTENT ); 1057*cdf0e10cSrcweir } 1058*cdf0e10cSrcweir } 1059*cdf0e10cSrcweir else if ( lObjArgs[nObjInd].Name.equalsAscii( "OutplaceFrameProperties" ) ) 1060*cdf0e10cSrcweir { 1061*cdf0e10cSrcweir uno::Sequence< uno::Any > aOutFrameProps; 1062*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aOutFramePropsTyped; 1063*cdf0e10cSrcweir if ( lObjArgs[nObjInd].Value >>= aOutFrameProps ) 1064*cdf0e10cSrcweir { 1065*cdf0e10cSrcweir m_pDocHolder->SetOutplaceFrameProperties( aOutFrameProps ); 1066*cdf0e10cSrcweir } 1067*cdf0e10cSrcweir else if ( lObjArgs[nObjInd].Value >>= aOutFramePropsTyped ) 1068*cdf0e10cSrcweir { 1069*cdf0e10cSrcweir aOutFrameProps.realloc( aOutFramePropsTyped.getLength() ); 1070*cdf0e10cSrcweir uno::Any* pProp = aOutFrameProps.getArray(); 1071*cdf0e10cSrcweir for ( const beans::NamedValue* pTypedProp = aOutFramePropsTyped.getConstArray(); 1072*cdf0e10cSrcweir pTypedProp != aOutFramePropsTyped.getConstArray() + aOutFramePropsTyped.getLength(); 1073*cdf0e10cSrcweir ++pTypedProp, ++pProp 1074*cdf0e10cSrcweir ) 1075*cdf0e10cSrcweir { 1076*cdf0e10cSrcweir *pProp <<= *pTypedProp; 1077*cdf0e10cSrcweir } 1078*cdf0e10cSrcweir m_pDocHolder->SetOutplaceFrameProperties( aOutFrameProps ); 1079*cdf0e10cSrcweir } 1080*cdf0e10cSrcweir else 1081*cdf0e10cSrcweir OSL_ENSURE( false, "OCommonEmbeddedObject::setPersistentEntry: illegal type for argument 'OutplaceFrameProperties'!" ); 1082*cdf0e10cSrcweir } 1083*cdf0e10cSrcweir else if ( lObjArgs[nObjInd].Name.equalsAscii( "ModuleName" ) ) 1084*cdf0e10cSrcweir { 1085*cdf0e10cSrcweir lObjArgs[nObjInd].Value >>= m_aModuleName; 1086*cdf0e10cSrcweir } 1087*cdf0e10cSrcweir else if ( lObjArgs[nObjInd].Name.equalsAscii( "EmbeddedScriptSupport" ) ) 1088*cdf0e10cSrcweir { 1089*cdf0e10cSrcweir OSL_VERIFY( lObjArgs[nObjInd].Value >>= m_bEmbeddedScriptSupport ); 1090*cdf0e10cSrcweir } 1091*cdf0e10cSrcweir else if ( lObjArgs[nObjInd].Name.equalsAscii( "DocumentRecoverySupport" ) ) 1092*cdf0e10cSrcweir { 1093*cdf0e10cSrcweir OSL_VERIFY( lObjArgs[nObjInd].Value >>= m_bDocumentRecoverySupport ); 1094*cdf0e10cSrcweir } 1095*cdf0e10cSrcweir else if ( lObjArgs[nObjInd].Name.equalsAscii( "RecoveryStorage" ) ) 1096*cdf0e10cSrcweir { 1097*cdf0e10cSrcweir OSL_VERIFY( lObjArgs[nObjInd].Value >>= m_xRecoveryStorage ); 1098*cdf0e10cSrcweir } 1099*cdf0e10cSrcweir 1100*cdf0e10cSrcweir 1101*cdf0e10cSrcweir sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE; 1102*cdf0e10cSrcweir 1103*cdf0e10cSrcweir SwitchOwnPersistence( xStorage, sEntName ); 1104*cdf0e10cSrcweir 1105*cdf0e10cSrcweir if ( nEntryConnectionMode == embed::EntryInitModes::DEFAULT_INIT ) 1106*cdf0e10cSrcweir { 1107*cdf0e10cSrcweir if ( bElExists ) 1108*cdf0e10cSrcweir { 1109*cdf0e10cSrcweir // the initialization from existing storage allows to leave object in loaded state 1110*cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::LOADED; 1111*cdf0e10cSrcweir } 1112*cdf0e10cSrcweir else 1113*cdf0e10cSrcweir { 1114*cdf0e10cSrcweir m_pDocHolder->SetComponent( InitNewDocument_Impl(), m_bReadOnly ); 1115*cdf0e10cSrcweir if ( !m_pDocHolder->GetComponent().is() ) 1116*cdf0e10cSrcweir throw io::IOException(); // TODO: can not create document 1117*cdf0e10cSrcweir 1118*cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::RUNNING; 1119*cdf0e10cSrcweir } 1120*cdf0e10cSrcweir } 1121*cdf0e10cSrcweir else 1122*cdf0e10cSrcweir { 1123*cdf0e10cSrcweir if ( ( nStorageMode & embed::ElementModes::READWRITE ) != embed::ElementModes::READWRITE ) 1124*cdf0e10cSrcweir throw io::IOException(); 1125*cdf0e10cSrcweir 1126*cdf0e10cSrcweir if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT ) 1127*cdf0e10cSrcweir { 1128*cdf0e10cSrcweir // the document just already changed its storage to store to 1129*cdf0e10cSrcweir // the links to OOo documents for now ignore this call 1130*cdf0e10cSrcweir // TODO: OOo links will have persistence so it will be switched here 1131*cdf0e10cSrcweir } 1132*cdf0e10cSrcweir else if ( nEntryConnectionMode == embed::EntryInitModes::TRUNCATE_INIT ) 1133*cdf0e10cSrcweir { 1134*cdf0e10cSrcweir if ( m_xRecoveryStorage.is() ) 1135*cdf0e10cSrcweir TransferMediaType( m_xRecoveryStorage, m_xObjectStorage ); 1136*cdf0e10cSrcweir 1137*cdf0e10cSrcweir // TODO: 1138*cdf0e10cSrcweir m_pDocHolder->SetComponent( InitNewDocument_Impl(), m_bReadOnly ); 1139*cdf0e10cSrcweir 1140*cdf0e10cSrcweir if ( !m_pDocHolder->GetComponent().is() ) 1141*cdf0e10cSrcweir throw io::IOException(); // TODO: can not create document 1142*cdf0e10cSrcweir 1143*cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::RUNNING; 1144*cdf0e10cSrcweir } 1145*cdf0e10cSrcweir else if ( nEntryConnectionMode == embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT ) 1146*cdf0e10cSrcweir { 1147*cdf0e10cSrcweir m_pDocHolder->SetComponent( CreateDocFromMediaDescr_Impl( lArguments ), m_bReadOnly ); 1148*cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::RUNNING; 1149*cdf0e10cSrcweir } 1150*cdf0e10cSrcweir //else if ( nEntryConnectionMode == embed::EntryInitModes::TRANSFERABLE_INIT ) 1151*cdf0e10cSrcweir //{ 1152*cdf0e10cSrcweir //TODO: 1153*cdf0e10cSrcweir //} 1154*cdf0e10cSrcweir else 1155*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Wrong connection mode is provided!\n" ), 1156*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 1157*cdf0e10cSrcweir 3 ); 1158*cdf0e10cSrcweir } 1159*cdf0e10cSrcweir } 1160*cdf0e10cSrcweir 1161*cdf0e10cSrcweir //------------------------------------------------------ 1162*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::storeToEntry( const uno::Reference< embed::XStorage >& xStorage, 1163*cdf0e10cSrcweir const ::rtl::OUString& sEntName, 1164*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lArguments, 1165*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 1166*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 1167*cdf0e10cSrcweir embed::WrongStateException, 1168*cdf0e10cSrcweir io::IOException, 1169*cdf0e10cSrcweir uno::Exception, 1170*cdf0e10cSrcweir uno::RuntimeException ) 1171*cdf0e10cSrcweir { 1172*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::storeToEntry" ); 1173*cdf0e10cSrcweir 1174*cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 1175*cdf0e10cSrcweir if ( m_bDisposed ) 1176*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1177*cdf0e10cSrcweir 1178*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1179*cdf0e10cSrcweir { 1180*cdf0e10cSrcweir // the object is still not loaded 1181*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ), 1182*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1183*cdf0e10cSrcweir } 1184*cdf0e10cSrcweir 1185*cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1186*cdf0e10cSrcweir throw embed::WrongStateException( 1187*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1188*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1189*cdf0e10cSrcweir 1190*cdf0e10cSrcweir // for now support of this interface is required to allow breaking of links and converting them to normal embedded 1191*cdf0e10cSrcweir // objects, so the persist name must be handled correctly ( althowgh no real persist entry is used ) 1192*cdf0e10cSrcweir // OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" ); 1193*cdf0e10cSrcweir if ( m_bIsLink ) 1194*cdf0e10cSrcweir return; 1195*cdf0e10cSrcweir 1196*cdf0e10cSrcweir OSL_ENSURE( m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" ); 1197*cdf0e10cSrcweir 1198*cdf0e10cSrcweir sal_Int32 nTargetStorageFormat = SOFFICE_FILEFORMAT_CURRENT; 1199*cdf0e10cSrcweir sal_Int32 nOriginalStorageFormat = SOFFICE_FILEFORMAT_CURRENT; 1200*cdf0e10cSrcweir try { 1201*cdf0e10cSrcweir nTargetStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( xStorage ); 1202*cdf0e10cSrcweir } 1203*cdf0e10cSrcweir catch ( beans::IllegalTypeException& ) 1204*cdf0e10cSrcweir { 1205*cdf0e10cSrcweir // the container just has an unknown type, use current file format 1206*cdf0e10cSrcweir } 1207*cdf0e10cSrcweir catch ( uno::Exception& ) 1208*cdf0e10cSrcweir { 1209*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Can not retrieve target storage media type!\n" ); 1210*cdf0e10cSrcweir } 1211*cdf0e10cSrcweir 1212*cdf0e10cSrcweir try 1213*cdf0e10cSrcweir { 1214*cdf0e10cSrcweir nOriginalStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( m_xParentStorage ); 1215*cdf0e10cSrcweir } 1216*cdf0e10cSrcweir catch ( beans::IllegalTypeException& ) 1217*cdf0e10cSrcweir { 1218*cdf0e10cSrcweir // the container just has an unknown type, use current file format 1219*cdf0e10cSrcweir } 1220*cdf0e10cSrcweir catch ( uno::Exception& ) 1221*cdf0e10cSrcweir { 1222*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Can not retrieve own storage media type!\n" ); 1223*cdf0e10cSrcweir } 1224*cdf0e10cSrcweir 1225*cdf0e10cSrcweir sal_Bool bTryOptimization = sal_False; 1226*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ ) 1227*cdf0e10cSrcweir { 1228*cdf0e10cSrcweir // StoreVisualReplacement and VisualReplacement args have no sence here 1229*cdf0e10cSrcweir if ( lObjArgs[nInd].Name.equalsAscii( "CanTryOptimization" ) ) 1230*cdf0e10cSrcweir lObjArgs[nInd].Value >>= bTryOptimization; 1231*cdf0e10cSrcweir } 1232*cdf0e10cSrcweir 1233*cdf0e10cSrcweir sal_Bool bSwitchBackToLoaded = sal_False; 1234*cdf0e10cSrcweir 1235*cdf0e10cSrcweir // Storing to different format can be done only in running state. 1236*cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED ) 1237*cdf0e10cSrcweir { 1238*cdf0e10cSrcweir // TODO/LATER: copying is not legal for documents with relative links. 1239*cdf0e10cSrcweir if ( nTargetStorageFormat == nOriginalStorageFormat ) 1240*cdf0e10cSrcweir { 1241*cdf0e10cSrcweir sal_Bool bOptimizationWorks = sal_False; 1242*cdf0e10cSrcweir if ( bTryOptimization ) 1243*cdf0e10cSrcweir { 1244*cdf0e10cSrcweir try 1245*cdf0e10cSrcweir { 1246*cdf0e10cSrcweir // try to use optimized copying 1247*cdf0e10cSrcweir uno::Reference< embed::XOptimizedStorage > xSource( m_xParentStorage, uno::UNO_QUERY_THROW ); 1248*cdf0e10cSrcweir uno::Reference< embed::XOptimizedStorage > xTarget( xStorage, uno::UNO_QUERY_THROW ); 1249*cdf0e10cSrcweir xSource->copyElementDirectlyTo( m_aEntryName, xTarget, sEntName ); 1250*cdf0e10cSrcweir bOptimizationWorks = sal_True; 1251*cdf0e10cSrcweir } 1252*cdf0e10cSrcweir catch( uno::Exception& ) 1253*cdf0e10cSrcweir { 1254*cdf0e10cSrcweir } 1255*cdf0e10cSrcweir } 1256*cdf0e10cSrcweir 1257*cdf0e10cSrcweir if ( !bOptimizationWorks ) 1258*cdf0e10cSrcweir m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName ); 1259*cdf0e10cSrcweir } 1260*cdf0e10cSrcweir else 1261*cdf0e10cSrcweir { 1262*cdf0e10cSrcweir changeState( embed::EmbedStates::RUNNING ); 1263*cdf0e10cSrcweir bSwitchBackToLoaded = sal_True; 1264*cdf0e10cSrcweir } 1265*cdf0e10cSrcweir } 1266*cdf0e10cSrcweir 1267*cdf0e10cSrcweir if ( m_nObjectState != embed::EmbedStates::LOADED ) 1268*cdf0e10cSrcweir { 1269*cdf0e10cSrcweir uno::Reference< embed::XStorage > xSubStorage = 1270*cdf0e10cSrcweir xStorage->openStorageElement( sEntName, embed::ElementModes::READWRITE ); 1271*cdf0e10cSrcweir 1272*cdf0e10cSrcweir if ( !xSubStorage.is() ) 1273*cdf0e10cSrcweir throw uno::RuntimeException(); //TODO 1274*cdf0e10cSrcweir 1275*cdf0e10cSrcweir aGuard.clear(); 1276*cdf0e10cSrcweir // TODO/LATER: support hierarchical name for embedded objects in embedded objects 1277*cdf0e10cSrcweir StoreDocToStorage_Impl( xSubStorage, nTargetStorageFormat, GetBaseURLFrom_Impl( lArguments, lObjArgs ), sEntName, sal_False ); 1278*cdf0e10cSrcweir aGuard.reset(); 1279*cdf0e10cSrcweir 1280*cdf0e10cSrcweir if ( bSwitchBackToLoaded ) 1281*cdf0e10cSrcweir changeState( embed::EmbedStates::LOADED ); 1282*cdf0e10cSrcweir } 1283*cdf0e10cSrcweir 1284*cdf0e10cSrcweir // TODO: should the listener notification be done? 1285*cdf0e10cSrcweir } 1286*cdf0e10cSrcweir 1287*cdf0e10cSrcweir //------------------------------------------------------ 1288*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::storeAsEntry( const uno::Reference< embed::XStorage >& xStorage, 1289*cdf0e10cSrcweir const ::rtl::OUString& sEntName, 1290*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lArguments, 1291*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 1292*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 1293*cdf0e10cSrcweir embed::WrongStateException, 1294*cdf0e10cSrcweir io::IOException, 1295*cdf0e10cSrcweir uno::Exception, 1296*cdf0e10cSrcweir uno::RuntimeException ) 1297*cdf0e10cSrcweir { 1298*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::storeAsEntry" ); 1299*cdf0e10cSrcweir 1300*cdf0e10cSrcweir // TODO: use lObjArgs 1301*cdf0e10cSrcweir 1302*cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 1303*cdf0e10cSrcweir if ( m_bDisposed ) 1304*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1305*cdf0e10cSrcweir 1306*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1307*cdf0e10cSrcweir { 1308*cdf0e10cSrcweir // the object is still not loaded 1309*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ), 1310*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1311*cdf0e10cSrcweir } 1312*cdf0e10cSrcweir 1313*cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1314*cdf0e10cSrcweir throw embed::WrongStateException( 1315*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1316*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1317*cdf0e10cSrcweir 1318*cdf0e10cSrcweir // for now support of this interface is required to allow breaking of links and converting them to normal embedded 1319*cdf0e10cSrcweir // objects, so the persist name must be handled correctly ( althowgh no real persist entry is used ) 1320*cdf0e10cSrcweir // OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" ); 1321*cdf0e10cSrcweir if ( m_bIsLink ) 1322*cdf0e10cSrcweir { 1323*cdf0e10cSrcweir m_aNewEntryName = sEntName; 1324*cdf0e10cSrcweir return; 1325*cdf0e10cSrcweir } 1326*cdf0e10cSrcweir 1327*cdf0e10cSrcweir OSL_ENSURE( m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" ); 1328*cdf0e10cSrcweir 1329*cdf0e10cSrcweir sal_Int32 nTargetStorageFormat = SOFFICE_FILEFORMAT_CURRENT; 1330*cdf0e10cSrcweir sal_Int32 nOriginalStorageFormat = SOFFICE_FILEFORMAT_CURRENT; 1331*cdf0e10cSrcweir try { 1332*cdf0e10cSrcweir nTargetStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( xStorage ); 1333*cdf0e10cSrcweir } 1334*cdf0e10cSrcweir catch ( beans::IllegalTypeException& ) 1335*cdf0e10cSrcweir { 1336*cdf0e10cSrcweir // the container just has an unknown type, use current file format 1337*cdf0e10cSrcweir } 1338*cdf0e10cSrcweir catch ( uno::Exception& ) 1339*cdf0e10cSrcweir { 1340*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Can not retrieve target storage media type!\n" ); 1341*cdf0e10cSrcweir } 1342*cdf0e10cSrcweir 1343*cdf0e10cSrcweir try 1344*cdf0e10cSrcweir { 1345*cdf0e10cSrcweir nOriginalStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( m_xParentStorage ); 1346*cdf0e10cSrcweir } 1347*cdf0e10cSrcweir catch ( beans::IllegalTypeException& ) 1348*cdf0e10cSrcweir { 1349*cdf0e10cSrcweir // the container just has an unknown type, use current file format 1350*cdf0e10cSrcweir } 1351*cdf0e10cSrcweir catch ( uno::Exception& ) 1352*cdf0e10cSrcweir { 1353*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Can not retrieve own storage media type!\n" ); 1354*cdf0e10cSrcweir } 1355*cdf0e10cSrcweir 1356*cdf0e10cSrcweir PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSaveAs" ) ); 1357*cdf0e10cSrcweir 1358*cdf0e10cSrcweir sal_Bool bTryOptimization = sal_False; 1359*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ ) 1360*cdf0e10cSrcweir { 1361*cdf0e10cSrcweir // StoreVisualReplacement and VisualReplacement args have no sence here 1362*cdf0e10cSrcweir if ( lObjArgs[nInd].Name.equalsAscii( "CanTryOptimization" ) ) 1363*cdf0e10cSrcweir lObjArgs[nInd].Value >>= bTryOptimization; 1364*cdf0e10cSrcweir } 1365*cdf0e10cSrcweir 1366*cdf0e10cSrcweir sal_Bool bSwitchBackToLoaded = sal_False; 1367*cdf0e10cSrcweir 1368*cdf0e10cSrcweir // Storing to different format can be done only in running state. 1369*cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED ) 1370*cdf0e10cSrcweir { 1371*cdf0e10cSrcweir // TODO/LATER: copying is not legal for documents with relative links. 1372*cdf0e10cSrcweir if ( nTargetStorageFormat == nOriginalStorageFormat ) 1373*cdf0e10cSrcweir { 1374*cdf0e10cSrcweir sal_Bool bOptimizationWorks = sal_False; 1375*cdf0e10cSrcweir if ( bTryOptimization ) 1376*cdf0e10cSrcweir { 1377*cdf0e10cSrcweir try 1378*cdf0e10cSrcweir { 1379*cdf0e10cSrcweir // try to use optimized copying 1380*cdf0e10cSrcweir uno::Reference< embed::XOptimizedStorage > xSource( m_xParentStorage, uno::UNO_QUERY_THROW ); 1381*cdf0e10cSrcweir uno::Reference< embed::XOptimizedStorage > xTarget( xStorage, uno::UNO_QUERY_THROW ); 1382*cdf0e10cSrcweir xSource->copyElementDirectlyTo( m_aEntryName, xTarget, sEntName ); 1383*cdf0e10cSrcweir bOptimizationWorks = sal_True; 1384*cdf0e10cSrcweir } 1385*cdf0e10cSrcweir catch( uno::Exception& ) 1386*cdf0e10cSrcweir { 1387*cdf0e10cSrcweir } 1388*cdf0e10cSrcweir } 1389*cdf0e10cSrcweir 1390*cdf0e10cSrcweir if ( !bOptimizationWorks ) 1391*cdf0e10cSrcweir m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName ); 1392*cdf0e10cSrcweir } 1393*cdf0e10cSrcweir else 1394*cdf0e10cSrcweir { 1395*cdf0e10cSrcweir changeState( embed::EmbedStates::RUNNING ); 1396*cdf0e10cSrcweir bSwitchBackToLoaded = sal_True; 1397*cdf0e10cSrcweir } 1398*cdf0e10cSrcweir } 1399*cdf0e10cSrcweir 1400*cdf0e10cSrcweir uno::Reference< embed::XStorage > xSubStorage = 1401*cdf0e10cSrcweir xStorage->openStorageElement( sEntName, embed::ElementModes::READWRITE ); 1402*cdf0e10cSrcweir 1403*cdf0e10cSrcweir if ( !xSubStorage.is() ) 1404*cdf0e10cSrcweir throw uno::RuntimeException(); //TODO 1405*cdf0e10cSrcweir 1406*cdf0e10cSrcweir if ( m_nObjectState != embed::EmbedStates::LOADED ) 1407*cdf0e10cSrcweir { 1408*cdf0e10cSrcweir aGuard.clear(); 1409*cdf0e10cSrcweir // TODO/LATER: support hierarchical name for embedded objects in embedded objects 1410*cdf0e10cSrcweir StoreDocToStorage_Impl( xSubStorage, nTargetStorageFormat, GetBaseURLFrom_Impl( lArguments, lObjArgs ), sEntName, sal_False ); 1411*cdf0e10cSrcweir aGuard.reset(); 1412*cdf0e10cSrcweir 1413*cdf0e10cSrcweir if ( bSwitchBackToLoaded ) 1414*cdf0e10cSrcweir changeState( embed::EmbedStates::LOADED ); 1415*cdf0e10cSrcweir } 1416*cdf0e10cSrcweir 1417*cdf0e10cSrcweir m_bWaitSaveCompleted = sal_True; 1418*cdf0e10cSrcweir m_xNewObjectStorage = xSubStorage; 1419*cdf0e10cSrcweir m_xNewParentStorage = xStorage; 1420*cdf0e10cSrcweir m_aNewEntryName = sEntName; 1421*cdf0e10cSrcweir m_aNewDocMediaDescriptor = GetValuableArgs_Impl( lArguments, sal_True ); 1422*cdf0e10cSrcweir 1423*cdf0e10cSrcweir // TODO: register listeners for storages above, in case thay are disposed 1424*cdf0e10cSrcweir // an exception will be thrown on saveCompleted( true ) 1425*cdf0e10cSrcweir 1426*cdf0e10cSrcweir // TODO: should the listener notification be done here or in saveCompleted? 1427*cdf0e10cSrcweir } 1428*cdf0e10cSrcweir 1429*cdf0e10cSrcweir //------------------------------------------------------ 1430*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::saveCompleted( sal_Bool bUseNew ) 1431*cdf0e10cSrcweir throw ( embed::WrongStateException, 1432*cdf0e10cSrcweir uno::Exception, 1433*cdf0e10cSrcweir uno::RuntimeException ) 1434*cdf0e10cSrcweir { 1435*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::saveCompleted" ); 1436*cdf0e10cSrcweir 1437*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1438*cdf0e10cSrcweir if ( m_bDisposed ) 1439*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1440*cdf0e10cSrcweir 1441*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1442*cdf0e10cSrcweir { 1443*cdf0e10cSrcweir // the object is still not loaded 1444*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ), 1445*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1446*cdf0e10cSrcweir } 1447*cdf0e10cSrcweir 1448*cdf0e10cSrcweir // for now support of this interface is required to allow breaking of links and converting them to normal embedded 1449*cdf0e10cSrcweir // objects, so the persist name must be handled correctly ( althowgh no real persist entry is used ) 1450*cdf0e10cSrcweir // OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" ); 1451*cdf0e10cSrcweir if ( m_bIsLink ) 1452*cdf0e10cSrcweir { 1453*cdf0e10cSrcweir if ( bUseNew ) 1454*cdf0e10cSrcweir m_aEntryName = m_aNewEntryName; 1455*cdf0e10cSrcweir m_aNewEntryName = ::rtl::OUString(); 1456*cdf0e10cSrcweir return; 1457*cdf0e10cSrcweir } 1458*cdf0e10cSrcweir 1459*cdf0e10cSrcweir // it is allowed to call saveCompleted( false ) for nonstored objects 1460*cdf0e10cSrcweir if ( !m_bWaitSaveCompleted && !bUseNew ) 1461*cdf0e10cSrcweir return; 1462*cdf0e10cSrcweir 1463*cdf0e10cSrcweir OSL_ENSURE( m_bWaitSaveCompleted, "Unexpected saveCompleted() call!\n" ); 1464*cdf0e10cSrcweir if ( !m_bWaitSaveCompleted ) 1465*cdf0e10cSrcweir throw io::IOException(); // TODO: illegal call 1466*cdf0e10cSrcweir 1467*cdf0e10cSrcweir OSL_ENSURE( m_xNewObjectStorage.is() && m_xNewParentStorage.is() , "Internal object information is broken!\n" ); 1468*cdf0e10cSrcweir if ( !m_xNewObjectStorage.is() || !m_xNewParentStorage.is() ) 1469*cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: broken internal information 1470*cdf0e10cSrcweir 1471*cdf0e10cSrcweir if ( bUseNew ) 1472*cdf0e10cSrcweir { 1473*cdf0e10cSrcweir SwitchOwnPersistence( m_xNewParentStorage, m_xNewObjectStorage, m_aNewEntryName ); 1474*cdf0e10cSrcweir m_aDocMediaDescriptor = m_aNewDocMediaDescriptor; 1475*cdf0e10cSrcweir 1476*cdf0e10cSrcweir uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 1477*cdf0e10cSrcweir if ( xModif.is() ) 1478*cdf0e10cSrcweir xModif->setModified( sal_False ); 1479*cdf0e10cSrcweir 1480*cdf0e10cSrcweir PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSaveAsDone" ) ); 1481*cdf0e10cSrcweir } 1482*cdf0e10cSrcweir else 1483*cdf0e10cSrcweir { 1484*cdf0e10cSrcweir try { 1485*cdf0e10cSrcweir uno::Reference< lang::XComponent > xComponent( m_xNewObjectStorage, uno::UNO_QUERY ); 1486*cdf0e10cSrcweir OSL_ENSURE( xComponent.is(), "Wrong storage implementation!" ); 1487*cdf0e10cSrcweir if ( xComponent.is() ) 1488*cdf0e10cSrcweir xComponent->dispose(); 1489*cdf0e10cSrcweir } 1490*cdf0e10cSrcweir catch ( uno::Exception& ) 1491*cdf0e10cSrcweir { 1492*cdf0e10cSrcweir } 1493*cdf0e10cSrcweir } 1494*cdf0e10cSrcweir 1495*cdf0e10cSrcweir m_xNewObjectStorage = uno::Reference< embed::XStorage >(); 1496*cdf0e10cSrcweir m_xNewParentStorage = uno::Reference< embed::XStorage >(); 1497*cdf0e10cSrcweir m_aNewEntryName = ::rtl::OUString(); 1498*cdf0e10cSrcweir m_aNewDocMediaDescriptor.realloc( 0 ); 1499*cdf0e10cSrcweir m_bWaitSaveCompleted = sal_False; 1500*cdf0e10cSrcweir 1501*cdf0e10cSrcweir if ( bUseNew ) 1502*cdf0e10cSrcweir { 1503*cdf0e10cSrcweir // TODO: notify listeners 1504*cdf0e10cSrcweir 1505*cdf0e10cSrcweir if ( m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE ) 1506*cdf0e10cSrcweir { 1507*cdf0e10cSrcweir // TODO: update visual representation 1508*cdf0e10cSrcweir } 1509*cdf0e10cSrcweir } 1510*cdf0e10cSrcweir } 1511*cdf0e10cSrcweir 1512*cdf0e10cSrcweir //------------------------------------------------------ 1513*cdf0e10cSrcweir sal_Bool SAL_CALL OCommonEmbeddedObject::hasEntry() 1514*cdf0e10cSrcweir throw ( embed::WrongStateException, 1515*cdf0e10cSrcweir uno::RuntimeException ) 1516*cdf0e10cSrcweir { 1517*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1518*cdf0e10cSrcweir if ( m_bDisposed ) 1519*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1520*cdf0e10cSrcweir 1521*cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1522*cdf0e10cSrcweir throw embed::WrongStateException( 1523*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1524*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1525*cdf0e10cSrcweir 1526*cdf0e10cSrcweir if ( m_xObjectStorage.is() ) 1527*cdf0e10cSrcweir return sal_True; 1528*cdf0e10cSrcweir 1529*cdf0e10cSrcweir return sal_False; 1530*cdf0e10cSrcweir } 1531*cdf0e10cSrcweir 1532*cdf0e10cSrcweir //------------------------------------------------------ 1533*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OCommonEmbeddedObject::getEntryName() 1534*cdf0e10cSrcweir throw ( embed::WrongStateException, 1535*cdf0e10cSrcweir uno::RuntimeException ) 1536*cdf0e10cSrcweir { 1537*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1538*cdf0e10cSrcweir if ( m_bDisposed ) 1539*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1540*cdf0e10cSrcweir 1541*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1542*cdf0e10cSrcweir { 1543*cdf0e10cSrcweir // the object is still not loaded 1544*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ), 1545*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1546*cdf0e10cSrcweir } 1547*cdf0e10cSrcweir 1548*cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1549*cdf0e10cSrcweir throw embed::WrongStateException( 1550*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1551*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1552*cdf0e10cSrcweir 1553*cdf0e10cSrcweir return m_aEntryName; 1554*cdf0e10cSrcweir } 1555*cdf0e10cSrcweir 1556*cdf0e10cSrcweir //------------------------------------------------------ 1557*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::storeOwn() 1558*cdf0e10cSrcweir throw ( embed::WrongStateException, 1559*cdf0e10cSrcweir io::IOException, 1560*cdf0e10cSrcweir uno::Exception, 1561*cdf0e10cSrcweir uno::RuntimeException ) 1562*cdf0e10cSrcweir { 1563*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::storeOwn" ); 1564*cdf0e10cSrcweir 1565*cdf0e10cSrcweir // during switching from Activated to Running and from Running to Loaded states the object will 1566*cdf0e10cSrcweir // ask container to store the object, the container has to make decision 1567*cdf0e10cSrcweir // to do so or not 1568*cdf0e10cSrcweir 1569*cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 1570*cdf0e10cSrcweir if ( m_bDisposed ) 1571*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1572*cdf0e10cSrcweir 1573*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1574*cdf0e10cSrcweir { 1575*cdf0e10cSrcweir // the object is still not loaded 1576*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ), 1577*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1578*cdf0e10cSrcweir } 1579*cdf0e10cSrcweir 1580*cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1581*cdf0e10cSrcweir throw embed::WrongStateException( 1582*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1583*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1584*cdf0e10cSrcweir 1585*cdf0e10cSrcweir if ( m_bReadOnly ) 1586*cdf0e10cSrcweir throw io::IOException(); // TODO: access denied 1587*cdf0e10cSrcweir 1588*cdf0e10cSrcweir // nothing to do, if the object is in loaded state 1589*cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED ) 1590*cdf0e10cSrcweir return; 1591*cdf0e10cSrcweir 1592*cdf0e10cSrcweir PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSave" ) ); 1593*cdf0e10cSrcweir 1594*cdf0e10cSrcweir OSL_ENSURE( m_pDocHolder->GetComponent().is(), "If an object is activated or in running state it must have a document!\n" ); 1595*cdf0e10cSrcweir if ( !m_pDocHolder->GetComponent().is() ) 1596*cdf0e10cSrcweir throw uno::RuntimeException(); 1597*cdf0e10cSrcweir 1598*cdf0e10cSrcweir if ( m_bIsLink ) 1599*cdf0e10cSrcweir { 1600*cdf0e10cSrcweir // TODO: just store the document to it's location 1601*cdf0e10cSrcweir uno::Reference< frame::XStorable > xStorable( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 1602*cdf0e10cSrcweir if ( !xStorable.is() ) 1603*cdf0e10cSrcweir throw uno::RuntimeException(); // TODO 1604*cdf0e10cSrcweir 1605*cdf0e10cSrcweir // free the main mutex for the storing time 1606*cdf0e10cSrcweir aGuard.clear(); 1607*cdf0e10cSrcweir 1608*cdf0e10cSrcweir xStorable->store(); 1609*cdf0e10cSrcweir 1610*cdf0e10cSrcweir aGuard.reset(); 1611*cdf0e10cSrcweir } 1612*cdf0e10cSrcweir else 1613*cdf0e10cSrcweir { 1614*cdf0e10cSrcweir OSL_ENSURE( m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" ); 1615*cdf0e10cSrcweir 1616*cdf0e10cSrcweir if ( !m_xObjectStorage.is() ) 1617*cdf0e10cSrcweir throw io::IOException(); //TODO: access denied 1618*cdf0e10cSrcweir 1619*cdf0e10cSrcweir sal_Int32 nStorageFormat = SOFFICE_FILEFORMAT_CURRENT; 1620*cdf0e10cSrcweir try { 1621*cdf0e10cSrcweir nStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( m_xParentStorage ); 1622*cdf0e10cSrcweir } 1623*cdf0e10cSrcweir catch ( beans::IllegalTypeException& ) 1624*cdf0e10cSrcweir { 1625*cdf0e10cSrcweir // the container just has an unknown type, use current file format 1626*cdf0e10cSrcweir } 1627*cdf0e10cSrcweir catch ( uno::Exception& ) 1628*cdf0e10cSrcweir { 1629*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Can not retrieve storage media type!\n" ); 1630*cdf0e10cSrcweir } 1631*cdf0e10cSrcweir 1632*cdf0e10cSrcweir aGuard.clear(); 1633*cdf0e10cSrcweir StoreDocToStorage_Impl( m_xObjectStorage, nStorageFormat, GetBaseURL_Impl(), m_aEntryName, sal_True ); 1634*cdf0e10cSrcweir aGuard.reset(); 1635*cdf0e10cSrcweir } 1636*cdf0e10cSrcweir 1637*cdf0e10cSrcweir uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 1638*cdf0e10cSrcweir if ( xModif.is() ) 1639*cdf0e10cSrcweir xModif->setModified( sal_False ); 1640*cdf0e10cSrcweir 1641*cdf0e10cSrcweir PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSaveDone" ) ); 1642*cdf0e10cSrcweir } 1643*cdf0e10cSrcweir 1644*cdf0e10cSrcweir //------------------------------------------------------ 1645*cdf0e10cSrcweir sal_Bool SAL_CALL OCommonEmbeddedObject::isReadonly() 1646*cdf0e10cSrcweir throw ( embed::WrongStateException, 1647*cdf0e10cSrcweir uno::RuntimeException ) 1648*cdf0e10cSrcweir { 1649*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1650*cdf0e10cSrcweir if ( m_bDisposed ) 1651*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1652*cdf0e10cSrcweir 1653*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1654*cdf0e10cSrcweir { 1655*cdf0e10cSrcweir // the object is still not loaded 1656*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ), 1657*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1658*cdf0e10cSrcweir } 1659*cdf0e10cSrcweir 1660*cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1661*cdf0e10cSrcweir throw embed::WrongStateException( 1662*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1663*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1664*cdf0e10cSrcweir 1665*cdf0e10cSrcweir return m_bReadOnly; 1666*cdf0e10cSrcweir } 1667*cdf0e10cSrcweir 1668*cdf0e10cSrcweir //------------------------------------------------------ 1669*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::reload( 1670*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lArguments, 1671*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 1672*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 1673*cdf0e10cSrcweir embed::WrongStateException, 1674*cdf0e10cSrcweir io::IOException, 1675*cdf0e10cSrcweir uno::Exception, 1676*cdf0e10cSrcweir uno::RuntimeException ) 1677*cdf0e10cSrcweir { 1678*cdf0e10cSrcweir // TODO: use lObjArgs 1679*cdf0e10cSrcweir // for now this method is used only to switch readonly state 1680*cdf0e10cSrcweir 1681*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1682*cdf0e10cSrcweir if ( m_bDisposed ) 1683*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1684*cdf0e10cSrcweir 1685*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1686*cdf0e10cSrcweir { 1687*cdf0e10cSrcweir // the object is still not loaded 1688*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ), 1689*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1690*cdf0e10cSrcweir } 1691*cdf0e10cSrcweir 1692*cdf0e10cSrcweir if ( m_nObjectState != embed::EmbedStates::LOADED ) 1693*cdf0e10cSrcweir { 1694*cdf0e10cSrcweir // the object is still not loaded 1695*cdf0e10cSrcweir throw embed::WrongStateException( 1696*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object must be in loaded state to be reloaded!\n" ), 1697*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1698*cdf0e10cSrcweir } 1699*cdf0e10cSrcweir 1700*cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1701*cdf0e10cSrcweir throw embed::WrongStateException( 1702*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1703*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1704*cdf0e10cSrcweir 1705*cdf0e10cSrcweir if ( m_bIsLink ) 1706*cdf0e10cSrcweir { 1707*cdf0e10cSrcweir // reload of the link 1708*cdf0e10cSrcweir ::rtl::OUString aOldLinkFilter = m_aLinkFilterName; 1709*cdf0e10cSrcweir 1710*cdf0e10cSrcweir ::rtl::OUString aNewLinkFilter; 1711*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ ) 1712*cdf0e10cSrcweir { 1713*cdf0e10cSrcweir if ( lArguments[nInd].Name.equalsAscii( "URL" ) ) 1714*cdf0e10cSrcweir { 1715*cdf0e10cSrcweir // the new URL 1716*cdf0e10cSrcweir lArguments[nInd].Value >>= m_aLinkURL; 1717*cdf0e10cSrcweir m_aLinkFilterName = ::rtl::OUString(); 1718*cdf0e10cSrcweir } 1719*cdf0e10cSrcweir else if ( lArguments[nInd].Name.equalsAscii( "FilterName" ) ) 1720*cdf0e10cSrcweir { 1721*cdf0e10cSrcweir lArguments[nInd].Value >>= aNewLinkFilter; 1722*cdf0e10cSrcweir m_aLinkFilterName = ::rtl::OUString(); 1723*cdf0e10cSrcweir } 1724*cdf0e10cSrcweir } 1725*cdf0e10cSrcweir 1726*cdf0e10cSrcweir ::comphelper::MimeConfigurationHelper aHelper( m_xFactory ); 1727*cdf0e10cSrcweir if ( !m_aLinkFilterName.getLength() ) 1728*cdf0e10cSrcweir { 1729*cdf0e10cSrcweir if ( aNewLinkFilter.getLength() ) 1730*cdf0e10cSrcweir m_aLinkFilterName = aNewLinkFilter; 1731*cdf0e10cSrcweir else 1732*cdf0e10cSrcweir { 1733*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aArgs( 1 ); 1734*cdf0e10cSrcweir aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ); 1735*cdf0e10cSrcweir aArgs[0].Value <<= m_aLinkURL; 1736*cdf0e10cSrcweir m_aLinkFilterName = aHelper.UpdateMediaDescriptorWithFilterName( aArgs, sal_False ); 1737*cdf0e10cSrcweir } 1738*cdf0e10cSrcweir } 1739*cdf0e10cSrcweir 1740*cdf0e10cSrcweir if ( !aOldLinkFilter.equals( m_aLinkFilterName ) ) 1741*cdf0e10cSrcweir { 1742*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aObject = aHelper.GetObjectPropsByFilter( m_aLinkFilterName ); 1743*cdf0e10cSrcweir 1744*cdf0e10cSrcweir // TODO/LATER: probably the document holder could be cleaned explicitly as in the destructor 1745*cdf0e10cSrcweir m_pDocHolder->release(); 1746*cdf0e10cSrcweir m_pDocHolder = NULL; 1747*cdf0e10cSrcweir 1748*cdf0e10cSrcweir LinkInit_Impl( aObject, lArguments, lObjArgs ); 1749*cdf0e10cSrcweir } 1750*cdf0e10cSrcweir } 1751*cdf0e10cSrcweir 1752*cdf0e10cSrcweir m_aDocMediaDescriptor = GetValuableArgs_Impl( lArguments, sal_True ); 1753*cdf0e10cSrcweir 1754*cdf0e10cSrcweir // TODO: use lObjArgs for StoreVisualReplacement 1755*cdf0e10cSrcweir for ( sal_Int32 nObjInd = 0; nObjInd < lObjArgs.getLength(); nObjInd++ ) 1756*cdf0e10cSrcweir if ( lObjArgs[nObjInd].Name.equalsAscii( "OutplaceDispatchInterceptor" ) ) 1757*cdf0e10cSrcweir { 1758*cdf0e10cSrcweir uno::Reference< frame::XDispatchProviderInterceptor > xDispatchInterceptor; 1759*cdf0e10cSrcweir if ( lObjArgs[nObjInd].Value >>= xDispatchInterceptor ) 1760*cdf0e10cSrcweir m_pDocHolder->SetOutplaceDispatchInterceptor( xDispatchInterceptor ); 1761*cdf0e10cSrcweir 1762*cdf0e10cSrcweir break; 1763*cdf0e10cSrcweir } 1764*cdf0e10cSrcweir 1765*cdf0e10cSrcweir // TODO: 1766*cdf0e10cSrcweir // when document allows reloading through API the object can be reloaded not only in loaded state 1767*cdf0e10cSrcweir 1768*cdf0e10cSrcweir sal_Bool bOldReadOnlyValue = m_bReadOnly; 1769*cdf0e10cSrcweir 1770*cdf0e10cSrcweir m_bReadOnly = sal_False; 1771*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ ) 1772*cdf0e10cSrcweir if ( lArguments[nInd].Name.equalsAscii( "ReadOnly" ) ) 1773*cdf0e10cSrcweir lArguments[nInd].Value >>= m_bReadOnly; 1774*cdf0e10cSrcweir 1775*cdf0e10cSrcweir if ( bOldReadOnlyValue != m_bReadOnly && !m_bIsLink ) 1776*cdf0e10cSrcweir { 1777*cdf0e10cSrcweir // close own storage 1778*cdf0e10cSrcweir try { 1779*cdf0e10cSrcweir uno::Reference< lang::XComponent > xComponent( m_xObjectStorage, uno::UNO_QUERY ); 1780*cdf0e10cSrcweir OSL_ENSURE( !m_xObjectStorage.is() || xComponent.is(), "Wrong storage implementation!" ); 1781*cdf0e10cSrcweir if ( xComponent.is() ) 1782*cdf0e10cSrcweir xComponent->dispose(); 1783*cdf0e10cSrcweir } 1784*cdf0e10cSrcweir catch ( uno::Exception& ) 1785*cdf0e10cSrcweir { 1786*cdf0e10cSrcweir } 1787*cdf0e10cSrcweir 1788*cdf0e10cSrcweir sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE; 1789*cdf0e10cSrcweir m_xObjectStorage = m_xParentStorage->openStorageElement( m_aEntryName, nStorageMode ); 1790*cdf0e10cSrcweir } 1791*cdf0e10cSrcweir } 1792*cdf0e10cSrcweir 1793*cdf0e10cSrcweir //------------------------------------------------------ 1794*cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::breakLink( const uno::Reference< embed::XStorage >& xStorage, 1795*cdf0e10cSrcweir const ::rtl::OUString& sEntName ) 1796*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 1797*cdf0e10cSrcweir embed::WrongStateException, 1798*cdf0e10cSrcweir io::IOException, 1799*cdf0e10cSrcweir uno::Exception, 1800*cdf0e10cSrcweir uno::RuntimeException ) 1801*cdf0e10cSrcweir { 1802*cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 1803*cdf0e10cSrcweir if ( m_bDisposed ) 1804*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1805*cdf0e10cSrcweir 1806*cdf0e10cSrcweir if ( !m_bIsLink ) 1807*cdf0e10cSrcweir { 1808*cdf0e10cSrcweir // it must be a linked initialized object 1809*cdf0e10cSrcweir throw embed::WrongStateException( 1810*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object is not a valid linked object!\n" ), 1811*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1812*cdf0e10cSrcweir } 1813*cdf0e10cSrcweir #if 0 1814*cdf0e10cSrcweir else 1815*cdf0e10cSrcweir { 1816*cdf0e10cSrcweir // the current implementation of OOo links does not implement this method since it does not implement 1817*cdf0e10cSrcweir // all the set of interfaces required for OOo embedded object ( XEmbedPersist is not supported ). 1818*cdf0e10cSrcweir throw io::IOException(); // TODO: 1819*cdf0e10cSrcweir } 1820*cdf0e10cSrcweir #endif 1821*cdf0e10cSrcweir 1822*cdf0e10cSrcweir if ( !xStorage.is() ) 1823*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 1824*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 1825*cdf0e10cSrcweir 1 ); 1826*cdf0e10cSrcweir 1827*cdf0e10cSrcweir if ( !sEntName.getLength() ) 1828*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 1829*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 1830*cdf0e10cSrcweir 2 ); 1831*cdf0e10cSrcweir 1832*cdf0e10cSrcweir if ( !m_bIsLink || m_nObjectState == -1 ) 1833*cdf0e10cSrcweir { 1834*cdf0e10cSrcweir // it must be a linked initialized object 1835*cdf0e10cSrcweir throw embed::WrongStateException( 1836*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object is not a valid linked object!\n" ), 1837*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1838*cdf0e10cSrcweir } 1839*cdf0e10cSrcweir 1840*cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1841*cdf0e10cSrcweir throw embed::WrongStateException( 1842*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1843*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1844*cdf0e10cSrcweir 1845*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY ); 1846*cdf0e10cSrcweir if ( !xNameAccess.is() ) 1847*cdf0e10cSrcweir throw uno::RuntimeException(); //TODO 1848*cdf0e10cSrcweir 1849*cdf0e10cSrcweir // detect entry existence 1850*cdf0e10cSrcweir /*sal_Bool bElExists =*/ xNameAccess->hasByName( sEntName ); 1851*cdf0e10cSrcweir 1852*cdf0e10cSrcweir m_bReadOnly = sal_False; 1853*cdf0e10cSrcweir // sal_Int32 nStorageMode = embed::ElementModes::READWRITE; 1854*cdf0e10cSrcweir 1855*cdf0e10cSrcweir if ( m_xParentStorage != xStorage || !m_aEntryName.equals( sEntName ) ) 1856*cdf0e10cSrcweir SwitchOwnPersistence( xStorage, sEntName ); 1857*cdf0e10cSrcweir 1858*cdf0e10cSrcweir // for linked object it means that it becomes embedded object 1859*cdf0e10cSrcweir // the document must switch it's persistence also 1860*cdf0e10cSrcweir 1861*cdf0e10cSrcweir // TODO/LATER: handle the case when temp doc can not be created 1862*cdf0e10cSrcweir // the document is a new embedded object so it must be marked as modified 1863*cdf0e10cSrcweir uno::Reference< util::XCloseable > xDocument = CreateTempDocFromLink_Impl(); 1864*cdf0e10cSrcweir uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 1865*cdf0e10cSrcweir if ( !xModif.is() ) 1866*cdf0e10cSrcweir throw uno::RuntimeException(); 1867*cdf0e10cSrcweir try 1868*cdf0e10cSrcweir { 1869*cdf0e10cSrcweir xModif->setModified( sal_True ); 1870*cdf0e10cSrcweir } 1871*cdf0e10cSrcweir catch( uno::Exception& ) 1872*cdf0e10cSrcweir {} 1873*cdf0e10cSrcweir 1874*cdf0e10cSrcweir m_pDocHolder->SetComponent( xDocument, m_bReadOnly ); 1875*cdf0e10cSrcweir OSL_ENSURE( m_pDocHolder->GetComponent().is(), "If document cant be created, an exception must be thrown!\n" ); 1876*cdf0e10cSrcweir 1877*cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED ) 1878*cdf0e10cSrcweir { 1879*cdf0e10cSrcweir // the state is changed and can not be switched to loaded state back without saving 1880*cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::RUNNING; 1881*cdf0e10cSrcweir StateChangeNotification_Impl( sal_False, embed::EmbedStates::LOADED, m_nObjectState, aGuard ); 1882*cdf0e10cSrcweir } 1883*cdf0e10cSrcweir else if ( m_nObjectState == embed::EmbedStates::ACTIVE ) 1884*cdf0e10cSrcweir m_pDocHolder->Show(); 1885*cdf0e10cSrcweir 1886*cdf0e10cSrcweir m_bIsLink = sal_False; 1887*cdf0e10cSrcweir m_aLinkFilterName = ::rtl::OUString(); 1888*cdf0e10cSrcweir m_aLinkURL = ::rtl::OUString(); 1889*cdf0e10cSrcweir } 1890*cdf0e10cSrcweir 1891*cdf0e10cSrcweir //------------------------------------------------------ 1892*cdf0e10cSrcweir sal_Bool SAL_CALL OCommonEmbeddedObject::isLink() 1893*cdf0e10cSrcweir throw ( embed::WrongStateException, 1894*cdf0e10cSrcweir uno::RuntimeException ) 1895*cdf0e10cSrcweir { 1896*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1897*cdf0e10cSrcweir if ( m_bDisposed ) 1898*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1899*cdf0e10cSrcweir 1900*cdf0e10cSrcweir // Actually this information is clear even in case object is wayting for saveCompleted 1901*cdf0e10cSrcweir // if ( m_bWaitSaveCompleted ) 1902*cdf0e10cSrcweir // throw embed::WrongStateException( 1903*cdf0e10cSrcweir // ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1904*cdf0e10cSrcweir // uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); 1905*cdf0e10cSrcweir 1906*cdf0e10cSrcweir return m_bIsLink; 1907*cdf0e10cSrcweir } 1908*cdf0e10cSrcweir 1909*cdf0e10cSrcweir //------------------------------------------------------ 1910*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OCommonEmbeddedObject::getLinkURL() 1911*cdf0e10cSrcweir throw ( embed::WrongStateException, 1912*cdf0e10cSrcweir uno::Exception, 1913*cdf0e10cSrcweir uno::RuntimeException ) 1914*cdf0e10cSrcweir { 1915*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1916*cdf0e10cSrcweir if ( m_bDisposed ) 1917*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1918*cdf0e10cSrcweir 1919*cdf0e10cSrcweir // Actually this information is clear even in case object is wayting for saveCompleted 1920*cdf0e10cSrcweir // if ( m_bWaitSaveCompleted ) 1921*cdf0e10cSrcweir // throw embed::WrongStateException( 1922*cdf0e10cSrcweir // ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1923*cdf0e10cSrcweir // uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); 1924*cdf0e10cSrcweir 1925*cdf0e10cSrcweir if ( !m_bIsLink ) 1926*cdf0e10cSrcweir throw embed::WrongStateException( 1927*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object is not a link object!\n" ), 1928*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1929*cdf0e10cSrcweir 1930*cdf0e10cSrcweir return m_aLinkURL; 1931*cdf0e10cSrcweir } 1932*cdf0e10cSrcweir 1933