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 if ( !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) ) 1711 return ERRCODE_IO_ACCESSDENIED; 1712 1713 // obtain/create a script provider 1714 Reference< provider::XScriptProvider > xScriptProvider; 1715 Reference< provider::XScriptProviderSupplier > xSPS( _rxScriptContext, UNO_QUERY ); 1716 if ( xSPS.is() ) 1717 xScriptProvider.set( xSPS->getScriptProvider() ); 1718 1719 if ( !xScriptProvider.is() ) 1720 { 1721 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 1722 Reference< provider::XScriptProviderFactory > xScriptProviderFactory( 1723 aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW ); 1724 xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( _rxScriptContext ) ), UNO_SET_THROW ); 1725 } 1726 1727 // ry to protect the invocation context's undo manager (if present), just in case the script tampers with it 1728 ::framework::DocumentUndoGuard aUndoGuard( _rxScriptContext.get() ); 1729 1730 // obtain the script, and execute it 1731 Reference< provider::XScript > xScript( xScriptProvider->getScript( _rScriptURL ), UNO_QUERY_THROW ); 1732 aRet = xScript->invoke( aParams, aOutParamIndex, aOutParam ); 1733 } 1734 catch ( const uno::Exception& ) 1735 { 1736 aException = ::cppu::getCaughtException(); 1737 bCaughtException = sal_True; 1738 nErr = ERRCODE_BASIC_INTERNAL_ERROR; 1739 } 1740 1741 if ( bCaughtException && bRaiseError ) 1742 { 1743 ::std::auto_ptr< VclAbstractDialog > pScriptErrDlg; 1744 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); 1745 if ( pFact ) 1746 pScriptErrDlg.reset( pFact->CreateScriptErrorDialog( NULL, aException ) ); 1747 OSL_ENSURE( pScriptErrDlg.get(), "SfxObjectShell::CallXScript: no script error dialog!" ); 1748 1749 if ( pScriptErrDlg.get() ) 1750 pScriptErrDlg->Execute(); 1751 } 1752 1753 OSL_TRACE( "leaving CallXScript" ); 1754 return nErr; 1755 } 1756 1757 // perhaps rename to CallScript once we get rid of the existing CallScript 1758 // and Call, CallBasic, CallStarBasic methods 1759 ErrCode SfxObjectShell::CallXScript( const String& rScriptURL, 1760 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& 1761 aParams, 1762 ::com::sun::star::uno::Any& aRet, 1763 ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex, 1764 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam 1765 , bool bRaiseError ) 1766 { 1767 return CallXScript( GetModel(), rScriptURL, aParams, aRet, aOutParamIndex, aOutParam, bRaiseError ); 1768 } 1769 1770 //------------------------------------------------------------------------- 1771 SfxFrame* SfxObjectShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ ) 1772 { 1773 return pSelf; 1774 } 1775 1776 SfxObjectShellFlags SfxObjectShell::GetFlags() const 1777 { 1778 if( pImp->eFlags == SFXOBJECTSHELL_UNDEFINED ) 1779 pImp->eFlags = GetFactory().GetFlags(); 1780 return pImp->eFlags; 1781 } 1782 1783 void SfxObjectShell::SetFlags( SfxObjectShellFlags eFlags ) 1784 { 1785 pImp->eFlags = eFlags; 1786 } 1787 1788 void SfxHeaderAttributes_Impl::SetAttributes() 1789 { 1790 bAlert = sal_True; 1791 SvKeyValue aPair; 1792 for( sal_Bool bCont = xIter->GetFirst( aPair ); bCont; 1793 bCont = xIter->GetNext( aPair ) ) 1794 SetAttribute( aPair ); 1795 } 1796 1797 void SfxHeaderAttributes_Impl::SetAttribute( const SvKeyValue& rKV ) 1798 { 1799 String aValue = rKV.GetValue(); 1800 if( rKV.GetKey().CompareIgnoreCaseToAscii( "refresh" ) == COMPARE_EQUAL && rKV.GetValue().Len() ) 1801 { 1802 sal_uInt32 nTime = aValue.GetToken( 0, ';' ).ToInt32() ; 1803 String aURL = aValue.GetToken( 1, ';' ); 1804 aURL.EraseTrailingChars().EraseLeadingChars(); 1805 uno::Reference<document::XDocumentProperties> xDocProps( 1806 pDoc->getDocProperties()); 1807 if( aURL.Copy(0, 4).CompareIgnoreCaseToAscii( "url=" ) == COMPARE_EQUAL ) 1808 { 1809 INetURLObject aObj; 1810 INetURLObject( pDoc->GetMedium()->GetName() ).GetNewAbsURL( aURL.Copy( 4 ), &aObj ); 1811 xDocProps->setAutoloadURL( 1812 aObj.GetMainURL( INetURLObject::NO_DECODE ) ); 1813 } 1814 try 1815 { 1816 xDocProps->setAutoloadSecs( nTime ); 1817 } 1818 catch (lang::IllegalArgumentException &) 1819 { 1820 // ignore 1821 } 1822 } 1823 else if( rKV.GetKey().CompareIgnoreCaseToAscii( "expires" ) == COMPARE_EQUAL ) 1824 { 1825 DateTime aDateTime; 1826 if( INetRFC822Message::ParseDateField( rKV.GetValue(), aDateTime ) ) 1827 { 1828 aDateTime.ConvertToLocalTime(); 1829 pDoc->GetMedium()->SetExpired_Impl( aDateTime ); 1830 } 1831 else 1832 { 1833 // DBG_ERROR( "Schlechtes ::com::sun::star::util::DateTime fuer Expired" ); 1834 pDoc->GetMedium()->SetExpired_Impl( Date( 1, 1, 1970 ) ); 1835 } 1836 } 1837 else if( rKV.GetKey().CompareIgnoreCaseToAscii( "content-type" ) == COMPARE_EQUAL ) 1838 { 1839 ::rtl::OString sContent = ::rtl::OUStringToOString( aValue, RTL_TEXTENCODING_ASCII_US ); 1840 ByteString sType, sSubType; 1841 INetContentTypeParameterList aParameters; 1842 1843 if( INetContentTypes::parse( sContent, sType, sSubType, &aParameters ) ) 1844 { 1845 const INetContentTypeParameter * pCharset = aParameters.find("charset"); 1846 if (pCharset != 0) 1847 pDoc->GetMedium()->SetCharset( pCharset->m_sValue ); 1848 } 1849 } 1850 } 1851 1852 void SfxHeaderAttributes_Impl::Append( const SvKeyValue& rKV ) 1853 { 1854 xIter->Append( rKV ); 1855 if( bAlert ) SetAttribute( rKV ); 1856 } 1857 1858 SvKeyValueIterator* SfxObjectShell::GetHeaderAttributes() 1859 { 1860 if( !pImp->xHeaderAttributes.Is() ) 1861 { 1862 DBG_ASSERT( pMedium, "Kein Medium" ); 1863 pImp->xHeaderAttributes = new SfxHeaderAttributes_Impl( this ); 1864 } 1865 return ( SvKeyValueIterator*) &pImp->xHeaderAttributes; 1866 } 1867 1868 void SfxObjectShell::ClearHeaderAttributesForSourceViewHack() 1869 { 1870 ((SfxHeaderAttributes_Impl*)GetHeaderAttributes()) 1871 ->ClearForSourceView(); 1872 } 1873 1874 1875 void SfxObjectShell::SetHeaderAttributesForSourceViewHack() 1876 { 1877 ((SfxHeaderAttributes_Impl*)GetHeaderAttributes()) 1878 ->SetAttributes(); 1879 } 1880 1881 sal_Bool SfxObjectShell::IsPreview() const 1882 { 1883 if ( !pMedium ) 1884 return sal_False; 1885 1886 sal_Bool bPreview = sal_False; 1887 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False); 1888 if ( pFlags ) 1889 { 1890 // Werte auf einzelne Items verteilen 1891 String aFileFlags = pFlags->GetValue(); 1892 aFileFlags.ToUpperAscii(); 1893 if ( STRING_NOTFOUND != aFileFlags.Search( 'B' ) ) 1894 bPreview = sal_True; 1895 } 1896 1897 if ( !bPreview ) 1898 { 1899 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pItem, SfxBoolItem, SID_PREVIEW, sal_False); 1900 if ( pItem ) 1901 bPreview = pItem->GetValue(); 1902 } 1903 1904 return bPreview; 1905 } 1906 1907 sal_Bool SfxObjectShell::IsSecure() 1908 { 1909 // Wenn globale Warnung an ist, nach Secure-Referer-Liste gehen 1910 String aReferer = GetMedium()->GetName(); 1911 if ( !aReferer.Len() ) 1912 { 1913 // bei neuen Dokumenten das Template als Referer nehmen 1914 ::rtl::OUString aTempl( getDocProperties()->getTemplateURL() ); 1915 if ( aTempl.getLength() ) 1916 aReferer = INetURLObject( aTempl ).GetMainURL( INetURLObject::NO_DECODE ); 1917 } 1918 1919 INetURLObject aURL( "macro:" ); 1920 if ( !aReferer.Len() ) 1921 // empty new or embedded document 1922 return sal_True; 1923 1924 SvtSecurityOptions aOpt; 1925 1926 if( aOpt.GetBasicMode() == eALWAYS_EXECUTE ) 1927 return sal_True; 1928 1929 if( aOpt.GetBasicMode() == eNEVER_EXECUTE ) 1930 return sal_False; 1931 1932 if ( aOpt.IsSecureURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aReferer ) ) 1933 //if ( SvtSecurityOptions().IsSecureURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aReferer ) ) 1934 { 1935 if ( GetMedium()->GetContent().is() ) 1936 { 1937 Any aAny( ::utl::UCBContentHelper::GetProperty( aURL.GetMainURL( INetURLObject::NO_DECODE ), String( RTL_CONSTASCII_USTRINGPARAM("IsProtected")) ) ); 1938 sal_Bool bIsProtected = sal_False; 1939 if ( ( aAny >>= bIsProtected ) && bIsProtected ) 1940 return sal_False; 1941 else 1942 return sal_True; 1943 } 1944 else 1945 return sal_True; 1946 } 1947 else 1948 return sal_False; 1949 } 1950 1951 void SfxObjectShell::SetWaitCursor( sal_Bool bSet ) const 1952 { 1953 for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) ) 1954 { 1955 if ( bSet ) 1956 pFrame->GetFrame().GetWindow().EnterWait(); 1957 else 1958 pFrame->GetFrame().GetWindow().LeaveWait(); 1959 } 1960 } 1961 1962 String SfxObjectShell::GetAPIName() const 1963 { 1964 INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) ); 1965 String aName( aURL.GetBase() ); 1966 if( !aName.Len() ) 1967 aName = aURL.GetURLNoPass(); 1968 if ( !aName.Len() ) 1969 aName = GetTitle( SFX_TITLE_DETECT ); 1970 return aName; 1971 } 1972 1973 void SfxObjectShell::Invalidate( sal_uInt16 nId ) 1974 { 1975 for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) ) 1976 Invalidate_Impl( pFrame->GetBindings(), nId ); 1977 } 1978 1979 bool SfxObjectShell::AdjustMacroMode( const String& /*rScriptType*/, bool bSuppressUI ) 1980 { 1981 uno::Reference< task::XInteractionHandler > xInteraction; 1982 if ( pMedium && !bSuppressUI ) 1983 xInteraction = pMedium->GetInteractionHandler(); 1984 1985 CheckForBrokenDocSignatures_Impl( xInteraction ); 1986 1987 CheckEncryption_Impl( xInteraction ); 1988 1989 return pImp->aMacroMode.adjustMacroMode( xInteraction ); 1990 } 1991 1992 Window* SfxObjectShell::GetDialogParent( SfxMedium* pLoadingMedium ) 1993 { 1994 Window* pWindow = 0; 1995 SfxItemSet* pSet = pLoadingMedium ? pLoadingMedium->GetItemSet() : GetMedium()->GetItemSet(); 1996 SFX_ITEMSET_ARG( pSet, pUnoItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False ); 1997 if ( pUnoItem ) 1998 { 1999 uno::Reference < frame::XFrame > xFrame( pUnoItem->GetFrame() ); 2000 pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); 2001 } 2002 2003 if ( !pWindow ) 2004 { 2005 SfxFrame* pFrame = 0; 2006 SFX_ITEMSET_ARG( pSet, pFrameItem, SfxFrameItem, SID_DOCFRAME, sal_False ); 2007 if( pFrameItem && pFrameItem->GetFrame() ) 2008 // get target frame from ItemSet 2009 pFrame = pFrameItem->GetFrame(); 2010 else 2011 { 2012 // try the current frame 2013 SfxViewFrame* pView = SfxViewFrame::Current(); 2014 if ( !pView || pView->GetObjectShell() != this ) 2015 // get any visible frame 2016 pView = SfxViewFrame::GetFirst(this); 2017 if ( pView ) 2018 pFrame = &pView->GetFrame(); 2019 } 2020 2021 if ( pFrame ) 2022 // get topmost window 2023 pWindow = VCLUnoHelper::GetWindow( pFrame->GetFrameInterface()->getContainerWindow() ); 2024 } 2025 2026 if ( pWindow ) 2027 { 2028 // this frame may be invisible, show it if it is allowed 2029 SFX_ITEMSET_ARG( pSet, pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False ); 2030 if ( !pHiddenItem || !pHiddenItem->GetValue() ) 2031 { 2032 pWindow->Show(); 2033 pWindow->ToTop(); 2034 } 2035 } 2036 2037 return pWindow; 2038 } 2039 2040 String SfxObjectShell::UpdateTitle( SfxMedium* pMed, sal_uInt16 nDocViewNumber ) 2041 { 2042 // Titel des Fensters 2043 String aTitle; 2044 if ( pMed ) 2045 { 2046 INetURLObject aTmp( pMed->GetName() ); 2047 aTitle = aTmp.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 2048 } 2049 else 2050 { 2051 pMed = GetMedium(); 2052 aTitle = GetTitle(SFX_TITLE_CAPTION); 2053 String aName(aTitle); 2054 if ( nDocViewNumber ) 2055 { 2056 aName += ':'; 2057 aName += String::CreateFromInt32( nDocViewNumber ); 2058 } 2059 } 2060 2061 if ( pMed ) 2062 { 2063 SFX_ITEMSET_ARG( pMed->GetItemSet(), pRepairedDocItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False ); 2064 if ( pRepairedDocItem && pRepairedDocItem->GetValue() ) 2065 aTitle += String( SfxResId(STR_REPAIREDDOCUMENT) ); 2066 } 2067 2068 if ( IsReadOnlyUI() || (pMed && pMed->IsReadOnly()) ) 2069 aTitle += String( SfxResId(STR_READONLY) ); 2070 else if ( IsDocShared() ) 2071 aTitle += String( SfxResId(STR_SHARED) ); 2072 2073 return aTitle; 2074 } 2075 2076 void SfxObjectShell::SetCreateMode_Impl( SfxObjectCreateMode nMode ) 2077 { 2078 eCreateMode = nMode; 2079 } 2080 2081 sal_Bool SfxObjectShell::IsInPlaceActive() 2082 { 2083 if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED ) 2084 return sal_False; 2085 2086 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); 2087 return pFrame && pFrame->GetFrame().IsInPlace(); 2088 } 2089 2090 sal_Bool SfxObjectShell::IsUIActive() 2091 { 2092 if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED ) 2093 return sal_False; 2094 2095 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); 2096 return pFrame && pFrame->GetFrame().IsInPlace() && pFrame->GetFrame().GetWorkWindow_Impl()->IsVisible_Impl(); 2097 } 2098 2099 void SfxObjectShell::UIActivate( sal_Bool ) 2100 { 2101 } 2102 2103 void SfxObjectShell::InPlaceActivate( sal_Bool ) 2104 { 2105 } 2106 2107 sal_Bool SfxObjectShell::UseInteractionToHandleError( 2108 const uno::Reference< task::XInteractionHandler >& xHandler, 2109 sal_uInt32 nError ) 2110 { 2111 sal_Bool bResult = sal_False; 2112 2113 if ( xHandler.is() ) 2114 { 2115 try 2116 { 2117 uno::Any aInteraction; 2118 uno::Sequence< uno::Reference< task::XInteractionContinuation > > lContinuations(2); 2119 ::comphelper::OInteractionAbort* pAbort = new ::comphelper::OInteractionAbort(); 2120 ::comphelper::OInteractionApprove* pApprove = new ::comphelper::OInteractionApprove(); 2121 lContinuations[0] = uno::Reference< task::XInteractionContinuation >( 2122 static_cast< task::XInteractionContinuation* >( pAbort ), uno::UNO_QUERY ); 2123 lContinuations[1] = uno::Reference< task::XInteractionContinuation >( 2124 static_cast< task::XInteractionContinuation* >( pApprove ), uno::UNO_QUERY ); 2125 2126 task::ErrorCodeRequest aErrorCode; 2127 aErrorCode.ErrCode = nError; 2128 aInteraction <<= aErrorCode; 2129 xHandler->handle(::framework::InteractionRequest::CreateRequest (aInteraction,lContinuations)); 2130 bResult = pAbort->wasSelected(); 2131 } 2132 catch( uno::Exception& ) 2133 {} 2134 } 2135 2136 return bResult; 2137 } 2138 2139 sal_Bool SfxObjectShell_Impl::NeedsOfficeUpdateDialog() 2140 { 2141 // if the configuration is not available for any reason, the default behavior is to show the message 2142 sal_Bool bResult = sal_True; 2143 2144 try 2145 { 2146 uno::Reference< lang::XMultiServiceFactory > xServiceManager( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); 2147 uno::Reference< uno::XInterface > xCommonConfig( 2148 ::comphelper::ConfigurationHelper::openConfig( 2149 xServiceManager, 2150 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ), 2151 ::comphelper::ConfigurationHelper::E_STANDARD ), 2152 uno::UNO_SET_THROW ); 2153 2154 ::comphelper::ConfigurationHelper::readRelativeKey( 2155 xCommonConfig, 2156 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Load/" ) ), 2157 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ShowOfficeUpdateDialog" ) ) ) >>= bResult; 2158 } 2159 catch( uno::Exception& ) 2160 { 2161 } 2162 2163 return bResult; 2164 } 2165 2166 sal_Int16 SfxObjectShell_Impl::getCurrentMacroExecMode() const 2167 { 2168 sal_Int16 nImposedExecMode( MacroExecMode::NEVER_EXECUTE ); 2169 2170 const SfxMedium* pMedium( rDocShell.GetMedium() ); 2171 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" ); 2172 if ( pMedium ) 2173 { 2174 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pMacroModeItem, SfxUInt16Item, SID_MACROEXECMODE, sal_False); 2175 if ( pMacroModeItem ) 2176 nImposedExecMode = pMacroModeItem->GetValue(); 2177 } 2178 return nImposedExecMode; 2179 } 2180 2181 sal_Bool SfxObjectShell_Impl::setCurrentMacroExecMode( sal_uInt16 nMacroMode ) 2182 { 2183 const SfxMedium* pMedium( rDocShell.GetMedium() ); 2184 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" ); 2185 if ( pMedium ) 2186 { 2187 pMedium->GetItemSet()->Put( SfxUInt16Item( SID_MACROEXECMODE, nMacroMode ) ); 2188 return sal_True; 2189 } 2190 2191 return sal_False; 2192 } 2193 2194 ::rtl::OUString SfxObjectShell_Impl::getDocumentLocation() const 2195 { 2196 ::rtl::OUString sLocation; 2197 2198 const SfxMedium* pMedium( rDocShell.GetMedium() ); 2199 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getDocumentLocation: no medium!" ); 2200 if ( pMedium ) 2201 { 2202 sLocation = pMedium->GetName(); 2203 if ( !sLocation.getLength() ) 2204 { 2205 // for documents made from a template: get the name of the template 2206 sLocation = rDocShell.getDocProperties()->getTemplateURL(); 2207 } 2208 } 2209 return sLocation; 2210 } 2211 2212 uno::Reference< embed::XStorage > SfxObjectShell_Impl::getZipStorageToSign() 2213 { 2214 Reference < embed::XStorage > xStore; 2215 2216 SfxMedium* pMedium( rDocShell.GetMedium() ); 2217 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getLastCommitDocumentStorage: no medium!" ); 2218 if ( pMedium ) 2219 xStore = pMedium->GetZipStorageToSign_Impl(); 2220 2221 return xStore; 2222 } 2223 2224 sal_Bool SfxObjectShell_Impl::documentStorageHasMacros() const 2225 { 2226 return ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocStorage ); 2227 } 2228 2229 Reference< XEmbeddedScripts > SfxObjectShell_Impl::getEmbeddedDocumentScripts() const 2230 { 2231 return Reference< XEmbeddedScripts >( rDocShell.GetModel(), UNO_QUERY ); 2232 } 2233 2234 sal_Int16 SfxObjectShell_Impl::getScriptingSignatureState() 2235 { 2236 sal_Int16 nSignatureState( rDocShell.GetScriptingSignatureState() ); 2237 2238 if ( nSignatureState != SIGNATURESTATE_NOSIGNATURES && m_bMacroSignBroken ) 2239 { 2240 // if there is a macro signature it must be handled as broken 2241 nSignatureState = SIGNATURESTATE_SIGNATURES_BROKEN; 2242 } 2243 2244 return nSignatureState; 2245 } 2246 2247 sal_Bool SfxObjectShell_Impl::hasTrustedScriptingSignature( sal_Bool bAllowUIToAddAuthor ) 2248 { 2249 sal_Bool bResult = sal_False; 2250 2251 try 2252 { 2253 ::rtl::OUString aVersion; 2254 try 2255 { 2256 uno::Reference < beans::XPropertySet > xPropSet( rDocShell.GetStorage(), uno::UNO_QUERY_THROW ); 2257 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aVersion; 2258 } 2259 catch( uno::Exception& ) 2260 { 2261 } 2262 uno::Sequence< uno::Any > aArgs( 1 ); 2263 aArgs[0] <<= aVersion; 2264 2265 uno::Reference< security::XDocumentDigitalSignatures > xSigner( comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ), aArgs ), uno::UNO_QUERY_THROW ); 2266 2267 if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN 2268 || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK 2269 || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED ) 2270 { 2271 uno::Sequence< security::DocumentSignatureInformation > aInfo = rDocShell.ImplAnalyzeSignature( sal_True, xSigner ); 2272 2273 if ( aInfo.getLength() ) 2274 { 2275 if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN ) 2276 nScriptingSignatureState = rDocShell.ImplCheckSignaturesInformation( aInfo ); 2277 2278 if ( nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK 2279 || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED ) 2280 { 2281 for ( sal_Int32 nInd = 0; !bResult && nInd < aInfo.getLength(); nInd++ ) 2282 { 2283 bResult = xSigner->isAuthorTrusted( aInfo[nInd].Signer ); 2284 } 2285 2286 if ( !bResult && bAllowUIToAddAuthor ) 2287 { 2288 uno::Reference< task::XInteractionHandler > xInteraction; 2289 if ( rDocShell.GetMedium() ) 2290 xInteraction = rDocShell.GetMedium()->GetInteractionHandler(); 2291 2292 if ( xInteraction.is() ) 2293 { 2294 task::DocumentMacroConfirmationRequest aRequest; 2295 aRequest.DocumentURL = getDocumentLocation(); 2296 aRequest.DocumentStorage = rDocShell.GetMedium()->GetZipStorageToSign_Impl(); 2297 aRequest.DocumentSignatureInformation = aInfo; 2298 aRequest.DocumentVersion = aVersion; 2299 aRequest.Classification = task::InteractionClassification_QUERY; 2300 bResult = SfxMedium::CallApproveHandler( xInteraction, uno::makeAny( aRequest ), sal_True ); 2301 } 2302 } 2303 } 2304 } 2305 } 2306 } 2307 catch( uno::Exception& ) 2308 {} 2309 2310 return bResult; 2311 } 2312 2313 void SfxObjectShell_Impl::showBrokenSignatureWarning( const uno::Reference< task::XInteractionHandler >& _rxInteraction ) const 2314 { 2315 if ( !bSignatureErrorIsShown ) 2316 { 2317 SfxObjectShell::UseInteractionToHandleError( _rxInteraction, ERRCODE_SFX_BROKENSIGNATURE ); 2318 const_cast< SfxObjectShell_Impl* >( this )->bSignatureErrorIsShown = sal_True; 2319 } 2320 } 2321 2322 void SfxObjectShell::AddLog( const ::rtl::OUString& aMessage ) 2323 { 2324 if ( !pImp->m_xLogRing.is() ) 2325 { 2326 try 2327 { 2328 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 2329 if ( aContext.is() ) 2330 pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW ); 2331 } 2332 catch( uno::Exception& ) 2333 {} 2334 } 2335 2336 if ( pImp->m_xLogRing.is() ) 2337 pImp->m_xLogRing->logString( aMessage ); 2338 } 2339 2340 namespace { 2341 2342 void WriteStringInStream( const uno::Reference< io::XOutputStream >& xOutStream, const ::rtl::OUString& aString ) 2343 { 2344 if ( xOutStream.is() ) 2345 { 2346 ::rtl::OString aStrLog = ::rtl::OUStringToOString( aString, RTL_TEXTENCODING_UTF8 ); 2347 uno::Sequence< sal_Int8 > aLogData( (const sal_Int8*)aStrLog.getStr(), aStrLog.getLength() ); 2348 xOutStream->writeBytes( aLogData ); 2349 2350 aLogData.realloc( 1 ); 2351 aLogData[0] = '\n'; 2352 xOutStream->writeBytes( aLogData ); 2353 } 2354 } 2355 2356 } 2357 2358 void SfxObjectShell::StoreLog() 2359 { 2360 if ( !pImp->m_xLogRing.is() ) 2361 { 2362 try 2363 { 2364 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 2365 if ( aContext.is() ) 2366 pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW ); 2367 } 2368 catch( uno::Exception& ) 2369 {} 2370 } 2371 2372 if ( pImp->m_xLogRing.is() ) 2373 { 2374 ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}" ) ); 2375 //#ifdef WNT 2376 // ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}" ) ); 2377 //#else 2378 // ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/bootstraprc:UserInstallation}" ) ); 2379 //#endif 2380 ::rtl::Bootstrap::expandMacros( aFileURL ); 2381 2382 //#ifdef WNT 2383 // ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/setup.ini:buildid}" ) ); 2384 //#else 2385 // ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/setuprc:buildid}" ) ); 2386 //#endif 2387 ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("setup") ":buildid}" ) ); 2388 ::rtl::Bootstrap::expandMacros( aBuildID ); 2389 2390 if ( aFileURL.getLength() ) 2391 { 2392 aFileURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/temp/document_io_logring.txt" ) ); 2393 try 2394 { 2395 uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); 2396 uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess( xFactory->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.ucb.SimpleFileAccess" ) ), uno::UNO_QUERY_THROW ); 2397 uno::Reference< io::XStream > xStream( xSimpleFileAccess->openFileReadWrite( aFileURL ), uno::UNO_SET_THROW ); 2398 uno::Reference< io::XOutputStream > xOutStream( xStream->getOutputStream(), uno::UNO_SET_THROW ); 2399 uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY_THROW ); 2400 xTruncate->truncate(); 2401 2402 if ( aBuildID.getLength() ) 2403 WriteStringInStream( xOutStream, aBuildID ); 2404 2405 uno::Sequence< ::rtl::OUString > aLogSeq = pImp->m_xLogRing->getCollectedLog(); 2406 for ( sal_Int32 nInd = 0; nInd < aLogSeq.getLength(); nInd++ ) 2407 WriteStringInStream( xOutStream, aLogSeq[nInd] ); 2408 } 2409 catch( uno::Exception& ) 2410 {} 2411 } 2412 } 2413 } 2414 2415