xref: /aoo41x/main/sfx2/source/doc/objmisc.cxx (revision 8699c4ff)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26 
27 #ifndef _INETMSG_HXX //autogen
28 #include <svl/inetmsg.hxx>
29 #endif
30 #include <tools/diagnose_ex.h>
31 #include <svl/eitem.hxx>
32 #include <svl/stritem.hxx>
33 #include <svl/intitem.hxx>
34 #include <svtools/svparser.hxx> // SvKeyValue
35 #include <vos/mutex.hxx>
36 #include <cppuhelper/exc_hlp.hxx>
37 
38 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
39 #include <com/sun/star/document/XDocumentProperties.hpp>
40 #include <com/sun/star/document/UpdateDocMode.hpp>
41 #include <com/sun/star/script/XTypeConverter.hpp>
42 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
43 #include <com/sun/star/script/FinishEngineEvent.hpp>
44 #include <com/sun/star/script/InterruptReason.hpp>
45 #include <com/sun/star/script/XEngineListener.hpp>
46 #include <com/sun/star/script/XDebugging.hpp>
47 #ifndef _COM_SUN_STAR_SCRIPT_XINVOKATION_HPP_
48 #include <com/sun/star/script/XInvocation.hpp>
49 #endif
50 #include <com/sun/star/script/ContextInformation.hpp>
51 #include <com/sun/star/script/FinishReason.hpp>
52 #include <com/sun/star/script/XEngine.hpp>
53 #include <com/sun/star/script/InterruptEngineEvent.hpp>
54 #include <com/sun/star/script/XLibraryAccess.hpp>
55 #include <com/sun/star/document/MacroExecMode.hpp>
56 #include <com/sun/star/document/XScriptInvocationContext.hpp>
57 #include <com/sun/star/embed/EmbedStates.hpp>
58 #include <com/sun/star/embed/XEmbedPersist.hpp>
59 #include <com/sun/star/util/XModifiable.hpp>
60 #include <com/sun/star/container/XChild.hpp>
61 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
62 
63 
64 #include <com/sun/star/script/provider/XScript.hpp>
65 #include <com/sun/star/script/provider/XScriptProvider.hpp>
66 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
67 
68 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
69 #include <toolkit/unohlp.hxx>
70 #endif
71 
72 #include <com/sun/star/uno/Reference.h>
73 #include <com/sun/star/uno/Any.h>
74 #include <com/sun/star/ucb/XContent.hpp>
75 #include <com/sun/star/task/ErrorCodeRequest.hpp>
76 #include <unotools/securityoptions.hxx>
77 
78 #include <comphelper/processfactory.hxx>
79 #include <comphelper/componentcontext.hxx>
80 #include <comphelper/configurationhelper.hxx>
81 
82 #include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
83 #include <com/sun/star/task/DocumentMacroConfirmationRequest.hpp>
84 #include <com/sun/star/task/InteractionClassification.hpp>
85 #include <com/sun/star/frame/XModel.hpp>
86 
87 using namespace ::com::sun::star;
88 using namespace ::com::sun::star::uno;
89 using namespace ::com::sun::star::ucb;
90 using namespace ::com::sun::star::document;
91 using namespace ::com::sun::star::frame;
92 using namespace ::com::sun::star::script;
93 using namespace ::com::sun::star::script::provider;
94 using namespace ::com::sun::star::container;
95 #include <basic/sbuno.hxx>
96 #include <basic/sbstar.hxx>
97 #ifndef _SB_BASMGR_HXX
98 #include <basic/basmgr.hxx>
99 #endif
100 #ifndef _VCL_MSGBOX_HXX
101 #include <vcl/msgbox.hxx>
102 #endif
103 #include <basic/sbx.hxx>
104 #include <svtools/sfxecode.hxx>
105 #include <svtools/ehdl.hxx>
106 
107 #include <unotools/pathoptions.hxx>
108 #include <unotools/ucbhelper.hxx>
109 #include <tools/inetmime.hxx>
110 #include <tools/urlobj.hxx>
111 #include <svl/inettype.hxx>
112 #include <svl/sharecontrolfile.hxx>
113 #include <osl/file.hxx>
114 #include <rtl/bootstrap.hxx>
115 #include <vcl/svapp.hxx>
116 #include <framework/interaction.hxx>
117 #include <framework/documentundoguard.hxx>
118 #include <comphelper/interaction.hxx>
119 #include <comphelper/storagehelper.hxx>
120 #include <comphelper/documentconstants.hxx>
121 
122 #include <sfx2/signaturestate.hxx>
123 #include <sfx2/app.hxx>
124 #include "appdata.hxx"
125 #include <sfx2/request.hxx>
126 #include <sfx2/bindings.hxx>
127 #include "sfx2/sfxresid.hxx"
128 #include <sfx2/docfile.hxx>
129 #include <sfx2/docfilt.hxx>
130 #include <sfx2/objsh.hxx>
131 #include "objshimp.hxx"
132 #include <sfx2/event.hxx>
133 #include "fltfnc.hxx"
134 #include <sfx2/sfx.hrc>
135 #include <sfx2/dispatch.hxx>
136 #include <sfx2/viewfrm.hxx>
137 #include <sfx2/viewsh.hxx>
138 #include <sfx2/ctrlitem.hxx>
139 #include "arrdecl.hxx"
140 #include <sfx2/module.hxx>
141 #include <sfx2/docfac.hxx>
142 #include "helper.hxx"
143 #include "doc.hrc"
144 #include "workwin.hxx"
145 #include "helpid.hrc"
146 #include "../appl/app.hrc"
147 #include <sfx2/sfxdlg.hxx>
148 #include "appbaslib.hxx"
149 #include <openflag.hxx> // SFX_STREAM_READWRITE
150 
151 #define C2S(cChar) String::CreateFromAscii( cChar )
152 
153 using namespace ::com::sun::star;
154 
155 // class SfxHeaderAttributes_Impl ----------------------------------------
156 
157 class SfxHeaderAttributes_Impl : public SvKeyValueIterator
158 {
159 private:
160 	SfxObjectShell* pDoc;
161 	SvKeyValueIteratorRef xIter;
162 	sal_Bool bAlert;
163 
164 public:
165 	SfxHeaderAttributes_Impl( SfxObjectShell* pSh ) :
166 		SvKeyValueIterator(), pDoc( pSh ),
167 		xIter( pSh->GetMedium()->GetHeaderAttributes_Impl() ),
168 		bAlert( sal_False ) {}
169 
170 	virtual sal_Bool GetFirst( SvKeyValue& rKV ) { return xIter->GetFirst( rKV ); }
171 	virtual sal_Bool GetNext( SvKeyValue& rKV ) { return xIter->GetNext( rKV ); }
172 	virtual void Append( const SvKeyValue& rKV );
173 
174 	void ClearForSourceView() { xIter = new SvKeyValueIterator; bAlert = sal_False; }
175 	void SetAttributes();
176 	void SetAttribute( const SvKeyValue& rKV );
177 };
178 
179 //=========================================================================
180 
181 sal_uInt16 __READONLY_DATA aTitleMap_Impl[3][2] =
182 {
183 								//	local				remote
184 	/*	SFX_TITLE_CAPTION	*/	{ 	SFX_TITLE_FILENAME, SFX_TITLE_TITLE },
185 	/*	SFX_TITLE_PICKLIST	*/	{ 	32,					SFX_TITLE_FULLNAME },
186 	/*	SFX_TITLE_HISTORY	*/	{ 	32,					SFX_TITLE_FULLNAME }
187 };
188 
189 //=========================================================================
190 
191 void SfxObjectShell::AbortImport()
192 {
193 	pImp->bIsAbortingImport = sal_True;
194 }
195 
196 //-------------------------------------------------------------------------
197 
198 sal_Bool SfxObjectShell::IsAbortingImport() const
199 {
200 	return pImp->bIsAbortingImport;
201 }
202 
203 //-------------------------------------------------------------------------
204 
205 uno::Reference<document::XDocumentProperties>
206 SfxObjectShell::getDocProperties()
207 {
208     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
209         GetModel(), uno::UNO_QUERY_THROW);
210     uno::Reference<document::XDocumentProperties> xDocProps(
211         xDPS->getDocumentProperties());
212     DBG_ASSERT(xDocProps.is(),
213         "SfxObjectShell: model has no DocumentProperties");
214     return xDocProps;
215 }
216 
217 //-------------------------------------------------------------------------
218 
219 void SfxObjectShell::DoFlushDocInfo()
220 {
221 }
222 
223 //-------------------------------------------------------------------------
224 
225 // Note: the only thing that calls this is the modification event handler
226 // that is installed at the XDocumentProperties
227 void SfxObjectShell::FlushDocInfo()
228 {
229     if ( IsLoading() )
230         return;
231 
232 	SetModified(sal_True);
233     uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
234     DoFlushDocInfo(); // call template method
235     ::rtl::OUString url(xDocProps->getAutoloadURL());
236     sal_Int32 delay(xDocProps->getAutoloadSecs());
237     SetAutoLoad( INetURLObject(url), delay * 1000,
238                  (delay > 0) || url.getLength() );
239 /*
240 	// bitte beachten:
241 	// 1. Titel in DocInfo aber nicht am Doc (nach HTML-Import)
242 	// 	=> auch am Doc setzen
243 	// 2. Titel in DocInfo leer (Briefumschlagsdruck)
244 	//	=> nicht am Doc setzen, da sonst "unbenanntX" daraus wird
245 	String aDocInfoTitle = GetDocInfo().GetTitle();
246 	if ( aDocInfoTitle.Len() )
247 		SetTitle( aDocInfoTitle );
248 	else
249 	{
250 		pImp->aTitle.Erase();
251 		SetNamedVisibility_Impl();
252     	if ( GetMedium() )
253     	{
254         	SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) );
255         	Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
256     	}
257     }*/
258 }
259 
260 //-------------------------------------------------------------------------
261 
262 void SfxObjectShell::SetError( sal_uInt32 lErr, const ::rtl::OUString& aLogMessage )
263 {
264 	if(pImp->lErr==ERRCODE_NONE)
265     {
266 		pImp->lErr=lErr;
267 
268         if( lErr != ERRCODE_NONE && aLogMessage.getLength() )
269             AddLog( aLogMessage );
270     }
271 }
272 
273 //-------------------------------------------------------------------------
274 
275 sal_uInt32 SfxObjectShell::GetError() const
276 {
277 	return ERRCODE_TOERROR(GetErrorCode());
278 }
279 
280 //-------------------------------------------------------------------------
281 
282 sal_uInt32 SfxObjectShell::GetErrorCode() const
283 {
284 	sal_uInt32 lError=pImp->lErr;
285 	if(!lError && GetMedium())
286 		lError=GetMedium()->GetErrorCode();
287 	return lError;
288 }
289 
290 //-------------------------------------------------------------------------
291 
292 void SfxObjectShell::ResetError()
293 {
294     if( pImp->lErr != ERRCODE_NONE )
295         AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Resetting Error." ) ) );
296 
297 	pImp->lErr=0;
298 	SfxMedium * pMed = GetMedium();
299 	if( pMed )
300 		pMed->ResetError();
301 }
302 
303 //-------------------------------------------------------------------------
304 
305 sal_Bool SfxObjectShell::IsTemplate() const
306 {
307 	return pImp->bIsTemplate;
308 }
309 
310 //-------------------------------------------------------------------------
311 
312 void SfxObjectShell::SetTemplate(sal_Bool bIs)
313 {
314 	pImp->bIsTemplate=bIs;
315 	SfxFilterMatcher aMatcher( GetFactory().GetFactoryName() );
316 	SfxFilterMatcherIter aIter( &aMatcher, SFX_FILTER_TEMPLATEPATH );
317 	SfxMedium* pMed = GetMedium();
318 	if( pMed ) pMed->SetFilter( aIter.First() );
319 }
320 
321 //-------------------------------------------------------------------------
322 
323 void SfxObjectShell::EnableSetModified( sal_Bool bEnable )
324 {
325 #ifdef DBG_UTIL
326 	if ( bEnable == pImp->m_bEnableSetModified )
327 		DBG_WARNING( "SFX_PERSIST: EnableSetModified called twice with the same value" );
328 #endif
329 	pImp->m_bEnableSetModified = bEnable;
330 }
331 
332 //-------------------------------------------------------------------------
333 
334 sal_Bool SfxObjectShell::IsEnableSetModified() const
335 {
336     return pImp->m_bEnableSetModified && !IsReadOnly();
337 }
338 
339 //-------------------------------------------------------------------------
340 
341 sal_Bool SfxObjectShell::IsModified()
342 {
343     if ( pImp->m_bIsModified )
344         return sal_True;
345 
346     if ( !pImp->m_xDocStorage.is() || IsReadOnly() )
347     {
348         // if the document still has no storage and is not set to be modified explicitly it is not modified
349         // a readonly document is also not modified
350 
351         return sal_False;
352     }
353 
354     uno::Sequence < ::rtl::OUString > aNames = GetEmbeddedObjectContainer().GetObjectNames();
355     for ( sal_Int32 n=0; n<aNames.getLength(); n++ )
356     {
357         uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObjectContainer().GetEmbeddedObject( aNames[n] );
358         OSL_ENSURE( xObj.is(), "An empty entry in the embedded objects list!\n" );
359         if ( xObj.is() )
360         {
361             try
362             {
363                 sal_Int32 nState = xObj->getCurrentState();
364                 if ( nState != embed::EmbedStates::LOADED )
365                 {
366                     uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
367                     if ( xModifiable.is() && xModifiable->isModified() )
368                         return sal_True;
369                 }
370             }
371             catch( uno::Exception& )
372             {}
373         }
374     }
375 
376     return sal_False;
377 }
378 
379 //-------------------------------------------------------------------------
380 
381 void SfxObjectShell::SetModified( sal_Bool bModifiedP )
382 {
383 #ifdef DBG_UTIL
384 	if ( !bModifiedP && !IsEnableSetModified() )
385 		DBG_WARNING( "SFX_PERSIST: SetModified( sal_False ), although IsEnableSetModified() == sal_False" );
386 #endif
387 
388 	if( !IsEnableSetModified() )
389 		return;
390 
391 	if( pImp->m_bIsModified != bModifiedP )
392 	{
393 		pImp->m_bIsModified = bModifiedP;
394 		ModifyChanged();
395 	}
396 }
397 
398 //-------------------------------------------------------------------------
399 
400 void SfxObjectShell::ModifyChanged()
401 {
402 	if ( pImp->bClosing )
403 		// SetModified aus dem dispose des Models!
404 		return;
405 
406 	{DBG_CHKTHIS(SfxObjectShell, 0);}
407 
408     SfxViewFrame* pViewFrame = SfxViewFrame::Current();
409     if ( pViewFrame )
410         pViewFrame->GetBindings().Invalidate( SID_SAVEDOCS );
411 
412     Invalidate( SID_SIGNATURE );
413     Invalidate( SID_MACRO_SIGNATURE );
414 	Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) );	// xmlsec05, signed state might change in title...
415 
416     SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_MODIFYCHANGED, GlobalEventConfig::GetEventName(STR_EVENT_MODIFYCHANGED), this ) );
417 }
418 
419 //-------------------------------------------------------------------------
420 
421 sal_Bool SfxObjectShell::IsReadOnlyUI() const
422 
423 /* 	[Beschreibung]
424 
425 	Liefert sal_True, wenn das Dokument fuer die UI wie r/o behandelt werden
426 	soll. Dieses ist unabhaengig vom tatsaechlichen r/o, welches per
427 	<IsReadOnly()> erfragbar ist.
428 */
429 
430 {
431 	return pImp->bReadOnlyUI;
432 }
433 
434 //-------------------------------------------------------------------------
435 
436 sal_Bool SfxObjectShell::IsReadOnlyMedium() const
437 
438 /* 	[Beschreibung]
439 
440 	Liefert sal_True, wenn das Medium r/o ist bzw. r/o geoeffnet wurde.
441 */
442 
443 {
444 	if ( !pMedium )
445 		return sal_True;
446 	return pMedium->IsReadOnly();
447 }
448 
449 //-------------------------------------------------------------------------
450 
451 void SfxObjectShell::SetReadOnlyUI( sal_Bool bReadOnly )
452 
453 /* 	[Beschreibung]
454 
455 	Schaltet das Dokument in einen r/o bzw. r/w Zustand ohne es neu
456 	zu laden und ohne die Open-Modi des Mediums zu aendern.
457 */
458 
459 {
460 	sal_Bool bWasRO = IsReadOnly();
461 	pImp->bReadOnlyUI = bReadOnly;
462 	if ( bWasRO != IsReadOnly() )
463 	{
464 		Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
465 		//if ( pImp->pDocInfo )
466 		//	pImp->pDocInfo->SetReadOnly( IsReadOnly() );
467 	}
468 }
469 
470 //-------------------------------------------------------------------------
471 
472 void SfxObjectShell::SetReadOnly()
473 {
474 	// Let the document be completely readonly, means that the
475 	// medium open mode is adjusted accordingly, and the write lock
476 	// on the file is removed.
477 
478  	if ( pMedium && !IsReadOnlyMedium() )
479     {
480         sal_Bool bWasROUI = IsReadOnly();
481 
482 		pMedium->UnlockFile( sal_False );
483 
484         // the storage-based mediums are already based on the temporary file
485         // so UnlockFile has already closed the locking stream
486         if ( !pMedium->HasStorage_Impl() && IsLoadingFinished() )
487             pMedium->CloseInStream();
488 
489         pMedium->SetOpenMode( SFX_STREAM_READONLY, pMedium->IsDirect(), sal_True );
490         pMedium->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
491 
492         if ( !bWasROUI )
493             Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
494     }
495 }
496 //-------------------------------------------------------------------------
497 
498 sal_Bool SfxObjectShell::IsReadOnly() const
499 {
500 	return pImp->bReadOnlyUI || IsReadOnlyMedium();
501 }
502 
503 //-------------------------------------------------------------------------
504 
505 sal_Bool SfxObjectShell::IsInModalMode() const
506 {
507     return pImp->bModalMode || pImp->bRunningMacro;
508 }
509 
510 //<!--Added by PengYunQuan for Validity Cell Range Picker
511 sal_Bool SfxObjectShell::AcceptStateUpdate() const
512 {
513 	return !IsInModalMode();
514 }
515 //-->Added by PengYunQuan for Validity Cell Range Picker
516 
517 //-------------------------------------------------------------------------
518 
519 sal_Bool SfxObjectShell::HasModalViews() const
520 {
521 	SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
522 	while( pFrame )
523 	{
524 		if ( pFrame->IsInModalMode() )
525 			return sal_True;
526 
527 		pFrame = SfxViewFrame::GetNext( *pFrame, this );
528 	}
529 
530 	return sal_False;
531 }
532 
533 //-------------------------------------------------------------------------
534 
535 void SfxObjectShell::SetMacroMode_Impl( sal_Bool bModal )
536 {
537     if ( !pImp->bRunningMacro != !bModal )
538 	{
539         pImp->bRunningMacro = bModal;
540 		Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
541 	}
542 }
543 
544 //-------------------------------------------------------------------------
545 
546 void SfxObjectShell::SetModalMode_Impl( sal_Bool bModal )
547 {
548 	// nur Broadcasten wenn modifiziert, sonst ggf. Endlosrekursion
549 	if ( !pImp->bModalMode != !bModal )
550 	{
551 		// zentral mitz"ahlen
552 		sal_uInt16 &rDocModalCount = SFX_APP()->Get_Impl()->nDocModalMode;
553 		if ( bModal )
554 			++rDocModalCount;
555 		else
556 			--rDocModalCount;
557 
558 		// umschalten
559 		pImp->bModalMode = bModal;
560 		Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
561 	}
562 }
563 
564 //--------------------------------------------------------------------
565 sal_Bool SfxObjectShell::SwitchToShared( sal_Bool bShared, sal_Bool bSave )
566 {
567     sal_Bool bResult = sal_True;
568 
569     if ( bShared != IsDocShared() )
570     {
571         ::rtl::OUString aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
572 
573         if ( !aOrigURL.getLength() && bSave )
574         {
575             // this is a new document, let it be stored before switching to the shared mode;
576             // the storing should be done without shared flag, since it is possible that the
577             // target location does not allow to create sharing control file;
578             // the shared flag will be set later after creation of sharing control file
579             SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
580 
581             if ( pViewFrame )
582             {
583                 // TODO/LATER: currently the application guards against the reentrance problem
584 				const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
585                 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
586                 bResult = ( pResult && pResult->GetValue() );
587                 if ( bResult )
588                     aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
589             }
590         }
591 
592         sal_Bool bOldValue = HasSharedXMLFlagSet();
593         SetSharedXMLFlag( bShared );
594 
595         sal_Bool bRemoveEntryOnError = sal_False;
596         if ( bResult && bShared )
597         {
598             try
599             {
600                 ::svt::ShareControlFile aControlFile( aOrigURL );
601                 aControlFile.InsertOwnEntry();
602                 bRemoveEntryOnError = sal_True;
603             }
604             catch( uno::Exception& )
605             {
606                 bResult = sal_False;
607             }
608         }
609 
610         if ( bResult && bSave )
611         {
612             SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
613 
614             if ( pViewFrame )
615             {
616                 // TODO/LATER: currently the application guards against the reentrance problem
617                 SetModified( sal_True ); // the modified flag has to be set to let the document be stored with the shared flag
618 				const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
619                 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
620                 bResult = ( pResult && pResult->GetValue() );
621             }
622         }
623 
624         if ( bResult )
625         {
626             // TODO/LATER: Is it possible that the following calls fail?
627             if ( bShared )
628             {
629                 pImp->m_aSharedFileURL = aOrigURL;
630                 GetMedium()->SwitchDocumentToTempFile();
631             }
632             else
633             {
634                 ::rtl::OUString aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
635                 GetMedium()->SwitchDocumentToFile( GetSharedFileURL() );
636                 pImp->m_aSharedFileURL = ::rtl::OUString();
637 
638                 // now remove the temporary file the document was based on
639                 ::utl::UCBContentHelper::Kill( aTempFileURL );
640 
641                 try
642                 {
643                     // aOrigURL can not be used since it contains an old value
644                     ::svt::ShareControlFile aControlFile( GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
645                     aControlFile.RemoveFile();
646                 }
647                 catch( uno::Exception& )
648                 {
649                 }
650             }
651         }
652         else
653         {
654             // the saving has failed!
655             if ( bRemoveEntryOnError )
656             {
657                 try
658                 {
659                     ::svt::ShareControlFile aControlFile( aOrigURL );
660                     aControlFile.RemoveEntry();
661                 }
662                 catch( uno::Exception& )
663                 {}
664             }
665 
666             SetSharedXMLFlag( bOldValue );
667         }
668     }
669     else
670         bResult = sal_False; // the second switch to the same mode
671 
672     if ( bResult )
673         SetTitle( String() );
674 
675     return bResult;
676 }
677 
678 //--------------------------------------------------------------------
679 
680 void SfxObjectShell::DisconnectFromShared()
681 {
682     if ( IsDocShared() )
683     {
684         if ( pMedium && pMedium->GetStorage().is() )
685         {
686             // set medium to noname
687             pMedium->SetName( String(), sal_True );
688             pMedium->Init_Impl();
689 
690             // drop resource
691             SetNoName();
692             InvalidateName();
693 
694             // untitled document must be based on temporary storage
695             // the medium should not dispose the storage in this case
696             if ( pMedium->GetStorage() == GetStorage() )
697                 ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium );
698 
699             pMedium->Close();
700             FreeSharedFile();
701 
702             SfxMedium* pTmpMedium = pMedium;
703             ForgetMedium();
704             if( !DoSaveCompleted( pTmpMedium ) )
705                 SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
706             else
707             {
708                 // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
709                 pMedium->CanDisposeStorage_Impl( sal_False );
710             }
711 
712             pMedium->GetItemSet()->ClearItem( SID_DOC_READONLY );
713             pMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True, sal_True );
714 
715             SetTitle( String() );
716         }
717     }
718 }
719 
720 //--------------------------------------------------------------------
721 
722 void SfxObjectShell::FreeSharedFile()
723 {
724     if ( pMedium )
725         FreeSharedFile( pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
726 }
727 
728 //--------------------------------------------------------------------
729 void SfxObjectShell::FreeSharedFile( const ::rtl::OUString& aTempFileURL )
730 {
731     SetSharedXMLFlag( sal_False );
732 
733     if ( IsDocShared() && aTempFileURL.getLength()
734       && !::utl::UCBContentHelper::EqualURLs( aTempFileURL, GetSharedFileURL() ) )
735     {
736         if ( pImp->m_bAllowShareControlFileClean )
737         {
738             try
739             {
740                 ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
741                 aControlFile.RemoveEntry();
742             }
743             catch( uno::Exception& )
744             {
745             }
746         }
747 
748         // the cleaning is forbidden only once
749         pImp->m_bAllowShareControlFileClean = sal_True;
750 
751         // now remove the temporary file the document is based currently on
752         ::utl::UCBContentHelper::Kill( aTempFileURL );
753 
754         pImp->m_aSharedFileURL = ::rtl::OUString();
755     }
756 }
757 
758 //--------------------------------------------------------------------
759 void SfxObjectShell::DoNotCleanShareControlFile()
760 {
761     pImp->m_bAllowShareControlFileClean = sal_False;
762 }
763 
764 //--------------------------------------------------------------------
765 void SfxObjectShell::SetSharedXMLFlag( sal_Bool bFlag ) const
766 {
767     pImp->m_bSharedXMLFlag = bFlag;
768 }
769 
770 //--------------------------------------------------------------------
771 sal_Bool SfxObjectShell::HasSharedXMLFlagSet() const
772 {
773     return pImp->m_bSharedXMLFlag;
774 }
775 
776 //--------------------------------------------------------------------
777 
778 sal_Bool SfxObjectShell::IsDocShared() const
779 {
780     return ( pImp->m_aSharedFileURL.getLength() > 0 );
781 }
782 
783 //--------------------------------------------------------------------
784 
785 ::rtl::OUString SfxObjectShell::GetSharedFileURL() const
786 {
787     return pImp->m_aSharedFileURL;
788 }
789 
790 //--------------------------------------------------------------------
791 
792 Size SfxObjectShell::GetFirstPageSize()
793 {
794     return GetVisArea(ASPECT_THUMBNAIL).GetSize();
795 }
796 
797 
798 //--------------------------------------------------------------------
799 
800 IndexBitSet& SfxObjectShell::GetNoSet_Impl()
801 {
802 	return pImp->aBitSet;
803 }
804 
805 //--------------------------------------------------------------------
806 // changes the title of the document
807 
808 void SfxObjectShell::SetTitle
809 (
810 	const String& rTitle		// der neue Titel des Dokuments
811 )
812 
813 /*	[Beschreibung]
814 
815 	Mit dieser Methode kann der Titel des Dokuments gesetzt werden.
816 	Dieser entspricht initial dem kompletten Dateinamen. Ein Setzen
817 	des Titels wirkt jedoch nicht zurück auf den Dateinamen; er wird
818 	jedoch in den Caption-Bars der MDI-Fenster angezeigt.
819 */
820 
821 {
822 	DBG_CHKTHIS(SfxObjectShell, 0);
823 
824 	// nix zu tun?
825 	if ( ( ( HasName() && pImp->aTitle == rTitle )
826 		|| ( !HasName() && GetTitle() == rTitle ) )
827 	  && !IsDocShared() )
828 		return;
829 
830 	SfxApplication *pSfxApp = SFX_APP();
831 #if 0
832 	// wird 'unbenannt#' als Titel gesetzt
833 	String aNoName(SfxResId(STR_NONAME));
834 	if ( rTitle.Match(aNoName) <= aNoName.Len() )
835 	{
836 		// er ist es selbst => ignorieren
837 		pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
838 		pImp->bIsNamedVisible=0;
839 	}
840 #endif
841 
842 	// ggf. die unbenannt-Nummer freigeben
843 	if ( pImp->bIsNamedVisible && USHRT_MAX != pImp->nVisualDocumentNumber )
844 	{
845 		pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
846 		pImp->bIsNamedVisible = 0;
847 	}
848 
849 	// Title setzen
850 	pImp->aTitle = rTitle;
851 //	Wieso denn in der DocInfo?
852 //	GetDocInfo().SetTitle( rTitle );
853 //	FlushDocInfo();
854 
855 	// Benachrichtigungen
856     if ( GetMedium() )
857     {
858         SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) );
859         Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
860     }
861 }
862 
863 //--------------------------------------------------------------------
864 
865 #if OSL_DEBUG_LEVEL > 1
866 String X(const String &rRet)
867 {
868 	if ( !rRet.Len() )
869 		return DEFINE_CONST_UNICODE( "-empty-" );
870 	return rRet;
871 }
872 #else
873 #define X(ret) ret
874 #endif
875 
876 //--------------------------------------------------------------------
877 //--------------------------------------------------------------------
878 String SfxObjectShell::GetTitle
879 (
880 	sal_uInt16	nMaxLength 		/*	0 (default)
881 								der Titel selbst, so wie er ist
882 
883 								1 (==SFX_TITLE_FILENAME)
884 								liefert den logischen Dateinamen ohne Pfad
885 								(unter WNT je nach Systemeinstellung ohne
886 								Extension)
887 
888 								2 (==SFX_TITLE_FULLNAME)
889 								liefert den mit komplettem logischen Dateinamen
890 								mit Pfad (remote => ::com::sun::star::util::URL)
891 
892 								3 (==SFX_TITLE_APINAME)
893 								liefert den logischen Dateinamen ohne Pfad
894 								und Extension
895 
896 								4 (==SFX_TITLE_DETECT)
897 								liefert den kompletten Titel, falls noch
898 								nicht gesetzt wird aber aus DocInfo oder
899 								dem Namen des Medium erzeugt
900 
901 								5 (==SFX_TITLE_CAPTION)
902 								liefert den Titel so, wie MB ihn heute in
903 								der CaptionBar anzeigen m"ochte
904 
905 								6 (==SFX_TITLE_PICKLIST)
906 								liefert den Titel so, wie MB ihn heute in
907 								der PickList anzeigen m"ochte
908 
909 								7 (==SFX_TITLE_HISTORY)
910 								liefert den Titel so, wie MB ihn heute in
911 								der History anzeigen m"ochte
912 
913 								10 bis USHRT_MAX
914 								liefert maximal 'nMaxLength' Zeichen vom logischen
915 								Dateinamen inkl. Pfad (remote => ::com::sun::star::util::URL)
916 								*/
917 ) const
918 
919 /*	[Beschreibung]
920 
921 	Liefert den Titel bzw. logischen Dateinamen des Dokuments, je nach
922 	'nMaxLength'.
923 
924 	Falls der Dateiname mit Pfad verwendet wird, wird die Namensk"urzung durch
925 	Ersetzung eines oder mehrerer Directory-Namen durch "..." durchgef"uhrt,
926 	URLs werden z.Zt. immer komplett geliefert.
927 */
928 
929 {
930 //    if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
931 //        return String();
932     SfxMedium *pMed = GetMedium();
933     if ( IsLoading() )
934         return String();
935 
936 /*    if ( !nMaxLength && pImp->pDocInfo )
937     {
938         String aTitle = pImp->pDocInfo->GetTitle();
939         if ( aTitle.Len() )
940             return aTitle;
941     } */
942 
943 	// Titel erzeugen?
944 	if ( SFX_TITLE_DETECT == nMaxLength && !pImp->aTitle.Len() )
945 	{
946 		static sal_Bool bRecur = sal_False;
947 		if ( bRecur )
948 			return DEFINE_CONST_UNICODE( "-not available-" );
949 		bRecur = sal_True;
950 
951 		String aTitle;
952 		SfxObjectShell *pThis = (SfxObjectShell*) this;
953 
954 		if ( pMed )
955 		{
956 			SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
957 			if ( pNameItem )
958 				aTitle = pNameItem->GetValue();
959 		}
960 
961 		if ( !aTitle.Len() )
962 			aTitle = GetTitle( SFX_TITLE_FILENAME );
963 
964 		if ( IsTemplate() )
965 			pThis->SetTitle( aTitle );
966 		bRecur = sal_False;
967 		return X(aTitle);
968 	}
969 	else if (SFX_TITLE_APINAME == nMaxLength )
970 		return X(GetAPIName());
971 
972 	// Sonderfall Vorlagen:
973 	if( IsTemplate() && pImp->aTitle.Len() &&
974 		 ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
975 		return X(pImp->aTitle);
976 
977 	// Picklist/Caption wird gemappt
978 	if ( pMed && ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
979 	{
980 		// Wenn ein spezieller Titel beim Öffnen mitgegeben wurde;
981 		// wichtig bei URLs, die INET_PROT_FILE verwenden, denn bei denen
982 		// wird der gesetzte Titel nicht beachtet.
983 		// (s.u., Auswertung von aTitleMap_Impl)
984 		SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
985 		if ( pNameItem )
986 			return X( pNameItem->GetValue() );
987 	}
988 
989 	// noch unbenannt?
990 	DBG_ASSERT( !HasName() || pMed, "HasName() but no Medium?" );
991 	if ( !HasName() || !pMed )
992 	{
993 		// schon Titel gesetzt?
994 		if ( pImp->aTitle.Len() )
995 			return X(pImp->aTitle);
996 
997 		// muß es durchnumeriert werden?
998 		String aNoName( SfxResId( STR_NONAME ) );
999 		if ( pImp->bIsNamedVisible )
1000 			// Leerzeichen und Nummer hinten anhängen
1001 			aNoName += C2S(" ");
1002 			aNoName += String::CreateFromInt32( pImp->nVisualDocumentNumber );
1003 
1004 		// Dokument heißt vorerst 'Unbenannt #'
1005 		return X(aNoName);
1006 	}
1007 
1008 	const INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
1009 	if ( nMaxLength > SFX_TITLE_CAPTION && nMaxLength <= SFX_TITLE_HISTORY )
1010 	{
1011 		sal_uInt16 nRemote;
1012 		if( !pMed || aURL.GetProtocol() == INET_PROT_FILE )
1013 			nRemote = 0;
1014 		else
1015 			nRemote = 1;
1016 		nMaxLength = aTitleMap_Impl[nMaxLength-SFX_TITLE_CAPTION][nRemote];
1017 	}
1018 
1019 	// local file?
1020 	if ( aURL.GetProtocol() == INET_PROT_FILE )
1021 	{
1022         String aName( aURL.HasMark() ? INetURLObject( aURL.GetURLNoMark() ).PathToFileName() : aURL.PathToFileName() );
1023 		if ( nMaxLength == SFX_TITLE_FULLNAME )
1024 			return X( aName );
1025 		else if ( nMaxLength == SFX_TITLE_FILENAME )
1026             return X( aURL.getName( INetURLObject::LAST_SEGMENT,
1027 				true, INetURLObject::DECODE_WITH_CHARSET ) );
1028 		else if ( !pImp->aTitle.Len() )
1029             pImp->aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT,
1030 										 true, INetURLObject::DECODE_WITH_CHARSET );
1031 	}
1032 	else
1033 	{
1034 		// ::com::sun::star::util::URL-Versionen
1035 		if ( nMaxLength >= SFX_TITLE_MAXLEN )
1036 		{
1037             String aComplete( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
1038 			if( aComplete.Len() > nMaxLength )
1039 			{
1040 				String aRet( DEFINE_CONST_UNICODE( "..." ) );
1041 				aRet += aComplete.Copy( aComplete.Len() - nMaxLength + 3, nMaxLength - 3 );
1042 				return X( aRet );
1043 			}
1044 			else
1045                 return X( aComplete );
1046 		}
1047 		else if ( nMaxLength == SFX_TITLE_FILENAME )
1048 		{
1049             String aName( aURL.GetBase() );
1050 			aName = INetURLObject::decode( aName, INET_HEX_ESCAPE, INetURLObject::DECODE_WITH_CHARSET );
1051 			if( !aName.Len() )
1052 				aName = aURL.GetURLNoPass();
1053 			return X(aName);
1054 		}
1055 		else if ( nMaxLength == SFX_TITLE_FULLNAME )
1056 			return X(aURL.GetMainURL( INetURLObject::DECODE_TO_IURI ));
1057 
1058 		// ggf. Titel aus Dateiname generieren
1059 		if ( !pImp->aTitle.Len() )
1060 			pImp->aTitle = aURL.GetBase();
1061 
1062 		// workaround for the case when the name can not be retrieved from URL by INetURLObject
1063 		if ( !pImp->aTitle.Len() )
1064 			pImp->aTitle = aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
1065 	}
1066 
1067 	// ganzer Titel
1068 	return X(pImp->aTitle);
1069 }
1070 
1071 //--------------------------------------------------------------------
1072 
1073 void SfxObjectShell::InvalidateName()
1074 
1075 /*	[Beschreibung]
1076 
1077 	Ermittelt den Titel des Dokuments neu aus 'unbenannt', DocInfo-Titel
1078 	bzw. Dateinamen. Wird nach Laden aus Template oder SaveAs benötigt.
1079 */
1080 
1081 {
1082 	// Title neu erzeugen
1083 	pImp->aTitle.Erase();
1084 //	pImp->nVisualDocumentNumber = USHRT_MAX;
1085 	//GetTitle( SFX_TITLE_DETECT );
1086 	SetName( GetTitle( SFX_TITLE_APINAME ) );
1087 
1088 	// Benachrichtigungen
1089 	Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
1090 }
1091 
1092 //--------------------------------------------------------------------
1093 
1094 void SfxObjectShell::SetNamedVisibility_Impl()
1095 {
1096 	if ( !pImp->bIsNamedVisible )
1097 	{
1098 		// Nummer verpassen
1099 		pImp->bIsNamedVisible = sal_True;
1100 		// ggf. neue Nummer verpassen
1101 		if ( !HasName() && USHRT_MAX == pImp->nVisualDocumentNumber && !pImp->aTitle.Len() )
1102 		{
1103 			pImp->nVisualDocumentNumber = SFX_APP()->GetFreeIndex();
1104 			Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
1105 		}
1106 	}
1107 
1108 	SetName( GetTitle(SFX_TITLE_APINAME) );
1109 }
1110 
1111 void SfxObjectShell::SetNoName()
1112 {
1113     bHasName = 0;
1114     bIsTmp = sal_True;
1115     GetModel()->attachResource( ::rtl::OUString(), GetModel()->getArgs() );
1116 }
1117 
1118 //--------------------------------------------------------------------
1119 
1120 void SfxObjectShell::MemoryError()
1121 {
1122 }
1123 
1124 //--------------------------------------------------------------------
1125 
1126 SfxProgress* SfxObjectShell::GetProgress() const
1127 {
1128 	return pImp->pProgress;
1129 }
1130 
1131 //--------------------------------------------------------------------
1132 
1133 void SfxObjectShell::SetProgress_Impl
1134 (
1135 	SfxProgress *pProgress	/*	zu startender <SfxProgress> oder 0, falls
1136 								der Progress zur"uckgesetzt werden soll */
1137 )
1138 
1139 /*	[Beschreibung]
1140 
1141 	Interne Methode zum setzen oder zur"ucksetzen des Progress-Modes
1142 	f"ur diese SfxObjectShell.
1143 */
1144 
1145 {
1146 	DBG_ASSERT( ( !pImp->pProgress && pProgress ) ||
1147 				( pImp->pProgress && !pProgress ),
1148 				"Progress activation/deacitivation mismatch" );
1149 	pImp->pProgress = pProgress;
1150 }
1151 
1152 //--------------------------------------------------------------------
1153 
1154 void SfxObjectShell::PostActivateEvent_Impl( SfxViewFrame* pFrame )
1155 {
1156 	SfxApplication* pSfxApp = SFX_APP();
1157     if ( !pSfxApp->IsDowning() && !IsLoading() && pFrame && !pFrame->GetFrame().IsClosing_Impl() )
1158 	{
1159         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
1160         if ( !pHiddenItem || !pHiddenItem->GetValue() )
1161         {
1162             sal_uInt16 nId = pImp->nEventId;
1163             pImp->nEventId = 0;
1164             if ( nId == SFX_EVENT_OPENDOC )
1165                 pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_OPENDOC), this, pFrame->GetFrame().GetController() ), sal_False);
1166 			else if (nId == SFX_EVENT_CREATEDOC )
1167                 pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_CREATEDOC), this, pFrame->GetFrame().GetController() ), sal_False);
1168         }
1169 	}
1170 }
1171 
1172 //--------------------------------------------------------------------
1173 
1174 void SfxObjectShell::SetActivateEvent_Impl(sal_uInt16 nId )
1175 {
1176 	if ( GetFactory().GetFlags() & SFXOBJECTSHELL_HASOPENDOC )
1177 		pImp->nEventId = nId;
1178 }
1179 
1180 //--------------------------------------------------------------------
1181 
1182 void SfxObjectShell::RegisterTransfer( SfxMedium& rMedium )
1183 /*  [Beschreibung ]
1184 	Alle Medien, die aufgesetzt werden, um Teile eines Dokumentes zu
1185 	laden, muessen an der zugehoerigen SfxObjectShell angemeldet
1186 	werden. So kann dokumentweise abgebrochen werden.  */
1187 {
1188 	rMedium.SetReferer( GetMedium()->GetName() );
1189 }
1190 
1191 //-------------------------------------------------------------------------
1192 
1193 void SfxObjectShell::PrepareReload( )
1194 /*  [Beschreibung ]
1195 	Wird vor dem Reload gerufen und gibt die Moeglichkeit,
1196 	etwaige Caches zu leeren. */
1197 {
1198 }
1199 
1200 //-------------------------------------------------------------------------
1201 
1202 void SfxObjectShell::LockAutoLoad( sal_Bool bLock )
1203 
1204 /* 	Verhindert ein evtl. eintreffendes AutoLoad. Wird auch vor AutoLoad
1205 	eines umgebenden FrameSet beruecksichtigt.
1206 */
1207 
1208 {
1209 	if ( bLock )
1210 		++pImp->nAutoLoadLocks;
1211 	else
1212 		--pImp->nAutoLoadLocks;
1213 }
1214 
1215 //-------------------------------------------------------------------------
1216 
1217 // kann nach frame.cxx gemoved werden, wenn 358+36x-Stand gemerged sind
1218 
1219 sal_Bool SfxFrame::IsAutoLoadLocked_Impl() const
1220 {
1221 	// sein einges Doc gelockt?
1222 	const SfxObjectShell* pObjSh = GetCurrentDocument();
1223 	if ( !pObjSh || !pObjSh->IsAutoLoadLocked() )
1224 		return sal_False;
1225 
1226 	// seine Childs gelockt?
1227 	for ( sal_uInt16 n = GetChildFrameCount(); n--; )
1228 		if ( !GetChildFrame(n)->IsAutoLoadLocked_Impl() )
1229 			return sal_False;
1230 
1231 	// sonst ist AutoLoad erlaubt
1232 	return sal_True;
1233 }
1234 
1235 //-------------------------------------------------------------------------
1236 
1237 sal_Bool SfxObjectShell::IsAutoLoadLocked() const
1238 
1239 /* 	Liefert, ob ein eintreffendes AutoLoad ausgefuehrt werden darf. Wird auch
1240 	vor AutoLoad eines umgebenden FrameSet beruecksichtigt.
1241 */
1242 
1243 {
1244 	return !IsReadOnly() || pImp->nAutoLoadLocks > 0;
1245 }
1246 
1247 //-------------------------------------------------------------------------
1248 void SfxObjectShell::BreakMacroSign_Impl( sal_Bool bBreakMacroSign )
1249 {
1250 	pImp->m_bMacroSignBroken = bBreakMacroSign;
1251 }
1252 
1253 //-------------------------------------------------------------------------
1254 void SfxObjectShell::CheckSecurityOnLoading_Impl()
1255 {
1256     uno::Reference< task::XInteractionHandler > xInteraction;
1257     if ( GetMedium() )
1258         xInteraction = GetMedium()->GetInteractionHandler();
1259 
1260 	// check if there is a broken signature...
1261     CheckForBrokenDocSignatures_Impl( xInteraction );
1262 
1263     CheckEncryption_Impl( xInteraction );
1264 
1265     // check macro security
1266     pImp->aMacroMode.checkMacrosOnLoading( xInteraction );
1267 }
1268 
1269 //-------------------------------------------------------------------------
1270 void SfxObjectShell::CheckEncryption_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
1271 {
1272     ::rtl::OUString aVersion;
1273     sal_Bool bIsEncrypted = sal_False;
1274     sal_Bool bHasNonEncrypted = sal_False;
1275 
1276     try
1277     {
1278         uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
1279         xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aVersion;
1280         xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasEncryptedEntries" ) ) ) >>= bIsEncrypted;
1281         xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasNonEncryptedEntries" ) ) ) >>= bHasNonEncrypted;
1282     }
1283     catch( uno::Exception& )
1284     {
1285     }
1286 
1287     if ( aVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
1288     {
1289         // this is ODF1.2 or later
1290         if ( bIsEncrypted && bHasNonEncrypted )
1291         {
1292             if ( !pImp->m_bIncomplEncrWarnShown )
1293             {
1294                 // this is an encrypted document with nonencrypted streams inside, show the warning
1295                 ::com::sun::star::task::ErrorCodeRequest aErrorCode;
1296                 aErrorCode.ErrCode = ERRCODE_SFX_INCOMPLETE_ENCRYPTION;
1297 
1298                 SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False );
1299                 pImp->m_bIncomplEncrWarnShown = sal_True;
1300             }
1301 
1302             // broken signatures imply no macro execution at all
1303             pImp->aMacroMode.disallowMacroExecution();
1304         }
1305     }
1306 }
1307 
1308 //-------------------------------------------------------------------------
1309 void SfxObjectShell::CheckForBrokenDocSignatures_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
1310 {
1311     sal_Int16 nSignatureState = GetDocumentSignatureState();
1312     bool bSignatureBroken = ( nSignatureState == SIGNATURESTATE_SIGNATURES_BROKEN );
1313     if ( !bSignatureBroken )
1314         return;
1315 
1316     pImp->showBrokenSignatureWarning( xHandler );
1317 
1318     // broken signatures imply no macro execution at all
1319     pImp->aMacroMode.disallowMacroExecution();
1320 }
1321 
1322 //-------------------------------------------------------------------------
1323 void SfxObjectShell::SetAutoLoad(
1324 	const INetURLObject& rUrl, sal_uInt32 nTime, sal_Bool bReload )
1325 {
1326 	if ( pImp->pReloadTimer )
1327 		DELETEZ(pImp->pReloadTimer);
1328 	if ( bReload )
1329 	{
1330 		pImp->pReloadTimer = new AutoReloadTimer_Impl(
1331 								rUrl.GetMainURL( INetURLObject::DECODE_TO_IURI ),
1332 								nTime, bReload, this );
1333 		pImp->pReloadTimer->Start();
1334 	}
1335 }
1336 
1337 sal_Bool SfxObjectShell::IsLoadingFinished() const
1338 {
1339 	return ( pImp->nLoadedFlags == SFX_LOADED_ALL );
1340 }
1341 
1342 void impl_addToModelCollection(const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& xModel);
1343 void SfxObjectShell::InitOwnModel_Impl()
1344 {
1345 	if ( !pImp->bModelInitialized )
1346 	{
1347 		SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
1348 		if ( pSalvageItem )
1349 		{
1350             pImp->aTempName = pMedium->GetPhysicalName();
1351 			pMedium->GetItemSet()->ClearItem( SID_DOC_SALVAGE );
1352 			pMedium->GetItemSet()->ClearItem( SID_FILE_NAME );
1353 			pMedium->GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, pMedium->GetOrigURL() ) );
1354 		}
1355 		else
1356 		{
1357 			pMedium->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
1358 			pMedium->GetItemSet()->ClearItem( SID_DOCUMENT );
1359 		}
1360 
1361 		pMedium->GetItemSet()->ClearItem( SID_REFERER );
1362 		uno::Reference< frame::XModel > xModel ( GetModel(), uno::UNO_QUERY );
1363 		if ( xModel.is() )
1364 		{
1365 			::rtl::OUString aURL = GetMedium()->GetOrigURL();
1366 			SfxItemSet *pSet = GetMedium()->GetItemSet();
1367             if ( !GetMedium()->IsReadOnly() )
1368                 pSet->ClearItem( SID_INPUTSTREAM );
1369 			uno::Sequence< beans::PropertyValue > aArgs;
1370 			TransformItems( SID_OPENDOC, *pSet, aArgs );
1371 			xModel->attachResource( aURL, aArgs );
1372             impl_addToModelCollection(xModel);
1373 		}
1374 
1375 		pImp->bModelInitialized = sal_True;
1376 	}
1377 }
1378 
1379 void SfxObjectShell::FinishedLoading( sal_uInt16 nFlags )
1380 {
1381 	sal_Bool bSetModifiedTRUE = sal_False;
1382 	SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
1383     if( ( nFlags & SFX_LOADED_MAINDOCUMENT ) && !(pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )
1384 	    && !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ))
1385 	{
1386 		pImp->nFlagsInProgress |= SFX_LOADED_MAINDOCUMENT;
1387 		((SfxHeaderAttributes_Impl*)GetHeaderAttributes())->SetAttributes();
1388 		pImp->bImportDone = sal_True;
1389 		if( !IsAbortingImport() )
1390 			PositionView_Impl();
1391 
1392         if ( ( GetModifyPasswordHash() || GetModifyPasswordInfo().getLength() ) && !IsModifyPasswordEntered() )
1393             SetReadOnly();
1394 
1395 		// Salvage
1396 		if ( pSalvageItem )
1397 			bSetModifiedTRUE = sal_True;
1398 
1399 		if ( !IsEnableSetModified() )
1400 			EnableSetModified( sal_True );
1401 
1402 		if( !bSetModifiedTRUE && IsEnableSetModified() )
1403 			SetModified( sal_False );
1404 
1405         CheckSecurityOnLoading_Impl();
1406 
1407 		bHasName = sal_True; // the document is loaded, so the name should already available
1408 		GetTitle( SFX_TITLE_DETECT );
1409 		InitOwnModel_Impl();
1410 		pImp->nFlagsInProgress &= ~SFX_LOADED_MAINDOCUMENT;
1411 	}
1412 
1413     if( ( nFlags & SFX_LOADED_IMAGES ) && !(pImp->nLoadedFlags & SFX_LOADED_IMAGES )
1414 	    && !(pImp->nFlagsInProgress & SFX_LOADED_IMAGES ))
1415 	{
1416 		pImp->nFlagsInProgress |= SFX_LOADED_IMAGES;
1417         uno::Reference<document::XDocumentProperties> xDocProps(
1418             getDocProperties());
1419         ::rtl::OUString url(xDocProps->getAutoloadURL());
1420         sal_Int32 delay(xDocProps->getAutoloadSecs());
1421         SetAutoLoad( INetURLObject(url), delay * 1000,
1422                      (delay > 0) || url.getLength() );
1423 		if( !bSetModifiedTRUE && IsEnableSetModified() )
1424 			SetModified( sal_False );
1425 		Invalidate( SID_SAVEASDOC );
1426 		pImp->nFlagsInProgress &= ~SFX_LOADED_IMAGES;
1427 	}
1428 
1429 	pImp->nLoadedFlags |= nFlags;
1430 
1431 	if ( !pImp->nFlagsInProgress )
1432 	{
1433 		// in case of reentrance calls the first called FinishedLoading() call on the stack
1434 		// should do the notification, in result the notification is done when all the FinishedLoading() calls are finished
1435 
1436 		if ( bSetModifiedTRUE )
1437 			SetModified( sal_True );
1438 		else
1439 			SetModified( sal_False );
1440 
1441 		if ( (pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) && (pImp->nLoadedFlags & SFX_LOADED_IMAGES ) )
1442 		{
1443             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
1444             sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
1445 
1446 			// closing the streams on loading should be under control of SFX!
1447 			DBG_ASSERT( pMedium->IsOpen(), "Don't close the medium when loading documents!" );
1448 
1449             if ( bTemplate )
1450             {
1451                 TemplateDisconnectionAfterLoad();
1452             }
1453             else
1454             {
1455                 // if a readonly medium has storage then it's stream is already based on temporary file
1456                 if( !(pMedium->GetOpenMode() & STREAM_WRITE) && !pMedium->HasStorage_Impl() )
1457                     // don't lock file opened read only
1458                     pMedium->CloseInStream();
1459             }
1460 		}
1461 
1462         SetInitialized_Impl( false );
1463 
1464 		// Title is not available until loading has finished
1465 		Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) );
1466 		if ( pImp->nEventId )
1467 			PostActivateEvent_Impl(SfxViewFrame::GetFirst(this));
1468 	}
1469 }
1470 
1471 //-------------------------------------------------------------------------
1472 extern void SetTemplate_Impl( const String&, const String&, SfxObjectShell* );
1473 
1474 void SfxObjectShell::TemplateDisconnectionAfterLoad()
1475 {
1476     // document is created from a template
1477     //TODO/LATER: should the templates always be XML docs!
1478 
1479     SfxMedium* pTmpMedium = pMedium;
1480     if ( pTmpMedium )
1481     {
1482         String aName( pTmpMedium->GetName() );
1483         SFX_ITEMSET_ARG( pTmpMedium->GetItemSet(), pTemplNamItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False);
1484         String aTemplateName;
1485         if ( pTemplNamItem )
1486             aTemplateName = pTemplNamItem->GetValue();
1487         else
1488         {
1489             // !TODO/LATER: what's this?!
1490             // Interaktiv ( DClick, Contextmenu ) kommt kein Langname mit
1491             aTemplateName = getDocProperties()->getTitle();
1492             if ( !aTemplateName.Len() )
1493             {
1494                 INetURLObject aURL( aName );
1495                 aURL.CutExtension();
1496                 aTemplateName = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1497             }
1498         }
1499 
1500         // set medium to noname
1501         pTmpMedium->SetName( String(), sal_True );
1502         pTmpMedium->Init_Impl();
1503 
1504         // drop resource
1505         SetNoName();
1506         InvalidateName();
1507 
1508         if( IsPackageStorageFormat_Impl( *pTmpMedium ) )
1509         {
1510             // untitled document must be based on temporary storage
1511             // the medium should not dispose the storage in this case
1512             uno::Reference < embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
1513             GetStorage()->copyToStorage( xTmpStor );
1514 
1515             // the medium should disconnect from the original location
1516             // the storage should not be disposed since the document is still
1517             // based on it, but in DoSaveCompleted it will be disposed
1518             pTmpMedium->CanDisposeStorage_Impl( sal_False );
1519             pTmpMedium->Close();
1520 
1521             // setting the new storage the medium will be based on
1522             pTmpMedium->SetStorage_Impl( xTmpStor );
1523 
1524             ForgetMedium();
1525             if( !DoSaveCompleted( pTmpMedium ) )
1526                 SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
1527             else
1528             {
1529                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
1530                 sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False;
1531 
1532                 if ( !bSalvage )
1533                 {
1534                     // some further initializations for templates
1535                     SetTemplate_Impl( aName, aTemplateName, this );
1536                 }
1537 
1538                 // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
1539                 pTmpMedium->CanDisposeStorage_Impl( sal_False );
1540             }
1541         }
1542         else
1543         {
1544             // some further initializations for templates
1545             SetTemplate_Impl( aName, aTemplateName, this );
1546             pTmpMedium->CreateTempFile( sal_True );
1547         }
1548 
1549         // templates are never readonly
1550         pTmpMedium->GetItemSet()->ClearItem( SID_DOC_READONLY );
1551         pTmpMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True, sal_True );
1552 
1553         // notifications about possible changes in readonly state and document info
1554         Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
1555 
1556         // created untitled document can't be modified
1557         SetModified( sal_False );
1558     }
1559 }
1560 
1561 //-------------------------------------------------------------------------
1562 
1563 void SfxObjectShell::PositionView_Impl()
1564 {
1565 	MarkData_Impl *pMark = Get_Impl()->pMarkData;
1566 	if( pMark )
1567 	{
1568 		SfxViewShell* pSh = pMark->pFrame->GetViewShell();
1569 		if( pMark->aUserData.Len() )
1570 			pSh->ReadUserData( pMark->aUserData, sal_True );
1571 		else if( pMark->aMark.Len() )
1572 			pSh->JumpToMark( pMark->aMark );
1573 		DELETEZ( Get_Impl()->pMarkData );
1574 	}
1575 }
1576 
1577 //-------------------------------------------------------------------------
1578 
1579 sal_Bool SfxObjectShell::IsLoading() const
1580 /*  [Beschreibung ]
1581 	Has FinishedLoading been called? */
1582 {
1583 	return !( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT );
1584 }
1585 
1586 //-------------------------------------------------------------------------
1587 
1588 void SfxObjectShell::CancelTransfers()
1589 /*  [Beschreibung ]
1590 	Hier koennen Transfers gecanceled werden, die nicht mit
1591 	RegisterTransfer registiert wurden */
1592 {
1593 	if( ( pImp->nLoadedFlags & SFX_LOADED_ALL ) != SFX_LOADED_ALL )
1594 	{
1595 		AbortImport();
1596 		if( IsLoading() )
1597 			FinishedLoading( SFX_LOADED_ALL );
1598 
1599 /*
1600 		SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
1601 		while( pFrame )
1602 		{
1603 			pFrame->CancelTransfers();
1604 			pFrame = SfxViewFrame::GetNext( *pFrame, this );
1605 		}*/
1606 	}
1607 }
1608 
1609 //-------------------------------------------------------------------------
1610 
1611 AutoReloadTimer_Impl::AutoReloadTimer_Impl(
1612 	const String& rURL, sal_uInt32 nTime, sal_Bool bReloadP, SfxObjectShell* pSh )
1613 	: aUrl( rURL ), bReload( bReloadP ), pObjSh( pSh )
1614 {
1615 	SetTimeout( nTime );
1616 }
1617 
1618 //-------------------------------------------------------------------------
1619 
1620 void AutoReloadTimer_Impl::Timeout()
1621 {
1622 	SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pObjSh );
1623 
1624 	if ( pFrame )
1625 	{
1626 		// momentan nicht m"oglich/sinnvoll?
1627         if ( !pObjSh->CanReload_Impl() || pObjSh->IsAutoLoadLocked() || Application::IsUICaptured() )
1628 		{
1629 			// erneuten Versuch erlauben
1630 			Start();
1631 			return;
1632 		}
1633 
1634 		SfxAllItemSet aSet( SFX_APP()->GetPool() );
1635 		aSet.Put( SfxBoolItem( SID_AUTOLOAD, sal_True ) );
1636 		if ( aUrl.Len() )
1637 			aSet.Put(  SfxStringItem( SID_FILE_NAME, aUrl ) );
1638 		SfxRequest aReq( SID_RELOAD, 0, aSet );
1639 		pObjSh->Get_Impl()->pReloadTimer = 0;
1640 		delete this;
1641 		pFrame->ExecReload_Impl( aReq );
1642 		return;
1643 	}
1644 
1645 	pObjSh->Get_Impl()->pReloadTimer = 0;
1646 	delete this;
1647 }
1648 
1649 SfxModule* SfxObjectShell::GetModule() const
1650 {
1651 	return GetFactory().GetModule();
1652 }
1653 
1654 ErrCode SfxObjectShell::CallBasic( const String& rMacro,
1655 	const String& rBasic, SbxArray* pArgs,
1656 	SbxValue* pRet )
1657 {
1658     SfxApplication* pApp = SFX_APP();
1659     if( pApp->GetName() != rBasic )
1660     {
1661         if ( !AdjustMacroMode( String() ) )
1662             return ERRCODE_IO_ACCESSDENIED;
1663     }
1664 
1665     BasicManager *pMgr = GetBasicManager();
1666     if( pApp->GetName() == rBasic )
1667         pMgr = pApp->GetBasicManager();
1668     ErrCode nRet = SfxApplication::CallBasic( rMacro, pMgr, pArgs, pRet );
1669     return nRet;
1670 }
1671 
1672 namespace
1673 {
1674     static bool lcl_isScriptAccessAllowed_nothrow( const Reference< XInterface >& _rxScriptContext )
1675     {
1676         try
1677         {
1678             Reference< XEmbeddedScripts > xScripts( _rxScriptContext, UNO_QUERY );
1679             if ( !xScripts.is() )
1680             {
1681                 Reference< XScriptInvocationContext > xContext( _rxScriptContext, UNO_QUERY_THROW );
1682                 xScripts.set( xContext->getScriptContainer(), UNO_SET_THROW );
1683             }
1684 
1685             return xScripts->getAllowMacroExecution();
1686         }
1687         catch( const Exception& )
1688         {
1689         	DBG_UNHANDLED_EXCEPTION();
1690         }
1691         return false;
1692     }
1693 }
1694 
1695 ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptContext, const ::rtl::OUString& _rScriptURL,
1696     const Sequence< Any >& aParams, Any& aRet, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam, bool bRaiseError )
1697 {
1698     OSL_TRACE( "in CallXScript" );
1699 	ErrCode nErr = ERRCODE_NONE;
1700 
1701 	bool bCaughtException = false;
1702     Any aException;
1703     try
1704     {
1705         if ( !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
1706             return ERRCODE_IO_ACCESSDENIED;
1707 
1708         // obtain/create a script provider
1709         Reference< provider::XScriptProvider > xScriptProvider;
1710         Reference< provider::XScriptProviderSupplier > xSPS( _rxScriptContext, UNO_QUERY );
1711         if ( xSPS.is() )
1712             xScriptProvider.set( xSPS->getScriptProvider() );
1713 
1714         if ( !xScriptProvider.is() )
1715         {
1716             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
1717             Reference< provider::XScriptProviderFactory > xScriptProviderFactory(
1718                 aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW );
1719             xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( _rxScriptContext ) ), UNO_SET_THROW );
1720         }
1721 
1722         // ry to protect the invocation context's undo manager (if present), just in case the script tampers with it
1723         ::framework::DocumentUndoGuard aUndoGuard( _rxScriptContext.get() );
1724 
1725         // obtain the script, and execute it
1726         Reference< provider::XScript > xScript( xScriptProvider->getScript( _rScriptURL ), UNO_QUERY_THROW );
1727         aRet = xScript->invoke( aParams, aOutParamIndex, aOutParam );
1728     }
1729     catch ( const uno::Exception& )
1730     {
1731         aException = ::cppu::getCaughtException();
1732 		bCaughtException = sal_True;
1733         nErr = ERRCODE_BASIC_INTERNAL_ERROR;
1734     }
1735 
1736 	if ( bCaughtException && bRaiseError )
1737 	{
1738         ::std::auto_ptr< VclAbstractDialog > pScriptErrDlg;
1739 		SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1740         if ( pFact )
1741             pScriptErrDlg.reset( pFact->CreateScriptErrorDialog( NULL, aException ) );
1742         OSL_ENSURE( pScriptErrDlg.get(), "SfxObjectShell::CallXScript: no script error dialog!" );
1743 
1744         if ( pScriptErrDlg.get() )
1745 			pScriptErrDlg->Execute();
1746 	}
1747 
1748     OSL_TRACE( "leaving CallXScript" );
1749     return nErr;
1750 }
1751 
1752 // perhaps rename to CallScript once we get rid of the existing CallScript
1753 // and Call, CallBasic, CallStarBasic methods
1754 ErrCode SfxObjectShell::CallXScript( const String& rScriptURL,
1755         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >&
1756             aParams,
1757         ::com::sun::star::uno::Any& aRet,
1758         ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex,
1759         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam
1760         , bool bRaiseError )
1761 {
1762     return CallXScript( GetModel(), rScriptURL, aParams, aRet, aOutParamIndex, aOutParam, bRaiseError );
1763 }
1764 
1765 //-------------------------------------------------------------------------
1766 SfxFrame* SfxObjectShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ )
1767 {
1768 	return pSelf;
1769 }
1770 
1771 SfxObjectShellFlags SfxObjectShell::GetFlags() const
1772 {
1773 	if( pImp->eFlags == SFXOBJECTSHELL_UNDEFINED )
1774 		pImp->eFlags = GetFactory().GetFlags();
1775 	return pImp->eFlags;
1776 }
1777 
1778 void SfxObjectShell::SetFlags( SfxObjectShellFlags eFlags )
1779 {
1780 	pImp->eFlags = eFlags;
1781 }
1782 
1783 void SfxHeaderAttributes_Impl::SetAttributes()
1784 {
1785 	bAlert = sal_True;
1786 	SvKeyValue aPair;
1787 	for( sal_Bool bCont = xIter->GetFirst( aPair ); bCont;
1788 		 bCont = xIter->GetNext( aPair ) )
1789 		SetAttribute( aPair );
1790 }
1791 
1792 void SfxHeaderAttributes_Impl::SetAttribute( const SvKeyValue& rKV )
1793 {
1794 	String aValue = rKV.GetValue();
1795 	if( rKV.GetKey().CompareIgnoreCaseToAscii( "refresh" ) == COMPARE_EQUAL && rKV.GetValue().Len() )
1796 	{
1797 		sal_uInt32 nTime = aValue.GetToken( 0, ';' ).ToInt32() ;
1798 		String aURL = aValue.GetToken( 1, ';' );
1799 		aURL.EraseTrailingChars().EraseLeadingChars();
1800         uno::Reference<document::XDocumentProperties> xDocProps(
1801             pDoc->getDocProperties());
1802 		if( aURL.Copy(0, 4).CompareIgnoreCaseToAscii( "url=" ) == COMPARE_EQUAL )
1803 		{
1804 			INetURLObject aObj;
1805 			INetURLObject( pDoc->GetMedium()->GetName() ).GetNewAbsURL( aURL.Copy( 4 ), &aObj );
1806             xDocProps->setAutoloadURL(
1807                 aObj.GetMainURL( INetURLObject::NO_DECODE ) );
1808 		}
1809         try
1810         {
1811             xDocProps->setAutoloadSecs( nTime );
1812         }
1813         catch (lang::IllegalArgumentException &)
1814         {
1815             // ignore
1816         }
1817 	}
1818 	else if( rKV.GetKey().CompareIgnoreCaseToAscii( "expires" ) == COMPARE_EQUAL )
1819 	{
1820 		DateTime aDateTime;
1821 		if( INetRFC822Message::ParseDateField( rKV.GetValue(), aDateTime ) )
1822 		{
1823 			aDateTime.ConvertToLocalTime();
1824 			pDoc->GetMedium()->SetExpired_Impl( aDateTime );
1825 		}
1826 		else
1827 		{
1828 //			DBG_ERROR( "Schlechtes ::com::sun::star::util::DateTime fuer Expired" );
1829 			pDoc->GetMedium()->SetExpired_Impl( Date( 1, 1, 1970 ) );
1830 		}
1831 	}
1832 	else if( rKV.GetKey().CompareIgnoreCaseToAscii( "content-type" ) == COMPARE_EQUAL )
1833 	{
1834 		::rtl::OString sContent = ::rtl::OUStringToOString( aValue, RTL_TEXTENCODING_ASCII_US );
1835 		ByteString sType, sSubType;
1836 		INetContentTypeParameterList aParameters;
1837 
1838 		if( INetContentTypes::parse( sContent, sType, sSubType, &aParameters ) )
1839 		{
1840 			const INetContentTypeParameter * pCharset = aParameters.find("charset");
1841 			if (pCharset != 0)
1842 				pDoc->GetMedium()->SetCharset( pCharset->m_sValue );
1843 		}
1844 	}
1845 }
1846 
1847 void SfxHeaderAttributes_Impl::Append( const SvKeyValue& rKV )
1848 {
1849 	xIter->Append( rKV );
1850 	if( bAlert ) SetAttribute( rKV );
1851 }
1852 
1853 SvKeyValueIterator* SfxObjectShell::GetHeaderAttributes()
1854 {
1855 	if( !pImp->xHeaderAttributes.Is() )
1856 	{
1857 		DBG_ASSERT( pMedium, "Kein Medium" );
1858 		pImp->xHeaderAttributes = new SfxHeaderAttributes_Impl( this );
1859 	}
1860 	return ( SvKeyValueIterator*) &pImp->xHeaderAttributes;
1861 }
1862 
1863 void SfxObjectShell::ClearHeaderAttributesForSourceViewHack()
1864 {
1865 	((SfxHeaderAttributes_Impl*)GetHeaderAttributes())
1866 		->ClearForSourceView();
1867 }
1868 
1869 
1870 void SfxObjectShell::SetHeaderAttributesForSourceViewHack()
1871 {
1872 	((SfxHeaderAttributes_Impl*)GetHeaderAttributes())
1873 		->SetAttributes();
1874 }
1875 
1876 sal_Bool SfxObjectShell::IsPreview() const
1877 {
1878 	if ( !pMedium )
1879 		return sal_False;
1880 
1881 	sal_Bool bPreview = sal_False;
1882 	SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False);
1883 	if ( pFlags )
1884 	{
1885 		// Werte auf einzelne Items verteilen
1886 		String aFileFlags = pFlags->GetValue();
1887 		aFileFlags.ToUpperAscii();
1888 		if ( STRING_NOTFOUND != aFileFlags.Search( 'B' ) )
1889 			bPreview = sal_True;
1890 	}
1891 
1892 	if ( !bPreview )
1893 	{
1894 		SFX_ITEMSET_ARG( pMedium->GetItemSet(), pItem, SfxBoolItem, SID_PREVIEW, sal_False);
1895 		if ( pItem )
1896 			bPreview = pItem->GetValue();
1897 	}
1898 
1899 	return bPreview;
1900 }
1901 
1902 sal_Bool SfxObjectShell::IsSecure()
1903 {
1904 	// Wenn globale Warnung an ist, nach Secure-Referer-Liste gehen
1905 	String aReferer = GetMedium()->GetName();
1906 	if ( !aReferer.Len() )
1907 	{
1908 		// bei neuen Dokumenten das Template als Referer nehmen
1909 		::rtl::OUString aTempl( getDocProperties()->getTemplateURL() );
1910 		if ( aTempl.getLength() )
1911             aReferer = INetURLObject( aTempl ).GetMainURL( INetURLObject::NO_DECODE );
1912 	}
1913 
1914 	INetURLObject aURL( "macro:" );
1915     if ( !aReferer.Len() )
1916         // empty new or embedded document
1917         return sal_True;
1918 
1919 		SvtSecurityOptions aOpt;
1920 
1921 	if( aOpt.GetBasicMode() == eALWAYS_EXECUTE )
1922     	return sal_True;
1923 
1924 	if( aOpt.GetBasicMode() == eNEVER_EXECUTE )
1925     	return sal_False;
1926 
1927 	if ( aOpt.IsSecureURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aReferer ) )
1928     //if ( SvtSecurityOptions().IsSecureURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aReferer ) )
1929 	{
1930         if ( GetMedium()->GetContent().is() )
1931         {
1932             Any aAny( ::utl::UCBContentHelper::GetProperty( aURL.GetMainURL( INetURLObject::NO_DECODE ), String( RTL_CONSTASCII_USTRINGPARAM("IsProtected")) ) );
1933             sal_Bool bIsProtected = sal_False;
1934             if ( ( aAny >>= bIsProtected ) && bIsProtected )
1935                 return sal_False;
1936             else
1937                 return sal_True;
1938 		}
1939 		else
1940 			return sal_True;
1941 	}
1942 	else
1943 		return sal_False;
1944 }
1945 
1946 void SfxObjectShell::SetWaitCursor( sal_Bool bSet ) const
1947 {
1948     for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) )
1949     {
1950         if ( bSet )
1951             pFrame->GetFrame().GetWindow().EnterWait();
1952         else
1953             pFrame->GetFrame().GetWindow().LeaveWait();
1954     }
1955 }
1956 
1957 String SfxObjectShell::GetAPIName() const
1958 {
1959 	INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
1960     String aName( aURL.GetBase() );
1961     if( !aName.Len() )
1962         aName = aURL.GetURLNoPass();
1963     if ( !aName.Len() )
1964         aName = GetTitle( SFX_TITLE_DETECT );
1965     return aName;
1966 }
1967 
1968 void SfxObjectShell::Invalidate( sal_uInt16 nId )
1969 {
1970     for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) )
1971         Invalidate_Impl( pFrame->GetBindings(), nId );
1972 }
1973 
1974 bool SfxObjectShell::AdjustMacroMode( const String& /*rScriptType*/, bool bSuppressUI )
1975 {
1976     uno::Reference< task::XInteractionHandler > xInteraction;
1977     if ( pMedium && !bSuppressUI )
1978         xInteraction = pMedium->GetInteractionHandler();
1979 
1980     CheckForBrokenDocSignatures_Impl( xInteraction );
1981 
1982     CheckEncryption_Impl( xInteraction );
1983 
1984     return pImp->aMacroMode.adjustMacroMode( xInteraction );
1985 }
1986 
1987 Window* SfxObjectShell::GetDialogParent( SfxMedium* pLoadingMedium )
1988 {
1989     Window* pWindow = 0;
1990     SfxItemSet* pSet = pLoadingMedium ? pLoadingMedium->GetItemSet() : GetMedium()->GetItemSet();
1991     SFX_ITEMSET_ARG( pSet, pUnoItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
1992     if ( pUnoItem )
1993     {
1994         uno::Reference < frame::XFrame > xFrame( pUnoItem->GetFrame() );
1995         pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
1996     }
1997 
1998     if ( !pWindow )
1999     {
2000         SfxFrame* pFrame = 0;
2001         SFX_ITEMSET_ARG( pSet, pFrameItem, SfxFrameItem, SID_DOCFRAME, sal_False );
2002         if( pFrameItem && pFrameItem->GetFrame() )
2003             // get target frame from ItemSet
2004             pFrame = pFrameItem->GetFrame();
2005         else
2006         {
2007             // try the current frame
2008             SfxViewFrame* pView = SfxViewFrame::Current();
2009             if ( !pView || pView->GetObjectShell() != this )
2010                 // get any visible frame
2011                 pView = SfxViewFrame::GetFirst(this);
2012             if ( pView )
2013                 pFrame = &pView->GetFrame();
2014         }
2015 
2016         if ( pFrame )
2017             // get topmost window
2018             pWindow = VCLUnoHelper::GetWindow( pFrame->GetFrameInterface()->getContainerWindow() );
2019     }
2020 
2021     if ( pWindow )
2022     {
2023         // this frame may be invisible, show it if it is allowed
2024         SFX_ITEMSET_ARG( pSet, pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
2025         if ( !pHiddenItem || !pHiddenItem->GetValue() )
2026         {
2027             pWindow->Show();
2028             pWindow->ToTop();
2029         }
2030     }
2031 
2032     return pWindow;
2033 }
2034 
2035 String SfxObjectShell::UpdateTitle( SfxMedium* pMed, sal_uInt16 nDocViewNumber )
2036 {
2037     // Titel des Fensters
2038     String aTitle;
2039     if ( pMed )
2040 	{
2041 		INetURLObject aTmp( pMed->GetName() );
2042         aTitle = aTmp.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
2043 	}
2044     else
2045     {
2046 		pMed = GetMedium();
2047         aTitle = GetTitle(SFX_TITLE_CAPTION);
2048         String aName(aTitle);
2049         if ( nDocViewNumber )
2050         {
2051             aName += ':';
2052             aName += String::CreateFromInt32( nDocViewNumber );
2053         }
2054     }
2055 
2056 	if ( pMed )
2057 	{
2058 		SFX_ITEMSET_ARG( pMed->GetItemSet(), pRepairedDocItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False );
2059 		if ( pRepairedDocItem && pRepairedDocItem->GetValue() )
2060         	aTitle += String( SfxResId(STR_REPAIREDDOCUMENT) );
2061 	}
2062 
2063 	if ( IsReadOnlyUI() || (pMed && pMed->IsReadOnly()) )
2064         aTitle += String( SfxResId(STR_READONLY) );
2065     else if ( IsDocShared() )
2066         aTitle += String( SfxResId(STR_SHARED) );
2067 
2068     return aTitle;
2069 }
2070 
2071 void SfxObjectShell::SetCreateMode_Impl( SfxObjectCreateMode nMode )
2072 {
2073 	eCreateMode = nMode;
2074 }
2075 
2076 sal_Bool SfxObjectShell::IsInPlaceActive()
2077 {
2078 	if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED )
2079 		return sal_False;
2080 
2081     SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
2082     return pFrame && pFrame->GetFrame().IsInPlace();
2083 }
2084 
2085 sal_Bool SfxObjectShell::IsUIActive()
2086 {
2087 	if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED )
2088 		return sal_False;
2089 
2090     SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
2091     return pFrame && pFrame->GetFrame().IsInPlace() && pFrame->GetFrame().GetWorkWindow_Impl()->IsVisible_Impl();
2092 }
2093 
2094 void SfxObjectShell::UIActivate( sal_Bool )
2095 {
2096 }
2097 
2098 void SfxObjectShell::InPlaceActivate( sal_Bool )
2099 {
2100 }
2101 
2102 sal_Bool SfxObjectShell::UseInteractionToHandleError(
2103                     const uno::Reference< task::XInteractionHandler >& xHandler,
2104                     sal_uInt32 nError )
2105 {
2106     sal_Bool bResult = sal_False;
2107 
2108     if ( xHandler.is() )
2109     {
2110         try
2111         {
2112             uno::Any aInteraction;
2113             uno::Sequence< uno::Reference< task::XInteractionContinuation > > lContinuations(2);
2114             ::comphelper::OInteractionAbort* pAbort = new ::comphelper::OInteractionAbort();
2115             ::comphelper::OInteractionApprove* pApprove = new ::comphelper::OInteractionApprove();
2116             lContinuations[0] = uno::Reference< task::XInteractionContinuation >(
2117                                  static_cast< task::XInteractionContinuation* >( pAbort ), uno::UNO_QUERY );
2118             lContinuations[1] = uno::Reference< task::XInteractionContinuation >(
2119                                  static_cast< task::XInteractionContinuation* >( pApprove ), uno::UNO_QUERY );
2120 
2121             task::ErrorCodeRequest aErrorCode;
2122             aErrorCode.ErrCode = nError;
2123             aInteraction <<= aErrorCode;
2124             xHandler->handle(::framework::InteractionRequest::CreateRequest (aInteraction,lContinuations));
2125             bResult = pAbort->wasSelected();
2126         }
2127         catch( uno::Exception& )
2128         {}
2129     }
2130 
2131     return bResult;
2132 }
2133 
2134 sal_Bool SfxObjectShell_Impl::NeedsOfficeUpdateDialog()
2135 {
2136     // if the configuration is not available for any reason, the default behavior is to show the message
2137     sal_Bool bResult = sal_True;
2138 
2139     try
2140     {
2141     	uno::Reference< lang::XMultiServiceFactory > xServiceManager( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
2142 		uno::Reference< uno::XInterface > xCommonConfig(
2143                         ::comphelper::ConfigurationHelper::openConfig(
2144 							xServiceManager,
2145 							::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ),
2146 							::comphelper::ConfigurationHelper::E_STANDARD ),
2147                         uno::UNO_SET_THROW );
2148 
2149         ::comphelper::ConfigurationHelper::readRelativeKey(
2150                         xCommonConfig,
2151                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Load/" ) ),
2152                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ShowOfficeUpdateDialog" ) ) ) >>= bResult;
2153     }
2154     catch( uno::Exception& )
2155     {
2156     }
2157 
2158 	return bResult;
2159 }
2160 
2161 sal_Int16 SfxObjectShell_Impl::getCurrentMacroExecMode() const
2162 {
2163     sal_Int16 nImposedExecMode( MacroExecMode::NEVER_EXECUTE );
2164 
2165     const SfxMedium* pMedium( rDocShell.GetMedium() );
2166     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
2167     if ( pMedium )
2168     {
2169         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pMacroModeItem, SfxUInt16Item, SID_MACROEXECMODE, sal_False);
2170         if ( pMacroModeItem )
2171             nImposedExecMode = pMacroModeItem->GetValue();
2172     }
2173     return nImposedExecMode;
2174 }
2175 
2176 sal_Bool SfxObjectShell_Impl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
2177 {
2178     const SfxMedium* pMedium( rDocShell.GetMedium() );
2179     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
2180     if ( pMedium )
2181     {
2182 		pMedium->GetItemSet()->Put( SfxUInt16Item( SID_MACROEXECMODE, nMacroMode ) );
2183         return sal_True;
2184     }
2185 
2186     return sal_False;
2187 }
2188 
2189 ::rtl::OUString SfxObjectShell_Impl::getDocumentLocation() const
2190 {
2191     ::rtl::OUString sLocation;
2192 
2193     const SfxMedium* pMedium( rDocShell.GetMedium() );
2194     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getDocumentLocation: no medium!" );
2195     if ( pMedium )
2196     {
2197         sLocation = pMedium->GetName();
2198         if ( !sLocation.getLength() )
2199         {
2200             // for documents made from a template: get the name of the template
2201             sLocation = rDocShell.getDocProperties()->getTemplateURL();
2202         }
2203     }
2204     return sLocation;
2205 }
2206 
2207 uno::Reference< embed::XStorage > SfxObjectShell_Impl::getZipStorageToSign()
2208 {
2209     Reference < embed::XStorage > xStore;
2210 
2211     SfxMedium* pMedium( rDocShell.GetMedium() );
2212     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getLastCommitDocumentStorage: no medium!" );
2213     if ( pMedium )
2214         xStore = pMedium->GetZipStorageToSign_Impl();
2215 
2216     return xStore;
2217 }
2218 
2219 sal_Bool SfxObjectShell_Impl::documentStorageHasMacros() const
2220 {
2221     return ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocStorage );
2222 }
2223 
2224 Reference< XEmbeddedScripts > SfxObjectShell_Impl::getEmbeddedDocumentScripts() const
2225 {
2226     return Reference< XEmbeddedScripts >( rDocShell.GetModel(), UNO_QUERY );
2227 }
2228 
2229 sal_Int16 SfxObjectShell_Impl::getScriptingSignatureState()
2230 {
2231     sal_Int16 nSignatureState( rDocShell.GetScriptingSignatureState() );
2232 
2233     if ( nSignatureState != SIGNATURESTATE_NOSIGNATURES && m_bMacroSignBroken )
2234     {
2235         // if there is a macro signature it must be handled as broken
2236         nSignatureState = SIGNATURESTATE_SIGNATURES_BROKEN;
2237     }
2238 
2239     return nSignatureState;
2240 }
2241 
2242 sal_Bool SfxObjectShell_Impl::hasTrustedScriptingSignature( sal_Bool bAllowUIToAddAuthor )
2243 {
2244     sal_Bool bResult = sal_False;
2245 
2246     try
2247     {
2248         ::rtl::OUString aVersion;
2249         try
2250         {
2251             uno::Reference < beans::XPropertySet > xPropSet( rDocShell.GetStorage(), uno::UNO_QUERY_THROW );
2252             xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aVersion;
2253         }
2254         catch( uno::Exception& )
2255         {
2256         }
2257         uno::Sequence< uno::Any > aArgs( 1 );
2258         aArgs[0] <<= aVersion;
2259 
2260         uno::Reference< security::XDocumentDigitalSignatures > xSigner( comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ), aArgs ), uno::UNO_QUERY_THROW );
2261 
2262         if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN
2263           || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
2264           || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
2265         {
2266             uno::Sequence< security::DocumentSignatureInformation > aInfo = rDocShell.ImplAnalyzeSignature( sal_True, xSigner );
2267 
2268             if ( aInfo.getLength() )
2269             {
2270                 if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN )
2271                     nScriptingSignatureState = rDocShell.ImplCheckSignaturesInformation( aInfo );
2272 
2273                 if ( nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
2274                   || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
2275                 {
2276                     for ( sal_Int32 nInd = 0; !bResult && nInd < aInfo.getLength(); nInd++ )
2277                     {
2278                         bResult = xSigner->isAuthorTrusted( aInfo[nInd].Signer );
2279                     }
2280 
2281                     if ( !bResult && bAllowUIToAddAuthor )
2282                     {
2283                         uno::Reference< task::XInteractionHandler > xInteraction;
2284                         if ( rDocShell.GetMedium() )
2285                             xInteraction = rDocShell.GetMedium()->GetInteractionHandler();
2286 
2287                         if ( xInteraction.is() )
2288                         {
2289                             task::DocumentMacroConfirmationRequest aRequest;
2290                             aRequest.DocumentURL = getDocumentLocation();
2291                             aRequest.DocumentStorage = rDocShell.GetMedium()->GetZipStorageToSign_Impl();
2292                             aRequest.DocumentSignatureInformation = aInfo;
2293                             aRequest.DocumentVersion = aVersion;
2294                             aRequest.Classification = task::InteractionClassification_QUERY;
2295                             bResult = SfxMedium::CallApproveHandler( xInteraction, uno::makeAny( aRequest ), sal_True );
2296                         }
2297                     }
2298                 }
2299             }
2300         }
2301     }
2302     catch( uno::Exception& )
2303     {}
2304 
2305     return bResult;
2306 }
2307 
2308 void SfxObjectShell_Impl::showBrokenSignatureWarning( const uno::Reference< task::XInteractionHandler >& _rxInteraction ) const
2309 {
2310     if  ( !bSignatureErrorIsShown )
2311     {
2312         SfxObjectShell::UseInteractionToHandleError( _rxInteraction, ERRCODE_SFX_BROKENSIGNATURE );
2313 	    const_cast< SfxObjectShell_Impl* >( this )->bSignatureErrorIsShown = sal_True;
2314     }
2315 }
2316 
2317 void SfxObjectShell::AddLog( const ::rtl::OUString& aMessage )
2318 {
2319     if ( !pImp->m_xLogRing.is() )
2320     {
2321         try
2322         {
2323             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
2324             if ( aContext.is() )
2325                 pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW );
2326         }
2327         catch( uno::Exception& )
2328         {}
2329     }
2330 
2331     if ( pImp->m_xLogRing.is() )
2332         pImp->m_xLogRing->logString( aMessage );
2333 }
2334 
2335 namespace {
2336 
2337 void WriteStringInStream( const uno::Reference< io::XOutputStream >& xOutStream, const ::rtl::OUString& aString )
2338 {
2339     if ( xOutStream.is() )
2340     {
2341         ::rtl::OString aStrLog = ::rtl::OUStringToOString( aString, RTL_TEXTENCODING_UTF8 );
2342         uno::Sequence< sal_Int8 > aLogData( (const sal_Int8*)aStrLog.getStr(), aStrLog.getLength() );
2343         xOutStream->writeBytes( aLogData );
2344 
2345         aLogData.realloc( 1 );
2346         aLogData[0] = '\n';
2347         xOutStream->writeBytes( aLogData );
2348     }
2349 }
2350 
2351 }
2352 
2353 void SfxObjectShell::StoreLog()
2354 {
2355     if ( !pImp->m_xLogRing.is() )
2356     {
2357         try
2358         {
2359             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
2360             if ( aContext.is() )
2361                 pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW );
2362         }
2363         catch( uno::Exception& )
2364         {}
2365     }
2366 
2367     if ( pImp->m_xLogRing.is() )
2368     {
2369         ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}" ) );
2370 //#ifdef WNT
2371 //        ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}" ) );
2372 //#else
2373 //        ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/bootstraprc:UserInstallation}" ) );
2374 //#endif
2375         ::rtl::Bootstrap::expandMacros( aFileURL );
2376 
2377 //#ifdef WNT
2378 //        ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/setup.ini:buildid}" ) );
2379 //#else
2380 //        ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/setuprc:buildid}" ) );
2381 //#endif
2382         ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("setup") ":buildid}" ) );
2383         ::rtl::Bootstrap::expandMacros( aBuildID );
2384 
2385         if ( aFileURL.getLength() )
2386         {
2387             aFileURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/temp/document_io_logring.txt" ) );
2388             try
2389             {
2390                 uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
2391                 uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess( xFactory->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.ucb.SimpleFileAccess" ) ), uno::UNO_QUERY_THROW );
2392                 uno::Reference< io::XStream > xStream( xSimpleFileAccess->openFileReadWrite( aFileURL ), uno::UNO_SET_THROW );
2393                 uno::Reference< io::XOutputStream > xOutStream( xStream->getOutputStream(), uno::UNO_SET_THROW );
2394                 uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY_THROW );
2395                 xTruncate->truncate();
2396 
2397                 if ( aBuildID.getLength() )
2398                     WriteStringInStream( xOutStream, aBuildID );
2399 
2400                 uno::Sequence< ::rtl::OUString > aLogSeq = pImp->m_xLogRing->getCollectedLog();
2401                 for ( sal_Int32 nInd = 0; nInd < aLogSeq.getLength(); nInd++ )
2402                     WriteStringInStream( xOutStream, aLogSeq[nInd] );
2403             }
2404             catch( uno::Exception& )
2405             {}
2406         }
2407     }
2408 }
2409