LCOV - code coverage report
Current view: top level - sfx2/source/appl - appopen.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 563 4.4 %
Date: 2012-08-25 Functions: 2 17 11.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 18 1730 1.0 %

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

Generated by: LCOV version 1.10