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