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