LCOV - code coverage report
Current view: top level - sfx2/source/doc - objmisc.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 1 871 0.1 %
Date: 2014-04-14 Functions: 2 105 1.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <config_features.h>
      21             : #include <config_folders.h>
      22             : 
      23             : #include <tools/inetmsg.hxx>
      24             : #include <tools/diagnose_ex.h>
      25             : #include <svl/eitem.hxx>
      26             : #include <svl/stritem.hxx>
      27             : #include <svl/intitem.hxx>
      28             : #include <svtools/svparser.hxx>
      29             : #include <osl/mutex.hxx>
      30             : #include <cppuhelper/exc_hlp.hxx>
      31             : 
      32             : #include <com/sun/star/container/XChild.hpp>
      33             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      34             : #include <com/sun/star/document/XDocumentProperties.hpp>
      35             : #include <com/sun/star/document/UpdateDocMode.hpp>
      36             : #include <com/sun/star/document/MacroExecMode.hpp>
      37             : #include <com/sun/star/document/XScriptInvocationContext.hpp>
      38             : #include <com/sun/star/embed/EmbedStates.hpp>
      39             : #include <com/sun/star/embed/XEmbedPersist.hpp>
      40             : #include <com/sun/star/logging/DocumentIOLogRing.hpp>
      41             : #include <com/sun/star/script/XTypeConverter.hpp>
      42             : #include <com/sun/star/script/FinishEngineEvent.hpp>
      43             : #include <com/sun/star/script/InterruptReason.hpp>
      44             : #include <com/sun/star/script/XEngineListener.hpp>
      45             : #include <com/sun/star/script/XDebugging.hpp>
      46             : #include <com/sun/star/script/XInvocation.hpp>
      47             : #include <com/sun/star/script/ContextInformation.hpp>
      48             : #include <com/sun/star/script/FinishReason.hpp>
      49             : #include <com/sun/star/script/XEngine.hpp>
      50             : #include <com/sun/star/script/InterruptEngineEvent.hpp>
      51             : #include <com/sun/star/script/XLibraryAccess.hpp>
      52             : #include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
      53             : #include <com/sun/star/script/provider/XScript.hpp>
      54             : #include <com/sun/star/script/provider/XScriptProvider.hpp>
      55             : #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
      56             : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
      57             : #include <com/sun/star/util/XModifiable.hpp>
      58             : 
      59             : #include <toolkit/helper/vclunohelper.hxx>
      60             : 
      61             : #include <com/sun/star/uno/Reference.h>
      62             : #include <com/sun/star/uno/Any.h>
      63             : #include <com/sun/star/ucb/XContent.hpp>
      64             : #include <com/sun/star/task/ErrorCodeRequest.hpp>
      65             : #include <unotools/securityoptions.hxx>
      66             : 
      67             : #include <comphelper/processfactory.hxx>
      68             : #include <comphelper/string.hxx>
      69             : 
      70             : #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
      71             : #include <com/sun/star/task/DocumentMacroConfirmationRequest.hpp>
      72             : #include <com/sun/star/task/InteractionClassification.hpp>
      73             : #include <com/sun/star/frame/XModel.hpp>
      74             : 
      75             : using namespace ::com::sun::star;
      76             : using namespace ::com::sun::star::uno;
      77             : using namespace ::com::sun::star::ucb;
      78             : using namespace ::com::sun::star::document;
      79             : using namespace ::com::sun::star::frame;
      80             : using namespace ::com::sun::star::script;
      81             : using namespace ::com::sun::star::script::provider;
      82             : using namespace ::com::sun::star::container;
      83             : #include <basic/sbuno.hxx>
      84             : #include <basic/sbstar.hxx>
      85             : #include <basic/basmgr.hxx>
      86             : #include <vcl/msgbox.hxx>
      87             : #include <basic/sbx.hxx>
      88             : #include <svtools/sfxecode.hxx>
      89             : #include <svtools/ehdl.hxx>
      90             : 
      91             : #include <unotools/pathoptions.hxx>
      92             : #include <unotools/ucbhelper.hxx>
      93             : #include <tools/inetmime.hxx>
      94             : #include <tools/urlobj.hxx>
      95             : #include <svl/inettype.hxx>
      96             : #include <svl/sharecontrolfile.hxx>
      97             : #include <osl/file.hxx>
      98             : #include <rtl/bootstrap.hxx>
      99             : #include <vcl/svapp.hxx>
     100             : #include <framework/interaction.hxx>
     101             : #include <framework/documentundoguard.hxx>
     102             : #include <comphelper/interaction.hxx>
     103             : #include <comphelper/storagehelper.hxx>
     104             : #include <comphelper/documentconstants.hxx>
     105             : 
     106             : #include <sfx2/signaturestate.hxx>
     107             : #include <sfx2/app.hxx>
     108             : #include "appdata.hxx"
     109             : #include <sfx2/request.hxx>
     110             : #include <sfx2/bindings.hxx>
     111             : #include <sfx2/sfxresid.hxx>
     112             : #include <sfx2/docfile.hxx>
     113             : #include <sfx2/docfilt.hxx>
     114             : #include <sfx2/objsh.hxx>
     115             : #include "objshimp.hxx"
     116             : #include <sfx2/event.hxx>
     117             : #include <sfx2/sfx.hrc>
     118             : #include <sfx2/dispatch.hxx>
     119             : #include <sfx2/viewfrm.hxx>
     120             : #include <sfx2/viewsh.hxx>
     121             : #include <sfx2/ctrlitem.hxx>
     122             : #include "arrdecl.hxx"
     123             : #include <sfx2/module.hxx>
     124             : #include <sfx2/docfac.hxx>
     125             : #include "helper.hxx"
     126             : #include "doc.hrc"
     127             : #include "workwin.hxx"
     128             : #include "helpid.hrc"
     129             : #include "../appl/app.hrc"
     130             : #include <sfx2/sfxdlg.hxx>
     131             : #include "appbaslib.hxx"
     132             : #include <openflag.hxx>
     133             : 
     134             : #include <boost/scoped_ptr.hpp>
     135             : 
     136             : // class SfxHeaderAttributes_Impl ----------------------------------------
     137             : 
     138           0 : class SfxHeaderAttributes_Impl : public SvKeyValueIterator
     139             : {
     140             : private:
     141             :     SfxObjectShell* pDoc;
     142             :     SvKeyValueIteratorRef xIter;
     143             :     bool bAlert;
     144             : 
     145             : public:
     146           0 :     SfxHeaderAttributes_Impl( SfxObjectShell* pSh ) :
     147             :         SvKeyValueIterator(), pDoc( pSh ),
     148             :         xIter( pSh->GetMedium()->GetHeaderAttributes_Impl() ),
     149           0 :         bAlert( false ) {}
     150             : 
     151           0 :     virtual bool GetFirst( SvKeyValue& rKV ) SAL_OVERRIDE { return xIter->GetFirst( rKV ); }
     152           0 :     virtual bool GetNext( SvKeyValue& rKV ) SAL_OVERRIDE { return xIter->GetNext( rKV ); }
     153             :     virtual void Append( const SvKeyValue& rKV ) SAL_OVERRIDE;
     154             : 
     155           0 :     void ClearForSourceView() { xIter = new SvKeyValueIterator; bAlert = false; }
     156             :     void SetAttributes();
     157             :     void SetAttribute( const SvKeyValue& rKV );
     158             : };
     159             : 
     160             : 
     161             : 
     162             : sal_uInt16 const aTitleMap_Impl[3][2] =
     163             : {
     164             :                                 //  local               remote
     165             :     /*  SFX_TITLE_CAPTION   */  {   SFX_TITLE_FILENAME, SFX_TITLE_TITLE },
     166             :     /*  SFX_TITLE_PICKLIST  */  {   32,                 SFX_TITLE_FULLNAME },
     167             :     /*  SFX_TITLE_HISTORY   */  {   32,                 SFX_TITLE_FULLNAME }
     168             : };
     169             : 
     170             : 
     171             : 
     172           0 : void SfxObjectShell::AbortImport()
     173             : {
     174           0 :     pImp->bIsAbortingImport = true;
     175           0 : }
     176             : 
     177             : 
     178             : 
     179           0 : bool SfxObjectShell::IsAbortingImport() const
     180             : {
     181           0 :     return pImp->bIsAbortingImport;
     182             : }
     183             : 
     184             : 
     185             : 
     186             : uno::Reference<document::XDocumentProperties>
     187           0 : SfxObjectShell::getDocProperties()
     188             : {
     189             :     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
     190           0 :         GetModel(), uno::UNO_QUERY_THROW);
     191             :     uno::Reference<document::XDocumentProperties> xDocProps(
     192           0 :         xDPS->getDocumentProperties());
     193             :     DBG_ASSERT(xDocProps.is(),
     194             :         "SfxObjectShell: model has no DocumentProperties");
     195           0 :     return xDocProps;
     196             : }
     197             : 
     198             : 
     199             : 
     200           0 : void SfxObjectShell::DoFlushDocInfo()
     201             : {
     202           0 : }
     203             : 
     204             : 
     205             : 
     206             : // Note: the only thing that calls this is the modification event handler
     207             : // that is installed at the XDocumentProperties
     208           0 : void SfxObjectShell::FlushDocInfo()
     209             : {
     210           0 :     if ( IsLoading() )
     211           0 :         return;
     212             : 
     213           0 :     SetModified(true);
     214           0 :     uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
     215           0 :     DoFlushDocInfo(); // call template method
     216           0 :     OUString url(xDocProps->getAutoloadURL());
     217           0 :     sal_Int32 delay(xDocProps->getAutoloadSecs());
     218           0 :     SetAutoLoad( INetURLObject(url), delay * 1000,
     219           0 :                  (delay > 0) || !url.isEmpty() );
     220             : }
     221             : 
     222             : 
     223             : 
     224           0 : void SfxObjectShell::SetError( sal_uInt32 lErr, const OUString& aLogMessage )
     225             : {
     226           0 :     if(pImp->lErr==ERRCODE_NONE)
     227             :     {
     228           0 :         pImp->lErr=lErr;
     229             : 
     230           0 :         if( lErr != ERRCODE_NONE && !aLogMessage.isEmpty() )
     231           0 :             AddLog( aLogMessage );
     232             :     }
     233           0 : }
     234             : 
     235             : 
     236             : 
     237           0 : sal_uInt32 SfxObjectShell::GetError() const
     238             : {
     239           0 :     return ERRCODE_TOERROR(GetErrorCode());
     240             : }
     241             : 
     242             : 
     243             : 
     244           0 : sal_uInt32 SfxObjectShell::GetErrorCode() const
     245             : {
     246           0 :     sal_uInt32 lError=pImp->lErr;
     247           0 :     if(!lError && GetMedium())
     248           0 :         lError=GetMedium()->GetErrorCode();
     249           0 :     return lError;
     250             : }
     251             : 
     252             : 
     253             : 
     254           0 : void SfxObjectShell::ResetError()
     255             : {
     256           0 :     if( pImp->lErr != ERRCODE_NONE )
     257           0 :         AddLog( OUString( OSL_LOG_PREFIX "Resetting Error."  ) );
     258             : 
     259           0 :     pImp->lErr=0;
     260           0 :     SfxMedium * pMed = GetMedium();
     261           0 :     if( pMed )
     262           0 :         pMed->ResetError();
     263           0 : }
     264             : 
     265             : 
     266             : 
     267           0 : bool SfxObjectShell::IsTemplate() const
     268             : {
     269           0 :     return pImp->bIsTemplate;
     270             : }
     271             : 
     272             : 
     273             : 
     274           0 : void SfxObjectShell::EnableSetModified( bool bEnable )
     275             : {
     276             : #ifdef DBG_UTIL
     277             :     if ( bEnable == pImp->m_bEnableSetModified )
     278             :         DBG_WARNING( "SFX_PERSIST: EnableSetModified 2x called with the same value" );
     279             : #endif
     280           0 :     pImp->m_bEnableSetModified = bEnable;
     281           0 : }
     282             : 
     283             : 
     284             : 
     285           0 : bool SfxObjectShell::IsEnableSetModified() const
     286             : {
     287           0 :     return pImp->m_bEnableSetModified && !IsReadOnly();
     288             : }
     289             : 
     290             : 
     291             : 
     292           0 : bool SfxObjectShell::IsModified()
     293             : {
     294           0 :     if ( pImp->m_bIsModified )
     295           0 :         return true;
     296             : 
     297           0 :     if ( !pImp->m_xDocStorage.is() || IsReadOnly() )
     298             :     {
     299             :         // if the document still has no storage and is not set to be modified explicitly it is not modified
     300             :         // a readonly document is also not modified
     301             : 
     302           0 :         return false;
     303             :     }
     304             : 
     305           0 :     uno::Sequence < OUString > aNames = GetEmbeddedObjectContainer().GetObjectNames();
     306           0 :     for ( sal_Int32 n=0; n<aNames.getLength(); n++ )
     307             :     {
     308           0 :         uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObjectContainer().GetEmbeddedObject( aNames[n] );
     309             :         OSL_ENSURE( xObj.is(), "An empty entry in the embedded objects list!\n" );
     310           0 :         if ( xObj.is() )
     311             :         {
     312             :             try
     313             :             {
     314           0 :                 sal_Int32 nState = xObj->getCurrentState();
     315           0 :                 if ( nState != embed::EmbedStates::LOADED )
     316             :                 {
     317           0 :                     uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
     318           0 :                     if ( xModifiable.is() && xModifiable->isModified() )
     319           0 :                         return true;
     320             :                 }
     321             :             }
     322           0 :             catch( uno::Exception& )
     323             :             {}
     324             :         }
     325           0 :     }
     326             : 
     327           0 :     return false;
     328             : }
     329             : 
     330             : 
     331             : 
     332           0 : void SfxObjectShell::SetModified( bool bModifiedP )
     333             : {
     334             : #ifdef DBG_UTIL
     335             :     if ( !bModifiedP && !IsEnableSetModified() )
     336             :         DBG_WARNING( "SFX_PERSIST: SetModified( sal_False ), although IsEnableSetModified() == sal_False" );
     337             : #endif
     338             : 
     339           0 :     if( !IsEnableSetModified() )
     340           0 :         return;
     341             : 
     342           0 :     if( pImp->m_bIsModified != bModifiedP )
     343             :     {
     344           0 :         pImp->m_bIsModified = bModifiedP;
     345           0 :         ModifyChanged();
     346             :     }
     347             : }
     348             : 
     349             : 
     350             : 
     351           0 : void SfxObjectShell::ModifyChanged()
     352             : {
     353           0 :     if ( pImp->bClosing )
     354             :         // SetModified dispose of the models!
     355           0 :         return;
     356             : 
     357             : 
     358           0 :     SfxViewFrame* pViewFrame = SfxViewFrame::Current();
     359           0 :     if ( pViewFrame )
     360           0 :         pViewFrame->GetBindings().Invalidate( SID_SAVEDOCS );
     361             : 
     362           0 :     Invalidate( SID_SIGNATURE );
     363           0 :     Invalidate( SID_MACRO_SIGNATURE );
     364           0 :     Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) );    // xmlsec05, signed state might change in title...
     365             : 
     366           0 :     SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_MODIFYCHANGED, GlobalEventConfig::GetEventName(STR_EVENT_MODIFYCHANGED), this ) );
     367             : }
     368             : 
     369             : 
     370             : 
     371           0 : bool SfxObjectShell::IsReadOnlyUI() const
     372             : 
     373             : /*  [Description]
     374             : 
     375             :     Returns sal_True if the document for the UI is treated as r/o. This is
     376             :     regardless of the actual r/o, which can be checked with <IsReadOnly()>.
     377             : */
     378             : 
     379             : {
     380           0 :     return pImp->bReadOnlyUI;
     381             : }
     382             : 
     383             : 
     384             : 
     385           0 : bool SfxObjectShell::IsReadOnlyMedium() const
     386             : 
     387             : /*  [Description]
     388             : 
     389             :     Returns sal_True when the medium is r/o, for instance when opened as r/o.
     390             : */
     391             : 
     392             : {
     393           0 :     if ( !pMedium )
     394           0 :         return true;
     395           0 :     return pMedium->IsReadOnly();
     396             : }
     397             : 
     398           0 : bool SfxObjectShell::IsOriginallyReadOnlyMedium() const
     399             : {
     400           0 :     return pMedium == 0 || pMedium->IsOriginallyReadOnly();
     401             : }
     402             : 
     403             : 
     404             : 
     405           0 : void SfxObjectShell::SetReadOnlyUI( bool bReadOnly )
     406             : 
     407             : /*  [Description]
     408             : 
     409             :     Turns the document in an r/o and r/w state respectively without reloading
     410             :     it and without changing the open mode of the medium.
     411             : */
     412             : 
     413             : {
     414           0 :     if ( bReadOnly != pImp->bReadOnlyUI )
     415             :     {
     416           0 :         pImp->bReadOnlyUI = bReadOnly;
     417           0 :         Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
     418             :     }
     419           0 : }
     420             : 
     421             : 
     422             : 
     423           0 : void SfxObjectShell::SetReadOnly()
     424             : {
     425             :     // Let the document be completely readonly, means that the
     426             :     // medium open mode is adjusted accordingly, and the write lock
     427             :     // on the file is removed.
     428             : 
     429           0 :      if ( pMedium && !IsReadOnlyMedium() )
     430             :     {
     431           0 :         bool bWasROUI = IsReadOnly();
     432             : 
     433           0 :         pMedium->UnlockFile( false );
     434             : 
     435             :         // the storage-based mediums are already based on the temporary file
     436             :         // so UnlockFile has already closed the locking stream
     437           0 :         if ( !pMedium->HasStorage_Impl() && IsLoadingFinished() )
     438           0 :             pMedium->CloseInStream();
     439             : 
     440           0 :         pMedium->SetOpenMode( SFX_STREAM_READONLY, true );
     441           0 :         pMedium->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, true ) );
     442             : 
     443           0 :         if ( !bWasROUI )
     444           0 :             Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
     445             :     }
     446           0 : }
     447             : 
     448             : 
     449           0 : bool SfxObjectShell::IsReadOnly() const
     450             : {
     451           0 :     return pImp->bReadOnlyUI || pMedium == 0;
     452             : }
     453             : 
     454             : 
     455             : 
     456           0 : bool SfxObjectShell::IsInModalMode() const
     457             : {
     458           0 :     return pImp->bModalMode || pImp->bRunningMacro;
     459             : }
     460             : 
     461           0 : bool SfxObjectShell::AcceptStateUpdate() const
     462             : {
     463           0 :     return !IsInModalMode();
     464             : }
     465             : 
     466             : 
     467             : 
     468           0 : void SfxObjectShell::SetMacroMode_Impl( bool bModal )
     469             : {
     470           0 :     if ( !pImp->bRunningMacro != !bModal )
     471             :     {
     472           0 :         pImp->bRunningMacro = bModal;
     473           0 :         Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
     474             :     }
     475           0 : }
     476             : 
     477             : 
     478             : 
     479           0 : void SfxObjectShell::SetModalMode_Impl( bool bModal )
     480             : {
     481             :     // Broadcast only if modified, or otherwise it will possibly go into
     482             :     // an endless loop
     483           0 :     if ( !pImp->bModalMode != !bModal )
     484             :     {
     485             :         // Central count
     486           0 :         sal_uInt16 &rDocModalCount = SFX_APP()->Get_Impl()->nDocModalMode;
     487           0 :         if ( bModal )
     488           0 :             ++rDocModalCount;
     489             :         else
     490           0 :             --rDocModalCount;
     491             : 
     492             :         // Switch
     493           0 :         pImp->bModalMode = bModal;
     494           0 :         Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
     495             :     }
     496           0 : }
     497             : 
     498             : #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
     499             : 
     500           0 : bool SfxObjectShell::SwitchToShared( bool bShared, bool bSave )
     501             : {
     502           0 :     bool bResult = true;
     503             : 
     504           0 :     if ( bShared != IsDocShared() )
     505             :     {
     506           0 :         OUString aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
     507             : 
     508           0 :         if ( aOrigURL.isEmpty() && bSave )
     509             :         {
     510             :             // this is a new document, let it be stored before switching to the shared mode;
     511             :             // the storing should be done without shared flag, since it is possible that the
     512             :             // target location does not allow to create sharing control file;
     513             :             // the shared flag will be set later after creation of sharing control file
     514           0 :             SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
     515             : 
     516           0 :             if ( pViewFrame )
     517             :             {
     518             :                 // TODO/LATER: currently the application guards against the reentrance problem
     519           0 :                 const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
     520           0 :                 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
     521           0 :                 bResult = ( pResult && pResult->GetValue() );
     522           0 :                 if ( bResult )
     523           0 :                     aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
     524             :             }
     525             :         }
     526             : 
     527           0 :         bool bOldValue = HasSharedXMLFlagSet();
     528           0 :         SetSharedXMLFlag( bShared );
     529             : 
     530           0 :         bool bRemoveEntryOnError = false;
     531           0 :         if ( bResult && bShared )
     532             :         {
     533             :             try
     534             :             {
     535           0 :                 ::svt::ShareControlFile aControlFile( aOrigURL );
     536           0 :                 aControlFile.InsertOwnEntry();
     537           0 :                 bRemoveEntryOnError = true;
     538             :             }
     539           0 :             catch( uno::Exception& )
     540             :             {
     541           0 :                 bResult = false;
     542             :             }
     543             :         }
     544             : 
     545           0 :         if ( bResult && bSave )
     546             :         {
     547           0 :             SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
     548             : 
     549           0 :             if ( pViewFrame )
     550             :             {
     551             :                 // TODO/LATER: currently the application guards against the reentrance problem
     552           0 :                 SetModified( true ); // the modified flag has to be set to let the document be stored with the shared flag
     553           0 :                 const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
     554           0 :                 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
     555           0 :                 bResult = ( pResult && pResult->GetValue() );
     556             :             }
     557             :         }
     558             : 
     559           0 :         if ( bResult )
     560             :         {
     561             :             // TODO/LATER: Is it possible that the following calls fail?
     562           0 :             if ( bShared )
     563             :             {
     564           0 :                 pImp->m_aSharedFileURL = aOrigURL;
     565           0 :                 GetMedium()->SwitchDocumentToTempFile();
     566             :             }
     567             :             else
     568             :             {
     569           0 :                 OUString aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
     570           0 :                 GetMedium()->SwitchDocumentToFile( GetSharedFileURL() );
     571           0 :                 pImp->m_aSharedFileURL = OUString();
     572             : 
     573             :                 // now remove the temporary file the document was based on
     574           0 :                 ::utl::UCBContentHelper::Kill( aTempFileURL );
     575             : 
     576             :                 try
     577             :                 {
     578             :                     // aOrigURL can not be used since it contains an old value
     579           0 :                     ::svt::ShareControlFile aControlFile( GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
     580           0 :                     aControlFile.RemoveFile();
     581             :                 }
     582           0 :                 catch( uno::Exception& )
     583             :                 {
     584           0 :                 }
     585             :             }
     586             :         }
     587             :         else
     588             :         {
     589             :             // the saving has failed!
     590           0 :             if ( bRemoveEntryOnError )
     591             :             {
     592             :                 try
     593             :                 {
     594           0 :                     ::svt::ShareControlFile aControlFile( aOrigURL );
     595           0 :                     aControlFile.RemoveEntry();
     596             :                 }
     597           0 :                 catch( uno::Exception& )
     598             :                 {}
     599             :             }
     600             : 
     601           0 :             SetSharedXMLFlag( bOldValue );
     602           0 :         }
     603             :     }
     604             :     else
     605           0 :         bResult = false; // the second switch to the same mode
     606             : 
     607           0 :     if ( bResult )
     608           0 :         SetTitle( "" );
     609             : 
     610           0 :     return bResult;
     611             : }
     612             : 
     613             : 
     614             : 
     615           0 : void SfxObjectShell::FreeSharedFile()
     616             : {
     617           0 :     if ( pMedium )
     618           0 :         FreeSharedFile( pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
     619           0 : }
     620             : 
     621             : 
     622           0 : void SfxObjectShell::FreeSharedFile( const OUString& aTempFileURL )
     623             : {
     624           0 :     SetSharedXMLFlag( false );
     625             : 
     626           0 :     if ( IsDocShared() && !aTempFileURL.isEmpty()
     627           0 :       && !::utl::UCBContentHelper::EqualURLs( aTempFileURL, GetSharedFileURL() ) )
     628             :     {
     629           0 :         if ( pImp->m_bAllowShareControlFileClean )
     630             :         {
     631             :             try
     632             :             {
     633           0 :                 ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
     634           0 :                 aControlFile.RemoveEntry();
     635             :             }
     636           0 :             catch( uno::Exception& )
     637             :             {
     638             :             }
     639             :         }
     640             : 
     641             :         // the cleaning is forbidden only once
     642           0 :         pImp->m_bAllowShareControlFileClean = true;
     643             : 
     644             :         // now remove the temporary file the document is based currently on
     645           0 :         ::utl::UCBContentHelper::Kill( aTempFileURL );
     646             : 
     647           0 :         pImp->m_aSharedFileURL = OUString();
     648             :     }
     649           0 : }
     650             : 
     651             : 
     652           0 : void SfxObjectShell::DoNotCleanShareControlFile()
     653             : {
     654           0 :     pImp->m_bAllowShareControlFileClean = false;
     655           0 : }
     656             : 
     657             : 
     658           0 : void SfxObjectShell::SetSharedXMLFlag( bool bFlag ) const
     659             : {
     660           0 :     pImp->m_bSharedXMLFlag = bFlag;
     661           0 : }
     662             : 
     663             : 
     664           0 : bool SfxObjectShell::HasSharedXMLFlagSet() const
     665             : {
     666           0 :     return pImp->m_bSharedXMLFlag;
     667             : }
     668             : 
     669             : 
     670             : 
     671           0 : bool SfxObjectShell::IsDocShared() const
     672             : {
     673           0 :     return ( !pImp->m_aSharedFileURL.isEmpty() );
     674             : }
     675             : 
     676             : 
     677             : 
     678           0 : OUString SfxObjectShell::GetSharedFileURL() const
     679             : {
     680           0 :     return pImp->m_aSharedFileURL;
     681             : }
     682             : 
     683             : #endif
     684             : 
     685             : 
     686             : 
     687           0 : Size SfxObjectShell::GetFirstPageSize()
     688             : {
     689           0 :     return GetVisArea(ASPECT_THUMBNAIL).GetSize();
     690             : }
     691             : 
     692             : 
     693             : 
     694             : 
     695           0 : IndexBitSet& SfxObjectShell::GetNoSet_Impl()
     696             : {
     697           0 :     return pImp->aBitSet;
     698             : }
     699             : 
     700             : 
     701             : // changes the title of the document
     702             : 
     703           0 : void SfxObjectShell::SetTitle
     704             : (
     705             :     const OUString& rTitle                // the new Document Title
     706             : )
     707             : 
     708             : /*  [Description]
     709             : 
     710             :     With this method, the title of the document can be set.
     711             :     This corresponds initially to the full file name. A setting of the
     712             :     title does not affect the file name, but it will be shown in the
     713             :     Caption-Bars of the MDI-window.
     714             : */
     715             : 
     716             : {
     717             : 
     718             :     // Nothing to do?
     719           0 :     if ( ( ( HasName() && pImp->aTitle == rTitle )
     720           0 :         || ( !HasName() && GetTitle() == rTitle ) )
     721           0 :       && !IsDocShared() )
     722           0 :         return;
     723             : 
     724           0 :     SfxApplication *pSfxApp = SFX_APP();
     725             : 
     726             :     // If possible relase the unnamed number.
     727           0 :     if ( pImp->bIsNamedVisible && USHRT_MAX != pImp->nVisualDocumentNumber )
     728             :     {
     729           0 :         pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
     730           0 :         pImp->bIsNamedVisible = false;
     731             :     }
     732             : 
     733             :     // Set Title
     734           0 :     pImp->aTitle = rTitle;
     735             : 
     736             :     // Notification
     737           0 :     if ( GetMedium() )
     738             :     {
     739           0 :         SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) );
     740           0 :         Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
     741             :     }
     742             : }
     743             : 
     744             : 
     745             : 
     746             : #if OSL_DEBUG_LEVEL > 1
     747             : OUString X(const OUString &rRet)
     748             : {
     749             :     if ( rRet.isEmpty() )
     750             :         return OUString( "-empty-" );
     751             :     return rRet;
     752             : }
     753             : #else
     754             : #define X(ret) ret
     755             : #endif
     756             : 
     757             : 
     758           0 : OUString SfxObjectShell::GetTitle
     759             : (
     760             :     sal_uInt16  nMaxLength      /*  0 (default)
     761             :                                 the title itself, as it is
     762             : 
     763             :                                 1 (==SFX_TITLE_FILENAME)
     764             :                                 provides the logical file name without path
     765             :                                 (under WNT depending on the system settings
     766             :                                 without extension)
     767             : 
     768             :                                 2 (==SFX_TITLE_FULLNAME)
     769             :                                 provides the logical file names with full path
     770             :                                 (remote =>:: com:: sun:: star:: util:: URL)
     771             : 
     772             :                                 3 (==SFX_TITLE_APINAME)
     773             :                                 provides the logical filname without path
     774             :                                 and extension
     775             : 
     776             :                                 4 (==SFX_TITLE_DETECT)
     777             :                                 provides the complete title, if not set yet
     778             :                                 it will be created from DocInfo or the name of
     779             :                                 the medium.
     780             : 
     781             :                                 5 (==SFX_TITLE_CAPTION)
     782             :                                 provides the Title just like MB now in the
     783             :                                 CaptionBar view
     784             : 
     785             :                                 6 (==SFX_TITLE_PICKLIST)
     786             :                                 returns the Title, just like MB now would
     787             :                                 display it in the in the PickList
     788             : 
     789             :                                 7 (==SFX_TITLE_HISTORY)
     790             :                                 returns the Title just like MB now would
     791             :                                 display it in the in the History
     792             : 
     793             :                                 10 bis USHRT_MAX
     794             :                                 provides the 'nMaxLength' of the logical
     795             :                                 file name including the path
     796             :                                 (remote => ::com::sun::star::util::URL)
     797             :                                 */
     798             : ) const
     799             : 
     800             : /*  [Description]
     801             : 
     802             :     Returns the title or logical file name of the document, depending on the
     803             :     'nMaxLength'.
     804             : 
     805             :     If the file name with path is used, the Name shortened by replacing one or
     806             :     more directory names with "...", URLs are currently always returned
     807             :     in complete form.
     808             : */
     809             : 
     810             : {
     811           0 :     SfxMedium *pMed = GetMedium();
     812           0 :     if ( IsLoading() )
     813           0 :         return OUString();
     814             : 
     815             :     // Create Title?
     816           0 :     if ( SFX_TITLE_DETECT == nMaxLength && pImp->aTitle.isEmpty() )
     817             :     {
     818             :         static bool bRecur = false;
     819           0 :         if ( bRecur )
     820           0 :             return OUString("-not available-");
     821           0 :         bRecur = true;
     822             : 
     823           0 :         OUString aTitle;
     824           0 :         SfxObjectShell *pThis = (SfxObjectShell*) this;
     825             : 
     826           0 :         if ( pMed )
     827             :         {
     828           0 :             SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, false );
     829           0 :             if ( pNameItem )
     830           0 :                 aTitle = pNameItem->GetValue();
     831             :         }
     832             : 
     833           0 :         if ( aTitle.isEmpty() )
     834           0 :             aTitle = GetTitle( SFX_TITLE_FILENAME );
     835             : 
     836           0 :         if ( IsTemplate() )
     837           0 :             pThis->SetTitle( aTitle );
     838           0 :         bRecur = false;
     839           0 :         return X(aTitle);
     840             :     }
     841           0 :     else if (SFX_TITLE_APINAME == nMaxLength )
     842           0 :         return X(GetAPIName());
     843             : 
     844             :     // Special case templates:
     845           0 :     if( IsTemplate() && !pImp->aTitle.isEmpty() &&
     846           0 :          ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
     847           0 :         return X(pImp->aTitle);
     848             : 
     849             :     // Picklist/Caption is mapped
     850           0 :     if ( pMed && ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
     851             :     {
     852             :         // If a specific title was given at open:
     853             :         // important for URLs: use INET_PROT_FILE for which the set title is not
     854             :         // considered. (See below, analysis of aTitleMap_Impl)
     855           0 :         SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, false );
     856           0 :         if ( pNameItem )
     857           0 :             return X( pNameItem->GetValue() );
     858             :     }
     859             : 
     860             :     // Still unnamed?
     861             :     DBG_ASSERT( !HasName() || pMed, "HasName() but no Medium?!?" );
     862           0 :     if ( !HasName() || !pMed )
     863             :     {
     864             :         // Title already set?
     865           0 :         if ( !pImp->aTitle.isEmpty() )
     866           0 :             return X(pImp->aTitle);
     867             : 
     868             :         // must it be numbered?
     869           0 :         OUString aNoName(SFX2_RESSTR(STR_NONAME));
     870           0 :         if (pImp->bIsNamedVisible)
     871             :         {
     872             :             // Append number
     873           0 :             aNoName += OUString::number(pImp->nVisualDocumentNumber);
     874             :         }
     875             : 
     876             :         // Document called "noname" for the time being
     877           0 :         return X(aNoName);
     878             :     }
     879             : 
     880           0 :     const INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : OUString( GetMedium()->GetName() ) );
     881           0 :     if ( nMaxLength > SFX_TITLE_CAPTION && nMaxLength <= SFX_TITLE_HISTORY )
     882             :     {
     883             :         sal_uInt16 nRemote;
     884           0 :         if( !pMed || aURL.GetProtocol() == INET_PROT_FILE )
     885           0 :             nRemote = 0;
     886             :         else
     887           0 :             nRemote = 1;
     888           0 :         nMaxLength = aTitleMap_Impl[nMaxLength-SFX_TITLE_CAPTION][nRemote];
     889             :     }
     890             : 
     891             :     // Local file?
     892           0 :     if ( aURL.GetProtocol() == INET_PROT_FILE )
     893             :     {
     894           0 :         OUString aName( aURL.HasMark() ? INetURLObject( aURL.GetURLNoMark() ).PathToFileName() : aURL.PathToFileName() );
     895           0 :         if ( nMaxLength == SFX_TITLE_FULLNAME )
     896           0 :             return X( aName );
     897           0 :         else if ( nMaxLength == SFX_TITLE_FILENAME )
     898           0 :             return X( aURL.getName( INetURLObject::LAST_SEGMENT,
     899             :                 true, INetURLObject::DECODE_WITH_CHARSET ) );
     900           0 :         else if ( pImp->aTitle.isEmpty() )
     901           0 :             pImp->aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT,
     902           0 :                                          true, INetURLObject::DECODE_WITH_CHARSET );
     903             :     }
     904             :     else
     905             :     {
     906             :         // ::com::sun::star::util::URL-Versions
     907           0 :         if ( nMaxLength >= SFX_TITLE_MAXLEN )
     908             :         {
     909           0 :             OUString aComplete( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
     910           0 :             if( aComplete.getLength() > nMaxLength )
     911             :             {
     912           0 :                 OUString aRet( "..." );
     913           0 :                 aRet += aComplete.copy( aComplete.getLength() - nMaxLength + 3, nMaxLength - 3 );
     914           0 :                 return X( aRet );
     915             :             }
     916             :             else
     917           0 :                 return X( aComplete );
     918             :         }
     919           0 :         else if ( nMaxLength == SFX_TITLE_FILENAME )
     920             :         {
     921           0 :             OUString aName( aURL.GetBase() );
     922           0 :             aName = INetURLObject::decode( aName, '%', INetURLObject::DECODE_WITH_CHARSET );
     923           0 :             if( aName.isEmpty() )
     924           0 :                 aName = aURL.GetURLNoPass();
     925           0 :             return X(aName);
     926             :         }
     927           0 :         else if ( nMaxLength == SFX_TITLE_FULLNAME )
     928           0 :             return X(aURL.GetMainURL( INetURLObject::DECODE_TO_IURI ));
     929             : 
     930             :         // Generate Title from file name if possible
     931           0 :         if ( pImp->aTitle.isEmpty() )
     932           0 :             pImp->aTitle = aURL.GetBase();
     933             : 
     934             :         // workaround for the case when the name can not be retrieved from URL by INetURLObject
     935           0 :         if ( pImp->aTitle.isEmpty() )
     936           0 :             pImp->aTitle = aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
     937             :     }
     938             : 
     939             :     // Complete Title
     940           0 :     return X(pImp->aTitle);
     941             : }
     942             : 
     943             : 
     944             : 
     945           0 : void SfxObjectShell::InvalidateName()
     946             : 
     947             : /*  [Description]
     948             : 
     949             :     Returns the title of the new document, DocInfo-Title or
     950             :     File name. Is required for loading from template or SaveAs.
     951             : */
     952             : 
     953             : {
     954           0 :     pImp->aTitle = "";
     955           0 :     SetName( GetTitle( SFX_TITLE_APINAME ) );
     956             : 
     957           0 :     Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
     958           0 : }
     959             : 
     960             : 
     961             : 
     962           0 : void SfxObjectShell::SetNamedVisibility_Impl()
     963             : {
     964           0 :     if ( !pImp->bIsNamedVisible )
     965             :     {
     966           0 :         pImp->bIsNamedVisible = true;
     967           0 :         if ( !HasName() && USHRT_MAX == pImp->nVisualDocumentNumber && pImp->aTitle.isEmpty() )
     968             :         {
     969           0 :             pImp->nVisualDocumentNumber = SFX_APP()->GetFreeIndex();
     970           0 :             Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
     971             :         }
     972             :     }
     973             : 
     974           0 :     SetName( GetTitle(SFX_TITLE_APINAME) );
     975           0 : }
     976             : 
     977           0 : void SfxObjectShell::SetNoName()
     978             : {
     979           0 :     bHasName = false;
     980           0 :     GetModel()->attachResource( OUString(), GetModel()->getArgs() );
     981           0 : }
     982             : 
     983             : 
     984             : 
     985           0 : SfxProgress* SfxObjectShell::GetProgress() const
     986             : {
     987           0 :     return pImp->pProgress;
     988             : }
     989             : 
     990             : 
     991             : 
     992           0 : void SfxObjectShell::SetProgress_Impl
     993             : (
     994             :     SfxProgress *pProgress      /* to started <SfxProgress> or 0,
     995             :                                    if the progress is to be reset */
     996             : )
     997             : 
     998             : /*  [Description]
     999             : 
    1000             :     Internal method to set or reset the Progress modes for
    1001             :     SfxObjectShell.
    1002             : */
    1003             : 
    1004             : {
    1005             :     DBG_ASSERT( ( !pImp->pProgress && pProgress ) ||
    1006             :                 ( pImp->pProgress && !pProgress ),
    1007             :                 "Progress activation/deacitivation mismatch" );
    1008           0 :     pImp->pProgress = pProgress;
    1009           0 : }
    1010             : 
    1011             : 
    1012             : 
    1013           0 : void SfxObjectShell::PostActivateEvent_Impl( SfxViewFrame* pFrame )
    1014             : {
    1015           0 :     SfxApplication* pSfxApp = SFX_APP();
    1016           0 :     if ( !pSfxApp->IsDowning() && !IsLoading() && pFrame && !pFrame->GetFrame().IsClosing_Impl() )
    1017             :     {
    1018           0 :         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, false );
    1019           0 :         if ( !pHiddenItem || !pHiddenItem->GetValue() )
    1020             :         {
    1021           0 :             sal_uInt16 nId = pImp->nEventId;
    1022           0 :             pImp->nEventId = 0;
    1023           0 :             if ( nId == SFX_EVENT_OPENDOC )
    1024           0 :                 pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_OPENDOC), this, pFrame->GetFrame().GetController() ), false);
    1025           0 :             else if (nId == SFX_EVENT_CREATEDOC )
    1026           0 :                 pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_CREATEDOC), this, pFrame->GetFrame().GetController() ), false);
    1027             :         }
    1028             :     }
    1029           0 : }
    1030             : 
    1031             : 
    1032             : 
    1033           0 : void SfxObjectShell::SetActivateEvent_Impl(sal_uInt16 nId )
    1034             : {
    1035           0 :     if ( GetFactory().GetFlags() & SFXOBJECTSHELL_HASOPENDOC )
    1036           0 :         pImp->nEventId = nId;
    1037           0 : }
    1038             : 
    1039           0 : void SfxObjectShell::PrepareReload( )
    1040             : /*  [Description]
    1041             : 
    1042             :     Is called before the Reload and gives the opportunity to clear any caches.
    1043             : */
    1044             : {
    1045           0 : }
    1046             : 
    1047           0 : bool SfxObjectShell::IsAutoLoadLocked() const
    1048             : 
    1049             : /* Returns whether an Autoload is allowed to be executed. Before the
    1050             :    surrounding FrameSet of the AutoLoad is also taken into account as well.
    1051             : */
    1052             : 
    1053             : {
    1054           0 :     return !IsReadOnly() || pImp->nAutoLoadLocks > 0;
    1055             : }
    1056             : 
    1057             : 
    1058           0 : void SfxObjectShell::BreakMacroSign_Impl( bool bBreakMacroSign )
    1059             : {
    1060           0 :     pImp->m_bMacroSignBroken = bBreakMacroSign;
    1061           0 : }
    1062             : 
    1063             : 
    1064           0 : void SfxObjectShell::CheckSecurityOnLoading_Impl()
    1065             : {
    1066           0 :     uno::Reference< task::XInteractionHandler > xInteraction;
    1067           0 :     if ( GetMedium() )
    1068           0 :         xInteraction = GetMedium()->GetInteractionHandler();
    1069             : 
    1070             :     // check if there is a broken signature...
    1071           0 :     CheckForBrokenDocSignatures_Impl( xInteraction );
    1072             : 
    1073           0 :     CheckEncryption_Impl( xInteraction );
    1074             : 
    1075             :     // check macro security
    1076           0 :     pImp->aMacroMode.checkMacrosOnLoading( xInteraction );
    1077           0 : }
    1078             : 
    1079             : 
    1080           0 : void SfxObjectShell::CheckEncryption_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
    1081             : {
    1082           0 :     OUString aVersion;
    1083           0 :     bool bIsEncrypted = false;
    1084           0 :     bool bHasNonEncrypted = false;
    1085             : 
    1086             :     try
    1087             :     {
    1088           0 :         uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
    1089           0 :         xPropSet->getPropertyValue("Version") >>= aVersion;
    1090           0 :         xPropSet->getPropertyValue("HasEncryptedEntries") >>= bIsEncrypted;
    1091           0 :         xPropSet->getPropertyValue("HasNonEncryptedEntries") >>= bHasNonEncrypted;
    1092             :     }
    1093           0 :     catch( uno::Exception& )
    1094             :     {
    1095             :     }
    1096             : 
    1097           0 :     if ( aVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
    1098             :     {
    1099             :         // this is ODF1.2 or later
    1100           0 :         if ( bIsEncrypted && bHasNonEncrypted )
    1101             :         {
    1102           0 :             if ( !pImp->m_bIncomplEncrWarnShown )
    1103             :             {
    1104             :                 // this is an encrypted document with nonencrypted streams inside, show the warning
    1105           0 :                 ::com::sun::star::task::ErrorCodeRequest aErrorCode;
    1106           0 :                 aErrorCode.ErrCode = ERRCODE_SFX_INCOMPLETE_ENCRYPTION;
    1107             : 
    1108           0 :                 SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), false );
    1109           0 :                 pImp->m_bIncomplEncrWarnShown = true;
    1110             :             }
    1111             : 
    1112             :             // broken signatures imply no macro execution at all
    1113           0 :             pImp->aMacroMode.disallowMacroExecution();
    1114             :         }
    1115           0 :     }
    1116           0 : }
    1117             : 
    1118             : 
    1119           0 : void SfxObjectShell::CheckForBrokenDocSignatures_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
    1120             : {
    1121           0 :     sal_Int16 nSignatureState = GetDocumentSignatureState();
    1122           0 :     bool bSignatureBroken = ( nSignatureState == SIGNATURESTATE_SIGNATURES_BROKEN );
    1123           0 :     if ( !bSignatureBroken )
    1124           0 :         return;
    1125             : 
    1126           0 :     pImp->showBrokenSignatureWarning( xHandler );
    1127             : 
    1128             :     // broken signatures imply no macro execution at all
    1129           0 :     pImp->aMacroMode.disallowMacroExecution();
    1130             : }
    1131             : 
    1132             : 
    1133           0 : void SfxObjectShell::SetAutoLoad(
    1134             :     const INetURLObject& rUrl, sal_uInt32 nTime, bool bReload )
    1135             : {
    1136           0 :     if ( pImp->pReloadTimer )
    1137           0 :         DELETEZ(pImp->pReloadTimer);
    1138           0 :     if ( bReload )
    1139             :     {
    1140             :         pImp->pReloadTimer = new AutoReloadTimer_Impl(
    1141             :                                 rUrl.GetMainURL( INetURLObject::DECODE_TO_IURI ),
    1142           0 :                                 nTime, this );
    1143           0 :         pImp->pReloadTimer->Start();
    1144             :     }
    1145           0 : }
    1146             : 
    1147           0 : bool SfxObjectShell::IsLoadingFinished() const
    1148             : {
    1149           0 :     return ( pImp->nLoadedFlags == SFX_LOADED_ALL );
    1150             : }
    1151             : 
    1152             : void impl_addToModelCollection(const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& xModel);
    1153           0 : void SfxObjectShell::InitOwnModel_Impl()
    1154             : {
    1155           0 :     if ( !pImp->bModelInitialized )
    1156             :     {
    1157           0 :         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, false);
    1158           0 :         if ( pSalvageItem )
    1159             :         {
    1160           0 :             pImp->aTempName = pMedium->GetPhysicalName();
    1161           0 :             pMedium->GetItemSet()->ClearItem( SID_DOC_SALVAGE );
    1162           0 :             pMedium->GetItemSet()->ClearItem( SID_FILE_NAME );
    1163           0 :             pMedium->GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, pMedium->GetOrigURL() ) );
    1164             :         }
    1165             :         else
    1166             :         {
    1167           0 :             pMedium->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
    1168           0 :             pMedium->GetItemSet()->ClearItem( SID_DOCUMENT );
    1169             :         }
    1170             : 
    1171           0 :         pMedium->GetItemSet()->ClearItem( SID_REFERER );
    1172           0 :         uno::Reference< frame::XModel >  xModel ( GetModel(), uno::UNO_QUERY );
    1173           0 :         if ( xModel.is() )
    1174             :         {
    1175           0 :             OUString aURL = GetMedium()->GetOrigURL();
    1176           0 :             SfxItemSet *pSet = GetMedium()->GetItemSet();
    1177           0 :             if ( !GetMedium()->IsReadOnly() )
    1178           0 :                 pSet->ClearItem( SID_INPUTSTREAM );
    1179           0 :             uno::Sequence< beans::PropertyValue > aArgs;
    1180           0 :             TransformItems( SID_OPENDOC, *pSet, aArgs );
    1181           0 :             xModel->attachResource( aURL, aArgs );
    1182           0 :             impl_addToModelCollection(xModel);
    1183             :         }
    1184             : 
    1185           0 :         pImp->bModelInitialized = true;
    1186             :     }
    1187           0 : }
    1188             : 
    1189           0 : void SfxObjectShell::FinishedLoading( sal_uInt16 nFlags )
    1190             : {
    1191           0 :     bool bSetModifiedTRUE = false;
    1192           0 :     SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, false );
    1193           0 :     if( ( nFlags & SFX_LOADED_MAINDOCUMENT ) && !(pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )
    1194           0 :         && !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ))
    1195             :     {
    1196           0 :         pImp->nFlagsInProgress |= SFX_LOADED_MAINDOCUMENT;
    1197           0 :         ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())->SetAttributes();
    1198           0 :         pImp->bImportDone = true;
    1199           0 :         if( !IsAbortingImport() )
    1200           0 :             PositionView_Impl();
    1201             : 
    1202           0 :         if ( ( GetModifyPasswordHash() || GetModifyPasswordInfo().getLength() ) && !IsModifyPasswordEntered() )
    1203           0 :             SetReadOnly();
    1204             : 
    1205             :         // Salvage
    1206           0 :         if ( pSalvageItem )
    1207           0 :             bSetModifiedTRUE = true;
    1208             : 
    1209           0 :         if ( !IsEnableSetModified() )
    1210           0 :             EnableSetModified( true );
    1211             : 
    1212           0 :         if( !bSetModifiedTRUE && IsEnableSetModified() )
    1213           0 :             SetModified( false );
    1214             : 
    1215           0 :         CheckSecurityOnLoading_Impl();
    1216             : 
    1217           0 :         bHasName = true; // the document is loaded, so the name should already available
    1218           0 :         GetTitle( SFX_TITLE_DETECT );
    1219           0 :         InitOwnModel_Impl();
    1220           0 :         pImp->nFlagsInProgress &= ~SFX_LOADED_MAINDOCUMENT;
    1221             :     }
    1222             : 
    1223           0 :     if( ( nFlags & SFX_LOADED_IMAGES ) && !(pImp->nLoadedFlags & SFX_LOADED_IMAGES )
    1224           0 :         && !(pImp->nFlagsInProgress & SFX_LOADED_IMAGES ))
    1225             :     {
    1226           0 :         pImp->nFlagsInProgress |= SFX_LOADED_IMAGES;
    1227             :         uno::Reference<document::XDocumentProperties> xDocProps(
    1228           0 :             getDocProperties());
    1229           0 :         OUString url(xDocProps->getAutoloadURL());
    1230           0 :         sal_Int32 delay(xDocProps->getAutoloadSecs());
    1231           0 :         SetAutoLoad( INetURLObject(url), delay * 1000,
    1232           0 :                      (delay > 0) || !url.isEmpty() );
    1233           0 :         if( !bSetModifiedTRUE && IsEnableSetModified() )
    1234           0 :             SetModified( false );
    1235           0 :         Invalidate( SID_SAVEASDOC );
    1236           0 :         pImp->nFlagsInProgress &= ~SFX_LOADED_IMAGES;
    1237             :     }
    1238             : 
    1239           0 :     pImp->nLoadedFlags |= nFlags;
    1240             : 
    1241           0 :     if ( !pImp->nFlagsInProgress )
    1242             :     {
    1243             :         // in case of reentrance calls the first called FinishedLoading() call on the stack
    1244             :         // should do the notification, in result the notification is done when all the FinishedLoading() calls are finished
    1245             : 
    1246           0 :         if ( bSetModifiedTRUE )
    1247           0 :             SetModified( true );
    1248             :         else
    1249           0 :             SetModified( false );
    1250             : 
    1251           0 :         if ( (pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) && (pImp->nLoadedFlags & SFX_LOADED_IMAGES ) )
    1252             :         {
    1253           0 :             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, false);
    1254           0 :             bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
    1255             : 
    1256             :             // closing the streams on loading should be under control of SFX!
    1257             :             DBG_ASSERT( pMedium->IsOpen(), "Don't close the medium when loading documents!" );
    1258             : 
    1259           0 :             if ( bTemplate )
    1260             :             {
    1261           0 :                 TemplateDisconnectionAfterLoad();
    1262             :             }
    1263             :             else
    1264             :             {
    1265             :                 // if a readonly medium has storage then it's stream is already based on temporary file
    1266           0 :                 if( !(pMedium->GetOpenMode() & STREAM_WRITE) && !pMedium->HasStorage_Impl() )
    1267             :                     // don't lock file opened read only
    1268           0 :                     pMedium->CloseInStream();
    1269             :             }
    1270             :         }
    1271             : 
    1272           0 :         SetInitialized_Impl( false );
    1273             : 
    1274             :         // Title is not available until loading has finished
    1275           0 :         Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) );
    1276           0 :         if ( pImp->nEventId )
    1277           0 :             PostActivateEvent_Impl(SfxViewFrame::GetFirst(this));
    1278             :     }
    1279           0 : }
    1280             : 
    1281             : 
    1282             : extern void SetTemplate_Impl( const OUString&, const OUString&, SfxObjectShell* );
    1283             : 
    1284           0 : void SfxObjectShell::TemplateDisconnectionAfterLoad()
    1285             : {
    1286             :     // document is created from a template
    1287             :     //TODO/LATER: should the templates always be XML docs!
    1288             : 
    1289           0 :     SfxMedium* pTmpMedium = pMedium;
    1290           0 :     if ( pTmpMedium )
    1291             :     {
    1292           0 :         OUString aName( pTmpMedium->GetName() );
    1293           0 :         SFX_ITEMSET_ARG( pTmpMedium->GetItemSet(), pTemplNamItem, SfxStringItem, SID_TEMPLATE_NAME, false);
    1294           0 :         OUString aTemplateName;
    1295           0 :         if ( pTemplNamItem )
    1296           0 :             aTemplateName = pTemplNamItem->GetValue();
    1297             :         else
    1298             :         {
    1299             :             // !TODO/LATER: what's this?!
    1300             :             // Interactiv ( DClick, Contextmenu ) no long name is included
    1301           0 :             aTemplateName = getDocProperties()->getTitle();
    1302           0 :             if ( aTemplateName.isEmpty() )
    1303             :             {
    1304           0 :                 INetURLObject aURL( aName );
    1305           0 :                 aURL.CutExtension();
    1306           0 :                 aTemplateName = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
    1307             :             }
    1308             :         }
    1309             : 
    1310             :         // set medium to noname
    1311           0 :         pTmpMedium->SetName( OUString(), true );
    1312           0 :         pTmpMedium->Init_Impl();
    1313             : 
    1314             :         // drop resource
    1315           0 :         SetNoName();
    1316           0 :         InvalidateName();
    1317             : 
    1318           0 :         if( IsPackageStorageFormat_Impl( *pTmpMedium ) )
    1319             :         {
    1320             :             // untitled document must be based on temporary storage
    1321             :             // the medium should not dispose the storage in this case
    1322           0 :             uno::Reference < embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
    1323           0 :             GetStorage()->copyToStorage( xTmpStor );
    1324             : 
    1325             :             // the medium should disconnect from the original location
    1326             :             // the storage should not be disposed since the document is still
    1327             :             // based on it, but in DoSaveCompleted it will be disposed
    1328           0 :             pTmpMedium->CanDisposeStorage_Impl( false );
    1329           0 :             pTmpMedium->Close();
    1330             : 
    1331             :             // setting the new storage the medium will be based on
    1332           0 :             pTmpMedium->SetStorage_Impl( xTmpStor );
    1333             : 
    1334           0 :             pMedium = 0;
    1335           0 :             bool ok = DoSaveCompleted( pTmpMedium );
    1336             :             assert(pMedium != 0);
    1337           0 :             if( ok )
    1338             :             {
    1339           0 :                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, false );
    1340           0 :                 bool bSalvage = pSalvageItem ? true : false;
    1341             : 
    1342           0 :                 if ( !bSalvage )
    1343             :                 {
    1344             :                     // some further initializations for templates
    1345           0 :                     SetTemplate_Impl( aName, aTemplateName, this );
    1346             :                 }
    1347             : 
    1348             :                 // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
    1349           0 :                 pTmpMedium->CanDisposeStorage_Impl( false );
    1350             :             }
    1351             :             else
    1352             :             {
    1353           0 :                 SetError( ERRCODE_IO_GENERAL, OUString( OSL_LOG_PREFIX  ) );
    1354           0 :             }
    1355             :         }
    1356             :         else
    1357             :         {
    1358             :             // some further initializations for templates
    1359           0 :             SetTemplate_Impl( aName, aTemplateName, this );
    1360           0 :             pTmpMedium->CreateTempFile( true );
    1361             :         }
    1362             : 
    1363             :         // templates are never readonly
    1364           0 :         pTmpMedium->GetItemSet()->ClearItem( SID_DOC_READONLY );
    1365           0 :         pTmpMedium->SetOpenMode( SFX_STREAM_READWRITE, true );
    1366             : 
    1367             :         // notifications about possible changes in readonly state and document info
    1368           0 :         Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
    1369             : 
    1370             :         // created untitled document can't be modified
    1371           0 :         SetModified( false );
    1372             :     }
    1373           0 : }
    1374             : 
    1375             : 
    1376             : 
    1377           0 : void SfxObjectShell::PositionView_Impl()
    1378             : {
    1379           0 :     MarkData_Impl *pMark = Get_Impl()->pMarkData;
    1380           0 :     if( pMark )
    1381             :     {
    1382           0 :         SfxViewShell* pSh = pMark->pFrame->GetViewShell();
    1383           0 :         if( !pMark->aUserData.isEmpty() )
    1384           0 :             pSh->ReadUserData( pMark->aUserData, true );
    1385           0 :         else if( !pMark->aMark.isEmpty() )
    1386           0 :             pSh->JumpToMark( pMark->aMark );
    1387           0 :         DELETEZ( Get_Impl()->pMarkData );
    1388             :     }
    1389           0 : }
    1390             : 
    1391             : 
    1392             : 
    1393           0 : bool SfxObjectShell::IsLoading() const
    1394             : /*  [Description]
    1395             : 
    1396             :     Has FinishedLoading been called?
    1397             : */
    1398             : {
    1399           0 :     return !( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT );
    1400             : }
    1401             : 
    1402             : 
    1403             : 
    1404           0 : void SfxObjectShell::CancelTransfers()
    1405             : /*  [Description]
    1406             : 
    1407             :     Here can Transfers get canceled, which were not regestered
    1408             :     by RegisterTransfer.
    1409             : */
    1410             : {
    1411           0 :     if( ( pImp->nLoadedFlags & SFX_LOADED_ALL ) != SFX_LOADED_ALL )
    1412             :     {
    1413           0 :         AbortImport();
    1414           0 :         if( IsLoading() )
    1415           0 :             FinishedLoading( SFX_LOADED_ALL );
    1416             :     }
    1417           0 : }
    1418             : 
    1419             : 
    1420             : 
    1421           0 : AutoReloadTimer_Impl::AutoReloadTimer_Impl(
    1422             :     const OUString& rURL, sal_uInt32 nTime, SfxObjectShell* pSh )
    1423           0 :     : aUrl( rURL ), pObjSh( pSh )
    1424             : {
    1425           0 :     SetTimeout( nTime );
    1426           0 : }
    1427             : 
    1428             : 
    1429             : 
    1430           0 : void AutoReloadTimer_Impl::Timeout()
    1431             : {
    1432           0 :     SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pObjSh );
    1433             : 
    1434           0 :     if ( pFrame )
    1435             :     {
    1436             :         // Not possible/meanigfull at the moment?
    1437           0 :         if ( !pObjSh->CanReload_Impl() || pObjSh->IsAutoLoadLocked() || Application::IsUICaptured() )
    1438             :         {
    1439             :             // Allow a retry
    1440           0 :             Start();
    1441           0 :             return;
    1442             :         }
    1443             : 
    1444           0 :         SfxAllItemSet aSet( SFX_APP()->GetPool() );
    1445           0 :         aSet.Put( SfxBoolItem( SID_AUTOLOAD, true ) );
    1446           0 :         if ( !aUrl.isEmpty() )
    1447           0 :             aSet.Put(  SfxStringItem( SID_FILE_NAME, aUrl ) );
    1448           0 :         if (pObjSh->HasName()) {
    1449             :             aSet.Put(
    1450           0 :                 SfxStringItem(SID_REFERER, pObjSh->GetMedium()->GetName()));
    1451             :         }
    1452           0 :         SfxRequest aReq( SID_RELOAD, 0, aSet );
    1453           0 :         pObjSh->Get_Impl()->pReloadTimer = 0;
    1454           0 :         delete this;
    1455           0 :         pFrame->ExecReload_Impl( aReq );
    1456           0 :         return;
    1457             :     }
    1458             : 
    1459           0 :     pObjSh->Get_Impl()->pReloadTimer = 0;
    1460           0 :     delete this;
    1461             : }
    1462             : 
    1463           0 : SfxModule* SfxObjectShell::GetModule() const
    1464             : {
    1465           0 :     return GetFactory().GetModule();
    1466             : }
    1467             : 
    1468           0 : ErrCode SfxObjectShell::CallBasic( const OUString& rMacro,
    1469             :     const OUString& rBasic, SbxArray* pArgs,
    1470             :     SbxValue* pRet )
    1471             : {
    1472           0 :     SfxApplication* pApp = SFX_APP();
    1473           0 :     if( pApp->GetName() != rBasic )
    1474             :     {
    1475           0 :         if ( !AdjustMacroMode( OUString() ) )
    1476           0 :             return ERRCODE_IO_ACCESSDENIED;
    1477             :     }
    1478             : 
    1479           0 :     BasicManager *pMgr = GetBasicManager();
    1480           0 :     if( pApp->GetName() == rBasic )
    1481           0 :         pMgr = pApp->GetBasicManager();
    1482           0 :     ErrCode nRet = SfxApplication::CallBasic( rMacro, pMgr, pArgs, pRet );
    1483           0 :     return nRet;
    1484             : }
    1485             : 
    1486             : namespace
    1487             : {
    1488           0 :     static bool lcl_isScriptAccessAllowed_nothrow( const Reference< XInterface >& _rxScriptContext )
    1489             :     {
    1490             :         try
    1491             :         {
    1492           0 :             Reference< XEmbeddedScripts > xScripts( _rxScriptContext, UNO_QUERY );
    1493           0 :             if ( !xScripts.is() )
    1494             :             {
    1495           0 :                 Reference< XScriptInvocationContext > xContext( _rxScriptContext, UNO_QUERY_THROW );
    1496           0 :                 xScripts.set( xContext->getScriptContainer(), UNO_SET_THROW );
    1497             :             }
    1498             : 
    1499           0 :             return xScripts->getAllowMacroExecution();
    1500             :         }
    1501           0 :         catch( const Exception& )
    1502             :         {
    1503             :             DBG_UNHANDLED_EXCEPTION();
    1504             :         }
    1505           0 :         return false;
    1506             :     }
    1507             : }
    1508             : 
    1509           0 : ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptContext, const OUString& _rScriptURL,
    1510             :     const Sequence< Any >& aParams, Any& aRet, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam, bool bRaiseError, const ::com::sun::star::uno::Any* pCaller )
    1511             : {
    1512             :     OSL_TRACE( "in CallXScript" );
    1513           0 :     ErrCode nErr = ERRCODE_NONE;
    1514             : 
    1515           0 :     bool bIsDocumentScript = ( _rScriptURL.indexOf( "location=document" ) >= 0 );
    1516             :         // TODO: we should parse the URL, and check whether there is a parameter with this name.
    1517             :         // Otherwise, we might find too much.
    1518           0 :     if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
    1519           0 :         return ERRCODE_IO_ACCESSDENIED;
    1520             : 
    1521           0 :     bool bCaughtException = false;
    1522           0 :     Any aException;
    1523             :     try
    1524             :     {
    1525             :         // obtain/create a script provider
    1526           0 :         Reference< provider::XScriptProvider > xScriptProvider;
    1527           0 :         Reference< provider::XScriptProviderSupplier > xSPS( _rxScriptContext, UNO_QUERY );
    1528           0 :         if ( xSPS.is() )
    1529           0 :             xScriptProvider.set( xSPS->getScriptProvider() );
    1530             : 
    1531           0 :         if ( !xScriptProvider.is() )
    1532             :         {
    1533             :             Reference< provider::XScriptProviderFactory > xScriptProviderFactory =
    1534           0 :                 provider::theMasterScriptProviderFactory::get( ::comphelper::getProcessComponentContext() );
    1535           0 :             xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( _rxScriptContext ) ), UNO_SET_THROW );
    1536             :         }
    1537             : 
    1538             :         // ry to protect the invocation context's undo manager (if present), just in case the script tampers with it
    1539           0 :         ::framework::DocumentUndoGuard aUndoGuard( _rxScriptContext.get() );
    1540             : 
    1541             :         // obtain the script, and execute it
    1542           0 :         Reference< provider::XScript > xScript( xScriptProvider->getScript( _rScriptURL ), UNO_QUERY_THROW );
    1543           0 :         if ( pCaller && pCaller->hasValue() )
    1544             :         {
    1545           0 :             Reference< beans::XPropertySet > xProps( xScript, uno::UNO_QUERY );
    1546           0 :             if ( xProps.is() )
    1547             :             {
    1548           0 :                 Sequence< uno::Any > aArgs( 1 );
    1549           0 :                 aArgs[ 0 ] = *pCaller;
    1550           0 :                 xProps->setPropertyValue("Caller", uno::makeAny( aArgs ) );
    1551           0 :             }
    1552             :         }
    1553           0 :         aRet = xScript->invoke( aParams, aOutParamIndex, aOutParam );
    1554             :     }
    1555           0 :     catch ( const uno::Exception& )
    1556             :     {
    1557           0 :         aException = ::cppu::getCaughtException();
    1558           0 :         bCaughtException = true;
    1559           0 :         nErr = ERRCODE_BASIC_INTERNAL_ERROR;
    1560             :     }
    1561             : 
    1562           0 :     if ( bCaughtException && bRaiseError )
    1563             :     {
    1564           0 :         boost::scoped_ptr< VclAbstractDialog > pScriptErrDlg;
    1565           0 :         SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
    1566           0 :         if ( pFact )
    1567           0 :             pScriptErrDlg.reset( pFact->CreateScriptErrorDialog( NULL, aException ) );
    1568             :         OSL_ENSURE( pScriptErrDlg.get(), "SfxObjectShell::CallXScript: no script error dialog!" );
    1569             : 
    1570           0 :         if ( pScriptErrDlg.get() )
    1571           0 :             pScriptErrDlg->Execute();
    1572             :     }
    1573             : 
    1574             :     OSL_TRACE( "leaving CallXScript" );
    1575           0 :     return nErr;
    1576             : }
    1577             : 
    1578             : // perhaps rename to CallScript once we get rid of the existing CallScript
    1579             : // and Call, CallBasic, CallStarBasic methods
    1580           0 : ErrCode SfxObjectShell::CallXScript( const OUString& rScriptURL,
    1581             :         const css::uno::Sequence< css::uno::Any >& aParams,
    1582             :         css::uno::Any& aRet,
    1583             :         css::uno::Sequence< sal_Int16 >& aOutParamIndex,
    1584             :         css::uno::Sequence< css::uno::Any >& aOutParam,
    1585             :         bool bRaiseError,
    1586             :         const css::uno::Any* pCaller )
    1587             : {
    1588           0 :     return CallXScript( GetModel(), rScriptURL, aParams, aRet, aOutParamIndex, aOutParam, bRaiseError, pCaller );
    1589             : }
    1590             : 
    1591             : 
    1592           0 : SfxFrame* SfxObjectShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ )
    1593             : {
    1594           0 :     return pSelf;
    1595             : }
    1596             : 
    1597           0 : SfxObjectShellFlags SfxObjectShell::GetFlags() const
    1598             : {
    1599           0 :     if( pImp->eFlags == SFXOBJECTSHELL_UNDEFINED )
    1600           0 :         pImp->eFlags = GetFactory().GetFlags();
    1601           0 :     return pImp->eFlags;
    1602             : }
    1603             : 
    1604           0 : void SfxHeaderAttributes_Impl::SetAttributes()
    1605             : {
    1606           0 :     bAlert = true;
    1607           0 :     SvKeyValue aPair;
    1608           0 :     for( bool bCont = xIter->GetFirst( aPair ); bCont;
    1609           0 :          bCont = xIter->GetNext( aPair ) )
    1610           0 :         SetAttribute( aPair );
    1611           0 : }
    1612             : 
    1613           0 : void SfxHeaderAttributes_Impl::SetAttribute( const SvKeyValue& rKV )
    1614             : {
    1615           0 :     OUString aValue = rKV.GetValue();
    1616           0 :     if( rKV.GetKey().equalsIgnoreAsciiCase("refresh") && !rKV.GetValue().isEmpty() )
    1617             :     {
    1618           0 :         sal_uInt32 nTime = aValue.getToken(  0, ';' ).toInt32() ;
    1619           0 :         OUString aURL = comphelper::string::strip(aValue.getToken( 1, ';' ), ' ');
    1620             :         uno::Reference<document::XDocumentProperties> xDocProps(
    1621           0 :             pDoc->getDocProperties());
    1622           0 :         if( aURL.startsWithIgnoreAsciiCase( "url=" ) )
    1623             :         {
    1624           0 :             INetURLObject aObj;
    1625           0 :             INetURLObject( pDoc->GetMedium()->GetName() ).GetNewAbsURL( aURL.copy( 4 ), &aObj );
    1626           0 :             xDocProps->setAutoloadURL(
    1627           0 :                 aObj.GetMainURL( INetURLObject::NO_DECODE ) );
    1628             :         }
    1629             :         try
    1630             :         {
    1631           0 :             xDocProps->setAutoloadSecs( nTime );
    1632             :         }
    1633           0 :         catch (lang::IllegalArgumentException &)
    1634             :         {
    1635             :             // ignore
    1636           0 :         }
    1637             :     }
    1638           0 :     else if( rKV.GetKey().equalsIgnoreAsciiCase( "expires" ) )
    1639             :     {
    1640           0 :         DateTime aDateTime( DateTime::EMPTY );
    1641           0 :         if( INetRFC822Message::ParseDateField( rKV.GetValue(), aDateTime ) )
    1642             :         {
    1643           0 :             aDateTime.ConvertToLocalTime();
    1644           0 :             pDoc->GetMedium()->SetExpired_Impl( aDateTime );
    1645             :         }
    1646             :         else
    1647             :         {
    1648           0 :             pDoc->GetMedium()->SetExpired_Impl( Date( 1, 1, 1970 ) );
    1649             :         }
    1650           0 :     }
    1651           0 : }
    1652             : 
    1653           0 : void SfxHeaderAttributes_Impl::Append( const SvKeyValue& rKV )
    1654             : {
    1655           0 :     xIter->Append( rKV );
    1656           0 :     if( bAlert ) SetAttribute( rKV );
    1657           0 : }
    1658             : 
    1659           0 : SvKeyValueIterator* SfxObjectShell::GetHeaderAttributes()
    1660             : {
    1661           0 :     if( !pImp->xHeaderAttributes.Is() )
    1662             :     {
    1663             :         DBG_ASSERT( pMedium, "No Medium" );
    1664           0 :         pImp->xHeaderAttributes = new SfxHeaderAttributes_Impl( this );
    1665             :     }
    1666           0 :     return ( SvKeyValueIterator*) &pImp->xHeaderAttributes;
    1667             : }
    1668             : 
    1669           0 : void SfxObjectShell::ClearHeaderAttributesForSourceViewHack()
    1670             : {
    1671           0 :     ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())
    1672           0 :         ->ClearForSourceView();
    1673           0 : }
    1674             : 
    1675             : 
    1676           0 : void SfxObjectShell::SetHeaderAttributesForSourceViewHack()
    1677             : {
    1678           0 :     ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())
    1679           0 :         ->SetAttributes();
    1680           0 : }
    1681             : 
    1682           0 : bool SfxObjectShell::IsPreview() const
    1683             : {
    1684           0 :     if ( !pMedium )
    1685           0 :         return false;
    1686             : 
    1687           0 :     bool bPreview = false;
    1688           0 :     SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, false);
    1689           0 :     if ( pFlags )
    1690             :     {
    1691             :         // Distributed values among individual items
    1692           0 :         OUString aFileFlags = pFlags->GetValue();
    1693           0 :         aFileFlags = aFileFlags.toAsciiUpperCase();
    1694           0 :         if ( -1 != aFileFlags.indexOf( 'B' ) )
    1695           0 :             bPreview = true;
    1696             :     }
    1697             : 
    1698           0 :     if ( !bPreview )
    1699             :     {
    1700           0 :         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pItem, SfxBoolItem, SID_PREVIEW, false);
    1701           0 :         if ( pItem )
    1702           0 :             bPreview = pItem->GetValue();
    1703             :     }
    1704             : 
    1705           0 :     return bPreview;
    1706             : }
    1707             : 
    1708           0 : void SfxObjectShell::SetWaitCursor( bool bSet ) const
    1709             : {
    1710           0 :     for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) )
    1711             :     {
    1712           0 :         if ( bSet )
    1713           0 :             pFrame->GetFrame().GetWindow().EnterWait();
    1714             :         else
    1715           0 :             pFrame->GetFrame().GetWindow().LeaveWait();
    1716             :     }
    1717           0 : }
    1718             : 
    1719           0 : OUString SfxObjectShell::GetAPIName() const
    1720             : {
    1721           0 :     INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : OUString( GetMedium()->GetName() ) );
    1722           0 :     OUString aName( aURL.GetBase() );
    1723           0 :     if( aName.isEmpty() )
    1724           0 :         aName = aURL.GetURLNoPass();
    1725           0 :     if ( aName.isEmpty() )
    1726           0 :         aName = GetTitle( SFX_TITLE_DETECT );
    1727           0 :     return aName;
    1728             : }
    1729             : 
    1730           0 : void SfxObjectShell::Invalidate( sal_uInt16 nId )
    1731             : {
    1732           0 :     for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) )
    1733           0 :         Invalidate_Impl( pFrame->GetBindings(), nId );
    1734           0 : }
    1735             : 
    1736           0 : bool SfxObjectShell::AdjustMacroMode( const OUString& /*rScriptType*/, bool bSuppressUI )
    1737             : {
    1738           0 :     uno::Reference< task::XInteractionHandler > xInteraction;
    1739           0 :     if ( pMedium && !bSuppressUI )
    1740           0 :         xInteraction = pMedium->GetInteractionHandler();
    1741             : 
    1742           0 :     CheckForBrokenDocSignatures_Impl( xInteraction );
    1743             : 
    1744           0 :     CheckEncryption_Impl( xInteraction );
    1745             : 
    1746           0 :     return pImp->aMacroMode.adjustMacroMode( xInteraction );
    1747             : }
    1748             : 
    1749           0 : Window* SfxObjectShell::GetDialogParent( SfxMedium* pLoadingMedium )
    1750             : {
    1751           0 :     Window* pWindow = 0;
    1752           0 :     SfxItemSet* pSet = pLoadingMedium ? pLoadingMedium->GetItemSet() : GetMedium()->GetItemSet();
    1753           0 :     SFX_ITEMSET_ARG( pSet, pUnoItem, SfxUnoFrameItem, SID_FILLFRAME, false );
    1754           0 :     if ( pUnoItem )
    1755             :     {
    1756           0 :         uno::Reference < frame::XFrame > xFrame( pUnoItem->GetFrame() );
    1757           0 :         pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
    1758             :     }
    1759             : 
    1760           0 :     if ( !pWindow )
    1761             :     {
    1762           0 :         SfxFrame* pFrame = 0;
    1763           0 :         SFX_ITEMSET_ARG( pSet, pFrameItem, SfxFrameItem, SID_DOCFRAME, false );
    1764           0 :         if( pFrameItem && pFrameItem->GetFrame() )
    1765             :             // get target frame from ItemSet
    1766           0 :             pFrame = pFrameItem->GetFrame();
    1767             :         else
    1768             :         {
    1769             :             // try the current frame
    1770           0 :             SfxViewFrame* pView = SfxViewFrame::Current();
    1771           0 :             if ( !pView || pView->GetObjectShell() != this )
    1772             :                 // get any visible frame
    1773           0 :                 pView = SfxViewFrame::GetFirst(this);
    1774           0 :             if ( pView )
    1775           0 :                 pFrame = &pView->GetFrame();
    1776             :         }
    1777             : 
    1778           0 :         if ( pFrame )
    1779             :             // get topmost window
    1780           0 :             pWindow = VCLUnoHelper::GetWindow( pFrame->GetFrameInterface()->getContainerWindow() );
    1781             :     }
    1782             : 
    1783           0 :     if ( pWindow )
    1784             :     {
    1785             :         // this frame may be invisible, show it if it is allowed
    1786           0 :         SFX_ITEMSET_ARG( pSet, pHiddenItem, SfxBoolItem, SID_HIDDEN, false );
    1787           0 :         if ( !pHiddenItem || !pHiddenItem->GetValue() )
    1788             :         {
    1789           0 :             pWindow->Show();
    1790           0 :             pWindow->ToTop();
    1791             :         }
    1792             :     }
    1793             : 
    1794           0 :     return pWindow;
    1795             : }
    1796             : 
    1797           0 : void SfxObjectShell::SetCreateMode_Impl( SfxObjectCreateMode nMode )
    1798             : {
    1799           0 :     eCreateMode = nMode;
    1800           0 : }
    1801             : 
    1802           0 : bool SfxObjectShell::IsInPlaceActive()
    1803             : {
    1804           0 :     if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED )
    1805           0 :         return false;
    1806             : 
    1807           0 :     SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
    1808           0 :     return pFrame && pFrame->GetFrame().IsInPlace();
    1809             : }
    1810             : 
    1811           0 : bool SfxObjectShell::IsUIActive()
    1812             : {
    1813           0 :     if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED )
    1814           0 :         return false;
    1815             : 
    1816           0 :     SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
    1817           0 :     return pFrame && pFrame->GetFrame().IsInPlace() && pFrame->GetFrame().GetWorkWindow_Impl()->IsVisible_Impl();
    1818             : }
    1819             : 
    1820           0 : void SfxObjectShell::UIActivate( bool )
    1821             : {
    1822           0 : }
    1823             : 
    1824           0 : void SfxObjectShell::InPlaceActivate( bool )
    1825             : {
    1826           0 : }
    1827             : 
    1828           0 : bool SfxObjectShell::UseInteractionToHandleError(
    1829             :                     const uno::Reference< task::XInteractionHandler >& xHandler,
    1830             :                     sal_uInt32 nError )
    1831             : {
    1832           0 :     bool bResult = false;
    1833             : 
    1834           0 :     if ( xHandler.is() )
    1835             :     {
    1836             :         try
    1837             :         {
    1838           0 :             uno::Any aInteraction;
    1839           0 :             uno::Sequence< uno::Reference< task::XInteractionContinuation > > lContinuations(2);
    1840           0 :             ::comphelper::OInteractionAbort* pAbort = new ::comphelper::OInteractionAbort();
    1841           0 :             ::comphelper::OInteractionApprove* pApprove = new ::comphelper::OInteractionApprove();
    1842           0 :             lContinuations[0] = uno::Reference< task::XInteractionContinuation >(
    1843           0 :                                  static_cast< task::XInteractionContinuation* >( pAbort ), uno::UNO_QUERY );
    1844           0 :             lContinuations[1] = uno::Reference< task::XInteractionContinuation >(
    1845           0 :                                  static_cast< task::XInteractionContinuation* >( pApprove ), uno::UNO_QUERY );
    1846             : 
    1847           0 :             task::ErrorCodeRequest aErrorCode;
    1848           0 :             aErrorCode.ErrCode = nError;
    1849           0 :             aInteraction <<= aErrorCode;
    1850           0 :             xHandler->handle(::framework::InteractionRequest::CreateRequest (aInteraction,lContinuations));
    1851           0 :             bResult = pAbort->wasSelected();
    1852             :         }
    1853           0 :         catch( uno::Exception& )
    1854             :         {}
    1855             :     }
    1856             : 
    1857           0 :     return bResult;
    1858             : }
    1859             : 
    1860           0 : sal_Int16 SfxObjectShell_Impl::getCurrentMacroExecMode() const
    1861             : {
    1862           0 :     sal_Int16 nImposedExecMode( MacroExecMode::NEVER_EXECUTE );
    1863             : 
    1864           0 :     const SfxMedium* pMedium( rDocShell.GetMedium() );
    1865             :     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
    1866           0 :     if ( pMedium )
    1867             :     {
    1868           0 :         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pMacroModeItem, SfxUInt16Item, SID_MACROEXECMODE, false);
    1869           0 :         if ( pMacroModeItem )
    1870           0 :             nImposedExecMode = pMacroModeItem->GetValue();
    1871             :     }
    1872           0 :     return nImposedExecMode;
    1873             : }
    1874             : 
    1875           0 : bool SfxObjectShell_Impl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
    1876             : {
    1877           0 :     const SfxMedium* pMedium( rDocShell.GetMedium() );
    1878             :     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
    1879           0 :     if ( pMedium )
    1880             :     {
    1881           0 :         pMedium->GetItemSet()->Put( SfxUInt16Item( SID_MACROEXECMODE, nMacroMode ) );
    1882           0 :         return true;
    1883             :     }
    1884             : 
    1885           0 :     return false;
    1886             : }
    1887             : 
    1888           0 : OUString SfxObjectShell_Impl::getDocumentLocation() const
    1889             : {
    1890           0 :     OUString sLocation;
    1891             : 
    1892           0 :     const SfxMedium* pMedium( rDocShell.GetMedium() );
    1893             :     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getDocumentLocation: no medium!" );
    1894           0 :     if ( pMedium )
    1895             :     {
    1896           0 :         sLocation = pMedium->GetName();
    1897           0 :         if ( sLocation.isEmpty() )
    1898             :         {
    1899             :             // for documents made from a template: get the name of the template
    1900           0 :             sLocation = rDocShell.getDocProperties()->getTemplateURL();
    1901             :         }
    1902             :     }
    1903           0 :     return sLocation;
    1904             : }
    1905             : 
    1906           0 : uno::Reference< embed::XStorage > SfxObjectShell_Impl::getZipStorageToSign()
    1907             : {
    1908           0 :     Reference < embed::XStorage > xStore;
    1909             : 
    1910           0 :     SfxMedium* pMedium( rDocShell.GetMedium() );
    1911             :     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getLastCommitDocumentStorage: no medium!" );
    1912           0 :     if ( pMedium )
    1913           0 :         xStore = pMedium->GetZipStorageToSign_Impl();
    1914             : 
    1915           0 :     return xStore;
    1916             : }
    1917             : 
    1918           0 : bool SfxObjectShell_Impl::documentStorageHasMacros() const
    1919             : {
    1920           0 :     return ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocStorage );
    1921             : }
    1922             : 
    1923           0 : Reference< XEmbeddedScripts > SfxObjectShell_Impl::getEmbeddedDocumentScripts() const
    1924             : {
    1925           0 :     return Reference< XEmbeddedScripts >( rDocShell.GetModel(), UNO_QUERY );
    1926             : }
    1927             : 
    1928           0 : sal_Int16 SfxObjectShell_Impl::getScriptingSignatureState()
    1929             : {
    1930           0 :     sal_Int16 nSignatureState( rDocShell.GetScriptingSignatureState() );
    1931             : 
    1932           0 :     if ( nSignatureState != SIGNATURESTATE_NOSIGNATURES && m_bMacroSignBroken )
    1933             :     {
    1934             :         // if there is a macro signature it must be handled as broken
    1935           0 :         nSignatureState = SIGNATURESTATE_SIGNATURES_BROKEN;
    1936             :     }
    1937             : 
    1938           0 :     return nSignatureState;
    1939             : }
    1940             : 
    1941           0 : bool SfxObjectShell_Impl::hasTrustedScriptingSignature( bool bAllowUIToAddAuthor )
    1942             : {
    1943           0 :     bool bResult = false;
    1944             : 
    1945             :     try
    1946             :     {
    1947           0 :         OUString aVersion;
    1948             :         try
    1949             :         {
    1950           0 :             uno::Reference < beans::XPropertySet > xPropSet( rDocShell.GetStorage(), uno::UNO_QUERY_THROW );
    1951           0 :             xPropSet->getPropertyValue("Version") >>= aVersion;
    1952             :         }
    1953           0 :         catch( uno::Exception& )
    1954             :         {
    1955             :         }
    1956             : 
    1957           0 :         uno::Reference< security::XDocumentDigitalSignatures > xSigner( security::DocumentDigitalSignatures::createWithVersion(comphelper::getProcessComponentContext(), aVersion) );
    1958             : 
    1959           0 :         if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN
    1960           0 :           || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
    1961           0 :           || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
    1962             :         {
    1963           0 :             uno::Sequence< security::DocumentSignatureInformation > aInfo = rDocShell.ImplAnalyzeSignature( true, xSigner );
    1964             : 
    1965           0 :             if ( aInfo.getLength() )
    1966             :             {
    1967           0 :                 if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN )
    1968           0 :                     nScriptingSignatureState = rDocShell.ImplCheckSignaturesInformation( aInfo );
    1969             : 
    1970           0 :                 if ( nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
    1971           0 :                   || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
    1972             :                 {
    1973           0 :                     for ( sal_Int32 nInd = 0; !bResult && nInd < aInfo.getLength(); nInd++ )
    1974             :                     {
    1975           0 :                         bResult = xSigner->isAuthorTrusted( aInfo[nInd].Signer );
    1976             :                     }
    1977             : 
    1978           0 :                     if ( !bResult && bAllowUIToAddAuthor )
    1979             :                     {
    1980           0 :                         uno::Reference< task::XInteractionHandler > xInteraction;
    1981           0 :                         if ( rDocShell.GetMedium() )
    1982           0 :                             xInteraction = rDocShell.GetMedium()->GetInteractionHandler();
    1983             : 
    1984           0 :                         if ( xInteraction.is() )
    1985             :                         {
    1986           0 :                             task::DocumentMacroConfirmationRequest aRequest;
    1987           0 :                             aRequest.DocumentURL = getDocumentLocation();
    1988           0 :                             aRequest.DocumentStorage = rDocShell.GetMedium()->GetZipStorageToSign_Impl();
    1989           0 :                             aRequest.DocumentSignatureInformation = aInfo;
    1990           0 :                             aRequest.DocumentVersion = aVersion;
    1991           0 :                             aRequest.Classification = task::InteractionClassification_QUERY;
    1992           0 :                             bResult = SfxMedium::CallApproveHandler( xInteraction, uno::makeAny( aRequest ), true );
    1993           0 :                         }
    1994             :                     }
    1995             :                 }
    1996           0 :             }
    1997           0 :         }
    1998             :     }
    1999           0 :     catch( uno::Exception& )
    2000             :     {}
    2001             : 
    2002           0 :     return bResult;
    2003             : }
    2004             : 
    2005           0 : void SfxObjectShell_Impl::showBrokenSignatureWarning( const uno::Reference< task::XInteractionHandler >& _rxInteraction ) const
    2006             : {
    2007           0 :     if  ( !bSignatureErrorIsShown )
    2008             :     {
    2009           0 :         SfxObjectShell::UseInteractionToHandleError( _rxInteraction, ERRCODE_SFX_BROKENSIGNATURE );
    2010           0 :         const_cast< SfxObjectShell_Impl* >( this )->bSignatureErrorIsShown = true;
    2011             :     }
    2012           0 : }
    2013             : 
    2014           0 : void SfxObjectShell::AddLog( const OUString& aMessage )
    2015             : {
    2016           0 :     if ( !pImp->m_xLogRing.is() )
    2017             :     {
    2018             :         try
    2019             :         {
    2020           0 :             Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
    2021           0 :             pImp->m_xLogRing.set( logging::DocumentIOLogRing::get(xContext) );
    2022             :         }
    2023           0 :         catch( uno::Exception& )
    2024             :         {}
    2025             :     }
    2026             : 
    2027           0 :     if ( pImp->m_xLogRing.is() )
    2028           0 :         pImp->m_xLogRing->logString( aMessage );
    2029           0 : }
    2030             : 
    2031             : namespace {
    2032             : 
    2033           0 : void WriteStringInStream( const uno::Reference< io::XOutputStream >& xOutStream, const OUString& aString )
    2034             : {
    2035           0 :     if ( xOutStream.is() )
    2036             :     {
    2037           0 :         OString aStrLog = OUStringToOString( aString, RTL_TEXTENCODING_UTF8 );
    2038           0 :         uno::Sequence< sal_Int8 > aLogData( (const sal_Int8*)aStrLog.getStr(), aStrLog.getLength() );
    2039           0 :         xOutStream->writeBytes( aLogData );
    2040             : 
    2041           0 :         aLogData.realloc( 1 );
    2042           0 :         aLogData[0] = '\n';
    2043           0 :         xOutStream->writeBytes( aLogData );
    2044             :     }
    2045           0 : }
    2046             : 
    2047             : }
    2048             : 
    2049           0 : void SfxObjectShell::StoreLog()
    2050             : {
    2051           0 :     if ( !pImp->m_xLogRing.is() )
    2052             :     {
    2053             :         try
    2054             :         {
    2055           0 :             Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
    2056           0 :             pImp->m_xLogRing.set( logging::DocumentIOLogRing::get(xContext) );
    2057             :         }
    2058           0 :         catch( uno::Exception& )
    2059             :         {}
    2060             :     }
    2061             : 
    2062           0 :     if ( pImp->m_xLogRing.is() )
    2063             :     {
    2064           0 :         OUString aFileURL = ( "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}"  );
    2065             : 
    2066           0 :         ::rtl::Bootstrap::expandMacros( aFileURL );
    2067             : 
    2068           0 :         OUString aBuildID = ( "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("setup") ":buildid}"  );
    2069             : 
    2070           0 :         ::rtl::Bootstrap::expandMacros( aBuildID );
    2071             : 
    2072           0 :         if ( !aFileURL.isEmpty() )
    2073             :         {
    2074           0 :             aFileURL += "/user/temp/document_io_logring.txt";
    2075             :             try
    2076             :             {
    2077           0 :                 uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
    2078           0 :                 uno::Reference< ucb::XSimpleFileAccess3 > xSimpleFileAccess(ucb::SimpleFileAccess::create(xContext));
    2079           0 :                 uno::Reference< io::XStream > xStream( xSimpleFileAccess->openFileReadWrite( aFileURL ), uno::UNO_SET_THROW );
    2080           0 :                 uno::Reference< io::XOutputStream > xOutStream( xStream->getOutputStream(), uno::UNO_SET_THROW );
    2081           0 :                 uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY_THROW );
    2082           0 :                 xTruncate->truncate();
    2083             : 
    2084           0 :                 if ( !aBuildID.isEmpty() )
    2085           0 :                     WriteStringInStream( xOutStream, aBuildID );
    2086             : 
    2087           0 :                 uno::Sequence< OUString > aLogSeq = pImp->m_xLogRing->getCollectedLog();
    2088           0 :                 for ( sal_Int32 nInd = 0; nInd < aLogSeq.getLength(); nInd++ )
    2089           0 :                     WriteStringInStream( xOutStream, aLogSeq[nInd] );
    2090             :             }
    2091           0 :             catch( uno::Exception& )
    2092             :             {}
    2093           0 :         }
    2094             :     }
    2095           3 : }
    2096             : 
    2097             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10