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/helper/vclunohelper.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 "com/sun/star/uri/XUriReferenceFactory.hpp" 79 #include <com/sun/star/uri/XVndSunStarScriptUrlReference.hpp> 80 81 #include <comphelper/processfactory.hxx> 82 #include <comphelper/componentcontext.hxx> 83 #include <comphelper/configurationhelper.hxx> 84 85 #include <com/sun/star/security/XDocumentDigitalSignatures.hpp> 86 #include <com/sun/star/task/DocumentMacroConfirmationRequest.hpp> 87 #include <com/sun/star/task/InteractionClassification.hpp> 88 #include <com/sun/star/frame/XModel.hpp> 89 90 using namespace ::com::sun::star; 91 using namespace ::com::sun::star::uno; 92 using namespace ::com::sun::star::ucb; 93 using namespace ::com::sun::star::document; 94 using namespace ::com::sun::star::frame; 95 using namespace ::com::sun::star::script; 96 using namespace ::com::sun::star::script::provider; 97 using namespace ::com::sun::star::container; 98 #include <basic/sbuno.hxx> 99 #include <basic/sbstar.hxx> 100 #ifndef _SB_BASMGR_HXX 101 #include <basic/basmgr.hxx> 102 #endif 103 #ifndef _VCL_MSGBOX_HXX 104 #include <vcl/msgbox.hxx> 105 #endif 106 #include <basic/sbx.hxx> 107 #include <svtools/sfxecode.hxx> 108 #include <svtools/ehdl.hxx> 109 110 #include <unotools/pathoptions.hxx> 111 #include <unotools/ucbhelper.hxx> 112 #include <tools/inetmime.hxx> 113 #include <tools/urlobj.hxx> 114 #include <svl/inettype.hxx> 115 #include <svl/sharecontrolfile.hxx> 116 #include <osl/file.hxx> 117 #include <rtl/bootstrap.hxx> 118 #include <vcl/svapp.hxx> 119 #include <framework/interaction.hxx> 120 #include <framework/documentundoguard.hxx> 121 #include <comphelper/interaction.hxx> 122 #include <comphelper/storagehelper.hxx> 123 #include <comphelper/documentconstants.hxx> 124 125 #include <sfx2/signaturestate.hxx> 126 #include <sfx2/app.hxx> 127 #include "appdata.hxx" 128 #include <sfx2/request.hxx> 129 #include <sfx2/bindings.hxx> 130 #include "sfx2/sfxresid.hxx" 131 #include <sfx2/docfile.hxx> 132 #include <sfx2/docfilt.hxx> 133 #include <sfx2/objsh.hxx> 134 #include "objshimp.hxx" 135 #include <sfx2/event.hxx> 136 #include "fltfnc.hxx" 137 #include <sfx2/sfx.hrc> 138 #include <sfx2/dispatch.hxx> 139 #include <sfx2/viewfrm.hxx> 140 #include <sfx2/viewsh.hxx> 141 #include <sfx2/ctrlitem.hxx> 142 #include "arrdecl.hxx" 143 #include <sfx2/module.hxx> 144 #include <sfx2/docfac.hxx> 145 #include "helper.hxx" 146 #include "doc.hrc" 147 #include "workwin.hxx" 148 #include "helpid.hrc" 149 #include "../appl/app.hrc" 150 #include <sfx2/sfxdlg.hxx> 151 #include "appbaslib.hxx" 152 #include <openflag.hxx> // SFX_STREAM_READWRITE 153 154 using namespace ::com::sun::star; 155 156 // class SfxHeaderAttributes_Impl ---------------------------------------- 157 158 class SfxHeaderAttributes_Impl : public SvKeyValueIterator 159 { 160 private: 161 SfxObjectShell* pDoc; 162 SvKeyValueIteratorRef xIter; 163 sal_Bool bAlert; 164 165 public: 166 SfxHeaderAttributes_Impl( SfxObjectShell* pSh ) : 167 SvKeyValueIterator(), pDoc( pSh ), 168 xIter( pSh->GetMedium()->GetHeaderAttributes_Impl() ), 169 bAlert( sal_False ) {} 170 171 virtual sal_Bool GetFirst( SvKeyValue& rKV ) { return xIter->GetFirst( rKV ); } 172 virtual sal_Bool GetNext( SvKeyValue& rKV ) { return xIter->GetNext( rKV ); } 173 virtual void Append( const SvKeyValue& rKV ); 174 175 void ClearForSourceView() { xIter = new SvKeyValueIterator; bAlert = sal_False; } 176 void SetAttributes(); 177 void SetAttribute( const SvKeyValue& rKV ); 178 }; 179 180 //========================================================================= 181 182 sal_uInt16 __READONLY_DATA aTitleMap_Impl[3][2] = 183 { 184 // local remote 185 /* SFX_TITLE_CAPTION */ { SFX_TITLE_FILENAME, SFX_TITLE_TITLE }, 186 /* SFX_TITLE_PICKLIST */ { 32, SFX_TITLE_FULLNAME }, 187 /* SFX_TITLE_HISTORY */ { 32, SFX_TITLE_FULLNAME } 188 }; 189 190 //========================================================================= 191 192 void SfxObjectShell::AbortImport() 193 { 194 pImp->bIsAbortingImport = sal_True; 195 } 196 197 //------------------------------------------------------------------------- 198 199 sal_Bool SfxObjectShell::IsAbortingImport() const 200 { 201 return pImp->bIsAbortingImport; 202 } 203 204 //------------------------------------------------------------------------- 205 206 uno::Reference<document::XDocumentProperties> 207 SfxObjectShell::getDocProperties() 208 { 209 uno::Reference<document::XDocumentPropertiesSupplier> xDPS( 210 GetModel(), uno::UNO_QUERY_THROW); 211 uno::Reference<document::XDocumentProperties> xDocProps( 212 xDPS->getDocumentProperties()); 213 DBG_ASSERT(xDocProps.is(), 214 "SfxObjectShell: model has no DocumentProperties"); 215 return xDocProps; 216 } 217 218 //------------------------------------------------------------------------- 219 220 void SfxObjectShell::DoFlushDocInfo() 221 { 222 } 223 224 //------------------------------------------------------------------------- 225 226 // Note: the only thing that calls this is the modification event handler 227 // that is installed at the XDocumentProperties 228 void SfxObjectShell::FlushDocInfo() 229 { 230 if ( IsLoading() ) 231 return; 232 233 SetModified(sal_True); 234 uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties()); 235 DoFlushDocInfo(); // call template method 236 ::rtl::OUString url(xDocProps->getAutoloadURL()); 237 sal_Int32 delay(xDocProps->getAutoloadSecs()); 238 SetAutoLoad( INetURLObject(url), delay * 1000, 239 (delay > 0) || url.getLength() ); 240 /* 241 // bitte beachten: 242 // 1. Titel in DocInfo aber nicht am Doc (nach HTML-Import) 243 // => auch am Doc setzen 244 // 2. Titel in DocInfo leer (Briefumschlagsdruck) 245 // => nicht am Doc setzen, da sonst "unbenanntX" daraus wird 246 String aDocInfoTitle = GetDocInfo().GetTitle(); 247 if ( aDocInfoTitle.Len() ) 248 SetTitle( aDocInfoTitle ); 249 else 250 { 251 pImp->aTitle.Erase(); 252 SetNamedVisibility_Impl(); 253 if ( GetMedium() ) 254 { 255 SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) ); 256 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) ); 257 } 258 }*/ 259 } 260 261 //------------------------------------------------------------------------- 262 263 void SfxObjectShell::SetError( sal_uInt32 lErr, const ::rtl::OUString& aLogMessage ) 264 { 265 if(pImp->lErr==ERRCODE_NONE) 266 { 267 pImp->lErr=lErr; 268 269 if( lErr != ERRCODE_NONE && aLogMessage.getLength() ) 270 AddLog( aLogMessage ); 271 } 272 } 273 274 //------------------------------------------------------------------------- 275 276 sal_uInt32 SfxObjectShell::GetError() const 277 { 278 return ERRCODE_TOERROR(GetErrorCode()); 279 } 280 281 //------------------------------------------------------------------------- 282 283 sal_uInt32 SfxObjectShell::GetErrorCode() const 284 { 285 sal_uInt32 lError=pImp->lErr; 286 if(!lError && GetMedium()) 287 lError=GetMedium()->GetErrorCode(); 288 return lError; 289 } 290 291 //------------------------------------------------------------------------- 292 293 void SfxObjectShell::ResetError() 294 { 295 if( pImp->lErr != ERRCODE_NONE ) 296 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Resetting Error." ) ) ); 297 298 pImp->lErr=0; 299 SfxMedium * pMed = GetMedium(); 300 if( pMed ) 301 pMed->ResetError(); 302 } 303 304 //------------------------------------------------------------------------- 305 306 sal_Bool SfxObjectShell::IsTemplate() const 307 { 308 return pImp->bIsTemplate; 309 } 310 311 //------------------------------------------------------------------------- 312 313 void SfxObjectShell::SetTemplate(sal_Bool bIs) 314 { 315 pImp->bIsTemplate=bIs; 316 SfxFilterMatcher aMatcher( GetFactory().GetFactoryName() ); 317 SfxFilterMatcherIter aIter( &aMatcher, SFX_FILTER_TEMPLATEPATH ); 318 SfxMedium* pMed = GetMedium(); 319 if( pMed ) pMed->SetFilter( aIter.First() ); 320 } 321 322 //------------------------------------------------------------------------- 323 324 void SfxObjectShell::EnableSetModified( sal_Bool bEnable ) 325 { 326 #ifdef DBG_UTIL 327 if ( bEnable == pImp->m_bEnableSetModified ) 328 DBG_WARNING( "SFX_PERSIST: EnableSetModified 2x mit dem gleichen Wert gerufen" ); 329 #endif 330 pImp->m_bEnableSetModified = bEnable; 331 } 332 333 //------------------------------------------------------------------------- 334 335 sal_Bool SfxObjectShell::IsEnableSetModified() const 336 { 337 return pImp->m_bEnableSetModified && !IsReadOnly(); 338 } 339 340 //------------------------------------------------------------------------- 341 342 sal_Bool SfxObjectShell::IsModified() 343 { 344 if ( pImp->m_bIsModified ) 345 return sal_True; 346 347 if ( !pImp->m_xDocStorage.is() || IsReadOnly() ) 348 { 349 // if the document still has no storage and is not set to be modified explicitly it is not modified 350 // a readonly document is also not modified 351 352 return sal_False; 353 } 354 355 uno::Sequence < ::rtl::OUString > aNames = GetEmbeddedObjectContainer().GetObjectNames(); 356 for ( sal_Int32 n=0; n<aNames.getLength(); n++ ) 357 { 358 uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObjectContainer().GetEmbeddedObject( aNames[n] ); 359 OSL_ENSURE( xObj.is(), "An empty entry in the embedded objects list!\n" ); 360 if ( xObj.is() ) 361 { 362 try 363 { 364 sal_Int32 nState = xObj->getCurrentState(); 365 if ( nState != embed::EmbedStates::LOADED ) 366 { 367 uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY ); 368 if ( xModifiable.is() && xModifiable->isModified() ) 369 return sal_True; 370 } 371 } 372 catch( uno::Exception& ) 373 {} 374 } 375 } 376 377 return sal_False; 378 } 379 380 //------------------------------------------------------------------------- 381 382 void SfxObjectShell::SetModified( sal_Bool bModifiedP ) 383 { 384 #ifdef DBG_UTIL 385 if ( !bModifiedP && !IsEnableSetModified() ) 386 DBG_WARNING( "SFX_PERSIST: SetModified( sal_False ), obwohl IsEnableSetModified() == sal_False" ); 387 #endif 388 389 if( !IsEnableSetModified() ) 390 return; 391 392 if( pImp->m_bIsModified != bModifiedP ) 393 { 394 pImp->m_bIsModified = bModifiedP; 395 ModifyChanged(); 396 } 397 } 398 399 //------------------------------------------------------------------------- 400 401 void SfxObjectShell::ModifyChanged() 402 { 403 if ( pImp->bClosing ) 404 // SetModified aus dem dispose des Models! 405 return; 406 407 {DBG_CHKTHIS(SfxObjectShell, 0);} 408 409 SfxViewFrame* pViewFrame = SfxViewFrame::Current(); 410 if ( pViewFrame ) 411 pViewFrame->GetBindings().Invalidate( SID_SAVEDOCS ); 412 413 Invalidate( SID_SIGNATURE ); 414 Invalidate( SID_MACRO_SIGNATURE ); 415 Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) ); // xmlsec05, signed state might change in title... 416 417 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_MODIFYCHANGED, GlobalEventConfig::GetEventName(STR_EVENT_MODIFYCHANGED), this ) ); 418 } 419 420 //------------------------------------------------------------------------- 421 422 sal_Bool SfxObjectShell::IsReadOnlyUI() const 423 424 /* [Beschreibung] 425 426 Liefert sal_True, wenn das Dokument fuer die UI wie r/o behandelt werden 427 soll. Dieses ist unabhaengig vom tatsaechlichen r/o, welches per 428 <IsReadOnly()> erfragbar ist. 429 */ 430 431 { 432 return pImp->bReadOnlyUI; 433 } 434 435 //------------------------------------------------------------------------- 436 437 sal_Bool SfxObjectShell::IsReadOnlyMedium() const 438 439 /* [Beschreibung] 440 441 Liefert sal_True, wenn das Medium r/o ist bzw. r/o geoeffnet wurde. 442 */ 443 444 { 445 if ( !pMedium ) 446 return sal_True; 447 return pMedium->IsReadOnly(); 448 } 449 450 //------------------------------------------------------------------------- 451 452 void SfxObjectShell::SetReadOnlyUI( sal_Bool bReadOnly ) 453 454 /* [Beschreibung] 455 456 Schaltet das Dokument in einen r/o bzw. r/w Zustand ohne es neu 457 zu laden und ohne die Open-Modi des Mediums zu aendern. 458 */ 459 460 { 461 sal_Bool bWasRO = IsReadOnly(); 462 pImp->bReadOnlyUI = bReadOnly; 463 if ( bWasRO != IsReadOnly() ) 464 { 465 Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) ); 466 //if ( pImp->pDocInfo ) 467 // pImp->pDocInfo->SetReadOnly( IsReadOnly() ); 468 } 469 } 470 471 //------------------------------------------------------------------------- 472 473 void SfxObjectShell::SetReadOnly() 474 { 475 // Let the document be completely readonly, means that the 476 // medium open mode is adjusted accordingly, and the write lock 477 // on the file is removed. 478 479 if ( pMedium && !IsReadOnlyMedium() ) 480 { 481 sal_Bool bWasROUI = IsReadOnly(); 482 483 pMedium->UnlockFile( sal_False ); 484 485 // the storage-based mediums are already based on the temporary file 486 // so UnlockFile has already closed the locking stream 487 if ( !pMedium->HasStorage_Impl() && IsLoadingFinished() ) 488 pMedium->CloseInStream(); 489 490 pMedium->SetOpenMode( SFX_STREAM_READONLY, pMedium->IsDirect(), sal_True ); 491 pMedium->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 492 493 if ( !bWasROUI ) 494 Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) ); 495 } 496 } 497 //------------------------------------------------------------------------- 498 499 sal_Bool SfxObjectShell::IsReadOnly() const 500 { 501 return pImp->bReadOnlyUI || IsReadOnlyMedium(); 502 } 503 504 //------------------------------------------------------------------------- 505 506 sal_Bool SfxObjectShell::IsInModalMode() const 507 { 508 return pImp->bModalMode || pImp->bRunningMacro; 509 } 510 511 //<!--Added by PengYunQuan for Validity Cell Range Picker 512 sal_Bool SfxObjectShell::AcceptStateUpdate() const 513 { 514 return !IsInModalMode(); 515 } 516 //-->Added by PengYunQuan for Validity Cell Range Picker 517 518 //------------------------------------------------------------------------- 519 520 sal_Bool SfxObjectShell::HasModalViews() const 521 { 522 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); 523 while( pFrame ) 524 { 525 if ( pFrame->IsInModalMode() ) 526 return sal_True; 527 528 pFrame = SfxViewFrame::GetNext( *pFrame, this ); 529 } 530 531 return sal_False; 532 } 533 534 //------------------------------------------------------------------------- 535 536 void SfxObjectShell::SetMacroMode_Impl( sal_Bool bModal ) 537 { 538 if ( !pImp->bRunningMacro != !bModal ) 539 { 540 pImp->bRunningMacro = bModal; 541 Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) ); 542 } 543 } 544 545 //------------------------------------------------------------------------- 546 547 void SfxObjectShell::SetModalMode_Impl( sal_Bool bModal ) 548 { 549 // nur Broadcasten wenn modifiziert, sonst ggf. Endlosrekursion 550 if ( !pImp->bModalMode != !bModal ) 551 { 552 // zentral mitz"ahlen 553 sal_uInt16 &rDocModalCount = SFX_APP()->Get_Impl()->nDocModalMode; 554 if ( bModal ) 555 ++rDocModalCount; 556 else 557 --rDocModalCount; 558 559 // umschalten 560 pImp->bModalMode = bModal; 561 Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) ); 562 } 563 } 564 565 //-------------------------------------------------------------------- 566 sal_Bool SfxObjectShell::SwitchToShared( sal_Bool bShared, sal_Bool bSave ) 567 { 568 sal_Bool bResult = sal_True; 569 570 if ( bShared != IsDocShared() ) 571 { 572 ::rtl::OUString aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); 573 574 if ( !aOrigURL.getLength() && bSave ) 575 { 576 // this is a new document, let it be stored before switching to the shared mode; 577 // the storing should be done without shared flag, since it is possible that the 578 // target location does not allow to create sharing control file; 579 // the shared flag will be set later after creation of sharing control file 580 SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this ); 581 582 if ( pViewFrame ) 583 { 584 // TODO/LATER: currently the application guards against the reentrance problem 585 const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC ); 586 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem ); 587 bResult = ( pResult && pResult->GetValue() ); 588 if ( bResult ) 589 aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); 590 } 591 } 592 593 sal_Bool bOldValue = HasSharedXMLFlagSet(); 594 SetSharedXMLFlag( bShared ); 595 596 sal_Bool bRemoveEntryOnError = sal_False; 597 if ( bResult && bShared ) 598 { 599 try 600 { 601 ::svt::ShareControlFile aControlFile( aOrigURL ); 602 aControlFile.InsertOwnEntry(); 603 bRemoveEntryOnError = sal_True; 604 } 605 catch( uno::Exception& ) 606 { 607 bResult = sal_False; 608 } 609 } 610 611 if ( bResult && bSave ) 612 { 613 SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this ); 614 615 if ( pViewFrame ) 616 { 617 // TODO/LATER: currently the application guards against the reentrance problem 618 SetModified( sal_True ); // the modified flag has to be set to let the document be stored with the shared flag 619 const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC ); 620 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem ); 621 bResult = ( pResult && pResult->GetValue() ); 622 } 623 } 624 625 if ( bResult ) 626 { 627 // TODO/LATER: Is it possible that the following calls fail? 628 if ( bShared ) 629 { 630 pImp->m_aSharedFileURL = aOrigURL; 631 GetMedium()->SwitchDocumentToTempFile(); 632 } 633 else 634 { 635 ::rtl::OUString aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); 636 GetMedium()->SwitchDocumentToFile( GetSharedFileURL() ); 637 pImp->m_aSharedFileURL = ::rtl::OUString(); 638 639 // now remove the temporary file the document was based on 640 ::utl::UCBContentHelper::Kill( aTempFileURL ); 641 642 try 643 { 644 // aOrigURL can not be used since it contains an old value 645 ::svt::ShareControlFile aControlFile( GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ); 646 aControlFile.RemoveFile(); 647 } 648 catch( uno::Exception& ) 649 { 650 } 651 } 652 } 653 else 654 { 655 // the saving has failed! 656 if ( bRemoveEntryOnError ) 657 { 658 try 659 { 660 ::svt::ShareControlFile aControlFile( aOrigURL ); 661 aControlFile.RemoveEntry(); 662 } 663 catch( uno::Exception& ) 664 {} 665 } 666 667 SetSharedXMLFlag( bOldValue ); 668 } 669 } 670 else 671 bResult = sal_False; // the second switch to the same mode 672 673 if ( bResult ) 674 SetTitle( String() ); 675 676 return bResult; 677 } 678 679 //-------------------------------------------------------------------- 680 681 void SfxObjectShell::DisconnectFromShared() 682 { 683 if ( IsDocShared() ) 684 { 685 if ( pMedium && pMedium->GetStorage().is() ) 686 { 687 // set medium to noname 688 pMedium->SetName( String(), sal_True ); 689 pMedium->Init_Impl(); 690 691 // drop resource 692 SetNoName(); 693 InvalidateName(); 694 695 // untitled document must be based on temporary storage 696 // the medium should not dispose the storage in this case 697 if ( pMedium->GetStorage() == GetStorage() ) 698 ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ); 699 700 pMedium->Close(); 701 FreeSharedFile(); 702 703 SfxMedium* pTmpMedium = pMedium; 704 ForgetMedium(); 705 if( !DoSaveCompleted( pTmpMedium ) ) 706 SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 707 else 708 { 709 // the medium should not dispose the storage, DoSaveCompleted() has let it to do so 710 pMedium->CanDisposeStorage_Impl( sal_False ); 711 } 712 713 pMedium->GetItemSet()->ClearItem( SID_DOC_READONLY ); 714 pMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True, sal_True ); 715 716 SetTitle( String() ); 717 } 718 } 719 } 720 721 //-------------------------------------------------------------------- 722 723 void SfxObjectShell::FreeSharedFile() 724 { 725 if ( pMedium ) 726 FreeSharedFile( pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ); 727 } 728 729 //-------------------------------------------------------------------- 730 void SfxObjectShell::FreeSharedFile( const ::rtl::OUString& aTempFileURL ) 731 { 732 SetSharedXMLFlag( sal_False ); 733 734 if ( IsDocShared() && aTempFileURL.getLength() 735 && !::utl::UCBContentHelper::EqualURLs( aTempFileURL, GetSharedFileURL() ) ) 736 { 737 if ( pImp->m_bAllowShareControlFileClean ) 738 { 739 try 740 { 741 ::svt::ShareControlFile aControlFile( GetSharedFileURL() ); 742 aControlFile.RemoveEntry(); 743 } 744 catch( uno::Exception& ) 745 { 746 } 747 } 748 749 // the cleaning is forbidden only once 750 pImp->m_bAllowShareControlFileClean = sal_True; 751 752 // now remove the temporary file the document is based currently on 753 ::utl::UCBContentHelper::Kill( aTempFileURL ); 754 755 pImp->m_aSharedFileURL = ::rtl::OUString(); 756 } 757 } 758 759 //-------------------------------------------------------------------- 760 void SfxObjectShell::DoNotCleanShareControlFile() 761 { 762 pImp->m_bAllowShareControlFileClean = sal_False; 763 } 764 765 //-------------------------------------------------------------------- 766 void SfxObjectShell::SetSharedXMLFlag( sal_Bool bFlag ) const 767 { 768 pImp->m_bSharedXMLFlag = bFlag; 769 } 770 771 //-------------------------------------------------------------------- 772 sal_Bool SfxObjectShell::HasSharedXMLFlagSet() const 773 { 774 return pImp->m_bSharedXMLFlag; 775 } 776 777 //-------------------------------------------------------------------- 778 779 sal_Bool SfxObjectShell::IsDocShared() const 780 { 781 return ( pImp->m_aSharedFileURL.getLength() > 0 ); 782 } 783 784 //-------------------------------------------------------------------- 785 786 ::rtl::OUString SfxObjectShell::GetSharedFileURL() const 787 { 788 return pImp->m_aSharedFileURL; 789 } 790 791 //-------------------------------------------------------------------- 792 793 Size SfxObjectShell::GetFirstPageSize() 794 { 795 return GetVisArea(ASPECT_THUMBNAIL).GetSize(); 796 } 797 798 799 //-------------------------------------------------------------------- 800 801 IndexBitSet& SfxObjectShell::GetNoSet_Impl() 802 { 803 return pImp->aBitSet; 804 } 805 806 //-------------------------------------------------------------------- 807 // changes the title of the document 808 809 void SfxObjectShell::SetTitle 810 ( 811 const String& rTitle // der neue Titel des Dokuments 812 ) 813 814 /* [Beschreibung] 815 816 Mit dieser Methode kann der Titel des Dokuments gesetzt werden. 817 Dieser entspricht initial dem kompletten Dateinamen. Ein Setzen 818 des Titels wirkt jedoch nicht zu"uck auf den Dateinamen; er wird 819 jedoch in den Caption-Bars der MDI-Fenster angezeigt. 820 */ 821 822 { 823 DBG_CHKTHIS(SfxObjectShell, 0); 824 825 // nix zu tun? 826 if ( ( ( HasName() && pImp->aTitle == rTitle ) 827 || ( !HasName() && GetTitle() == rTitle ) ) 828 && !IsDocShared() ) 829 return; 830 831 SfxApplication *pSfxApp = SFX_APP(); 832 #if 0 833 // wird 'unbenannt#' als Titel gesetzt 834 String aNoName(SfxResId(STR_NONAME)); 835 if ( rTitle.Match(aNoName) <= aNoName.Len() ) 836 { 837 // er ist es selbst => ignorieren 838 pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber); 839 pImp->bIsNamedVisible=0; 840 } 841 #endif 842 843 // ggf. die unbenannt-Nummer freigeben 844 if ( pImp->bIsNamedVisible && USHRT_MAX != pImp->nVisualDocumentNumber ) 845 { 846 pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber); 847 pImp->bIsNamedVisible = 0; 848 } 849 850 // Title setzen 851 pImp->aTitle = rTitle; 852 // Wieso denn in der DocInfo? 853 // GetDocInfo().SetTitle( rTitle ); 854 // FlushDocInfo(); 855 856 // Benachrichtigungen 857 if ( GetMedium() ) 858 { 859 SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) ); 860 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) ); 861 } 862 } 863 864 //-------------------------------------------------------------------- 865 866 #if OSL_DEBUG_LEVEL > 1 867 String X(const String &rRet) 868 { 869 if ( !rRet.Len() ) 870 return DEFINE_CONST_UNICODE( "-empty-" ); 871 return rRet; 872 } 873 #else 874 #define X(ret) ret 875 #endif 876 877 //-------------------------------------------------------------------- 878 //-------------------------------------------------------------------- 879 String SfxObjectShell::GetTitle 880 ( 881 sal_uInt16 nMaxLength /* 0 (default) 882 der Titel selbst, so wie er ist 883 884 1 (==SFX_TITLE_FILENAME) 885 liefert den logischen Dateinamen ohne Pfad 886 (unter WNT je nach Systemeinstellung ohne 887 Extension) 888 889 2 (==SFX_TITLE_FULLNAME) 890 liefert den mit komplettem logischen Dateinamen 891 mit Pfad (remote => ::com::sun::star::util::URL) 892 893 3 (==SFX_TITLE_APINAME) 894 liefert den logischen Dateinamen ohne Pfad 895 und Extension 896 897 4 (==SFX_TITLE_DETECT) 898 liefert den kompletten Titel, falls noch 899 nicht gesetzt wird aber aus DocInfo oder 900 dem Namen des Medium erzeugt 901 902 5 (==SFX_TITLE_CAPTION) 903 liefert den Titel so, wie MB ihn heute in 904 der CaptionBar anzeigen m"ochte 905 906 6 (==SFX_TITLE_PICKLIST) 907 liefert den Titel so, wie MB ihn heute in 908 der PickList anzeigen m"ochte 909 910 7 (==SFX_TITLE_HISTORY) 911 liefert den Titel so, wie MB ihn heute in 912 der History anzeigen m"ochte 913 914 10 bis USHRT_MAX 915 liefert maximal 'nMaxLength' Zeichen vom logischen 916 Dateinamen inkl. Pfad (remote => ::com::sun::star::util::URL) 917 */ 918 ) const 919 920 /* [Beschreibung] 921 922 Liefert den Titel bzw. logischen Dateinamen des Dokuments, je nach 923 'nMaxLength'. 924 925 Falls der Dateiname mit Pfad verwendet wird, wird die Namensk"urzung durch 926 Ersetzung eines oder mehrerer Directory-Namen durch "..." durchgef"uhrt, 927 URLs werden z.Zt. immer komplett geliefert. 928 */ 929 930 { 931 // if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) 932 // return String(); 933 SfxMedium *pMed = GetMedium(); 934 if ( IsLoading() ) 935 return String(); 936 937 /* if ( !nMaxLength && pImp->pDocInfo ) 938 { 939 String aTitle = pImp->pDocInfo->GetTitle(); 940 if ( aTitle.Len() ) 941 return aTitle; 942 } */ 943 944 // Titel erzeugen? 945 if ( SFX_TITLE_DETECT == nMaxLength && !pImp->aTitle.Len() ) 946 { 947 static sal_Bool bRecur = sal_False; 948 if ( bRecur ) 949 return DEFINE_CONST_UNICODE( "-not available-" ); 950 bRecur = sal_True; 951 952 String aTitle; 953 SfxObjectShell *pThis = (SfxObjectShell*) this; 954 955 if ( pMed ) 956 { 957 SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False ); 958 if ( pNameItem ) 959 aTitle = pNameItem->GetValue(); 960 } 961 962 if ( !aTitle.Len() ) 963 aTitle = GetTitle( SFX_TITLE_FILENAME ); 964 965 if ( IsTemplate() ) 966 pThis->SetTitle( aTitle ); 967 bRecur = sal_False; 968 return X(aTitle); 969 } 970 else if (SFX_TITLE_APINAME == nMaxLength ) 971 return X(GetAPIName()); 972 973 // Sonderfall Vorlagen: 974 if( IsTemplate() && pImp->aTitle.Len() && 975 ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) ) 976 return X(pImp->aTitle); 977 978 // Picklist/Caption wird gemappt 979 if ( pMed && ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) ) 980 { 981 // Wenn ein spezieller Titel beim "Offnen mitgegeben wurde; 982 // wichtig bei URLs, die INET_PROT_FILE verwenden, denn bei denen 983 // wird der gesetzte Titel nicht beachtet. 984 // (s.u., Auswertung von aTitleMap_Impl) 985 SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False ); 986 if ( pNameItem ) 987 return X( pNameItem->GetValue() ); 988 } 989 990 // noch unbenannt? 991 DBG_ASSERT( !HasName() || pMed, "HasName() aber kein Medium?!?" ); 992 if ( !HasName() || !pMed ) 993 { 994 // schon Titel gesezt? 995 if ( pImp->aTitle.Len() ) 996 return X(pImp->aTitle); 997 998 // mu\s es durchnumeriert werden? 999 String aNoName( SfxResId( STR_NONAME ) ); 1000 if ( pImp->bIsNamedVisible ) 1001 // Nummer hintenanh"angen 1002 aNoName += String::CreateFromInt32( pImp->nVisualDocumentNumber ); 1003 1004 // Dokument hei\st 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 // lokale Datei? 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"otigt. 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 uno::Reference< lang::XMultiServiceFactory > xServiceManager( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); 1706 Reference< uri::XUriReferenceFactory > xFac ( 1707 xServiceManager->createInstance( rtl::OUString::createFromAscii( 1708 "com.sun.star.uri.UriReferenceFactory") ) , UNO_QUERY_THROW ); 1709 Reference< uri::XVndSunStarScriptUrlReference > xScriptUri( xFac->parse( _rScriptURL ), UNO_QUERY_THROW ); 1710 ::rtl::OUString sLocation = xScriptUri->getParameter( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "location" ) ) ); 1711 bool bIsDocumentScript = ( sLocation == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "document" ) ) ); 1712 if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) ) 1713 return ERRCODE_IO_ACCESSDENIED; 1714 1715 // obtain/create a script provider 1716 Reference< provider::XScriptProvider > xScriptProvider; 1717 Reference< provider::XScriptProviderSupplier > xSPS( _rxScriptContext, UNO_QUERY ); 1718 if ( xSPS.is() ) 1719 xScriptProvider.set( xSPS->getScriptProvider() ); 1720 1721 if ( !xScriptProvider.is() ) 1722 { 1723 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 1724 Reference< provider::XScriptProviderFactory > xScriptProviderFactory( 1725 aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW ); 1726 xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( _rxScriptContext ) ), UNO_SET_THROW ); 1727 } 1728 1729 // ry to protect the invocation context's undo manager (if present), just in case the script tampers with it 1730 ::framework::DocumentUndoGuard aUndoGuard( _rxScriptContext.get() ); 1731 1732 // obtain the script, and execute it 1733 Reference< provider::XScript > xScript( xScriptProvider->getScript( _rScriptURL ), UNO_QUERY_THROW ); 1734 aRet = xScript->invoke( aParams, aOutParamIndex, aOutParam ); 1735 } 1736 catch ( const uno::Exception& ) 1737 { 1738 aException = ::cppu::getCaughtException(); 1739 bCaughtException = sal_True; 1740 nErr = ERRCODE_BASIC_INTERNAL_ERROR; 1741 } 1742 1743 if ( bCaughtException && bRaiseError ) 1744 { 1745 ::std::auto_ptr< VclAbstractDialog > pScriptErrDlg; 1746 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); 1747 if ( pFact ) 1748 pScriptErrDlg.reset( pFact->CreateScriptErrorDialog( NULL, aException ) ); 1749 OSL_ENSURE( pScriptErrDlg.get(), "SfxObjectShell::CallXScript: no script error dialog!" ); 1750 1751 if ( pScriptErrDlg.get() ) 1752 pScriptErrDlg->Execute(); 1753 } 1754 1755 OSL_TRACE( "leaving CallXScript" ); 1756 return nErr; 1757 } 1758 1759 // perhaps rename to CallScript once we get rid of the existing CallScript 1760 // and Call, CallBasic, CallStarBasic methods 1761 ErrCode SfxObjectShell::CallXScript( const String& rScriptURL, 1762 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& 1763 aParams, 1764 ::com::sun::star::uno::Any& aRet, 1765 ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex, 1766 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam 1767 , bool bRaiseError ) 1768 { 1769 return CallXScript( GetModel(), rScriptURL, aParams, aRet, aOutParamIndex, aOutParam, bRaiseError ); 1770 } 1771 1772 //------------------------------------------------------------------------- 1773 SfxFrame* SfxObjectShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ ) 1774 { 1775 return pSelf; 1776 } 1777 1778 SfxObjectShellFlags SfxObjectShell::GetFlags() const 1779 { 1780 if( pImp->eFlags == SFXOBJECTSHELL_UNDEFINED ) 1781 pImp->eFlags = GetFactory().GetFlags(); 1782 return pImp->eFlags; 1783 } 1784 1785 void SfxObjectShell::SetFlags( SfxObjectShellFlags eFlags ) 1786 { 1787 pImp->eFlags = eFlags; 1788 } 1789 1790 void SfxHeaderAttributes_Impl::SetAttributes() 1791 { 1792 bAlert = sal_True; 1793 SvKeyValue aPair; 1794 for( sal_Bool bCont = xIter->GetFirst( aPair ); bCont; 1795 bCont = xIter->GetNext( aPair ) ) 1796 SetAttribute( aPair ); 1797 } 1798 1799 void SfxHeaderAttributes_Impl::SetAttribute( const SvKeyValue& rKV ) 1800 { 1801 String aValue = rKV.GetValue(); 1802 if( rKV.GetKey().CompareIgnoreCaseToAscii( "refresh" ) == COMPARE_EQUAL && rKV.GetValue().Len() ) 1803 { 1804 sal_uInt32 nTime = aValue.GetToken( 0, ';' ).ToInt32() ; 1805 String aURL = aValue.GetToken( 1, ';' ); 1806 aURL.EraseTrailingChars().EraseLeadingChars(); 1807 uno::Reference<document::XDocumentProperties> xDocProps( 1808 pDoc->getDocProperties()); 1809 if( aURL.Copy(0, 4).CompareIgnoreCaseToAscii( "url=" ) == COMPARE_EQUAL ) 1810 { 1811 INetURLObject aObj; 1812 INetURLObject( pDoc->GetMedium()->GetName() ).GetNewAbsURL( aURL.Copy( 4 ), &aObj ); 1813 xDocProps->setAutoloadURL( 1814 aObj.GetMainURL( INetURLObject::NO_DECODE ) ); 1815 } 1816 try 1817 { 1818 xDocProps->setAutoloadSecs( nTime ); 1819 } 1820 catch (lang::IllegalArgumentException &) 1821 { 1822 // ignore 1823 } 1824 } 1825 else if( rKV.GetKey().CompareIgnoreCaseToAscii( "expires" ) == COMPARE_EQUAL ) 1826 { 1827 DateTime aDateTime; 1828 if( INetRFC822Message::ParseDateField( rKV.GetValue(), aDateTime ) ) 1829 { 1830 aDateTime.ConvertToLocalTime(); 1831 pDoc->GetMedium()->SetExpired_Impl( aDateTime ); 1832 } 1833 else 1834 { 1835 // DBG_ERROR( "Schlechtes ::com::sun::star::util::DateTime fuer Expired" ); 1836 pDoc->GetMedium()->SetExpired_Impl( Date( 1, 1, 1970 ) ); 1837 } 1838 } 1839 else if( rKV.GetKey().CompareIgnoreCaseToAscii( "content-type" ) == COMPARE_EQUAL ) 1840 { 1841 ::rtl::OString sContent = ::rtl::OUStringToOString( aValue, RTL_TEXTENCODING_ASCII_US ); 1842 ByteString sType, sSubType; 1843 INetContentTypeParameterList aParameters; 1844 1845 if( INetContentTypes::parse( sContent, sType, sSubType, &aParameters ) ) 1846 { 1847 const INetContentTypeParameter * pCharset = aParameters.find("charset"); 1848 if (pCharset != 0) 1849 pDoc->GetMedium()->SetCharset( pCharset->m_sValue ); 1850 } 1851 } 1852 } 1853 1854 void SfxHeaderAttributes_Impl::Append( const SvKeyValue& rKV ) 1855 { 1856 xIter->Append( rKV ); 1857 if( bAlert ) SetAttribute( rKV ); 1858 } 1859 1860 SvKeyValueIterator* SfxObjectShell::GetHeaderAttributes() 1861 { 1862 if( !pImp->xHeaderAttributes.Is() ) 1863 { 1864 DBG_ASSERT( pMedium, "Kein Medium" ); 1865 pImp->xHeaderAttributes = new SfxHeaderAttributes_Impl( this ); 1866 } 1867 return ( SvKeyValueIterator*) &pImp->xHeaderAttributes; 1868 } 1869 1870 void SfxObjectShell::ClearHeaderAttributesForSourceViewHack() 1871 { 1872 ((SfxHeaderAttributes_Impl*)GetHeaderAttributes()) 1873 ->ClearForSourceView(); 1874 } 1875 1876 1877 void SfxObjectShell::SetHeaderAttributesForSourceViewHack() 1878 { 1879 ((SfxHeaderAttributes_Impl*)GetHeaderAttributes()) 1880 ->SetAttributes(); 1881 } 1882 1883 sal_Bool SfxObjectShell::IsPreview() const 1884 { 1885 if ( !pMedium ) 1886 return sal_False; 1887 1888 sal_Bool bPreview = sal_False; 1889 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False); 1890 if ( pFlags ) 1891 { 1892 // Werte auf einzelne Items verteilen 1893 String aFileFlags = pFlags->GetValue(); 1894 aFileFlags.ToUpperAscii(); 1895 if ( STRING_NOTFOUND != aFileFlags.Search( 'B' ) ) 1896 bPreview = sal_True; 1897 } 1898 1899 if ( !bPreview ) 1900 { 1901 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pItem, SfxBoolItem, SID_PREVIEW, sal_False); 1902 if ( pItem ) 1903 bPreview = pItem->GetValue(); 1904 } 1905 1906 return bPreview; 1907 } 1908 1909 sal_Bool SfxObjectShell::IsSecure() 1910 { 1911 // Wenn globale Warnung an ist, nach Secure-Referer-Liste gehen 1912 String aReferer = GetMedium()->GetName(); 1913 if ( !aReferer.Len() ) 1914 { 1915 // bei neuen Dokumenten das Template als Referer nehmen 1916 ::rtl::OUString aTempl( getDocProperties()->getTemplateURL() ); 1917 if ( aTempl.getLength() ) 1918 aReferer = INetURLObject( aTempl ).GetMainURL( INetURLObject::NO_DECODE ); 1919 } 1920 1921 INetURLObject aURL( "macro:" ); 1922 if ( !aReferer.Len() ) 1923 // empty new or embedded document 1924 return sal_True; 1925 1926 SvtSecurityOptions aOpt; 1927 1928 if( aOpt.GetBasicMode() == eALWAYS_EXECUTE ) 1929 return sal_True; 1930 1931 if( aOpt.GetBasicMode() == eNEVER_EXECUTE ) 1932 return sal_False; 1933 1934 if ( aOpt.IsSecureURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aReferer ) ) 1935 //if ( SvtSecurityOptions().IsSecureURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aReferer ) ) 1936 { 1937 if ( GetMedium()->GetContent().is() ) 1938 { 1939 Any aAny( ::utl::UCBContentHelper::GetProperty( aURL.GetMainURL( INetURLObject::NO_DECODE ), String( RTL_CONSTASCII_USTRINGPARAM("IsProtected")) ) ); 1940 sal_Bool bIsProtected = sal_False; 1941 if ( ( aAny >>= bIsProtected ) && bIsProtected ) 1942 return sal_False; 1943 else 1944 return sal_True; 1945 } 1946 else 1947 return sal_True; 1948 } 1949 else 1950 return sal_False; 1951 } 1952 1953 void SfxObjectShell::SetWaitCursor( sal_Bool bSet ) const 1954 { 1955 for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) ) 1956 { 1957 if ( bSet ) 1958 pFrame->GetFrame().GetWindow().EnterWait(); 1959 else 1960 pFrame->GetFrame().GetWindow().LeaveWait(); 1961 } 1962 } 1963 1964 String SfxObjectShell::GetAPIName() const 1965 { 1966 INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) ); 1967 String aName( aURL.GetBase() ); 1968 if( !aName.Len() ) 1969 aName = aURL.GetURLNoPass(); 1970 if ( !aName.Len() ) 1971 aName = GetTitle( SFX_TITLE_DETECT ); 1972 return aName; 1973 } 1974 1975 void SfxObjectShell::Invalidate( sal_uInt16 nId ) 1976 { 1977 for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) ) 1978 Invalidate_Impl( pFrame->GetBindings(), nId ); 1979 } 1980 1981 bool SfxObjectShell::AdjustMacroMode( const String& /*rScriptType*/, bool bSuppressUI ) 1982 { 1983 uno::Reference< task::XInteractionHandler > xInteraction; 1984 if ( pMedium && !bSuppressUI ) 1985 xInteraction = pMedium->GetInteractionHandler(); 1986 1987 CheckForBrokenDocSignatures_Impl( xInteraction ); 1988 1989 CheckEncryption_Impl( xInteraction ); 1990 1991 return pImp->aMacroMode.adjustMacroMode( xInteraction ); 1992 } 1993 1994 Window* SfxObjectShell::GetDialogParent( SfxMedium* pLoadingMedium ) 1995 { 1996 Window* pWindow = 0; 1997 SfxItemSet* pSet = pLoadingMedium ? pLoadingMedium->GetItemSet() : GetMedium()->GetItemSet(); 1998 SFX_ITEMSET_ARG( pSet, pUnoItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False ); 1999 if ( pUnoItem ) 2000 { 2001 uno::Reference < frame::XFrame > xFrame( pUnoItem->GetFrame() ); 2002 pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); 2003 } 2004 2005 if ( !pWindow ) 2006 { 2007 SfxFrame* pFrame = 0; 2008 SFX_ITEMSET_ARG( pSet, pFrameItem, SfxFrameItem, SID_DOCFRAME, sal_False ); 2009 if( pFrameItem && pFrameItem->GetFrame() ) 2010 // get target frame from ItemSet 2011 pFrame = pFrameItem->GetFrame(); 2012 else 2013 { 2014 // try the current frame 2015 SfxViewFrame* pView = SfxViewFrame::Current(); 2016 if ( !pView || pView->GetObjectShell() != this ) 2017 // get any visible frame 2018 pView = SfxViewFrame::GetFirst(this); 2019 if ( pView ) 2020 pFrame = &pView->GetFrame(); 2021 } 2022 2023 if ( pFrame ) 2024 // get topmost window 2025 pWindow = VCLUnoHelper::GetWindow( pFrame->GetFrameInterface()->getContainerWindow() ); 2026 } 2027 2028 if ( pWindow ) 2029 { 2030 // this frame may be invisible, show it if it is allowed 2031 SFX_ITEMSET_ARG( pSet, pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False ); 2032 if ( !pHiddenItem || !pHiddenItem->GetValue() ) 2033 { 2034 pWindow->Show(); 2035 pWindow->ToTop(); 2036 } 2037 } 2038 2039 return pWindow; 2040 } 2041 2042 String SfxObjectShell::UpdateTitle( SfxMedium* pMed, sal_uInt16 nDocViewNumber ) 2043 { 2044 // Titel des Fensters 2045 String aTitle; 2046 if ( pMed ) 2047 { 2048 INetURLObject aTmp( pMed->GetName() ); 2049 aTitle = aTmp.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 2050 } 2051 else 2052 { 2053 pMed = GetMedium(); 2054 aTitle = GetTitle(SFX_TITLE_CAPTION); 2055 String aName(aTitle); 2056 if ( nDocViewNumber ) 2057 { 2058 aName += ':'; 2059 aName += String::CreateFromInt32( nDocViewNumber ); 2060 } 2061 } 2062 2063 if ( pMed ) 2064 { 2065 SFX_ITEMSET_ARG( pMed->GetItemSet(), pRepairedDocItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False ); 2066 if ( pRepairedDocItem && pRepairedDocItem->GetValue() ) 2067 aTitle += String( SfxResId(STR_REPAIREDDOCUMENT) ); 2068 } 2069 2070 if ( IsReadOnlyUI() || (pMed && pMed->IsReadOnly()) ) 2071 aTitle += String( SfxResId(STR_READONLY) ); 2072 else if ( IsDocShared() ) 2073 aTitle += String( SfxResId(STR_SHARED) ); 2074 2075 return aTitle; 2076 } 2077 2078 void SfxObjectShell::SetCreateMode_Impl( SfxObjectCreateMode nMode ) 2079 { 2080 eCreateMode = nMode; 2081 } 2082 2083 sal_Bool SfxObjectShell::IsInPlaceActive() 2084 { 2085 if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED ) 2086 return sal_False; 2087 2088 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); 2089 return pFrame && pFrame->GetFrame().IsInPlace(); 2090 } 2091 2092 sal_Bool SfxObjectShell::IsUIActive() 2093 { 2094 if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED ) 2095 return sal_False; 2096 2097 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); 2098 return pFrame && pFrame->GetFrame().IsInPlace() && pFrame->GetFrame().GetWorkWindow_Impl()->IsVisible_Impl(); 2099 } 2100 2101 void SfxObjectShell::UIActivate( sal_Bool ) 2102 { 2103 } 2104 2105 void SfxObjectShell::InPlaceActivate( sal_Bool ) 2106 { 2107 } 2108 2109 sal_Bool SfxObjectShell::UseInteractionToHandleError( 2110 const uno::Reference< task::XInteractionHandler >& xHandler, 2111 sal_uInt32 nError ) 2112 { 2113 sal_Bool bResult = sal_False; 2114 2115 if ( xHandler.is() ) 2116 { 2117 try 2118 { 2119 uno::Any aInteraction; 2120 uno::Sequence< uno::Reference< task::XInteractionContinuation > > lContinuations(2); 2121 ::comphelper::OInteractionAbort* pAbort = new ::comphelper::OInteractionAbort(); 2122 ::comphelper::OInteractionApprove* pApprove = new ::comphelper::OInteractionApprove(); 2123 lContinuations[0] = uno::Reference< task::XInteractionContinuation >( 2124 static_cast< task::XInteractionContinuation* >( pAbort ), uno::UNO_QUERY ); 2125 lContinuations[1] = uno::Reference< task::XInteractionContinuation >( 2126 static_cast< task::XInteractionContinuation* >( pApprove ), uno::UNO_QUERY ); 2127 2128 task::ErrorCodeRequest aErrorCode; 2129 aErrorCode.ErrCode = nError; 2130 aInteraction <<= aErrorCode; 2131 xHandler->handle(::framework::InteractionRequest::CreateRequest (aInteraction,lContinuations)); 2132 bResult = pAbort->wasSelected(); 2133 } 2134 catch( uno::Exception& ) 2135 {} 2136 } 2137 2138 return bResult; 2139 } 2140 2141 sal_Bool SfxObjectShell_Impl::NeedsOfficeUpdateDialog() 2142 { 2143 // if the configuration is not available for any reason, the default behavior is to show the message 2144 sal_Bool bResult = sal_True; 2145 2146 try 2147 { 2148 uno::Reference< lang::XMultiServiceFactory > xServiceManager( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); 2149 uno::Reference< uno::XInterface > xCommonConfig( 2150 ::comphelper::ConfigurationHelper::openConfig( 2151 xServiceManager, 2152 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ), 2153 ::comphelper::ConfigurationHelper::E_STANDARD ), 2154 uno::UNO_SET_THROW ); 2155 2156 ::comphelper::ConfigurationHelper::readRelativeKey( 2157 xCommonConfig, 2158 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Load/" ) ), 2159 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ShowOfficeUpdateDialog" ) ) ) >>= bResult; 2160 } 2161 catch( uno::Exception& ) 2162 { 2163 } 2164 2165 return bResult; 2166 } 2167 2168 sal_Int16 SfxObjectShell_Impl::getCurrentMacroExecMode() const 2169 { 2170 sal_Int16 nImposedExecMode( MacroExecMode::NEVER_EXECUTE ); 2171 2172 const SfxMedium* pMedium( rDocShell.GetMedium() ); 2173 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" ); 2174 if ( pMedium ) 2175 { 2176 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pMacroModeItem, SfxUInt16Item, SID_MACROEXECMODE, sal_False); 2177 if ( pMacroModeItem ) 2178 nImposedExecMode = pMacroModeItem->GetValue(); 2179 } 2180 return nImposedExecMode; 2181 } 2182 2183 sal_Bool SfxObjectShell_Impl::setCurrentMacroExecMode( sal_uInt16 nMacroMode ) 2184 { 2185 const SfxMedium* pMedium( rDocShell.GetMedium() ); 2186 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" ); 2187 if ( pMedium ) 2188 { 2189 pMedium->GetItemSet()->Put( SfxUInt16Item( SID_MACROEXECMODE, nMacroMode ) ); 2190 return sal_True; 2191 } 2192 2193 return sal_False; 2194 } 2195 2196 ::rtl::OUString SfxObjectShell_Impl::getDocumentLocation() const 2197 { 2198 ::rtl::OUString sLocation; 2199 2200 const SfxMedium* pMedium( rDocShell.GetMedium() ); 2201 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getDocumentLocation: no medium!" ); 2202 if ( pMedium ) 2203 { 2204 sLocation = pMedium->GetName(); 2205 if ( !sLocation.getLength() ) 2206 { 2207 // for documents made from a template: get the name of the template 2208 sLocation = rDocShell.getDocProperties()->getTemplateURL(); 2209 } 2210 } 2211 return sLocation; 2212 } 2213 2214 uno::Reference< embed::XStorage > SfxObjectShell_Impl::getZipStorageToSign() 2215 { 2216 Reference < embed::XStorage > xStore; 2217 2218 SfxMedium* pMedium( rDocShell.GetMedium() ); 2219 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getLastCommitDocumentStorage: no medium!" ); 2220 if ( pMedium ) 2221 xStore = pMedium->GetZipStorageToSign_Impl(); 2222 2223 return xStore; 2224 } 2225 2226 sal_Bool SfxObjectShell_Impl::documentStorageHasMacros() const 2227 { 2228 return ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocStorage ); 2229 } 2230 2231 Reference< XEmbeddedScripts > SfxObjectShell_Impl::getEmbeddedDocumentScripts() const 2232 { 2233 return Reference< XEmbeddedScripts >( rDocShell.GetModel(), UNO_QUERY ); 2234 } 2235 2236 sal_Int16 SfxObjectShell_Impl::getScriptingSignatureState() 2237 { 2238 sal_Int16 nSignatureState( rDocShell.GetScriptingSignatureState() ); 2239 2240 if ( nSignatureState != SIGNATURESTATE_NOSIGNATURES && m_bMacroSignBroken ) 2241 { 2242 // if there is a macro signature it must be handled as broken 2243 nSignatureState = SIGNATURESTATE_SIGNATURES_BROKEN; 2244 } 2245 2246 return nSignatureState; 2247 } 2248 2249 sal_Bool SfxObjectShell_Impl::hasTrustedScriptingSignature( sal_Bool bAllowUIToAddAuthor ) 2250 { 2251 sal_Bool bResult = sal_False; 2252 2253 try 2254 { 2255 ::rtl::OUString aVersion; 2256 try 2257 { 2258 uno::Reference < beans::XPropertySet > xPropSet( rDocShell.GetStorage(), uno::UNO_QUERY_THROW ); 2259 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aVersion; 2260 } 2261 catch( uno::Exception& ) 2262 { 2263 } 2264 uno::Sequence< uno::Any > aArgs( 1 ); 2265 aArgs[0] <<= aVersion; 2266 2267 uno::Reference< security::XDocumentDigitalSignatures > xSigner( comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ), aArgs ), uno::UNO_QUERY_THROW ); 2268 2269 if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN 2270 || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK 2271 || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED ) 2272 { 2273 uno::Sequence< security::DocumentSignatureInformation > aInfo = rDocShell.ImplAnalyzeSignature( sal_True, xSigner ); 2274 2275 if ( aInfo.getLength() ) 2276 { 2277 if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN ) 2278 nScriptingSignatureState = rDocShell.ImplCheckSignaturesInformation( aInfo ); 2279 2280 if ( nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK 2281 || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED ) 2282 { 2283 for ( sal_Int32 nInd = 0; !bResult && nInd < aInfo.getLength(); nInd++ ) 2284 { 2285 bResult = xSigner->isAuthorTrusted( aInfo[nInd].Signer ); 2286 } 2287 2288 if ( !bResult && bAllowUIToAddAuthor ) 2289 { 2290 uno::Reference< task::XInteractionHandler > xInteraction; 2291 if ( rDocShell.GetMedium() ) 2292 xInteraction = rDocShell.GetMedium()->GetInteractionHandler(); 2293 2294 if ( xInteraction.is() ) 2295 { 2296 task::DocumentMacroConfirmationRequest aRequest; 2297 aRequest.DocumentURL = getDocumentLocation(); 2298 aRequest.DocumentStorage = rDocShell.GetMedium()->GetZipStorageToSign_Impl(); 2299 aRequest.DocumentSignatureInformation = aInfo; 2300 aRequest.DocumentVersion = aVersion; 2301 aRequest.Classification = task::InteractionClassification_QUERY; 2302 bResult = SfxMedium::CallApproveHandler( xInteraction, uno::makeAny( aRequest ), sal_True ); 2303 } 2304 } 2305 } 2306 } 2307 } 2308 } 2309 catch( uno::Exception& ) 2310 {} 2311 2312 return bResult; 2313 } 2314 2315 void SfxObjectShell_Impl::showBrokenSignatureWarning( const uno::Reference< task::XInteractionHandler >& _rxInteraction ) const 2316 { 2317 if ( !bSignatureErrorIsShown ) 2318 { 2319 SfxObjectShell::UseInteractionToHandleError( _rxInteraction, ERRCODE_SFX_BROKENSIGNATURE ); 2320 const_cast< SfxObjectShell_Impl* >( this )->bSignatureErrorIsShown = sal_True; 2321 } 2322 } 2323 2324 void SfxObjectShell::AddLog( const ::rtl::OUString& aMessage ) 2325 { 2326 if ( !pImp->m_xLogRing.is() ) 2327 { 2328 try 2329 { 2330 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 2331 if ( aContext.is() ) 2332 pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW ); 2333 } 2334 catch( uno::Exception& ) 2335 {} 2336 } 2337 2338 if ( pImp->m_xLogRing.is() ) 2339 pImp->m_xLogRing->logString( aMessage ); 2340 } 2341 2342 namespace { 2343 2344 void WriteStringInStream( const uno::Reference< io::XOutputStream >& xOutStream, const ::rtl::OUString& aString ) 2345 { 2346 if ( xOutStream.is() ) 2347 { 2348 ::rtl::OString aStrLog = ::rtl::OUStringToOString( aString, RTL_TEXTENCODING_UTF8 ); 2349 uno::Sequence< sal_Int8 > aLogData( (const sal_Int8*)aStrLog.getStr(), aStrLog.getLength() ); 2350 xOutStream->writeBytes( aLogData ); 2351 2352 aLogData.realloc( 1 ); 2353 aLogData[0] = '\n'; 2354 xOutStream->writeBytes( aLogData ); 2355 } 2356 } 2357 2358 } 2359 2360 void SfxObjectShell::StoreLog() 2361 { 2362 if ( !pImp->m_xLogRing.is() ) 2363 { 2364 try 2365 { 2366 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 2367 if ( aContext.is() ) 2368 pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW ); 2369 } 2370 catch( uno::Exception& ) 2371 {} 2372 } 2373 2374 if ( pImp->m_xLogRing.is() ) 2375 { 2376 ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}" ) ); 2377 //#ifdef WNT 2378 // ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}" ) ); 2379 //#else 2380 // ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/bootstraprc:UserInstallation}" ) ); 2381 //#endif 2382 ::rtl::Bootstrap::expandMacros( aFileURL ); 2383 2384 //#ifdef WNT 2385 // ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/setup.ini:buildid}" ) ); 2386 //#else 2387 // ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/setuprc:buildid}" ) ); 2388 //#endif 2389 ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("setup") ":buildid}" ) ); 2390 ::rtl::Bootstrap::expandMacros( aBuildID ); 2391 2392 if ( aFileURL.getLength() ) 2393 { 2394 aFileURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/temp/document_io_logring.txt" ) ); 2395 try 2396 { 2397 uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); 2398 uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess( xFactory->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.ucb.SimpleFileAccess" ) ), uno::UNO_QUERY_THROW ); 2399 uno::Reference< io::XStream > xStream( xSimpleFileAccess->openFileReadWrite( aFileURL ), uno::UNO_SET_THROW ); 2400 uno::Reference< io::XOutputStream > xOutStream( xStream->getOutputStream(), uno::UNO_SET_THROW ); 2401 uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY_THROW ); 2402 xTruncate->truncate(); 2403 2404 if ( aBuildID.getLength() ) 2405 WriteStringInStream( xOutStream, aBuildID ); 2406 2407 uno::Sequence< ::rtl::OUString > aLogSeq = pImp->m_xLogRing->getCollectedLog(); 2408 for ( sal_Int32 nInd = 0; nInd < aLogSeq.getLength(); nInd++ ) 2409 WriteStringInStream( xOutStream, aLogSeq[nInd] ); 2410 } 2411 catch( uno::Exception& ) 2412 {} 2413 } 2414 } 2415 } 2416 2417