LCOV - code coverage report
Current view: top level - sfx2/source/appl - appopen.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 27 518 5.2 %
Date: 2015-06-13 12:38:46 Functions: 4 14 28.6 %
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 <com/sun/star/uno/Reference.h>
      21             : #include <com/sun/star/beans/PropertyValue.hpp>
      22             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      23             : #include <com/sun/star/frame/XComponentLoader.hpp>
      24             : #include <com/sun/star/frame/XNotifyingDispatch.hpp>
      25             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      26             : #include <com/sun/star/util/XCloseable.hpp>
      27             : #include <com/sun/star/frame/XFrame.hpp>
      28             : #include <com/sun/star/frame/Desktop.hpp>
      29             : #include <com/sun/star/frame/DispatchResultState.hpp>
      30             : #include <com/sun/star/frame/XDispatchResultListener.hpp>
      31             : #include <com/sun/star/util/URL.hpp>
      32             : #include <com/sun/star/util/URLTransformer.hpp>
      33             : #include <com/sun/star/util/XURLTransformer.hpp>
      34             : #include <com/sun/star/system/SystemShellExecuteException.hpp>
      35             : #include <com/sun/star/document/XTypeDetection.hpp>
      36             : #include <com/sun/star/document/MacroExecMode.hpp>
      37             : #include <com/sun/star/document/UpdateDocMode.hpp>
      38             : #include <com/sun/star/task/ErrorCodeRequest.hpp>
      39             : #include <com/sun/star/task/InteractionHandler.hpp>
      40             : #include <com/sun/star/beans/XPropertySet.hpp>
      41             : #include <com/sun/star/embed/ElementModes.hpp>
      42             : #include <com/sun/star/container/XNameAccess.hpp>
      43             : #include <com/sun/star/uno/Sequence.h>
      44             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      45             : #include <cppuhelper/implbase1.hxx>
      46             : #include <rtl/ustring.hxx>
      47             : 
      48             : #include <comphelper/processfactory.hxx>
      49             : #include <comphelper/storagehelper.hxx>
      50             : #include <comphelper/string.hxx>
      51             : #include <comphelper/synchronousdispatch.hxx>
      52             : 
      53             : #include <vcl/wrkwin.hxx>
      54             : #include <svl/intitem.hxx>
      55             : #include <vcl/layout.hxx>
      56             : #include <svl/stritem.hxx>
      57             : #include <svl/eitem.hxx>
      58             : #include <sfx2/doctempl.hxx>
      59             : #include <svtools/sfxecode.hxx>
      60             : #include <framework/preventduplicateinteraction.hxx>
      61             : #include <svtools/ehdl.hxx>
      62             : #include <basic/sbxobj.hxx>
      63             : #include <svl/urihelper.hxx>
      64             : #include <unotools/localfilehelper.hxx>
      65             : #include <unotools/pathoptions.hxx>
      66             : #include <unotools/moduleoptions.hxx>
      67             : #include <svtools/miscopt.hxx>
      68             : #include <osl/file.hxx>
      69             : #include <unotools/extendedsecurityoptions.hxx>
      70             : #include <comphelper/docpasswordhelper.hxx>
      71             : #include <vcl/svapp.hxx>
      72             : 
      73             : #include <osl/mutex.hxx>
      74             : 
      75             : 
      76             : #include <sfx2/app.hxx>
      77             : #include <sfx2/bindings.hxx>
      78             : #include <sfx2/dispatch.hxx>
      79             : #include <sfx2/docfile.hxx>
      80             : #include <sfx2/fcontnr.hxx>
      81             : #include <sfx2/new.hxx>
      82             : #include <sfx2/objitem.hxx>
      83             : #include <sfx2/objsh.hxx>
      84             : #include <svl/slstitm.hxx>
      85             : #include "appopen.hxx"
      86             : #include "objshimp.hxx"
      87             : #include "openflag.hxx"
      88             : #include <sfx2/passwd.hxx>
      89             : #include <sfx2/request.hxx>
      90             : #include <sfx2/sfxresid.hxx>
      91             : #include <sfx2/viewsh.hxx>
      92             : #include "app.hrc"
      93             : #include <sfx2/viewfrm.hxx>
      94             : #include <sfx2/sfxuno.hxx>
      95             : #include <sfx2/objface.hxx>
      96             : #include <sfx2/filedlghelper.hxx>
      97             : #include <sfx2/docfac.hxx>
      98             : #include <sfx2/event.hxx>
      99             : #include <sfx2/templatedlg.hxx>
     100             : #include "openuriexternally.hxx"
     101             : 
     102             : #include <officecfg/Office/ProtocolHandler.hxx>
     103             : 
     104             : using namespace ::com::sun::star;
     105             : using namespace ::com::sun::star::beans;
     106             : using namespace ::com::sun::star::frame;
     107             : using namespace ::com::sun::star::lang;
     108             : using namespace ::com::sun::star::uno;
     109             : using namespace ::com::sun::star::util;
     110             : using namespace ::com::sun::star::task;
     111             : using namespace ::com::sun::star::container;
     112             : using namespace ::cppu;
     113             : using namespace ::sfx2;
     114             : 
     115          49 : void SetTemplate_Impl( const OUString &rFileName,
     116             :                         const OUString &rLongName,
     117             :                         SfxObjectShell *pDoc)
     118             : {
     119             :     // write TemplateName to DocumentProperties of document
     120             :     // TemplateDate stays as default (=current date)
     121          49 :     pDoc->ResetFromTemplate( rLongName, rFileName );
     122          49 : }
     123             : 
     124             : 
     125           0 : class SfxDocPasswordVerifier : public ::comphelper::IDocPasswordVerifier
     126             : {
     127             : public:
     128           0 :     inline explicit     SfxDocPasswordVerifier( const Reference< embed::XStorage >& rxStorage ) :
     129           0 :                             mxStorage( rxStorage ) {}
     130             : 
     131             :     virtual ::comphelper::DocPasswordVerifierResult
     132             :                         verifyPassword( const OUString& rPassword, uno::Sequence< beans::NamedValue >& o_rEncryptionData ) SAL_OVERRIDE;
     133             :     virtual ::comphelper::DocPasswordVerifierResult
     134             :                         verifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData ) SAL_OVERRIDE;
     135             : 
     136             : 
     137             : private:
     138             :     Reference< embed::XStorage > mxStorage;
     139             : };
     140             : 
     141             : 
     142           0 : ::comphelper::DocPasswordVerifierResult SfxDocPasswordVerifier::verifyPassword( const OUString& rPassword, uno::Sequence< beans::NamedValue >& o_rEncryptionData )
     143             : {
     144           0 :     o_rEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( rPassword );
     145           0 :     return verifyEncryptionData( o_rEncryptionData );
     146             : }
     147             : 
     148             : 
     149             : 
     150           0 : ::comphelper::DocPasswordVerifierResult SfxDocPasswordVerifier::verifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData )
     151             : {
     152           0 :     ::comphelper::DocPasswordVerifierResult eResult = ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD;
     153             :     try
     154             :     {
     155             :         // check the encryption data
     156             :         // if the data correct is the stream will be opened successfully
     157             :         // and immediatelly closed
     158           0 :         ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( mxStorage, rEncryptionData );
     159             : 
     160           0 :         mxStorage->openStreamElement(
     161             :                 OUString( "content.xml"  ),
     162           0 :                 embed::ElementModes::READ | embed::ElementModes::NOCREATE );
     163             : 
     164             :         // no exception -> success
     165           0 :         eResult = ::comphelper::DocPasswordVerifierResult_OK;
     166             :     }
     167           0 :     catch( const packages::WrongPasswordException& )
     168             :     {
     169           0 :         eResult = ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD;
     170             :     }
     171           0 :     catch( const uno::Exception& )
     172             :     {
     173             :         // unknown error, report it as wrong password
     174             :         // TODO/LATER: we need an additional way to report unknown problems in this case
     175           0 :         eResult = ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD;
     176             :     }
     177           0 :     return eResult;
     178             : }
     179             : 
     180             : 
     181             : 
     182             : 
     183             : 
     184         496 : sal_uInt32 CheckPasswd_Impl
     185             : (
     186             :     SfxObjectShell*  pDoc,
     187             :     SfxItemPool&     /*rPool*/, // Pool, if a Set has to be created
     188             :     SfxMedium*       pFile      // the Medium and its Password shold be obtained
     189             : )
     190             : 
     191             : /*  [Description]
     192             : 
     193             :     Ask for the password for a medium, only works if it concerns storage.
     194             :     If the password flag is set in the Document Info, then the password is
     195             :     requested through a user dialogue and the set at the Set of the medium.
     196             :     If the set does not exist the it is created.
     197             : */
     198             : {
     199         496 :     sal_uIntPtr nRet = ERRCODE_NONE;
     200             : 
     201         496 :     if( ( !pFile->GetFilter() || pFile->IsStorage() ) )
     202             :     {
     203         496 :         uno::Reference< embed::XStorage > xStorage = pFile->GetStorage( true );
     204         496 :         if( xStorage.is() )
     205             :         {
     206         496 :             uno::Reference< beans::XPropertySet > xStorageProps( xStorage, uno::UNO_QUERY );
     207         496 :             if ( xStorageProps.is() )
     208             :             {
     209         496 :                 bool bIsEncrypted = false;
     210             :                 try {
     211         496 :                     xStorageProps->getPropertyValue("HasEncryptedEntries")
     212         500 :                         >>= bIsEncrypted;
     213           4 :                 } catch( uno::Exception& )
     214             :                 {
     215             :                     // TODO/LATER:
     216             :                     // the storage either has no encrypted elements or it's just
     217             :                     // does not allow to detect it, probably it should be implemented laiter
     218             :                 }
     219             : 
     220         496 :                 if ( bIsEncrypted )
     221             :                 {
     222           4 :                     vcl::Window* pWin = pDoc ? pDoc->GetDialogParent( pFile ) : NULL;
     223           4 :                     if ( pWin )
     224           0 :                         pWin->Show();
     225             : 
     226           4 :                     nRet = ERRCODE_SFX_CANTGETPASSWD;
     227             : 
     228           4 :                     SfxItemSet *pSet = pFile->GetItemSet();
     229           4 :                     if( pSet )
     230             :                     {
     231           4 :                         Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = pFile->GetInteractionHandler();
     232           4 :                         if( xInteractionHandler.is() )
     233             :                         {
     234             :                             // use the comphelper password helper to request a password
     235           0 :                             OUString aPassword;
     236           0 :                             SFX_ITEMSET_ARG( pSet, pPasswordItem, SfxStringItem, SID_PASSWORD, false);
     237           0 :                             if ( pPasswordItem )
     238           0 :                                 aPassword = pPasswordItem->GetValue();
     239             : 
     240           0 :                             uno::Sequence< beans::NamedValue > aEncryptionData;
     241           0 :                             SFX_ITEMSET_ARG( pSet, pEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, false);
     242           0 :                             if ( pEncryptionDataItem )
     243           0 :                                 pEncryptionDataItem->GetValue() >>= aEncryptionData;
     244             : 
     245           0 :                             OUString aDocumentName = INetURLObject( pFile->GetOrigURL() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
     246             : 
     247           0 :                             SfxDocPasswordVerifier aVerifier( xStorage );
     248           0 :                             aEncryptionData = ::comphelper::DocPasswordHelper::requestAndVerifyDocPassword(
     249           0 :                                 aVerifier, aEncryptionData, aPassword, xInteractionHandler, aDocumentName, comphelper::DocPasswordRequestType_STANDARD );
     250             : 
     251           0 :                             pSet->ClearItem( SID_PASSWORD );
     252           0 :                             pSet->ClearItem( SID_ENCRYPTIONDATA );
     253             : 
     254           0 :                             if ( aEncryptionData.getLength() > 0 )
     255             :                             {
     256           0 :                                 pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aEncryptionData ) ) );
     257             : 
     258             :                                 try
     259             :                                 {
     260             :                                     // update the version list of the medium using the new password
     261           0 :                                     pFile->GetVersionList();
     262             :                                 }
     263           0 :                                 catch( uno::Exception& )
     264             :                                 {
     265             :                                     // TODO/LATER: set the error code
     266             :                                 }
     267             : 
     268           0 :                                 nRet = ERRCODE_NONE;
     269             :                             }
     270             :                             else
     271           0 :                                 nRet = ERRCODE_IO_ABORT;
     272           4 :                         }
     273             :                     }
     274             :                 }
     275             :             }
     276             :             else
     277             :             {
     278             :                 OSL_FAIL( "A storage must implement XPropertySet interface!" );
     279           0 :                 nRet = ERRCODE_SFX_CANTGETPASSWD;
     280         496 :             }
     281         496 :         }
     282             :     }
     283             : 
     284         496 :     return nRet;
     285             : }
     286             : 
     287             : 
     288             : 
     289             : 
     290           0 : sal_uIntPtr SfxApplication::LoadTemplate( SfxObjectShellLock& xDoc, const OUString &rFileName, bool bCopy, SfxItemSet* pSet )
     291             : {
     292           0 :     const SfxFilter* pFilter = NULL;
     293           0 :     SfxMedium aMedium( rFileName,  ( StreamMode::READ | StreamMode::SHARE_DENYNONE ) );
     294             : 
     295           0 :     if ( !aMedium.GetStorage( false ).is() )
     296           0 :         aMedium.GetInStream();
     297             : 
     298           0 :     if ( aMedium.GetError() )
     299             :     {
     300           0 :         delete pSet;
     301           0 :         return aMedium.GetErrorCode();
     302             :     }
     303             : 
     304           0 :     aMedium.UseInteractionHandler( true );
     305           0 :     sal_uIntPtr nErr = GetFilterMatcher().GuessFilter( aMedium,&pFilter,SfxFilterFlags::TEMPLATE, SfxFilterFlags::NONE );
     306           0 :     if ( 0 != nErr)
     307             :     {
     308           0 :         delete pSet;
     309           0 :         return ERRCODE_SFX_NOTATEMPLATE;
     310             :     }
     311             : 
     312           0 :     if( !pFilter || !pFilter->IsAllowedAsTemplate() )
     313             :     {
     314           0 :         delete pSet;
     315           0 :         return ERRCODE_SFX_NOTATEMPLATE;
     316             :     }
     317             : 
     318           0 :     if ( pFilter->GetFilterFlags() & SfxFilterFlags::STARONEFILTER )
     319             :     {
     320             :         DBG_ASSERT( !xDoc.Is(), "Sorry, not implemented!" );
     321           0 :         delete pSet;
     322           0 :         SfxStringItem aName( SID_FILE_NAME, rFileName );
     323           0 :         SfxStringItem aReferer( SID_REFERER, OUString("private:user") );
     324           0 :         SfxStringItem aFlags( SID_OPTIONS, OUString("T") );
     325           0 :         SfxBoolItem aHidden( SID_HIDDEN, true );
     326           0 :         const SfxPoolItem *pRet = GetDispatcher_Impl()->Execute( SID_OPENDOC, SfxCallMode::SYNCHRON, &aName, &aHidden, &aReferer, &aFlags, 0L );
     327           0 :         const SfxObjectItem *pObj = PTR_CAST( SfxObjectItem, pRet );
     328           0 :         if ( pObj )
     329           0 :             xDoc = PTR_CAST( SfxObjectShell, pObj->GetShell() );
     330             :         else
     331             :         {
     332           0 :             const SfxViewFrameItem *pView = PTR_CAST( SfxViewFrameItem, pRet );
     333           0 :             if ( pView )
     334             :             {
     335           0 :                 SfxViewFrame *pFrame = pView->GetFrame();
     336           0 :                 if ( pFrame )
     337           0 :                     xDoc = pFrame->GetObjectShell();
     338             :             }
     339             :         }
     340             : 
     341           0 :         if ( !xDoc.Is() )
     342           0 :             return ERRCODE_SFX_DOLOADFAILED;
     343             :     }
     344             :     else
     345             :     {
     346           0 :         if ( !xDoc.Is() )
     347           0 :             xDoc = SfxObjectShell::CreateObject( pFilter->GetServiceName() );
     348             : 
     349             :         //pMedium takes ownership of pSet
     350           0 :         SfxMedium *pMedium = new SfxMedium( rFileName, STREAM_STD_READ, pFilter, pSet );
     351           0 :         if(!xDoc->DoLoad(pMedium))
     352             :         {
     353           0 :             ErrCode nErrCode = xDoc->GetErrorCode();
     354           0 :             xDoc->DoClose();
     355           0 :             xDoc.Clear();
     356           0 :             return nErrCode;
     357             :         }
     358             :     }
     359             : 
     360           0 :     if( bCopy )
     361             :     {
     362             :         try
     363             :         {
     364             :             // TODO: introduce error handling
     365             : 
     366           0 :             uno::Reference< embed::XStorage > xTempStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
     367           0 :             if( !xTempStorage.is() )
     368           0 :                 throw uno::RuntimeException();
     369             : 
     370           0 :                xDoc->GetStorage()->copyToStorage( xTempStorage );
     371             : 
     372           0 :             if ( !xDoc->DoSaveCompleted( new SfxMedium( xTempStorage, OUString() ) ) )
     373           0 :                 throw uno::RuntimeException();
     374             :         }
     375           0 :         catch( uno::Exception& )
     376             :         {
     377           0 :             xDoc->DoClose();
     378           0 :             xDoc.Clear();
     379             : 
     380             :             // TODO: transfer correct error outside
     381           0 :             return ERRCODE_SFX_GENERAL;
     382             :         }
     383             : 
     384           0 :         SetTemplate_Impl( rFileName, OUString(), xDoc );
     385             :     }
     386             :     else
     387           0 :         SetTemplate_Impl( rFileName, OUString(), xDoc );
     388             : 
     389           0 :     xDoc->SetNoName();
     390           0 :     xDoc->InvalidateName();
     391           0 :     xDoc->SetModified(false);
     392           0 :     xDoc->ResetError();
     393             : 
     394           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >  xModel ( xDoc->GetModel(), ::com::sun::star::uno::UNO_QUERY );
     395           0 :     if ( xModel.is() )
     396             :     {
     397           0 :         SfxItemSet* pNew = xDoc->GetMedium()->GetItemSet()->Clone();
     398           0 :         pNew->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
     399           0 :         pNew->ClearItem( SID_FILTER_NAME );
     400           0 :         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
     401           0 :         TransformItems( SID_OPENDOC, *pNew, aArgs );
     402           0 :         sal_Int32 nLength = aArgs.getLength();
     403           0 :         aArgs.realloc( nLength + 1 );
     404           0 :         aArgs[nLength].Name = "Title";
     405           0 :         aArgs[nLength].Value <<= OUString( xDoc->GetTitle( SFX_TITLE_DETECT ) );
     406           0 :         xModel->attachResource( OUString(), aArgs );
     407           0 :         delete pNew;
     408             :     }
     409             : 
     410           0 :     return xDoc->GetErrorCode();
     411             : }
     412             : 
     413             : 
     414             : 
     415           0 : void SfxApplication::NewDocDirectExec_Impl( SfxRequest& rReq )
     416             : {
     417           0 :     SFX_REQUEST_ARG( rReq, pFactoryItem, SfxStringItem, SID_NEWDOCDIRECT, false);
     418           0 :     OUString aFactName;
     419           0 :     if ( pFactoryItem )
     420           0 :         aFactName = pFactoryItem->GetValue();
     421             :    else
     422           0 :         aFactName = SvtModuleOptions().GetDefaultModuleName();
     423             : 
     424             : 
     425           0 :     SfxRequest aReq( SID_OPENDOC, SfxCallMode::SYNCHRON, GetPool() );
     426           0 :     OUString aFact("private:factory/");
     427           0 :     aFact += aFactName;
     428           0 :     aReq.AppendItem( SfxStringItem( SID_FILE_NAME, aFact ) );
     429           0 :     aReq.AppendItem( SfxFrameItem( SID_DOCFRAME, GetFrame() ) );
     430           0 :     aReq.AppendItem( SfxStringItem( SID_TARGETNAME, OUString( "_default" ) ) );
     431             : 
     432             :     // TODO/LATER: Should the other arguments be transferred as well?
     433           0 :     SFX_REQUEST_ARG( rReq, pDefaultPathItem, SfxStringItem, SID_DEFAULTFILEPATH, false);
     434           0 :     if ( pDefaultPathItem )
     435           0 :         aReq.AppendItem( *pDefaultPathItem );
     436           0 :     SFX_REQUEST_ARG( rReq, pDefaultNameItem, SfxStringItem, SID_DEFAULTFILENAME, false);
     437           0 :     if ( pDefaultNameItem )
     438           0 :         aReq.AppendItem( *pDefaultNameItem );
     439             : 
     440           0 :     SfxGetpApp()->ExecuteSlot( aReq );
     441           0 :     const SfxViewFrameItem* pItem = PTR_CAST( SfxViewFrameItem, aReq.GetReturnValue() );
     442           0 :     if ( pItem )
     443           0 :         rReq.SetReturnValue( SfxFrameItem( 0, pItem->GetFrame() ) );
     444           0 : }
     445             : 
     446             : 
     447             : 
     448           0 : void SfxApplication::NewDocExec_Impl( SfxRequest& rReq )
     449             : {
     450             :     // No Parameter from BASIC only Factory given?
     451           0 :     SFX_REQUEST_ARG(rReq, pTemplNameItem, SfxStringItem, SID_TEMPLATE_NAME, false);
     452           0 :     SFX_REQUEST_ARG(rReq, pTemplFileNameItem, SfxStringItem, SID_FILE_NAME, false);
     453           0 :     SFX_REQUEST_ARG(rReq, pTemplRegionNameItem, SfxStringItem, SID_TEMPLATE_REGIONNAME, false);
     454             : 
     455           0 :     SfxObjectShellLock xDoc;
     456             : 
     457           0 :     OUString  aTemplateRegion, aTemplateName, aTemplateFileName;
     458           0 :     bool    bDirect = false; // through FileName instead of Region/Template
     459           0 :     SfxErrorContext aEc(ERRCTX_SFX_NEWDOC);
     460           0 :     if ( !pTemplNameItem && !pTemplFileNameItem )
     461             :     {
     462           0 :         bool bNewWin = false;
     463           0 :         vcl::Window* pTopWin = GetTopWindow();
     464             : 
     465           0 :         ScopedVclPtrInstance< SfxTemplateManagerDlg > aTemplDlg;
     466           0 :         int nRet = aTemplDlg->Execute();
     467           0 :         if ( nRet == RET_OK )
     468             :         {
     469           0 :             rReq.Done();
     470           0 :             if ( pTopWin != GetTopWindow() )
     471             :             {
     472             :                 // the dialogue opens a document -> a new TopWindow appears
     473           0 :                 pTopWin = GetTopWindow();
     474           0 :                 bNewWin = true;
     475             :             }
     476             :         }
     477             : 
     478           0 :         if ( bNewWin && pTopWin )
     479             :             // after the destruction of the dialogue its parent comes to top,
     480             :             // but we want that the new document is on top
     481           0 :             pTopWin->ToTop();
     482             : 
     483           0 :         return;
     484             :     }
     485             :     else
     486             :     {
     487             :         // Template-Name
     488           0 :         if ( pTemplNameItem )
     489           0 :             aTemplateName = pTemplNameItem->GetValue();
     490             : 
     491             :         // Template-Region
     492           0 :         if ( pTemplRegionNameItem )
     493           0 :             aTemplateRegion = pTemplRegionNameItem->GetValue();
     494             : 
     495             :         // Template-File-Name
     496           0 :         if ( pTemplFileNameItem )
     497             :         {
     498           0 :             aTemplateFileName = pTemplFileNameItem->GetValue();
     499           0 :             bDirect = true;
     500             :         }
     501             :     }
     502             : 
     503           0 :     sal_uIntPtr lErr = 0;
     504           0 :     SfxItemSet* pSet = new SfxAllItemSet( GetPool() );
     505           0 :     pSet->Put( SfxBoolItem( SID_TEMPLATE, true ) );
     506           0 :     if ( !bDirect )
     507             :     {
     508           0 :         SfxDocumentTemplates aTmpFac;
     509           0 :         if( aTemplateFileName.isEmpty() )
     510           0 :             aTmpFac.GetFull( aTemplateRegion, aTemplateName, aTemplateFileName );
     511             : 
     512           0 :         if( aTemplateFileName.isEmpty() )
     513           0 :             lErr = ERRCODE_SFX_TEMPLATENOTFOUND;
     514             :     }
     515             : 
     516           0 :     INetURLObject aObj( aTemplateFileName );
     517           0 :     SfxErrorContext aEC( ERRCTX_SFX_LOADTEMPLATE, aObj.PathToFileName() );
     518             : 
     519           0 :     if ( lErr != ERRCODE_NONE )
     520             :     {
     521           0 :         sal_uIntPtr lFatalErr = ERRCODE_TOERROR(lErr);
     522           0 :         if ( lFatalErr )
     523           0 :             ErrorHandler::HandleError(lErr);
     524             :     }
     525             :     else
     526             :     {
     527           0 :         SfxCallMode eMode = SfxCallMode::SYNCHRON;
     528             : 
     529           0 :         const SfxPoolItem *pRet=0;
     530           0 :         SfxStringItem aReferer( SID_REFERER, "private:user" );
     531           0 :         SfxStringItem aTarget( SID_TARGETNAME, "_default" );
     532           0 :         if ( !aTemplateFileName.isEmpty() )
     533             :         {
     534             :             DBG_ASSERT( aObj.GetProtocol() != INetProtocol::NotValid, "Illegal URL!" );
     535             : 
     536           0 :             SfxStringItem aName( SID_FILE_NAME, aObj.GetMainURL( INetURLObject::NO_DECODE ) );
     537           0 :             SfxStringItem aTemplName( SID_TEMPLATE_NAME, aTemplateName );
     538           0 :             SfxStringItem aTemplRegionName( SID_TEMPLATE_REGIONNAME, aTemplateRegion );
     539           0 :             pRet = GetDispatcher_Impl()->Execute( SID_OPENDOC, eMode, &aName, &aTarget, &aReferer, &aTemplName, &aTemplRegionName, 0L );
     540             :         }
     541             :         else
     542             :         {
     543           0 :             SfxStringItem aName( SID_FILE_NAME, "private:factory" );
     544           0 :             pRet = GetDispatcher_Impl()->Execute( SID_OPENDOC, eMode, &aName, &aTarget, &aReferer, 0L );
     545             :         }
     546             : 
     547           0 :         if ( pRet )
     548           0 :             rReq.SetReturnValue( *pRet );
     549           0 :     }
     550             : }
     551             : 
     552             : 
     553             : 
     554             : namespace {
     555             : 
     556             : /**
     557             :  * Check if a given filter type should open the hyperlinked document
     558             :  * natively.
     559             :  *
     560             :  * @param rFilter filter object
     561             :  */
     562           0 : bool lcl_isFilterNativelySupported(const SfxFilter& rFilter)
     563             : {
     564           0 :     if (rFilter.IsOwnFormat())
     565           0 :         return true;
     566             : 
     567           0 :     OUString aName = rFilter.GetFilterName();
     568           0 :     if (aName.startsWith("MS Excel"))
     569             :         // We can handle all Excel variants natively.
     570           0 :         return true;
     571             : 
     572           0 :     return false;
     573             : }
     574             : 
     575             : }
     576             : 
     577           0 : void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
     578             : {
     579           0 :     OUString aDocService;
     580           0 :     SFX_REQUEST_ARG(rReq, pDocSrvItem, SfxStringItem, SID_DOC_SERVICE, false);
     581           0 :     if (pDocSrvItem)
     582           0 :         aDocService = pDocSrvItem->GetValue();
     583             : 
     584           0 :     sal_uInt16 nSID = rReq.GetSlot();
     585           0 :     SFX_REQUEST_ARG( rReq, pFileNameItem, SfxStringItem, SID_FILE_NAME, false );
     586           0 :     if ( pFileNameItem )
     587             :     {
     588           0 :         OUString aCommand( pFileNameItem->GetValue() );
     589           0 :         const SfxSlot* pSlot = GetInterface()->GetSlot( aCommand );
     590           0 :         if ( pSlot )
     591             :         {
     592           0 :             pFileNameItem = NULL;
     593             :         }
     594             :         else
     595             :         {
     596           0 :             if ( aCommand.startsWith("slot:") )
     597             :             {
     598           0 :                 sal_uInt16 nSlotId = (sal_uInt16) aCommand.copy(5).toInt32();
     599           0 :                 if ( nSlotId == SID_OPENDOC )
     600           0 :                     pFileNameItem = NULL;
     601             :             }
     602           0 :         }
     603             :     }
     604             : 
     605           0 :     if ( !pFileNameItem )
     606             :     {
     607             :         // get FileName from dialog
     608           0 :         std::vector<OUString> pURLList;
     609           0 :         OUString aFilter;
     610           0 :         SfxItemSet* pSet = NULL;
     611           0 :         OUString aPath;
     612           0 :         SFX_REQUEST_ARG( rReq, pFolderNameItem, SfxStringItem, SID_PATH, false );
     613           0 :         if ( pFolderNameItem )
     614           0 :             aPath = pFolderNameItem->GetValue();
     615           0 :         else if ( nSID == SID_OPENTEMPLATE )
     616             :         {
     617           0 :             aPath = SvtPathOptions().GetTemplatePath();
     618           0 :             sal_Int32 nTokenCount = comphelper::string::getTokenCount(aPath, ';');
     619           0 :             aPath = aPath.getToken( nTokenCount ? ( nTokenCount - 1 ) : 0 , ';' );
     620             :         }
     621             : 
     622           0 :         sal_Int16 nDialog = SFX2_IMPL_DIALOG_CONFIG;
     623           0 :         SFX_REQUEST_ARG( rReq, pSystemDialogItem, SfxBoolItem, SID_FILE_DIALOG, false );
     624           0 :         if ( pSystemDialogItem )
     625           0 :             nDialog = pSystemDialogItem->GetValue() ? SFX2_IMPL_DIALOG_SYSTEM : SFX2_IMPL_DIALOG_OOO;
     626             : 
     627           0 :         OUString sStandardDir;
     628             : 
     629           0 :         SFX_REQUEST_ARG( rReq, pStandardDirItem, SfxStringItem, SID_STANDARD_DIR, false );
     630           0 :         if ( pStandardDirItem )
     631           0 :             sStandardDir = pStandardDirItem->GetValue();
     632             : 
     633           0 :         ::com::sun::star::uno::Sequence< OUString >  aBlackList;
     634             : 
     635           0 :         SFX_REQUEST_ARG( rReq, pBlackListItem, SfxStringListItem, SID_BLACK_LIST, false );
     636           0 :         if ( pBlackListItem )
     637           0 :             pBlackListItem->GetStringList( aBlackList );
     638             : 
     639             : 
     640             :         sal_uIntPtr nErr = sfx2::FileOpenDialog_Impl(
     641             :                 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
     642             :                 SFXWB_MULTISELECTION, OUString(), pURLList,
     643           0 :                 aFilter, pSet, &aPath, nDialog, sStandardDir, aBlackList );
     644             : 
     645           0 :         if ( nErr == ERRCODE_ABORT )
     646             :         {
     647           0 :             pURLList.clear();
     648           0 :             return;
     649             :         }
     650             : 
     651           0 :         rReq.SetArgs( *static_cast<SfxAllItemSet*>(pSet) );
     652           0 :         if ( !aFilter.isEmpty() )
     653           0 :             rReq.AppendItem( SfxStringItem( SID_FILTER_NAME, aFilter ) );
     654           0 :         rReq.AppendItem( SfxStringItem( SID_TARGETNAME, OUString("_default") ) );
     655           0 :         rReq.AppendItem( SfxStringItem( SID_REFERER, "private:user" ) );
     656           0 :         delete pSet;
     657             : 
     658           0 :         if(!pURLList.empty())
     659             :         {
     660           0 :             if ( nSID == SID_OPENTEMPLATE )
     661           0 :                 rReq.AppendItem( SfxBoolItem( SID_TEMPLATE, false ) );
     662             : 
     663             :             // This helper wraps an existing (or may new created InteractionHandler)
     664             :             // intercept all incoming interactions and provide useful information
     665             :             // later if the following transaction was finished.
     666             : 
     667           0 :             ::framework::PreventDuplicateInteraction*                 pHandler       = new ::framework::PreventDuplicateInteraction(::comphelper::getProcessComponentContext());
     668           0 :             css::uno::Reference< css::task::XInteractionHandler >     xHandler       (static_cast< css::task::XInteractionHandler* >(pHandler), css::uno::UNO_QUERY);
     669           0 :             css::uno::Reference< css::task::XInteractionHandler >     xWrappedHandler;
     670             : 
     671             :             // wrap existing handler or create new UUI handler
     672           0 :             SFX_REQUEST_ARG(rReq, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, false);
     673           0 :             if (pInteractionItem)
     674             :             {
     675           0 :                 pInteractionItem->GetValue() >>= xWrappedHandler;
     676           0 :                 rReq.RemoveItem( SID_INTERACTIONHANDLER );
     677             :             }
     678           0 :             if (xWrappedHandler.is())
     679           0 :                 pHandler->setHandler(xWrappedHandler);
     680             :             else
     681           0 :                 pHandler->useDefaultUUIHandler();
     682           0 :             rReq.AppendItem( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHandler)) );
     683             : 
     684             :             // define rules for this handler
     685           0 :             css::uno::Type                                            aInteraction = ::cppu::UnoType<css::task::ErrorCodeRequest>::get();
     686           0 :             ::framework::PreventDuplicateInteraction::InteractionInfo aRule        (aInteraction, 1);
     687           0 :             pHandler->addInteractionRule(aRule);
     688             : 
     689           0 :             if (!aDocService.isEmpty())
     690             :             {
     691           0 :                 rReq.RemoveItem(SID_DOC_SERVICE);
     692           0 :                 rReq.AppendItem(SfxStringItem(SID_DOC_SERVICE, aDocService));
     693             :             }
     694             : 
     695           0 :             for(std::vector<OUString>::const_iterator i = pURLList.begin(); i != pURLList.end(); ++i)
     696             :             {
     697           0 :                 rReq.RemoveItem( SID_FILE_NAME );
     698           0 :                 rReq.AppendItem( SfxStringItem( SID_FILE_NAME, *i ) );
     699             : 
     700             :                 // Run synchronous, so that not the next document is loaded
     701             :                 // when rescheduling
     702             :                 // TODO/LATER: use URLList argument and always remove one document after another, each step in asychronous execution, until finished
     703             :                 // but only if reschedule is a problem
     704           0 :                 GetDispatcher_Impl()->Execute( SID_OPENDOC, SfxCallMode::SYNCHRON, *rReq.GetArgs() );
     705             : 
     706             :                 // check for special interaction "NO MORE DOCUMENTS ALLOWED" and
     707             :                 // break loop then. Otherwise we risk showing the same interaction more than once.
     708           0 :                 if ( pHandler->getInteractionInfo(aInteraction, &aRule) )
     709             :                 {
     710           0 :                     if (aRule.m_nCallCount > 0)
     711             :                     {
     712           0 :                         if (aRule.m_xRequest.is())
     713             :                         {
     714           0 :                             css::task::ErrorCodeRequest aRequest;
     715           0 :                             if (aRule.m_xRequest->getRequest() >>= aRequest)
     716             :                             {
     717           0 :                                 if (aRequest.ErrCode ==
     718             :                                     sal::static_int_cast< sal_Int32 >(
     719           0 :                                         ERRCODE_SFX_NOMOREDOCUMENTSALLOWED))
     720           0 :                                     break;
     721           0 :                             }
     722             :                         }
     723             :                     }
     724             :                 }
     725             :             }
     726             : 
     727           0 :             pURLList.clear();
     728           0 :             return;
     729             :         }
     730           0 :         pURLList.clear();
     731             :     }
     732             : 
     733           0 :     bool bHyperlinkUsed = false;
     734             : 
     735           0 :     if ( SID_OPENURL == nSID )
     736             :     {
     737             :         // SID_OPENURL does the same as SID_OPENDOC!
     738           0 :         rReq.SetSlot( SID_OPENDOC );
     739           0 :         nSID = SID_OPENDOC;
     740             :     }
     741           0 :     else if ( nSID == SID_OPENTEMPLATE )
     742             :     {
     743           0 :         rReq.AppendItem( SfxBoolItem( SID_TEMPLATE, false ) );
     744             :     }
     745             :     // pass URL to OS by using ShellExecuter or open it internal
     746             :     // if it seems to be an own format.
     747             :     /* Attention!
     748             :             There exist two possibilities to open hyperlinks:
     749             :             a) using SID_OPENHYPERLINK (new)
     750             :             b) using SID_BROWSE        (old)
     751             :      */
     752           0 :     else if ( nSID == SID_OPENHYPERLINK )
     753             :     {
     754           0 :         rReq.SetSlot( SID_OPENDOC );
     755           0 :         nSID = SID_OPENDOC;
     756           0 :         bHyperlinkUsed = true;
     757             :     }
     758             : 
     759             :     // no else here! It's optional ...
     760           0 :     if (!bHyperlinkUsed)
     761             :     {
     762           0 :         SFX_REQUEST_ARG(rReq, pHyperLinkUsedItem, SfxBoolItem, SID_BROWSE, false);
     763           0 :         if ( pHyperLinkUsedItem )
     764           0 :             bHyperlinkUsed = pHyperLinkUsedItem->GetValue();
     765             :         // no "official" item, so remove it from ItemSet before using UNO-API
     766           0 :         rReq.RemoveItem( SID_BROWSE );
     767             :     }
     768             : 
     769           0 :     SFX_REQUEST_ARG( rReq, pFileName, SfxStringItem, SID_FILE_NAME, false );
     770           0 :     OUString aFileName = pFileName->GetValue();
     771             : 
     772           0 :     OUString aReferer;
     773           0 :     SFX_REQUEST_ARG( rReq, pRefererItem, SfxStringItem, SID_REFERER, false );
     774           0 :     if ( pRefererItem )
     775           0 :         aReferer = pRefererItem->GetValue();
     776             : 
     777           0 :     SFX_REQUEST_ARG( rReq, pFileFlagsItem, SfxStringItem, SID_OPTIONS, false);
     778           0 :     if ( pFileFlagsItem )
     779             :     {
     780           0 :         OUString aFileFlags = pFileFlagsItem->GetValue();
     781           0 :         aFileFlags = aFileFlags.toAsciiUpperCase();
     782           0 :         if ( -1 != aFileFlags.indexOf( 0x0054 ) )               // T = 54h
     783             :         {
     784           0 :             rReq.RemoveItem( SID_TEMPLATE );
     785           0 :             rReq.AppendItem( SfxBoolItem( SID_TEMPLATE, true ) );
     786             :         }
     787             : 
     788           0 :         if ( -1 != aFileFlags.indexOf( 0x0048 ) )               // H = 48h
     789             :         {
     790           0 :             rReq.RemoveItem( SID_HIDDEN );
     791           0 :             rReq.AppendItem( SfxBoolItem( SID_HIDDEN, true ) );
     792             :         }
     793             : 
     794           0 :         if ( -1 != aFileFlags.indexOf( 0x0052 ) )               // R = 52h
     795             :         {
     796           0 :             rReq.RemoveItem( SID_DOC_READONLY );
     797           0 :             rReq.AppendItem( SfxBoolItem( SID_DOC_READONLY, true ) );
     798             :         }
     799             : 
     800           0 :         if ( -1 != aFileFlags.indexOf( 0x0042 ) )               // B = 42h
     801             :         {
     802           0 :             rReq.RemoveItem( SID_PREVIEW );
     803           0 :             rReq.AppendItem( SfxBoolItem( SID_PREVIEW, true ) );
     804             :         }
     805             : 
     806           0 :         rReq.RemoveItem( SID_OPTIONS );
     807             :     }
     808             : 
     809             :     // Mark without URL cannot be handled by hyperlink code
     810           0 :     if ( bHyperlinkUsed && !aFileName.isEmpty() && aFileName[0] != '#' )
     811             :     {
     812             :         Reference< ::com::sun::star::document::XTypeDetection > xTypeDetection(
     813           0 :                                                                     ::comphelper::getProcessServiceFactory()->createInstance(
     814           0 :                                                                     OUString("com.sun.star.document.TypeDetection")),
     815           0 :                                                                     UNO_QUERY );
     816           0 :         if ( xTypeDetection.is() )
     817             :         {
     818           0 :             URL             aURL;
     819           0 :             OUString aTypeName;
     820             : 
     821           0 :             aURL.Complete = aFileName;
     822           0 :             Reference< util::XURLTransformer > xTrans( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
     823           0 :             xTrans->parseStrict( aURL );
     824             : 
     825           0 :             INetProtocol aINetProtocol = INetURLObject( aURL.Complete ).GetProtocol();
     826           0 :             SvtExtendedSecurityOptions aExtendedSecurityOptions;
     827           0 :             SvtExtendedSecurityOptions::OpenHyperlinkMode eMode = aExtendedSecurityOptions.GetOpenHyperlinkMode();
     828             : 
     829           0 :             if ( eMode == SvtExtendedSecurityOptions::OPEN_NEVER && aINetProtocol != INetProtocol::VndSunStarHelp )
     830             :             {
     831           0 :                 SolarMutexGuard aGuard;
     832           0 :                 vcl::Window *pWindow = SfxGetpApp()->GetTopWindow();
     833             : 
     834             :                 ScopedVclPtrInstance<MessageDialog> aSecurityWarningBox(pWindow,
     835             :                                                   SfxResId(STR_SECURITY_WARNING_NO_HYPERLINKS),
     836           0 :                                                   VCL_MESSAGE_WARNING);
     837           0 :                 aSecurityWarningBox->SetText( SfxResId(RID_SECURITY_WARNING_TITLE).toString() );
     838           0 :                 aSecurityWarningBox->Execute();
     839           0 :                 return;
     840             :             }
     841             : 
     842           0 :             aTypeName = xTypeDetection->queryTypeByURL( aURL.Main );
     843           0 :             SfxFilterMatcher& rMatcher = SfxGetpApp()->GetFilterMatcher();
     844           0 :             const SfxFilter* pFilter = rMatcher.GetFilter4EA( aTypeName );
     845           0 :             if (!pFilter || !lcl_isFilterNativelySupported(*pFilter))
     846             :             {
     847             :                 // hyperlink does not link to own type => special handling (http, ftp) browser and (other external protocols) OS
     848           0 :                 if ( aINetProtocol == INetProtocol::Mailto )
     849             :                 {
     850             :                     // don't dispatch mailto hyperlink to desktop dispatcher
     851           0 :                     rReq.RemoveItem( SID_TARGETNAME );
     852           0 :                     rReq.AppendItem( SfxStringItem( SID_TARGETNAME, OUString("_self") ) );
     853             :                 }
     854           0 :                 else if ( aINetProtocol == INetProtocol::Ftp ||
     855           0 :                      aINetProtocol == INetProtocol::Http ||
     856             :                      aINetProtocol == INetProtocol::Https )
     857             :                 {
     858           0 :                     sfx2::openUriExternally(aURL.Complete, true);
     859           0 :                     return;
     860             :                 }
     861             :                 else
     862             :                 {
     863             :                     // check for "internal" protocols that should not be forwarded to the system
     864           0 :                     std::vector < OUString > aProtocols(2);
     865             : 
     866             :                     // add special protocols that always should be treated as internal
     867           0 :                     aProtocols[0] = "private:*";
     868           0 :                     aProtocols[1] = "vnd.sun.star.*";
     869             : 
     870             :                     // get registered protocol handlers from configuration
     871           0 :                     Reference < XNameAccess > xAccess(officecfg::Office::ProtocolHandler::HandlerSet::get());
     872           0 :                     Sequence < OUString > aNames = xAccess->getElementNames();
     873           0 :                     for ( sal_Int32 nName = 0; nName < aNames.getLength(); nName ++)
     874             :                     {
     875           0 :                         Reference < XPropertySet > xSet;
     876           0 :                         Any aRet = xAccess->getByName( aNames[nName] );
     877           0 :                         aRet >>= xSet;
     878           0 :                         if ( xSet.is() )
     879             :                         {
     880             :                             // copy protocols
     881           0 :                             aRet = xSet->getPropertyValue("Protocols");
     882           0 :                             Sequence < OUString > aTmp;
     883           0 :                             aRet >>= aTmp;
     884             : 
     885           0 :                             aProtocols.insert(aProtocols.end(),aTmp.begin(),aTmp.end());
     886             :                         }
     887           0 :                     }
     888             : 
     889           0 :                     bool bFound = false;
     890           0 :                     for ( size_t nProt=0; nProt<aProtocols.size(); nProt++ )
     891             :                     {
     892           0 :                         WildCard aPattern(aProtocols[nProt]);
     893           0 :                         if ( aPattern.Matches( aURL.Complete ) )
     894             :                         {
     895           0 :                             bFound = true;
     896           0 :                             break;
     897             :                         }
     898           0 :                     }
     899             : 
     900           0 :                     if ( !bFound )
     901             :                     {
     902           0 :                         bool bLoadInternal = false;
     903             :                         try
     904             :                         {
     905             :                             sfx2::openUriExternally(
     906           0 :                                 aURL.Complete, pFilter == 0);
     907             :                         }
     908           0 :                         catch ( ::com::sun::star::system::SystemShellExecuteException& )
     909             :                         {
     910           0 :                             rReq.RemoveItem( SID_TARGETNAME );
     911           0 :                             rReq.AppendItem( SfxStringItem( SID_TARGETNAME, OUString("_default") ) );
     912           0 :                             bLoadInternal = true;
     913             :                         }
     914           0 :                         if ( !bLoadInternal )
     915           0 :                             return;
     916           0 :                     }
     917             :                 }
     918             :             }
     919             :             else
     920             :             {
     921             :                 // hyperlink document must be loaded into a new frame
     922           0 :                 rReq.RemoveItem( SID_TARGETNAME );
     923           0 :                 rReq.AppendItem( SfxStringItem( SID_TARGETNAME, OUString("_default") ) );
     924           0 :             }
     925           0 :         }
     926             :     }
     927             : 
     928           0 :     if (!SvtSecurityOptions().isSecureMacroUri(aFileName, aReferer))
     929             :     {
     930           0 :         SfxErrorContext aCtx( ERRCTX_SFX_OPENDOC, aFileName );
     931           0 :         ErrorHandler::HandleError( ERRCODE_IO_ACCESSDENIED );
     932           0 :         return;
     933             :     }
     934             : 
     935           0 :     SfxFrame* pTargetFrame = NULL;
     936           0 :     Reference< XFrame > xTargetFrame;
     937             : 
     938           0 :     SFX_REQUEST_ARG(rReq, pFrameItem, SfxFrameItem, SID_DOCFRAME, false);
     939           0 :     if ( pFrameItem )
     940           0 :         pTargetFrame = pFrameItem->GetFrame();
     941             : 
     942           0 :     if ( !pTargetFrame )
     943             :     {
     944           0 :         SFX_REQUEST_ARG(rReq, pUnoFrameItem, SfxUnoFrameItem, SID_FILLFRAME, false);
     945           0 :         if ( pUnoFrameItem )
     946           0 :             xTargetFrame = pUnoFrameItem->GetFrame();
     947             :     }
     948             : 
     949           0 :     if ( !pTargetFrame && !xTargetFrame.is() && SfxViewFrame::Current() )
     950           0 :         pTargetFrame = &SfxViewFrame::Current()->GetFrame();
     951             : 
     952             :     // check if caller has set a callback
     953           0 :     SFX_REQUEST_ARG(rReq, pLinkItem, SfxLinkItem, SID_DONELINK, false );
     954             : 
     955             :     // remove from Itemset, because it confuses the parameter transformation
     956           0 :     if ( pLinkItem )
     957           0 :         pLinkItem = static_cast<SfxLinkItem*>( pLinkItem->Clone() );
     958             : 
     959           0 :     rReq.RemoveItem( SID_DONELINK );
     960             : 
     961             :     // check if the view must be hidden
     962           0 :     bool bHidden = false;
     963           0 :     SFX_REQUEST_ARG(rReq, pHidItem, SfxBoolItem, SID_HIDDEN, false);
     964           0 :     if ( pHidItem )
     965           0 :         bHidden = pHidItem->GetValue();
     966             : 
     967             :     // This request is a UI call. We have to set the right values inside the MediaDescriptor
     968             :     // for: InteractionHandler, StatusIndicator, MacroExecutionMode and DocTemplate.
     969             :     // But we have to look for already existing values or for real hidden requests.
     970           0 :     SFX_REQUEST_ARG(rReq, pPreviewItem, SfxBoolItem, SID_PREVIEW, false);
     971           0 :     if (!bHidden && ( !pPreviewItem || !pPreviewItem->GetValue() ) )
     972             :     {
     973           0 :         SFX_REQUEST_ARG(rReq, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, false);
     974           0 :         SFX_REQUEST_ARG(rReq, pMacroExecItem  , SfxUInt16Item, SID_MACROEXECMODE     , false);
     975           0 :         SFX_REQUEST_ARG(rReq, pDocTemplateItem, SfxUInt16Item, SID_UPDATEDOCMODE     , false);
     976             : 
     977           0 :         if (!pInteractionItem)
     978             :         {
     979           0 :             Reference < task::XInteractionHandler2 > xHdl = task::InteractionHandler::createWithParent( ::comphelper::getProcessComponentContext(), 0 );
     980           0 :             rReq.AppendItem( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHdl)) );
     981             :         }
     982           0 :         if (!pMacroExecItem)
     983           0 :             rReq.AppendItem( SfxUInt16Item(SID_MACROEXECMODE,::com::sun::star::document::MacroExecMode::USE_CONFIG) );
     984           0 :         if (!pDocTemplateItem)
     985           0 :             rReq.AppendItem( SfxUInt16Item(SID_UPDATEDOCMODE,::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG) );
     986             :     }
     987             : 
     988             :     // extract target name
     989           0 :     OUString aTarget;
     990           0 :     SFX_REQUEST_ARG(rReq, pTargetItem, SfxStringItem, SID_TARGETNAME, false);
     991           0 :     if ( pTargetItem )
     992           0 :         aTarget = pTargetItem->GetValue();
     993             :     else
     994             :     {
     995           0 :         SFX_REQUEST_ARG( rReq, pNewViewItem, SfxBoolItem, SID_OPEN_NEW_VIEW, false );
     996           0 :         if ( pNewViewItem && pNewViewItem->GetValue() )
     997           0 :             aTarget = "_blank" ;
     998             :     }
     999             : 
    1000           0 :     if ( bHidden )
    1001             :     {
    1002           0 :         aTarget = "_blank";
    1003             :         DBG_ASSERT( rReq.IsSynchronCall() || pLinkItem, "Hidden load process must be done synchronously!" );
    1004             :     }
    1005             : 
    1006           0 :     Reference < XController > xController;
    1007             :         // if a frame is given, it must be used for the starting point of the targeting mechanism
    1008             :         // this code is also used if asynchronous loading is possible, because loadComponent always is synchron
    1009           0 :         if ( !xTargetFrame.is() )
    1010             :         {
    1011           0 :             if ( pTargetFrame )
    1012             :             {
    1013           0 :                 xTargetFrame = pTargetFrame->GetFrameInterface();
    1014             :             }
    1015             :             else
    1016             :             {
    1017           0 :                 xTargetFrame.set( Desktop::create(::comphelper::getProcessComponentContext()), UNO_QUERY );
    1018             :             }
    1019             :         }
    1020             : 
    1021             :         // make URL ready
    1022           0 :         SFX_REQUEST_ARG( rReq, pURLItem, SfxStringItem, SID_FILE_NAME, false );
    1023           0 :         aFileName = pURLItem->GetValue();
    1024           0 :         if( aFileName.startsWith("#") ) // Mark without URL
    1025             :         {
    1026           0 :             SfxViewFrame *pView = pTargetFrame ? pTargetFrame->GetCurrentViewFrame() : 0;
    1027           0 :             if ( !pView )
    1028           0 :                 pView = SfxViewFrame::Current();
    1029           0 :             pView->GetViewShell()->JumpToMark( aFileName.copy(1) );
    1030           0 :             rReq.SetReturnValue( SfxViewFrameItem( 0, pView ) );
    1031           0 :             return;
    1032             :         }
    1033             : 
    1034             :         // convert items to properties for framework API calls
    1035           0 :         Sequence < PropertyValue > aArgs;
    1036           0 :         TransformItems( SID_OPENDOC, *rReq.GetArgs(), aArgs );
    1037             :         // Any Referer (that was relevant in the above call to
    1038             :         // SvtSecurityOptions::isSecureMacroUri) is no longer relevant, assuming
    1039             :         // this "open" request is initiated directly by the user:
    1040           0 :         for (sal_Int32 i = 0; i != aArgs.getLength(); ++i) {
    1041           0 :             if (aArgs[i].Name == "Referer") {
    1042           0 :                 ++i;
    1043           0 :                 for (; i != aArgs.getLength(); ++i) {
    1044           0 :                     aArgs[i - 1] = aArgs[i];
    1045             :                 }
    1046           0 :                 aArgs.realloc(aArgs.getLength()-1);
    1047           0 :                 break;
    1048             :             }
    1049             :         }
    1050             : 
    1051             :         // TODO/LATER: either remove LinkItem or create an asynchronous process for it
    1052           0 :         if( bHidden || pLinkItem || rReq.IsSynchronCall() )
    1053             :         {
    1054             :             // if loading must be done synchron, we must wait for completion to get a return value
    1055             :             // find frame by myself; I must know the exact frame to get the controller for the return value from it
    1056           0 :             Reference < XComponent > xComp;
    1057             : 
    1058             :             try
    1059             :             {
    1060           0 :                 xComp = ::comphelper::SynchronousDispatch::dispatch( xTargetFrame, aFileName, aTarget, 0, aArgs );
    1061             :             }
    1062           0 :             catch(const RuntimeException&)
    1063             :             {
    1064           0 :                 throw;
    1065             :             }
    1066           0 :             catch(const ::com::sun::star::uno::Exception&)
    1067             :             {
    1068             :             }
    1069             : 
    1070           0 :             Reference < XModel > xModel( xComp, UNO_QUERY );
    1071           0 :             if ( xModel.is() )
    1072           0 :                 xController = xModel->getCurrentController();
    1073             :             else
    1074           0 :                 xController = Reference < XController >( xComp, UNO_QUERY );
    1075             : 
    1076             :         }
    1077             :         else
    1078             :         {
    1079           0 :             URL aURL;
    1080           0 :             aURL.Complete = aFileName;
    1081           0 :             Reference< util::XURLTransformer > xTrans( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
    1082           0 :             xTrans->parseStrict( aURL );
    1083             : 
    1084           0 :             Reference < XDispatchProvider > xProv( xTargetFrame, UNO_QUERY );
    1085           0 :             Reference < XDispatch > xDisp = xProv.is() ? xProv->queryDispatch( aURL, aTarget, FrameSearchFlag::ALL ) : Reference < XDispatch >();;
    1086           0 :             if ( xDisp.is() )
    1087           0 :                 xDisp->dispatch( aURL, aArgs );
    1088             :         }
    1089             : 
    1090           0 :     if ( xController.is() )
    1091             :     {
    1092             :         // try to find the SfxFrame for the controller
    1093           0 :         SfxFrame* pCntrFrame = NULL;
    1094           0 :         for ( SfxViewShell* pShell = SfxViewShell::GetFirst( 0, false ); pShell; pShell = SfxViewShell::GetNext( *pShell, 0, false ) )
    1095             :         {
    1096           0 :             if ( pShell->GetController() == xController )
    1097             :             {
    1098           0 :                 pCntrFrame = &pShell->GetViewFrame()->GetFrame();
    1099           0 :                 break;
    1100             :             }
    1101             :         }
    1102             : 
    1103           0 :         if ( pCntrFrame )
    1104             :         {
    1105           0 :             SfxObjectShell* pSh = pCntrFrame->GetCurrentDocument();
    1106             :             DBG_ASSERT( pSh, "Controller without ObjectShell ?!" );
    1107             : 
    1108           0 :             rReq.SetReturnValue( SfxViewFrameItem( 0, pCntrFrame->GetCurrentViewFrame() ) );
    1109             : 
    1110           0 :             if ( bHidden )
    1111           0 :                 pSh->RestoreNoDelete();
    1112             :         }
    1113             :     }
    1114             : 
    1115           0 :     if ( pLinkItem )
    1116             :     {
    1117           0 :         SfxPoolItem* pRet = rReq.GetReturnValue()->Clone();
    1118           0 :         pLinkItem->GetValue().Call(pRet);
    1119           0 :         delete pLinkItem;
    1120           0 :     }
    1121         648 : }
    1122             : 
    1123             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11