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

Generated by: LCOV version 1.11