Update ooo320-m1
[ooovba.git] / framework / source / dispatch / dispatchprovider.cxx
blob1dfee32e85b01369d7bc914ae66b65fd84f7d29e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
38 #include <stdio.h>
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>
53 #include <services.h>
54 #include <targets.h>
55 #include <general.h>
57 //_________________________________________________________________________________________________________________
58 // interface includes
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 //_________________________________________________________________________________________________________________
75 // namespace
76 //_________________________________________________________________________________________________________________
78 namespace framework{
80 //_________________________________________________________________________________________________________________
81 // non exported const
82 //_________________________________________________________________________________________________________________
84 //_________________________________________________________________________________________________________________
85 // non exported definitions
86 //_________________________________________________________________________________________________________________
88 //_________________________________________________________________________________________________________________
89 // declarations
90 //_________________________________________________________________________________________________________________
92 //*****************************************************************************************************************
93 // XInterface, XTypeProvider
94 //*****************************************************************************************************************
95 DEFINE_XINTERFACE_2( DispatchProvider ,
96 OWeakObject ,
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
117 @param xFactory
118 reference to servicemanager to create new services.
119 @param xFrame
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() )
128 , OWeakObject ( )
129 // Init member
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.
158 @param aURL
159 URL to dispatch.
160 @param sTargetFrameName
161 name of searched frame.
162 @param nSearchFlags
163 flags for searching.
164 @return A reference to a dispatch object for this URL (if someone was found!).
166 @threadsafe yes
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;
175 /* SAFE { */
176 ReadGuard aReadLock( m_aLock );
177 css::uno::Reference< css::frame::XFrame > xOwner( m_xFrame.get(), css::uno::UNO_QUERY );
178 aReadLock.unlock();
179 /* } SAFE */
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);
185 else
186 xDispatcher = implts_queryFrameDispatch(xOwner, aURL, sTargetFrameName, nSearchFlags);
188 return xDispatcher;
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()
202 @param lDescriptions
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.
206 @threadsafe yes
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 );
224 return lDispatcher;
227 //_________________________________________________________________________________________________________________
229 ::sal_Bool lcl_isStartModuleDispatch (const css::util::URL& aURL)
231 return (aURL.Complete.equals(CMD_UNO_SHOWSTARTMODULE));
234 //_________________________________________________________________________________________________________________
237 @short helper for queryDispatch()
238 @descr Every member of the frame tree (frame, desktop) must handle such request
239 in another way. So we implement different specialized metods for every one.
241 @threadsafe yes
242 @modified 20.08.2003 08:32, as96863
244 css::uno::Reference< css::frame::XDispatch > DispatchProvider::implts_queryDesktopDispatch( const css::uno::Reference< css::frame::XFrame > xDesktop ,
245 const css::util::URL& aURL ,
246 const ::rtl::OUString& sTargetFrameName ,
247 sal_Int32 nSearchFlags )
249 css::uno::Reference< css::frame::XDispatch > xDispatcher;
251 // ignore wrong requests which are not supported
252 if (
253 (sTargetFrameName==SPECIALTARGET_MENUBAR ) || // valid for frame dispatches - not for desktop
254 (sTargetFrameName==SPECIALTARGET_HELPAGENT) || // valid for frame dispatches - not for desktop
255 (sTargetFrameName==SPECIALTARGET_PARENT ) || // we have no parent by definition
256 (sTargetFrameName==SPECIALTARGET_BEAMER ) // beamer frames are allowed as child of tasks only -
257 // and they exist more then ones. We have no idea which our sub tasks is the right one
260 return NULL;
263 //-----------------------------------------------------------------------------------------------------
264 // I) handle special cases which not right for using findFrame() first
265 //-----------------------------------------------------------------------------------------------------
267 //-----------------------------------------------------------------------------------------------------
268 // I.I) "_blank"
269 // It's not the right place to create a new task here - because we are queried for a dispatch object
270 // only, which can handle such request. Such dispatcher should create the required task on demand.
271 // Normaly the functionality for "_blank" is provided by findFrame() - but that would create it directly
272 // here. Thats why we must "intercept" here.
273 //-----------------------------------------------------------------------------------------------------
274 if (sTargetFrameName==SPECIALTARGET_BLANK)
276 if (implts_isLoadableContent(aURL))
277 xDispatcher = implts_getOrCreateDispatchHelper( E_BLANKDISPATCHER, xDesktop );
280 //-----------------------------------------------------------------------------------------------------
281 // I.II) "_default"
282 // This is a combination of search an empty task for recycling - or create a new one.
283 //-----------------------------------------------------------------------------------------------------
284 else
285 if (sTargetFrameName==SPECIALTARGET_DEFAULT)
287 if (implts_isLoadableContent(aURL))
288 xDispatcher = implts_getOrCreateDispatchHelper( E_DEFAULTDISPATCHER, xDesktop );
290 if (lcl_isStartModuleDispatch(aURL))
291 xDispatcher = implts_getOrCreateDispatchHelper( E_STARTMODULEDISPATCHER, xDesktop );
294 //-----------------------------------------------------------------------------------------------------
295 // I.III) "_self", "", "_top"
296 // The desktop can't load any document - but he can handle some special protocols like "uno", "slot" ...
297 // Why is "top" here handled too? Because the desktop is the topest frame. Normaly it's superflous
298 // to use this target - but we can handle it in the same manner then "_self".
299 //-----------------------------------------------------------------------------------------------------
300 else
301 if (
302 (sTargetFrameName==SPECIALTARGET_SELF) ||
303 (sTargetFrameName==SPECIALTARGET_TOP ) ||
304 (sTargetFrameName.getLength()<1 )
307 xDispatcher = implts_searchProtocolHandler(aURL);
310 //-----------------------------------------------------------------------------------------------------
311 // I.IV) no further special targets exist
312 // Now we have to search for the right target frame by calling findFrame() - but should provide our code
313 // against creation of a new task if no frame could be found.
314 // I said it b efore - it's allowed for dispatch() only.
315 //-----------------------------------------------------------------------------------------------------
316 else
318 sal_Int32 nRightFlags = nSearchFlags;
319 nRightFlags &= ~css::frame::FrameSearchFlag::CREATE;
321 // try to find any existing target and ask him for his dispatcher
322 css::uno::Reference< css::frame::XFrame > xFoundFrame = xDesktop->findFrame(sTargetFrameName, nRightFlags);
323 if (xFoundFrame.is())
325 css::uno::Reference< css::frame::XDispatchProvider > xProvider( xFoundFrame, css::uno::UNO_QUERY );
326 xDispatcher = xProvider->queryDispatch(aURL,SPECIALTARGET_SELF,0);
328 else
329 // if it couldn't be found - but creation was allowed
330 // use special dispatcher for creatio or froward it to the browser
331 if (nSearchFlags & css::frame::FrameSearchFlag::CREATE)
332 xDispatcher = implts_getOrCreateDispatchHelper( E_CREATEDISPATCHER, xDesktop, sTargetFrameName, nSearchFlags );
335 return xDispatcher;
338 //_________________________________________________________________________________________________________________
340 css::uno::Reference< css::frame::XDispatch > DispatchProvider::implts_queryFrameDispatch( const css::uno::Reference< css::frame::XFrame > xFrame ,
341 const css::util::URL& aURL ,
342 const ::rtl::OUString& sTargetFrameName ,
343 sal_Int32 nSearchFlags )
345 css::uno::Reference< css::frame::XDispatch > xDispatcher;
347 //-----------------------------------------------------------------------------------------------------
348 // 0) Some URLs are dispatched in a generic way (e.g. by the menu) using the default target "".
349 // But they are specified to use her own fix target. Detect such URLs here and use the correct target.
350 //-----------------------------------------------------------------------------------------------------
352 ::rtl::OUString sTargetName = sTargetFrameName;
354 //-----------------------------------------------------------------------------------------------------
355 // I) handle special cases which not right for using findFrame() first
356 //-----------------------------------------------------------------------------------------------------
358 //-----------------------------------------------------------------------------------------------------
359 // I.I) "_blank", "_default"
360 // It's not the right place to create a new task here. Only the desktop can do that.
361 // Normaly the functionality for "_blank" is provided by findFrame() - but that would create it directly
362 // here. Thats why we must "intercept" here.
363 //-----------------------------------------------------------------------------------------------------
364 if (
365 (sTargetName==SPECIALTARGET_BLANK ) ||
366 (sTargetName==SPECIALTARGET_DEFAULT)
369 css::uno::Reference< css::frame::XDispatchProvider > xParent( xFrame->getCreator(), css::uno::UNO_QUERY );
370 if (xParent.is())
371 xDispatcher = xParent->queryDispatch(aURL, sTargetName, 0); // its a special target - ignore search flags
374 //-----------------------------------------------------------------------------------------------------
375 // I.II) "_menubar"
376 // Special mode on frame or task to receive the local menu. Not supported by findFrame()
377 //-----------------------------------------------------------------------------------------------------
378 else
379 if (sTargetName==SPECIALTARGET_MENUBAR)
381 xDispatcher = implts_getOrCreateDispatchHelper( E_MENUDISPATCHER, xFrame );
384 //-----------------------------------------------------------------------------------------------------
385 // I.III) "_helpagent"
386 // Special mode on frame or task to start the help agent.
387 // It's defined for top level frames only.
388 //-----------------------------------------------------------------------------------------------------
389 else
390 if (sTargetName==SPECIALTARGET_HELPAGENT)
392 if (WindowHelper::isTopWindow(xFrame->getContainerWindow()))
393 xDispatcher = implts_getOrCreateDispatchHelper( E_HELPAGENTDISPATCHER, xFrame );
394 else
396 // Don''t use findFrame() here - because it's not possible to find
397 // a top lebel frame without knowing his name. And a frame with name
398 // "" can't be realy searched! That's why forward query to any parent
399 // explicitly.
400 css::uno::Reference< css::frame::XDispatchProvider > xProvider( xFrame->getCreator(), css::uno::UNO_QUERY );
401 if (xProvider.is())
402 xDispatcher = xProvider->queryDispatch(aURL,SPECIALTARGET_HELPAGENT,0);
406 //-----------------------------------------------------------------------------------------------------
407 // I.IV) "_helpagent"
408 // Special sub frame of a top frame only. Search or create it. ... OK it's currently a little bit HACKI.
409 // Only the sfx (means the controller) can create it it.
410 //-----------------------------------------------------------------------------------------------------
411 else
412 if (sTargetName==SPECIALTARGET_BEAMER)
414 css::uno::Reference< css::frame::XDispatchProvider > xBeamer( xFrame->findFrame( SPECIALTARGET_BEAMER, css::frame::FrameSearchFlag::CHILDREN | css::frame::FrameSearchFlag::SELF ), css::uno::UNO_QUERY );
415 if (xBeamer.is())
417 xDispatcher = xBeamer->queryDispatch(aURL, SPECIALTARGET_SELF, 0);
419 else
421 css::uno::Reference< css::frame::XDispatchProvider > xController( xFrame->getController(), css::uno::UNO_QUERY );
422 if (xController.is())
423 // force using of special target - but use original search flags
424 // May the caller used the CREATE flag or not!
425 xDispatcher = xController->queryDispatch(aURL, SPECIALTARGET_BEAMER, nSearchFlags);
429 //-----------------------------------------------------------------------------------------------------
430 // I.V) "_parent"
431 // Our parent frame (if it exist) should handle this URL.
432 //-----------------------------------------------------------------------------------------------------
433 else
434 if (sTargetName==SPECIALTARGET_PARENT)
436 css::uno::Reference< css::frame::XDispatchProvider > xParent( xFrame->getCreator(), css::uno::UNO_QUERY );
437 if (xParent.is())
438 // SELF => we must adress the parent directly... and not his parent or any other parent!
439 xDispatcher = xParent->queryDispatch(aURL, SPECIALTARGET_SELF, 0);
442 //-----------------------------------------------------------------------------------------------------
443 // I.VI) "_top"
444 // This request must be forwarded to any parent frame, till we reach a top frame.
445 // If no parent exist, we can handle itself.
446 //-----------------------------------------------------------------------------------------------------
447 else
448 if (sTargetName==SPECIALTARGET_TOP)
450 if (xFrame->isTop())
452 // If we are this top frame itself (means our owner frame)
453 // we should call ourself recursiv with a better target "_self".
454 // So we can share the same code! (see reaction for "_self" inside this method too.)
455 xDispatcher = this->queryDispatch(aURL,SPECIALTARGET_SELF,0);
457 else
459 css::uno::Reference< css::frame::XDispatchProvider > xParent( xFrame->getCreator(), css::uno::UNO_QUERY );
460 // Normaly if isTop() returned FALSE ... the parent frame MUST(!) exist ...
461 // But it seams to be better to check that here to prevent us against an access violation.
462 if (xParent.is())
463 xDispatcher = xParent->queryDispatch(aURL, SPECIALTARGET_TOP, 0);
467 //-----------------------------------------------------------------------------------------------------
468 // I.VII) "_self", ""
469 // Our owner frame should handle this URL. But we can't do it for all of them.
470 // So we ask the internal setted controller first. If he disagree we try to find a registered
471 // protocol handler. If this failed too - we check for a loadable content and in case of true
472 // we load it into the frame by returning specilized dispatch object.
473 //-----------------------------------------------------------------------------------------------------
474 else
475 if (
476 (sTargetName==SPECIALTARGET_SELF) ||
477 (sTargetName.getLength()<1 )
480 // There exist a hard coded interception for special URLs.
481 if (
482 (aURL.Complete.equalsAscii(".uno:CloseDoc" )) ||
483 (aURL.Complete.equalsAscii(".uno:CloseWin" ))
486 css::uno::Reference< css::frame::XDispatchProvider > xParent( xFrame->getCreator(), css::uno::UNO_QUERY );
487 // In case the frame is not a top one, is not based on system window and has a parent,
488 // the parent frame should to be queried for the correct dispatcher.
489 // See i93473
490 if (
491 !WindowHelper::isTopWindow(xFrame->getContainerWindow()) &&
492 !VCLUnoHelper::GetWindow(xFrame->getContainerWindow())->IsSystemWindow() &&
493 xParent.is()
495 xDispatcher = xParent->queryDispatch(aURL, SPECIALTARGET_SELF, 0);
496 else
497 xDispatcher = implts_getOrCreateDispatchHelper( E_CLOSEDISPATCHER, xFrame );
499 else if (aURL.Complete.equalsAscii(".uno:CloseFrame"))
500 xDispatcher = implts_getOrCreateDispatchHelper( E_CLOSEDISPATCHER, xFrame );
502 if ( ! xDispatcher.is())
504 // Ask our controller for his agreement for these dispatched URL ...
505 // because some URLs are internal and can be handled faster by SFX - which most is the current controller!
506 // But in case of e.g. the bibliography not all queries will be handled successfully here.
507 css::uno::Reference< css::frame::XDispatchProvider > xController( xFrame->getController(), css::uno::UNO_QUERY );
508 if (xController.is())
509 xDispatcher = xController->queryDispatch(aURL, SPECIALTARGET_SELF, 0);
512 // If controller has no fun to dispatch these URL - we must search another right dispatcher.
513 // Search for any registered protocol handler first.
514 if (!xDispatcher.is())
515 xDispatcher = implts_searchProtocolHandler(aURL);
517 // Not for controller - not for protocol handler
518 // It should be a loadable content - may be a file. Check it ...
519 // This check is neccessary to found out, that
520 // support for some protocols isn't installed by user. May be
521 // "ftp" isn't available. So we suppress creation of our self dispatcher.
522 // The result will be clear. He can't handle it - but he would try it.
523 if (
524 ( ! xDispatcher.is() ) &&
525 ( implts_isLoadableContent(aURL) )
528 xDispatcher = implts_getOrCreateDispatchHelper( E_SELFDISPATCHER, xFrame );
532 //-----------------------------------------------------------------------------------------------------
533 // I.VI) no further special handlings exist
534 // Now we have to search for the right target frame by calling findFrame() - but should provide our code
535 // against creation of a new task if no frame could be found.
536 // I said it before - it's allowed for dispatch() only.
537 //-----------------------------------------------------------------------------------------------------
538 else
540 sal_Int32 nRightFlags = nSearchFlags;
541 nRightFlags &= ~css::frame::FrameSearchFlag::CREATE;
543 // try to find any existing target and ask him for his dispatcher
544 css::uno::Reference< css::frame::XFrame > xFoundFrame = xFrame->findFrame(sTargetName, nRightFlags);
545 if (xFoundFrame.is())
547 // Attention: Found target is our own owner frame!
548 // Don't ask him for his dispatcher. We know it already - it's our self dispatch helper.
549 // Otherwhise we can start a never ending recursiv call. Why?
550 // Somewere called our owner frame - he called some interceptor objects - and may by this dispatch provider
551 // is called. If wa use queryDispatch() on our owner frame again - we start this call stack again ... and again.
552 if (xFoundFrame==xFrame)
553 xDispatcher = implts_getOrCreateDispatchHelper( E_SELFDISPATCHER, xFrame );
554 else
556 css::uno::Reference< css::frame::XDispatchProvider > xProvider( xFoundFrame, css::uno::UNO_QUERY );
557 xDispatcher = xProvider->queryDispatch(aURL,SPECIALTARGET_SELF,0);
560 else
561 // if it couldn't be found - but creation was allowed
562 // forward request to the desktop.
563 // Note: The given target name must be used to set the name on new created task!
564 // Don't forward request by changing it to a special one e.g _blank.
565 // Use the CREATE flag only to prevent call against further searches.
566 // We already know it - the target must be created new.
567 if (nSearchFlags & css::frame::FrameSearchFlag::CREATE)
569 css::uno::Reference< css::frame::XDispatchProvider > xParent( xFrame->getCreator(), css::uno::UNO_QUERY );
570 if (xParent.is())
571 xDispatcher = xParent->queryDispatch(aURL, sTargetName, css::frame::FrameSearchFlag::CREATE);
575 return xDispatcher;
578 //_________________________________________________________________________________________________________________
581 @short search for a registered protocol handler and ask him for a dispatch object
582 @descr Wes earch a suitable handler inside our cfg package org.openoffice.Office.ProtocolHandler.
583 If we found anyone, we create and initialize it. Initialize means: we set our owner frame on it
584 as context information. He can use it or leave it. Of course - we are aware of handler implementations,
585 which doesn't support initialization. It's an optional feature.
587 @param aURL
588 the dispatch URL for which may a handler is registered
590 @return A dispatch object if a handler was found and agree with the given URL or <NULL/> otherwhise.
592 @threadsafe yes
593 @modified 05.09.2002 13:43, as96863
595 css::uno::Reference< css::frame::XDispatch > DispatchProvider::implts_searchProtocolHandler( const css::util::URL& aURL )
597 css::uno::Reference< css::frame::XDispatch > xDispatcher;
598 ProtocolHandler aHandler ;
600 // This member is threadsafe by himself and lives if we live - we doesn't need any mutex here.
601 if (m_aProtocolHandlerCache.search(aURL,&aHandler))
603 /* SAFE { */
604 ReadGuard aReadLock( m_aLock );
606 // create it
607 css::uno::Reference< css::frame::XDispatchProvider > xHandler;
610 xHandler = css::uno::Reference< css::frame::XDispatchProvider >(
611 m_xFactory->createInstance(aHandler.m_sUNOName),
612 css::uno::UNO_QUERY);
614 catch(css::uno::Exception&) {}
616 // look if initialization is neccessary
617 css::uno::Reference< css::lang::XInitialization > xInit( xHandler, css::uno::UNO_QUERY );
618 if (xInit.is())
620 css::uno::Reference< css::frame::XFrame > xOwner( m_xFrame.get(), css::uno::UNO_QUERY );
621 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.")
622 if (xOwner.is())
626 // but do it only, if all context informations are OK
627 css::uno::Sequence< css::uno::Any > lContext(1);
628 lContext[0] <<= xOwner;
629 xInit->initialize(lContext);
631 catch(css::uno::Exception&) {}
635 aReadLock.unlock();
636 /* } SAFE */
638 // ask for his (sub)dispatcher for the given URL
639 if (xHandler.is())
640 xDispatcher = xHandler->queryDispatch(aURL,SPECIALTARGET_SELF,0);
643 return xDispatcher;
646 //_________________________________________________________________________________________________________________
649 @short get or create new dispatch helper
650 @descr Sometimes we need some helper implementations to support dispatching of special URLs or commands.
651 But it's not a good idea to hold these services for the whole life time of this provider instance.
652 We should create it on demand ...
653 Thats why we implement this method. It return an already existing helper or create a new one otherwise.
655 @attention The parameter sTarget and nSearchFlags are defaulted to "" and 0!
656 Please use it only, if you can be shure, that the realy given by the outside calli!
657 Mostly it depends from the parameter eHelper is they are required or not.
659 @param eHelper
660 specify the requested dispatch helper
661 @param xOwner
662 the target of possible dispatch() call on created dispatch helper
663 @param sTarget
664 the target parameter of the original queryDispatch() request
665 @param nSearchFlags
666 the flags parameter of the original queryDispatch() request
667 @return A reference to a dispatch helper.
669 @threadsafe yes
670 @modified 20.08.2003 10:22, as96863
672 css::uno::Reference< css::frame::XDispatch > DispatchProvider::implts_getOrCreateDispatchHelper( EDispatchHelper eHelper ,
673 const css::uno::Reference< css::frame::XFrame >& xOwner ,
674 const ::rtl::OUString& sTarget ,
675 sal_Int32 nSearchFlags)
677 css::uno::Reference< css::frame::XDispatch > xDispatchHelper;
679 /* SAFE { */
680 ReadGuard aReadLock( m_aLock );
681 css::uno::Reference< css::lang::XMultiServiceFactory > xFactory = m_xFactory;
682 aReadLock.unlock();
683 /* } SAFE */
685 switch (eHelper)
687 case E_MENUDISPATCHER :
689 // Attention: Such menue dispatcher must be a singleton for this frame - means our owner frame.
690 // Otherwhise he can make some trouble.
691 /* SAFE { */
692 WriteGuard aWriteLock( m_aLock );
693 if ( ! m_xMenuDispatcher.is() )
695 MenuDispatcher* pDispatcher = new MenuDispatcher( xFactory, xOwner );
696 m_xMenuDispatcher = css::uno::Reference< css::frame::XDispatch >( static_cast< ::cppu::OWeakObject* >(pDispatcher), css::uno::UNO_QUERY );
698 xDispatchHelper = m_xMenuDispatcher;
699 aWriteLock.unlock();
700 /* } SAFE */
702 break;
704 case E_HELPAGENTDISPATCHER :
706 // Attention: It's not a good idea to create this help agent twice for the same frame (window)
707 // May it will be shown twice too - and user activate the first one. Then he get the corresponding
708 // help window ... but there exist another help agent window on bottom side of the frame window.
709 // It's superflous. Create it on demand - but hold it alive till this provider dies.
710 /* SAFE { */
711 WriteGuard aWriteLock( m_aLock );
712 if ( ! m_xHelpAgentDispatcher.is() )
714 HelpAgentDispatcher* pDispatcher = new HelpAgentDispatcher( xOwner );
715 m_xHelpAgentDispatcher = css::uno::Reference< css::frame::XDispatch >( static_cast< ::cppu::OWeakObject* >(pDispatcher), css::uno::UNO_QUERY );
717 xDispatchHelper = m_xHelpAgentDispatcher;
718 aWriteLock.unlock();
719 /* } SAFE */
721 break;
723 case E_CREATEDISPATCHER :
725 LoadDispatcher* pDispatcher = new LoadDispatcher(xFactory, xOwner, sTarget, nSearchFlags);
726 xDispatchHelper = css::uno::Reference< css::frame::XDispatch >( static_cast< ::cppu::OWeakObject* >(pDispatcher), css::uno::UNO_QUERY );
728 break;
730 case E_BLANKDISPATCHER :
732 css::uno::Reference< css::frame::XFrame > xDesktop( xOwner, css::uno::UNO_QUERY );
733 if (xDesktop.is())
735 LoadDispatcher* pDispatcher = new LoadDispatcher(xFactory, xOwner, SPECIALTARGET_BLANK, 0);
736 xDispatchHelper = css::uno::Reference< css::frame::XDispatch >( static_cast< ::cppu::OWeakObject* >(pDispatcher), css::uno::UNO_QUERY );
739 break;
741 case E_DEFAULTDISPATCHER :
743 css::uno::Reference< css::frame::XFrame > xDesktop( xOwner, css::uno::UNO_QUERY );
744 if (xDesktop.is())
746 LoadDispatcher* pDispatcher = new LoadDispatcher(xFactory, xOwner, SPECIALTARGET_DEFAULT, 0);
747 xDispatchHelper = css::uno::Reference< css::frame::XDispatch >( static_cast< ::cppu::OWeakObject* >(pDispatcher), css::uno::UNO_QUERY );
750 break;
752 case E_SELFDISPATCHER :
754 LoadDispatcher* pDispatcher = new LoadDispatcher(xFactory, xOwner, SPECIALTARGET_SELF, 0);
755 xDispatchHelper = css::uno::Reference< css::frame::XDispatch >( static_cast< ::cppu::OWeakObject* >(pDispatcher), css::uno::UNO_QUERY );
757 break;
759 case E_CLOSEDISPATCHER :
761 CloseDispatcher* pDispatcher = new CloseDispatcher( xFactory, xOwner, sTarget );
762 xDispatchHelper = css::uno::Reference< css::frame::XDispatch >( static_cast< ::cppu::OWeakObject* >(pDispatcher), css::uno::UNO_QUERY );
764 break;
766 case E_STARTMODULEDISPATCHER :
768 StartModuleDispatcher* pDispatcher = new StartModuleDispatcher( xFactory, xOwner, sTarget );
769 xDispatchHelper = css::uno::Reference< css::frame::XDispatch >( static_cast< ::cppu::OWeakObject* >(pDispatcher), css::uno::UNO_QUERY );
771 break;
774 return xDispatchHelper;
777 //_________________________________________________________________________________________________________________
780 @short check URL for support by our used loader or handler
781 @descr If we must return our own dispatch helper implementations (self, blank, create dispatcher!)
782 we should be shure, that URL describe any loadable content. Otherwise slot/uno URLs
783 will be detected ... but there exist nothing for ral loading into a target frame!
785 @param aURL
786 URL which should be "detected"
787 @return <TRUE/> if somewhere could handle that - <FALSE/> otherwise.
789 @threadsafe yes
790 @modified 17.05.2002 09:47, as96863
792 sal_Bool DispatchProvider::implts_isLoadableContent( const css::util::URL& aURL )
794 LoadEnv::EContentType eType = LoadEnv::classifyContent(aURL.Complete, css::uno::Sequence< css::beans::PropertyValue >());
795 return ( eType == LoadEnv::E_CAN_BE_LOADED );
798 } // namespace framework