21#include <com/sun/star/embed/Aspects.hpp>
22#include <com/sun/star/document/XStorageBasedDocument.hpp>
23#include <com/sun/star/embed/EmbedStates.hpp>
24#include <com/sun/star/embed/EntryInitModes.hpp>
25#include <com/sun/star/embed/StorageWrappedTargetException.hpp>
26#include <com/sun/star/embed/WrongStateException.hpp>
27#include <com/sun/star/embed/XStorage.hpp>
28#include <com/sun/star/embed/XOptimizedStorage.hpp>
29#include <com/sun/star/embed/ElementModes.hpp>
30#include <com/sun/star/embed/EmbedUpdateModes.hpp>
31#include <com/sun/star/embed/StorageFactory.hpp>
32#include <com/sun/star/io/IOException.hpp>
33#include <com/sun/star/io/TempFile.hpp>
34#include <com/sun/star/frame/XModel.hpp>
35#include <com/sun/star/frame/XStorable.hpp>
36#include <com/sun/star/frame/XLoadable.hpp>
37#include <com/sun/star/frame/XModule.hpp>
38#include <com/sun/star/lang/NoSupportException.hpp>
39#include <com/sun/star/lang/XSingleServiceFactory.hpp>
40#include <com/sun/star/lang/DisposedException.hpp>
41#include <com/sun/star/util/XModifiable.hpp>
43#include <com/sun/star/container/XNameAccess.hpp>
44#include <com/sun/star/container/XChild.hpp>
45#include <com/sun/star/util/XCloseable.hpp>
46#include <com/sun/star/beans/XPropertySet.hpp>
47#include <com/sun/star/beans/IllegalTypeException.hpp>
48#include <com/sun/star/chart2/XChartDocument.hpp>
50#include <com/sun/star/ucb/SimpleFileAccess.hpp>
67uno::Sequence< beans::PropertyValue >
GetValuableArgs_Impl(
const uno::Sequence< beans::PropertyValue >& aMedDescr,
68 bool bCanUseDocumentBaseURL )
70 uno::Sequence< beans::PropertyValue > aResult;
71 sal_Int32 nResLen = 0;
73 for ( beans::PropertyValue
const & prop : aMedDescr )
75 if ( prop.Name ==
"ComponentData" || prop.Name ==
"DocumentTitle"
76 || prop.Name ==
"InteractionHandler" || prop.Name ==
"JumpMark"
78 || prop.Name ==
"Preview" || prop.Name ==
"ReadOnly"
79 || prop.Name ==
"StartPresentation" || prop.Name ==
"RepairPackage"
80 || prop.Name ==
"StatusIndicator" || prop.Name ==
"ViewData"
81 || prop.Name ==
"ViewId" || prop.Name ==
"MacroExecutionMode"
82 || prop.Name ==
"UpdateDocMode"
83 || (prop.Name ==
"DocumentBaseURL" && bCanUseDocumentBaseURL) )
85 aResult.realloc( ++nResLen );
86 aResult.getArray()[nResLen-1] = prop;
94static uno::Sequence< beans::PropertyValue >
addAsTemplate(
const uno::Sequence< beans::PropertyValue >& aOrig )
96 bool bAsTemplateSet =
false;
97 sal_Int32
nLength = aOrig.getLength();
98 uno::Sequence< beans::PropertyValue > aResult( aOrig );
100 for ( sal_Int32 nInd = 0; nInd <
nLength; nInd++ )
102 if ( aResult[nInd].
Name ==
"AsTemplate" )
104 aResult.getArray()[nInd].Value <<=
true;
105 bAsTemplateSet =
true;
109 if ( !bAsTemplateSet )
111 aResult.realloc(
nLength + 1 );
112 auto pResult = aResult.getArray();
113 pResult[
nLength].Name =
"AsTemplate";
114 pResult[
nLength].Value <<=
true;
122 const uno::Reference< embed::XStorage >& xStorage,
123 const uno::Reference< uno::XComponentContext >& xContext )
125 SAL_WARN_IF( !xStorage.is(),
"embeddedobj.common",
"The storage can not be empty!" );
127 uno::Reference< io::XInputStream > xResult;
129 uno::Reference < io::XStream > xTempStream( io::TempFile::create(xContext), uno::UNO_QUERY_THROW );
131 uno::Reference < lang::XSingleServiceFactory > xStorageFactory( embed::StorageFactory::create(xContext) );
133 uno::Sequence< uno::Any > aArgs{
uno::Any(xTempStream),
134 uno::Any(embed::ElementModes::READWRITE) };
135 uno::Reference< embed::XStorage > xTempStorage( xStorageFactory->createInstanceWithArguments( aArgs ),
136 uno::UNO_QUERY_THROW );
140 xStorage->copyToStorage( xTempStorage );
141 }
catch(
const uno::Exception& )
144 throw embed::StorageWrappedTargetException(
145 "Can't copy storage!",
146 uno::Reference< uno::XInterface >(),
151 if ( xTempStorage.is() )
152 xTempStorage->dispose();
154 catch (
const uno::Exception& )
159 uno::Reference< io::XOutputStream > xTempOut = xTempStream->getOutputStream();
161 xTempOut->closeOutput();
163 catch (
const uno::Exception& )
167 xResult = xTempStream->getInputStream();
174static void TransferMediaType(
const uno::Reference< embed::XStorage >& i_rSource,
const uno::Reference< embed::XStorage >& i_rTarget )
178 const uno::Reference< beans::XPropertySet > xSourceProps( i_rSource, uno::UNO_QUERY_THROW );
179 const uno::Reference< beans::XPropertySet > xTargetProps( i_rTarget, uno::UNO_QUERY_THROW );
180 static constexpr OUStringLiteral sMediaTypePropName(
u"MediaType" );
181 xTargetProps->setPropertyValue( sMediaTypePropName, xSourceProps->getPropertyValue( sMediaTypePropName ) );
183 catch(
const uno::Exception& )
190static uno::Reference< util::XCloseable >
CreateDocument(
const uno::Reference< uno::XComponentContext >& _rxContext,
191 const OUString& _rDocumentServiceName,
bool _bEmbeddedScriptSupport,
const bool i_bDocumentRecoverySupport )
193 static constexpr OUStringLiteral sEmbeddedObject =
u"EmbeddedObject";
194 static constexpr OUStringLiteral sEmbeddedScriptSupport =
u"EmbeddedScriptSupport";
195 static constexpr OUStringLiteral sDocumentRecoverySupport =
u"DocumentRecoverySupport";
198 aArguments.put( sEmbeddedScriptSupport, _bEmbeddedScriptSupport );
199 aArguments.put( sDocumentRecoverySupport, i_bDocumentRecoverySupport );
201 uno::Reference< uno::XInterface > xDocument;
204 xDocument = _rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
205 _rDocumentServiceName,
aArguments.getWrappedPropertyValues(), _rxContext );
207 catch(
const uno::Exception& )
213 OSL_FAIL(
"Consider implementing interface XInitialization to avoid duplicate construction");
214 xDocument = _rxContext->getServiceManager()->createInstanceWithContext( _rDocumentServiceName, _rxContext );
217 SAL_WARN_IF(!xDocument.is(),
"embeddedobj.common",
"Service " << _rDocumentServiceName <<
" is not available?");
218 return uno::Reference< util::XCloseable >( xDocument, uno::UNO_QUERY );
222static void SetDocToEmbedded(
const uno::Reference< frame::XModel >& rDocument,
const OUString& aModuleName )
228 rDocument->attachResource( OUString(),
aSeq );
230 if ( !aModuleName.isEmpty() )
234 uno::Reference< frame::XModule > xModule( rDocument, uno::UNO_QUERY_THROW );
235 xModule->setIdentifier( aModuleName );
237 catch(
const uno::Exception& )
244 const uno::Reference< embed::XStorage >& xNewObjectStorage,
245 const OUString& aNewName )
261 uno::Reference< document::XStorageBasedDocument > xDoc(
m_xDocHolder->GetComponent(), uno::UNO_QUERY );
267 if ( xOldObjectStorage.is() )
268 xOldObjectStorage->dispose();
270 catch (
const uno::Exception& )
277 const OUString& aNewName )
282 sal_Int32 nStorageMode =
m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE;
284 uno::Reference< embed::XStorage > xNewOwnStorage = xNewParentStorage->openStorageElement( aNewName, nStorageMode );
285 SAL_WARN_IF( !xNewOwnStorage.is(),
"embeddedobj.common",
"The method can not return empty reference!" );
297 uno::Reference < container::XChild > xChild( i_rxDocument, uno::UNO_QUERY );
301 catch(
const lang::NoSupportException & )
303 SAL_WARN(
"embeddedobj.common",
"OCommonEmbeddedObject::EmbedAndReparentDoc: cannot set parent at document!" );
313 uno::Reference< frame::XModel >
xModel( xDocument, uno::UNO_QUERY );
314 uno::Reference< frame::XLoadable > xLoadable(
xModel, uno::UNO_QUERY_THROW );
322 bool bInitNew =
true;
325 uno::Reference< document::XStorageBasedDocument > xDoc( xLoadable, uno::UNO_QUERY );
326 SAL_WARN_IF( !xDoc.is(),
"embeddedobj.common",
"OCommonEmbeddedObject::InitNewDocument_Impl: cannot recover from a storage when the document is not storage based!" );
341 xLoadable->initNew();
345 catch(
const uno::Exception& )
347 if ( xDocument.is() )
351 xDocument->close(
true );
353 catch(
const uno::Exception& )
370 uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY_THROW );
374 auto pArgs = aArgs.getArray();
376 pArgs[0].Name =
"URL";
382 pArgs[1].Name =
"FilterName";
387 pArgs[2].Name =
"Password";
405 xLoadable->load( aArgs );
410 uno::Reference< frame::XModel >
xModel( xLoadable, uno::UNO_QUERY_THROW );
411 const uno::Sequence< beans::PropertyValue > aProps =
xModel->getArgs();
412 for ( beans::PropertyValue
const & prop : aProps )
420 catch(
const uno::Exception& )
422 if ( xDocument.is() )
426 xDocument->close(
true );
428 catch(
const uno::Exception& )
444 if ( aFilterName.isEmpty() )
448 sDocumentServiceName ==
"com.sun.star.chart2.ChartDocument")
454 aFilterName =
aHelper.GetDefaultFilterFromServiceName(sDocumentServiceName,
nVersion);
459 }
catch(
const uno::Exception& )
475 SAL_WARN_IF( aFilterName.isEmpty(),
"embeddedobj.common",
"OCommonEmbeddedObject::FillDefaultLoadArgs_Impl: Wrong document service name!" );
476 if ( aFilterName.isEmpty() )
477 throw io::IOException();
479 o_rLoadArgs.
put(
"FilterName", aFilterName );
493 uno::Reference< chart2::XChartDocument > xChart( xDocument, uno::UNO_QUERY );
496 uno::Reference< embed::XVisualObject > xChartVisualObject( xChart, uno::UNO_QUERY );
497 if( xChartVisualObject.is() )
501 uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY );
502 uno::Reference< document::XStorageBasedDocument > xDoc( xDocument, uno::UNO_QUERY );
503 if ( !xDoc.is() && !xLoadable.is() )
504 throw uno::RuntimeException();
509 uno::Reference< io::XInputStream > xTempInpStream;
513 if ( !xTempInpStream.is() )
514 throw uno::RuntimeException();
516 OUString aTempFileURL;
521 uno::Reference< beans::XPropertySet > xTempStreamProps( xTempInpStream, uno::UNO_QUERY_THROW );
522 xTempStreamProps->getPropertyValue(
"Uri") >>= aTempFileURL;
524 catch(
const uno::Exception& )
528 SAL_WARN_IF( aTempFileURL.isEmpty(),
"embeddedobj.common",
"Couldn't retrieve temporary file URL!" );
530 aLoadArgs.
put(
"URL", aTempFileURL );
531 aLoadArgs.
put(
"InputStream", xTempInpStream );
544 aLoadArgs.
put(
"ReadOnly",
true);
556 catch(
const uno::Exception& )
558 if ( xDocument.is() )
562 xDocument->close(
true );
564 catch(
const uno::Exception& )
578 sal_Int32 nStorageFormat,
579 const OUString& aBaseURL,
580 const OUString& aHierarchName )
582 uno::Reference < io::XOutputStream > xTempOut(
584 uno::UNO_QUERY_THROW );
585 uno::Reference< io::XInputStream > aResult( xTempOut, uno::UNO_QUERY_THROW );
587 uno::Reference< frame::XStorable > xStorable;
591 xStorable.set(
m_xDocHolder->GetComponent(), uno::UNO_QUERY );
594 if( !xStorable.is() )
595 throw uno::RuntimeException(
"No storage is provided for storing!");
599 SAL_WARN_IF( aFilterName.isEmpty(),
"embeddedobj.common",
"Wrong document service name!" );
600 if ( aFilterName.isEmpty() )
601 throw io::IOException(
"No filter name provided / Wrong document service name");
603 uno::Sequence< beans::PropertyValue > aArgs{
610 xStorable->storeToURL(
"private:stream", aArgs );
613 xTempOut->closeOutput();
615 catch(
const uno::Exception& )
617 SAL_WARN(
"embeddedobj.common",
"Looks like stream was closed already" );
633 uno::Reference< util::XModifiable > xModifiable(
m_xDocHolder->GetComponent(), uno::UNO_QUERY );
634 if ( xModifiable.is() && !xModifiable->isModified() )
637 catch(
const uno::Exception& )
643 catch(
const uno::Exception& )
645 SAL_WARN(
"embeddedobj.common",
"The object was not stored!" );
658 uno::Reference< frame::XModel > xParentModel(
m_xClientSite->getComponent(), uno::UNO_QUERY_THROW );
659 const uno::Sequence< beans::PropertyValue > aModelProps = xParentModel->getArgs();
660 for ( beans::PropertyValue
const & prop : aModelProps )
661 if ( prop.Name ==
"DocumentBaseURL" )
663 prop.Value >>= aBaseURL;
667 catch(
const uno::Exception& )
671 if ( aBaseURL.isEmpty() )
674 if ( prop.Name ==
"DocumentBaseURL" )
676 prop.Value >>= aBaseURL;
681 if ( aBaseURL.isEmpty() )
689 const uno::Sequence< beans::PropertyValue >& lArguments,
690 const uno::Sequence< beans::PropertyValue >& lObjArgs )
694 for ( beans::PropertyValue
const & prop : lArguments )
695 if ( prop.Name ==
"DocumentBaseURL" )
697 prop.Value >>= aBaseURL;
701 if ( aBaseURL.isEmpty() )
703 for ( beans::PropertyValue
const & prop : lObjArgs )
704 if ( prop.Name ==
"DefaultParentBaseURL" )
706 prop.Value >>= aBaseURL;
717 xDoc->switchToStorage( xStorage );
719 uno::Reference< util::XModifiable > xModif( xDoc, uno::UNO_QUERY );
721 xModif->setModified(
false );
729OUString getStringPropertyValue(
const uno::Sequence<beans::PropertyValue>& rProps, std::u16string_view rName )
733 for (beans::PropertyValue
const & prop : rProps)
735 if (prop.Name == rName)
748 const uno::Reference<embed::XStorage>& xStorage,
749 const uno::Sequence<beans::PropertyValue>& rMediaArgs,
750 const uno::Sequence<beans::PropertyValue>& rObjArgs,
751 sal_Int32 nStorageFormat,
752 const OUString& aHierarchName,
753 bool bAttachToTheStorage )
755 SAL_WARN_IF( !xStorage.is(),
"embeddedobj.common",
"No storage is provided for storing!" );
757 if ( !xStorage.is() )
758 throw uno::RuntimeException();
760 uno::Reference< document::XStorageBasedDocument > xDoc;
764 xDoc.set(
m_xDocHolder->GetComponent(), uno::UNO_QUERY );
777 SAL_WARN_IF( aFilterName.isEmpty(),
"embeddedobj.common",
"Wrong document service name!" );
778 if ( aFilterName.isEmpty() )
779 throw io::IOException();
781 static constexpr OUStringLiteral sFilterName =
u"FilterName";
784 static constexpr OUStringLiteral sSourceShellID =
u"SourceShellID";
785 static constexpr OUStringLiteral sDestinationShellID =
u"DestinationShellID";
786 uno::Sequence<beans::PropertyValue> aArgs{
791 getStringPropertyValue(rObjArgs, sSourceShellID)),
793 sDestinationShellID, getStringPropertyValue(rObjArgs, sDestinationShellID))
796 xDoc->storeToStorage( xStorage, aArgs );
797 if ( bAttachToTheStorage )
805 SAL_WARN_IF( !xTempIn.is(),
"embeddedobj.common",
"The stream reference can not be empty!" );
808 uno::Reference < lang::XSingleServiceFactory > xStorageFactory = embed::StorageFactory::create(
m_xContext);
810 uno::Sequence< uno::Any > aArgs{
uno::Any(xTempIn) };
811 uno::Reference< embed::XStorage > xTempStorage( xStorageFactory->createInstanceWithArguments( aArgs ),
812 uno::UNO_QUERY_THROW );
815 xTempStorage->copyToStorage( xStorage );
821 const uno::Sequence< beans::PropertyValue >& aMedDescr )
826 uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY_THROW );
835 catch(
const uno::Exception& )
837 if ( xDocument.is() )
841 xDocument->close(
true );
843 catch(
const uno::Exception& )
857 uno::Reference< util::XCloseable > xResult;
861 uno::Sequence< beans::PropertyValue > aTempMediaDescr;
867 catch (
const beans::IllegalTypeException& )
871 catch (
const uno::Exception& )
873 SAL_WARN(
"embeddedobj.common",
"Can not retrieve storage media type!" );
878 aTempMediaDescr.realloc( 4 );
881 OUString aTempFileURL;
889 uno::Reference< beans::XPropertySet > xTempStreamProps( xTempStream, uno::UNO_QUERY_THROW );
890 xTempStreamProps->getPropertyValue(
"Uri") >>= aTempFileURL;
892 catch(
const uno::Exception& )
896 SAL_WARN_IF( aTempFileURL.isEmpty(),
"embeddedobj.common",
"Couldn't retrieve temporary file URL!" );
920 const uno::Reference< embed::XStorage >& xStorage,
921 const OUString& sEntName,
922 sal_Int32 nEntryConnectionMode,
923 const uno::Sequence< beans::PropertyValue >& lArguments,
924 const uno::Sequence< beans::PropertyValue >& lObjArgs )
929 ::osl::MutexGuard aGuard(
m_aMutex );
931 throw lang::DisposedException();
933 if ( !xStorage.is() )
934 throw lang::IllegalArgumentException(
"No parent storage is provided!",
938 if ( sEntName.isEmpty() )
939 throw lang::IllegalArgumentException(
"Empty element name is provided!",
944 if ( (
m_nObjectState != -1 || nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
945 && (
m_nObjectState == -1 || nEntryConnectionMode != embed::EntryInitModes::NO_INIT ) )
953 throw embed::WrongStateException(
954 "Can't change persistent representation of activated object!",
960 if ( nEntryConnectionMode != embed::EntryInitModes::NO_INIT )
961 throw embed::WrongStateException(
962 "The object waits for saveCompleted() call!",
975 if ( !bSwitchFurther )
988 uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY_THROW );
991 bool bElExists = xNameAccess->hasByName( sEntName );
994 nEntryConnectionMode != embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT );
997 for ( beans::PropertyValue
const & prop : lArguments )
998 if ( prop.Name ==
"ReadOnly" )
1002 for ( beans::PropertyValue
const & prop : lObjArgs )
1003 if ( prop.Name ==
"OutplaceDispatchInterceptor" )
1005 uno::Reference< frame::XDispatchProviderInterceptor > xDispatchInterceptor;
1006 if ( prop.Value >>= xDispatchInterceptor )
1007 m_xDocHolder->SetOutplaceDispatchInterceptor( xDispatchInterceptor );
1009 else if ( prop.Name ==
"DefaultParentBaseURL" )
1013 else if ( prop.Name ==
"Parent" )
1017 else if ( prop.Name ==
"IndividualMiscStatus" )
1019 sal_Int64 nMiscStatus=0;
1020 prop.Value >>= nMiscStatus;
1023 else if ( prop.Name ==
"CloneFrom" )
1025 uno::Reference < embed::XEmbeddedObject > xObj;
1026 prop.Value >>= xObj;
1030 m_aClonedSize = xObj->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT );
1034 else if ( prop.Name ==
"OutplaceFrameProperties" )
1036 uno::Sequence< uno::Any > aOutFrameProps;
1037 uno::Sequence< beans::NamedValue > aOutFramePropsTyped;
1038 if ( prop.Value >>= aOutFrameProps )
1040 m_xDocHolder->SetOutplaceFrameProperties( aOutFrameProps );
1042 else if ( prop.Value >>= aOutFramePropsTyped )
1044 aOutFrameProps.realloc( aOutFramePropsTyped.getLength() );
1045 uno::Any* pProp = aOutFrameProps.getArray();
1046 for (
const beans::NamedValue* pTypedProp = aOutFramePropsTyped.getConstArray();
1047 pTypedProp != aOutFramePropsTyped.getConstArray() + aOutFramePropsTyped.getLength();
1048 ++pTypedProp, ++pProp
1051 *pProp <<= *pTypedProp;
1053 m_xDocHolder->SetOutplaceFrameProperties( aOutFrameProps );
1056 SAL_WARN(
"embeddedobj.common",
"OCommonEmbeddedObject::setPersistentEntry: illegal type for argument 'OutplaceFrameProperties'!" );
1058 else if ( prop.Name ==
"ModuleName" )
1062 else if ( prop.Name ==
"EmbeddedScriptSupport" )
1066 else if ( prop.Name ==
"DocumentRecoverySupport" )
1070 else if ( prop.Name ==
"RecoveryStorage" )
1076 sal_Int32 nStorageMode =
m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE;
1080 if ( nEntryConnectionMode == embed::EntryInitModes::DEFAULT_INIT )
1091 throw io::IOException();
1098 if ( ( nStorageMode & embed::ElementModes::READWRITE ) != embed::ElementModes::READWRITE )
1099 throw io::IOException();
1101 if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
1107 else if ( nEntryConnectionMode == embed::EntryInitModes::TRUNCATE_INIT )
1116 throw io::IOException();
1120 else if ( nEntryConnectionMode == embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT )
1130 throw lang::IllegalArgumentException(
"Wrong connection mode is provided!",
1138 const OUString& sEntName,
1139 const uno::Sequence< beans::PropertyValue >& lArguments,
1140 const uno::Sequence< beans::PropertyValue >& lObjArgs )
1142 ::osl::ResettableMutexGuard aGuard(
m_aMutex );
1144 throw lang::DisposedException();
1149 throw embed::WrongStateException(
"Can't store object without persistence!",
1154 throw embed::WrongStateException(
1155 "The object waits for saveCompleted() call!",
1171 catch (
const beans::IllegalTypeException& )
1175 catch (
const uno::Exception& )
1177 SAL_WARN(
"embeddedobj.common",
"Can not retrieve target storage media type!" );
1181 SAL_INFO(
"embeddedobj.common",
"fdo#78159: Storing OOoXML as ODF");
1190 catch (
const beans::IllegalTypeException& )
1194 catch (
const uno::Exception& )
1196 SAL_WARN(
"embeddedobj.common",
"Can not retrieve own storage media type!" );
1199 bool bTryOptimization =
false;
1200 for ( beans::PropertyValue
const & prop : lObjArgs )
1203 if ( prop.Name ==
"CanTryOptimization" )
1204 prop.Value >>= bTryOptimization;
1207 bool bSwitchBackToLoaded =
false;
1213 if ( nTargetStorageFormat == nOriginalStorageFormat )
1215 bool bOptimizationWorks =
false;
1216 if ( bTryOptimization )
1221 uno::Reference< embed::XOptimizedStorage > xSource(
m_xParentStorage, uno::UNO_QUERY_THROW );
1222 uno::Reference< embed::XOptimizedStorage >
xTarget( xStorage, uno::UNO_QUERY_THROW );
1224 bOptimizationWorks =
true;
1226 catch(
const uno::Exception& )
1231 if ( !bOptimizationWorks )
1237 bSwitchBackToLoaded =
true;
1244 uno::Reference< embed::XStorage > xSubStorage =
1245 xStorage->openStorageElement( sEntName, embed::ElementModes::READWRITE );
1247 if ( !xSubStorage.is() )
1248 throw uno::RuntimeException();
1253 xSubStorage, lArguments, lObjArgs, nTargetStorageFormat, sEntName,
false );
1256 if ( bSwitchBackToLoaded )
1264 const OUString& sEntName,
1265 const uno::Sequence< beans::PropertyValue >& lArguments,
1266 const uno::Sequence< beans::PropertyValue >& lObjArgs )
1268 ::osl::ResettableMutexGuard aGuard(
m_aMutex );
1270 throw lang::DisposedException();
1272 bool AutoSaveEvent =
false;
1279 throw embed::WrongStateException(
"Can't store object without persistence!",
1284 throw embed::WrongStateException(
1285 "The object waits for saveCompleted() call!",
1295 if ( !AutoSaveEvent )
1308 catch (
const beans::IllegalTypeException& )
1312 catch (
const uno::Exception& )
1314 SAL_WARN(
"embeddedobj.common",
"Can not retrieve target storage media type!" );
1318 SAL_INFO(
"embeddedobj.common",
"fdo#78159: Storing OOoXML as ODF");
1327 catch (
const beans::IllegalTypeException& )
1331 catch (
const uno::Exception& )
1333 SAL_WARN(
"embeddedobj.common",
"Can not retrieve own storage media type!" );
1338 bool bTryOptimization =
false;
1339 for ( beans::PropertyValue
const & prop : lObjArgs )
1342 if ( prop.Name ==
"CanTryOptimization" )
1343 prop.Value >>= bTryOptimization;
1346 bool bSwitchBackToLoaded =
false;
1352 if ( nTargetStorageFormat == nOriginalStorageFormat )
1354 bool bOptimizationWorks =
false;
1355 if ( bTryOptimization )
1360 uno::Reference< embed::XOptimizedStorage > xSource(
m_xParentStorage, uno::UNO_QUERY_THROW );
1361 uno::Reference< embed::XOptimizedStorage >
xTarget( xStorage, uno::UNO_QUERY_THROW );
1363 bOptimizationWorks =
true;
1365 catch(
const uno::Exception& )
1370 if ( !bOptimizationWorks )
1376 bSwitchBackToLoaded =
true;
1380 uno::Reference< embed::XStorage > xSubStorage =
1381 xStorage->openStorageElement( sEntName, embed::ElementModes::READWRITE );
1383 if ( !xSubStorage.is() )
1384 throw uno::RuntimeException();
1391 xSubStorage, lArguments, lObjArgs, nTargetStorageFormat, sEntName,
false );
1394 if ( bSwitchBackToLoaded )
1413 ::osl::MutexGuard aGuard(
m_aMutex );
1415 throw lang::DisposedException();
1420 throw embed::WrongStateException(
"Can't store object without persistence!",
1441 throw io::IOException();
1445 throw uno::RuntimeException();
1452 uno::Reference< util::XModifiable > xModif(
m_xDocHolder->GetComponent(), uno::UNO_QUERY );
1454 xModif->setModified(
false );
1463 catch (
const uno::Exception& )
1478 if (
m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE )
1488 ::osl::MutexGuard aGuard(
m_aMutex );
1490 throw lang::DisposedException();
1493 throw embed::WrongStateException(
1494 "The object waits for saveCompleted() call!",
1506 ::osl::MutexGuard aGuard(
m_aMutex );
1508 throw lang::DisposedException();
1513 throw embed::WrongStateException(
"The object persistence is not initialized!",
1518 throw embed::WrongStateException(
1519 "The object waits for saveCompleted() call!",
1532 ::osl::ResettableMutexGuard aGuard(
m_aMutex );
1534 throw lang::DisposedException();
1539 throw embed::WrongStateException(
"Can't store object without persistence!",
1544 throw embed::WrongStateException(
1545 "The object waits for saveCompleted() call!",
1549 throw io::IOException();
1557 SAL_WARN_IF( !
m_xDocHolder->GetComponent().is(),
"embeddedobj.common",
"If an object is activated or in running state it must have a document!" );
1559 throw uno::RuntimeException();
1564 uno::Reference< frame::XStorable > xStorable(
m_xDocHolder->GetComponent(), uno::UNO_QUERY_THROW );
1578 throw io::IOException();
1584 catch (
const beans::IllegalTypeException& )
1588 catch (
const uno::Exception& )
1590 SAL_WARN(
"embeddedobj.common",
"Can not retrieve storage media type!" );
1594 SAL_INFO(
"embeddedobj.common",
"fdo#78159: Storing OOoXML as ODF");
1600 uno::Sequence<beans::PropertyValue> aEmpty;
1607 uno::Reference< util::XModifiable > xModif(
m_xDocHolder->GetComponent(), uno::UNO_QUERY );
1609 xModif->setModified(
false );
1617 ::osl::MutexGuard aGuard(
m_aMutex );
1619 throw lang::DisposedException();
1624 throw embed::WrongStateException(
"The object persistence is not initialized!",
1629 throw embed::WrongStateException(
1630 "The object waits for saveCompleted() call!",
1638 const uno::Sequence< beans::PropertyValue >& lArguments,
1639 const uno::Sequence< beans::PropertyValue >& lObjArgs )
1644 ::osl::MutexGuard aGuard(
m_aMutex );
1646 throw lang::DisposedException();
1651 throw embed::WrongStateException(
"The object persistence is not initialized!",
1658 throw embed::WrongStateException(
1659 "The object must be in loaded state to be reloaded!",
1664 throw embed::WrongStateException(
1665 "The object waits for saveCompleted() call!",
1673 OUString aNewLinkFilter;
1674 for ( beans::PropertyValue
const & prop : lArguments )
1676 if ( prop.Name ==
"URL" )
1682 else if ( prop.Name ==
"FilterName" )
1684 prop.Value >>= aNewLinkFilter;
1692 if ( !aNewLinkFilter.isEmpty() )
1716 for ( beans::PropertyValue
const & prop : lObjArgs )
1717 if ( prop.Name ==
"OutplaceDispatchInterceptor" )
1719 uno::Reference< frame::XDispatchProviderInterceptor > xDispatchInterceptor;
1720 if ( prop.Value >>= xDispatchInterceptor )
1721 m_xDocHolder->SetOutplaceDispatchInterceptor( xDispatchInterceptor );
1732 for ( beans::PropertyValue
const & prop : lArguments )
1733 if ( prop.Name ==
"ReadOnly" )
1744 catch (
const uno::Exception& )
1748 sal_Int32 nStorageMode =
m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE;
1762 const OUString& sEntName )
1764 ::osl::ResettableMutexGuard aGuard(
m_aMutex );
1766 throw lang::DisposedException();
1771 throw embed::WrongStateException(
1772 "The object is not a valid linked object!",
1778 if ( !xStorage.is() )
1779 throw lang::IllegalArgumentException(
"No parent storage is provided!",
1783 if ( sEntName.isEmpty() )
1784 throw lang::IllegalArgumentException(
"Empty element name is provided!",
1789 throw embed::WrongStateException(
1790 "The object waits for saveCompleted() call!",
1793 uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY_THROW );
1815 uno::Reference< util::XModifiable > xModif(
m_xDocHolder->GetComponent(), uno::UNO_QUERY_THROW );
1819 xModif->setModified(
true );
1822 catch(
const uno::Exception& )
1826 SAL_WARN_IF( !
m_xDocHolder->GetComponent().is(),
"embeddedobj.common",
"If document can't be created, an exception must be thrown!" );
1848 ::osl::MutexGuard aGuard(
m_aMutex );
1850 throw lang::DisposedException();
1858 ::osl::MutexGuard aGuard(
m_aMutex );
1860 throw lang::DisposedException();
1863 throw embed::WrongStateException(
1864 "The object is not a link object!",
constexpr OUStringLiteral sDocumentBaseURL
constexpr OUStringLiteral sHierarchicalDocumentName
css::uno::Sequence< css::beans::PropertyValue > m_aDocMediaDescriptor
virtual sal_Bool SAL_CALL isReadonly() override
css::awt::Size m_aDefaultSizeForChart_In_100TH_MM
css::uno::Reference< css::uno::XComponentContext > m_xContext
css::uno::Sequence< css::beans::PropertyValue > m_aNewDocMediaDescriptor
OUString m_aLinkFilterName
const OUString & GetDocumentServiceName() const
css::uno::Reference< css::uno::XInterface > m_xParent
virtual void SAL_CALL reload(const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
virtual sal_Bool SAL_CALL hasEntry() override
static OUString GetBaseURLFrom_Impl(const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs)
void PostEvent_Impl(const OUString &aEventName)
void StateChangeNotification_Impl(bool bBeforeChange, sal_Int32 nOldState, sal_Int32 nNewState,::osl::ResettableMutexGuard &_rGuard)
bool m_bDocumentRecoverySupport
virtual sal_Bool SAL_CALL isLink() override
css::uno::Reference< css::embed::XStorage > m_xRecoveryStorage
css::uno::Reference< css::util::XCloseable > InitNewDocument_Impl()
virtual void SAL_CALL changeState(sal_Int32 nNewState) override
OUString GetBaseURL_Impl() const
virtual void SAL_CALL setPersistentEntry(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, sal_Int32 nEntryConnectionMode, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
void StoreDocToStorage_Impl(const css::uno::Reference< css::embed::XStorage > &xStorage, const css::uno::Sequence< css::beans::PropertyValue > &rMediaArgs, const css::uno::Sequence< css::beans::PropertyValue > &rObjArgs, sal_Int32 nStorageVersion, const OUString &aHierarchName, bool bAttachToStorage)
virtual void SAL_CALL breakLink(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName) override
bool m_bEmbeddedScriptSupport
css::uno::Reference< css::util::XCloseable > CreateTempDocFromLink_Impl()
virtual OUString SAL_CALL getEntryName() override
virtual void SAL_CALL saveCompleted(sal_Bool bUseNew) override
OUString m_aDefaultParentBaseURL
void LinkInit_Impl(const css::uno::Sequence< css::beans::NamedValue > &aObjectProps, const css::uno::Sequence< css::beans::PropertyValue > &aMediaDescr, const css::uno::Sequence< css::beans::PropertyValue > &aObjectDescr)
css::uno::Reference< css::io::XTempFile > m_aLinkTempFile
virtual void SAL_CALL storeAsEntry(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
css::uno::Reference< css::util::XCloseable > LoadLink_Impl()
sal_Int32 m_nClonedMapUnit
css::uno::Reference< css::embed::XStorage > m_xNewObjectStorage
virtual void SAL_CALL storeToEntry(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
void EmbedAndReparentDoc_Impl(const css::uno::Reference< css::util::XCloseable > &i_rxDocument) const
const OUString & GetPresetFilterName() const
css::awt::Size m_aClonedSize
rtl::Reference< DocumentHolder > m_xDocHolder
css::uno::Reference< css::util::XCloseable > CreateDocFromMediaDescr_Impl(const css::uno::Sequence< css::beans::PropertyValue > &aMedDescr)
void SwitchOwnPersistence(const css::uno::Reference< css::embed::XStorage > &xNewParentStorage, const css::uno::Reference< css::embed::XStorage > &xNewObjectStorage, const OUString &aNewName)
virtual sal_Bool SAL_CALL isStored() override
void handleLinkedOLE(CopyBackToOLELink eState)
OUString GetFilterName(sal_Int32 nVersion) const
css::uno::Reference< css::embed::XStorage > m_xNewParentStorage
void SwitchDocToStorage_Impl(const css::uno::Reference< css::document::XStorageBasedDocument > &xDoc, const css::uno::Reference< css::embed::XStorage > &xStorage)
css::uno::Reference< css::embed::XEmbeddedClient > m_xClientSite
virtual void SAL_CALL storeOwn() override
bool m_bWaitSaveCompleted
css::uno::Reference< css::embed::XStorage > m_xParentStorage
css::uno::Reference< css::io::XInputStream > StoreDocumentToTempStream_Impl(sal_Int32 nStorageFormat, const OUString &aBaseURL, const OUString &aHierarchName)
css::uno::Reference< css::util::XCloseable > LoadDocumentFromStorage_Impl()
css::uno::Reference< css::embed::XStorage > m_xObjectStorage
void FillDefaultLoadArgs_Impl(const css::uno::Reference< css::embed::XStorage > &i_rxStorage, ::comphelper::NamedValueCollection &o_rLoadArgs) const
virtual OUString SAL_CALL getLinkURL() override
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
NamedValueCollection & merge(const NamedValueCollection &_rAdditionalValues, bool _bOverwriteExisting)
css::uno::Sequence< css::beans::PropertyValue > getPropertyValues() const
static sal_Int32 GetXStorageFormat(const css::uno::Reference< css::embed::XStorage > &xStorage)
#define ENSURE_OR_THROW(c, m)
#define DBG_UNHANDLED_EXCEPTION(...)
Reference< XInterface > xTarget
Sequence< PropertyValue > aArguments
Sequence< sal_Int8 > aSeq
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
Any SAL_CALL getCaughtException()
static uno::Sequence< beans::PropertyValue > addAsTemplate(const uno::Sequence< beans::PropertyValue > &aOrig)
static uno::Reference< io::XInputStream > createTempInpStreamFromStor(const uno::Reference< embed::XStorage > &xStorage, const uno::Reference< uno::XComponentContext > &xContext)
uno::Sequence< beans::PropertyValue > GetValuableArgs_Impl(const uno::Sequence< beans::PropertyValue > &aMedDescr, bool bCanUseDocumentBaseURL)
static uno::Reference< util::XCloseable > CreateDocument(const uno::Reference< uno::XComponentContext > &_rxContext, const OUString &_rDocumentServiceName, bool _bEmbeddedScriptSupport, const bool i_bDocumentRecoverySupport)
static void TransferMediaType(const uno::Reference< embed::XStorage > &i_rSource, const uno::Reference< embed::XStorage > &i_rTarget)
static void SetDocToEmbedded(const uno::Reference< frame::XModel > &rDocument, const OUString &aModuleName)
Reference< XModel > xModel