1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dispatchprovider.cxx,v $
10 * $Revision: 1.37.82.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
36 //_________________________________________________________________________________________________________________
39 #include <dispatch/dispatchprovider.hxx>
40 #include <loadenv/loadenv.hxx>
41 #include <dispatch/loaddispatcher.hxx>
42 #include <dispatch/closedispatcher.hxx>
43 #include <dispatch/menudispatcher.hxx>
44 #include <dispatch/helpagentdispatcher.hxx>
45 #include <dispatch/startmoduledispatcher.hxx>
47 #include <pattern/window.hxx>
48 #include <threadhelp/transactionguard.hxx>
49 #include <threadhelp/readguard.hxx>
50 #include <threadhelp/writeguard.hxx>
51 #include <dispatchcommands.h>
52 #include <protocols.h>
57 //_________________________________________________________________________________________________________________
59 //_________________________________________________________________________________________________________________
60 #include <com/sun/star/frame/FrameSearchFlag.hpp>
61 #include <com/sun/star/uno/Exception.hpp>
62 #include <com/sun/star/ucb/XContentProviderManager.hpp>
63 #include <com/sun/star/document/XTypeDetection.hpp>
64 #include <com/sun/star/lang/XInitialization.hpp>
66 //_________________________________________________________________________________________________________________
67 // includes of other projects
68 //_________________________________________________________________________________________________________________
69 #include <osl/diagnose.h>
70 #include <rtl/string.h>
71 #include <rtl/ustring.hxx>
72 #include <vcl/svapp.hxx>
73 #include <rtl/ustrbuf.hxx>
74 //_________________________________________________________________________________________________________________
76 //_________________________________________________________________________________________________________________
80 //_________________________________________________________________________________________________________________
82 //_________________________________________________________________________________________________________________
84 //_________________________________________________________________________________________________________________
85 // non exported definitions
86 //_________________________________________________________________________________________________________________
88 //_________________________________________________________________________________________________________________
90 //_________________________________________________________________________________________________________________
92 //*****************************************************************************************************************
93 // XInterface, XTypeProvider
94 //*****************************************************************************************************************
95 DEFINE_XINTERFACE_2( DispatchProvider
,
97 DIRECT_INTERFACE(css::lang::XTypeProvider
),
98 DIRECT_INTERFACE(css::frame::XDispatchProvider
)
101 DEFINE_XTYPEPROVIDER_2( DispatchProvider
,
102 css::lang::XTypeProvider
,
103 css::frame::XDispatchProvider
106 //_________________________________________________________________________________________________________________
109 @short standard ctor/dtor
110 @descr These initialize a new instance of tihs class with needed informations for work.
111 We hold a weakreference to our owner frame which start dispatches at us.
112 We can't use a normal reference because he hold a reference of us too ...
113 nobody can die so ...!
115 @seealso using at owner
118 reference to servicemanager to create new services.
120 reference to our owner frame.
122 @modified 17.05.2002 10:07, as96863
124 DispatchProvider::DispatchProvider( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xFactory
,
125 const css::uno::Reference
< css::frame::XFrame
>& xFrame
)
126 // Init baseclasses first
127 : ThreadHelpBase( &Application::GetSolarMutex() )
130 , m_xFactory ( xFactory
)
131 , m_xFrame ( xFrame
)
135 //_________________________________________________________________________________________________________________
138 @short protected(!) dtor for deinitializing
139 @descr We made it protected to prevent using of us as base class instead as a member.
141 @modified 17.05.2002 10:05, as96863
143 DispatchProvider::~DispatchProvider()
147 //_________________________________________________________________________________________________________________
150 @interface XDispatchProvider
151 @short search a dispatcher for given URL
152 @descr If no interceptor is set on owner, we search for right frame and dispatch URL to it.
153 If no frame was found, we do nothing.
154 But we doesn't do it directly here. We detect the type of our owner frame and calls
155 specialized queryDispatch() helper dependen from that. Because a Desktop handle some
156 requests in another way then a normal frame.
160 @param sTargetFrameName
161 name of searched frame.
164 @return A reference to a dispatch object for this URL (if someone was found!).
167 @modified 17.05.2002 10:59, as96863
169 css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
DispatchProvider::queryDispatch( const css::util::URL
& aURL
,
170 const ::rtl::OUString
& sTargetFrameName
,
171 sal_Int32 nSearchFlags
) throw( css::uno::RuntimeException
)
173 css::uno::Reference
< css::frame::XDispatch
> xDispatcher
;
176 ReadGuard
aReadLock( m_aLock
);
177 css::uno::Reference
< css::frame::XFrame
> xOwner( m_xFrame
.get(), css::uno::UNO_QUERY
);
181 css::uno::Reference
< css::frame::XDesktop
> xDesktopCheck( xOwner
, css::uno::UNO_QUERY
);
183 if (xDesktopCheck
.is())
184 xDispatcher
= implts_queryDesktopDispatch(xOwner
, aURL
, sTargetFrameName
, nSearchFlags
);
186 xDispatcher
= implts_queryFrameDispatch(xOwner
, aURL
, sTargetFrameName
, nSearchFlags
);
191 //_________________________________________________________________________________________________________________
194 @interface XDispatchProvider
195 @short do the same like queryDispatch() ... but handle multiple dispatches at the same time
196 @descr It's an optimism. User give us a list of queries ... and we return a list of dispatcher.
197 If one of given queries couldn't be solved to a real existing dispatcher ...
198 we return a list with empty references in it! Order of both lists will be retained!
200 @seealso method queryDispatch()
203 a list of all dispatch parameters for multiple requests
204 @return A reference a list of dispatch objects for these URLs - may with some <NULL/> values inside.
207 @modified 17.05.2002 09:55, as96863
209 css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> > SAL_CALL
DispatchProvider::queryDispatches( const css::uno::Sequence
< css::frame::DispatchDescriptor
>& lDescriptions
) throw( css::uno::RuntimeException
)
211 // Create return list - which must have same size then the given descriptor
212 // It's not allowed to pack it!
213 sal_Int32 nCount
= lDescriptions
.getLength();
214 css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> > lDispatcher( nCount
);
216 // Step over all descriptors and try to get any dispatcher for it.
217 for( sal_Int32 i
=0; i
<nCount
; ++i
)
219 lDispatcher
[i
] = queryDispatch( lDescriptions
[i
].FeatureURL
,
220 lDescriptions
[i
].FrameName
,
221 lDescriptions
[i
].SearchFlags
);
227 //_________________________________________________________________________________________________________________
229 ::sal_Bool
lcl_isCloseDispatch (const css::util::URL
& aURL
)
232 (aURL
.Complete
.equals(CMD_UNO_CLOSEDOC
)) ||
233 (aURL
.Complete
.equals(CMD_UNO_CLOSEWIN
)) ||
234 (aURL
.Complete
.equals(CMD_UNO_CLOSEFRAME
))
238 //_________________________________________________________________________________________________________________
240 ::sal_Bool
lcl_isStartModuleDispatch (const css::util::URL
& aURL
)
242 return (aURL
.Complete
.equals(CMD_UNO_SHOWSTARTMODULE
));
245 //_________________________________________________________________________________________________________________
248 @short helper for queryDispatch()
249 @descr Every member of the frame tree (frame, desktop) must handle such request
250 in another way. So we implement different specialized metods for every one.
253 @modified 20.08.2003 08:32, as96863
255 css::uno::Reference
< css::frame::XDispatch
> DispatchProvider::implts_queryDesktopDispatch( const css::uno::Reference
< css::frame::XFrame
> xDesktop
,
256 const css::util::URL
& aURL
,
257 const ::rtl::OUString
& sTargetFrameName
,
258 sal_Int32 nSearchFlags
)
260 css::uno::Reference
< css::frame::XDispatch
> xDispatcher
;
262 // ignore wrong requests which are not supported
264 (sTargetFrameName
==SPECIALTARGET_MENUBAR
) || // valid for frame dispatches - not for desktop
265 (sTargetFrameName
==SPECIALTARGET_HELPAGENT
) || // valid for frame dispatches - not for desktop
266 (sTargetFrameName
==SPECIALTARGET_PARENT
) || // we have no parent by definition
267 (sTargetFrameName
==SPECIALTARGET_BEAMER
) // beamer frames are allowed as child of tasks only -
268 // and they exist more then ones. We have no idea which our sub tasks is the right one
274 //-----------------------------------------------------------------------------------------------------
275 // I) handle special cases which not right for using findFrame() first
276 //-----------------------------------------------------------------------------------------------------
278 //-----------------------------------------------------------------------------------------------------
280 // It's not the right place to create a new task here - because we are queried for a dispatch object
281 // only, which can handle such request. Such dispatcher should create the required task on demand.
282 // Normaly the functionality for "_blank" is provided by findFrame() - but that would create it directly
283 // here. Thats why we must "intercept" here.
284 //-----------------------------------------------------------------------------------------------------
285 if (sTargetFrameName
==SPECIALTARGET_BLANK
)
287 if (implts_isLoadableContent(aURL
))
288 xDispatcher
= implts_getOrCreateDispatchHelper( E_BLANKDISPATCHER
, xDesktop
);
291 //-----------------------------------------------------------------------------------------------------
293 // This is a combination of search an empty task for recycling - or create a new one.
294 //-----------------------------------------------------------------------------------------------------
296 if (sTargetFrameName
==SPECIALTARGET_DEFAULT
)
298 if (implts_isLoadableContent(aURL
))
299 xDispatcher
= implts_getOrCreateDispatchHelper( E_DEFAULTDISPATCHER
, xDesktop
);
301 if (lcl_isStartModuleDispatch(aURL
))
302 xDispatcher
= implts_getOrCreateDispatchHelper( E_STARTMODULEDISPATCHER
, xDesktop
);
305 //-----------------------------------------------------------------------------------------------------
306 // I.III) "_self", "", "_top"
307 // The desktop can't load any document - but he can handle some special protocols like "uno", "slot" ...
308 // Why is "top" here handled too? Because the desktop is the topest frame. Normaly it's superflous
309 // to use this target - but we can handle it in the same manner then "_self".
310 //-----------------------------------------------------------------------------------------------------
313 (sTargetFrameName
==SPECIALTARGET_SELF
) ||
314 (sTargetFrameName
==SPECIALTARGET_TOP
) ||
315 (sTargetFrameName
.getLength()<1 )
318 xDispatcher
= implts_searchProtocolHandler(aURL
);
321 //-----------------------------------------------------------------------------------------------------
322 // I.IV) no further special targets exist
323 // Now we have to search for the right target frame by calling findFrame() - but should provide our code
324 // against creation of a new task if no frame could be found.
325 // I said it b efore - it's allowed for dispatch() only.
326 //-----------------------------------------------------------------------------------------------------
329 sal_Int32 nRightFlags
= nSearchFlags
;
330 nRightFlags
&= ~css::frame::FrameSearchFlag::CREATE
;
332 // try to find any existing target and ask him for his dispatcher
333 css::uno::Reference
< css::frame::XFrame
> xFoundFrame
= xDesktop
->findFrame(sTargetFrameName
, nRightFlags
);
334 if (xFoundFrame
.is())
336 css::uno::Reference
< css::frame::XDispatchProvider
> xProvider( xFoundFrame
, css::uno::UNO_QUERY
);
337 xDispatcher
= xProvider
->queryDispatch(aURL
,SPECIALTARGET_SELF
,0);
340 // if it couldn't be found - but creation was allowed
341 // use special dispatcher for creatio or froward it to the browser
342 if (nSearchFlags
& css::frame::FrameSearchFlag::CREATE
)
343 xDispatcher
= implts_getOrCreateDispatchHelper( E_CREATEDISPATCHER
, xDesktop
, sTargetFrameName
, nSearchFlags
);
349 //_________________________________________________________________________________________________________________
351 css::uno::Reference
< css::frame::XDispatch
> DispatchProvider::implts_queryFrameDispatch( const css::uno::Reference
< css::frame::XFrame
> xFrame
,
352 const css::util::URL
& aURL
,
353 const ::rtl::OUString
& sTargetFrameName
,
354 sal_Int32 nSearchFlags
)
356 css::uno::Reference
< css::frame::XDispatch
> xDispatcher
;
358 //-----------------------------------------------------------------------------------------------------
359 // 0) Some URLs are dispatched in a generic way (e.g. by the menu) using the default target "".
360 // But they are specified to use her own fix target. Detect such URLs here and use the correct target.
361 //-----------------------------------------------------------------------------------------------------
363 ::rtl::OUString sTargetName
= sTargetFrameName
;
365 //-----------------------------------------------------------------------------------------------------
366 // I) handle special cases which not right for using findFrame() first
367 //-----------------------------------------------------------------------------------------------------
369 //-----------------------------------------------------------------------------------------------------
370 // I.I) "_blank", "_default"
371 // It's not the right place to create a new task here. Only the desktop can do that.
372 // Normaly the functionality for "_blank" is provided by findFrame() - but that would create it directly
373 // here. Thats why we must "intercept" here.
374 //-----------------------------------------------------------------------------------------------------
376 (sTargetName
==SPECIALTARGET_BLANK
) ||
377 (sTargetName
==SPECIALTARGET_DEFAULT
)
380 css::uno::Reference
< css::frame::XDispatchProvider
> xParent( xFrame
->getCreator(), css::uno::UNO_QUERY
);
382 xDispatcher
= xParent
->queryDispatch(aURL
, sTargetName
, 0); // its a special target - ignore search flags
385 //-----------------------------------------------------------------------------------------------------
387 // Special mode on frame or task to receive the local menu. Not supported by findFrame()
388 //-----------------------------------------------------------------------------------------------------
390 if (sTargetName
==SPECIALTARGET_MENUBAR
)
392 xDispatcher
= implts_getOrCreateDispatchHelper( E_MENUDISPATCHER
, xFrame
);
395 //-----------------------------------------------------------------------------------------------------
396 // I.III) "_helpagent"
397 // Special mode on frame or task to start the help agent.
398 // It's defined for top level frames only.
399 //-----------------------------------------------------------------------------------------------------
401 if (sTargetName
==SPECIALTARGET_HELPAGENT
)
403 if (WindowHelper::isTopWindow(xFrame
->getContainerWindow()))
404 xDispatcher
= implts_getOrCreateDispatchHelper( E_HELPAGENTDISPATCHER
, xFrame
);
407 // Don''t use findFrame() here - because it's not possible to find
408 // a top lebel frame without knowing his name. And a frame with name
409 // "" can't be realy searched! That's why forward query to any parent
411 css::uno::Reference
< css::frame::XDispatchProvider
> xProvider( xFrame
->getCreator(), css::uno::UNO_QUERY
);
413 xDispatcher
= xProvider
->queryDispatch(aURL
,SPECIALTARGET_HELPAGENT
,0);
417 //-----------------------------------------------------------------------------------------------------
418 // I.IV) "_helpagent"
419 // Special sub frame of a top frame only. Search or create it. ... OK it's currently a little bit HACKI.
420 // Only the sfx (means the controller) can create it it.
421 //-----------------------------------------------------------------------------------------------------
423 if (sTargetName
==SPECIALTARGET_BEAMER
)
425 css::uno::Reference
< css::frame::XDispatchProvider
> xBeamer( xFrame
->findFrame( SPECIALTARGET_BEAMER
, css::frame::FrameSearchFlag::CHILDREN
| css::frame::FrameSearchFlag::SELF
), css::uno::UNO_QUERY
);
428 xDispatcher
= xBeamer
->queryDispatch(aURL
, SPECIALTARGET_SELF
, 0);
432 css::uno::Reference
< css::frame::XDispatchProvider
> xController( xFrame
->getController(), css::uno::UNO_QUERY
);
433 if (xController
.is())
434 // force using of special target - but use original search flags
435 // May the caller used the CREATE flag or not!
436 xDispatcher
= xController
->queryDispatch(aURL
, SPECIALTARGET_BEAMER
, nSearchFlags
);
440 //-----------------------------------------------------------------------------------------------------
442 // Our parent frame (if it exist) should handle this URL.
443 //-----------------------------------------------------------------------------------------------------
445 if (sTargetName
==SPECIALTARGET_PARENT
)
447 css::uno::Reference
< css::frame::XDispatchProvider
> xParent( xFrame
->getCreator(), css::uno::UNO_QUERY
);
449 // SELF => we must adress the parent directly... and not his parent or any other parent!
450 xDispatcher
= xParent
->queryDispatch(aURL
, SPECIALTARGET_SELF
, 0);
453 //-----------------------------------------------------------------------------------------------------
455 // This request must be forwarded to any parent frame, till we reach a top frame.
456 // If no parent exist, we can handle itself.
457 //-----------------------------------------------------------------------------------------------------
459 if (sTargetName
==SPECIALTARGET_TOP
)
463 // If we are this top frame itself (means our owner frame)
464 // we should call ourself recursiv with a better target "_self".
465 // So we can share the same code! (see reaction for "_self" inside this method too.)
466 xDispatcher
= this->queryDispatch(aURL
,SPECIALTARGET_SELF
,0);
470 css::uno::Reference
< css::frame::XDispatchProvider
> xParent( xFrame
->getCreator(), css::uno::UNO_QUERY
);
471 // Normaly if isTop() returned FALSE ... the parent frame MUST(!) exist ...
472 // But it seams to be better to check that here to prevent us against an access violation.
474 xDispatcher
= xParent
->queryDispatch(aURL
, SPECIALTARGET_TOP
, 0);
478 //-----------------------------------------------------------------------------------------------------
479 // I.VII) "_self", ""
480 // Our owner frame should handle this URL. But we can't do it for all of them.
481 // So we ask the internal setted controller first. If he disagree we try to find a registered
482 // protocol handler. If this failed too - we check for a loadable content and in case of true
483 // we load it into the frame by returning specilized dispatch object.
484 //-----------------------------------------------------------------------------------------------------
487 (sTargetName
==SPECIALTARGET_SELF
) ||
488 (sTargetName
.getLength()<1 )
491 // There exist a hard coded interception for special URLs.
493 (aURL
.Complete
.equalsAscii(".uno:CloseDoc" )) ||
494 (aURL
.Complete
.equalsAscii(".uno:CloseWin" ))
497 css::uno::Reference
< css::frame::XDispatchProvider
> xParent( xFrame
->getCreator(), css::uno::UNO_QUERY
);
498 // In case the frame is not a top one, is not based on system window and has a parent,
499 // the parent frame should to be queried for the correct dispatcher.
502 !WindowHelper::isTopWindow(xFrame
->getContainerWindow()) &&
503 !VCLUnoHelper::GetWindow(xFrame
->getContainerWindow())->IsSystemWindow() &&
506 xDispatcher
= xParent
->queryDispatch(aURL
, SPECIALTARGET_SELF
, 0);
508 xDispatcher
= implts_getOrCreateDispatchHelper( E_CLOSEDISPATCHER
, xFrame
);
510 else if (aURL
.Complete
.equalsAscii(".uno:CloseFrame"))
511 xDispatcher
= implts_getOrCreateDispatchHelper( E_CLOSEDISPATCHER
, xFrame
);
513 if ( ! xDispatcher
.is())
515 // Ask our controller for his agreement for these dispatched URL ...
516 // because some URLs are internal and can be handled faster by SFX - which most is the current controller!
517 // But in case of e.g. the bibliography not all queries will be handled successfully here.
518 css::uno::Reference
< css::frame::XDispatchProvider
> xController( xFrame
->getController(), css::uno::UNO_QUERY
);
519 if (xController
.is())
520 xDispatcher
= xController
->queryDispatch(aURL
, SPECIALTARGET_SELF
, 0);
523 // If controller has no fun to dispatch these URL - we must search another right dispatcher.
524 // Search for any registered protocol handler first.
525 if (!xDispatcher
.is())
526 xDispatcher
= implts_searchProtocolHandler(aURL
);
528 // Not for controller - not for protocol handler
529 // It should be a loadable content - may be a file. Check it ...
530 // This check is neccessary to found out, that
531 // support for some protocols isn't installed by user. May be
532 // "ftp" isn't available. So we suppress creation of our self dispatcher.
533 // The result will be clear. He can't handle it - but he would try it.
535 ( ! xDispatcher
.is() ) &&
536 ( implts_isLoadableContent(aURL
) )
539 xDispatcher
= implts_getOrCreateDispatchHelper( E_SELFDISPATCHER
, xFrame
);
543 //-----------------------------------------------------------------------------------------------------
544 // I.VI) no further special handlings exist
545 // Now we have to search for the right target frame by calling findFrame() - but should provide our code
546 // against creation of a new task if no frame could be found.
547 // I said it before - it's allowed for dispatch() only.
548 //-----------------------------------------------------------------------------------------------------
551 sal_Int32 nRightFlags
= nSearchFlags
;
552 nRightFlags
&= ~css::frame::FrameSearchFlag::CREATE
;
554 // try to find any existing target and ask him for his dispatcher
555 css::uno::Reference
< css::frame::XFrame
> xFoundFrame
= xFrame
->findFrame(sTargetName
, nRightFlags
);
556 if (xFoundFrame
.is())
558 // Attention: Found target is our own owner frame!
559 // Don't ask him for his dispatcher. We know it already - it's our self dispatch helper.
560 // Otherwhise we can start a never ending recursiv call. Why?
561 // Somewere called our owner frame - he called some interceptor objects - and may by this dispatch provider
562 // is called. If wa use queryDispatch() on our owner frame again - we start this call stack again ... and again.
563 if (xFoundFrame
==xFrame
)
564 xDispatcher
= implts_getOrCreateDispatchHelper( E_SELFDISPATCHER
, xFrame
);
567 css::uno::Reference
< css::frame::XDispatchProvider
> xProvider( xFoundFrame
, css::uno::UNO_QUERY
);
568 xDispatcher
= xProvider
->queryDispatch(aURL
,SPECIALTARGET_SELF
,0);
572 // if it couldn't be found - but creation was allowed
573 // forward request to the desktop.
574 // Note: The given target name must be used to set the name on new created task!
575 // Don't forward request by changing it to a special one e.g _blank.
576 // Use the CREATE flag only to prevent call against further searches.
577 // We already know it - the target must be created new.
578 if (nSearchFlags
& css::frame::FrameSearchFlag::CREATE
)
580 css::uno::Reference
< css::frame::XDispatchProvider
> xParent( xFrame
->getCreator(), css::uno::UNO_QUERY
);
582 xDispatcher
= xParent
->queryDispatch(aURL
, sTargetName
, css::frame::FrameSearchFlag::CREATE
);
589 //_________________________________________________________________________________________________________________
592 @short search for a registered protocol handler and ask him for a dispatch object
593 @descr Wes earch a suitable handler inside our cfg package org.openoffice.Office.ProtocolHandler.
594 If we found anyone, we create and initialize it. Initialize means: we set our owner frame on it
595 as context information. He can use it or leave it. Of course - we are aware of handler implementations,
596 which doesn't support initialization. It's an optional feature.
599 the dispatch URL for which may a handler is registered
601 @return A dispatch object if a handler was found and agree with the given URL or <NULL/> otherwhise.
604 @modified 05.09.2002 13:43, as96863
606 css::uno::Reference
< css::frame::XDispatch
> DispatchProvider::implts_searchProtocolHandler( const css::util::URL
& aURL
)
608 css::uno::Reference
< css::frame::XDispatch
> xDispatcher
;
609 ProtocolHandler aHandler
;
611 // This member is threadsafe by himself and lives if we live - we doesn't need any mutex here.
612 if (m_aProtocolHandlerCache
.search(aURL
,&aHandler
))
615 ReadGuard
aReadLock( m_aLock
);
618 css::uno::Reference
< css::frame::XDispatchProvider
> xHandler
;
621 xHandler
= css::uno::Reference
< css::frame::XDispatchProvider
>(
622 m_xFactory
->createInstance(aHandler
.m_sUNOName
),
623 css::uno::UNO_QUERY
);
625 catch(css::uno::Exception
&) {}
627 // look if initialization is neccessary
628 css::uno::Reference
< css::lang::XInitialization
> xInit( xHandler
, css::uno::UNO_QUERY
);
631 css::uno::Reference
< css::frame::XFrame
> xOwner( m_xFrame
.get(), css::uno::UNO_QUERY
);
632 LOG_ASSERT(xOwner
.is(), "DispatchProvider::implts_searchProtocolHandler()\nCouldn't get reference to my owner frame. So I can't set may needed context information for this protocol handler.")
637 // but do it only, if all context informations are OK
638 css::uno::Sequence
< css::uno::Any
> lContext(1);
639 lContext
[0] <<= xOwner
;
640 xInit
->initialize(lContext
);
642 catch(css::uno::Exception
&) {}
649 // ask for his (sub)dispatcher for the given URL
651 xDispatcher
= xHandler
->queryDispatch(aURL
,SPECIALTARGET_SELF
,0);
657 //_________________________________________________________________________________________________________________
660 @short get or create new dispatch helper
661 @descr Sometimes we need some helper implementations to support dispatching of special URLs or commands.
662 But it's not a good idea to hold these services for the whole life time of this provider instance.
663 We should create it on demand ...
664 Thats why we implement this method. It return an already existing helper or create a new one otherwise.
666 @attention The parameter sTarget and nSearchFlags are defaulted to "" and 0!
667 Please use it only, if you can be shure, that the realy given by the outside calli!
668 Mostly it depends from the parameter eHelper is they are required or not.
671 specify the requested dispatch helper
673 the target of possible dispatch() call on created dispatch helper
675 the target parameter of the original queryDispatch() request
677 the flags parameter of the original queryDispatch() request
678 @return A reference to a dispatch helper.
681 @modified 20.08.2003 10:22, as96863
683 css::uno::Reference
< css::frame::XDispatch
> DispatchProvider::implts_getOrCreateDispatchHelper( EDispatchHelper eHelper
,
684 const css::uno::Reference
< css::frame::XFrame
>& xOwner
,
685 const ::rtl::OUString
& sTarget
,
686 sal_Int32 nSearchFlags
)
688 css::uno::Reference
< css::frame::XDispatch
> xDispatchHelper
;
691 ReadGuard
aReadLock( m_aLock
);
692 css::uno::Reference
< css::lang::XMultiServiceFactory
> xFactory
= m_xFactory
;
698 case E_MENUDISPATCHER
:
700 // Attention: Such menue dispatcher must be a singleton for this frame - means our owner frame.
701 // Otherwhise he can make some trouble.
703 WriteGuard
aWriteLock( m_aLock
);
704 if ( ! m_xMenuDispatcher
.is() )
706 MenuDispatcher
* pDispatcher
= new MenuDispatcher( xFactory
, xOwner
);
707 m_xMenuDispatcher
= css::uno::Reference
< css::frame::XDispatch
>( static_cast< ::cppu::OWeakObject
* >(pDispatcher
), css::uno::UNO_QUERY
);
709 xDispatchHelper
= m_xMenuDispatcher
;
715 case E_HELPAGENTDISPATCHER
:
717 // Attention: It's not a good idea to create this help agent twice for the same frame (window)
718 // May it will be shown twice too - and user activate the first one. Then he get the corresponding
719 // help window ... but there exist another help agent window on bottom side of the frame window.
720 // It's superflous. Create it on demand - but hold it alive till this provider dies.
722 WriteGuard
aWriteLock( m_aLock
);
723 if ( ! m_xHelpAgentDispatcher
.is() )
725 HelpAgentDispatcher
* pDispatcher
= new HelpAgentDispatcher( xOwner
);
726 m_xHelpAgentDispatcher
= css::uno::Reference
< css::frame::XDispatch
>( static_cast< ::cppu::OWeakObject
* >(pDispatcher
), css::uno::UNO_QUERY
);
728 xDispatchHelper
= m_xHelpAgentDispatcher
;
734 case E_CREATEDISPATCHER
:
736 LoadDispatcher
* pDispatcher
= new LoadDispatcher(xFactory
, xOwner
, sTarget
, nSearchFlags
);
737 xDispatchHelper
= css::uno::Reference
< css::frame::XDispatch
>( static_cast< ::cppu::OWeakObject
* >(pDispatcher
), css::uno::UNO_QUERY
);
741 case E_BLANKDISPATCHER
:
743 css::uno::Reference
< css::frame::XFrame
> xDesktop( xOwner
, css::uno::UNO_QUERY
);
746 LoadDispatcher
* pDispatcher
= new LoadDispatcher(xFactory
, xOwner
, SPECIALTARGET_BLANK
, 0);
747 xDispatchHelper
= css::uno::Reference
< css::frame::XDispatch
>( static_cast< ::cppu::OWeakObject
* >(pDispatcher
), css::uno::UNO_QUERY
);
752 case E_DEFAULTDISPATCHER
:
754 css::uno::Reference
< css::frame::XFrame
> xDesktop( xOwner
, css::uno::UNO_QUERY
);
757 LoadDispatcher
* pDispatcher
= new LoadDispatcher(xFactory
, xOwner
, SPECIALTARGET_DEFAULT
, 0);
758 xDispatchHelper
= css::uno::Reference
< css::frame::XDispatch
>( static_cast< ::cppu::OWeakObject
* >(pDispatcher
), css::uno::UNO_QUERY
);
763 case E_SELFDISPATCHER
:
765 LoadDispatcher
* pDispatcher
= new LoadDispatcher(xFactory
, xOwner
, SPECIALTARGET_SELF
, 0);
766 xDispatchHelper
= css::uno::Reference
< css::frame::XDispatch
>( static_cast< ::cppu::OWeakObject
* >(pDispatcher
), css::uno::UNO_QUERY
);
770 case E_CLOSEDISPATCHER
:
772 CloseDispatcher
* pDispatcher
= new CloseDispatcher( xFactory
, xOwner
, sTarget
);
773 xDispatchHelper
= css::uno::Reference
< css::frame::XDispatch
>( static_cast< ::cppu::OWeakObject
* >(pDispatcher
), css::uno::UNO_QUERY
);
777 case E_STARTMODULEDISPATCHER
:
779 StartModuleDispatcher
* pDispatcher
= new StartModuleDispatcher( xFactory
, xOwner
, sTarget
);
780 xDispatchHelper
= css::uno::Reference
< css::frame::XDispatch
>( static_cast< ::cppu::OWeakObject
* >(pDispatcher
), css::uno::UNO_QUERY
);
785 return xDispatchHelper
;
788 //_________________________________________________________________________________________________________________
791 @short check URL for support by our used loader or handler
792 @descr If we must return our own dispatch helper implementations (self, blank, create dispatcher!)
793 we should be shure, that URL describe any loadable content. Otherwise slot/uno URLs
794 will be detected ... but there exist nothing for ral loading into a target frame!
797 URL which should be "detected"
798 @return <TRUE/> if somewhere could handle that - <FALSE/> otherwise.
801 @modified 17.05.2002 09:47, as96863
803 sal_Bool
DispatchProvider::implts_isLoadableContent( const css::util::URL
& aURL
)
805 LoadEnv::EContentType eType
= LoadEnv::classifyContent(aURL
.Complete
, css::uno::Sequence
< css::beans::PropertyValue
>());
806 return ( eType
== LoadEnv::E_CAN_BE_LOADED
);
809 } // namespace framework