xref: /aoo41x/main/sfx2/source/doc/objstor.cxx (revision d321cf2f)
1d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5d119d52dSAndrew Rist  * distributed with this work for additional information
6d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10d119d52dSAndrew Rist  *
11d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12d119d52dSAndrew Rist  *
13d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17d119d52dSAndrew Rist  * specific language governing permissions and limitations
18d119d52dSAndrew Rist  * under the License.
19d119d52dSAndrew Rist  *
20d119d52dSAndrew Rist  *************************************************************/
21d119d52dSAndrew Rist 
22d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _MSGBOX_HXX //autogen
28cdf0e10cSrcweir #include <vcl/msgbox.hxx>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <svl/eitem.hxx>
31cdf0e10cSrcweir #include <svl/stritem.hxx>
32cdf0e10cSrcweir #include <svl/intitem.hxx>
33cdf0e10cSrcweir #include <tools/zcodec.hxx>
34cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
35cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
36cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
37cdf0e10cSrcweir #include <com/sun/star/document/XFilter.hpp>
38cdf0e10cSrcweir #include <com/sun/star/document/XImporter.hpp>
39cdf0e10cSrcweir #include <com/sun/star/document/XExporter.hpp>
40cdf0e10cSrcweir #include <com/sun/star/document/FilterOptionsRequest.hpp>
41cdf0e10cSrcweir #include <com/sun/star/document/XInteractionFilterOptions.hpp>
42cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
43cdf0e10cSrcweir #include <com/sun/star/task/XInteractionAskLater.hpp>
44cdf0e10cSrcweir #include <com/sun/star/task/FutureDocumentVersionProductUpdateRequest.hpp>
45cdf0e10cSrcweir #include <com/sun/star/task/InteractionClassification.hpp>
46cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
47cdf0e10cSrcweir #include <com/sun/star/document/MacroExecMode.hpp>
48cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
49cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
50cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
51cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySetInfo.hpp>
52cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
53cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyAccess.hpp>
54cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
55cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
56cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
57cdf0e10cSrcweir #include <com/sun/star/container/XSet.hpp>
58cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
59cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp>
60cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp>
61cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp>
62cdf0e10cSrcweir #include <com/sun/star/embed/XEmbedPersist.hpp>
63cdf0e10cSrcweir #include <com/sun/star/embed/XLinkageSupport.hpp>
64cdf0e10cSrcweir #include <com/sun/star/embed/EntryInitModes.hpp>
65cdf0e10cSrcweir #include <com/sun/star/embed/XOptimizedStorage.hpp>
66cdf0e10cSrcweir #include <com/sun/star/embed/XEncryptionProtectedStorage.hpp>
67cdf0e10cSrcweir #include <com/sun/star/io/XTruncate.hpp>
68cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
69cdf0e10cSrcweir #include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
70cdf0e10cSrcweir #include <com/sun/star/xml/crypto/CipherID.hpp>
71cdf0e10cSrcweir #include <com/sun/star/xml/crypto/DigestID.hpp>
72cdf0e10cSrcweir 
73cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp>
74cdf0e10cSrcweir #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
75cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
76cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx>
77cdf0e10cSrcweir #include <comphelper/interaction.hxx>
78cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
79cdf0e10cSrcweir #include <unotools/securityoptions.hxx>
80cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
81cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
82cdf0e10cSrcweir #include <tools/cachestr.hxx>
83cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
84cdf0e10cSrcweir 
85cdf0e10cSrcweir #include <unotools/saveopt.hxx>
86cdf0e10cSrcweir #include <unotools/useroptions.hxx>
87cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
88cdf0e10cSrcweir #include <tools/urlobj.hxx>
89cdf0e10cSrcweir #include <tools/diagnose_ex.h>
90cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
91cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
92cdf0e10cSrcweir #include <unotools/tempfile.hxx>
93cdf0e10cSrcweir #include <unotools/docinfohelper.hxx>
94cdf0e10cSrcweir #include <ucbhelper/content.hxx>
95cdf0e10cSrcweir #include <sot/storinfo.hxx>
96cdf0e10cSrcweir #include <sot/exchange.hxx>
97cdf0e10cSrcweir #include <sot/formats.hxx>
98cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
99cdf0e10cSrcweir #include <comphelper/seqstream.hxx>
100cdf0e10cSrcweir #include <comphelper/documentconstants.hxx>
101cdf0e10cSrcweir #include <comphelper/string.hxx>
102cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
103cdf0e10cSrcweir #include <svtools/embedhlp.hxx>
104cdf0e10cSrcweir #include <rtl/logfile.hxx>
105cdf0e10cSrcweir #include <basic/modsizeexceeded.hxx>
106cdf0e10cSrcweir #include <osl/file.hxx>
107cdf0e10cSrcweir 
108cdf0e10cSrcweir #include <sfx2/signaturestate.hxx>
109cdf0e10cSrcweir #include <sfx2/app.hxx>
110cdf0e10cSrcweir #include <sfx2/objsh.hxx>
111cdf0e10cSrcweir #include <sfx2/childwin.hxx>
112cdf0e10cSrcweir #include <sfx2/request.hxx>
113cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
114cdf0e10cSrcweir #include <sfx2/docfile.hxx>
115cdf0e10cSrcweir #include "fltfnc.hxx"
116cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
117cdf0e10cSrcweir #include <sfx2/docfac.hxx>
118cdf0e10cSrcweir #include "objshimp.hxx"
119cdf0e10cSrcweir #include "sfxtypes.hxx"
120cdf0e10cSrcweir #include "doc.hrc"
121cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
122cdf0e10cSrcweir #include <sfx2/module.hxx>
123cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
124cdf0e10cSrcweir #include "openflag.hxx"
125cdf0e10cSrcweir #include "helper.hxx"
126cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
127cdf0e10cSrcweir #include <sfx2/event.hxx>
128cdf0e10cSrcweir #include "fltoptint.hxx"
129cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
130cdf0e10cSrcweir #include "graphhelp.hxx"
131cdf0e10cSrcweir #include "appbaslib.hxx"
132cdf0e10cSrcweir #include "appdata.hxx"
133cdf0e10cSrcweir 
134cdf0e10cSrcweir #ifdef OS2
13567a1b670SPedro Giffuni #include <svpm.h>
136cdf0e10cSrcweir #include <osl/file.hxx>
137cdf0e10cSrcweir #include <stdio.h>
138cdf0e10cSrcweir #include <sys/ea.h>
139cdf0e10cSrcweir #endif
140cdf0e10cSrcweir 
141cdf0e10cSrcweir #include "../appl/app.hrc"
142cdf0e10cSrcweir 
143cdf0e10cSrcweir extern sal_uInt32 CheckPasswd_Impl( SfxObjectShell*, SfxItemPool&, SfxMedium* );
144cdf0e10cSrcweir 
145cdf0e10cSrcweir using namespace ::com::sun::star;
146cdf0e10cSrcweir using namespace ::com::sun::star::container;
147cdf0e10cSrcweir using namespace ::com::sun::star::lang;
148cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
149cdf0e10cSrcweir using namespace ::com::sun::star::uno;
150cdf0e10cSrcweir using namespace ::com::sun::star::beans;
151cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
152cdf0e10cSrcweir using namespace ::com::sun::star::task;
153cdf0e10cSrcweir using namespace ::com::sun::star::document;
154cdf0e10cSrcweir using namespace ::rtl;
155cdf0e10cSrcweir using namespace ::cppu;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir namespace css = ::com::sun::star;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir //=========================================================================
impl_addToModelCollection(const css::uno::Reference<css::frame::XModel> & xModel)160cdf0e10cSrcweir void impl_addToModelCollection(const css::uno::Reference< css::frame::XModel >& xModel)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     if (!xModel.is())
163cdf0e10cSrcweir         return;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
166cdf0e10cSrcweir     css::uno::Reference< css::container::XSet > xModelCollection(
167cdf0e10cSrcweir         xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.GlobalEventBroadcaster")),
168cdf0e10cSrcweir         css::uno::UNO_QUERY);
169cdf0e10cSrcweir     if (xModelCollection.is())
170cdf0e10cSrcweir     {
171cdf0e10cSrcweir         try
172cdf0e10cSrcweir         {
173cdf0e10cSrcweir             xModelCollection->insert(css::uno::makeAny(xModel));
174cdf0e10cSrcweir         }
175cdf0e10cSrcweir         catch ( uno::Exception& )
176cdf0e10cSrcweir         {
177cdf0e10cSrcweir             OSL_ENSURE( sal_False, "The document seems to be in the collection already!\n" );
178cdf0e10cSrcweir         }
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir //=========================================================================
183cdf0e10cSrcweir 
Save()184cdf0e10cSrcweir sal_Bool SfxObjectShell::Save()
185cdf0e10cSrcweir {
186cdf0e10cSrcweir     return SaveChildren();
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir //--------------------------------------------------------------------------
190cdf0e10cSrcweir 
SaveAs(SfxMedium & rMedium)191cdf0e10cSrcweir sal_Bool SfxObjectShell::SaveAs( SfxMedium& rMedium )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir     return SaveAsChildren( rMedium );
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir //-------------------------------------------------------------------------
197cdf0e10cSrcweir 
QuerySlotExecutable(sal_uInt16)198cdf0e10cSrcweir sal_Bool SfxObjectShell::QuerySlotExecutable( sal_uInt16 /*nSlotId*/ )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir     return sal_True;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir //-------------------------------------------------------------------------
204cdf0e10cSrcweir 
GetEncryptionData_Impl(const SfxItemSet * pSet,uno::Sequence<beans::NamedValue> & o_rEncryptionData)205cdf0e10cSrcweir bool GetEncryptionData_Impl( const SfxItemSet* pSet, uno::Sequence< beans::NamedValue >& o_rEncryptionData )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir     bool bResult = false;
208cdf0e10cSrcweir     if ( pSet )
209cdf0e10cSrcweir     {
210cdf0e10cSrcweir         SFX_ITEMSET_ARG( pSet, pEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, sal_False);
211cdf0e10cSrcweir         if ( pEncryptionDataItem )
212cdf0e10cSrcweir         {
213cdf0e10cSrcweir             pEncryptionDataItem->GetValue() >>= o_rEncryptionData;
214cdf0e10cSrcweir             bResult = true;
215cdf0e10cSrcweir         }
216cdf0e10cSrcweir         else
217cdf0e10cSrcweir         {
218cdf0e10cSrcweir             SFX_ITEMSET_ARG( pSet, pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False);
219cdf0e10cSrcweir             if ( pPasswordItem )
220cdf0e10cSrcweir             {
221cdf0e10cSrcweir                 ::rtl::OUString aPassword = pPasswordItem->GetValue();
222cdf0e10cSrcweir                 o_rEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPassword );
223cdf0e10cSrcweir                 bResult = true;
224cdf0e10cSrcweir             }
225cdf0e10cSrcweir         }
226cdf0e10cSrcweir     }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir     return bResult;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir //-------------------------------------------------------------------------
PutURLContentsToVersionStream_Impl(::rtl::OUString aURL,const uno::Reference<embed::XStorage> & xDocStorage,::rtl::OUString aStreamName)232cdf0e10cSrcweir sal_Bool SfxObjectShell::PutURLContentsToVersionStream_Impl(
233cdf0e10cSrcweir                                             ::rtl::OUString aURL,
234cdf0e10cSrcweir                                             const uno::Reference< embed::XStorage >& xDocStorage,
235cdf0e10cSrcweir                                             ::rtl::OUString aStreamName )
236cdf0e10cSrcweir {
237cdf0e10cSrcweir     sal_Bool bResult = sal_False;
238cdf0e10cSrcweir     try
239cdf0e10cSrcweir     {
240cdf0e10cSrcweir         uno::Reference< embed::XStorage > xVersion = xDocStorage->openStorageElement(
241cdf0e10cSrcweir                                                         ::rtl::OUString::createFromAscii( "Versions" ),
242cdf0e10cSrcweir                                                         embed::ElementModes::READWRITE );
243cdf0e10cSrcweir 
244cdf0e10cSrcweir         DBG_ASSERT( xVersion.is(),
245cdf0e10cSrcweir                 "The method must throw an exception if the storage can not be opened!\n" );
246cdf0e10cSrcweir         if ( !xVersion.is() )
247cdf0e10cSrcweir             throw uno::RuntimeException();
248cdf0e10cSrcweir 
249cdf0e10cSrcweir         uno::Reference< io::XStream > xVerStream = xVersion->openStreamElement(
250cdf0e10cSrcweir                                                                 aStreamName,
251cdf0e10cSrcweir                                                                 embed::ElementModes::READWRITE );
252cdf0e10cSrcweir         DBG_ASSERT( xVerStream.is(), "The method must throw an exception if the storage can not be opened!\n" );
253cdf0e10cSrcweir         if ( !xVerStream.is() )
254cdf0e10cSrcweir             throw uno::RuntimeException();
255cdf0e10cSrcweir 
256cdf0e10cSrcweir         uno::Reference< io::XOutputStream > xOutStream = xVerStream->getOutputStream();
257cdf0e10cSrcweir         uno::Reference< io::XTruncate > xTrunc( xOutStream, uno::UNO_QUERY );
258cdf0e10cSrcweir 
259cdf0e10cSrcweir         DBG_ASSERT( xTrunc.is(), "The output stream must exist and implement XTruncate interface!\n" );
260cdf0e10cSrcweir         if ( !xTrunc.is() )
261cdf0e10cSrcweir             throw RuntimeException();
262cdf0e10cSrcweir 
263cdf0e10cSrcweir         uno::Reference< io::XInputStream > xTmpInStream =
264cdf0e10cSrcweir             ::comphelper::OStorageHelper::GetInputStreamFromURL( aURL );
265cdf0e10cSrcweir         DBG_ASSERT( xTmpInStream.is(), "The method must create the stream or throw an exception!\n" );
266cdf0e10cSrcweir         if ( !xTmpInStream.is() )
267cdf0e10cSrcweir             throw uno::RuntimeException();
268cdf0e10cSrcweir 
269cdf0e10cSrcweir         xTrunc->truncate();
270cdf0e10cSrcweir         ::comphelper::OStorageHelper::CopyInputToOutput( xTmpInStream, xOutStream );
271cdf0e10cSrcweir         xOutStream->closeOutput();
272cdf0e10cSrcweir 
273cdf0e10cSrcweir         uno::Reference< embed::XTransactedObject > xTransact( xVersion, uno::UNO_QUERY );
274cdf0e10cSrcweir         DBG_ASSERT( xTransact.is(), "The storage must implement XTransacted interface!\n" );
275cdf0e10cSrcweir         if ( xTransact.is() )
276cdf0e10cSrcweir             xTransact->commit();
277cdf0e10cSrcweir 
278cdf0e10cSrcweir         bResult = sal_True;
279cdf0e10cSrcweir     }
280cdf0e10cSrcweir     catch( uno::Exception& )
281cdf0e10cSrcweir     {
282cdf0e10cSrcweir         // TODO/LATER: handle the error depending on exception
283cdf0e10cSrcweir         SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
284cdf0e10cSrcweir     }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir     return bResult;
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir //-------------------------------------------------------------------------
CreateTempCopyOfStorage_Impl(const uno::Reference<embed::XStorage> & xStorage)290cdf0e10cSrcweir ::rtl::OUString SfxObjectShell::CreateTempCopyOfStorage_Impl( const uno::Reference< embed::XStorage >& xStorage )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir     ::rtl::OUString aTempURL = ::utl::TempFile().GetURL();
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     DBG_ASSERT( aTempURL.getLength(), "Can't create a temporary file!\n" );
295cdf0e10cSrcweir     if ( aTempURL.getLength() )
296cdf0e10cSrcweir     {
297cdf0e10cSrcweir         try
298cdf0e10cSrcweir         {
299cdf0e10cSrcweir             uno::Reference< embed::XStorage > xTempStorage =
300cdf0e10cSrcweir                 ::comphelper::OStorageHelper::GetStorageFromURL( aTempURL, embed::ElementModes::READWRITE );
301cdf0e10cSrcweir 
302cdf0e10cSrcweir             // the password will be transfered from the xStorage to xTempStorage by storage implemetation
303cdf0e10cSrcweir             xStorage->copyToStorage( xTempStorage );
304cdf0e10cSrcweir 
305cdf0e10cSrcweir             // the temporary storage was commited by the previous method and it will die by refcount
306cdf0e10cSrcweir         }
307cdf0e10cSrcweir         catch ( uno::Exception& )
308cdf0e10cSrcweir         {
309cdf0e10cSrcweir             DBG_ERROR( "Creation of a storage copy is failed!" );
310cdf0e10cSrcweir             ::utl::UCBContentHelper::Kill( aTempURL );
311cdf0e10cSrcweir 
312cdf0e10cSrcweir             aTempURL = ::rtl::OUString();
313cdf0e10cSrcweir 
314cdf0e10cSrcweir             // TODO/LATER: may need error code setting based on exception
315cdf0e10cSrcweir             SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
316cdf0e10cSrcweir         }
317cdf0e10cSrcweir     }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir     return aTempURL;
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir //-------------------------------------------------------------------------
GetClassName() const323cdf0e10cSrcweir SvGlobalName SfxObjectShell::GetClassName() const
324cdf0e10cSrcweir {
325cdf0e10cSrcweir     return GetFactory().GetClassId();
326cdf0e10cSrcweir }
327cdf0e10cSrcweir 
328cdf0e10cSrcweir //-------------------------------------------------------------------------
SetupStorage(const uno::Reference<embed::XStorage> & xStorage,sal_Int32 nVersion,sal_Bool bTemplate) const329cdf0e10cSrcweir void SfxObjectShell::SetupStorage( const uno::Reference< embed::XStorage >& xStorage,
330cdf0e10cSrcweir                                    sal_Int32 nVersion,
331cdf0e10cSrcweir                                    sal_Bool bTemplate ) const
332cdf0e10cSrcweir {
333cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY );
334cdf0e10cSrcweir 
335cdf0e10cSrcweir     if ( xProps.is() )
336cdf0e10cSrcweir     {
337cdf0e10cSrcweir         SvGlobalName aName;
338cdf0e10cSrcweir         String aFullTypeName, aShortTypeName, aAppName;
339cdf0e10cSrcweir         sal_uInt32 nClipFormat=0;
340cdf0e10cSrcweir 
341cdf0e10cSrcweir         FillClass( &aName, &nClipFormat, &aAppName, &aFullTypeName, &aShortTypeName, nVersion, bTemplate );
342cdf0e10cSrcweir         if ( nClipFormat )
343cdf0e10cSrcweir         {
344cdf0e10cSrcweir             // basic doesn't have a ClipFormat
345cdf0e10cSrcweir             // without MediaType the storage is not really usable, but currently the BasicIDE still
346cdf0e10cSrcweir             // is an SfxObjectShell and so we can't take this as an error
347cdf0e10cSrcweir             datatransfer::DataFlavor aDataFlavor;
348cdf0e10cSrcweir             SotExchange::GetFormatDataFlavor( nClipFormat, aDataFlavor );
349cdf0e10cSrcweir             if ( aDataFlavor.MimeType.getLength() )
350cdf0e10cSrcweir             {
351cdf0e10cSrcweir                 try
352cdf0e10cSrcweir                 {
353cdf0e10cSrcweir                     xProps->setPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ), uno::makeAny( aDataFlavor.MimeType ) );
354cdf0e10cSrcweir                 }
355cdf0e10cSrcweir                 catch( uno::Exception& )
356cdf0e10cSrcweir                 {
357cdf0e10cSrcweir                     const_cast<SfxObjectShell*>( this )->SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
358cdf0e10cSrcweir                 }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir                 SvtSaveOptions aSaveOpt;
361cdf0e10cSrcweir                 SvtSaveOptions::ODFDefaultVersion nDefVersion = aSaveOpt.GetODFDefaultVersion();
362cdf0e10cSrcweir 
363cdf0e10cSrcweir                 uno::Sequence< beans::NamedValue > aEncryptionAlgs( 3 );
364cdf0e10cSrcweir                 aEncryptionAlgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StartKeyGenerationAlgorithm" ) );
365cdf0e10cSrcweir                 aEncryptionAlgs[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionAlgorithm" ) );
366cdf0e10cSrcweir                 aEncryptionAlgs[2].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ChecksumAlgorithm" ) );
367cdf0e10cSrcweir                 // the default values, that should be used for ODF1.1 and older formats
368cdf0e10cSrcweir                 aEncryptionAlgs[0].Value <<= xml::crypto::DigestID::SHA1;
369cdf0e10cSrcweir                 aEncryptionAlgs[1].Value <<= xml::crypto::CipherID::BLOWFISH_CFB_8;
370cdf0e10cSrcweir                 aEncryptionAlgs[2].Value <<= xml::crypto::DigestID::SHA1_1K;
371cdf0e10cSrcweir 
372cdf0e10cSrcweir                 if ( nDefVersion >= SvtSaveOptions::ODFVER_012 )
373cdf0e10cSrcweir                 {
374cdf0e10cSrcweir                     try
375cdf0e10cSrcweir                     {
376cdf0e10cSrcweir                         // older versions can not have this property set, it exists only starting from ODF1.2
377cdf0e10cSrcweir                         xProps->setPropertyValue( ::rtl::OUString::createFromAscii( "Version" ), uno::makeAny( ODFVER_012_TEXT ) );
378cdf0e10cSrcweir                     }
379cdf0e10cSrcweir                     catch( uno::Exception& )
380cdf0e10cSrcweir                     {
381cdf0e10cSrcweir                     }
382cdf0e10cSrcweir 
383cdf0e10cSrcweir                     if ( !aSaveOpt.IsUseSHA1InODF12() )
384cdf0e10cSrcweir                     {
385cdf0e10cSrcweir                         aEncryptionAlgs[0].Value <<= xml::crypto::DigestID::SHA256;
386cdf0e10cSrcweir                         aEncryptionAlgs[2].Value <<= xml::crypto::DigestID::SHA256_1K;
387cdf0e10cSrcweir                     }
388cdf0e10cSrcweir                     if ( !aSaveOpt.IsUseBlowfishInODF12() )
389cdf0e10cSrcweir                         aEncryptionAlgs[1].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
390cdf0e10cSrcweir                 }
391cdf0e10cSrcweir 
392cdf0e10cSrcweir                 try
393cdf0e10cSrcweir                 {
394cdf0e10cSrcweir                     // set the encryption algorithms accordingly;
395cdf0e10cSrcweir                     // the setting does not trigger encryption,
396cdf0e10cSrcweir                     // it just provides the format for the case that contents should be encrypted
397cdf0e10cSrcweir                     uno::Reference< embed::XEncryptionProtectedStorage > xEncr( xStorage, uno::UNO_QUERY_THROW );
398cdf0e10cSrcweir                     xEncr->setEncryptionAlgorithms( aEncryptionAlgs );
399cdf0e10cSrcweir                 }
400cdf0e10cSrcweir                 catch( uno::Exception& )
401cdf0e10cSrcweir                 {
402cdf0e10cSrcweir                     const_cast<SfxObjectShell*>( this )->SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
403cdf0e10cSrcweir                 }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir             }
406cdf0e10cSrcweir         }
407cdf0e10cSrcweir     }
408cdf0e10cSrcweir }
409cdf0e10cSrcweir 
410cdf0e10cSrcweir //-------------------------------------------------------------------------
PrepareSecondTryLoad_Impl()411cdf0e10cSrcweir void SfxObjectShell::PrepareSecondTryLoad_Impl()
412cdf0e10cSrcweir {
413cdf0e10cSrcweir     // only for internal use
414cdf0e10cSrcweir     pImp->m_xDocStorage = uno::Reference< embed::XStorage >();
415cdf0e10cSrcweir     pImp->m_bIsInit = sal_False;
416cdf0e10cSrcweir     ResetError();
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
419cdf0e10cSrcweir //-------------------------------------------------------------------------
GeneralInit_Impl(const uno::Reference<embed::XStorage> & xStorage,sal_Bool bTypeMustBeSetAlready)420cdf0e10cSrcweir sal_Bool SfxObjectShell::GeneralInit_Impl( const uno::Reference< embed::XStorage >& xStorage,
421cdf0e10cSrcweir                                             sal_Bool bTypeMustBeSetAlready )
422cdf0e10cSrcweir {
423cdf0e10cSrcweir     if ( pImp->m_bIsInit )
424cdf0e10cSrcweir         return sal_False;
425cdf0e10cSrcweir 
426cdf0e10cSrcweir     pImp->m_bIsInit = sal_True;
427cdf0e10cSrcweir     if ( xStorage.is() )
428cdf0e10cSrcweir     {
429cdf0e10cSrcweir         // no notification is required the storage is set the first time
430cdf0e10cSrcweir         pImp->m_xDocStorage = xStorage;
431cdf0e10cSrcweir 
432cdf0e10cSrcweir         try {
433cdf0e10cSrcweir             uno::Reference < beans::XPropertySet > xPropSet( xStorage, uno::UNO_QUERY_THROW );
434cdf0e10cSrcweir             Any a = xPropSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) );
435cdf0e10cSrcweir             ::rtl::OUString aMediaType;
436cdf0e10cSrcweir             if ( !(a>>=aMediaType) || !aMediaType.getLength() )
437cdf0e10cSrcweir             {
438cdf0e10cSrcweir                 if ( bTypeMustBeSetAlready )
439cdf0e10cSrcweir                 {
440cdf0e10cSrcweir                     SetError( ERRCODE_IO_BROKENPACKAGE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
441cdf0e10cSrcweir                     return sal_False;
442cdf0e10cSrcweir                 }
443cdf0e10cSrcweir 
444cdf0e10cSrcweir                 SetupStorage( xStorage, SOFFICE_FILEFORMAT_CURRENT, sal_False );
445cdf0e10cSrcweir             }
446cdf0e10cSrcweir         }
447cdf0e10cSrcweir         catch ( uno::Exception& )
448cdf0e10cSrcweir         {
449cdf0e10cSrcweir             OSL_ENSURE( sal_False, "Can't check storage's mediatype!\n" );
450cdf0e10cSrcweir         }
451cdf0e10cSrcweir     }
452cdf0e10cSrcweir     else
453cdf0e10cSrcweir         pImp->m_bCreateTempStor = sal_True;
454cdf0e10cSrcweir 
455cdf0e10cSrcweir     return sal_True;
456cdf0e10cSrcweir }
457cdf0e10cSrcweir 
458cdf0e10cSrcweir //-------------------------------------------------------------------------
InitNew(const uno::Reference<embed::XStorage> & xStorage)459cdf0e10cSrcweir sal_Bool SfxObjectShell::InitNew( const uno::Reference< embed::XStorage >& xStorage )
460cdf0e10cSrcweir {
461cdf0e10cSrcweir     return GeneralInit_Impl( xStorage, sal_False );
462cdf0e10cSrcweir }
463cdf0e10cSrcweir 
464cdf0e10cSrcweir //-------------------------------------------------------------------------
Load(SfxMedium & rMedium)465cdf0e10cSrcweir sal_Bool SfxObjectShell::Load( SfxMedium& rMedium )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir     return GeneralInit_Impl( rMedium.GetStorage(), sal_True );
468cdf0e10cSrcweir }
469cdf0e10cSrcweir 
DoInitNew(SfxMedium * pMed)470cdf0e10cSrcweir sal_Bool SfxObjectShell::DoInitNew( SfxMedium* pMed )
471cdf0e10cSrcweir /*  [Beschreibung]
472cdf0e10cSrcweir 
473cdf0e10cSrcweir     Diese von SvPersist geerbte virtuelle Methode wird gerufen, um
474cdf0e10cSrcweir     die SfxObjectShell-Instanz aus einem Storage (pStor != 0) bzw.
475cdf0e10cSrcweir     (pStor == 0) ganz neu zu initialisieren.
476cdf0e10cSrcweir 
477cdf0e10cSrcweir     Wie alle Do...-Methoden liegt hier eine Steuerung vor, die eigentliche
478cdf0e10cSrcweir     Implementierung erfolgt, indem die ebenfalls virtuellen Methode
479cdf0e10cSrcweir     InitNew(SvStorate*) von der SfxObjectShell-Subclass implementiert wird.
480cdf0e10cSrcweir 
481cdf0e10cSrcweir     F"ur pStor == 0 wird ein die SfxObjectShell-Instanz mit einem leeren
482cdf0e10cSrcweir     SfxMedium verbunden, sonst mit einem SfxMedium, welches auf den
483cdf0e10cSrcweir     als Parameter "ubergeben SvStorage verweist.
484cdf0e10cSrcweir 
485cdf0e10cSrcweir     Erst nach InitNew() oder Load() ist das Objekt korrekt initialisiert.
486cdf0e10cSrcweir 
487cdf0e10cSrcweir     [R"uckgabewert]
488cdf0e10cSrcweir     sal_True            Das Objekt wurde initialisiert.
489cdf0e10cSrcweir     sal_False           Das Objekt konnte nicht initialisiert werden
490cdf0e10cSrcweir */
491cdf0e10cSrcweir 
492cdf0e10cSrcweir {
493cdf0e10cSrcweir     ModifyBlocker_Impl aBlock( this );
494cdf0e10cSrcweir     pMedium = pMed;
495cdf0e10cSrcweir     if ( !pMedium )
496cdf0e10cSrcweir     {
497cdf0e10cSrcweir         bIsTmp = sal_True;
498cdf0e10cSrcweir         pMedium = new SfxMedium;
499cdf0e10cSrcweir     }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir     pMedium->CanDisposeStorage_Impl( sal_True );
502cdf0e10cSrcweir 
503cdf0e10cSrcweir     if ( InitNew( pMed ? pMed->GetStorage() : uno::Reference < embed::XStorage >() ) )
504cdf0e10cSrcweir     {
505cdf0e10cSrcweir         // empty documents always get their macros from the user, so there is no reason to restrict access
506cdf0e10cSrcweir         pImp->aMacroMode.allowMacroExecution();
507cdf0e10cSrcweir         if ( SFX_CREATE_MODE_EMBEDDED == eCreateMode )
508cdf0e10cSrcweir             SetTitle( String( SfxResId( STR_NONAME ) ));
509cdf0e10cSrcweir 
510cdf0e10cSrcweir         uno::Reference< frame::XModel >  xModel ( GetModel(), uno::UNO_QUERY );
511cdf0e10cSrcweir         if ( xModel.is() )
512cdf0e10cSrcweir         {
513cdf0e10cSrcweir             SfxItemSet *pSet = GetMedium()->GetItemSet();
514cdf0e10cSrcweir             uno::Sequence< beans::PropertyValue > aArgs;
515cdf0e10cSrcweir             TransformItems( SID_OPENDOC, *pSet, aArgs );
516cdf0e10cSrcweir             sal_Int32 nLength = aArgs.getLength();
517cdf0e10cSrcweir             aArgs.realloc( nLength + 1 );
518cdf0e10cSrcweir             aArgs[nLength].Name = DEFINE_CONST_UNICODE("Title");
519cdf0e10cSrcweir             aArgs[nLength].Value <<= ::rtl::OUString( GetTitle( SFX_TITLE_DETECT ) );
520cdf0e10cSrcweir             xModel->attachResource( ::rtl::OUString(), aArgs );
521cdf0e10cSrcweir             impl_addToModelCollection(xModel);
522cdf0e10cSrcweir         }
523cdf0e10cSrcweir 
524cdf0e10cSrcweir         SetInitialized_Impl( true );
525cdf0e10cSrcweir 		return sal_True;
526cdf0e10cSrcweir 	}
527cdf0e10cSrcweir 
528cdf0e10cSrcweir     return sal_False;
529cdf0e10cSrcweir }
530cdf0e10cSrcweir 
531cdf0e10cSrcweir //-------------------------------------------------------------------------
532cdf0e10cSrcweir 
ImportFromGeneratedStream_Impl(const uno::Reference<io::XStream> & xStream,const uno::Sequence<beans::PropertyValue> & aMediaDescr)533cdf0e10cSrcweir sal_Bool SfxObjectShell::ImportFromGeneratedStream_Impl(
534cdf0e10cSrcweir                     const uno::Reference< io::XStream >& xStream,
535cdf0e10cSrcweir                     const uno::Sequence< beans::PropertyValue >& aMediaDescr )
536cdf0e10cSrcweir {
537cdf0e10cSrcweir     if ( !xStream.is() )
538cdf0e10cSrcweir         return sal_False;
539cdf0e10cSrcweir 
540cdf0e10cSrcweir     if ( pMedium && pMedium->HasStorage_Impl() )
541cdf0e10cSrcweir         pMedium->CloseStorage();
542cdf0e10cSrcweir 
543cdf0e10cSrcweir     sal_Bool bResult = sal_False;
544cdf0e10cSrcweir 
545cdf0e10cSrcweir     try
546cdf0e10cSrcweir     {
547cdf0e10cSrcweir         uno::Reference< embed::XStorage > xStorage =
548cdf0e10cSrcweir             ::comphelper::OStorageHelper::GetStorageFromStream( xStream, embed::ElementModes::READWRITE );
549cdf0e10cSrcweir 
550cdf0e10cSrcweir         if ( !xStorage.is() )
551cdf0e10cSrcweir             throw uno::RuntimeException();
552cdf0e10cSrcweir 
553cdf0e10cSrcweir         if ( !pMedium )
554cdf0e10cSrcweir             pMedium = new SfxMedium( xStorage, String() );
555cdf0e10cSrcweir         else
556cdf0e10cSrcweir             pMedium->SetStorage_Impl( xStorage );
557cdf0e10cSrcweir 
558cdf0e10cSrcweir         SfxAllItemSet aSet( SFX_APP()->GetPool() );
559cdf0e10cSrcweir         TransformParameters( SID_OPENDOC, aMediaDescr, aSet );
560cdf0e10cSrcweir         pMedium->GetItemSet()->Put( aSet );
561cdf0e10cSrcweir         pMedium->CanDisposeStorage_Impl( sal_False );
562cdf0e10cSrcweir 
563cdf0e10cSrcweir         // allow the subfilter to reinit the model
564cdf0e10cSrcweir         if ( pImp->m_bIsInit )
565cdf0e10cSrcweir             pImp->m_bIsInit = sal_False;
566cdf0e10cSrcweir 
567cdf0e10cSrcweir         if ( LoadOwnFormat( *pMedium ) )
568cdf0e10cSrcweir         {
569cdf0e10cSrcweir             bHasName = sal_True;
570cdf0e10cSrcweir             if ( !IsReadOnly() && IsLoadReadonly() )
571cdf0e10cSrcweir                 SetReadOnlyUI();
572cdf0e10cSrcweir 
573cdf0e10cSrcweir             bResult = sal_True;
574cdf0e10cSrcweir             OSL_ENSURE( pImp->m_xDocStorage == xStorage, "Wrong storage is used!\n" );
575cdf0e10cSrcweir         }
576cdf0e10cSrcweir 
577cdf0e10cSrcweir         // now the medium can be disconnected from the storage
578cdf0e10cSrcweir         // the medium is not allowed to dispose the storage so CloseStorage() can be used
579cdf0e10cSrcweir         pMedium->CloseStorage();
580cdf0e10cSrcweir     }
581cdf0e10cSrcweir     catch( uno::Exception& )
582cdf0e10cSrcweir     {
583cdf0e10cSrcweir     }
584cdf0e10cSrcweir 
585cdf0e10cSrcweir     return bResult;
586cdf0e10cSrcweir }
587cdf0e10cSrcweir 
588cdf0e10cSrcweir //-------------------------------------------------------------------------
589cdf0e10cSrcweir 
DoLoad(SfxMedium * pMed)590cdf0e10cSrcweir sal_Bool SfxObjectShell::DoLoad( SfxMedium *pMed )
591cdf0e10cSrcweir {
592cdf0e10cSrcweir     ModifyBlocker_Impl aBlock( this );
593cdf0e10cSrcweir 
594cdf0e10cSrcweir     if ( SFX_CREATE_MODE_EMBEDDED != eCreateMode )
595cdf0e10cSrcweir         GetpApp()->ShowStatusText( SfxResId(STR_DOC_LOADING) );
596cdf0e10cSrcweir 
597cdf0e10cSrcweir     pMedium = pMed;
598cdf0e10cSrcweir     pMedium->CanDisposeStorage_Impl( sal_True );
599cdf0e10cSrcweir 
600cdf0e10cSrcweir     sal_Bool bOk = sal_False;
601cdf0e10cSrcweir     const SfxFilter* pFilter = pMed->GetFilter();
602cdf0e10cSrcweir     SfxItemSet* pSet = pMedium->GetItemSet();
603cdf0e10cSrcweir     if( !pImp->nEventId )
604cdf0e10cSrcweir     {
605cdf0e10cSrcweir         SFX_ITEMSET_ARG(
606cdf0e10cSrcweir             pSet, pTemplateItem, SfxBoolItem,
607cdf0e10cSrcweir             SID_TEMPLATE, sal_False);
608cdf0e10cSrcweir         SetActivateEvent_Impl(
609cdf0e10cSrcweir             ( pTemplateItem && pTemplateItem->GetValue() )
610cdf0e10cSrcweir             ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
611cdf0e10cSrcweir     }
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 
614cdf0e10cSrcweir     SFX_ITEMSET_ARG( pSet, pBaseItem, SfxStringItem,
615cdf0e10cSrcweir                      SID_BASEURL, sal_False);
616cdf0e10cSrcweir     String aBaseURL;
617cdf0e10cSrcweir     SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
618cdf0e10cSrcweir     if( pBaseItem )
619cdf0e10cSrcweir         aBaseURL = pBaseItem->GetValue();
620cdf0e10cSrcweir     else
621cdf0e10cSrcweir     {
622cdf0e10cSrcweir         if ( pSalvageItem )
623cdf0e10cSrcweir         {
624cdf0e10cSrcweir             String aName( pMed->GetPhysicalName() );
625cdf0e10cSrcweir             ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aBaseURL );
626cdf0e10cSrcweir         }
627cdf0e10cSrcweir         else
628cdf0e10cSrcweir             aBaseURL = pMed->GetBaseURL();
629cdf0e10cSrcweir     }
630cdf0e10cSrcweir     pMed->GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, aBaseURL ) );
631cdf0e10cSrcweir 
632cdf0e10cSrcweir     pImp->nLoadedFlags = 0;
633cdf0e10cSrcweir     pImp->bModelInitialized = sal_False;
634cdf0e10cSrcweir 
635cdf0e10cSrcweir     //TODO/LATER: make a clear strategy how to handle "UsesStorage" etc.
636cdf0e10cSrcweir     sal_Bool bOwnStorageFormat = IsOwnStorageFormat_Impl( *pMedium );
637cdf0e10cSrcweir     sal_Bool bHasStorage = IsPackageStorageFormat_Impl( *pMedium );
638cdf0e10cSrcweir     if ( pMedium->GetFilter() )
639cdf0e10cSrcweir     {
640cdf0e10cSrcweir         sal_uInt32 nError = HandleFilter( pMedium, this );
641cdf0e10cSrcweir         if ( nError != ERRCODE_NONE )
642cdf0e10cSrcweir             SetError( nError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
643cdf0e10cSrcweir     }
644cdf0e10cSrcweir 
645cdf0e10cSrcweir     EnableSetModified( sal_False );
646cdf0e10cSrcweir 
647cdf0e10cSrcweir     pMedium->LockOrigFileOnDemand( sal_True, sal_False );
648cdf0e10cSrcweir     if ( GetError() == ERRCODE_NONE && bOwnStorageFormat && ( !pFilter || !( pFilter->GetFilterFlags() & SFX_FILTER_STARONEFILTER ) ) )
649cdf0e10cSrcweir     {
650cdf0e10cSrcweir         uno::Reference< embed::XStorage > xStorage;
651cdf0e10cSrcweir         if ( pMedium->GetError() == ERRCODE_NONE )
652cdf0e10cSrcweir             xStorage = pMedium->GetStorage();
653cdf0e10cSrcweir 
654cdf0e10cSrcweir         if( xStorage.is() && pMedium->GetLastStorageCreationState() == ERRCODE_NONE )
655cdf0e10cSrcweir         {
656cdf0e10cSrcweir             DBG_ASSERT( pFilter, "No filter for storage found!" );
657cdf0e10cSrcweir 
658cdf0e10cSrcweir             try
659cdf0e10cSrcweir             {
660cdf0e10cSrcweir                 sal_Bool bWarnMediaTypeFallback = sal_False;
661cdf0e10cSrcweir                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairPackageItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False);
662cdf0e10cSrcweir 
663cdf0e10cSrcweir                 // treat the package as broken if the mediatype was retrieved as a fallback
664cdf0e10cSrcweir                 uno::Reference< beans::XPropertySet > xStorProps( xStorage, uno::UNO_QUERY_THROW );
665cdf0e10cSrcweir                 xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaTypeFallbackUsed" ) ) )
666cdf0e10cSrcweir                                                                     >>= bWarnMediaTypeFallback;
667cdf0e10cSrcweir 
668cdf0e10cSrcweir                 if ( pRepairPackageItem && pRepairPackageItem->GetValue() )
669cdf0e10cSrcweir                 {
670cdf0e10cSrcweir                     // the macros in repaired documents should be disabled
671cdf0e10cSrcweir                     pMedium->GetItemSet()->Put( SfxUInt16Item( SID_MACROEXECMODE, document::MacroExecMode::NEVER_EXECUTE ) );
672cdf0e10cSrcweir 
673cdf0e10cSrcweir                     // the mediatype was retrieved by using fallback solution but this is a repairing mode
674cdf0e10cSrcweir                     // so it is acceptable to open the document if there is no contents that required manifest.xml
675cdf0e10cSrcweir                     bWarnMediaTypeFallback = sal_False;
676cdf0e10cSrcweir                 }
677cdf0e10cSrcweir 
678cdf0e10cSrcweir                 if ( bWarnMediaTypeFallback || !xStorage->getElementNames().getLength() )
679cdf0e10cSrcweir                     SetError( ERRCODE_IO_BROKENPACKAGE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
680cdf0e10cSrcweir             }
681cdf0e10cSrcweir             catch( uno::Exception& )
682cdf0e10cSrcweir             {
683cdf0e10cSrcweir                 // TODO/LATER: may need error code setting based on exception
684cdf0e10cSrcweir                 SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
685cdf0e10cSrcweir             }
686cdf0e10cSrcweir 
687cdf0e10cSrcweir             // Load
688cdf0e10cSrcweir             if ( !GetError() )
689cdf0e10cSrcweir             {
690cdf0e10cSrcweir                 pImp->nLoadedFlags = 0;
691cdf0e10cSrcweir                 pImp->bModelInitialized = sal_False;
692cdf0e10cSrcweir                 bOk = xStorage.is() && LoadOwnFormat( *pMed );
693cdf0e10cSrcweir                 if ( bOk )
694cdf0e10cSrcweir                 {
695cdf0e10cSrcweir                     // the document loaded from template has no name
696cdf0e10cSrcweir                     SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
697cdf0e10cSrcweir                     if ( !pTemplateItem || !pTemplateItem->GetValue() )
698cdf0e10cSrcweir                         bHasName = sal_True;
699cdf0e10cSrcweir 
700cdf0e10cSrcweir                     if ( !IsReadOnly() && IsLoadReadonly() )
701cdf0e10cSrcweir                         SetReadOnlyUI();
702cdf0e10cSrcweir                 }
703cdf0e10cSrcweir                 else
704cdf0e10cSrcweir                     SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
705cdf0e10cSrcweir             }
706cdf0e10cSrcweir         }
707cdf0e10cSrcweir         else
708cdf0e10cSrcweir             SetError( pMed->GetLastStorageCreationState(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
709cdf0e10cSrcweir     }
710cdf0e10cSrcweir     else if ( GetError() == ERRCODE_NONE && InitNew(0) )
711cdf0e10cSrcweir     {
712cdf0e10cSrcweir         // Name vor ConvertFrom setzen, damit GetSbxObject() schon funktioniert
713cdf0e10cSrcweir         bHasName = sal_True;
714cdf0e10cSrcweir         SetName( SfxResId( STR_NONAME ) );
715cdf0e10cSrcweir 
716cdf0e10cSrcweir         if( !bHasStorage )
717cdf0e10cSrcweir             pMedium->GetInStream();
718cdf0e10cSrcweir         else
719cdf0e10cSrcweir             pMedium->GetStorage();
720cdf0e10cSrcweir 
721cdf0e10cSrcweir         if ( GetError() == ERRCODE_NONE )
722cdf0e10cSrcweir         {
723cdf0e10cSrcweir             pImp->nLoadedFlags = 0;
724cdf0e10cSrcweir             pImp->bModelInitialized = sal_False;
725cdf0e10cSrcweir             if ( pMedium->GetFilter() && ( pMedium->GetFilter()->GetFilterFlags() & SFX_FILTER_STARONEFILTER ) )
726cdf0e10cSrcweir             {
727cdf0e10cSrcweir                 uno::Reference < beans::XPropertySet > xSet( GetModel(), uno::UNO_QUERY );
728cdf0e10cSrcweir                 ::rtl::OUString sLockUpdates(::rtl::OUString::createFromAscii("LockUpdates"));
729cdf0e10cSrcweir                 bool bSetProperty = true;
730cdf0e10cSrcweir                 try
731cdf0e10cSrcweir                 {
732cdf0e10cSrcweir                     xSet->setPropertyValue( sLockUpdates, makeAny( (sal_Bool) sal_True ) );
733cdf0e10cSrcweir                 }
734cdf0e10cSrcweir                 catch(const beans::UnknownPropertyException& )
735cdf0e10cSrcweir                 {
736cdf0e10cSrcweir                     bSetProperty = false;
737cdf0e10cSrcweir                 }
738cdf0e10cSrcweir                 bOk = ImportFrom(*pMedium);
739cdf0e10cSrcweir                 if(bSetProperty)
740cdf0e10cSrcweir                 {
741cdf0e10cSrcweir                     try
742cdf0e10cSrcweir                     {
743cdf0e10cSrcweir                         xSet->setPropertyValue( sLockUpdates, makeAny( (sal_Bool) sal_False ) );
744cdf0e10cSrcweir                     }
745cdf0e10cSrcweir                     catch(const beans::UnknownPropertyException& )
746cdf0e10cSrcweir                     {}
747cdf0e10cSrcweir                 }
748cdf0e10cSrcweir                 UpdateLinks();
749cdf0e10cSrcweir                 FinishedLoading( SFX_LOADED_ALL );
750cdf0e10cSrcweir             }
751cdf0e10cSrcweir             else
752cdf0e10cSrcweir             {
753cdf0e10cSrcweir                 bOk = ConvertFrom(*pMedium);
754cdf0e10cSrcweir                 InitOwnModel_Impl();
755cdf0e10cSrcweir             }
756cdf0e10cSrcweir         }
757cdf0e10cSrcweir     }
758cdf0e10cSrcweir 
759cdf0e10cSrcweir     if ( bOk )
760cdf0e10cSrcweir     {
761cdf0e10cSrcweir         try
762cdf0e10cSrcweir         {
763cdf0e10cSrcweir             ::ucbhelper::Content aContent( pMedium->GetName(), com::sun::star::uno::Reference < XCommandEnvironment >() );
764cdf0e10cSrcweir             com::sun::star::uno::Reference < XPropertySetInfo > xProps = aContent.getProperties();
765cdf0e10cSrcweir             if ( xProps.is() )
766cdf0e10cSrcweir             {
767cdf0e10cSrcweir                 ::rtl::OUString aAuthor( RTL_CONSTASCII_USTRINGPARAM("Author") );
768cdf0e10cSrcweir                 ::rtl::OUString aKeywords( RTL_CONSTASCII_USTRINGPARAM("Keywords") );
769cdf0e10cSrcweir                 ::rtl::OUString aSubject( RTL_CONSTASCII_USTRINGPARAM("Subject") );
770cdf0e10cSrcweir                 Any aAny;
771cdf0e10cSrcweir                 ::rtl::OUString aValue;
772cdf0e10cSrcweir                 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
773cdf0e10cSrcweir                     GetModel(), uno::UNO_QUERY_THROW);
774cdf0e10cSrcweir                 uno::Reference<document::XDocumentProperties> xDocProps
775cdf0e10cSrcweir                     = xDPS->getDocumentProperties();
776cdf0e10cSrcweir                 if ( xProps->hasPropertyByName( aAuthor ) )
777cdf0e10cSrcweir                 {
778cdf0e10cSrcweir                     aAny = aContent.getPropertyValue( aAuthor );
779cdf0e10cSrcweir                     if ( ( aAny >>= aValue ) )
780cdf0e10cSrcweir                         xDocProps->setAuthor(aValue);
781cdf0e10cSrcweir                 }
782cdf0e10cSrcweir                 if ( xProps->hasPropertyByName( aKeywords ) )
783cdf0e10cSrcweir                 {
784cdf0e10cSrcweir                     aAny = aContent.getPropertyValue( aKeywords );
785cdf0e10cSrcweir                     if ( ( aAny >>= aValue ) )
786cdf0e10cSrcweir                         xDocProps->setKeywords(
787cdf0e10cSrcweir                           ::comphelper::string::convertCommaSeparated(aValue));
788cdf0e10cSrcweir ;
789cdf0e10cSrcweir                 }
790cdf0e10cSrcweir                 if ( xProps->hasPropertyByName( aSubject ) )
791cdf0e10cSrcweir                 {
792cdf0e10cSrcweir                     aAny = aContent.getPropertyValue( aSubject );
793cdf0e10cSrcweir                     if ( ( aAny >>= aValue ) ) {
794cdf0e10cSrcweir                         xDocProps->setSubject(aValue);
795cdf0e10cSrcweir                     }
796cdf0e10cSrcweir                 }
797cdf0e10cSrcweir             }
798cdf0e10cSrcweir         }
799cdf0e10cSrcweir         catch( Exception& )
800cdf0e10cSrcweir         {
801cdf0e10cSrcweir         }
802cdf0e10cSrcweir 
803cdf0e10cSrcweir         // Falls nicht asynchron geladen wird selbst FinishedLoading aufrufen
804cdf0e10cSrcweir         if ( !( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) &&
805cdf0e10cSrcweir             ( !pMedium->GetFilter() || pMedium->GetFilter()->UsesStorage() )
806cdf0e10cSrcweir             )
807cdf0e10cSrcweir             FinishedLoading( SFX_LOADED_MAINDOCUMENT );
808cdf0e10cSrcweir 
809cdf0e10cSrcweir         if( IsOwnStorageFormat_Impl(*pMed) && pMed->GetFilter() )
810cdf0e10cSrcweir         {
811cdf0e10cSrcweir //???? dv			DirEntry aDirEntry( pMed->GetPhysicalName() );
812cdf0e10cSrcweir //???? dv			SetFileName( aDirEntry.GetFull() );
813cdf0e10cSrcweir         }
814cdf0e10cSrcweir         Broadcast( SfxSimpleHint(SFX_HINT_NAMECHANGED) );
815cdf0e10cSrcweir 
816cdf0e10cSrcweir         if ( SFX_CREATE_MODE_EMBEDDED != eCreateMode )
817cdf0e10cSrcweir         {
818cdf0e10cSrcweir             GetpApp()->HideStatusText();
819cdf0e10cSrcweir 
820cdf0e10cSrcweir             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pAsTempItem, SfxBoolItem, SID_TEMPLATE, sal_False);
821cdf0e10cSrcweir             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pPreviewItem, SfxBoolItem, SID_PREVIEW, sal_False);
822cdf0e10cSrcweir             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False);
823cdf0e10cSrcweir             if( bOk && pMedium->GetOrigURL().Len()
824cdf0e10cSrcweir             && !( pAsTempItem && pAsTempItem->GetValue() )
825cdf0e10cSrcweir             && !( pPreviewItem && pPreviewItem->GetValue() )
826cdf0e10cSrcweir             && !( pHiddenItem && pHiddenItem->GetValue() ) )
827cdf0e10cSrcweir             {
828cdf0e10cSrcweir                 INetURLObject aUrl( pMedium->GetOrigURL() );
829cdf0e10cSrcweir 
830cdf0e10cSrcweir                 if ( aUrl.GetProtocol() == INET_PROT_FILE )
831cdf0e10cSrcweir                 {
832cdf0e10cSrcweir                     const SfxFilter* pOrgFilter = pMedium->GetOrigFilter();
833cdf0e10cSrcweir                     Application::AddToRecentDocumentList(
834cdf0e10cSrcweir                         aUrl.GetURLNoPass( INetURLObject::NO_DECODE ),
835cdf0e10cSrcweir                         (pOrgFilter) ? pOrgFilter->GetMimeType() : String() );
836cdf0e10cSrcweir                 }
837cdf0e10cSrcweir             }
838cdf0e10cSrcweir         }
839cdf0e10cSrcweir 
840cdf0e10cSrcweir         if ( pMedium->HasStorage_Impl() )
841cdf0e10cSrcweir         {
842cdf0e10cSrcweir             uno::Reference< XInteractionHandler > xHandler( pMedium->GetInteractionHandler() );
843cdf0e10cSrcweir             if ( xHandler.is() && !SFX_APP()->Get_Impl()->bODFVersionWarningLater )
844cdf0e10cSrcweir             {
845cdf0e10cSrcweir                 uno::Reference<beans::XPropertySet> xStorageProps( pMedium->GetStorage(), uno::UNO_QUERY_THROW );
846cdf0e10cSrcweir                 ::rtl::OUString sVersion;
847cdf0e10cSrcweir                 try
848cdf0e10cSrcweir                 {
849cdf0e10cSrcweir                     xStorageProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= sVersion;
850cdf0e10cSrcweir                 }
851cdf0e10cSrcweir                 catch( const uno::Exception& )
852cdf0e10cSrcweir                 {
853cdf0e10cSrcweir                     // Custom Property "ODFVersion" does not exist
854cdf0e10cSrcweir                 }
855cdf0e10cSrcweir 
856cdf0e10cSrcweir                 if ( sVersion.getLength() )
857cdf0e10cSrcweir                 {
858cdf0e10cSrcweir                     double nVersion = sVersion.toDouble();
859cdf0e10cSrcweir                     if ( nVersion > 1.20001  && SfxObjectShell_Impl::NeedsOfficeUpdateDialog() )
860cdf0e10cSrcweir                         // ODF version greater than 1.2 - added some decimal places to be safe against floating point conversion errors (hack)
861cdf0e10cSrcweir                     {
862cdf0e10cSrcweir                         ::rtl::OUString sDocumentURL( pMedium->GetOrigURL() );
863cdf0e10cSrcweir                         ::rtl::OUString aSystemFileURL;
864cdf0e10cSrcweir                         if ( osl::FileBase::getSystemPathFromFileURL( sDocumentURL, aSystemFileURL ) == osl::FileBase::E_None )
865cdf0e10cSrcweir                             sDocumentURL = aSystemFileURL;
866cdf0e10cSrcweir 
867cdf0e10cSrcweir                         FutureDocumentVersionProductUpdateRequest aUpdateRequest;
868cdf0e10cSrcweir                         aUpdateRequest.Classification = InteractionClassification_QUERY;
869cdf0e10cSrcweir                         aUpdateRequest.DocumentURL = sDocumentURL;
870cdf0e10cSrcweir 
871cdf0e10cSrcweir                         ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest = new ::comphelper::OInteractionRequest( makeAny( aUpdateRequest ) );
872cdf0e10cSrcweir                         pRequest->addContinuation( new ::comphelper::OInteractionApprove );
873cdf0e10cSrcweir                         pRequest->addContinuation( new ::comphelper::OInteractionAbort );
874cdf0e10cSrcweir 
875cdf0e10cSrcweir                         typedef ::comphelper::OInteraction< XInteractionAskLater > OInteractionAskLater;
876cdf0e10cSrcweir                         OInteractionAskLater* pLater = new OInteractionAskLater;
877cdf0e10cSrcweir                         pRequest->addContinuation( pLater );
878cdf0e10cSrcweir 
879cdf0e10cSrcweir                         try
880cdf0e10cSrcweir                         {
881cdf0e10cSrcweir                             xHandler->handle( pRequest.get() );
882cdf0e10cSrcweir                         }
883cdf0e10cSrcweir                         catch( const Exception& )
884cdf0e10cSrcweir                         {
885cdf0e10cSrcweir                             DBG_UNHANDLED_EXCEPTION();
886cdf0e10cSrcweir                         }
887cdf0e10cSrcweir                         if ( pLater->wasSelected() )
888cdf0e10cSrcweir                             SFX_APP()->Get_Impl()->bODFVersionWarningLater = true;
889cdf0e10cSrcweir                     }
890cdf0e10cSrcweir                 }
891cdf0e10cSrcweir             }
892cdf0e10cSrcweir         }
893cdf0e10cSrcweir     }
894cdf0e10cSrcweir     else
895cdf0e10cSrcweir         GetpApp()->HideStatusText();
896cdf0e10cSrcweir 
897cdf0e10cSrcweir     return bOk;
898cdf0e10cSrcweir }
899cdf0e10cSrcweir 
HandleFilter(SfxMedium * pMedium,SfxObjectShell * pDoc)900cdf0e10cSrcweir sal_uInt32 SfxObjectShell::HandleFilter( SfxMedium* pMedium, SfxObjectShell* pDoc )
901cdf0e10cSrcweir {
902cdf0e10cSrcweir     sal_uInt32 nError = ERRCODE_NONE;
903cdf0e10cSrcweir     SfxItemSet* pSet = pMedium->GetItemSet();
904cdf0e10cSrcweir     SFX_ITEMSET_ARG( pSet, pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False );
905cdf0e10cSrcweir     SFX_ITEMSET_ARG( pSet, pData, SfxUnoAnyItem, SID_FILTER_DATA, sal_False );
906cdf0e10cSrcweir     if ( !pData && !pOptions )
907cdf0e10cSrcweir     {
908cdf0e10cSrcweir         com::sun::star::uno::Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
909cdf0e10cSrcweir         com::sun::star::uno::Reference< XNameAccess > xFilterCFG;
910cdf0e10cSrcweir         if( xServiceManager.is() )
911cdf0e10cSrcweir         {
912cdf0e10cSrcweir             xFilterCFG = com::sun::star::uno::Reference< XNameAccess >(
913cdf0e10cSrcweir                 xServiceManager->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ),
914cdf0e10cSrcweir                 UNO_QUERY );
915cdf0e10cSrcweir         }
916cdf0e10cSrcweir 
917cdf0e10cSrcweir         if( xFilterCFG.is() )
918cdf0e10cSrcweir         {
919cdf0e10cSrcweir             sal_Bool bAbort = sal_False;
920cdf0e10cSrcweir             try {
921cdf0e10cSrcweir                 const SfxFilter* pFilter = pMedium->GetFilter();
922cdf0e10cSrcweir                 Sequence < PropertyValue > aProps;
923cdf0e10cSrcweir                 Any aAny = xFilterCFG->getByName( pFilter->GetName() );
924cdf0e10cSrcweir                 if ( aAny >>= aProps )
925cdf0e10cSrcweir                 {
926cdf0e10cSrcweir                     sal_Int32 nPropertyCount = aProps.getLength();
927cdf0e10cSrcweir                     for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty )
928cdf0e10cSrcweir                         if( aProps[nProperty].Name.equals( ::rtl::OUString::createFromAscii("UIComponent")) )
929cdf0e10cSrcweir                         {
930cdf0e10cSrcweir                             ::rtl::OUString aServiceName;
931cdf0e10cSrcweir                             aProps[nProperty].Value >>= aServiceName;
932cdf0e10cSrcweir                             if( aServiceName.getLength() )
933cdf0e10cSrcweir                             {
934cdf0e10cSrcweir                                 com::sun::star::uno::Reference< XInteractionHandler > rHandler = pMedium->GetInteractionHandler();
935cdf0e10cSrcweir                                 if( rHandler.is() )
936cdf0e10cSrcweir                                 {
937cdf0e10cSrcweir                                     // we need some properties in the media descriptor, so we have to make sure that they are in
938cdf0e10cSrcweir                                     Any aStreamAny;
939cdf0e10cSrcweir                                     aStreamAny <<= pMedium->GetInputStream();
940cdf0e10cSrcweir                                     if ( pSet->GetItemState( SID_INPUTSTREAM ) < SFX_ITEM_SET )
941cdf0e10cSrcweir                                         pSet->Put( SfxUnoAnyItem( SID_INPUTSTREAM, aStreamAny ) );
942cdf0e10cSrcweir                                     if ( pSet->GetItemState( SID_FILE_NAME ) < SFX_ITEM_SET )
943cdf0e10cSrcweir                                         pSet->Put( SfxStringItem( SID_FILE_NAME, pMedium->GetName() ) );
944cdf0e10cSrcweir                                     if ( pSet->GetItemState( SID_FILTER_NAME ) < SFX_ITEM_SET )
945cdf0e10cSrcweir                                         pSet->Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) );
946cdf0e10cSrcweir 
947cdf0e10cSrcweir                                     Sequence< PropertyValue > rProperties;
948cdf0e10cSrcweir                                     TransformItems( SID_OPENDOC, *pSet, rProperties, NULL );
949cdf0e10cSrcweir                                     RequestFilterOptions* pFORequest = new RequestFilterOptions( pDoc->GetModel(), rProperties );
950cdf0e10cSrcweir 
951cdf0e10cSrcweir                                     com::sun::star::uno::Reference< XInteractionRequest > rRequest( pFORequest );
952cdf0e10cSrcweir                                     rHandler->handle( rRequest );
953cdf0e10cSrcweir 
954cdf0e10cSrcweir                                     if ( !pFORequest->isAbort() )
955cdf0e10cSrcweir                                     {
956cdf0e10cSrcweir                                             SfxAllItemSet aNewParams( pDoc->GetPool() );
957cdf0e10cSrcweir                                             TransformParameters( SID_OPENDOC,
958cdf0e10cSrcweir                                                             pFORequest->getFilterOptions(),
959cdf0e10cSrcweir                                                             aNewParams,
960cdf0e10cSrcweir                                                             NULL );
961cdf0e10cSrcweir 
962cdf0e10cSrcweir                                             SFX_ITEMSET_ARG( &aNewParams,
963cdf0e10cSrcweir                                                         pFilterOptions,
964cdf0e10cSrcweir                                                         SfxStringItem,
965cdf0e10cSrcweir                                                         SID_FILE_FILTEROPTIONS,
966cdf0e10cSrcweir                                                         sal_False );
967cdf0e10cSrcweir                                             if ( pFilterOptions )
968cdf0e10cSrcweir                                                 pSet->Put( *pFilterOptions );
969cdf0e10cSrcweir 
970cdf0e10cSrcweir                                             SFX_ITEMSET_ARG( &aNewParams,
971cdf0e10cSrcweir                                                         pFilterData,
972cdf0e10cSrcweir                                                         SfxUnoAnyItem,
973cdf0e10cSrcweir                                                         SID_FILTER_DATA,
974cdf0e10cSrcweir                                                         sal_False );
975cdf0e10cSrcweir                                             if ( pFilterData )
976cdf0e10cSrcweir                                                 pSet->Put( *pFilterData );
977cdf0e10cSrcweir                                     }
978cdf0e10cSrcweir                                     else
979cdf0e10cSrcweir                                         bAbort = sal_True;
980cdf0e10cSrcweir                                 }
981cdf0e10cSrcweir                             }
982cdf0e10cSrcweir 
983cdf0e10cSrcweir                             break;
984cdf0e10cSrcweir                         }
985cdf0e10cSrcweir                 }
986cdf0e10cSrcweir 
987cdf0e10cSrcweir                 if( bAbort )
988cdf0e10cSrcweir                 {
989cdf0e10cSrcweir                     // filter options were not entered
990cdf0e10cSrcweir                     nError = ERRCODE_ABORT;
991cdf0e10cSrcweir                 }
992cdf0e10cSrcweir             }
993cdf0e10cSrcweir             catch( NoSuchElementException& )
994cdf0e10cSrcweir             {
995cdf0e10cSrcweir                 // the filter name is unknown
996cdf0e10cSrcweir                 nError = ERRCODE_IO_INVALIDPARAMETER;
997cdf0e10cSrcweir             }
998cdf0e10cSrcweir             catch( Exception& )
999cdf0e10cSrcweir             {
1000cdf0e10cSrcweir                 nError = ERRCODE_ABORT;
1001cdf0e10cSrcweir             }
1002cdf0e10cSrcweir         }
1003cdf0e10cSrcweir     }
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir     return nError;
1006cdf0e10cSrcweir }
1007cdf0e10cSrcweir 
1008cdf0e10cSrcweir //-------------------------------------------------------------------------
1009cdf0e10cSrcweir 
IsOwnStorageFormat_Impl(const SfxMedium & rMedium) const1010cdf0e10cSrcweir sal_Bool SfxObjectShell::IsOwnStorageFormat_Impl(const SfxMedium &rMedium) const
1011cdf0e10cSrcweir {
1012cdf0e10cSrcweir     return !rMedium.GetFilter() || // Embedded
1013cdf0e10cSrcweir            ( rMedium.GetFilter()->IsOwnFormat() &&
1014cdf0e10cSrcweir              rMedium.GetFilter()->UsesStorage() &&
1015cdf0e10cSrcweir              rMedium.GetFilter()->GetVersion() >= SOFFICE_FILEFORMAT_60 );
1016cdf0e10cSrcweir }
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir //-------------------------------------------------------------------------
1019cdf0e10cSrcweir 
IsPackageStorageFormat_Impl(const SfxMedium & rMedium) const1020cdf0e10cSrcweir sal_Bool SfxObjectShell::IsPackageStorageFormat_Impl(const SfxMedium &rMedium) const
1021cdf0e10cSrcweir {
1022cdf0e10cSrcweir     return !rMedium.GetFilter() || // Embedded
1023cdf0e10cSrcweir            ( rMedium.GetFilter()->UsesStorage() &&
1024cdf0e10cSrcweir              rMedium.GetFilter()->GetVersion() >= SOFFICE_FILEFORMAT_60 );
1025cdf0e10cSrcweir }
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir //-------------------------------------------------------------------------
1028cdf0e10cSrcweir 
DoSave()1029cdf0e10cSrcweir sal_Bool SfxObjectShell::DoSave()
1030cdf0e10cSrcweir // DoSave wird nur noch ueber OLE aufgerufen. Sichern eigener Dokumente im SFX
1031cdf0e10cSrcweir // laeuft uber DoSave_Impl, um das Anlegen von Backups zu ermoeglichen.
1032cdf0e10cSrcweir // Save in eigenes Format jetzt auch wieder Hierueber
1033cdf0e10cSrcweir {
1034cdf0e10cSrcweir     sal_Bool bOk = sal_False ;
1035cdf0e10cSrcweir     {
1036cdf0e10cSrcweir         ModifyBlocker_Impl aBlock( this );
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir         pImp->bIsSaving = sal_True;
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aEncryptionData;
1041cdf0e10cSrcweir         if ( IsPackageStorageFormat_Impl( *GetMedium() ) )
1042cdf0e10cSrcweir         {
1043cdf0e10cSrcweir             if ( GetEncryptionData_Impl( GetMedium()->GetItemSet(), aEncryptionData ) )
1044cdf0e10cSrcweir             {
1045cdf0e10cSrcweir                 try
1046cdf0e10cSrcweir                 {
1047cdf0e10cSrcweir                     //TODO/MBA: GetOutputStorage?! Special mode, because it's "Save"?!
1048cdf0e10cSrcweir                     ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( GetMedium()->GetStorage(), aEncryptionData );
1049cdf0e10cSrcweir                     bOk = sal_True;
1050cdf0e10cSrcweir                 }
1051cdf0e10cSrcweir                 catch( uno::Exception& )
1052cdf0e10cSrcweir                 {
1053cdf0e10cSrcweir                     SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
1054cdf0e10cSrcweir                 }
1055cdf0e10cSrcweir 
1056cdf0e10cSrcweir                 DBG_ASSERT( bOk, "The root storage must allow to set common password!\n" );
1057cdf0e10cSrcweir             }
1058cdf0e10cSrcweir             else
1059cdf0e10cSrcweir                 bOk = sal_True;
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir             if ( HasBasic() )
1062cdf0e10cSrcweir             {
1063cdf0e10cSrcweir                 try
1064cdf0e10cSrcweir                 {
1065cdf0e10cSrcweir                     // The basic and dialogs related contents are still not able to proceed with save operation ( saveTo only )
1066cdf0e10cSrcweir                     // so since the document storage is locked a workaround has to be used
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir                     uno::Reference< embed::XStorage > xTmpStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
1069cdf0e10cSrcweir                     DBG_ASSERT( xTmpStorage.is(), "If a storage can not be created an exception must be thrown!\n" );
1070cdf0e10cSrcweir                     if ( !xTmpStorage.is() )
1071cdf0e10cSrcweir                         throw uno::RuntimeException();
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir                     ::rtl::OUString aBasicStorageName( RTL_CONSTASCII_USTRINGPARAM( "Basic" ) );
1074cdf0e10cSrcweir                     ::rtl::OUString aDialogsStorageName( RTL_CONSTASCII_USTRINGPARAM( "Dialogs" ) );
1075cdf0e10cSrcweir                     if ( GetMedium()->GetStorage()->hasByName( aBasicStorageName ) )
1076cdf0e10cSrcweir                         GetMedium()->GetStorage()->copyElementTo( aBasicStorageName, xTmpStorage, aBasicStorageName );
1077cdf0e10cSrcweir                     if ( GetMedium()->GetStorage()->hasByName( aDialogsStorageName ) )
1078cdf0e10cSrcweir                         GetMedium()->GetStorage()->copyElementTo( aDialogsStorageName, xTmpStorage, aDialogsStorageName );
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir                     GetBasicManager();
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir                     // disconnect from the current storage
1083cdf0e10cSrcweir                     pImp->pBasicManager->setStorage( xTmpStorage );
1084cdf0e10cSrcweir 
1085cdf0e10cSrcweir                     // store to the current storage
1086cdf0e10cSrcweir                     pImp->pBasicManager->storeLibrariesToStorage( GetMedium()->GetStorage() );
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir                     // connect to the current storage back
1089cdf0e10cSrcweir                     pImp->pBasicManager->setStorage( GetMedium()->GetStorage() );
1090cdf0e10cSrcweir                 }
1091cdf0e10cSrcweir                 catch( uno::Exception& )
1092cdf0e10cSrcweir                 {
1093cdf0e10cSrcweir                     SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
1094cdf0e10cSrcweir                     bOk = sal_False;
1095cdf0e10cSrcweir                 }
1096cdf0e10cSrcweir             }
1097cdf0e10cSrcweir         }
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir         if ( bOk )
1100cdf0e10cSrcweir             bOk = Save();
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir         bOk = pMedium->Commit();
1103cdf0e10cSrcweir     }
1104cdf0e10cSrcweir 
1105cdf0e10cSrcweir //#88046
1106cdf0e10cSrcweir //    if ( bOk )
1107cdf0e10cSrcweir //        SetModified( sal_False );
1108cdf0e10cSrcweir     return bOk;
1109cdf0e10cSrcweir }
1110cdf0e10cSrcweir 
Lock_Impl(SfxObjectShell * pDoc,sal_Bool bLock)1111cdf0e10cSrcweir void Lock_Impl( SfxObjectShell* pDoc, sal_Bool bLock )
1112cdf0e10cSrcweir {
1113cdf0e10cSrcweir     SfxViewFrame *pFrame= SfxViewFrame::GetFirst( pDoc );
1114cdf0e10cSrcweir     while ( pFrame )
1115cdf0e10cSrcweir     {
1116cdf0e10cSrcweir         pFrame->GetDispatcher()->Lock( bLock );
1117cdf0e10cSrcweir         pFrame->Enable( !bLock );
1118cdf0e10cSrcweir         pFrame = SfxViewFrame::GetNext( *pFrame, pDoc );
1119cdf0e10cSrcweir     }
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir }
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir //-------------------------------------------------------------------------
1124cdf0e10cSrcweir 
SaveTo_Impl(SfxMedium & rMedium,const SfxItemSet * pSet)1125cdf0e10cSrcweir sal_Bool SfxObjectShell::SaveTo_Impl
1126cdf0e10cSrcweir (
1127cdf0e10cSrcweir      SfxMedium &rMedium, // Medium, in das gespeichert werden soll
1128cdf0e10cSrcweir      const SfxItemSet* pSet
1129cdf0e10cSrcweir )
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir /*  [Beschreibung]
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir     Schreibt den aktuellen Inhalt in das Medium rMedium.
1134cdf0e10cSrcweir     Ist das Zielmedium kein Storage, so wird ueber ein temporaeres
1135cdf0e10cSrcweir     Medium gespeichert, sonst direkt, da das Medium transacted
1136cdf0e10cSrcweir     geschaltet ist, wenn wir es selbst geoeffnet haben und falls wir
1137cdf0e10cSrcweir     Server sind entweder der Container einen transacted Storage zur
1138cdf0e10cSrcweir     Verfuegung stellt oder selbst einen temporaeren Storage erzeugt hat.
1139cdf0e10cSrcweir */
1140cdf0e10cSrcweir 
1141cdf0e10cSrcweir {
1142cdf0e10cSrcweir     RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "PERFORMANCE SfxObjectShell::SaveTo_Impl" );
1143cdf0e10cSrcweir     if( RTL_LOGFILE_HASLOGFILE() )
1144cdf0e10cSrcweir     {
1145cdf0e10cSrcweir         ByteString aString( rMedium.GetName(), RTL_TEXTENCODING_ASCII_US );
1146cdf0e10cSrcweir         RTL_LOGFILE_PRODUCT_CONTEXT_TRACE1( aLog, "saving \"%s\"", aString.GetBuffer() );
1147cdf0e10cSrcweir     }
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir     AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Begin" ) ) );
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir     ModifyBlocker_Impl aMod(this);
1152cdf0e10cSrcweir 
1153cdf0e10cSrcweir     const SfxFilter *pFilter = rMedium.GetFilter();
1154cdf0e10cSrcweir     if ( !pFilter )
1155cdf0e10cSrcweir     {
1156cdf0e10cSrcweir         // if no filter was set, use the default filter
1157cdf0e10cSrcweir         // this should be changed in the feature, it should be an error!
1158cdf0e10cSrcweir         DBG_ERROR("No filter set!");
1159cdf0e10cSrcweir         pFilter = GetFactory().GetFilterContainer()->GetAnyFilter( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT );
1160cdf0e10cSrcweir         rMedium.SetFilter(pFilter);
1161cdf0e10cSrcweir     }
1162cdf0e10cSrcweir 
1163cdf0e10cSrcweir     sal_Bool bStorageBasedSource = IsPackageStorageFormat_Impl( *pMedium );
1164cdf0e10cSrcweir     sal_Bool bStorageBasedTarget = IsPackageStorageFormat_Impl( rMedium );
1165cdf0e10cSrcweir     sal_Bool bOwnSource = IsOwnStorageFormat_Impl( *pMedium );
1166cdf0e10cSrcweir     sal_Bool bOwnTarget = IsOwnStorageFormat_Impl( rMedium );
1167cdf0e10cSrcweir 
1168cdf0e10cSrcweir     // Examine target format to determine whether to query if any password
1169cdf0e10cSrcweir     // protected libraries exceed the size we can handler
1170cdf0e10cSrcweir     if ( bOwnTarget && !QuerySaveSizeExceededModules_Impl( rMedium.GetInteractionHandler() ) )
1171cdf0e10cSrcweir     {
1172cdf0e10cSrcweir         SetError( ERRCODE_IO_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
1173cdf0e10cSrcweir         return sal_False;
1174cdf0e10cSrcweir     }
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir     sal_Bool bNeedsDisconnectionOnFail = sal_False;
1177cdf0e10cSrcweir 
1178cdf0e10cSrcweir     sal_Bool bStoreToSameLocation = sal_False;
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir     // the detection whether the script is changed should be done before saving
1181cdf0e10cSrcweir     sal_Bool bTryToPreserveScriptSignature = sal_False;
1182cdf0e10cSrcweir     // no way to detect whether a filter is oasis format, have to wait for saving process
1183cdf0e10cSrcweir     sal_Bool bNoPreserveForOasis = sal_False;
1184cdf0e10cSrcweir     if ( bOwnSource && bOwnTarget
1185cdf0e10cSrcweir       && ( pImp->nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
1186cdf0e10cSrcweir         || pImp->nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED
1187cdf0e10cSrcweir         || pImp->nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_INVALID ) )
1188cdf0e10cSrcweir     {
1189cdf0e10cSrcweir         AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "MacroSignaturePreserving" ) ) );
1190cdf0e10cSrcweir 
1191cdf0e10cSrcweir         // the checking of the library modified state iterates over the libraries, should be done only when required
1192cdf0e10cSrcweir         // currently the check is commented out since it is broken, we have to check the signature every time we save
1193cdf0e10cSrcweir         // TODO/LATER: let isAnyContainerModified() work!
1194cdf0e10cSrcweir         bTryToPreserveScriptSignature = sal_True; // !pImp->pBasicManager->isAnyContainerModified();
1195cdf0e10cSrcweir         if ( bTryToPreserveScriptSignature )
1196cdf0e10cSrcweir         {
1197cdf0e10cSrcweir             // check that the storage format stays the same
1198cdf0e10cSrcweir             SvtSaveOptions aSaveOpt;
1199cdf0e10cSrcweir             SvtSaveOptions::ODFDefaultVersion nVersion = aSaveOpt.GetODFDefaultVersion();
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir             ::rtl::OUString aODFVersion;
1202cdf0e10cSrcweir             try
1203cdf0e10cSrcweir             {
1204cdf0e10cSrcweir                 uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
1205cdf0e10cSrcweir                 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aODFVersion;
1206cdf0e10cSrcweir             }
1207cdf0e10cSrcweir             catch( uno::Exception& )
1208cdf0e10cSrcweir             {}
1209cdf0e10cSrcweir 
1210cdf0e10cSrcweir             // preserve only if the same filter has been used
1211cdf0e10cSrcweir             bTryToPreserveScriptSignature = pMedium->GetFilter() && pFilter && pMedium->GetFilter()->GetFilterName() == pFilter->GetFilterName();
1212cdf0e10cSrcweir 
1213cdf0e10cSrcweir             bNoPreserveForOasis = (
1214cdf0e10cSrcweir                                    (aODFVersion.equals( ODFVER_012_TEXT ) && nVersion == SvtSaveOptions::ODFVER_011) ||
1215cdf0e10cSrcweir                                    (!aODFVersion.getLength() && nVersion >= SvtSaveOptions::ODFVER_012)
1216cdf0e10cSrcweir                                   );
1217cdf0e10cSrcweir         }
1218cdf0e10cSrcweir     }
1219cdf0e10cSrcweir 
1220cdf0e10cSrcweir     sal_Bool bCopyTo = sal_False;
1221cdf0e10cSrcweir     SfxItemSet *pMedSet = rMedium.GetItemSet();
1222cdf0e10cSrcweir     if( pMedSet )
1223cdf0e10cSrcweir     {
1224cdf0e10cSrcweir         SFX_ITEMSET_ARG( pMedSet, pSaveToItem, SfxBoolItem, SID_SAVETO, sal_False );
1225cdf0e10cSrcweir         bCopyTo =   GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ||
1226cdf0e10cSrcweir                     (pSaveToItem && pSaveToItem->GetValue());
1227cdf0e10cSrcweir     }
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir     // use UCB for case sensitive/insensitive file name comparison
1230cdf0e10cSrcweir     if ( pMedium
1231cdf0e10cSrcweir       && pMedium->GetName().CompareIgnoreCaseToAscii( "private:stream", 14 ) != COMPARE_EQUAL
1232cdf0e10cSrcweir       && rMedium.GetName().CompareIgnoreCaseToAscii( "private:stream", 14 ) != COMPARE_EQUAL
1233cdf0e10cSrcweir       && ::utl::UCBContentHelper::EqualURLs( pMedium->GetName(), rMedium.GetName() ) )
1234cdf0e10cSrcweir     {
1235cdf0e10cSrcweir         bStoreToSameLocation = sal_True;
1236cdf0e10cSrcweir         AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Save" ) ) );
1237cdf0e10cSrcweir 
1238cdf0e10cSrcweir         if ( pMedium->DocNeedsFileDateCheck() )
1239cdf0e10cSrcweir             rMedium.CheckFileDate( pMedium->GetInitFileDate( sal_False ) );
1240cdf0e10cSrcweir 
1241cdf0e10cSrcweir         if ( bCopyTo && GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
1242cdf0e10cSrcweir         {
1243cdf0e10cSrcweir             // export to the same location is vorbidden
1244cdf0e10cSrcweir             SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
1245cdf0e10cSrcweir         }
1246cdf0e10cSrcweir         else
1247cdf0e10cSrcweir         {
1248cdf0e10cSrcweir             // before we overwrite the original file, we will make a backup if there is a demand for that
1249cdf0e10cSrcweir             // if the backup is not created here it will be created internally and will be removed in case of successful saving
1250cdf0e10cSrcweir             const sal_Bool bDoBackup = SvtSaveOptions().IsBackup();
1251cdf0e10cSrcweir             if ( bDoBackup )
1252cdf0e10cSrcweir             {
1253cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "DoBackup" ) ) );
1254cdf0e10cSrcweir                 rMedium.DoBackup_Impl();
1255cdf0e10cSrcweir                 if ( rMedium.GetError() )
1256cdf0e10cSrcweir                 {
1257cdf0e10cSrcweir                     SetError( rMedium.GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
1258cdf0e10cSrcweir                     rMedium.ResetError();
1259cdf0e10cSrcweir                 }
1260cdf0e10cSrcweir             }
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir             if ( bStorageBasedSource && bStorageBasedTarget )
1263cdf0e10cSrcweir             {
1264cdf0e10cSrcweir                 // The active storage must be switched. The simple saving is not enough.
1265cdf0e10cSrcweir                 // The problem is that the target medium contains target MediaDescriptor.
1266cdf0e10cSrcweir 
1267cdf0e10cSrcweir                     // In future the switch of the persistance could be done on stream level:
1268cdf0e10cSrcweir                     // a new wrapper service will be implemented that allows to exchange
1269cdf0e10cSrcweir                     // persistance on the fly. So the real persistance will be set
1270cdf0e10cSrcweir                     // to that stream only after successful commit of the storage.
1271cdf0e10cSrcweir                     // TODO/LATER:
1272cdf0e10cSrcweir                     // create wrapper stream based on the URL
1273cdf0e10cSrcweir                     // create a new storage based on this stream
1274cdf0e10cSrcweir                     // store to this new storage
1275cdf0e10cSrcweir                     // commit the new storage
1276cdf0e10cSrcweir                     // call saveCompleted based with this new storage ( get rid of old storage and "frees" URL )
1277cdf0e10cSrcweir                     // commit the wrapper stream ( the stream will connect the URL only on commit, after that it will hold it )
1278cdf0e10cSrcweir                     // if the last step is failed the stream should stay to be transacted and should be commited on any flush
1279cdf0e10cSrcweir                     // so we can forget the stream in any way and the next storage commit will flush it
1280cdf0e10cSrcweir 
1281cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Save: Own to Own" ) ) );
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir                 bNeedsDisconnectionOnFail = DisconnectStorage_Impl(
1284cdf0e10cSrcweir                     *pMedium, rMedium );
1285cdf0e10cSrcweir                 if ( bNeedsDisconnectionOnFail
1286cdf0e10cSrcweir                   || ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
1287cdf0e10cSrcweir                 {
1288cdf0e10cSrcweir                     pMedium->CloseAndRelease();
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir                     // TODO/LATER: for now the medium must be closed since it can already contain streams from old medium
1291cdf0e10cSrcweir                     //             in future those streams should not be copied in case a valid target url is provided,
1292cdf0e10cSrcweir                     //             if the url is not provided ( means the document is based on a stream ) this code is not
1293cdf0e10cSrcweir                     //             reachable.
1294cdf0e10cSrcweir                     rMedium.CloseAndRelease();
1295cdf0e10cSrcweir                     rMedium.GetOutputStorage();
1296cdf0e10cSrcweir                 }
1297cdf0e10cSrcweir             }
1298cdf0e10cSrcweir             else if ( !bStorageBasedSource && !bStorageBasedTarget )
1299cdf0e10cSrcweir             {
1300cdf0e10cSrcweir                 // the source and the target formats are alien
1301cdf0e10cSrcweir                 // just disconnect the stream from the source format
1302cdf0e10cSrcweir                 // so that the target medium can use it
1303cdf0e10cSrcweir 
1304cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Save: Alien to Alien" ) ) );
1305cdf0e10cSrcweir 
1306cdf0e10cSrcweir                 pMedium->CloseAndRelease();
1307cdf0e10cSrcweir                 rMedium.CloseAndRelease();
1308cdf0e10cSrcweir                 rMedium.CreateTempFileNoCopy();
1309cdf0e10cSrcweir                 rMedium.GetOutStream();
1310cdf0e10cSrcweir             }
1311cdf0e10cSrcweir             else if ( !bStorageBasedSource && bStorageBasedTarget )
1312cdf0e10cSrcweir             {
1313cdf0e10cSrcweir                 // the source format is an alien one but the target
1314cdf0e10cSrcweir                 // format is an own one so just disconnect the source
1315cdf0e10cSrcweir                 // medium
1316cdf0e10cSrcweir 
1317cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Save: Alien to Own" ) ) );
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir                 pMedium->CloseAndRelease();
1320cdf0e10cSrcweir                 rMedium.CloseAndRelease();
1321cdf0e10cSrcweir                 rMedium.GetOutputStorage();
1322cdf0e10cSrcweir             }
1323cdf0e10cSrcweir             else // means if ( bStorageBasedSource && !bStorageBasedTarget )
1324cdf0e10cSrcweir             {
1325cdf0e10cSrcweir                 // the source format is an own one but the target is
1326cdf0e10cSrcweir                 // an alien format, just connect the source to temporary
1327cdf0e10cSrcweir                 // storage
1328cdf0e10cSrcweir 
1329cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Save: Own to Alien" ) ) );
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir                 bNeedsDisconnectionOnFail = DisconnectStorage_Impl(
1332cdf0e10cSrcweir                     *pMedium, rMedium );
1333cdf0e10cSrcweir                 if ( bNeedsDisconnectionOnFail
1334cdf0e10cSrcweir                   || ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
1335cdf0e10cSrcweir                 {
1336cdf0e10cSrcweir                     pMedium->CloseAndRelease();
1337cdf0e10cSrcweir                     rMedium.CloseAndRelease();
1338cdf0e10cSrcweir                     rMedium.CreateTempFileNoCopy();
1339cdf0e10cSrcweir                     rMedium.GetOutStream();
1340cdf0e10cSrcweir                 }
1341cdf0e10cSrcweir             }
1342cdf0e10cSrcweir         }
1343cdf0e10cSrcweir     }
1344cdf0e10cSrcweir     else
1345cdf0e10cSrcweir     {
1346cdf0e10cSrcweir         // This is SaveAs or export action, prepare the target medium
1347cdf0e10cSrcweir         // the alien filters still might write directly to the file, that is of course a bug,
1348cdf0e10cSrcweir         // but for now the framework has to be ready for it
1349cdf0e10cSrcweir         // TODO/LATER: let the medium be prepared for alien formats as well
1350cdf0e10cSrcweir 
1351cdf0e10cSrcweir         AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "SaveAs/Export" ) ) );
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir         rMedium.CloseAndRelease();
1354cdf0e10cSrcweir         if ( bStorageBasedTarget )
1355cdf0e10cSrcweir         {
1356cdf0e10cSrcweir             rMedium.GetOutputStorage();
1357cdf0e10cSrcweir         }
1358cdf0e10cSrcweir     }
1359cdf0e10cSrcweir 
1360cdf0e10cSrcweir     // TODO/LATER: error handling
1361cdf0e10cSrcweir     if( rMedium.GetErrorCode() || pMedium->GetErrorCode() || GetErrorCode() )
1362cdf0e10cSrcweir         return sal_False;
1363cdf0e10cSrcweir 
1364cdf0e10cSrcweir     AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Locking" ) ) );
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir     rMedium.LockOrigFileOnDemand( sal_False, sal_False );
1367cdf0e10cSrcweir 
1368cdf0e10cSrcweir     if ( bStorageBasedTarget )
1369cdf0e10cSrcweir     {
1370cdf0e10cSrcweir         if ( rMedium.GetErrorCode() )
1371cdf0e10cSrcweir             return sal_False;
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir         // If the filter is a "cross export" filter ( f.e. a filter for exporting an impress document from
1374cdf0e10cSrcweir         // a draw document ), the ClassId of the destination storage is different from the ClassId of this
1375cdf0e10cSrcweir         // document. It can be retrieved from the default filter for the desired target format
1376cdf0e10cSrcweir         long nFormat = rMedium.GetFilter()->GetFormat();
1377cdf0e10cSrcweir         SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
1378cdf0e10cSrcweir         const SfxFilter *pFilt = rMatcher.GetFilter4ClipBoardId( nFormat );
1379cdf0e10cSrcweir         if ( pFilt )
1380cdf0e10cSrcweir         {
1381cdf0e10cSrcweir             if ( pFilt->GetServiceName() != rMedium.GetFilter()->GetServiceName() )
1382cdf0e10cSrcweir             {
1383cdf0e10cSrcweir                 datatransfer::DataFlavor aDataFlavor;
1384cdf0e10cSrcweir                 SotExchange::GetFormatDataFlavor( nFormat, aDataFlavor );
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir                 try
1387cdf0e10cSrcweir                 {
1388cdf0e10cSrcweir                     uno::Reference< beans::XPropertySet > xProps( rMedium.GetStorage(), uno::UNO_QUERY );
1389cdf0e10cSrcweir                     DBG_ASSERT( xProps.is(), "The storage implementation must implement XPropertySet!" );
1390cdf0e10cSrcweir                     if ( !xProps.is() )
1391cdf0e10cSrcweir                         throw uno::RuntimeException();
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir                     xProps->setPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ),
1394cdf0e10cSrcweir                                             uno::makeAny( aDataFlavor.MimeType ) );
1395cdf0e10cSrcweir                 }
1396cdf0e10cSrcweir                 catch( uno::Exception& )
1397cdf0e10cSrcweir                 {
1398cdf0e10cSrcweir                 }
1399cdf0e10cSrcweir             }
1400cdf0e10cSrcweir         }
1401cdf0e10cSrcweir     }
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir     // TODO/LATER: error handling
1404cdf0e10cSrcweir     if( rMedium.GetErrorCode() || pMedium->GetErrorCode() || GetErrorCode() )
1405cdf0e10cSrcweir         return sal_False;
1406cdf0e10cSrcweir 
1407cdf0e10cSrcweir     sal_Bool bOldStat = pImp->bForbidReload;
1408cdf0e10cSrcweir     pImp->bForbidReload = sal_True;
1409cdf0e10cSrcweir 
1410cdf0e10cSrcweir     // lock user interface while saving the document
1411cdf0e10cSrcweir     Lock_Impl( this, sal_True );
1412cdf0e10cSrcweir 
1413cdf0e10cSrcweir     sal_Bool bOk = sal_False;
1414cdf0e10cSrcweir     // TODO/LATER: get rid of bOk
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir     if( bOwnTarget && !( pFilter->GetFilterFlags() & SFX_FILTER_STARONEFILTER ) )
1417cdf0e10cSrcweir     {
1418cdf0e10cSrcweir         AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing in own format." ) ) );
1419cdf0e10cSrcweir         uno::Reference< embed::XStorage > xMedStorage = rMedium.GetStorage();
1420cdf0e10cSrcweir         if ( !xMedStorage.is() )
1421cdf0e10cSrcweir         {
1422cdf0e10cSrcweir             // no saving without storage, unlock UI and return
1423cdf0e10cSrcweir             Lock_Impl( this, sal_False );
1424cdf0e10cSrcweir             pImp->bForbidReload = bOldStat;
1425cdf0e10cSrcweir             AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed, still no error set." ) ) );
1426cdf0e10cSrcweir             return sal_False;
1427cdf0e10cSrcweir         }
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir         // transfer password from the parameters to the storage
1430cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aEncryptionData;
1431cdf0e10cSrcweir         sal_Bool bPasswdProvided = sal_False;
1432cdf0e10cSrcweir         if ( GetEncryptionData_Impl( rMedium.GetItemSet(), aEncryptionData ) )
1433cdf0e10cSrcweir         {
1434cdf0e10cSrcweir             bPasswdProvided = sal_True;
1435cdf0e10cSrcweir             try {
1436cdf0e10cSrcweir                 ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( xMedStorage, aEncryptionData );
1437cdf0e10cSrcweir                 bOk = sal_True;
1438cdf0e10cSrcweir             }
1439cdf0e10cSrcweir             catch( uno::Exception& )
1440cdf0e10cSrcweir             {
1441cdf0e10cSrcweir                 DBG_ERROR( "Setting of common encryption key failed!" );
1442cdf0e10cSrcweir                 SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
1443cdf0e10cSrcweir             }
1444cdf0e10cSrcweir         }
1445cdf0e10cSrcweir         else
1446cdf0e10cSrcweir             bOk = sal_True;
1447cdf0e10cSrcweir 
1448cdf0e10cSrcweir         pFilter = rMedium.GetFilter();
1449cdf0e10cSrcweir 
1450cdf0e10cSrcweir         const SfxStringItem *pVersionItem = pSet ? (const SfxStringItem*)
1451cdf0e10cSrcweir                 SfxRequest::GetItem( pSet, SID_DOCINFO_COMMENTS, sal_False, TYPE(SfxStringItem) ) : NULL;
1452cdf0e10cSrcweir         ::rtl::OUString aTmpVersionURL;
1453cdf0e10cSrcweir 
1454cdf0e10cSrcweir         if ( bOk )
1455cdf0e10cSrcweir         {
1456cdf0e10cSrcweir             bOk = sal_False;
1457cdf0e10cSrcweir             // currently the case that the storage is the same should be impossible
1458cdf0e10cSrcweir             if ( xMedStorage == GetStorage() )
1459cdf0e10cSrcweir             {
1460cdf0e10cSrcweir                 OSL_ENSURE( !pVersionItem, "This scenario is impossible currently!\n" );
1461cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Should be impossible." ) ) );
1462cdf0e10cSrcweir                 // usual save procedure
1463cdf0e10cSrcweir                 bOk = Save();
1464cdf0e10cSrcweir             }
1465cdf0e10cSrcweir             else
1466cdf0e10cSrcweir             {
1467cdf0e10cSrcweir                 // save to target
1468cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Save as own format." ) ) );
1469cdf0e10cSrcweir                 bOk = SaveAsOwnFormat( rMedium );
1470cdf0e10cSrcweir                 if ( bOk && pVersionItem )
1471cdf0e10cSrcweir                 {
1472cdf0e10cSrcweir                     AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "pVersionItem != NULL" ) ) );
1473cdf0e10cSrcweir                     aTmpVersionURL = CreateTempCopyOfStorage_Impl( xMedStorage );
1474cdf0e10cSrcweir                     bOk = ( aTmpVersionURL.getLength() > 0 );
1475cdf0e10cSrcweir                 }
1476cdf0e10cSrcweir             }
1477cdf0e10cSrcweir         }
1478cdf0e10cSrcweir 
1479cdf0e10cSrcweir 
1480cdf0e10cSrcweir         if ( bOk && GetCreateMode() != SFX_CREATE_MODE_EMBEDDED && !bPasswdProvided )
1481cdf0e10cSrcweir         {
1482cdf0e10cSrcweir             // store the thumbnail representation image
1483cdf0e10cSrcweir             // the thumbnail is not stored in case of encrypted document
1484cdf0e10cSrcweir             AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Thumbnail creation." ) ) );
1485cdf0e10cSrcweir             if ( !GenerateAndStoreThumbnail( bPasswdProvided,
1486cdf0e10cSrcweir                                             sal_False,
1487cdf0e10cSrcweir                                             pFilter->IsOwnTemplateFormat(),
1488cdf0e10cSrcweir                                             xMedStorage ) )
1489cdf0e10cSrcweir             {
1490cdf0e10cSrcweir                 // TODO: error handling
1491cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "Couldn't store thumbnail representation!" );
1492cdf0e10cSrcweir             }
1493cdf0e10cSrcweir         }
1494cdf0e10cSrcweir 
1495cdf0e10cSrcweir         if ( bOk )
1496cdf0e10cSrcweir         {
1497cdf0e10cSrcweir             if ( pImp->bIsSaving || pImp->bPreserveVersions )
1498cdf0e10cSrcweir             {
1499cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Preserve versions." ) ) );
1500cdf0e10cSrcweir                 try
1501cdf0e10cSrcweir                 {
1502cdf0e10cSrcweir                     Sequence < util::RevisionTag > aVersions = rMedium.GetVersionList();
1503cdf0e10cSrcweir                     if ( aVersions.getLength() )
1504cdf0e10cSrcweir                     {
1505cdf0e10cSrcweir                         // copy the version streams
1506cdf0e10cSrcweir                         ::rtl::OUString aVersionsName( RTL_CONSTASCII_USTRINGPARAM( "Versions" ) );
1507cdf0e10cSrcweir                         uno::Reference< embed::XStorage > xNewVerStor = xMedStorage->openStorageElement(
1508cdf0e10cSrcweir                                                         aVersionsName,
1509cdf0e10cSrcweir                                                         embed::ElementModes::READWRITE );
1510cdf0e10cSrcweir                         uno::Reference< embed::XStorage > xOldVerStor = GetStorage()->openStorageElement(
1511cdf0e10cSrcweir                                                         aVersionsName,
1512cdf0e10cSrcweir                                                         embed::ElementModes::READ );
1513cdf0e10cSrcweir                         if ( !xNewVerStor.is() || !xOldVerStor.is() )
1514cdf0e10cSrcweir                             throw uno::RuntimeException();
1515cdf0e10cSrcweir 
1516cdf0e10cSrcweir                         for ( sal_Int32 n=0; n<aVersions.getLength(); n++ )
1517cdf0e10cSrcweir                         {
1518cdf0e10cSrcweir                             if ( xOldVerStor->hasByName( aVersions[n].Identifier ) )
1519cdf0e10cSrcweir                                 xOldVerStor->copyElementTo( aVersions[n].Identifier, xNewVerStor, aVersions[n].Identifier );
1520cdf0e10cSrcweir                         }
1521cdf0e10cSrcweir 
1522cdf0e10cSrcweir                         uno::Reference< embed::XTransactedObject > xTransact( xNewVerStor, uno::UNO_QUERY );
1523cdf0e10cSrcweir                         if ( xTransact.is() )
1524cdf0e10cSrcweir                             xTransact->commit();
1525cdf0e10cSrcweir                     }
1526cdf0e10cSrcweir                 }
1527cdf0e10cSrcweir                 catch( uno::Exception& )
1528cdf0e10cSrcweir                 {
1529cdf0e10cSrcweir                     AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Preserve versions has failed." ) ) );
1530cdf0e10cSrcweir                     DBG_ERROR( "Couldn't copy versions!\n" );
1531cdf0e10cSrcweir                     bOk = sal_False;
1532cdf0e10cSrcweir                     // TODO/LATER: a specific error could be set
1533cdf0e10cSrcweir                 }
1534cdf0e10cSrcweir             }
1535cdf0e10cSrcweir 
1536cdf0e10cSrcweir             if ( bOk && pVersionItem )
1537cdf0e10cSrcweir             {
1538cdf0e10cSrcweir                 // store a version also
1539cdf0e10cSrcweir                 const SfxStringItem *pAuthorItem = pSet ? (const SfxStringItem*)
1540cdf0e10cSrcweir                     SfxRequest::GetItem( pSet, SID_DOCINFO_AUTHOR, sal_False, TYPE(SfxStringItem) ) : NULL;
1541cdf0e10cSrcweir 
1542cdf0e10cSrcweir                 // version comment
1543cdf0e10cSrcweir                 util::RevisionTag aInfo;
1544cdf0e10cSrcweir                 aInfo.Comment = pVersionItem->GetValue();
1545cdf0e10cSrcweir 
1546cdf0e10cSrcweir                 // version author
1547cdf0e10cSrcweir                 String aAuthor;
1548cdf0e10cSrcweir                 if ( pAuthorItem )
1549cdf0e10cSrcweir                     aInfo.Author = pAuthorItem->GetValue();
1550cdf0e10cSrcweir                 else
1551cdf0e10cSrcweir                     // if not transferred as a parameter, get it from user settings
1552cdf0e10cSrcweir                     aInfo.Author = SvtUserOptions().GetFullName();
1553cdf0e10cSrcweir 
1554cdf0e10cSrcweir                 DateTime aTime;
1555cdf0e10cSrcweir                 aInfo.TimeStamp.Day = aTime.GetDay();
1556cdf0e10cSrcweir                 aInfo.TimeStamp.Month = aTime.GetMonth();
1557cdf0e10cSrcweir                 aInfo.TimeStamp.Year = aTime.GetYear();
1558cdf0e10cSrcweir                 aInfo.TimeStamp.Hours = aTime.GetHour();
1559cdf0e10cSrcweir                 aInfo.TimeStamp.Minutes = aTime.GetMin();
1560cdf0e10cSrcweir                 aInfo.TimeStamp.Seconds = aTime.GetSec();
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir                 if ( bOk )
1563cdf0e10cSrcweir                 {
1564cdf0e10cSrcweir                     // add new version information into the versionlist and save the versionlist
1565cdf0e10cSrcweir                     // the version list must have been transferred from the "old" medium before
1566cdf0e10cSrcweir                     rMedium.AddVersion_Impl( aInfo );
1567cdf0e10cSrcweir                     rMedium.SaveVersionList_Impl( sal_True );
1568cdf0e10cSrcweir                     bOk = PutURLContentsToVersionStream_Impl( aTmpVersionURL, xMedStorage, aInfo.Identifier );
1569cdf0e10cSrcweir                 }
1570cdf0e10cSrcweir             }
1571cdf0e10cSrcweir             else if ( bOk && ( pImp->bIsSaving || pImp->bPreserveVersions ) )
1572cdf0e10cSrcweir             {
1573cdf0e10cSrcweir                 rMedium.SaveVersionList_Impl( sal_True );
1574cdf0e10cSrcweir             }
1575cdf0e10cSrcweir         }
1576cdf0e10cSrcweir 
1577cdf0e10cSrcweir         if ( aTmpVersionURL.getLength() )
1578cdf0e10cSrcweir             ::utl::UCBContentHelper::Kill( aTmpVersionURL );
1579cdf0e10cSrcweir     }
1580cdf0e10cSrcweir     else
1581cdf0e10cSrcweir     {
1582cdf0e10cSrcweir         AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing in alien format." ) ) );
1583cdf0e10cSrcweir         // it's a "SaveAs" in an alien format
1584cdf0e10cSrcweir         if ( rMedium.GetFilter() && ( rMedium.GetFilter()->GetFilterFlags() & SFX_FILTER_STARONEFILTER ) )
1585cdf0e10cSrcweir             bOk = ExportTo( rMedium );
1586cdf0e10cSrcweir         else
1587cdf0e10cSrcweir             bOk = ConvertTo( rMedium );
1588cdf0e10cSrcweir 
1589cdf0e10cSrcweir         // after saving the document, the temporary object storage must be updated
1590cdf0e10cSrcweir         // if the old object storage was not a temporary one, it will be updated also, because it will be used
1591cdf0e10cSrcweir         // as a source for copying the objects into the new temporary storage that will be created below
1592cdf0e10cSrcweir         // updating means: all child objects must be stored into it
1593cdf0e10cSrcweir         // ( same as on loading, where these objects are copied to the temporary storage )
1594cdf0e10cSrcweir         // but don't commit these changes, because in the case when the old object storage is not a temporary one,
1595cdf0e10cSrcweir         // all changes will be written into the original file !
1596cdf0e10cSrcweir 
1597cdf0e10cSrcweir         if( bOk && !bCopyTo )
1598cdf0e10cSrcweir             // we also don't touch any graphical replacements here
1599cdf0e10cSrcweir             bOk = SaveChildren( sal_True );
1600cdf0e10cSrcweir     }
1601cdf0e10cSrcweir 
1602cdf0e10cSrcweir     if ( bOk )
1603cdf0e10cSrcweir     {
1604cdf0e10cSrcweir         // if ODF version of oasis format changes on saving the signature should not be preserved
1605cdf0e10cSrcweir         if ( bOk && bTryToPreserveScriptSignature && bNoPreserveForOasis )
1606cdf0e10cSrcweir             bTryToPreserveScriptSignature = ( SotStorage::GetVersion( rMedium.GetStorage() ) == SOFFICE_FILEFORMAT_60 );
1607cdf0e10cSrcweir 
1608cdf0e10cSrcweir         uno::Reference< security::XDocumentDigitalSignatures > xDDSigns;
1609cdf0e10cSrcweir         if ( bOk && bTryToPreserveScriptSignature )
1610cdf0e10cSrcweir         {
1611cdf0e10cSrcweir             AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Copying scripting signature." ) ) );
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir             // if the scripting code was not changed and it is signed the signature should be preserved
1614cdf0e10cSrcweir             // unfortunately at this point we have only information whether the basic code has changed or not
1615cdf0e10cSrcweir             // so the only way is to check the signature if the basic was not changed
1616cdf0e10cSrcweir             try
1617cdf0e10cSrcweir             {
1618cdf0e10cSrcweir                 // get the ODF version of the new medium
1619cdf0e10cSrcweir                 uno::Sequence< uno::Any > aArgs( 1 );
1620cdf0e10cSrcweir                 aArgs[0] <<= ::rtl::OUString();
1621cdf0e10cSrcweir                 try
1622cdf0e10cSrcweir                 {
1623cdf0e10cSrcweir                     uno::Reference < beans::XPropertySet > xPropSet( rMedium.GetStorage(), uno::UNO_QUERY_THROW );
1624cdf0e10cSrcweir                     aArgs[0] = xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) );
1625cdf0e10cSrcweir                 }
1626cdf0e10cSrcweir                 catch( uno::Exception& )
1627cdf0e10cSrcweir                 {
1628cdf0e10cSrcweir                 }
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir                 xDDSigns = uno::Reference< security::XDocumentDigitalSignatures >(
1631cdf0e10cSrcweir                     comphelper::getProcessServiceFactory()->createInstanceWithArguments(
1632cdf0e10cSrcweir                         rtl::OUString(
1633cdf0e10cSrcweir                             RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ),
1634cdf0e10cSrcweir                         aArgs ),
1635cdf0e10cSrcweir                     uno::UNO_QUERY_THROW );
1636cdf0e10cSrcweir 
1637cdf0e10cSrcweir                 ::rtl::OUString aScriptSignName = xDDSigns->getScriptingContentSignatureDefaultStreamName();
1638cdf0e10cSrcweir 
1639cdf0e10cSrcweir                 if ( aScriptSignName.getLength() )
1640cdf0e10cSrcweir                 {
1641cdf0e10cSrcweir                     pMedium->Close();
1642cdf0e10cSrcweir 
1643cdf0e10cSrcweir                     // target medium is still not commited, it should not be closed
1644cdf0e10cSrcweir                     // commit the package storage and close it, but leave the streams open
1645cdf0e10cSrcweir                     rMedium.StorageCommit_Impl();
1646cdf0e10cSrcweir                     rMedium.CloseStorage();
1647cdf0e10cSrcweir 
1648cdf0e10cSrcweir                     uno::Reference< embed::XStorage > xReadOrig = pMedium->GetZipStorageToSign_Impl();
1649cdf0e10cSrcweir                     if ( !xReadOrig.is() )
1650cdf0e10cSrcweir                         throw uno::RuntimeException();
1651cdf0e10cSrcweir                     uno::Reference< embed::XStorage > xMetaInf = xReadOrig->openStorageElement(
1652cdf0e10cSrcweir                                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ),
1653cdf0e10cSrcweir                                 embed::ElementModes::READ );
1654cdf0e10cSrcweir 
1655cdf0e10cSrcweir                     uno::Reference< embed::XStorage > xTarget = rMedium.GetZipStorageToSign_Impl( sal_False );
1656cdf0e10cSrcweir                     if ( !xTarget.is() )
1657cdf0e10cSrcweir                         throw uno::RuntimeException();
1658cdf0e10cSrcweir                     uno::Reference< embed::XStorage > xTargetMetaInf = xTarget->openStorageElement(
1659cdf0e10cSrcweir                                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ),
1660cdf0e10cSrcweir                                 embed::ElementModes::READWRITE );
1661cdf0e10cSrcweir 
1662cdf0e10cSrcweir                     if ( xMetaInf.is() && xTargetMetaInf.is() )
1663cdf0e10cSrcweir                     {
1664cdf0e10cSrcweir                         xMetaInf->copyElementTo( aScriptSignName, xTargetMetaInf, aScriptSignName );
1665cdf0e10cSrcweir 
1666cdf0e10cSrcweir                         uno::Reference< embed::XTransactedObject > xTransact( xTargetMetaInf, uno::UNO_QUERY );
1667cdf0e10cSrcweir                         if ( xTransact.is() )
1668cdf0e10cSrcweir                             xTransact->commit();
1669cdf0e10cSrcweir 
1670cdf0e10cSrcweir                         xTargetMetaInf->dispose();
1671cdf0e10cSrcweir 
1672cdf0e10cSrcweir                         // now check the copied signature
1673cdf0e10cSrcweir                         uno::Sequence< security::DocumentSignatureInformation > aInfos =
1674cdf0e10cSrcweir                             xDDSigns->verifyScriptingContentSignatures( xTarget,
1675cdf0e10cSrcweir                                                                         uno::Reference< io::XInputStream >() );
1676cdf0e10cSrcweir                         sal_uInt16 nState = ImplCheckSignaturesInformation( aInfos );
1677cdf0e10cSrcweir                         if ( nState == SIGNATURESTATE_SIGNATURES_OK || nState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED
1678cdf0e10cSrcweir                             || nState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK)
1679cdf0e10cSrcweir                         {
1680cdf0e10cSrcweir                             rMedium.SetCachedSignatureState_Impl( nState );
1681cdf0e10cSrcweir 
1682cdf0e10cSrcweir                             // commit the ZipStorage from target medium
1683cdf0e10cSrcweir                             xTransact.set( xTarget, uno::UNO_QUERY );
1684cdf0e10cSrcweir                             if ( xTransact.is() )
1685cdf0e10cSrcweir                                 xTransact->commit();
1686cdf0e10cSrcweir                         }
1687cdf0e10cSrcweir                         else
1688cdf0e10cSrcweir                         {
1689cdf0e10cSrcweir                             // it should not happen, the copies signature is invalid!
1690cdf0e10cSrcweir                             // throw the changes away
1691cdf0e10cSrcweir                             OSL_ASSERT( "An invalid signature was copied!" );
1692cdf0e10cSrcweir                         }
1693cdf0e10cSrcweir                     }
1694cdf0e10cSrcweir                 }
1695cdf0e10cSrcweir             }
1696cdf0e10cSrcweir             catch( uno::Exception& )
1697cdf0e10cSrcweir             {
1698cdf0e10cSrcweir             }
1699cdf0e10cSrcweir 
1700cdf0e10cSrcweir             pMedium->Close();
1701cdf0e10cSrcweir             rMedium.CloseZipStorage_Impl();
1702cdf0e10cSrcweir         }
1703cdf0e10cSrcweir 
1704cdf0e10cSrcweir         AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Medium commit." ) ) );
1705cdf0e10cSrcweir 
1706cdf0e10cSrcweir         // transfer data to its destinated location
1707cdf0e10cSrcweir         // the medium commits the storage or the stream it is based on
1708cdf0e10cSrcweir         RegisterTransfer( rMedium );
1709cdf0e10cSrcweir         bOk = rMedium.Commit();
1710cdf0e10cSrcweir 
1711cdf0e10cSrcweir         if ( bOk )
1712cdf0e10cSrcweir         {
1713cdf0e10cSrcweir             AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing is successful." ) ) );
1714cdf0e10cSrcweir 
1715cdf0e10cSrcweir             // if the target medium is an alien format and the "old" medium was an own format and the "old" medium
1716cdf0e10cSrcweir             // has a name, the object storage must be exchanged, because now we need a new temporary storage
1717cdf0e10cSrcweir             // as object storage
1718cdf0e10cSrcweir             if ( !bCopyTo && bStorageBasedSource && !bStorageBasedTarget )
1719cdf0e10cSrcweir             {
1720cdf0e10cSrcweir                 if ( bStoreToSameLocation )
1721cdf0e10cSrcweir                 {
1722cdf0e10cSrcweir                     // if the old medium already disconnected from document storage, the storage still must
1723cdf0e10cSrcweir                     // be switched if backup file is used
1724cdf0e10cSrcweir                     if ( bNeedsDisconnectionOnFail )
1725cdf0e10cSrcweir                         ConnectTmpStorage_Impl( pImp->m_xDocStorage, NULL );
1726cdf0e10cSrcweir                 }
1727cdf0e10cSrcweir                 else if ( pMedium->GetName().Len()
1728cdf0e10cSrcweir                   || ( pMedium->HasStorage_Impl() && pMedium->WillDisposeStorageOnClose_Impl() ) )
1729cdf0e10cSrcweir                 {
1730cdf0e10cSrcweir                     OSL_ENSURE( pMedium->GetName().Len(), "Fallback is used, the medium without name should not dispose the storage!\n" );
1731cdf0e10cSrcweir                     // copy storage of old medium to new temporary storage and take this over
1732cdf0e10cSrcweir                     if( !ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
1733cdf0e10cSrcweir                     {
1734cdf0e10cSrcweir                         AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Process after storing has failed." ) ) );
1735cdf0e10cSrcweir                         bOk = sal_False;
1736cdf0e10cSrcweir                     }
1737cdf0e10cSrcweir                 }
1738cdf0e10cSrcweir             }
1739cdf0e10cSrcweir         }
1740cdf0e10cSrcweir         else
1741cdf0e10cSrcweir         {
1742cdf0e10cSrcweir             AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing has failed." ) ) );
1743cdf0e10cSrcweir 
1744cdf0e10cSrcweir             // in case the document storage was connected to backup temporarely it must be disconnected now
1745cdf0e10cSrcweir             if ( bNeedsDisconnectionOnFail )
1746cdf0e10cSrcweir                 ConnectTmpStorage_Impl( pImp->m_xDocStorage, NULL );
1747cdf0e10cSrcweir         }
1748cdf0e10cSrcweir     }
1749cdf0e10cSrcweir 
1750cdf0e10cSrcweir     // unlock user interface
1751cdf0e10cSrcweir     Lock_Impl( this, sal_False );
1752cdf0e10cSrcweir     pImp->bForbidReload = bOldStat;
1753cdf0e10cSrcweir 
1754cdf0e10cSrcweir     if ( bOk )
1755cdf0e10cSrcweir     {
1756cdf0e10cSrcweir         try
1757cdf0e10cSrcweir         {
1758cdf0e10cSrcweir             ::ucbhelper::Content aContent( rMedium.GetName(), com::sun::star::uno::Reference < XCommandEnvironment >() );
1759cdf0e10cSrcweir             com::sun::star::uno::Reference < XPropertySetInfo > xProps = aContent.getProperties();
1760cdf0e10cSrcweir             if ( xProps.is() )
1761cdf0e10cSrcweir             {
1762cdf0e10cSrcweir                 ::rtl::OUString aAuthor( RTL_CONSTASCII_USTRINGPARAM("Author") );
1763cdf0e10cSrcweir                 ::rtl::OUString aKeywords( RTL_CONSTASCII_USTRINGPARAM("Keywords") );
1764cdf0e10cSrcweir                 ::rtl::OUString aSubject( RTL_CONSTASCII_USTRINGPARAM("Subject") );
1765cdf0e10cSrcweir                 Any aAny;
1766cdf0e10cSrcweir 
1767cdf0e10cSrcweir                 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
1768cdf0e10cSrcweir                     GetModel(), uno::UNO_QUERY_THROW);
1769cdf0e10cSrcweir                 uno::Reference<document::XDocumentProperties> xDocProps
1770cdf0e10cSrcweir                     = xDPS->getDocumentProperties();
1771cdf0e10cSrcweir 
1772cdf0e10cSrcweir                 if ( xProps->hasPropertyByName( aAuthor ) )
1773cdf0e10cSrcweir                 {
1774cdf0e10cSrcweir                     aAny <<= xDocProps->getAuthor();
1775cdf0e10cSrcweir                     aContent.setPropertyValue( aAuthor, aAny );
1776cdf0e10cSrcweir                 }
1777cdf0e10cSrcweir                 if ( xProps->hasPropertyByName( aKeywords ) )
1778cdf0e10cSrcweir                 {
1779cdf0e10cSrcweir                     aAny <<= ::comphelper::string::convertCommaSeparated(
1780cdf0e10cSrcweir                                 xDocProps->getKeywords());
1781cdf0e10cSrcweir                     aContent.setPropertyValue( aKeywords, aAny );
1782cdf0e10cSrcweir                 }
1783cdf0e10cSrcweir                 if ( xProps->hasPropertyByName( aSubject ) )
1784cdf0e10cSrcweir                 {
1785cdf0e10cSrcweir                     aAny <<= xDocProps->getSubject();
1786cdf0e10cSrcweir                     aContent.setPropertyValue( aSubject, aAny );
1787cdf0e10cSrcweir                 }
1788cdf0e10cSrcweir             }
1789cdf0e10cSrcweir         }
1790cdf0e10cSrcweir         catch( Exception& )
1791cdf0e10cSrcweir         {
1792cdf0e10cSrcweir         }
1793cdf0e10cSrcweir 
1794cdf0e10cSrcweir #ifdef OS2
1795cdf0e10cSrcweir         {
1796cdf0e10cSrcweir #define CHAR_POINTER(THE_OUSTRING) ::rtl::OUStringToOString (THE_OUSTRING, RTL_TEXTENCODING_UTF8).pData->buffer
1797cdf0e10cSrcweir             // Header for a single-valued ASCII EA data item
1798cdf0e10cSrcweir             typedef struct _EA_ASCII_header {
1799cdf0e10cSrcweir             sal_uInt16      usAttr;                 /* value: EAT_ASCII                        */
1800cdf0e10cSrcweir             sal_uInt16      usLen;                  /* length of data                          */
1801cdf0e10cSrcweir             CHAR        szType[_MAX_PATH];      /* ASCII data fits in here ...             */
1802cdf0e10cSrcweir             } EA_ASCII_HEADER;
1803cdf0e10cSrcweir             char   filePath[_MAX_PATH];
1804cdf0e10cSrcweir             char   fileExt[_MAX_PATH];
1805cdf0e10cSrcweir             char   docType[_MAX_PATH];
1806cdf0e10cSrcweir             int    rc;
1807cdf0e10cSrcweir             oslFileError eRet;
1808cdf0e10cSrcweir             ::rtl::OUString aSystemFileURL;
1809cdf0e10cSrcweir             const ::rtl::OUString aFileURL = rMedium.GetName();
1810cdf0e10cSrcweir             // close medium
1811cdf0e10cSrcweir             rMedium.Close();
1812cdf0e10cSrcweir 
1813cdf0e10cSrcweir             // convert file URL to system path
1814cdf0e10cSrcweir             if (osl::FileBase::getSystemPathFromFileURL( aFileURL, aSystemFileURL) == osl::FileBase::E_None) {
1815cdf0e10cSrcweir             EA_ASCII_HEADER eaAscii;
1816cdf0e10cSrcweir             struct _ea eaType;
1817cdf0e10cSrcweir             strcpy( filePath, CHAR_POINTER( aSystemFileURL));
1818cdf0e10cSrcweir             strcpy( docType, CHAR_POINTER( rMedium.GetFilter()->GetServiceName()));
1819cdf0e10cSrcweir #if OSL_DEBUG_LEVEL>1
1820cdf0e10cSrcweir             printf( "file name: %s\n", filePath);
1821cdf0e10cSrcweir             printf( "filter name: %s\n", CHAR_POINTER(rMedium.GetFilter()->GetFilterName()));
1822cdf0e10cSrcweir             printf( "service name: %s\n", docType);
1823cdf0e10cSrcweir #endif
1824cdf0e10cSrcweir             // initialize OS/2 EA data structure
1825cdf0e10cSrcweir             eaAscii.usAttr = EAT_ASCII;
1826cdf0e10cSrcweir             _splitpath ( filePath, NULL, NULL, NULL, fileExt);
1827cdf0e10cSrcweir             if (!stricmp( fileExt, ".pdf"))
1828cdf0e10cSrcweir                 strcpy( eaAscii.szType, "Acrobat Document");
1829cdf0e10cSrcweir             else if (!strcmp( docType, "com.sun.star.text.TextDocument"))
1830cdf0e10cSrcweir                 strcpy( eaAscii.szType, "OpenOfficeOrg Writer Document");
1831cdf0e10cSrcweir             else if (!strcmp( docType, "com.sun.star.sheet.SpreadsheetDocument"))
1832cdf0e10cSrcweir                 strcpy( eaAscii.szType, "OpenOfficeOrg Calc Document");
1833cdf0e10cSrcweir             else if (!strcmp( docType, "com.sun.star.presentation.PresentationDocument"))
1834cdf0e10cSrcweir                 strcpy( eaAscii.szType, "OpenOfficeOrg Impress Document");
1835cdf0e10cSrcweir             else if (!strcmp( docType, "com.sun.star.drawing.DrawingDocument"))
1836cdf0e10cSrcweir                 strcpy( eaAscii.szType, "OpenOfficeOrg Draw Document");
1837cdf0e10cSrcweir             else
1838cdf0e10cSrcweir                 strcpy( eaAscii.szType, "OpenOfficeOrg Document");
1839cdf0e10cSrcweir             eaAscii.usLen = strlen( eaAscii.szType);
1840cdf0e10cSrcweir             // fill libc EA data structure
1841cdf0e10cSrcweir             eaType.flags = 0;
1842cdf0e10cSrcweir             eaType.size = sizeof(sal_uInt16)*2 + eaAscii.usLen;
1843cdf0e10cSrcweir             eaType.value = &eaAscii;
1844cdf0e10cSrcweir             // put EA to file
1845cdf0e10cSrcweir             rc = _ea_put( &eaType, filePath, 0, ".TYPE");
1846cdf0e10cSrcweir #if OSL_DEBUG_LEVEL>1
1847cdf0e10cSrcweir             printf( "ea name: %s, rc %d, errno %d\n", eaAscii.szType, rc, errno);
1848cdf0e10cSrcweir #endif
1849cdf0e10cSrcweir         }
1850cdf0e10cSrcweir     }
1851cdf0e10cSrcweir #endif
1852cdf0e10cSrcweir 
1853cdf0e10cSrcweir     }
1854cdf0e10cSrcweir 
1855cdf0e10cSrcweir     return bOk;
1856cdf0e10cSrcweir }
1857cdf0e10cSrcweir 
1858cdf0e10cSrcweir //------------------------------------------------------------------------
DisconnectStorage_Impl(SfxMedium & rSrcMedium,SfxMedium & rTargetMedium)1859cdf0e10cSrcweir sal_Bool SfxObjectShell::DisconnectStorage_Impl( SfxMedium& rSrcMedium, SfxMedium& rTargetMedium )
1860cdf0e10cSrcweir {
1861cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::DisconnectStorage_Impl" );
1862cdf0e10cSrcweir 
1863cdf0e10cSrcweir     // this method disconnects the storage from source medium, and attaches it to the backup created by the target medium
1864cdf0e10cSrcweir 
1865cdf0e10cSrcweir     uno::Reference< embed::XStorage > xStorage = rSrcMedium.GetStorage();
1866cdf0e10cSrcweir 
1867cdf0e10cSrcweir     sal_Bool bResult = sal_False;
1868cdf0e10cSrcweir     if ( xStorage == pImp->m_xDocStorage )
1869cdf0e10cSrcweir     {
1870cdf0e10cSrcweir         try
1871cdf0e10cSrcweir         {
1872cdf0e10cSrcweir             uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY_THROW );
1873cdf0e10cSrcweir             ::rtl::OUString aBackupURL = rTargetMedium.GetBackup_Impl();
1874cdf0e10cSrcweir             if ( !aBackupURL.getLength() )
1875cdf0e10cSrcweir             {
1876cdf0e10cSrcweir                 // the backup could not be created, try to disconnect the storage and close the source SfxMedium
1877cdf0e10cSrcweir                 // in this case the optimization is not possible, connect storage to a temporary file
1878cdf0e10cSrcweir                 rTargetMedium.ResetError();
1879cdf0e10cSrcweir                 xOptStorage->writeAndAttachToStream( uno::Reference< io::XStream >() );
1880cdf0e10cSrcweir                 rSrcMedium.CanDisposeStorage_Impl( sal_False );
1881cdf0e10cSrcweir                 rSrcMedium.Close();
1882cdf0e10cSrcweir 
1883cdf0e10cSrcweir                 // now try to create the backup
1884cdf0e10cSrcweir                 rTargetMedium.GetBackup_Impl();
1885cdf0e10cSrcweir             }
1886cdf0e10cSrcweir             else
1887cdf0e10cSrcweir             {
1888cdf0e10cSrcweir                 // the following call will only compare stream sizes
1889cdf0e10cSrcweir                 // TODO/LATER: this is a very risky part, since if the URL contents are different from the storage
1890cdf0e10cSrcweir                 // contents, the storag will be broken
1891cdf0e10cSrcweir                 xOptStorage->attachToURL( aBackupURL, sal_True );
1892cdf0e10cSrcweir 
1893cdf0e10cSrcweir                 // the storage is successfuly attached to backup, thus it it owned by the document not by the medium
1894cdf0e10cSrcweir                 rSrcMedium.CanDisposeStorage_Impl( sal_False );
1895cdf0e10cSrcweir                 bResult = sal_True;
1896cdf0e10cSrcweir             }
1897cdf0e10cSrcweir         }
1898cdf0e10cSrcweir         catch ( uno::Exception& )
1899cdf0e10cSrcweir         {}
1900cdf0e10cSrcweir     }
1901cdf0e10cSrcweir 
1902cdf0e10cSrcweir     OSL_ENSURE( bResult, "Storage disconnecting has failed - affects performance!" );
1903cdf0e10cSrcweir 
1904cdf0e10cSrcweir     return bResult;
1905cdf0e10cSrcweir }
1906cdf0e10cSrcweir 
1907cdf0e10cSrcweir //------------------------------------------------------------------------
1908cdf0e10cSrcweir 
ConnectTmpStorage_Impl(const uno::Reference<embed::XStorage> & xStorage,SfxMedium * pMediumArg)1909cdf0e10cSrcweir sal_Bool SfxObjectShell::ConnectTmpStorage_Impl(
1910cdf0e10cSrcweir     const uno::Reference< embed::XStorage >& xStorage,
1911cdf0e10cSrcweir     SfxMedium* pMediumArg )
1912cdf0e10cSrcweir 
1913cdf0e10cSrcweir /*   [Beschreibung]
1914cdf0e10cSrcweir 
1915cdf0e10cSrcweir      Arbeitet die Applikation auf einem temporaeren Storage,
1916cdf0e10cSrcweir      so darf der temporaere Storage nicht aus dem SaveCompleted
1917cdf0e10cSrcweir      genommen werden. Daher wird in diesem Fall schon hier an
1918cdf0e10cSrcweir      den neuen Storage connected. SaveCompleted tut dann nichts.
1919cdf0e10cSrcweir 
1920cdf0e10cSrcweir      */
1921cdf0e10cSrcweir 
1922cdf0e10cSrcweir {
1923cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::ConnectTmpStorage_Impl" );
1924cdf0e10cSrcweir 
1925cdf0e10cSrcweir     sal_Bool bResult = sal_False;
1926cdf0e10cSrcweir 
1927cdf0e10cSrcweir     if ( xStorage.is() )
1928cdf0e10cSrcweir     {
1929cdf0e10cSrcweir         try
1930cdf0e10cSrcweir         {
1931cdf0e10cSrcweir             // the empty argument means that the storage will create temporary stream itself
1932cdf0e10cSrcweir             uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY_THROW );
1933cdf0e10cSrcweir             xOptStorage->writeAndAttachToStream( uno::Reference< io::XStream >() );
1934cdf0e10cSrcweir 
1935cdf0e10cSrcweir             // the storage is successfuly disconnected from the original sources, thus the medium must not dispose it
1936cdf0e10cSrcweir             if ( pMediumArg )
1937cdf0e10cSrcweir                 pMediumArg->CanDisposeStorage_Impl( sal_False );
1938cdf0e10cSrcweir 
1939cdf0e10cSrcweir             bResult = sal_True;
1940cdf0e10cSrcweir         }
1941cdf0e10cSrcweir         catch( uno::Exception& )
1942cdf0e10cSrcweir         {
1943cdf0e10cSrcweir         }
1944cdf0e10cSrcweir 
1945cdf0e10cSrcweir         // if switching of the storage does not work for any reason ( nonroot storage for example ) use the old method
1946cdf0e10cSrcweir         if ( !bResult ) try
1947cdf0e10cSrcweir         {
1948cdf0e10cSrcweir             uno::Reference< embed::XStorage > xTmpStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
1949cdf0e10cSrcweir 
1950cdf0e10cSrcweir             DBG_ASSERT( xTmpStorage.is(), "If a storage can not be created an exception must be thrown!\n" );
1951cdf0e10cSrcweir             if ( !xTmpStorage.is() )
1952cdf0e10cSrcweir                 throw uno::RuntimeException();
1953cdf0e10cSrcweir 
1954cdf0e10cSrcweir             // TODO/LATER: may be it should be done in SwitchPersistence also
1955cdf0e10cSrcweir             // TODO/LATER: find faster way to copy storage; perhaps sharing with backup?!
1956cdf0e10cSrcweir             xStorage->copyToStorage( xTmpStorage );
1957cdf0e10cSrcweir             //CopyStoragesOfUnknownMediaType( xStorage, xTmpStorage );
1958cdf0e10cSrcweir             bResult = SaveCompleted( xTmpStorage );
1959cdf0e10cSrcweir 
1960cdf0e10cSrcweir             if ( bResult )
1961cdf0e10cSrcweir             {
1962cdf0e10cSrcweir                 pImp->pBasicManager->setStorage( xTmpStorage );
1963cdf0e10cSrcweir 
1964cdf0e10cSrcweir                 // Get rid of this workaround after issue i113914 is fixed
1965cdf0e10cSrcweir                 try
1966cdf0e10cSrcweir                 {
1967cdf0e10cSrcweir                     uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries( pImp->xBasicLibraries, uno::UNO_QUERY_THROW );
1968cdf0e10cSrcweir                     xBasicLibraries->setRootStorage( xTmpStorage );
1969cdf0e10cSrcweir                 }
1970cdf0e10cSrcweir                 catch( uno::Exception& )
1971cdf0e10cSrcweir                 {}
1972cdf0e10cSrcweir                 try
1973cdf0e10cSrcweir                 {
1974cdf0e10cSrcweir                     uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries( pImp->xDialogLibraries, uno::UNO_QUERY_THROW );
1975cdf0e10cSrcweir                     xDialogLibraries->setRootStorage( xTmpStorage );
1976cdf0e10cSrcweir                 }
1977cdf0e10cSrcweir                 catch( uno::Exception& )
1978cdf0e10cSrcweir                 {}
1979cdf0e10cSrcweir             }
1980cdf0e10cSrcweir         }
1981cdf0e10cSrcweir         catch( uno::Exception& )
1982cdf0e10cSrcweir         {}
1983cdf0e10cSrcweir 
1984cdf0e10cSrcweir         if ( !bResult )
1985cdf0e10cSrcweir         {
1986cdf0e10cSrcweir             // TODO/LATER: may need error code setting based on exception
1987cdf0e10cSrcweir             SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
1988cdf0e10cSrcweir         }
1989cdf0e10cSrcweir     }
1990cdf0e10cSrcweir 
1991cdf0e10cSrcweir     return bResult;
1992cdf0e10cSrcweir }
1993cdf0e10cSrcweir 
1994cdf0e10cSrcweir //-------------------------------------------------------------------------
1995cdf0e10cSrcweir 
DoSaveObjectAs(SfxMedium & rMedium,sal_Bool bCommit)1996cdf0e10cSrcweir sal_Bool SfxObjectShell::DoSaveObjectAs( SfxMedium& rMedium, sal_Bool bCommit )
1997cdf0e10cSrcweir {
1998cdf0e10cSrcweir     sal_Bool bOk = sal_False;
1999cdf0e10cSrcweir     {
2000cdf0e10cSrcweir         ModifyBlocker_Impl aBlock( this );
2001cdf0e10cSrcweir 
2002cdf0e10cSrcweir         uno::Reference < embed::XStorage > xNewStor = rMedium.GetStorage();
2003cdf0e10cSrcweir         if ( !xNewStor.is() )
2004cdf0e10cSrcweir             return sal_False;
2005cdf0e10cSrcweir 
2006cdf0e10cSrcweir         uno::Reference < beans::XPropertySet > xPropSet( xNewStor, uno::UNO_QUERY );
2007cdf0e10cSrcweir         if ( xPropSet.is() )
2008cdf0e10cSrcweir         {
2009cdf0e10cSrcweir             Any a = xPropSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) );
2010cdf0e10cSrcweir             ::rtl::OUString aMediaType;
2011cdf0e10cSrcweir             if ( !(a>>=aMediaType) || !aMediaType.getLength() )
2012cdf0e10cSrcweir             {
2013cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "The mediatype must be set already!\n" );
2014cdf0e10cSrcweir                 SetupStorage( xNewStor, SOFFICE_FILEFORMAT_CURRENT, sal_False );
2015cdf0e10cSrcweir             }
2016cdf0e10cSrcweir 
2017cdf0e10cSrcweir             pImp->bIsSaving = sal_False;
2018cdf0e10cSrcweir             bOk = SaveAsOwnFormat( rMedium );
2019cdf0e10cSrcweir 
2020cdf0e10cSrcweir             if ( bCommit )
2021cdf0e10cSrcweir             {
2022cdf0e10cSrcweir                 try {
2023cdf0e10cSrcweir                     uno::Reference< embed::XTransactedObject > xTransact( xNewStor, uno::UNO_QUERY_THROW );
2024cdf0e10cSrcweir                     xTransact->commit();
2025cdf0e10cSrcweir                 }
2026cdf0e10cSrcweir                 catch( uno::Exception& )
2027cdf0e10cSrcweir                 {
2028cdf0e10cSrcweir                     DBG_ERROR( "The strotage was not commited on DoSaveAs!\n" );
2029cdf0e10cSrcweir                 }
2030cdf0e10cSrcweir             }
2031cdf0e10cSrcweir         }
2032cdf0e10cSrcweir     }
2033cdf0e10cSrcweir 
2034cdf0e10cSrcweir     return bOk;
2035cdf0e10cSrcweir }
2036cdf0e10cSrcweir 
2037cdf0e10cSrcweir //-------------------------------------------------------------------------
2038cdf0e10cSrcweir // TODO/LATER: may be the call must be removed completelly
DoSaveAs(SfxMedium & rMedium)2039cdf0e10cSrcweir sal_Bool SfxObjectShell::DoSaveAs( SfxMedium& rMedium )
2040cdf0e10cSrcweir {
2041cdf0e10cSrcweir     // hier kommen nur Root-Storages rein, die via Temp-File gespeichert werden
2042cdf0e10cSrcweir     rMedium.CreateTempFileNoCopy();
2043cdf0e10cSrcweir     SetError(rMedium.GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2044cdf0e10cSrcweir     if ( GetError() )
2045cdf0e10cSrcweir         return sal_False;
2046cdf0e10cSrcweir 
2047cdf0e10cSrcweir     // copy version list from "old" medium to target medium, so it can be used on saving
2048cdf0e10cSrcweir     if ( pImp->bPreserveVersions )
2049cdf0e10cSrcweir         rMedium.TransferVersionList_Impl( *pMedium );
2050cdf0e10cSrcweir 
2051cdf0e10cSrcweir     sal_Bool bRet = SaveTo_Impl( rMedium, NULL );
2052cdf0e10cSrcweir     if ( !bRet )
2053cdf0e10cSrcweir         SetError(rMedium.GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2054cdf0e10cSrcweir     return bRet;
2055cdf0e10cSrcweir }
2056cdf0e10cSrcweir 
2057cdf0e10cSrcweir //-------------------------------------------------------------------------
2058cdf0e10cSrcweir 
DoSaveCompleted(SfxMedium * pNewMed)2059cdf0e10cSrcweir sal_Bool SfxObjectShell::DoSaveCompleted( SfxMedium* pNewMed )
2060cdf0e10cSrcweir {
2061cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::DoSaveCompleted" );
2062cdf0e10cSrcweir 
2063cdf0e10cSrcweir     sal_Bool bOk = sal_True;
2064cdf0e10cSrcweir     sal_Bool bMedChanged = pNewMed && pNewMed!=pMedium;
2065cdf0e10cSrcweir /*	sal_Bool bCreatedTempStor = pNewMed && pMedium &&
2066cdf0e10cSrcweir         IsPackageStorageFormat_Impl(*pMedium) &&
2067cdf0e10cSrcweir         !IsPackageStorageFormat_Impl(*pNewMed) &&
2068cdf0e10cSrcweir         pMedium->GetName().Len();
2069cdf0e10cSrcweir */
2070cdf0e10cSrcweir     DBG_ASSERT( !pNewMed || pNewMed->GetError() == ERRCODE_NONE, "DoSaveCompleted: Medium has error!" );
2071cdf0e10cSrcweir 
2072cdf0e10cSrcweir     // delete Medium (and Storage!) after all notifications
2073cdf0e10cSrcweir     SfxMedium* pOld = pMedium;
2074cdf0e10cSrcweir     if ( bMedChanged )
2075cdf0e10cSrcweir     {
2076cdf0e10cSrcweir         pMedium = pNewMed;
2077cdf0e10cSrcweir         pMedium->CanDisposeStorage_Impl( sal_True );
2078cdf0e10cSrcweir     }
2079cdf0e10cSrcweir 
2080cdf0e10cSrcweir     const SfxFilter *pFilter = pMedium ? pMedium->GetFilter() : 0;
2081cdf0e10cSrcweir     if ( pNewMed )
2082cdf0e10cSrcweir     {
2083cdf0e10cSrcweir         if( bMedChanged )
2084cdf0e10cSrcweir         {
2085cdf0e10cSrcweir             if( pNewMed->GetName().Len() )
2086cdf0e10cSrcweir                 bHasName = sal_True;
2087cdf0e10cSrcweir             Broadcast( SfxSimpleHint(SFX_HINT_NAMECHANGED) );
2088cdf0e10cSrcweir             getDocProperties()->setGenerator(
2089cdf0e10cSrcweir                ::utl::DocInfoHelper::GetGeneratorString() );
2090cdf0e10cSrcweir         }
2091cdf0e10cSrcweir 
2092cdf0e10cSrcweir         uno::Reference< embed::XStorage > xStorage;
2093cdf0e10cSrcweir         if ( !pFilter || IsPackageStorageFormat_Impl( *pMedium ) )
2094cdf0e10cSrcweir         {
2095cdf0e10cSrcweir             uno::Reference < embed::XStorage > xOld = GetStorage();
2096cdf0e10cSrcweir 
2097cdf0e10cSrcweir             // when the package based medium is broken and has no storage or if the storage
2098cdf0e10cSrcweir             // is the same as the document storage the current document storage should be preserved
2099cdf0e10cSrcweir             xStorage = pMedium->GetStorage();
2100cdf0e10cSrcweir             bOk = SaveCompleted( xStorage );
2101cdf0e10cSrcweir             if ( bOk && xStorage.is() && xOld != xStorage
2102cdf0e10cSrcweir               && (!pOld || !pOld->HasStorage_Impl() || xOld != pOld->GetStorage() ) )
2103cdf0e10cSrcweir             {
2104cdf0e10cSrcweir                 // old own storage was not controlled by old Medium -> dispose it
2105cdf0e10cSrcweir                 try {
2106cdf0e10cSrcweir                     xOld->dispose();
2107cdf0e10cSrcweir                 } catch( uno::Exception& )
2108cdf0e10cSrcweir                 {
2109cdf0e10cSrcweir                     // the storage is disposed already
2110cdf0e10cSrcweir                     // can happen during reload scenario when the medium has disposed it during the closing
2111cdf0e10cSrcweir                     // will be fixed in one of the next milestones
2112cdf0e10cSrcweir                 }
2113cdf0e10cSrcweir             }
2114cdf0e10cSrcweir         }
2115cdf0e10cSrcweir         else
2116cdf0e10cSrcweir         {
2117cdf0e10cSrcweir             if( pMedium->GetOpenMode() & STREAM_WRITE )
2118cdf0e10cSrcweir                 pMedium->GetInStream();
2119cdf0e10cSrcweir             xStorage = GetStorage();
2120cdf0e10cSrcweir         }
2121cdf0e10cSrcweir 
2122cdf0e10cSrcweir         // TODO/LATER: may be this code will be replaced, but not sure
2123cdf0e10cSrcweir         // Set storage in document library containers
2124cdf0e10cSrcweir         pImp->pBasicManager->setStorage( xStorage );
2125cdf0e10cSrcweir 
2126cdf0e10cSrcweir         // Get rid of this workaround after issue i113914 is fixed
2127cdf0e10cSrcweir         try
2128cdf0e10cSrcweir         {
2129cdf0e10cSrcweir             uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries( pImp->xBasicLibraries, uno::UNO_QUERY_THROW );
2130cdf0e10cSrcweir             xBasicLibraries->setRootStorage( xStorage );
2131cdf0e10cSrcweir         }
2132cdf0e10cSrcweir         catch( uno::Exception& )
2133cdf0e10cSrcweir         {}
2134cdf0e10cSrcweir         try
2135cdf0e10cSrcweir         {
2136cdf0e10cSrcweir             uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries( pImp->xDialogLibraries, uno::UNO_QUERY_THROW );
2137cdf0e10cSrcweir             xDialogLibraries->setRootStorage( xStorage );
2138cdf0e10cSrcweir         }
2139cdf0e10cSrcweir         catch( uno::Exception& )
2140cdf0e10cSrcweir         {}
2141cdf0e10cSrcweir     }
2142cdf0e10cSrcweir     else
2143cdf0e10cSrcweir     {
2144cdf0e10cSrcweir         if( pMedium )
2145cdf0e10cSrcweir         {
2146cdf0e10cSrcweir             if( pFilter && !IsPackageStorageFormat_Impl( *pMedium ) && (pMedium->GetOpenMode() & STREAM_WRITE ))
2147cdf0e10cSrcweir             {
2148cdf0e10cSrcweir                 pMedium->ReOpen();
2149cdf0e10cSrcweir                 bOk = SaveCompletedChildren( sal_False );
2150cdf0e10cSrcweir             }
2151cdf0e10cSrcweir             else
2152cdf0e10cSrcweir                 bOk = SaveCompleted( NULL );
2153cdf0e10cSrcweir         }
2154cdf0e10cSrcweir         // entweder Save oder ConvertTo
2155cdf0e10cSrcweir         else
2156cdf0e10cSrcweir             bOk = SaveCompleted( NULL );
2157cdf0e10cSrcweir     }
2158cdf0e10cSrcweir 
2159cdf0e10cSrcweir     if ( bOk && pNewMed )
2160cdf0e10cSrcweir     {
2161cdf0e10cSrcweir         if( bMedChanged )
2162cdf0e10cSrcweir         {
2163cdf0e10cSrcweir             delete pOld;
2164cdf0e10cSrcweir 
2165cdf0e10cSrcweir             uno::Reference< frame::XModel > xModel = GetModel();
2166cdf0e10cSrcweir             if ( xModel.is() )
2167cdf0e10cSrcweir             {
2168cdf0e10cSrcweir                 ::rtl::OUString aURL = pNewMed->GetOrigURL();
2169cdf0e10cSrcweir                 uno::Sequence< beans::PropertyValue > aMediaDescr;
2170cdf0e10cSrcweir                 TransformItems( SID_OPENDOC, *pNewMed->GetItemSet(), aMediaDescr );
2171cdf0e10cSrcweir                 try
2172cdf0e10cSrcweir                 {
2173cdf0e10cSrcweir                     xModel->attachResource( aURL, aMediaDescr );
2174cdf0e10cSrcweir                 }
2175cdf0e10cSrcweir                 catch( uno::Exception& )
2176cdf0e10cSrcweir                 {}
2177cdf0e10cSrcweir             }
2178cdf0e10cSrcweir 
2179cdf0e10cSrcweir             // before the title regenerated the document must loose the signatures
2180cdf0e10cSrcweir             pImp->nDocumentSignatureState = SIGNATURESTATE_NOSIGNATURES;
2181cdf0e10cSrcweir             pImp->nScriptingSignatureState = pNewMed->GetCachedSignatureState_Impl();
2182cdf0e10cSrcweir             OSL_ENSURE( pImp->nScriptingSignatureState != SIGNATURESTATE_SIGNATURES_BROKEN, "The signature must not be broken at this place" );
2183cdf0e10cSrcweir             pImp->bSignatureErrorIsShown = sal_False;
2184cdf0e10cSrcweir 
2185cdf0e10cSrcweir             // TODO/LATER: in future the medium must control own signature state, not the document
2186cdf0e10cSrcweir             pNewMed->SetCachedSignatureState_Impl( SIGNATURESTATE_NOSIGNATURES ); // set the default value back
2187cdf0e10cSrcweir 
2188cdf0e10cSrcweir             // Titel neu setzen
2189cdf0e10cSrcweir             if ( pNewMed->GetName().Len() && SFX_CREATE_MODE_EMBEDDED != eCreateMode )
2190cdf0e10cSrcweir                 InvalidateName();
2191cdf0e10cSrcweir             SetModified(sal_False); // nur bei gesetztem Medium zur"ucksetzen
2192cdf0e10cSrcweir             Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
2193cdf0e10cSrcweir 
2194cdf0e10cSrcweir             // this is the end of the saving process, it is possible that the file was changed
2195cdf0e10cSrcweir             // between medium commit and this step ( attributes change and so on )
2196cdf0e10cSrcweir             // so get the file date again
2197cdf0e10cSrcweir             if ( pNewMed->DocNeedsFileDateCheck() )
2198cdf0e10cSrcweir                 pNewMed->GetInitFileDate( sal_True );
2199cdf0e10cSrcweir         }
2200cdf0e10cSrcweir     }
2201cdf0e10cSrcweir 
2202cdf0e10cSrcweir     pMedium->ClearBackup_Impl();
2203cdf0e10cSrcweir     pMedium->LockOrigFileOnDemand( sal_True, sal_False );
2204cdf0e10cSrcweir 
2205cdf0e10cSrcweir     return bOk;
2206cdf0e10cSrcweir }
2207cdf0e10cSrcweir 
2208cdf0e10cSrcweir //-------------------------------------------------------------------------
2209cdf0e10cSrcweir 
ConvertFrom(SfxMedium &)2210cdf0e10cSrcweir sal_Bool SfxObjectShell::ConvertFrom
2211cdf0e10cSrcweir (
2212cdf0e10cSrcweir     SfxMedium&  /*rMedium*/     /*  <SfxMedium>, welches die Quell-Datei beschreibt
2213cdf0e10cSrcweir                                 (z.B. Dateiname, <SfxFilter>, Open-Modi etc.) */
2214cdf0e10cSrcweir )
2215cdf0e10cSrcweir 
2216cdf0e10cSrcweir /*  [Beschreibung]
2217cdf0e10cSrcweir 
2218cdf0e10cSrcweir     Diese Methode wird zum Laden von Dokumenten "uber alle Filter gerufen,
2219cdf0e10cSrcweir     die nicht SFX_FILTER_OWN sind oder f"ur die kein Clipboard-Format
2220cdf0e10cSrcweir     registriert wurde (also kein Storage-Format benutzen). Mit anderen Worten:
2221cdf0e10cSrcweir     mit dieser Methode wird importiert.
2222cdf0e10cSrcweir 
2223cdf0e10cSrcweir     Das hier zu "offende File sollte "uber 'rMedium' ge"offnet werden,
2224cdf0e10cSrcweir     um die richtigen Open-Modi zu gew"ahrleisten. Insbesondere wenn das
2225cdf0e10cSrcweir     Format beibehalten wird (nur m"oglich bei SFX_FILTER_SIMULATE oder
2226cdf0e10cSrcweir     SFX_FILTER_ONW) mu\s die Datei STREAM_SHARE_DENYWRITE ge"offnet werden.
2227cdf0e10cSrcweir 
2228cdf0e10cSrcweir 
2229cdf0e10cSrcweir     [R"uckgabewert]
2230cdf0e10cSrcweir 
2231cdf0e10cSrcweir     sal_Bool                sal_True
2232cdf0e10cSrcweir                         Das Dokument konnte geladen werden.
2233cdf0e10cSrcweir 
2234cdf0e10cSrcweir                         sal_False
2235cdf0e10cSrcweir                         Das Dokument konnte nicht geladen werden, ein
2236cdf0e10cSrcweir                         Fehlercode ist mit <SvMedium::GetError()const> zu
2237cdf0e10cSrcweir                         erhalten.
2238cdf0e10cSrcweir 
2239cdf0e10cSrcweir 
2240cdf0e10cSrcweir     [Beispiel]
2241cdf0e10cSrcweir 
2242cdf0e10cSrcweir     sal_Bool DocSh::ConvertFrom( SfxMedium &rMedium )
2243cdf0e10cSrcweir     {
2244cdf0e10cSrcweir         SvStreamRef xStream = rMedium.GetInStream();
2245cdf0e10cSrcweir         if( xStream.is() )
2246cdf0e10cSrcweir         {
2247cdf0e10cSrcweir             xStream->SetBufferSize(4096);
2248cdf0e10cSrcweir             *xStream >> ...;
2249cdf0e10cSrcweir 
2250cdf0e10cSrcweir             // NICHT 'rMedium.CloseInStream()' rufen! File gelockt halten!
2251cdf0e10cSrcweir             return SVSTREAM_OK == rMedium.GetError();
2252cdf0e10cSrcweir         }
2253cdf0e10cSrcweir 
2254cdf0e10cSrcweir         return sal_False;
2255cdf0e10cSrcweir     }
2256cdf0e10cSrcweir 
2257cdf0e10cSrcweir 
2258cdf0e10cSrcweir     [Querverweise]
2259cdf0e10cSrcweir 
2260cdf0e10cSrcweir     <SfxObjectShell::ConvertTo(SfxMedium&)>
2261cdf0e10cSrcweir     <SFX_FILTER_REGISTRATION>
2262cdf0e10cSrcweir */
2263cdf0e10cSrcweir {
2264cdf0e10cSrcweir     return sal_False;
2265cdf0e10cSrcweir }
2266cdf0e10cSrcweir 
InsertFrom(SfxMedium & rMedium)2267cdf0e10cSrcweir sal_Bool SfxObjectShell::InsertFrom( SfxMedium& rMedium )
2268cdf0e10cSrcweir {
2269cdf0e10cSrcweir     ::rtl::OUString aTypeName( rMedium.GetFilter()->GetTypeName() );
2270cdf0e10cSrcweir     ::rtl::OUString aFilterName( rMedium.GetFilter()->GetFilterName() );
2271cdf0e10cSrcweir 
2272cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory >  xMan = ::comphelper::getProcessServiceFactory();
2273cdf0e10cSrcweir     uno::Reference < lang::XMultiServiceFactory > xFilterFact (
2274cdf0e10cSrcweir                 xMan->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), uno::UNO_QUERY );
2275cdf0e10cSrcweir 
2276cdf0e10cSrcweir     uno::Sequence < beans::PropertyValue > aProps;
2277cdf0e10cSrcweir     uno::Reference < container::XNameAccess > xFilters ( xFilterFact, uno::UNO_QUERY );
2278cdf0e10cSrcweir     if ( xFilters->hasByName( aFilterName ) )
2279cdf0e10cSrcweir     {
2280cdf0e10cSrcweir         xFilters->getByName( aFilterName ) >>= aProps;
2281cdf0e10cSrcweir         rMedium.GetItemSet()->Put( SfxStringItem( SID_FILTER_NAME, aFilterName ) );
2282cdf0e10cSrcweir     }
2283cdf0e10cSrcweir 
2284cdf0e10cSrcweir     ::rtl::OUString aFilterImplName;
2285cdf0e10cSrcweir     sal_Int32 nFilterProps = aProps.getLength();
2286cdf0e10cSrcweir     for ( sal_Int32 nFilterProp = 0; nFilterProp<nFilterProps; nFilterProp++ )
2287cdf0e10cSrcweir     {
2288cdf0e10cSrcweir         const beans::PropertyValue& rFilterProp = aProps[nFilterProp];
2289cdf0e10cSrcweir         if ( rFilterProp.Name.compareToAscii("FilterService") == COMPARE_EQUAL )
2290cdf0e10cSrcweir         {
2291cdf0e10cSrcweir             rFilterProp.Value >>= aFilterImplName;
2292cdf0e10cSrcweir             break;
2293cdf0e10cSrcweir         }
2294cdf0e10cSrcweir     }
2295cdf0e10cSrcweir 
2296cdf0e10cSrcweir     uno::Reference< document::XFilter > xLoader;
2297cdf0e10cSrcweir     if ( aFilterImplName.getLength() )
2298cdf0e10cSrcweir     {
2299cdf0e10cSrcweir         try{
2300cdf0e10cSrcweir         xLoader = uno::Reference< document::XFilter >
2301cdf0e10cSrcweir             ( xFilterFact->createInstanceWithArguments( aFilterName, uno::Sequence < uno::Any >() ), uno::UNO_QUERY );
2302cdf0e10cSrcweir         }catch(const uno::Exception&)
2303cdf0e10cSrcweir             { xLoader.clear(); }
2304cdf0e10cSrcweir     }
2305cdf0e10cSrcweir     if ( xLoader.is() )
2306cdf0e10cSrcweir     {
2307cdf0e10cSrcweir         // #131744#: it happens that xLoader does not support xImporter!
2308cdf0e10cSrcweir         try{
2309cdf0e10cSrcweir         uno::Reference< lang::XComponent >  xComp( GetModel(), uno::UNO_QUERY_THROW );
2310cdf0e10cSrcweir         uno::Reference< document::XImporter > xImporter( xLoader, uno::UNO_QUERY_THROW );
2311cdf0e10cSrcweir         xImporter->setTargetDocument( xComp );
2312cdf0e10cSrcweir 
2313cdf0e10cSrcweir         uno::Sequence < beans::PropertyValue > lDescriptor;
2314cdf0e10cSrcweir         rMedium.GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, rMedium.GetName() ) );
2315cdf0e10cSrcweir         TransformItems( SID_OPENDOC, *rMedium.GetItemSet(), lDescriptor );
2316cdf0e10cSrcweir 
2317cdf0e10cSrcweir         com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aArgs ( lDescriptor.getLength() );
2318cdf0e10cSrcweir         com::sun::star::beans::PropertyValue * pNewValue = aArgs.getArray();
2319cdf0e10cSrcweir         const com::sun::star::beans::PropertyValue * pOldValue = lDescriptor.getConstArray();
2320cdf0e10cSrcweir         const OUString sInputStream ( RTL_CONSTASCII_USTRINGPARAM ( "InputStream" ) );
2321cdf0e10cSrcweir 
2322cdf0e10cSrcweir         sal_Bool bHasInputStream = sal_False;
2323cdf0e10cSrcweir         sal_Bool bHasBaseURL = sal_False;
2324cdf0e10cSrcweir         sal_Int32 i;
2325cdf0e10cSrcweir         sal_Int32 nEnd = lDescriptor.getLength();
2326cdf0e10cSrcweir 
2327cdf0e10cSrcweir         for ( i = 0; i < nEnd; i++ )
2328cdf0e10cSrcweir         {
2329cdf0e10cSrcweir             pNewValue[i] = pOldValue[i];
2330cdf0e10cSrcweir             if ( pOldValue [i].Name == sInputStream )
2331cdf0e10cSrcweir                 bHasInputStream = sal_True;
2332cdf0e10cSrcweir             else if ( pOldValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "DocumentBaseURL" ) ) )
2333cdf0e10cSrcweir                 bHasBaseURL = sal_True;
2334cdf0e10cSrcweir         }
2335cdf0e10cSrcweir 
2336cdf0e10cSrcweir         if ( !bHasInputStream )
2337cdf0e10cSrcweir         {
2338cdf0e10cSrcweir             aArgs.realloc ( ++nEnd );
2339cdf0e10cSrcweir             aArgs[nEnd-1].Name = sInputStream;
2340*d321cf2fSArrigo Marchiori             com::sun::star::uno::Reference < com::sun::star::io::XInputStream > temp;
2341*d321cf2fSArrigo Marchiori             temp = new utl::OSeekableInputStreamWrapper ( *rMedium.GetInStream() );
2342*d321cf2fSArrigo Marchiori             aArgs[nEnd-1].Value <<= temp;
2343cdf0e10cSrcweir         }
2344cdf0e10cSrcweir 
2345cdf0e10cSrcweir         if ( !bHasBaseURL )
2346cdf0e10cSrcweir         {
2347cdf0e10cSrcweir             aArgs.realloc ( ++nEnd );
2348cdf0e10cSrcweir             aArgs[nEnd-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DocumentBaseURL" ) );
2349cdf0e10cSrcweir             aArgs[nEnd-1].Value <<= rMedium.GetBaseURL();
2350cdf0e10cSrcweir         }
2351cdf0e10cSrcweir 
2352cdf0e10cSrcweir         aArgs.realloc( ++nEnd );
2353cdf0e10cSrcweir         aArgs[nEnd-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "InsertMode" ) );
2354cdf0e10cSrcweir         aArgs[nEnd-1].Value <<= (sal_Bool) sal_True;
2355cdf0e10cSrcweir 
2356602d7686SAndre Fischer         return xLoader->filter( aArgs );
2357cdf0e10cSrcweir         }catch(const uno::Exception&)
2358cdf0e10cSrcweir         {}
2359cdf0e10cSrcweir     }
2360cdf0e10cSrcweir 
2361cdf0e10cSrcweir     return sal_False;
2362cdf0e10cSrcweir }
2363cdf0e10cSrcweir 
ImportFrom(SfxMedium & rMedium)2364cdf0e10cSrcweir sal_Bool SfxObjectShell::ImportFrom( SfxMedium& rMedium )
2365cdf0e10cSrcweir {
2366cdf0e10cSrcweir     ::rtl::OUString aTypeName( rMedium.GetFilter()->GetTypeName() );
2367cdf0e10cSrcweir     ::rtl::OUString aFilterName( rMedium.GetFilter()->GetFilterName() );
2368cdf0e10cSrcweir 
2369577c0052SWang Lei         BeforeLoading( rMedium, aTypeName, aFilterName );
2370cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory >  xMan = ::comphelper::getProcessServiceFactory();
2371cdf0e10cSrcweir     uno::Reference < lang::XMultiServiceFactory > xFilterFact (
2372cdf0e10cSrcweir                 xMan->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), uno::UNO_QUERY );
2373cdf0e10cSrcweir 
2374cdf0e10cSrcweir     uno::Sequence < beans::PropertyValue > aProps;
2375cdf0e10cSrcweir     uno::Reference < container::XNameAccess > xFilters ( xFilterFact, uno::UNO_QUERY );
2376cdf0e10cSrcweir     if ( xFilters->hasByName( aFilterName ) )
2377cdf0e10cSrcweir     {
2378cdf0e10cSrcweir         xFilters->getByName( aFilterName ) >>= aProps;
2379cdf0e10cSrcweir         rMedium.GetItemSet()->Put( SfxStringItem( SID_FILTER_NAME, aFilterName ) );
2380cdf0e10cSrcweir     }
2381cdf0e10cSrcweir 
2382cdf0e10cSrcweir     ::rtl::OUString aFilterImplName;
2383cdf0e10cSrcweir     sal_Int32 nFilterProps = aProps.getLength();
2384cdf0e10cSrcweir     for ( sal_Int32 nFilterProp = 0; nFilterProp<nFilterProps; nFilterProp++ )
2385cdf0e10cSrcweir     {
2386cdf0e10cSrcweir         const beans::PropertyValue& rFilterProp = aProps[nFilterProp];
2387cdf0e10cSrcweir         if ( rFilterProp.Name.compareToAscii("FilterService") == COMPARE_EQUAL )
2388cdf0e10cSrcweir         {
2389cdf0e10cSrcweir             rFilterProp.Value >>= aFilterImplName;
2390cdf0e10cSrcweir             break;
2391cdf0e10cSrcweir         }
2392cdf0e10cSrcweir     }
2393cdf0e10cSrcweir 
2394cdf0e10cSrcweir     uno::Reference< document::XFilter > xLoader;
2395cdf0e10cSrcweir     if ( aFilterImplName.getLength() )
2396cdf0e10cSrcweir     {
2397cdf0e10cSrcweir         try{
2398cdf0e10cSrcweir         xLoader = uno::Reference< document::XFilter >
2399cdf0e10cSrcweir             ( xFilterFact->createInstanceWithArguments( aFilterName, uno::Sequence < uno::Any >() ), uno::UNO_QUERY );
2400cdf0e10cSrcweir         }catch(const uno::Exception&)
2401cdf0e10cSrcweir             { xLoader.clear(); }
2402cdf0e10cSrcweir     }
2403cdf0e10cSrcweir     if ( xLoader.is() )
2404cdf0e10cSrcweir     {
2405cdf0e10cSrcweir         // #131744#: it happens that xLoader does not support xImporter!
2406cdf0e10cSrcweir         try{
2407cdf0e10cSrcweir         uno::Reference< lang::XComponent >  xComp( GetModel(), uno::UNO_QUERY_THROW );
2408cdf0e10cSrcweir         uno::Reference< document::XImporter > xImporter( xLoader, uno::UNO_QUERY_THROW );
2409cdf0e10cSrcweir         xImporter->setTargetDocument( xComp );
2410cdf0e10cSrcweir 
2411cdf0e10cSrcweir         uno::Sequence < beans::PropertyValue > lDescriptor;
2412cdf0e10cSrcweir         rMedium.GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, rMedium.GetName() ) );
2413cdf0e10cSrcweir         TransformItems( SID_OPENDOC, *rMedium.GetItemSet(), lDescriptor );
2414cdf0e10cSrcweir 
2415cdf0e10cSrcweir         com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aArgs ( lDescriptor.getLength() );
2416cdf0e10cSrcweir         com::sun::star::beans::PropertyValue * pNewValue = aArgs.getArray();
2417cdf0e10cSrcweir         const com::sun::star::beans::PropertyValue * pOldValue = lDescriptor.getConstArray();
2418cdf0e10cSrcweir         const OUString sInputStream ( RTL_CONSTASCII_USTRINGPARAM ( "InputStream" ) );
2419cdf0e10cSrcweir 
2420cdf0e10cSrcweir         sal_Bool bHasInputStream = sal_False;
2421cdf0e10cSrcweir         sal_Bool bHasBaseURL = sal_False;
2422cdf0e10cSrcweir         sal_Int32 i;
2423cdf0e10cSrcweir         sal_Int32 nEnd = lDescriptor.getLength();
2424cdf0e10cSrcweir 
2425cdf0e10cSrcweir         for ( i = 0; i < nEnd; i++ )
2426cdf0e10cSrcweir         {
2427cdf0e10cSrcweir             pNewValue[i] = pOldValue[i];
2428cdf0e10cSrcweir             if ( pOldValue [i].Name == sInputStream )
2429cdf0e10cSrcweir                 bHasInputStream = sal_True;
2430cdf0e10cSrcweir             else if ( pOldValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "DocumentBaseURL" ) ) )
2431cdf0e10cSrcweir                 bHasBaseURL = sal_True;
2432cdf0e10cSrcweir         }
2433cdf0e10cSrcweir 
2434cdf0e10cSrcweir         if ( !bHasInputStream )
2435cdf0e10cSrcweir         {
2436cdf0e10cSrcweir             aArgs.realloc ( ++nEnd );
2437cdf0e10cSrcweir             aArgs[nEnd-1].Name = sInputStream;
2438cdf0e10cSrcweir             aArgs[nEnd-1].Value <<= com::sun::star::uno::Reference < com::sun::star::io::XInputStream > ( new utl::OSeekableInputStreamWrapper ( *rMedium.GetInStream() ) );
2439cdf0e10cSrcweir         }
2440cdf0e10cSrcweir 
2441cdf0e10cSrcweir         if ( !bHasBaseURL )
2442cdf0e10cSrcweir         {
2443cdf0e10cSrcweir             aArgs.realloc ( ++nEnd );
2444cdf0e10cSrcweir             aArgs[nEnd-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DocumentBaseURL" ) );
2445cdf0e10cSrcweir             aArgs[nEnd-1].Value <<= rMedium.GetBaseURL();
2446cdf0e10cSrcweir         }
2447cdf0e10cSrcweir 
2448602d7686SAndre Fischer //-> #i119492
2449602d7686SAndre Fischer //        return xLoader->filter( aArgs );
2450602d7686SAndre Fischer // During loading, some OLE objects like chart will be set modified flag, so needs to reset the flag to false after loading
2451602d7686SAndre Fischer         sal_Bool bRtn = xLoader->filter( aArgs );
2452602d7686SAndre Fischer         uno::Sequence < ::rtl::OUString > aNames = GetEmbeddedObjectContainer().GetObjectNames();
2453602d7686SAndre Fischer         for ( sal_Int32 n = 0; n < aNames.getLength(); n++ )
2454602d7686SAndre Fischer         {
2455602d7686SAndre Fischer             ::rtl::OUString	aName = aNames[n];
2456602d7686SAndre Fischer             uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObjectContainer().GetEmbeddedObject( aName );
2457602d7686SAndre Fischer             OSL_ENSURE( xObj.is(), "An empty entry in the embedded objects list!\n" );
2458602d7686SAndre Fischer             if ( xObj.is() )
2459602d7686SAndre Fischer             {
2460602d7686SAndre Fischer                 sal_Int32 nState = xObj->getCurrentState();
2461602d7686SAndre Fischer                 if ( nState == embed::EmbedStates::LOADED || nState == embed::EmbedStates::RUNNING )	// means that the object is not active
2462602d7686SAndre Fischer                 {
2463602d7686SAndre Fischer                     uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
2464602d7686SAndre Fischer                     if ( xModifiable.is() )
2465602d7686SAndre Fischer                         xModifiable->setModified(sal_False);
2466602d7686SAndre Fischer                 }
2467602d7686SAndre Fischer             }
2468602d7686SAndre Fischer         }
2469577c0052SWang Lei         AfterLoading( rMedium, aTypeName, aFilterName );
2470577c0052SWang Lei 
2471602d7686SAndre Fischer         return bRtn;
2472602d7686SAndre Fischer //<- #i119492
2473cdf0e10cSrcweir         }catch(const uno::Exception&)
2474cdf0e10cSrcweir         {}
2475cdf0e10cSrcweir     }
2476cdf0e10cSrcweir 
2477cdf0e10cSrcweir     return sal_False;
2478cdf0e10cSrcweir }
2479cdf0e10cSrcweir 
ExportTo(SfxMedium & rMedium)2480cdf0e10cSrcweir sal_Bool SfxObjectShell::ExportTo( SfxMedium& rMedium )
2481cdf0e10cSrcweir {
2482cdf0e10cSrcweir     ::rtl::OUString aTypeName( rMedium.GetFilter()->GetTypeName() );
2483cdf0e10cSrcweir     ::rtl::OUString aFilterName( rMedium.GetFilter()->GetFilterName() );
2484cdf0e10cSrcweir     uno::Reference< document::XExporter > xExporter;
2485cdf0e10cSrcweir 
2486cdf0e10cSrcweir     {
2487cdf0e10cSrcweir         uno::Reference< lang::XMultiServiceFactory >  xMan = ::comphelper::getProcessServiceFactory();
2488cdf0e10cSrcweir         uno::Reference < lang::XMultiServiceFactory > xFilterFact (
2489cdf0e10cSrcweir                 xMan->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), uno::UNO_QUERY );
2490cdf0e10cSrcweir 
2491cdf0e10cSrcweir         uno::Sequence < beans::PropertyValue > aProps;
2492cdf0e10cSrcweir         uno::Reference < container::XNameAccess > xFilters ( xFilterFact, uno::UNO_QUERY );
2493cdf0e10cSrcweir         if ( xFilters->hasByName( aFilterName ) )
2494cdf0e10cSrcweir             xFilters->getByName( aFilterName ) >>= aProps;
2495cdf0e10cSrcweir 
2496cdf0e10cSrcweir         ::rtl::OUString aFilterImplName;
2497cdf0e10cSrcweir         sal_Int32 nFilterProps = aProps.getLength();
2498cdf0e10cSrcweir         for ( sal_Int32 nFilterProp = 0; nFilterProp<nFilterProps; nFilterProp++ )
2499cdf0e10cSrcweir         {
2500cdf0e10cSrcweir             const beans::PropertyValue& rFilterProp = aProps[nFilterProp];
2501cdf0e10cSrcweir             if ( rFilterProp.Name.compareToAscii("FilterService") == COMPARE_EQUAL )
2502cdf0e10cSrcweir             {
2503cdf0e10cSrcweir                 rFilterProp.Value >>= aFilterImplName;
2504cdf0e10cSrcweir                 break;
2505cdf0e10cSrcweir             }
2506cdf0e10cSrcweir         }
2507cdf0e10cSrcweir 
2508cdf0e10cSrcweir         if ( aFilterImplName.getLength() )
2509cdf0e10cSrcweir         {
2510cdf0e10cSrcweir             try{
2511cdf0e10cSrcweir             xExporter = uno::Reference< document::XExporter >
2512cdf0e10cSrcweir                 ( xFilterFact->createInstanceWithArguments( aFilterName, uno::Sequence < uno::Any >() ), uno::UNO_QUERY );
2513cdf0e10cSrcweir             }catch(const uno::Exception&)
2514cdf0e10cSrcweir                 { xExporter.clear(); }
2515cdf0e10cSrcweir         }
2516cdf0e10cSrcweir     }
2517cdf0e10cSrcweir 
2518cdf0e10cSrcweir     if ( xExporter.is() )
2519cdf0e10cSrcweir     {
2520cdf0e10cSrcweir         try{
2521cdf0e10cSrcweir         uno::Reference< lang::XComponent >  xComp( GetModel(), uno::UNO_QUERY_THROW );
2522cdf0e10cSrcweir         uno::Reference< document::XFilter > xFilter( xExporter, uno::UNO_QUERY_THROW );
2523cdf0e10cSrcweir         xExporter->setSourceDocument( xComp );
2524cdf0e10cSrcweir 
2525cdf0e10cSrcweir         com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aOldArgs;
2526cdf0e10cSrcweir         SfxItemSet* pItems = rMedium.GetItemSet();
2527cdf0e10cSrcweir         TransformItems( SID_SAVEASDOC, *pItems, aOldArgs );
2528cdf0e10cSrcweir 
2529cdf0e10cSrcweir         const com::sun::star::beans::PropertyValue * pOldValue = aOldArgs.getConstArray();
2530cdf0e10cSrcweir         com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aArgs ( aOldArgs.getLength() );
2531cdf0e10cSrcweir         com::sun::star::beans::PropertyValue * pNewValue = aArgs.getArray();
2532cdf0e10cSrcweir 
2533cdf0e10cSrcweir         // put in the REAL file name, and copy all PropertyValues
2534cdf0e10cSrcweir         const OUString sOutputStream ( RTL_CONSTASCII_USTRINGPARAM ( "OutputStream" ) );
2535cdf0e10cSrcweir         const OUString sStream ( RTL_CONSTASCII_USTRINGPARAM ( "StreamForOutput" ) );
2536cdf0e10cSrcweir         sal_Bool bHasOutputStream = sal_False;
2537cdf0e10cSrcweir         sal_Bool bHasStream = sal_False;
2538cdf0e10cSrcweir         sal_Bool bHasBaseURL = sal_False;
2539cdf0e10cSrcweir         sal_Int32 i;
2540cdf0e10cSrcweir         sal_Int32 nEnd = aOldArgs.getLength();
2541cdf0e10cSrcweir 
2542cdf0e10cSrcweir         for ( i = 0; i < nEnd; i++ )
2543cdf0e10cSrcweir         {
2544cdf0e10cSrcweir             pNewValue[i] = pOldValue[i];
2545cdf0e10cSrcweir             if ( pOldValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "FileName" ) ) )
2546cdf0e10cSrcweir                 pNewValue[i].Value <<= OUString ( rMedium.GetName() );
2547cdf0e10cSrcweir             else if ( pOldValue[i].Name == sOutputStream )
2548cdf0e10cSrcweir                 bHasOutputStream = sal_True;
2549cdf0e10cSrcweir             else if ( pOldValue[i].Name == sStream )
2550cdf0e10cSrcweir                 bHasStream = sal_True;
2551cdf0e10cSrcweir             else if ( pOldValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "DocumentBaseURL" ) ) )
2552cdf0e10cSrcweir                 bHasBaseURL = sal_True;
2553cdf0e10cSrcweir         }
2554cdf0e10cSrcweir 
2555cdf0e10cSrcweir         if ( !bHasOutputStream )
2556cdf0e10cSrcweir         {
2557cdf0e10cSrcweir             aArgs.realloc ( ++nEnd );
2558cdf0e10cSrcweir             aArgs[nEnd-1].Name = sOutputStream;
2559cdf0e10cSrcweir             aArgs[nEnd-1].Value <<= com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > ( new utl::OOutputStreamWrapper ( *rMedium.GetOutStream() ) );
2560cdf0e10cSrcweir         }
2561cdf0e10cSrcweir 
2562cdf0e10cSrcweir         // add stream as well, for OOX export and maybe others
2563cdf0e10cSrcweir         if ( !bHasStream )
2564cdf0e10cSrcweir         {
2565cdf0e10cSrcweir             aArgs.realloc ( ++nEnd );
2566cdf0e10cSrcweir             aArgs[nEnd-1].Name = sStream;
2567cdf0e10cSrcweir             aArgs[nEnd-1].Value <<= com::sun::star::uno::Reference < com::sun::star::io::XStream > ( new utl::OStreamWrapper ( *rMedium.GetOutStream() ) );
2568cdf0e10cSrcweir         }
2569cdf0e10cSrcweir 
2570cdf0e10cSrcweir         if ( !bHasBaseURL )
2571cdf0e10cSrcweir         {
2572cdf0e10cSrcweir             aArgs.realloc ( ++nEnd );
2573cdf0e10cSrcweir             aArgs[nEnd-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DocumentBaseURL" ) );
2574cdf0e10cSrcweir             aArgs[nEnd-1].Value <<= rMedium.GetBaseURL( sal_True );
2575cdf0e10cSrcweir         }
2576cdf0e10cSrcweir 
2577cdf0e10cSrcweir         return xFilter->filter( aArgs );
2578cdf0e10cSrcweir         }catch(const uno::Exception&)
2579cdf0e10cSrcweir         {}
2580cdf0e10cSrcweir     }
2581cdf0e10cSrcweir 
2582cdf0e10cSrcweir     return sal_False;
2583cdf0e10cSrcweir }
2584cdf0e10cSrcweir 
2585cdf0e10cSrcweir //-------------------------------------------------------------------------
2586cdf0e10cSrcweir 
ConvertTo(SfxMedium &)2587cdf0e10cSrcweir sal_Bool SfxObjectShell::ConvertTo
2588cdf0e10cSrcweir (
2589cdf0e10cSrcweir     SfxMedium&  /*rMedium*/     /*  <SfxMedium>, welches die Ziel-Datei beschreibt
2590cdf0e10cSrcweir                                 (z.B. Dateiname, <SfxFilter>, Open-Modi etc.) */
2591cdf0e10cSrcweir )
2592cdf0e10cSrcweir 
2593cdf0e10cSrcweir /*  [Beschreibung]
2594cdf0e10cSrcweir 
2595cdf0e10cSrcweir     Diese Methode wird zum Speichern von Dokumenten "uber alle Filter gerufen,
2596cdf0e10cSrcweir     die nicht SFX_FILTER_OWN sind oder f"ur die kein Clipboard-Format
2597cdf0e10cSrcweir     registriert wurde (also kein Storage-Format benutzen). Mit anderen Worten:
2598cdf0e10cSrcweir     mit dieser Methode wird exportiert.
2599cdf0e10cSrcweir 
2600cdf0e10cSrcweir     Das hier zu "offende File sollte "uber 'rMedium' ge"offnet werden,
2601cdf0e10cSrcweir     um die richtigen Open-Modi zu gew"ahrleisten. Insbesondere wenn das
2602cdf0e10cSrcweir     Format beibehalten wird (nur m"oglich bei SFX_FILTER_SIMULATE oder
2603cdf0e10cSrcweir     SFX_FILTER_ONW) mu\s die Datei auch nach dem Speichern im Modus
2604cdf0e10cSrcweir     STREAM_SHARE_DENYWRITE ge"offnet bleiben.
2605cdf0e10cSrcweir 
2606cdf0e10cSrcweir 
2607cdf0e10cSrcweir     [R"uckgabewert]
2608cdf0e10cSrcweir 
2609cdf0e10cSrcweir     sal_Bool                sal_True
2610cdf0e10cSrcweir                         Das Dokument konnte gespeichert werden.
2611cdf0e10cSrcweir 
2612cdf0e10cSrcweir                         sal_False
2613cdf0e10cSrcweir                         Das Dokument konnte nicht gespeichert werden, ein
2614cdf0e10cSrcweir                         Fehlercode ist mit <SvMedium::GetError()const> zu
2615cdf0e10cSrcweir                         erhalten.
2616cdf0e10cSrcweir 
2617cdf0e10cSrcweir 
2618cdf0e10cSrcweir     [Beispiel]
2619cdf0e10cSrcweir 
2620cdf0e10cSrcweir     sal_Bool DocSh::ConvertTo( SfxMedium &rMedium )
2621cdf0e10cSrcweir     {
2622cdf0e10cSrcweir         SvStreamRef xStream = rMedium.GetOutStream();
2623cdf0e10cSrcweir         if ( xStream.is() )
2624cdf0e10cSrcweir         {
2625cdf0e10cSrcweir             xStream->SetBufferSize(4096);
2626cdf0e10cSrcweir             *xStream << ...;
2627cdf0e10cSrcweir 
2628cdf0e10cSrcweir             rMedium.CloseOutStream(); // "offnet automatisch wieder den InStream
2629cdf0e10cSrcweir             return SVSTREAM_OK == rMedium.GetError();
2630cdf0e10cSrcweir         }
2631cdf0e10cSrcweir         return sal_False ;
2632cdf0e10cSrcweir     }
2633cdf0e10cSrcweir 
2634cdf0e10cSrcweir 
2635cdf0e10cSrcweir     [Querverweise]
2636cdf0e10cSrcweir 
2637cdf0e10cSrcweir     <SfxObjectShell::ConvertFrom(SfxMedium&)>
2638cdf0e10cSrcweir     <SFX_FILTER_REGISTRATION>
2639cdf0e10cSrcweir */
2640cdf0e10cSrcweir 
2641cdf0e10cSrcweir {
2642cdf0e10cSrcweir     return sal_False;
2643cdf0e10cSrcweir }
2644cdf0e10cSrcweir 
2645cdf0e10cSrcweir //-------------------------------------------------------------------------
2646cdf0e10cSrcweir 
DoSave_Impl(const SfxItemSet * pArgs)2647cdf0e10cSrcweir sal_Bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs )
2648cdf0e10cSrcweir {
2649cdf0e10cSrcweir     SfxMedium* pRetrMedium = GetMedium();
2650cdf0e10cSrcweir     const SfxFilter* pFilter = pRetrMedium->GetFilter();
2651cdf0e10cSrcweir 
2652cdf0e10cSrcweir     // copy the original itemset, but remove the "version" item, because pMediumTmp
2653cdf0e10cSrcweir     // is a new medium "from scratch", so no version should be stored into it
2654cdf0e10cSrcweir     SfxItemSet* pSet = new SfxAllItemSet(*pRetrMedium->GetItemSet());
2655cdf0e10cSrcweir     pSet->ClearItem( SID_VERSION );
2656cdf0e10cSrcweir     pSet->ClearItem( SID_DOC_BASEURL );
2657cdf0e10cSrcweir 
2658cdf0e10cSrcweir     // create a medium as a copy; this medium is only for writingm, because it uses the same name as the original one
2659cdf0e10cSrcweir     // writing is done through a copy, that will be transferred to the target ( of course after calling HandsOff )
2660cdf0e10cSrcweir     SfxMedium* pMediumTmp = new SfxMedium( pRetrMedium->GetName(), pRetrMedium->GetOpenMode(), pRetrMedium->IsDirect(), pFilter, pSet );
2661cdf0e10cSrcweir     pMediumTmp->SetLongName( pRetrMedium->GetLongName() );
2662cdf0e10cSrcweir //    pMediumTmp->CreateTempFileNoCopy();
2663cdf0e10cSrcweir     if ( pMediumTmp->GetErrorCode() != ERRCODE_NONE )
2664cdf0e10cSrcweir     {
2665cdf0e10cSrcweir         SetError( pMediumTmp->GetError(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2666cdf0e10cSrcweir         delete pMediumTmp;
2667cdf0e10cSrcweir         return sal_False;
2668cdf0e10cSrcweir     }
2669cdf0e10cSrcweir 
2670cdf0e10cSrcweir     // copy version list from "old" medium to target medium, so it can be used on saving
2671cdf0e10cSrcweir     pMediumTmp->TransferVersionList_Impl( *pRetrMedium );
2672cdf0e10cSrcweir /*
2673cdf0e10cSrcweir     if ( pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_PACKED ) )
2674cdf0e10cSrcweir         SetError( GetMedium()->Unpack_Impl( pRetrMedium->GetPhysicalName() ), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2675cdf0e10cSrcweir */
2676cdf0e10cSrcweir 
2677cdf0e10cSrcweir     // an interaction handler here can aquire only in case of GUI Saving
2678cdf0e10cSrcweir     // and should be removed after the saving is done
2679cdf0e10cSrcweir     com::sun::star::uno::Reference< XInteractionHandler > xInteract;
2680cdf0e10cSrcweir     SFX_ITEMSET_ARG( pArgs, pxInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False );
2681cdf0e10cSrcweir     if ( pxInteractionItem && ( pxInteractionItem->GetValue() >>= xInteract ) && xInteract.is() )
2682cdf0e10cSrcweir         pMediumTmp->GetItemSet()->Put( SfxUnoAnyItem( SID_INTERACTIONHANDLER, makeAny( xInteract ) ) );
2683cdf0e10cSrcweir 
2684cdf0e10cSrcweir     sal_Bool bSaved = sal_False;
2685cdf0e10cSrcweir     if( !GetError() && SaveTo_Impl( *pMediumTmp, pArgs ) )
2686cdf0e10cSrcweir     {
2687cdf0e10cSrcweir         bSaved = sal_True;
2688cdf0e10cSrcweir 
2689cdf0e10cSrcweir         if( pMediumTmp->GetItemSet() )
2690cdf0e10cSrcweir         {
2691cdf0e10cSrcweir             pMediumTmp->GetItemSet()->ClearItem( SID_INTERACTIONHANDLER );
2692cdf0e10cSrcweir             pMediumTmp->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
2693cdf0e10cSrcweir         }
2694cdf0e10cSrcweir 
2695cdf0e10cSrcweir         SetError(pMediumTmp->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2696cdf0e10cSrcweir 
2697cdf0e10cSrcweir         sal_Bool bOpen( sal_False );
2698cdf0e10cSrcweir         bOpen = DoSaveCompleted( pMediumTmp );
2699cdf0e10cSrcweir         DBG_ASSERT(bOpen,"Fehlerbehandlung fuer DoSaveCompleted nicht implementiert");
2700cdf0e10cSrcweir     }
2701cdf0e10cSrcweir     else
2702cdf0e10cSrcweir     {
2703cdf0e10cSrcweir         // transfer error code from medium to objectshell
2704cdf0e10cSrcweir         SetError( pMediumTmp->GetError(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2705cdf0e10cSrcweir 
2706cdf0e10cSrcweir         // reconnect to object storage
2707cdf0e10cSrcweir         DoSaveCompleted( 0 );
2708cdf0e10cSrcweir 
2709cdf0e10cSrcweir         if( pRetrMedium->GetItemSet() )
2710cdf0e10cSrcweir         {
2711cdf0e10cSrcweir             pRetrMedium->GetItemSet()->ClearItem( SID_INTERACTIONHANDLER );
2712cdf0e10cSrcweir             pRetrMedium->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
2713cdf0e10cSrcweir         }
2714cdf0e10cSrcweir 
2715cdf0e10cSrcweir         delete pMediumTmp;
2716cdf0e10cSrcweir     }
2717cdf0e10cSrcweir 
2718cdf0e10cSrcweir     SetModified( !bSaved );
2719cdf0e10cSrcweir     return bSaved;
2720cdf0e10cSrcweir }
2721cdf0e10cSrcweir 
2722cdf0e10cSrcweir //-------------------------------------------------------------------------
2723cdf0e10cSrcweir 
Save_Impl(const SfxItemSet * pSet)2724cdf0e10cSrcweir sal_Bool SfxObjectShell::Save_Impl( const SfxItemSet* pSet )
2725cdf0e10cSrcweir {
2726cdf0e10cSrcweir     if ( IsReadOnly() )
2727cdf0e10cSrcweir     {
2728cdf0e10cSrcweir         SetError( ERRCODE_SFX_DOCUMENTREADONLY, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2729cdf0e10cSrcweir         return sal_False;
2730cdf0e10cSrcweir     }
2731cdf0e10cSrcweir 
2732cdf0e10cSrcweir     DBG_CHKTHIS(SfxObjectShell, 0);
2733cdf0e10cSrcweir 
2734cdf0e10cSrcweir     pImp->bIsSaving = sal_True;
2735cdf0e10cSrcweir     sal_Bool bSaved = sal_False;
2736cdf0e10cSrcweir     SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
2737cdf0e10cSrcweir     if ( pSalvageItem )
2738cdf0e10cSrcweir     {
2739cdf0e10cSrcweir         SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False);
2740cdf0e10cSrcweir         String aFilterName;
2741cdf0e10cSrcweir         const SfxFilter *pFilter = NULL;
2742cdf0e10cSrcweir         if ( pFilterItem )
2743cdf0e10cSrcweir             pFilter = SfxFilterMatcher( String::CreateFromAscii( GetFactory().GetShortName()) ).GetFilter4FilterName( aFilterName );
2744cdf0e10cSrcweir 
2745cdf0e10cSrcweir         SfxMedium *pMed = new SfxMedium(
2746cdf0e10cSrcweir             pSalvageItem->GetValue(), STREAM_READWRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC, sal_False, pFilter );
2747cdf0e10cSrcweir 
2748cdf0e10cSrcweir         SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False );
2749cdf0e10cSrcweir         if ( pPasswordItem )
2750cdf0e10cSrcweir             pMed->GetItemSet()->Put( *pPasswordItem );
2751cdf0e10cSrcweir 
2752cdf0e10cSrcweir         bSaved = DoSaveAs( *pMed );
2753cdf0e10cSrcweir         if ( bSaved )
2754cdf0e10cSrcweir             bSaved = DoSaveCompleted( pMed );
2755cdf0e10cSrcweir         else
2756cdf0e10cSrcweir             delete pMed;
2757cdf0e10cSrcweir     }
2758cdf0e10cSrcweir     else
2759cdf0e10cSrcweir         bSaved = DoSave_Impl( pSet );
2760cdf0e10cSrcweir     return bSaved;
2761cdf0e10cSrcweir }
2762cdf0e10cSrcweir 
2763cdf0e10cSrcweir //-------------------------------------------------------------------------
2764cdf0e10cSrcweir 
CommonSaveAs_Impl(const INetURLObject & aURL,const String & aFilterName,SfxItemSet * aParams)2765cdf0e10cSrcweir sal_Bool SfxObjectShell::CommonSaveAs_Impl
2766cdf0e10cSrcweir (
2767cdf0e10cSrcweir     const INetURLObject&   aURL,
2768cdf0e10cSrcweir     const String&   aFilterName,
2769cdf0e10cSrcweir     SfxItemSet*     aParams
2770cdf0e10cSrcweir )
2771cdf0e10cSrcweir {
2772cdf0e10cSrcweir     if( aURL.HasError() )
2773cdf0e10cSrcweir     {
2774cdf0e10cSrcweir         SetError( ERRCODE_IO_INVALIDPARAMETER, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2775cdf0e10cSrcweir         return sal_False;
2776cdf0e10cSrcweir     }
2777cdf0e10cSrcweir 
2778cdf0e10cSrcweir     if ( aURL != INetURLObject( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:stream" ) ) ) )
2779cdf0e10cSrcweir     {
2780cdf0e10cSrcweir         // gibt es schon ein Doc mit dem Namen?
2781cdf0e10cSrcweir         SfxObjectShell* pDoc = 0;
2782cdf0e10cSrcweir         for ( SfxObjectShell* pTmp = SfxObjectShell::GetFirst();
2783cdf0e10cSrcweir                 pTmp && !pDoc;
2784cdf0e10cSrcweir                 pTmp = SfxObjectShell::GetNext(*pTmp) )
2785cdf0e10cSrcweir         {
2786cdf0e10cSrcweir             if( ( pTmp != this ) && pTmp->GetMedium() )
2787cdf0e10cSrcweir             {
2788cdf0e10cSrcweir                 INetURLObject aCompare( pTmp->GetMedium()->GetName() );
2789cdf0e10cSrcweir                 if ( aCompare == aURL )
2790cdf0e10cSrcweir                     pDoc = pTmp;
2791cdf0e10cSrcweir             }
2792cdf0e10cSrcweir         }
2793cdf0e10cSrcweir         if ( pDoc )
2794cdf0e10cSrcweir         {
2795cdf0e10cSrcweir             // dann Fehlermeldeung: "schon offen"
2796cdf0e10cSrcweir             SetError(ERRCODE_SFX_ALREADYOPEN, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
2797cdf0e10cSrcweir             return sal_False;
2798cdf0e10cSrcweir         }
2799cdf0e10cSrcweir     }
2800cdf0e10cSrcweir 
2801cdf0e10cSrcweir     DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL!" );
2802cdf0e10cSrcweir     DBG_ASSERT( aParams->Count() != 0, "fehlerhafte Parameter");
2803cdf0e10cSrcweir 
2804cdf0e10cSrcweir     SFX_ITEMSET_ARG( aParams, pSaveToItem, SfxBoolItem, SID_SAVETO, sal_False );
2805cdf0e10cSrcweir     sal_Bool bSaveTo = pSaveToItem ? pSaveToItem->GetValue() : sal_False;
2806cdf0e10cSrcweir 
2807cdf0e10cSrcweir     const SfxFilter* pFilter = GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName );
2808cdf0e10cSrcweir     if ( !pFilter
2809cdf0e10cSrcweir         || !pFilter->CanExport()
2810cdf0e10cSrcweir         || (!bSaveTo && !pFilter->CanImport()) )
2811cdf0e10cSrcweir     {
2812cdf0e10cSrcweir         SetError( ERRCODE_IO_INVALIDPARAMETER, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2813cdf0e10cSrcweir         return sal_False;
2814cdf0e10cSrcweir     }
2815cdf0e10cSrcweir 
2816cdf0e10cSrcweir     SFX_ITEMSET_ARG( aParams, pCopyStreamItem, SfxBoolItem, SID_COPY_STREAM_IF_POSSIBLE, sal_False );
2817cdf0e10cSrcweir     if ( bSaveTo && pCopyStreamItem && pCopyStreamItem->GetValue() && !IsModified() )
2818cdf0e10cSrcweir     {
2819cdf0e10cSrcweir         if ( pMedium->TryDirectTransfer( aURL.GetMainURL( INetURLObject::NO_DECODE ), *aParams ) )
2820cdf0e10cSrcweir             return sal_True;
2821cdf0e10cSrcweir     }
2822cdf0e10cSrcweir     aParams->ClearItem( SID_COPY_STREAM_IF_POSSIBLE );
2823cdf0e10cSrcweir 
2824cdf0e10cSrcweir     pImp->bPasswd = aParams && SFX_ITEM_SET == aParams->GetItemState(SID_PASSWORD);
2825cdf0e10cSrcweir 
2826cdf0e10cSrcweir     SfxMedium *pActMed = GetMedium();
2827cdf0e10cSrcweir     const INetURLObject aActName(pActMed->GetName());
2828cdf0e10cSrcweir 
2829cdf0e10cSrcweir     sal_Bool bWasReadonly = IsReadOnly();
2830cdf0e10cSrcweir 
2831cdf0e10cSrcweir     if ( aURL == aActName && aURL != INetURLObject( OUString::createFromAscii( "private:stream" ) )
2832cdf0e10cSrcweir         && IsReadOnly() )
2833cdf0e10cSrcweir     {
2834cdf0e10cSrcweir         SetError(ERRCODE_SFX_DOCUMENTREADONLY, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
2835cdf0e10cSrcweir         return sal_False;
2836cdf0e10cSrcweir     }
2837cdf0e10cSrcweir 
2838cdf0e10cSrcweir     // this notification should be already sent by caller in sfxbasemodel
2839cdf0e10cSrcweir     // SFX_APP()->NotifyEvent(SfxEventHint( bSaveTo? SFX_EVENT_SAVETODOC : SFX_EVENT_SAVEASDOC,this));
2840cdf0e10cSrcweir 
2841cdf0e10cSrcweir     if( SFX_ITEM_SET != aParams->GetItemState(SID_UNPACK) && SvtSaveOptions().IsSaveUnpacked() )
2842cdf0e10cSrcweir         aParams->Put( SfxBoolItem( SID_UNPACK, sal_False ) );
2843cdf0e10cSrcweir 
2844cdf0e10cSrcweir     ::rtl::OUString aTempFileURL;
2845cdf0e10cSrcweir     if ( IsDocShared() )
2846cdf0e10cSrcweir         aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
2847cdf0e10cSrcweir 
2848cdf0e10cSrcweir     if ( PreDoSaveAs_Impl(aURL.GetMainURL( INetURLObject::NO_DECODE ),aFilterName,aParams))
2849cdf0e10cSrcweir     {
2850cdf0e10cSrcweir         pImp->bWaitingForPicklist = sal_True;
2851cdf0e10cSrcweir 
2852cdf0e10cSrcweir         // Daten am Medium updaten
2853cdf0e10cSrcweir         SfxItemSet *pSet = GetMedium()->GetItemSet();
2854cdf0e10cSrcweir         pSet->ClearItem( SID_INTERACTIONHANDLER );
2855cdf0e10cSrcweir         pSet->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
2856cdf0e10cSrcweir         pSet->ClearItem( SID_STANDARD_DIR );
2857cdf0e10cSrcweir         pSet->ClearItem( SID_PATH );
2858cdf0e10cSrcweir 
2859cdf0e10cSrcweir 		if ( !bSaveTo )
2860cdf0e10cSrcweir 		{
2861cdf0e10cSrcweir 			pSet->ClearItem( SID_REFERER );
2862cdf0e10cSrcweir 			pSet->ClearItem( SID_POSTDATA );
2863cdf0e10cSrcweir 			pSet->ClearItem( SID_TEMPLATE );
2864cdf0e10cSrcweir 			pSet->ClearItem( SID_DOC_READONLY );
2865cdf0e10cSrcweir 			pSet->ClearItem( SID_CONTENTTYPE );
2866cdf0e10cSrcweir 			pSet->ClearItem( SID_CHARSET );
2867cdf0e10cSrcweir 			pSet->ClearItem( SID_FILTER_NAME );
2868cdf0e10cSrcweir 			pSet->ClearItem( SID_OPTIONS );
2869cdf0e10cSrcweir 			//pSet->ClearItem( SID_FILE_FILTEROPTIONS );
2870cdf0e10cSrcweir 			pSet->ClearItem( SID_VERSION );
2871cdf0e10cSrcweir 			pSet->ClearItem( SID_EDITDOC );
2872cdf0e10cSrcweir 			pSet->ClearItem( SID_OVERWRITE );
2873cdf0e10cSrcweir 			pSet->ClearItem( SID_DEFAULTFILEPATH );
2874cdf0e10cSrcweir 			pSet->ClearItem( SID_DEFAULTFILENAME );
2875cdf0e10cSrcweir 
2876cdf0e10cSrcweir             SFX_ITEMSET_GET( (*aParams), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
2877cdf0e10cSrcweir             if ( pFilterItem )
2878cdf0e10cSrcweir                 pSet->Put( *pFilterItem );
2879cdf0e10cSrcweir 
2880cdf0e10cSrcweir             SFX_ITEMSET_GET( (*aParams), pOptionsItem, SfxStringItem, SID_OPTIONS, sal_False );
2881cdf0e10cSrcweir             if ( pOptionsItem )
2882cdf0e10cSrcweir                 pSet->Put( *pOptionsItem );
2883cdf0e10cSrcweir 
2884cdf0e10cSrcweir             SFX_ITEMSET_GET( (*aParams), pFilterOptItem, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False );
2885cdf0e10cSrcweir             if ( pFilterOptItem )
2886cdf0e10cSrcweir                 pSet->Put( *pFilterOptItem );
2887cdf0e10cSrcweir 
2888cdf0e10cSrcweir             if ( IsDocShared() && aTempFileURL.getLength() )
2889cdf0e10cSrcweir             {
2890cdf0e10cSrcweir                 // this is a shared document that has to be disconnected from the old location
2891cdf0e10cSrcweir                 FreeSharedFile( aTempFileURL );
2892cdf0e10cSrcweir 
2893cdf0e10cSrcweir                 if ( pFilter->IsOwnFormat()
2894cdf0e10cSrcweir                   && pFilter->UsesStorage()
2895cdf0e10cSrcweir                   && pFilter->GetVersion() >= SOFFICE_FILEFORMAT_60 )
2896cdf0e10cSrcweir                 {
2897cdf0e10cSrcweir                     // the target format is the own format
2898cdf0e10cSrcweir                     // the target document must be shared
2899cdf0e10cSrcweir                     SwitchToShared( sal_True, sal_False );
2900cdf0e10cSrcweir                 }
2901cdf0e10cSrcweir             }
2902cdf0e10cSrcweir         }
2903cdf0e10cSrcweir 
2904cdf0e10cSrcweir         if ( bWasReadonly && !bSaveTo )
2905cdf0e10cSrcweir             Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
2906cdf0e10cSrcweir 
2907cdf0e10cSrcweir         return sal_True;
2908cdf0e10cSrcweir     }
2909cdf0e10cSrcweir     else
2910cdf0e10cSrcweir         return sal_False;
2911cdf0e10cSrcweir }
2912cdf0e10cSrcweir 
2913cdf0e10cSrcweir //-------------------------------------------------------------------------
2914cdf0e10cSrcweir 
PreDoSaveAs_Impl(const String & rFileName,const String & aFilterName,SfxItemSet * pParams)2915cdf0e10cSrcweir sal_Bool SfxObjectShell::PreDoSaveAs_Impl
2916cdf0e10cSrcweir (
2917cdf0e10cSrcweir     const String&   rFileName,
2918cdf0e10cSrcweir     const String&   aFilterName,
2919cdf0e10cSrcweir     SfxItemSet*     pParams
2920cdf0e10cSrcweir )
2921cdf0e10cSrcweir {
2922cdf0e10cSrcweir     // copy all items stored in the itemset of the current medium
2923cdf0e10cSrcweir     SfxAllItemSet* pMergedParams = new SfxAllItemSet( *pMedium->GetItemSet() );
2924cdf0e10cSrcweir 
2925cdf0e10cSrcweir     // in "SaveAs" title and password will be cleared ( maybe the new itemset contains new values, otherwise they will be empty )
2926cdf0e10cSrcweir     pMergedParams->ClearItem( SID_PASSWORD );
2927f6b63cabSOliver-Rainer Wittmann     // 119366 - As the SID_ENCRYPTIONDATA and SID_PASSWORD are using for setting passward together, we need to clear them both.
2928f6b63cabSOliver-Rainer Wittmann     // Also, ( maybe the new itemset contains new values, otherwise they will be empty )
2929f6b63cabSOliver-Rainer Wittmann     pMergedParams->ClearItem( SID_ENCRYPTIONDATA );
2930cdf0e10cSrcweir     pMergedParams->ClearItem( SID_DOCINFO_TITLE );
2931cdf0e10cSrcweir 
2932cdf0e10cSrcweir     pMergedParams->ClearItem( SID_INPUTSTREAM );
2933cdf0e10cSrcweir     pMergedParams->ClearItem( SID_STREAM );
2934cdf0e10cSrcweir     pMergedParams->ClearItem( SID_CONTENT );
2935cdf0e10cSrcweir     pMergedParams->ClearItem( SID_DOC_READONLY );
2936cdf0e10cSrcweir     pMergedParams->ClearItem( SID_DOC_BASEURL );
2937cdf0e10cSrcweir 
2938cdf0e10cSrcweir     pMergedParams->ClearItem( SID_REPAIRPACKAGE );
2939cdf0e10cSrcweir 
2940cdf0e10cSrcweir     // "SaveAs" will never store any version information - it's a complete new file !
2941cdf0e10cSrcweir     pMergedParams->ClearItem( SID_VERSION );
2942cdf0e10cSrcweir 
2943cdf0e10cSrcweir     // merge the new parameters into the copy
2944cdf0e10cSrcweir     // all values present in both itemsets will be overwritten by the new parameters
2945cdf0e10cSrcweir     if( pParams )
2946cdf0e10cSrcweir         pMergedParams->Put( *pParams );
2947cdf0e10cSrcweir     //DELETEZ( pParams );
2948cdf0e10cSrcweir 
2949cdf0e10cSrcweir #ifdef DBG_UTIL
2950cdf0e10cSrcweir     if ( pMergedParams->GetItemState( SID_DOC_SALVAGE) >= SFX_ITEM_SET )
2951cdf0e10cSrcweir         DBG_ERROR("Salvage item present in Itemset, check the parameters!");
2952cdf0e10cSrcweir #endif
2953cdf0e10cSrcweir 
2954cdf0e10cSrcweir     // should be unneccessary - too hot to handle!
2955cdf0e10cSrcweir     pMergedParams->ClearItem( SID_DOC_SALVAGE );
2956cdf0e10cSrcweir 
2957cdf0e10cSrcweir     // take over the new merged itemset
2958cdf0e10cSrcweir     pParams = pMergedParams;
2959cdf0e10cSrcweir 
2960cdf0e10cSrcweir     // create a medium for the target URL
2961cdf0e10cSrcweir     SfxMedium *pNewFile = new SfxMedium( rFileName, STREAM_READWRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC, sal_False, 0, pParams );
2962cdf0e10cSrcweir 
2963cdf0e10cSrcweir     // set filter; if no filter is given, take the default filter of the factory
2964cdf0e10cSrcweir     if ( aFilterName.Len() )
2965cdf0e10cSrcweir         pNewFile->SetFilter( GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName ) );
2966cdf0e10cSrcweir     else
2967cdf0e10cSrcweir         pNewFile->SetFilter( GetFactory().GetFilterContainer()->GetAnyFilter( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT ) );
2968cdf0e10cSrcweir 
2969cdf0e10cSrcweir     if ( pNewFile->GetErrorCode() != ERRCODE_NONE )
2970cdf0e10cSrcweir     {
2971cdf0e10cSrcweir         // creating temporary file failed ( f.e. floppy disk not inserted! )
2972cdf0e10cSrcweir         SetError( pNewFile->GetError(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2973cdf0e10cSrcweir         delete pNewFile;
2974cdf0e10cSrcweir         return sal_False;
2975cdf0e10cSrcweir     }
2976cdf0e10cSrcweir 
2977cdf0e10cSrcweir     // check if a "SaveTo" is wanted, no "SaveAs"
2978cdf0e10cSrcweir     SFX_ITEMSET_ARG( pParams, pSaveToItem, SfxBoolItem, SID_SAVETO, sal_False );
2979cdf0e10cSrcweir     sal_Bool bCopyTo = GetCreateMode() == SFX_CREATE_MODE_EMBEDDED || (pSaveToItem && pSaveToItem->GetValue());
2980cdf0e10cSrcweir 
2981cdf0e10cSrcweir     // distinguish between "Save" and "SaveAs"
2982cdf0e10cSrcweir     pImp->bIsSaving = sal_False;
2983cdf0e10cSrcweir 
2984cdf0e10cSrcweir     // copy version list from "old" medium to target medium, so it can be used on saving
2985cdf0e10cSrcweir     if ( pImp->bPreserveVersions )
2986cdf0e10cSrcweir         pNewFile->TransferVersionList_Impl( *pMedium );
2987cdf0e10cSrcweir 
2988cdf0e10cSrcweir /*
2989cdf0e10cSrcweir     if ( GetMedium()->GetFilter() && ( GetMedium()->GetFilter()->GetFilterFlags() & SFX_FILTER_PACKED ) )
2990cdf0e10cSrcweir     {
2991cdf0e10cSrcweir         SfxMedium *pMed = bCopyTo ? pMedium : pNewFile;
2992cdf0e10cSrcweir         pNewFile->SetError( GetMedium()->Unpack_Impl( pMed->GetPhysicalName() ) , ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2993cdf0e10cSrcweir     }
2994cdf0e10cSrcweir */
2995cdf0e10cSrcweir     // Save the document ( first as temporary file, then transfer to the target URL by committing the medium )
2996cdf0e10cSrcweir     sal_Bool bOk = sal_False;
2997cdf0e10cSrcweir     if ( !pNewFile->GetErrorCode() && SaveTo_Impl( *pNewFile, NULL ) )
2998cdf0e10cSrcweir     {
2999cdf0e10cSrcweir         bOk = sal_True;
3000cdf0e10cSrcweir 
3001cdf0e10cSrcweir         // transfer a possible error from the medium to the document
3002cdf0e10cSrcweir         SetError( pNewFile->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
3003cdf0e10cSrcweir 
3004cdf0e10cSrcweir         // notify the document that saving was done successfully
3005cdf0e10cSrcweir         if ( !bCopyTo )
3006cdf0e10cSrcweir         {
3007cdf0e10cSrcweir             bOk = DoSaveCompleted( pNewFile );
3008cdf0e10cSrcweir         }
3009cdf0e10cSrcweir         else
3010cdf0e10cSrcweir             bOk = DoSaveCompleted(0);
3011cdf0e10cSrcweir 
3012cdf0e10cSrcweir         if( bOk )
3013cdf0e10cSrcweir         {
3014cdf0e10cSrcweir             if( !bCopyTo )
3015cdf0e10cSrcweir                 SetModified( sal_False );
3016cdf0e10cSrcweir         }
3017cdf0e10cSrcweir         else
3018cdf0e10cSrcweir         {
3019cdf0e10cSrcweir             // TODO/LATER: the code below must be dead since the storage commit makes all the stuff
3020cdf0e10cSrcweir             //		 and the DoSaveCompleted call should not be able to fail in general
3021cdf0e10cSrcweir 
3022cdf0e10cSrcweir             DBG_ASSERT( !bCopyTo, "Error while reconnecting to medium, can't be handled!");
3023cdf0e10cSrcweir             SetError( pNewFile->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
3024cdf0e10cSrcweir 
3025cdf0e10cSrcweir             if ( !bCopyTo )
3026cdf0e10cSrcweir             {
3027cdf0e10cSrcweir                 // reconnect to the old medium
3028cdf0e10cSrcweir                 sal_Bool bRet( sal_False );
3029cdf0e10cSrcweir                 bRet = DoSaveCompleted( pMedium );
3030cdf0e10cSrcweir                 DBG_ASSERT( bRet, "Error in DoSaveCompleted, can't be handled!");
3031cdf0e10cSrcweir             }
3032cdf0e10cSrcweir 
3033cdf0e10cSrcweir             // TODO/LATER: disconnect the new file from the storage for the case when pure saving is done
3034cdf0e10cSrcweir             //		 if storing has corrupted the file, probably it must be restored either here or
3035cdf0e10cSrcweir             //		 by the storage
3036cdf0e10cSrcweir             DELETEZ( pNewFile );
3037cdf0e10cSrcweir         }
3038cdf0e10cSrcweir     }
3039cdf0e10cSrcweir     else
3040cdf0e10cSrcweir     {
3041cdf0e10cSrcweir         SetError( pNewFile->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
3042cdf0e10cSrcweir 
3043cdf0e10cSrcweir         // reconnect to the old storage
3044cdf0e10cSrcweir         DoSaveCompleted( 0 );
3045cdf0e10cSrcweir 
3046cdf0e10cSrcweir         DELETEZ( pNewFile );
3047cdf0e10cSrcweir     }
3048cdf0e10cSrcweir 
3049cdf0e10cSrcweir     if ( bCopyTo )
3050cdf0e10cSrcweir         DELETEZ( pNewFile );
3051cdf0e10cSrcweir     else if( !bOk )
3052cdf0e10cSrcweir         SetModified( sal_True );
3053cdf0e10cSrcweir 
3054cdf0e10cSrcweir     return bOk;
3055cdf0e10cSrcweir }
3056cdf0e10cSrcweir 
3057cdf0e10cSrcweir //------------------------------------------------------------------------
3058cdf0e10cSrcweir 
LoadFrom(SfxMedium &)3059cdf0e10cSrcweir sal_Bool SfxObjectShell::LoadFrom( SfxMedium& /*rMedium*/ )
3060cdf0e10cSrcweir {
3061cdf0e10cSrcweir     DBG_ERROR( "Base implementation, must not be called in general!" );
3062cdf0e10cSrcweir     return sal_True;
3063cdf0e10cSrcweir }
3064cdf0e10cSrcweir 
3065cdf0e10cSrcweir //-------------------------------------------------------------------------
IsInformationLost()3066cdf0e10cSrcweir sal_Bool SfxObjectShell::IsInformationLost()
3067cdf0e10cSrcweir {
3068cdf0e10cSrcweir     Sequence< PropertyValue > aProps = GetModel()->getArgs();
3069cdf0e10cSrcweir     ::rtl::OUString aFilterName;
3070cdf0e10cSrcweir     ::rtl::OUString aPreusedFilterName;
3071cdf0e10cSrcweir     for ( sal_Int32 nInd = 0; nInd < aProps.getLength(); nInd++ )
3072cdf0e10cSrcweir     {
3073cdf0e10cSrcweir         if ( aProps[nInd].Name.equalsAscii( "FilterName" ) )
3074cdf0e10cSrcweir             aProps[nInd].Value >>= aFilterName;
3075cdf0e10cSrcweir         else if ( aProps[nInd].Name.equalsAscii( "PreusedFilterName" ) )
3076cdf0e10cSrcweir             aProps[nInd].Value >>= aPreusedFilterName;
3077cdf0e10cSrcweir     }
3078cdf0e10cSrcweir 
3079cdf0e10cSrcweir     // if current filter can lead to information loss and it was used
3080cdf0e10cSrcweir     // for the latest store then the user should be asked to store in own format
3081cdf0e10cSrcweir     if ( aFilterName.getLength() && aFilterName.equals( aPreusedFilterName ) )
3082cdf0e10cSrcweir     {
3083cdf0e10cSrcweir         const SfxFilter *pFilt = GetMedium()->GetFilter();
3084cdf0e10cSrcweir         DBG_ASSERT( pFilt && aFilterName.equals( pFilt->GetName() ), "MediaDescriptor contains wrong filter!\n" );
3085cdf0e10cSrcweir         return ( pFilt && pFilt->IsAlienFormat() );
3086cdf0e10cSrcweir     }
3087cdf0e10cSrcweir 
3088cdf0e10cSrcweir     return sal_False;
3089cdf0e10cSrcweir }
3090cdf0e10cSrcweir 
3091cdf0e10cSrcweir //-------------------------------------------------------------------------
CanReload_Impl()3092cdf0e10cSrcweir sal_Bool SfxObjectShell::CanReload_Impl()
3093cdf0e10cSrcweir 
3094cdf0e10cSrcweir /*  [Beschreibung]
3095cdf0e10cSrcweir 
3096cdf0e10cSrcweir     Interne Methode zum Feststellen, ob eine erneutes Laden des
3097cdf0e10cSrcweir     Dokuments (auch als RevertToSaved oder LastVersion bekannt)
3098cdf0e10cSrcweir     m"oglich ist.
3099cdf0e10cSrcweir */
3100cdf0e10cSrcweir 
3101cdf0e10cSrcweir {
3102cdf0e10cSrcweir     return pMedium && HasName() && !IsInModalMode() && !pImp->bForbidReload;
3103cdf0e10cSrcweir }
3104cdf0e10cSrcweir 
3105cdf0e10cSrcweir //-------------------------------------------------------------------------
3106cdf0e10cSrcweir 
GetHiddenInformationState(sal_uInt16 nStates)3107cdf0e10cSrcweir sal_uInt16 SfxObjectShell::GetHiddenInformationState( sal_uInt16 nStates )
3108cdf0e10cSrcweir {
3109cdf0e10cSrcweir     sal_uInt16 nState = 0;
3110cdf0e10cSrcweir     if ( nStates & HIDDENINFORMATION_DOCUMENTVERSIONS )
3111cdf0e10cSrcweir     {
3112cdf0e10cSrcweir         if ( GetMedium()->GetVersionList().getLength() )
3113cdf0e10cSrcweir             nState |= HIDDENINFORMATION_DOCUMENTVERSIONS;
3114cdf0e10cSrcweir     }
3115cdf0e10cSrcweir 
3116cdf0e10cSrcweir     return nState;
3117cdf0e10cSrcweir }
3118cdf0e10cSrcweir 
QueryHiddenInformation(HiddenWarningFact eFact,Window * pParent)3119cdf0e10cSrcweir sal_Int16 SfxObjectShell::QueryHiddenInformation( HiddenWarningFact eFact, Window* pParent )
3120cdf0e10cSrcweir {
3121cdf0e10cSrcweir     sal_Int16 nRet = RET_YES;
3122cdf0e10cSrcweir     sal_uInt16 nResId = 0;
3123cdf0e10cSrcweir     SvtSecurityOptions::EOption eOption = static_cast< SvtSecurityOptions::EOption >( -1 );
3124cdf0e10cSrcweir 
3125cdf0e10cSrcweir     switch ( eFact )
3126cdf0e10cSrcweir     {
3127cdf0e10cSrcweir         case WhenSaving :
3128cdf0e10cSrcweir         {
3129cdf0e10cSrcweir             nResId = STR_HIDDENINFO_CONTINUE_SAVING;
3130cdf0e10cSrcweir             eOption = SvtSecurityOptions::E_DOCWARN_SAVEORSEND;
3131cdf0e10cSrcweir             break;
3132cdf0e10cSrcweir         }
3133cdf0e10cSrcweir         case WhenPrinting :
3134cdf0e10cSrcweir         {
3135cdf0e10cSrcweir             nResId = STR_HIDDENINFO_CONTINUE_PRINTING;
3136cdf0e10cSrcweir             eOption = SvtSecurityOptions::E_DOCWARN_PRINT;
3137cdf0e10cSrcweir             break;
3138cdf0e10cSrcweir         }
3139cdf0e10cSrcweir         case WhenSigning :
3140cdf0e10cSrcweir         {
3141cdf0e10cSrcweir             nResId = STR_HIDDENINFO_CONTINUE_SIGNING;
3142cdf0e10cSrcweir             eOption = SvtSecurityOptions::E_DOCWARN_SIGNING;
3143cdf0e10cSrcweir             break;
3144cdf0e10cSrcweir         }
3145cdf0e10cSrcweir         case WhenCreatingPDF :
3146cdf0e10cSrcweir         {
3147cdf0e10cSrcweir             nResId = STR_HIDDENINFO_CONTINUE_CREATEPDF;
3148cdf0e10cSrcweir             eOption = SvtSecurityOptions::E_DOCWARN_CREATEPDF;
3149cdf0e10cSrcweir             break;
3150cdf0e10cSrcweir         }
3151cdf0e10cSrcweir         default:
3152cdf0e10cSrcweir         {
3153cdf0e10cSrcweir             DBG_ERRORFILE( "SfxObjectShell::DetectHiddenInformation(): what fact?" );
3154cdf0e10cSrcweir         }
3155cdf0e10cSrcweir     }
3156cdf0e10cSrcweir 
3157cdf0e10cSrcweir     if ( eOption != -1 && SvtSecurityOptions().IsOptionSet( eOption ) )
3158cdf0e10cSrcweir     {
3159cdf0e10cSrcweir         String sMessage( SfxResId( STR_HIDDENINFO_CONTAINS ) );
3160cdf0e10cSrcweir         sal_uInt16 nWantedStates = HIDDENINFORMATION_RECORDEDCHANGES | HIDDENINFORMATION_NOTES;
3161cdf0e10cSrcweir         if ( eFact != WhenPrinting )
3162cdf0e10cSrcweir             nWantedStates |= HIDDENINFORMATION_DOCUMENTVERSIONS;
3163cdf0e10cSrcweir         sal_uInt16 nStates = GetHiddenInformationState( nWantedStates );
3164cdf0e10cSrcweir         bool bWarning = false;
3165cdf0e10cSrcweir 
3166cdf0e10cSrcweir         if ( ( nStates & HIDDENINFORMATION_RECORDEDCHANGES ) == HIDDENINFORMATION_RECORDEDCHANGES )
3167cdf0e10cSrcweir         {
3168cdf0e10cSrcweir             sMessage += String( SfxResId( STR_HIDDENINFO_RECORDCHANGES ) );
3169cdf0e10cSrcweir             sMessage += '\n';
3170cdf0e10cSrcweir             bWarning = true;
3171cdf0e10cSrcweir         }
3172cdf0e10cSrcweir         if ( ( nStates & HIDDENINFORMATION_NOTES ) == HIDDENINFORMATION_NOTES )
3173cdf0e10cSrcweir         {
3174cdf0e10cSrcweir             sMessage += String( SfxResId( STR_HIDDENINFO_NOTES ) );
3175cdf0e10cSrcweir             sMessage += '\n';
3176cdf0e10cSrcweir             bWarning = true;
3177cdf0e10cSrcweir         }
3178cdf0e10cSrcweir         if ( ( nStates & HIDDENINFORMATION_DOCUMENTVERSIONS ) == HIDDENINFORMATION_DOCUMENTVERSIONS )
3179cdf0e10cSrcweir         {
3180cdf0e10cSrcweir             sMessage += String( SfxResId( STR_HIDDENINFO_DOCVERSIONS ) );
3181cdf0e10cSrcweir             sMessage += '\n';
3182cdf0e10cSrcweir             bWarning = true;
3183cdf0e10cSrcweir         }
3184cdf0e10cSrcweir 
3185cdf0e10cSrcweir         if ( bWarning )
3186cdf0e10cSrcweir         {
3187cdf0e10cSrcweir             sMessage += '\n';
3188cdf0e10cSrcweir             sMessage += String( SfxResId( nResId ) );
3189cdf0e10cSrcweir             WarningBox aWBox( pParent, WB_YES_NO | WB_DEF_NO, sMessage );
3190cdf0e10cSrcweir             nRet = aWBox.Execute();
3191cdf0e10cSrcweir         }
3192cdf0e10cSrcweir     }
3193cdf0e10cSrcweir 
3194cdf0e10cSrcweir     return nRet;
3195cdf0e10cSrcweir }
3196cdf0e10cSrcweir 
HasSecurityOptOpenReadOnly() const3197cdf0e10cSrcweir sal_Bool SfxObjectShell::HasSecurityOptOpenReadOnly() const
3198cdf0e10cSrcweir {
3199cdf0e10cSrcweir     return sal_True;
3200cdf0e10cSrcweir }
3201cdf0e10cSrcweir 
IsSecurityOptOpenReadOnly() const3202cdf0e10cSrcweir sal_Bool SfxObjectShell::IsSecurityOptOpenReadOnly() const
3203cdf0e10cSrcweir {
3204cdf0e10cSrcweir     return IsLoadReadonly();
3205cdf0e10cSrcweir }
3206cdf0e10cSrcweir 
SetSecurityOptOpenReadOnly(sal_Bool _b)3207cdf0e10cSrcweir void SfxObjectShell::SetSecurityOptOpenReadOnly( sal_Bool _b )
3208cdf0e10cSrcweir {
3209cdf0e10cSrcweir     SetLoadReadonly( _b );
3210cdf0e10cSrcweir }
3211cdf0e10cSrcweir 
LoadOwnFormat(SfxMedium & rMedium)3212cdf0e10cSrcweir sal_Bool SfxObjectShell::LoadOwnFormat( SfxMedium& rMedium )
3213cdf0e10cSrcweir {
3214cdf0e10cSrcweir     RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "PERFORMANCE SfxObjectShell::LoadOwnFormat" );
3215cdf0e10cSrcweir     if( RTL_LOGFILE_HASLOGFILE() )
3216cdf0e10cSrcweir     {
3217cdf0e10cSrcweir         ByteString aString( rMedium.GetName(), RTL_TEXTENCODING_ASCII_US );
3218cdf0e10cSrcweir         RTL_LOGFILE_PRODUCT_CONTEXT_TRACE1( aLog, "loading \"%s\"", aString.GetBuffer() );
3219cdf0e10cSrcweir     }
3220cdf0e10cSrcweir 
3221cdf0e10cSrcweir     uno::Reference< embed::XStorage > xStorage = rMedium.GetStorage();
3222cdf0e10cSrcweir     if ( xStorage.is() )
3223cdf0e10cSrcweir     {
3224cdf0e10cSrcweir         // Password
3225cdf0e10cSrcweir         SFX_ITEMSET_ARG( rMedium.GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False );
3226cdf0e10cSrcweir         if ( pPasswdItem || ERRCODE_IO_ABORT != CheckPasswd_Impl( this, SFX_APP()->GetPool(), pMedium ) )
3227cdf0e10cSrcweir         {
3228cdf0e10cSrcweir             uno::Sequence< beans::NamedValue > aEncryptionData;
3229cdf0e10cSrcweir             if ( GetEncryptionData_Impl(pMedium->GetItemSet(), aEncryptionData) )
3230cdf0e10cSrcweir             {
3231cdf0e10cSrcweir                 try
3232cdf0e10cSrcweir                 {
3233cdf0e10cSrcweir                     // the following code must throw an exception in case of failure
3234cdf0e10cSrcweir                     ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( xStorage, aEncryptionData );
3235cdf0e10cSrcweir                 }
3236cdf0e10cSrcweir                 catch( uno::Exception& )
3237cdf0e10cSrcweir                 {
3238cdf0e10cSrcweir                     // TODO/LATER: handle the error code
3239cdf0e10cSrcweir                 }
3240cdf0e10cSrcweir             }
3241cdf0e10cSrcweir 
3242cdf0e10cSrcweir             // load document
3243cdf0e10cSrcweir             return Load( rMedium );
3244cdf0e10cSrcweir         }
3245cdf0e10cSrcweir         return sal_False;
3246cdf0e10cSrcweir     }
3247cdf0e10cSrcweir     else
3248cdf0e10cSrcweir         return sal_False;
3249cdf0e10cSrcweir }
3250cdf0e10cSrcweir 
SaveAsOwnFormat(SfxMedium & rMedium)3251cdf0e10cSrcweir sal_Bool SfxObjectShell::SaveAsOwnFormat( SfxMedium& rMedium )
3252cdf0e10cSrcweir {
3253cdf0e10cSrcweir     uno::Reference< embed::XStorage > xStorage = rMedium.GetStorage();
3254cdf0e10cSrcweir     if( xStorage.is() )
3255cdf0e10cSrcweir     {
3256cdf0e10cSrcweir         sal_Int32 nVersion = rMedium.GetFilter()->GetVersion();
3257cdf0e10cSrcweir 
3258cdf0e10cSrcweir         // OASIS templates have own mediatypes ( SO7 also actually, but it is to late to use them here )
3259cdf0e10cSrcweir         sal_Bool bTemplate = ( rMedium.GetFilter()->IsOwnTemplateFormat() && nVersion > SOFFICE_FILEFORMAT_60 );
3260cdf0e10cSrcweir 
3261cdf0e10cSrcweir         SetupStorage( xStorage, nVersion, bTemplate );
3262cdf0e10cSrcweir 
3263cdf0e10cSrcweir         if ( HasBasic() )
3264cdf0e10cSrcweir         {
3265cdf0e10cSrcweir             // Initialize Basic
3266cdf0e10cSrcweir             GetBasicManager();
3267cdf0e10cSrcweir 
3268cdf0e10cSrcweir             // Save dialog/script container
3269cdf0e10cSrcweir             pImp->pBasicManager->storeLibrariesToStorage( xStorage );
3270cdf0e10cSrcweir         }
3271cdf0e10cSrcweir 
3272cdf0e10cSrcweir         return SaveAs( rMedium );
3273cdf0e10cSrcweir     }
3274cdf0e10cSrcweir     else return sal_False;
3275cdf0e10cSrcweir }
3276cdf0e10cSrcweir 
GetStorage()3277cdf0e10cSrcweir uno::Reference< embed::XStorage > SfxObjectShell::GetStorage()
3278cdf0e10cSrcweir {
3279cdf0e10cSrcweir     if ( !pImp->m_xDocStorage.is() )
3280cdf0e10cSrcweir     {
3281cdf0e10cSrcweir         OSL_ENSURE( pImp->m_bCreateTempStor, "The storage must exist already!\n" );
3282cdf0e10cSrcweir         try {
3283cdf0e10cSrcweir             // no notification is required the storage is set the first time
3284cdf0e10cSrcweir             pImp->m_xDocStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
3285cdf0e10cSrcweir             OSL_ENSURE( pImp->m_xDocStorage.is(), "The method must either return storage or throw an exception!" );
3286cdf0e10cSrcweir 
3287cdf0e10cSrcweir             SetupStorage( pImp->m_xDocStorage, SOFFICE_FILEFORMAT_CURRENT, sal_False );
3288cdf0e10cSrcweir             pImp->m_bCreateTempStor = sal_False;
3289cdf0e10cSrcweir             SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_STORAGECHANGED, GlobalEventConfig::GetEventName(STR_EVENT_STORAGECHANGED), this ) );
3290cdf0e10cSrcweir         }
3291cdf0e10cSrcweir         catch( uno::Exception& )
3292cdf0e10cSrcweir         {
3293cdf0e10cSrcweir             // TODO/LATER: error handling?
3294cdf0e10cSrcweir         }
3295cdf0e10cSrcweir     }
3296cdf0e10cSrcweir 
3297cdf0e10cSrcweir     OSL_ENSURE( pImp->m_xDocStorage.is(), "The document storage must be created!" );
3298cdf0e10cSrcweir     return pImp->m_xDocStorage;
3299cdf0e10cSrcweir }
3300cdf0e10cSrcweir 
3301cdf0e10cSrcweir 
SaveChildren(sal_Bool bObjectsOnly)3302cdf0e10cSrcweir sal_Bool SfxObjectShell::SaveChildren( sal_Bool bObjectsOnly )
3303cdf0e10cSrcweir {
3304cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::SaveChildren" );
3305cdf0e10cSrcweir 
3306cdf0e10cSrcweir     sal_Bool bResult = sal_True;
3307cdf0e10cSrcweir     if ( pImp->mpObjectContainer )
3308cdf0e10cSrcweir     {
3309cdf0e10cSrcweir         sal_Bool bOasis = ( SotStorage::GetVersion( GetStorage() ) > SOFFICE_FILEFORMAT_60 );
3310cdf0e10cSrcweir         GetEmbeddedObjectContainer().StoreChildren(bOasis,bObjectsOnly);
3311cdf0e10cSrcweir     }
3312cdf0e10cSrcweir 
3313cdf0e10cSrcweir     return bResult;
3314cdf0e10cSrcweir }
3315cdf0e10cSrcweir 
SaveAsChildren(SfxMedium & rMedium)3316cdf0e10cSrcweir sal_Bool SfxObjectShell::SaveAsChildren( SfxMedium& rMedium )
3317cdf0e10cSrcweir {
3318cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::SaveAsChildren" );
3319cdf0e10cSrcweir 
3320cdf0e10cSrcweir     sal_Bool bResult = sal_True;
3321cdf0e10cSrcweir 
3322cdf0e10cSrcweir     uno::Reference < embed::XStorage > xStorage = rMedium.GetStorage();
3323cdf0e10cSrcweir     if ( !xStorage.is() )
3324cdf0e10cSrcweir         return sal_False;
3325cdf0e10cSrcweir 
3326cdf0e10cSrcweir     if ( xStorage == GetStorage() )
3327cdf0e10cSrcweir         return SaveChildren();
3328cdf0e10cSrcweir 
3329cdf0e10cSrcweir     sal_Bool bOasis = sal_True;
3330cdf0e10cSrcweir     if ( pImp->mpObjectContainer )
3331cdf0e10cSrcweir     {
3332cdf0e10cSrcweir         bOasis = ( SotStorage::GetVersion( xStorage ) > SOFFICE_FILEFORMAT_60 );
3333cdf0e10cSrcweir         GetEmbeddedObjectContainer().StoreAsChildren(bOasis,SFX_CREATE_MODE_EMBEDDED == eCreateMode,xStorage);
3334cdf0e10cSrcweir     }
3335cdf0e10cSrcweir 
3336cdf0e10cSrcweir     if ( bResult )
3337cdf0e10cSrcweir         bResult = CopyStoragesOfUnknownMediaType( GetStorage(), xStorage );
3338cdf0e10cSrcweir 
3339cdf0e10cSrcweir     return bResult;
3340cdf0e10cSrcweir }
3341cdf0e10cSrcweir 
SaveCompletedChildren(sal_Bool bSuccess)3342cdf0e10cSrcweir sal_Bool SfxObjectShell::SaveCompletedChildren( sal_Bool bSuccess )
3343cdf0e10cSrcweir {
3344cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::SaveCompletedChildren" );
3345cdf0e10cSrcweir 
3346cdf0e10cSrcweir     sal_Bool bResult = sal_True;
3347cdf0e10cSrcweir 
3348cdf0e10cSrcweir     if ( pImp->mpObjectContainer )
3349cdf0e10cSrcweir     {
3350cdf0e10cSrcweir         uno::Sequence < ::rtl::OUString > aNames = GetEmbeddedObjectContainer().GetObjectNames();
3351cdf0e10cSrcweir         for ( sal_Int32 n=0; n<aNames.getLength(); n++ )
3352cdf0e10cSrcweir         {
3353cdf0e10cSrcweir             uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObjectContainer().GetEmbeddedObject( aNames[n] );
3354cdf0e10cSrcweir             OSL_ENSURE( xObj.is(), "An empty entry in the embedded objects list!\n" );
3355cdf0e10cSrcweir             if ( xObj.is() )
3356cdf0e10cSrcweir             {
3357cdf0e10cSrcweir                 uno::Reference< embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
3358cdf0e10cSrcweir                 if ( xPersist.is() )
3359cdf0e10cSrcweir                 {
3360cdf0e10cSrcweir                     try
3361cdf0e10cSrcweir                     {
3362cdf0e10cSrcweir                         xPersist->saveCompleted( bSuccess );
3363cdf0e10cSrcweir                     }
3364cdf0e10cSrcweir                     catch( uno::Exception& )
3365cdf0e10cSrcweir                     {
3366cdf0e10cSrcweir                         // TODO/LATER: error handling
3367cdf0e10cSrcweir                         bResult = sal_False;
3368cdf0e10cSrcweir                         break;
3369cdf0e10cSrcweir                     }
3370cdf0e10cSrcweir                 }
3371cdf0e10cSrcweir             }
3372cdf0e10cSrcweir         }
3373cdf0e10cSrcweir     }
3374cdf0e10cSrcweir 
3375cdf0e10cSrcweir     return bResult;
3376cdf0e10cSrcweir }
3377cdf0e10cSrcweir 
SwitchChildrenPersistance(const uno::Reference<embed::XStorage> & xStorage,sal_Bool bForceNonModified)3378cdf0e10cSrcweir sal_Bool SfxObjectShell::SwitchChildrenPersistance( const uno::Reference< embed::XStorage >& xStorage,
3379cdf0e10cSrcweir                                                     sal_Bool bForceNonModified )
3380cdf0e10cSrcweir {
3381cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::SwitchChildrenPersistence" );
3382cdf0e10cSrcweir 
3383cdf0e10cSrcweir     if ( !xStorage.is() )
3384cdf0e10cSrcweir     {
3385cdf0e10cSrcweir         // TODO/LATER: error handling
3386cdf0e10cSrcweir         return sal_False;
3387cdf0e10cSrcweir     }
3388cdf0e10cSrcweir 
3389cdf0e10cSrcweir     sal_Bool bResult = sal_True;
3390cdf0e10cSrcweir 
3391cdf0e10cSrcweir     if ( pImp->mpObjectContainer )
3392cdf0e10cSrcweir         pImp->mpObjectContainer->SetPersistentEntries(xStorage,bForceNonModified);
3393cdf0e10cSrcweir 
3394cdf0e10cSrcweir     return bResult;
3395cdf0e10cSrcweir }
3396cdf0e10cSrcweir 
3397cdf0e10cSrcweir // Never call this method directly, always use the DoSaveCompleted call
SaveCompleted(const uno::Reference<embed::XStorage> & xStorage)3398cdf0e10cSrcweir sal_Bool SfxObjectShell::SaveCompleted( const uno::Reference< embed::XStorage >& xStorage )
3399cdf0e10cSrcweir {
3400cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::SaveCompleted" );
3401cdf0e10cSrcweir 
3402cdf0e10cSrcweir     sal_Bool bResult = sal_False;
3403cdf0e10cSrcweir     sal_Bool bSendNotification = sal_False;
3404cdf0e10cSrcweir     uno::Reference< embed::XStorage > xOldStorageHolder;
3405cdf0e10cSrcweir 
3406cdf0e10cSrcweir #ifdef DBG_UTIL
3407cdf0e10cSrcweir     // check for wrong creation of object container
3408cdf0e10cSrcweir     sal_Bool bHasContainer = ( pImp->mpObjectContainer != 0 );
3409cdf0e10cSrcweir #endif
3410cdf0e10cSrcweir 
3411cdf0e10cSrcweir     if ( !xStorage.is() || xStorage == GetStorage() )
3412cdf0e10cSrcweir     {
3413cdf0e10cSrcweir         // no persistence change
3414cdf0e10cSrcweir         bResult = SaveCompletedChildren( sal_False );
3415cdf0e10cSrcweir     }
3416cdf0e10cSrcweir     else
3417cdf0e10cSrcweir     {
3418cdf0e10cSrcweir         if ( pImp->mpObjectContainer )
3419cdf0e10cSrcweir             GetEmbeddedObjectContainer().SwitchPersistence( xStorage );
3420cdf0e10cSrcweir 
3421cdf0e10cSrcweir         bResult = SwitchChildrenPersistance( xStorage, sal_True );
3422cdf0e10cSrcweir     }
3423cdf0e10cSrcweir 
3424cdf0e10cSrcweir     if ( bResult )
3425cdf0e10cSrcweir     {
3426cdf0e10cSrcweir         if ( xStorage.is() && pImp->m_xDocStorage != xStorage )
3427cdf0e10cSrcweir         {
3428cdf0e10cSrcweir             // make sure that until the storage is assigned the object container is not created by accident!
3429cdf0e10cSrcweir             DBG_ASSERT( bHasContainer == (pImp->mpObjectContainer != 0), "Wrong storage in object container!" );
3430cdf0e10cSrcweir             xOldStorageHolder = pImp->m_xDocStorage;
3431cdf0e10cSrcweir             pImp->m_xDocStorage = xStorage;
3432cdf0e10cSrcweir             bSendNotification = sal_True;
3433cdf0e10cSrcweir 
3434cdf0e10cSrcweir             if ( IsEnableSetModified() )
3435cdf0e10cSrcweir                 SetModified( sal_False );
3436cdf0e10cSrcweir         }
3437cdf0e10cSrcweir     }
3438cdf0e10cSrcweir     else
3439cdf0e10cSrcweir     {
3440cdf0e10cSrcweir         if ( pImp->mpObjectContainer )
3441cdf0e10cSrcweir             GetEmbeddedObjectContainer().SwitchPersistence( pImp->m_xDocStorage );
3442cdf0e10cSrcweir 
3443cdf0e10cSrcweir         // let already successfully connected objects be switched back
3444cdf0e10cSrcweir         SwitchChildrenPersistance( pImp->m_xDocStorage, sal_True );
3445cdf0e10cSrcweir     }
3446cdf0e10cSrcweir 
3447cdf0e10cSrcweir     if ( bSendNotification )
3448cdf0e10cSrcweir     {
3449cdf0e10cSrcweir         SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_STORAGECHANGED, GlobalEventConfig::GetEventName(STR_EVENT_STORAGECHANGED), this ) );
3450cdf0e10cSrcweir     }
3451cdf0e10cSrcweir 
3452cdf0e10cSrcweir     return bResult;
3453cdf0e10cSrcweir }
3454cdf0e10cSrcweir 
3455cdf0e10cSrcweir 
StoragesOfUnknownMediaTypeAreCopied_Impl(const uno::Reference<embed::XStorage> & xSource,const uno::Reference<embed::XStorage> & xTarget)3456cdf0e10cSrcweir sal_Bool StoragesOfUnknownMediaTypeAreCopied_Impl( const uno::Reference< embed::XStorage >& xSource,
3457cdf0e10cSrcweir                                                    const uno::Reference< embed::XStorage >& xTarget )
3458cdf0e10cSrcweir {
3459cdf0e10cSrcweir     OSL_ENSURE( xSource.is() && xTarget.is(), "Source and/or target storages are not available!\n" );
3460cdf0e10cSrcweir     if ( !xSource.is() || !xTarget.is() || xSource == xTarget )
3461cdf0e10cSrcweir         return sal_True;
3462cdf0e10cSrcweir 
3463cdf0e10cSrcweir     try
3464cdf0e10cSrcweir     {
3465cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString > aSubElements = xSource->getElementNames();
3466cdf0e10cSrcweir         for ( sal_Int32 nInd = 0; nInd < aSubElements.getLength(); nInd++ )
3467cdf0e10cSrcweir         {
3468cdf0e10cSrcweir             if ( xSource->isStorageElement( aSubElements[nInd] ) )
3469cdf0e10cSrcweir             {
3470cdf0e10cSrcweir                 ::rtl::OUString aMediaType;
3471cdf0e10cSrcweir                 ::rtl::OUString aMediaTypePropName( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
3472cdf0e10cSrcweir                 sal_Bool bGotMediaType = sal_False;
3473cdf0e10cSrcweir 
3474cdf0e10cSrcweir                 try
3475cdf0e10cSrcweir                 {
3476cdf0e10cSrcweir                     uno::Reference< embed::XOptimizedStorage > xOptStorage( xSource, uno::UNO_QUERY_THROW );
3477cdf0e10cSrcweir                     bGotMediaType =
3478cdf0e10cSrcweir                         ( xOptStorage->getElementPropertyValue( aSubElements[nInd], aMediaTypePropName ) >>= aMediaType );
3479cdf0e10cSrcweir                 }
3480cdf0e10cSrcweir                 catch( uno::Exception& )
3481cdf0e10cSrcweir                 {}
3482cdf0e10cSrcweir 
3483cdf0e10cSrcweir                 if ( !bGotMediaType )
3484cdf0e10cSrcweir                 {
3485cdf0e10cSrcweir                     uno::Reference< embed::XStorage > xSubStorage;
3486cdf0e10cSrcweir                     try {
3487cdf0e10cSrcweir                         xSubStorage = xSource->openStorageElement( aSubElements[nInd], embed::ElementModes::READ );
3488cdf0e10cSrcweir                     } catch( uno::Exception& )
3489cdf0e10cSrcweir                     {}
3490cdf0e10cSrcweir 
3491cdf0e10cSrcweir                     if ( !xSubStorage.is() )
3492cdf0e10cSrcweir                     {
3493cdf0e10cSrcweir                         xSubStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
3494cdf0e10cSrcweir                         xSource->copyStorageElementLastCommitTo( aSubElements[nInd], xSubStorage );
3495cdf0e10cSrcweir                     }
3496cdf0e10cSrcweir 
3497cdf0e10cSrcweir                     uno::Reference< beans::XPropertySet > xProps( xSubStorage, uno::UNO_QUERY_THROW );
3498cdf0e10cSrcweir                     bGotMediaType = ( xProps->getPropertyValue( aMediaTypePropName ) >>= aMediaType );
3499cdf0e10cSrcweir                 }
3500cdf0e10cSrcweir 
3501cdf0e10cSrcweir                 // TODO/LATER: there should be a way to detect whether an object with such a MediaType can exist
3502cdf0e10cSrcweir                 //             probably it should be placed in the MimeType-ClassID table or in standalone table
3503cdf0e10cSrcweir                 if ( aMediaType.getLength()
3504cdf0e10cSrcweir                   && aMediaType.compareToAscii( "application/vnd.sun.star.oleobject" ) != COMPARE_EQUAL )
3505cdf0e10cSrcweir                 {
3506cdf0e10cSrcweir                     ::com::sun::star::datatransfer::DataFlavor aDataFlavor;
3507cdf0e10cSrcweir                     aDataFlavor.MimeType = aMediaType;
3508cdf0e10cSrcweir                     sal_uInt32 nFormat = SotExchange::GetFormat( aDataFlavor );
3509cdf0e10cSrcweir 
3510cdf0e10cSrcweir                     switch ( nFormat )
3511cdf0e10cSrcweir                     {
3512cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARWRITER_60 :
3513cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARWRITERWEB_60 :
3514cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARWRITERGLOB_60 :
3515cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARDRAW_60 :
3516cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARIMPRESS_60 :
3517cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARCALC_60 :
3518cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARCHART_60 :
3519cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARMATH_60 :
3520cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARWRITER_8:
3521cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARWRITERWEB_8:
3522cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARWRITERGLOB_8:
3523cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARDRAW_8:
3524cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARIMPRESS_8:
3525cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARCALC_8:
3526cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARCHART_8:
3527cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARMATH_8:
3528cdf0e10cSrcweir                             break;
3529cdf0e10cSrcweir 
3530cdf0e10cSrcweir                         default:
3531cdf0e10cSrcweir                         {
3532cdf0e10cSrcweir                             if ( !xTarget->hasByName( aSubElements[nInd] ) )
3533cdf0e10cSrcweir                                 return sal_False;
3534cdf0e10cSrcweir                         }
3535cdf0e10cSrcweir                     }
3536cdf0e10cSrcweir                 }
3537cdf0e10cSrcweir             }
3538cdf0e10cSrcweir         }
3539cdf0e10cSrcweir     }
3540cdf0e10cSrcweir     catch( uno::Exception& )
3541cdf0e10cSrcweir     {
3542cdf0e10cSrcweir         OSL_ENSURE( sal_False, "Cant check storage consistency!\n" );
3543cdf0e10cSrcweir     }
3544cdf0e10cSrcweir 
3545cdf0e10cSrcweir     return sal_True;
3546cdf0e10cSrcweir }
3547cdf0e10cSrcweir 
3548cdf0e10cSrcweir 
SwitchPersistance(const uno::Reference<embed::XStorage> & xStorage)3549cdf0e10cSrcweir sal_Bool SfxObjectShell::SwitchPersistance( const uno::Reference< embed::XStorage >& xStorage )
3550cdf0e10cSrcweir {
3551cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::SwitchPersistance" );
3552cdf0e10cSrcweir 
3553cdf0e10cSrcweir     sal_Bool bResult = sal_False;
3554cdf0e10cSrcweir #ifdef DBG_UTIL
3555cdf0e10cSrcweir     // check for wrong creation of object container
3556cdf0e10cSrcweir     sal_Bool bHasContainer = ( pImp->mpObjectContainer != 0 );
3557cdf0e10cSrcweir #endif
3558cdf0e10cSrcweir     if ( xStorage.is() )
3559cdf0e10cSrcweir     {
3560cdf0e10cSrcweir         if ( pImp->mpObjectContainer )
3561cdf0e10cSrcweir             GetEmbeddedObjectContainer().SwitchPersistence( xStorage );
3562cdf0e10cSrcweir         bResult = SwitchChildrenPersistance( xStorage );
3563cdf0e10cSrcweir 
3564cdf0e10cSrcweir         // TODO/LATER: substorages that have unknown mimetypes probably should be copied to the target storage here
3565cdf0e10cSrcweir         OSL_ENSURE( StoragesOfUnknownMediaTypeAreCopied_Impl( pImp->m_xDocStorage, xStorage ),
3566cdf0e10cSrcweir                     "Some of substorages with unknown mimetypes is lost!" );
3567cdf0e10cSrcweir     }
3568cdf0e10cSrcweir 
3569cdf0e10cSrcweir     if ( bResult )
3570cdf0e10cSrcweir     {
3571cdf0e10cSrcweir         // make sure that until the storage is assigned the object container is not created by accident!
3572cdf0e10cSrcweir         DBG_ASSERT( bHasContainer == (pImp->mpObjectContainer != 0), "Wrong storage in object container!" );
3573cdf0e10cSrcweir         if ( pImp->m_xDocStorage != xStorage )
3574cdf0e10cSrcweir             DoSaveCompleted( new SfxMedium( xStorage, GetMedium()->GetBaseURL() ) );
3575cdf0e10cSrcweir 
3576cdf0e10cSrcweir         if ( IsEnableSetModified() )
3577cdf0e10cSrcweir             SetModified( sal_True ); // ???
3578cdf0e10cSrcweir     }
3579cdf0e10cSrcweir 
3580cdf0e10cSrcweir     return bResult;
3581cdf0e10cSrcweir }
3582cdf0e10cSrcweir 
CopyStoragesOfUnknownMediaType(const uno::Reference<embed::XStorage> & xSource,const uno::Reference<embed::XStorage> & xTarget)3583cdf0e10cSrcweir sal_Bool SfxObjectShell::CopyStoragesOfUnknownMediaType( const uno::Reference< embed::XStorage >& xSource,
3584cdf0e10cSrcweir                                                          const uno::Reference< embed::XStorage >& xTarget )
3585cdf0e10cSrcweir {
3586cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::CopyStoragesOfUnknownMediaType" );
3587cdf0e10cSrcweir 
3588cdf0e10cSrcweir     // This method does not commit the target storage and should not do it
3589cdf0e10cSrcweir     sal_Bool bResult = sal_True;
3590cdf0e10cSrcweir 
3591cdf0e10cSrcweir     try
3592cdf0e10cSrcweir     {
3593cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString > aSubElements = xSource->getElementNames();
3594cdf0e10cSrcweir         for ( sal_Int32 nInd = 0; nInd < aSubElements.getLength(); nInd++ )
3595cdf0e10cSrcweir         {
3596cdf0e10cSrcweir             if ( aSubElements[nInd].equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Configurations" ) ) ) )
3597cdf0e10cSrcweir             {
3598cdf0e10cSrcweir                 // The workaround for compatibility with SO7, "Configurations" substorage must be preserved
3599cdf0e10cSrcweir                 if ( xSource->isStorageElement( aSubElements[nInd] ) )
3600cdf0e10cSrcweir                 {
3601cdf0e10cSrcweir                     OSL_ENSURE( !xTarget->hasByName( aSubElements[nInd] ),
3602cdf0e10cSrcweir                                 "The target storage is an output storage, the element should not exist in the target!\n" );
3603cdf0e10cSrcweir 
3604cdf0e10cSrcweir                     xSource->copyElementTo( aSubElements[nInd], xTarget, aSubElements[nInd] );
3605cdf0e10cSrcweir                 }
3606cdf0e10cSrcweir             }
3607cdf0e10cSrcweir             else if ( xSource->isStorageElement( aSubElements[nInd] ) )
3608cdf0e10cSrcweir             {
3609cdf0e10cSrcweir                 ::rtl::OUString aMediaType;
3610cdf0e10cSrcweir                 ::rtl::OUString aMediaTypePropName( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
3611cdf0e10cSrcweir                 sal_Bool bGotMediaType = sal_False;
3612cdf0e10cSrcweir 
3613cdf0e10cSrcweir                 try
3614cdf0e10cSrcweir                 {
3615cdf0e10cSrcweir                     uno::Reference< embed::XOptimizedStorage > xOptStorage( xSource, uno::UNO_QUERY_THROW );
3616cdf0e10cSrcweir                     bGotMediaType =
3617cdf0e10cSrcweir                         ( xOptStorage->getElementPropertyValue( aSubElements[nInd], aMediaTypePropName ) >>= aMediaType );
3618cdf0e10cSrcweir                 }
3619cdf0e10cSrcweir                 catch( uno::Exception& )
3620cdf0e10cSrcweir                 {}
3621cdf0e10cSrcweir 
3622cdf0e10cSrcweir                 if ( !bGotMediaType )
3623cdf0e10cSrcweir                 {
3624cdf0e10cSrcweir                     uno::Reference< embed::XStorage > xSubStorage;
3625cdf0e10cSrcweir                     try {
3626cdf0e10cSrcweir                         xSubStorage = xSource->openStorageElement( aSubElements[nInd], embed::ElementModes::READ );
3627cdf0e10cSrcweir                     } catch( uno::Exception& )
3628cdf0e10cSrcweir                     {}
3629cdf0e10cSrcweir 
3630cdf0e10cSrcweir                     if ( !xSubStorage.is() )
3631cdf0e10cSrcweir                     {
3632cdf0e10cSrcweir                         // TODO/LATER: as optimization in future a substorage of target storage could be used
3633cdf0e10cSrcweir                         //             instead of the temporary storage; this substorage should be removed later
3634cdf0e10cSrcweir                         //             if the MimeType is wrong
3635cdf0e10cSrcweir                         xSubStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
3636cdf0e10cSrcweir                         xSource->copyStorageElementLastCommitTo( aSubElements[nInd], xSubStorage );
3637cdf0e10cSrcweir                     }
3638cdf0e10cSrcweir 
3639cdf0e10cSrcweir                     uno::Reference< beans::XPropertySet > xProps( xSubStorage, uno::UNO_QUERY_THROW );
3640cdf0e10cSrcweir                     bGotMediaType = ( xProps->getPropertyValue( aMediaTypePropName ) >>= aMediaType );
3641cdf0e10cSrcweir                 }
3642cdf0e10cSrcweir 
3643cdf0e10cSrcweir                 // TODO/LATER: there should be a way to detect whether an object with such a MediaType can exist
3644cdf0e10cSrcweir                 //             probably it should be placed in the MimeType-ClassID table or in standalone table
3645cdf0e10cSrcweir                 if ( aMediaType.getLength()
3646cdf0e10cSrcweir                   && aMediaType.compareToAscii( "application/vnd.sun.star.oleobject" ) != COMPARE_EQUAL )
3647cdf0e10cSrcweir                 {
3648cdf0e10cSrcweir                     ::com::sun::star::datatransfer::DataFlavor aDataFlavor;
3649cdf0e10cSrcweir                     aDataFlavor.MimeType = aMediaType;
3650cdf0e10cSrcweir                     sal_uInt32 nFormat = SotExchange::GetFormat( aDataFlavor );
3651cdf0e10cSrcweir 
3652cdf0e10cSrcweir                     switch ( nFormat )
3653cdf0e10cSrcweir                     {
3654cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARWRITER_60 :
3655cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARWRITERWEB_60 :
3656cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARWRITERGLOB_60 :
3657cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARDRAW_60 :
3658cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARIMPRESS_60 :
3659cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARCALC_60 :
3660cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARCHART_60 :
3661cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARMATH_60 :
3662cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARWRITER_8:
3663cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARWRITERWEB_8:
3664cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARWRITERGLOB_8:
3665cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARDRAW_8:
3666cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARIMPRESS_8:
3667cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARCALC_8:
3668cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARCHART_8:
3669cdf0e10cSrcweir                         case SOT_FORMATSTR_ID_STARMATH_8:
3670cdf0e10cSrcweir                             break;
3671cdf0e10cSrcweir 
3672cdf0e10cSrcweir                         default:
3673cdf0e10cSrcweir                         {
3674cdf0e10cSrcweir                             OSL_ENSURE(
3675cdf0e10cSrcweir                                 aSubElements[nInd].equalsAscii( "Configurations2" ) || !xTarget->hasByName( aSubElements[nInd] ),
3676cdf0e10cSrcweir                                 "The target storage is an output storage, the element should not exist in the target!\n" );
3677cdf0e10cSrcweir 
3678cdf0e10cSrcweir                             if ( !xTarget->hasByName( aSubElements[nInd] ) )
3679cdf0e10cSrcweir                             {
3680cdf0e10cSrcweir                                 xSource->copyElementTo( aSubElements[nInd], xTarget, aSubElements[nInd] );
3681cdf0e10cSrcweir                             }
3682cdf0e10cSrcweir                         }
3683cdf0e10cSrcweir                     }
3684cdf0e10cSrcweir                 }
3685cdf0e10cSrcweir             }
3686cdf0e10cSrcweir         }
3687cdf0e10cSrcweir     }
3688cdf0e10cSrcweir     catch( uno::Exception& )
3689cdf0e10cSrcweir     {
3690cdf0e10cSrcweir         bResult = sal_False;
3691cdf0e10cSrcweir         // TODO/LATER: a specific error could be provided
3692cdf0e10cSrcweir     }
3693cdf0e10cSrcweir 
3694cdf0e10cSrcweir     return bResult;
3695cdf0e10cSrcweir }
3696cdf0e10cSrcweir 
GenerateAndStoreThumbnail(sal_Bool bEncrypted,sal_Bool bSigned,sal_Bool bIsTemplate,const uno::Reference<embed::XStorage> & xStor)3697cdf0e10cSrcweir sal_Bool SfxObjectShell::GenerateAndStoreThumbnail( sal_Bool bEncrypted,
3698cdf0e10cSrcweir                                                     sal_Bool bSigned,
3699cdf0e10cSrcweir                                                     sal_Bool bIsTemplate,
3700cdf0e10cSrcweir                                                     const uno::Reference< embed::XStorage >& xStor )
3701cdf0e10cSrcweir {
3702cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::GenerateAndStoreThumbnail" );
3703cb65df5dSJürgen Schmidt 
3704cb65df5dSJürgen Schmidt     bIsInGenerateThumbnail = sal_True;//optimize thumbnail generate and store procedure to improve odt saving performance, i120030
3705cdf0e10cSrcweir 
3706cdf0e10cSrcweir     sal_Bool bResult = sal_False;
3707cdf0e10cSrcweir 
3708cdf0e10cSrcweir     try {
3709cdf0e10cSrcweir         uno::Reference< embed::XStorage > xThumbnailStor =
3710ea211b37SAriel Constenla-Haile                                         xStor->openStorageElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Thumbnails")),
3711cdf0e10cSrcweir                                                                     embed::ElementModes::READWRITE );
3712cdf0e10cSrcweir         if ( xThumbnailStor.is() )
3713cdf0e10cSrcweir         {
3714cdf0e10cSrcweir             uno::Reference< io::XStream > xStream = xThumbnailStor->openStreamElement(
3715ea211b37SAriel Constenla-Haile                                                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("thumbnail.png")),
3716cdf0e10cSrcweir                                                         embed::ElementModes::READWRITE );
3717cdf0e10cSrcweir 
3718cdf0e10cSrcweir             if ( xStream.is() && WriteThumbnail( bEncrypted, bSigned, bIsTemplate, xStream ) )
3719cdf0e10cSrcweir             {
3720ea211b37SAriel Constenla-Haile                 uno::Reference< beans::XPropertySet > xPropSet( xStream, uno::UNO_QUERY );
3721ea211b37SAriel Constenla-Haile                 if ( xPropSet.is() )
3722ea211b37SAriel Constenla-Haile                     xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("MediaType")),
3723ea211b37SAriel Constenla-Haile                                                 uno::makeAny( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("image/png"))));
3724cdf0e10cSrcweir                 uno::Reference< embed::XTransactedObject > xTransact( xThumbnailStor, uno::UNO_QUERY_THROW );
3725cdf0e10cSrcweir                 xTransact->commit();
3726cdf0e10cSrcweir                 bResult = sal_True;
3727cdf0e10cSrcweir             }
3728cdf0e10cSrcweir         }
3729cdf0e10cSrcweir     }
3730cdf0e10cSrcweir     catch( uno::Exception& )
3731cdf0e10cSrcweir     {
3732cdf0e10cSrcweir     }
3733cb65df5dSJürgen Schmidt 
3734cb65df5dSJürgen Schmidt     bIsInGenerateThumbnail = sal_False;//optimize thumbnail generate and store procedure to improve odt saving performance, i120030
3735cdf0e10cSrcweir 
3736cdf0e10cSrcweir     return bResult;
3737cdf0e10cSrcweir }
3738cdf0e10cSrcweir 
WriteThumbnail(sal_Bool bEncrypted,sal_Bool bSigned,sal_Bool bIsTemplate,const uno::Reference<io::XStream> & xStream)3739cdf0e10cSrcweir sal_Bool SfxObjectShell::WriteThumbnail( sal_Bool bEncrypted,
3740cdf0e10cSrcweir                                          sal_Bool bSigned,
3741cdf0e10cSrcweir                                          sal_Bool bIsTemplate,
3742cdf0e10cSrcweir                                          const uno::Reference< io::XStream >& xStream )
3743cdf0e10cSrcweir {
3744cdf0e10cSrcweir     sal_Bool bResult = sal_False;
3745cdf0e10cSrcweir 
3746cdf0e10cSrcweir     if ( xStream.is() )
3747cdf0e10cSrcweir     {
3748cdf0e10cSrcweir         try {
3749cdf0e10cSrcweir             uno::Reference< io::XTruncate > xTruncate( xStream->getOutputStream(), uno::UNO_QUERY_THROW );
3750cdf0e10cSrcweir             xTruncate->truncate();
3751cdf0e10cSrcweir 
3752cdf0e10cSrcweir             if ( bEncrypted )
3753cdf0e10cSrcweir             {
3754cdf0e10cSrcweir                 sal_uInt16 nResID = GraphicHelper::getThumbnailReplacementIDByFactoryName_Impl(
3755cdf0e10cSrcweir                                         ::rtl::OUString::createFromAscii( GetFactory().GetShortName() ),
3756cdf0e10cSrcweir                                         bIsTemplate );
3757cdf0e10cSrcweir                 if ( nResID )
3758cdf0e10cSrcweir                 {
3759cdf0e10cSrcweir                     if ( !bSigned )
3760cdf0e10cSrcweir                     {
3761cdf0e10cSrcweir                         bResult = GraphicHelper::getThumbnailReplacement_Impl( nResID, xStream );
3762cdf0e10cSrcweir                     }
3763cdf0e10cSrcweir                     else
3764cdf0e10cSrcweir                     {
3765cdf0e10cSrcweir                         // retrieve the bitmap and write a signature bitmap over it
3766cdf0e10cSrcweir                         SfxResId aResId( nResID );
3767cdf0e10cSrcweir                         BitmapEx aThumbBitmap( aResId );
3768cdf0e10cSrcweir                         bResult = GraphicHelper::getSignedThumbnailFormatFromBitmap_Impl( aThumbBitmap, xStream );
3769cdf0e10cSrcweir                     }
3770cdf0e10cSrcweir                 }
3771cdf0e10cSrcweir             }
3772cdf0e10cSrcweir             else
3773cdf0e10cSrcweir             {
3774cdf0e10cSrcweir                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
3775cdf0e10cSrcweir                     GetPreviewMetaFile( sal_False );
3776cdf0e10cSrcweir                 if ( pMetaFile )
3777cdf0e10cSrcweir                 {
3778cdf0e10cSrcweir                     bResult = GraphicHelper::getThumbnailFormatFromGDI_Impl(
3779cdf0e10cSrcweir                                 pMetaFile.get(), bSigned, xStream );
3780cdf0e10cSrcweir                 }
3781cdf0e10cSrcweir             }
3782cdf0e10cSrcweir         }
3783cdf0e10cSrcweir         catch( uno::Exception& )
3784cdf0e10cSrcweir         {}
3785cdf0e10cSrcweir     }
3786cdf0e10cSrcweir 
3787cdf0e10cSrcweir     return bResult;
3788cdf0e10cSrcweir }
3789cdf0e10cSrcweir 
UpdateLinks()3790cdf0e10cSrcweir void SfxObjectShell::UpdateLinks()
3791cdf0e10cSrcweir {
3792cdf0e10cSrcweir }
3793cdf0e10cSrcweir 
QuerySaveSizeExceededModules_Impl(const uno::Reference<task::XInteractionHandler> & xHandler)3794cdf0e10cSrcweir sal_Bool SfxObjectShell::QuerySaveSizeExceededModules_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
3795cdf0e10cSrcweir {
3796cdf0e10cSrcweir     if ( !HasBasic() )
3797cdf0e10cSrcweir         return sal_True;
3798cdf0e10cSrcweir 
3799cdf0e10cSrcweir     if ( !pImp->pBasicManager->isValid() )
3800cdf0e10cSrcweir         GetBasicManager();
3801cdf0e10cSrcweir     uno::Sequence< rtl::OUString > sModules;
3802cdf0e10cSrcweir     if ( xHandler.is() )
3803cdf0e10cSrcweir     {
3804cdf0e10cSrcweir         if( pImp->pBasicManager->LegacyPsswdBinaryLimitExceeded( sModules ) )
3805cdf0e10cSrcweir         {
3806cdf0e10cSrcweir             ModuleSizeExceeded* pReq =  new ModuleSizeExceeded( sModules );
3807cdf0e10cSrcweir             uno::Reference< task::XInteractionRequest > xReq( pReq );
3808cdf0e10cSrcweir             xHandler->handle( xReq );
3809cdf0e10cSrcweir             return pReq->isApprove();
3810cdf0e10cSrcweir         }
3811cdf0e10cSrcweir     }
3812cdf0e10cSrcweir     // No interaction handler, default is to continue to save
3813cdf0e10cSrcweir     return sal_True;
3814cdf0e10cSrcweir }
3815cdf0e10cSrcweir // -----------------------------------------------------------------------------
getInteractionHandler() const3816cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > SfxObjectShell::getInteractionHandler() const
3817cdf0e10cSrcweir {
3818cdf0e10cSrcweir     uno::Reference< task::XInteractionHandler > xRet;
3819cdf0e10cSrcweir     if ( GetMedium() )
3820cdf0e10cSrcweir         xRet = GetMedium()->GetInteractionHandler();
3821cdf0e10cSrcweir     return xRet;
3822cdf0e10cSrcweir }
3823