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