xref: /aoo42x/main/sfx2/source/view/frmload.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "frmload.hxx"
32*cdf0e10cSrcweir #include "objshimp.hxx"
33*cdf0e10cSrcweir #include "sfx2/app.hxx"
34*cdf0e10cSrcweir #include "sfx2/dispatch.hxx"
35*cdf0e10cSrcweir #include "sfx2/docfac.hxx"
36*cdf0e10cSrcweir #include "sfx2/docfile.hxx"
37*cdf0e10cSrcweir #include "sfx2/docfilt.hxx"
38*cdf0e10cSrcweir #include "sfx2/doctempl.hxx"
39*cdf0e10cSrcweir #include "sfx2/fcontnr.hxx"
40*cdf0e10cSrcweir #include "sfx2/frame.hxx"
41*cdf0e10cSrcweir #include "sfx2/request.hxx"
42*cdf0e10cSrcweir #include "sfx2/sfx.hrc"
43*cdf0e10cSrcweir #include "sfx2/sfxsids.hrc"
44*cdf0e10cSrcweir #include "sfx2/sfxuno.hxx"
45*cdf0e10cSrcweir #include "sfx2/viewfrm.hxx"
46*cdf0e10cSrcweir #include "sfx2/viewsh.hxx"
47*cdf0e10cSrcweir #include "sfx2/viewfac.hxx"
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir /** === begin UNO includes === **/
50*cdf0e10cSrcweir #include <com/sun/star/container/XContainerQuery.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/document/XTypeDetection.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/frame/XLoadable.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler2.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/document/XViewDataSupplier.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
58*cdf0e10cSrcweir /** === end UNO includes === **/
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir #include <comphelper/interaction.hxx>
61*cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
62*cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
63*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
64*cdf0e10cSrcweir #include <framework/interaction.hxx>
65*cdf0e10cSrcweir #include <rtl/logfile.hxx>
66*cdf0e10cSrcweir #include <rtl/ustring.h>
67*cdf0e10cSrcweir #include <sot/storinfo.hxx>
68*cdf0e10cSrcweir #include <svtools/ehdl.hxx>
69*cdf0e10cSrcweir #include <svl/eitem.hxx>
70*cdf0e10cSrcweir #include <svl/itemset.hxx>
71*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
72*cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
73*cdf0e10cSrcweir #include <svl/stritem.hxx>
74*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
75*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
76*cdf0e10cSrcweir #include <ucbhelper/simpleinteractionrequest.hxx>
77*cdf0e10cSrcweir #include <vos/mutex.hxx>
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir /** === begin UNO using === **/
80*cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue;
81*cdf0e10cSrcweir using ::com::sun::star::container::XContainerQuery;
82*cdf0e10cSrcweir using ::com::sun::star::container::XEnumeration;
83*cdf0e10cSrcweir using ::com::sun::star::document::XTypeDetection;
84*cdf0e10cSrcweir using ::com::sun::star::frame::XFrame;
85*cdf0e10cSrcweir using ::com::sun::star::frame::XLoadable;
86*cdf0e10cSrcweir using ::com::sun::star::frame::XModel;
87*cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory;
88*cdf0e10cSrcweir using ::com::sun::star::task::XInteractionHandler;
89*cdf0e10cSrcweir using ::com::sun::star::task::XInteractionHandler2;
90*cdf0e10cSrcweir using ::com::sun::star::task::XInteractionRequest;
91*cdf0e10cSrcweir using ::com::sun::star::task::XStatusIndicator;
92*cdf0e10cSrcweir using ::com::sun::star::uno::Any;
93*cdf0e10cSrcweir using ::com::sun::star::uno::Exception;
94*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
95*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException;
96*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
97*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY;
98*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW;
99*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW;
100*cdf0e10cSrcweir using ::com::sun::star::uno::makeAny;
101*cdf0e10cSrcweir using ::com::sun::star::util::XCloseable;
102*cdf0e10cSrcweir using ::com::sun::star::document::XViewDataSupplier;
103*cdf0e10cSrcweir using ::com::sun::star::container::XIndexAccess;
104*cdf0e10cSrcweir using ::com::sun::star::frame::XController2;
105*cdf0e10cSrcweir using ::com::sun::star::frame::XController;
106*cdf0e10cSrcweir using ::com::sun::star::frame::XModel2;
107*cdf0e10cSrcweir /** === end UNO using === **/
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir SfxFrameLoader_Impl::SfxFrameLoader_Impl( const Reference< XMultiServiceFactory >& _rxFactory )
110*cdf0e10cSrcweir     :m_aContext( _rxFactory )
111*cdf0e10cSrcweir {
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir SfxFrameLoader_Impl::~SfxFrameLoader_Impl()
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
119*cdf0e10cSrcweir const SfxFilter* SfxFrameLoader_Impl::impl_detectFilterForURL( const ::rtl::OUString& sURL,
120*cdf0e10cSrcweir         const ::comphelper::NamedValueCollection& i_rDescriptor, const SfxFilterMatcher& rMatcher ) const
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir     ::rtl::OUString sFilter;
123*cdf0e10cSrcweir     try
124*cdf0e10cSrcweir     {
125*cdf0e10cSrcweir         if ( !sURL.getLength() )
126*cdf0e10cSrcweir             return 0;
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir         Reference< XTypeDetection > xDetect(
129*cdf0e10cSrcweir             m_aContext.createComponent( "com.sun.star.document.TypeDetection" ),
130*cdf0e10cSrcweir             UNO_QUERY_THROW);
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir         ::comphelper::NamedValueCollection aNewArgs;
133*cdf0e10cSrcweir         aNewArgs.put( "URL", sURL );
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir         if ( i_rDescriptor.has( "InteractionHandler" ) )
136*cdf0e10cSrcweir             aNewArgs.put( "InteractionHandler", i_rDescriptor.get( "InteractionHandler" ) );
137*cdf0e10cSrcweir         if ( i_rDescriptor.has( "StatusIndicator" ) )
138*cdf0e10cSrcweir             aNewArgs.put( "StatusIndicator", i_rDescriptor.get( "StatusIndicator" ) );
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         Sequence< PropertyValue > aQueryArgs( aNewArgs.getPropertyValues() );
141*cdf0e10cSrcweir         ::rtl::OUString sType = xDetect->queryTypeByDescriptor( aQueryArgs, sal_True );
142*cdf0e10cSrcweir         if ( sType.getLength() )
143*cdf0e10cSrcweir         {
144*cdf0e10cSrcweir             const SfxFilter* pFilter = rMatcher.GetFilter4EA( sType );
145*cdf0e10cSrcweir             if ( pFilter )
146*cdf0e10cSrcweir                 sFilter = pFilter->GetName();
147*cdf0e10cSrcweir         }
148*cdf0e10cSrcweir     }
149*cdf0e10cSrcweir     catch ( const RuntimeException& )
150*cdf0e10cSrcweir     {
151*cdf0e10cSrcweir         throw;
152*cdf0e10cSrcweir     }
153*cdf0e10cSrcweir     catch( const Exception& )
154*cdf0e10cSrcweir     {
155*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
156*cdf0e10cSrcweir         sFilter = ::rtl::OUString();
157*cdf0e10cSrcweir     }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir     const SfxFilter* pFilter = 0;
160*cdf0e10cSrcweir     if (sFilter.getLength())
161*cdf0e10cSrcweir         pFilter = rMatcher.GetFilter4FilterName(sFilter);
162*cdf0e10cSrcweir     return pFilter;
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
166*cdf0e10cSrcweir const SfxFilter* SfxFrameLoader_Impl::impl_getFilterFromServiceName_nothrow( const ::rtl::OUString& i_rServiceName ) const
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir     try
169*cdf0e10cSrcweir     {
170*cdf0e10cSrcweir         ::comphelper::NamedValueCollection aQuery;
171*cdf0e10cSrcweir         aQuery.put( "DocumentService", i_rServiceName );
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir         const Reference< XContainerQuery > xQuery(
174*cdf0e10cSrcweir             m_aContext.createComponent( "com.sun.star.document.FilterFactory" ),
175*cdf0e10cSrcweir             UNO_QUERY_THROW );
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir         const SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
178*cdf0e10cSrcweir         const SfxFilterFlags nMust = SFX_FILTER_IMPORT;
179*cdf0e10cSrcweir         const SfxFilterFlags nDont = SFX_FILTER_NOTINSTALLED;
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir         Reference < XEnumeration > xEnum( xQuery->createSubSetEnumerationByProperties(
182*cdf0e10cSrcweir             aQuery.getNamedValues() ), UNO_SET_THROW );
183*cdf0e10cSrcweir         while ( xEnum->hasMoreElements() )
184*cdf0e10cSrcweir         {
185*cdf0e10cSrcweir             ::comphelper::NamedValueCollection aType( xEnum->nextElement() );
186*cdf0e10cSrcweir             ::rtl::OUString sFilterName = aType.getOrDefault( "Name", ::rtl::OUString() );
187*cdf0e10cSrcweir             if ( !sFilterName.getLength() )
188*cdf0e10cSrcweir                 continue;
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir             const SfxFilter* pFilter = rMatcher.GetFilter4FilterName( sFilterName );
191*cdf0e10cSrcweir             if ( !pFilter )
192*cdf0e10cSrcweir                 continue;
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir             SfxFilterFlags nFlags = pFilter->GetFilterFlags();
195*cdf0e10cSrcweir             if  (   ( ( nFlags & nMust ) == nMust )
196*cdf0e10cSrcweir                 &&  ( ( nFlags & nDont ) == 0 )
197*cdf0e10cSrcweir                 )
198*cdf0e10cSrcweir             {
199*cdf0e10cSrcweir                 return pFilter;
200*cdf0e10cSrcweir             }
201*cdf0e10cSrcweir         }
202*cdf0e10cSrcweir     }
203*cdf0e10cSrcweir     catch( const Exception& )
204*cdf0e10cSrcweir     {
205*cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
206*cdf0e10cSrcweir     }
207*cdf0e10cSrcweir     return NULL;
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
211*cdf0e10cSrcweir ::rtl::OUString SfxFrameLoader_Impl::impl_askForFilter_nothrow( const Reference< XInteractionHandler >& i_rxHandler,
212*cdf0e10cSrcweir                                                                  const ::rtl::OUString& i_rDocumentURL ) const
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir     ENSURE_OR_THROW( i_rxHandler.is(), "invalid interaction handler" );
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir     ::rtl::OUString sFilterName;
217*cdf0e10cSrcweir     try
218*cdf0e10cSrcweir     {
219*cdf0e10cSrcweir         ::framework::RequestFilterSelect aRequest( i_rDocumentURL );
220*cdf0e10cSrcweir         i_rxHandler->handle( aRequest.GetRequest() );
221*cdf0e10cSrcweir         if( !aRequest.isAbort() )
222*cdf0e10cSrcweir             sFilterName = aRequest.getFilter();
223*cdf0e10cSrcweir     }
224*cdf0e10cSrcweir     catch( const Exception& )
225*cdf0e10cSrcweir     {
226*cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
227*cdf0e10cSrcweir     }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir     return sFilterName;
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
233*cdf0e10cSrcweir namespace
234*cdf0e10cSrcweir {
235*cdf0e10cSrcweir     sal_Bool lcl_getDispatchResult( const SfxPoolItem* _pResult )
236*cdf0e10cSrcweir     {
237*cdf0e10cSrcweir         if ( !_pResult )
238*cdf0e10cSrcweir             return sal_False;
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir         // default must be set to true, because some return values
241*cdf0e10cSrcweir         // cant be checked, but nonetheless indicate "success"!
242*cdf0e10cSrcweir 	    sal_Bool bSuccess = sal_True;
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 	    // On the other side some special slots return a boolean state,
245*cdf0e10cSrcweir         // which can be set to FALSE.
246*cdf0e10cSrcweir         SfxBoolItem *pItem = PTR_CAST( SfxBoolItem, _pResult );
247*cdf0e10cSrcweir         if ( pItem )
248*cdf0e10cSrcweir             bSuccess = pItem->GetValue();
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir         return bSuccess;
251*cdf0e10cSrcweir     }
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
255*cdf0e10cSrcweir sal_Bool SfxFrameLoader_Impl::impl_createNewDocWithSlotParam( const sal_uInt16 _nSlotID, const Reference< XFrame >& i_rxFrame,
256*cdf0e10cSrcweir                                                               const bool i_bHidden )
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir     SfxRequest aRequest( _nSlotID, SFX_CALLMODE_SYNCHRON, SFX_APP()->GetPool() );
259*cdf0e10cSrcweir     aRequest.AppendItem( SfxUnoFrameItem( SID_FILLFRAME, i_rxFrame ) );
260*cdf0e10cSrcweir     if ( i_bHidden )
261*cdf0e10cSrcweir         aRequest.AppendItem( SfxBoolItem( SID_HIDDEN, sal_True ) );
262*cdf0e10cSrcweir     return lcl_getDispatchResult( SFX_APP()->ExecuteSlot( aRequest ) );
263*cdf0e10cSrcweir }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
266*cdf0e10cSrcweir void SfxFrameLoader_Impl::impl_determineFilter( ::comphelper::NamedValueCollection& io_rDescriptor ) const
267*cdf0e10cSrcweir {
268*cdf0e10cSrcweir     const ::rtl::OUString     sURL         = io_rDescriptor.getOrDefault( "URL",                ::rtl::OUString() );
269*cdf0e10cSrcweir     const ::rtl::OUString     sTypeName    = io_rDescriptor.getOrDefault( "TypeName",           ::rtl::OUString() );
270*cdf0e10cSrcweir     const ::rtl::OUString     sFilterName  = io_rDescriptor.getOrDefault( "FilterName",         ::rtl::OUString() );
271*cdf0e10cSrcweir     const ::rtl::OUString     sServiceName = io_rDescriptor.getOrDefault( "DocumentService",    ::rtl::OUString() );
272*cdf0e10cSrcweir     const Reference< XInteractionHandler >
273*cdf0e10cSrcweir                               xInteraction = io_rDescriptor.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() );
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir     const SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
276*cdf0e10cSrcweir     const SfxFilter* pFilter = NULL;
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir     // get filter by its name directly ...
279*cdf0e10cSrcweir     if ( sFilterName.getLength() )
280*cdf0e10cSrcweir         pFilter = rMatcher.GetFilter4FilterName( sFilterName );
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir     // or search the preferred filter for the detected type ...
283*cdf0e10cSrcweir     if ( !pFilter && sTypeName.getLength() )
284*cdf0e10cSrcweir         pFilter = rMatcher.GetFilter4EA( sTypeName );
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir     // or use given document service for detection, too
287*cdf0e10cSrcweir     if ( !pFilter && sServiceName.getLength() )
288*cdf0e10cSrcweir         pFilter = impl_getFilterFromServiceName_nothrow( sServiceName );
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir     // or use interaction to ask user for right filter.
291*cdf0e10cSrcweir     if ( !pFilter && xInteraction.is() && sURL.getLength() )
292*cdf0e10cSrcweir     {
293*cdf0e10cSrcweir         ::rtl::OUString sSelectedFilter = impl_askForFilter_nothrow( xInteraction, sURL );
294*cdf0e10cSrcweir         if ( sSelectedFilter.getLength() )
295*cdf0e10cSrcweir             pFilter = rMatcher.GetFilter4FilterName( sSelectedFilter );
296*cdf0e10cSrcweir     }
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir     if ( pFilter )
299*cdf0e10cSrcweir     {
300*cdf0e10cSrcweir         io_rDescriptor.put( "FilterName", ::rtl::OUString( pFilter->GetFilterName() ) );
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir         // If detected filter indicates using of an own template format
303*cdf0e10cSrcweir         // add property "AsTemplate" to descriptor. But suppress this step
304*cdf0e10cSrcweir         // if such property already exists.
305*cdf0e10cSrcweir         if ( pFilter->IsOwnTemplateFormat() && !io_rDescriptor.has( "AsTemplate" ) )
306*cdf0e10cSrcweir             io_rDescriptor.put( "AsTemplate", sal_Bool( sal_True ) );
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir         // The DocumentService property will finally be used to determine the document type to create, so
309*cdf0e10cSrcweir         // override it with the service name as indicated by the found filter.
310*cdf0e10cSrcweir         io_rDescriptor.put( "DocumentService", ::rtl::OUString( pFilter->GetServiceName() ) );
311*cdf0e10cSrcweir     }
312*cdf0e10cSrcweir }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
315*cdf0e10cSrcweir SfxObjectShellRef SfxFrameLoader_Impl::impl_findObjectShell( const Reference< XModel2 >& i_rxDocument ) const
316*cdf0e10cSrcweir {
317*cdf0e10cSrcweir 	for ( SfxObjectShell* pDoc = SfxObjectShell::GetFirst( NULL, sal_False ); pDoc; pDoc = SfxObjectShell::GetNext( *pDoc, NULL, sal_False ) )
318*cdf0e10cSrcweir 	{
319*cdf0e10cSrcweir 		if ( i_rxDocument == pDoc->GetModel() )
320*cdf0e10cSrcweir         {
321*cdf0e10cSrcweir             return pDoc;
322*cdf0e10cSrcweir         }
323*cdf0e10cSrcweir 	}
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir     DBG_ERROR( "SfxFrameLoader_Impl::impl_findObjectShell: model is not based on SfxObjectShell - wrong frame loader usage!" );
326*cdf0e10cSrcweir     return NULL;
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
330*cdf0e10cSrcweir bool SfxFrameLoader_Impl::impl_determineTemplateDocument( ::comphelper::NamedValueCollection& io_rDescriptor ) const
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir     const ::rtl::OUString sTemplateRegioName = io_rDescriptor.getOrDefault( "TemplateRegionName", ::rtl::OUString() );
333*cdf0e10cSrcweir     const ::rtl::OUString sTemplateName      = io_rDescriptor.getOrDefault( "TemplateName",       ::rtl::OUString() );
334*cdf0e10cSrcweir     const ::rtl::OUString sServiceName       = io_rDescriptor.getOrDefault( "DocumentService",    ::rtl::OUString() );
335*cdf0e10cSrcweir     const ::rtl::OUString sURL               = io_rDescriptor.getOrDefault( "URL",                ::rtl::OUString() );
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir     // determine the full URL of the template to use, if any
338*cdf0e10cSrcweir     String sTemplateURL;
339*cdf0e10cSrcweir 	if ( sTemplateRegioName.getLength() && sTemplateName.getLength() )
340*cdf0e10cSrcweir 	{
341*cdf0e10cSrcweir 		SfxDocumentTemplates aTmpFac;
342*cdf0e10cSrcweir 		aTmpFac.GetFull( sTemplateRegioName, sTemplateName, sTemplateURL );
343*cdf0e10cSrcweir 	}
344*cdf0e10cSrcweir 	else
345*cdf0e10cSrcweir 	{
346*cdf0e10cSrcweir 	    if ( sServiceName.getLength() )
347*cdf0e10cSrcweir             sTemplateURL = SfxObjectFactory::GetStandardTemplate( sServiceName );
348*cdf0e10cSrcweir         else
349*cdf0e10cSrcweir             sTemplateURL = SfxObjectFactory::GetStandardTemplate( SfxObjectShell::GetServiceNameFromFactory( sURL ) );
350*cdf0e10cSrcweir 	}
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir     if ( sTemplateURL.Len() > 0 )
353*cdf0e10cSrcweir     {
354*cdf0e10cSrcweir         // detect the filter for the template. Might still be NULL (if the template is broken, or does not
355*cdf0e10cSrcweir         // exist, or some such), but this is handled by our caller the same way as if no template/URL was present.
356*cdf0e10cSrcweir         const SfxFilter* pTemplateFilter = impl_detectFilterForURL( sTemplateURL, io_rDescriptor, SFX_APP()->GetFilterMatcher() );
357*cdf0e10cSrcweir         if ( pTemplateFilter )
358*cdf0e10cSrcweir         {
359*cdf0e10cSrcweir             // load the template document, but, well, "as template"
360*cdf0e10cSrcweir             io_rDescriptor.put( "FilterName", ::rtl::OUString( pTemplateFilter->GetName() ) );
361*cdf0e10cSrcweir             io_rDescriptor.put( "FileName", ::rtl::OUString( sTemplateURL ) );
362*cdf0e10cSrcweir             io_rDescriptor.put( "AsTemplate", sal_True );
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir             // #i21583#
365*cdf0e10cSrcweir             // the DocumentService property will finally be used to create the document. Thus, override any possibly
366*cdf0e10cSrcweir             // present value with the document service of the template.
367*cdf0e10cSrcweir             io_rDescriptor.put( "DocumentService", ::rtl::OUString( pTemplateFilter->GetServiceName() ) );
368*cdf0e10cSrcweir             return true;
369*cdf0e10cSrcweir         }
370*cdf0e10cSrcweir     }
371*cdf0e10cSrcweir     return false;
372*cdf0e10cSrcweir }
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
375*cdf0e10cSrcweir sal_uInt16 SfxFrameLoader_Impl::impl_findSlotParam( const ::rtl::OUString& i_rFactoryURL ) const
376*cdf0e10cSrcweir {
377*cdf0e10cSrcweir     ::rtl::OUString sSlotParam;
378*cdf0e10cSrcweir     const sal_Int32 nParamPos = i_rFactoryURL.indexOf( '?' );
379*cdf0e10cSrcweir     if ( nParamPos >= 0 )
380*cdf0e10cSrcweir     {
381*cdf0e10cSrcweir         // currently only the "slot" parameter is supported
382*cdf0e10cSrcweir         const sal_Int32 nSlotPos = i_rFactoryURL.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "slot=" ), nParamPos );
383*cdf0e10cSrcweir         if ( nSlotPos > 0 )
384*cdf0e10cSrcweir             sSlotParam = i_rFactoryURL.copy( nSlotPos + 5 );
385*cdf0e10cSrcweir     }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir     if ( sSlotParam.getLength() )
388*cdf0e10cSrcweir         return sal_uInt16( sSlotParam.toInt32() );
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir     return 0;
391*cdf0e10cSrcweir }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
394*cdf0e10cSrcweir void SfxFrameLoader_Impl::impl_handleCaughtError_nothrow( const Any& i_rCaughtError, const ::comphelper::NamedValueCollection& i_rDescriptor ) const
395*cdf0e10cSrcweir {
396*cdf0e10cSrcweir     try
397*cdf0e10cSrcweir     {
398*cdf0e10cSrcweir         const Reference< XInteractionHandler > xInteraction =
399*cdf0e10cSrcweir             i_rDescriptor.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() );
400*cdf0e10cSrcweir         if ( !xInteraction.is() )
401*cdf0e10cSrcweir             return;
402*cdf0e10cSrcweir         ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( i_rCaughtError ) );
403*cdf0e10cSrcweir         ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
404*cdf0e10cSrcweir         pRequest->addContinuation( pApprove.get() );
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir         const Reference< XInteractionHandler2 > xHandler( xInteraction, UNO_QUERY );
407*cdf0e10cSrcweir     #if OSL_DEBUG_LEVEL > 0
408*cdf0e10cSrcweir         const sal_Bool bHandled =
409*cdf0e10cSrcweir     #endif
410*cdf0e10cSrcweir         xHandler.is() && xHandler->handleInteractionRequest( pRequest.get() );
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir     #if OSL_DEBUG_LEVEL > 0
413*cdf0e10cSrcweir         if ( !bHandled )
414*cdf0e10cSrcweir             // the interaction handler couldn't deal with this error
415*cdf0e10cSrcweir             // => report it as assertion, at least (done in the DBG_UNHANDLED_EXCEPTION below)
416*cdf0e10cSrcweir             ::cppu::throwException( i_rCaughtError );
417*cdf0e10cSrcweir     #endif
418*cdf0e10cSrcweir     }
419*cdf0e10cSrcweir     catch( const Exception& )
420*cdf0e10cSrcweir     {
421*cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
422*cdf0e10cSrcweir     }
423*cdf0e10cSrcweir }
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
426*cdf0e10cSrcweir void SfxFrameLoader_Impl::impl_removeLoaderArguments( ::comphelper::NamedValueCollection& io_rDescriptor )
427*cdf0e10cSrcweir {
428*cdf0e10cSrcweir     // remove the arguments which are for the loader only, and not for a call to attachResource
429*cdf0e10cSrcweir     io_rDescriptor.remove( "StatusIndicator" );
430*cdf0e10cSrcweir     io_rDescriptor.remove( "Model" );
431*cdf0e10cSrcweir }
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
434*cdf0e10cSrcweir ::comphelper::NamedValueCollection SfxFrameLoader_Impl::impl_extractViewCreationArgs( ::comphelper::NamedValueCollection& io_rDescriptor )
435*cdf0e10cSrcweir {
436*cdf0e10cSrcweir     const sal_Char* pKnownViewArgs[] = {
437*cdf0e10cSrcweir         "JumpMark"
438*cdf0e10cSrcweir     };
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir     ::comphelper::NamedValueCollection aViewArgs;
441*cdf0e10cSrcweir     for ( size_t i=0; i < sizeof( pKnownViewArgs ) / sizeof( pKnownViewArgs[0] ); ++i )
442*cdf0e10cSrcweir     {
443*cdf0e10cSrcweir         if ( io_rDescriptor.has( pKnownViewArgs[i] ) )
444*cdf0e10cSrcweir         {
445*cdf0e10cSrcweir             aViewArgs.put( pKnownViewArgs[i], io_rDescriptor.get( pKnownViewArgs[i] ) );
446*cdf0e10cSrcweir             io_rDescriptor.remove( pKnownViewArgs[i] );
447*cdf0e10cSrcweir         }
448*cdf0e10cSrcweir     }
449*cdf0e10cSrcweir     return aViewArgs;
450*cdf0e10cSrcweir }
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
453*cdf0e10cSrcweir sal_Int16 SfxFrameLoader_Impl::impl_determineEffectiveViewId_nothrow( const SfxObjectShell& i_rDocument, const ::comphelper::NamedValueCollection& i_rDescriptor )
454*cdf0e10cSrcweir {
455*cdf0e10cSrcweir     sal_Int16 nViewId = i_rDescriptor.getOrDefault( "ViewId", sal_Int16( 0 ) );
456*cdf0e10cSrcweir     try
457*cdf0e10cSrcweir     {
458*cdf0e10cSrcweir         if ( nViewId == 0 ) do
459*cdf0e10cSrcweir         {
460*cdf0e10cSrcweir             Reference< XViewDataSupplier > xViewDataSupplier( i_rDocument.GetModel(), UNO_QUERY );
461*cdf0e10cSrcweir             Reference< XIndexAccess > xViewData;
462*cdf0e10cSrcweir             if ( xViewDataSupplier.is() )
463*cdf0e10cSrcweir 	            xViewData.set( xViewDataSupplier->getViewData() );
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir             if ( !xViewData.is() || ( xViewData->getCount() == 0 ) )
466*cdf0e10cSrcweir                 // no view data stored together with the model
467*cdf0e10cSrcweir 	            break;
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir             // obtain the ViewID from the view data
470*cdf0e10cSrcweir             Sequence< PropertyValue > aViewData;
471*cdf0e10cSrcweir             if ( !( xViewData->getByIndex( 0 ) >>= aViewData ) )
472*cdf0e10cSrcweir                 break;
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir             ::comphelper::NamedValueCollection aNamedViewData( aViewData );
475*cdf0e10cSrcweir             ::rtl::OUString sViewId = aNamedViewData.getOrDefault( "ViewId", ::rtl::OUString() );
476*cdf0e10cSrcweir             if ( !sViewId.getLength() )
477*cdf0e10cSrcweir                 break;
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir             // somewhat weird convention here ... in the view data, the ViewId is a string, effectively describing
480*cdf0e10cSrcweir             // a view name. In the document load descriptor, the ViewId is in fact the numeric ID.
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir             SfxViewFactory* pViewFactory = i_rDocument.GetFactory().GetViewFactoryByViewName( sViewId );
483*cdf0e10cSrcweir             if ( pViewFactory )
484*cdf0e10cSrcweir                 nViewId = sal_Int16( pViewFactory->GetOrdinal() );
485*cdf0e10cSrcweir         }
486*cdf0e10cSrcweir         while ( false );
487*cdf0e10cSrcweir     }
488*cdf0e10cSrcweir     catch( const Exception& )
489*cdf0e10cSrcweir     {
490*cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
491*cdf0e10cSrcweir     }
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir     if ( nViewId == 0 )
494*cdf0e10cSrcweir         nViewId = i_rDocument.GetFactory().GetViewFactory( 0 ).GetOrdinal();
495*cdf0e10cSrcweir     return nViewId;
496*cdf0e10cSrcweir }
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
499*cdf0e10cSrcweir Reference< XController2 > SfxFrameLoader_Impl::impl_createDocumentView( const Reference< XModel2 >& i_rModel,
500*cdf0e10cSrcweir         const Reference< XFrame >& i_rFrame, const ::comphelper::NamedValueCollection& i_rViewFactoryArgs,
501*cdf0e10cSrcweir         const ::rtl::OUString& i_rViewName )
502*cdf0e10cSrcweir {
503*cdf0e10cSrcweir     // let the model create a new controller
504*cdf0e10cSrcweir     const Reference< XController2 > xController( i_rModel->createViewController(
505*cdf0e10cSrcweir         i_rViewName,
506*cdf0e10cSrcweir         i_rViewFactoryArgs.getPropertyValues(),
507*cdf0e10cSrcweir         i_rFrame
508*cdf0e10cSrcweir     ), UNO_SET_THROW );
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir     // introduce model/view/controller to each other
511*cdf0e10cSrcweir     xController->attachModel( i_rModel.get() );
512*cdf0e10cSrcweir     i_rModel->connectController( xController.get() );
513*cdf0e10cSrcweir     i_rFrame->setComponent( xController->getComponentWindow(), xController.get() );
514*cdf0e10cSrcweir     xController->attachFrame( i_rFrame );
515*cdf0e10cSrcweir     i_rModel->setCurrentController( xController.get() );
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir     return xController;
518*cdf0e10cSrcweir }
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
521*cdf0e10cSrcweir sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const Sequence< PropertyValue >& rArgs,
522*cdf0e10cSrcweir                                              const Reference< XFrame >& _rTargetFrame )
523*cdf0e10cSrcweir     throw( RuntimeException )
524*cdf0e10cSrcweir {
525*cdf0e10cSrcweir     ENSURE_OR_THROW( _rTargetFrame.is(), "illegal NULL frame" );
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxFrameLoader::load" );
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir     ::comphelper::NamedValueCollection aDescriptor( rArgs );
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir     // ensure the descriptor contains a referrer
534*cdf0e10cSrcweir     if ( !aDescriptor.has( "Referer" ) )
535*cdf0e10cSrcweir         aDescriptor.put( "Referer", ::rtl::OUString() );
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir     // TODO: is this needed? finally, when loading is successfull, then there should be no need for this item,
538*cdf0e10cSrcweir     // as the document can always obtain its frame. In particular, there might be situations where this frame
539*cdf0e10cSrcweir     // is accessed, but already disposed: Imagine the user loading a document, opening a second view on it, and
540*cdf0e10cSrcweir     // then closing the first view/frame.
541*cdf0e10cSrcweir     aDescriptor.put( "Frame", _rTargetFrame );
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir     // did the caller already pass a model?
544*cdf0e10cSrcweir     Reference< XModel2 > xModel = aDescriptor.getOrDefault( "Model", Reference< XModel2 >() );
545*cdf0e10cSrcweir     const bool bExternalModel = xModel.is();
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir     // check for factory URLs to create a new doc, instead of loading one
548*cdf0e10cSrcweir     const ::rtl::OUString sURL = aDescriptor.getOrDefault( "URL", ::rtl::OUString() );
549*cdf0e10cSrcweir     const bool bIsFactoryURL = ( sURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "private:factory/" ) ) == 0 );
550*cdf0e10cSrcweir     bool bInitNewModel = bIsFactoryURL;
551*cdf0e10cSrcweir     if ( bIsFactoryURL && !bExternalModel )
552*cdf0e10cSrcweir     {
553*cdf0e10cSrcweir         const ::rtl::OUString sFactory = sURL.copy( sizeof( "private:factory/" ) -1 );
554*cdf0e10cSrcweir         // special handling for some weird factory URLs a la private:factory/swriter?slot=21053
555*cdf0e10cSrcweir         const sal_uInt16 nSlotParam = impl_findSlotParam( sFactory );
556*cdf0e10cSrcweir         if ( nSlotParam != 0 )
557*cdf0e10cSrcweir         {
558*cdf0e10cSrcweir             return impl_createNewDocWithSlotParam( nSlotParam, _rTargetFrame, aDescriptor.getOrDefault( "Hidden", false ) );
559*cdf0e10cSrcweir         }
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir         const bool bDescribesValidTemplate = impl_determineTemplateDocument( aDescriptor );
562*cdf0e10cSrcweir         if ( bDescribesValidTemplate )
563*cdf0e10cSrcweir         {
564*cdf0e10cSrcweir             // if the media descriptor allowed us to determine a template document to create the new document
565*cdf0e10cSrcweir             // from, then do not init a new document model from scratch (below), but instead load the
566*cdf0e10cSrcweir             // template document
567*cdf0e10cSrcweir             bInitNewModel = false;
568*cdf0e10cSrcweir         }
569*cdf0e10cSrcweir         else
570*cdf0e10cSrcweir         {
571*cdf0e10cSrcweir             const ::rtl::OUString sServiceName = SfxObjectShell::GetServiceNameFromFactory( sFactory );
572*cdf0e10cSrcweir             aDescriptor.put( "DocumentService", sServiceName );
573*cdf0e10cSrcweir         }
574*cdf0e10cSrcweir 	}
575*cdf0e10cSrcweir     else
576*cdf0e10cSrcweir     {
577*cdf0e10cSrcweir         // compatibility
578*cdf0e10cSrcweir         aDescriptor.put( "FileName", aDescriptor.get( "URL" ) );
579*cdf0e10cSrcweir     }
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir     sal_Bool bLoadSuccess = sal_False;
582*cdf0e10cSrcweir 	try
583*cdf0e10cSrcweir 	{
584*cdf0e10cSrcweir         // extract view releant arguments from the loader args
585*cdf0e10cSrcweir         ::comphelper::NamedValueCollection aViewCreationArgs( impl_extractViewCreationArgs( aDescriptor ) );
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir         // no model passed from outside? => create one from scratch
588*cdf0e10cSrcweir 	    if ( !xModel.is() )
589*cdf0e10cSrcweir         {
590*cdf0e10cSrcweir             // beforehand, determine the filter to use, and update the descriptor with its information
591*cdf0e10cSrcweir             if ( !bInitNewModel )
592*cdf0e10cSrcweir             {
593*cdf0e10cSrcweir                 impl_determineFilter( aDescriptor );
594*cdf0e10cSrcweir             }
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir             // create the new doc
597*cdf0e10cSrcweir             const ::rtl::OUString sServiceName = aDescriptor.getOrDefault( "DocumentService", ::rtl::OUString() );
598*cdf0e10cSrcweir             xModel.set( m_aContext.createComponent( sServiceName ), UNO_QUERY_THROW );
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir             // load resp. init it
601*cdf0e10cSrcweir             const Reference< XLoadable > xLoadable( xModel, UNO_QUERY_THROW );
602*cdf0e10cSrcweir             if ( bInitNewModel )
603*cdf0e10cSrcweir             {
604*cdf0e10cSrcweir 	            xLoadable->initNew();
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir                 impl_removeLoaderArguments( aDescriptor );
607*cdf0e10cSrcweir                 xModel->attachResource( ::rtl::OUString(), aDescriptor.getPropertyValues() );
608*cdf0e10cSrcweir             }
609*cdf0e10cSrcweir             else
610*cdf0e10cSrcweir             {
611*cdf0e10cSrcweir 		        xLoadable->load( aDescriptor.getPropertyValues() );
612*cdf0e10cSrcweir             }
613*cdf0e10cSrcweir         }
614*cdf0e10cSrcweir         else
615*cdf0e10cSrcweir         {
616*cdf0e10cSrcweir             // tell the doc its (current) load args.
617*cdf0e10cSrcweir             impl_removeLoaderArguments( aDescriptor );
618*cdf0e10cSrcweir             xModel->attachResource( xModel->getURL(), aDescriptor.getPropertyValues() );
619*cdf0e10cSrcweir         }
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir         // get the SfxObjectShell (still needed at the moment)
622*cdf0e10cSrcweir         // SfxObjectShellRef is used here ( instead of ...Lock ) since the model is closed below if necessary
623*cdf0e10cSrcweir         // SfxObjectShellLock would be even dangerous here, since the lifetime control should be done outside in case of success
624*cdf0e10cSrcweir         const SfxObjectShellRef xDoc = impl_findObjectShell( xModel );
625*cdf0e10cSrcweir         ENSURE_OR_THROW( xDoc.Is(), "no SfxObjectShell for the given model" );
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir         // ensure the ID of the to-be-created view is in the descriptor, if possible
628*cdf0e10cSrcweir         const sal_Int16 nViewId = impl_determineEffectiveViewId_nothrow( *xDoc, aDescriptor );
629*cdf0e10cSrcweir         const sal_Int16 nViewNo = xDoc->GetFactory().GetViewNo_Impl( nViewId, 0 );
630*cdf0e10cSrcweir         const ::rtl::OUString sViewName( xDoc->GetFactory().GetViewFactory( nViewNo ).GetAPIViewName() );
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir         // plug the document into the frame
633*cdf0e10cSrcweir         impl_createDocumentView( xModel, _rTargetFrame, aViewCreationArgs, sViewName );
634*cdf0e10cSrcweir 		bLoadSuccess = sal_True;
635*cdf0e10cSrcweir 	}
636*cdf0e10cSrcweir 	catch ( Exception& )
637*cdf0e10cSrcweir 	{
638*cdf0e10cSrcweir         const Any aError( ::cppu::getCaughtException() );
639*cdf0e10cSrcweir         if ( !aDescriptor.getOrDefault( "Silent", sal_False ) )
640*cdf0e10cSrcweir             impl_handleCaughtError_nothrow( aError, aDescriptor );
641*cdf0e10cSrcweir 	}
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir     // if loading was not successful, close the document
644*cdf0e10cSrcweir     if ( !bLoadSuccess && !bExternalModel )
645*cdf0e10cSrcweir     {
646*cdf0e10cSrcweir 	    try
647*cdf0e10cSrcweir         {
648*cdf0e10cSrcweir             const Reference< XCloseable > xCloseable( xModel, UNO_QUERY_THROW );
649*cdf0e10cSrcweir 		    xCloseable->close( sal_True );
650*cdf0e10cSrcweir 	    }
651*cdf0e10cSrcweir         catch ( Exception& )
652*cdf0e10cSrcweir 	    {
653*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
654*cdf0e10cSrcweir         }
655*cdf0e10cSrcweir     }
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir 	return bLoadSuccess;
658*cdf0e10cSrcweir }
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir void SfxFrameLoader_Impl::cancel() throw( RuntimeException )
661*cdf0e10cSrcweir {
662*cdf0e10cSrcweir }
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir SFX_IMPL_SINGLEFACTORY( SfxFrameLoader_Impl )
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir /* XServiceInfo */
667*cdf0e10cSrcweir UNOOUSTRING SAL_CALL SfxFrameLoader_Impl::getImplementationName() throw( RuntimeException )
668*cdf0e10cSrcweir {
669*cdf0e10cSrcweir     return impl_getStaticImplementationName();
670*cdf0e10cSrcweir }
671*cdf0e10cSrcweir                                                                                                                                 \
672*cdf0e10cSrcweir /* XServiceInfo */
673*cdf0e10cSrcweir sal_Bool SAL_CALL SfxFrameLoader_Impl::supportsService( const UNOOUSTRING& sServiceName ) throw( RuntimeException )
674*cdf0e10cSrcweir {
675*cdf0e10cSrcweir     UNOSEQUENCE< UNOOUSTRING >  seqServiceNames =   getSupportedServiceNames();
676*cdf0e10cSrcweir     const UNOOUSTRING*          pArray          =   seqServiceNames.getConstArray();
677*cdf0e10cSrcweir     for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ )
678*cdf0e10cSrcweir     {
679*cdf0e10cSrcweir         if ( pArray[nCounter] == sServiceName )
680*cdf0e10cSrcweir         {
681*cdf0e10cSrcweir             return sal_True ;
682*cdf0e10cSrcweir         }
683*cdf0e10cSrcweir     }
684*cdf0e10cSrcweir     return sal_False ;
685*cdf0e10cSrcweir }
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir /* XServiceInfo */
688*cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > SAL_CALL SfxFrameLoader_Impl::getSupportedServiceNames() throw( RuntimeException )
689*cdf0e10cSrcweir {
690*cdf0e10cSrcweir     return impl_getStaticSupportedServiceNames();
691*cdf0e10cSrcweir }
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir /* Helper for XServiceInfo */
694*cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > SfxFrameLoader_Impl::impl_getStaticSupportedServiceNames()
695*cdf0e10cSrcweir {
696*cdf0e10cSrcweir     UNOMUTEXGUARD aGuard( UNOMUTEX::getGlobalMutex() );
697*cdf0e10cSrcweir     UNOSEQUENCE< UNOOUSTRING > seqServiceNames( 1 );
698*cdf0e10cSrcweir     seqServiceNames.getArray() [0] = UNOOUSTRING::createFromAscii( "com.sun.star.frame.SynchronousFrameLoader" );
699*cdf0e10cSrcweir     return seqServiceNames ;
700*cdf0e10cSrcweir }
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir /* Helper for XServiceInfo */
703*cdf0e10cSrcweir UNOOUSTRING SfxFrameLoader_Impl::impl_getStaticImplementationName()
704*cdf0e10cSrcweir {
705*cdf0e10cSrcweir     return UNOOUSTRING::createFromAscii( "com.sun.star.comp.office.FrameLoader" );
706*cdf0e10cSrcweir }
707*cdf0e10cSrcweir 
708*cdf0e10cSrcweir /* Helper for registry */
709*cdf0e10cSrcweir UNOREFERENCE< UNOXINTERFACE > SAL_CALL SfxFrameLoader_Impl::impl_createInstance( const UNOREFERENCE< UNOXMULTISERVICEFACTORY >& xServiceManager ) throw( UNOEXCEPTION )
710*cdf0e10cSrcweir {
711*cdf0e10cSrcweir     return UNOREFERENCE< UNOXINTERFACE >( *new SfxFrameLoader_Impl( xServiceManager ) );
712*cdf0e10cSrcweir }
713*cdf0e10cSrcweir 
714