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