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