LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/appl - appopen.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 26 553 4.7 %
Date: 2012-12-27 Functions: 4 19 21.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10