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 #ifndef __FRAMEWORK_HELPER_INTERCEPTIONHELPER_HXX_ 29*cdf0e10cSrcweir #define __FRAMEWORK_HELPER_INTERCEPTIONHELPER_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 32*cdf0e10cSrcweir // my own includes 33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <services/frame.hxx> 36*cdf0e10cSrcweir #include <threadhelp/threadhelpbase.hxx> 37*cdf0e10cSrcweir #include <macros/xinterface.hxx> 38*cdf0e10cSrcweir #include <macros/generic.hxx> 39*cdf0e10cSrcweir #include <macros/debug.hxx> 40*cdf0e10cSrcweir #include <general.h> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 43*cdf0e10cSrcweir // interface includes 44*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 45*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/frame/DispatchDescriptor.hpp> 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 54*cdf0e10cSrcweir // other includes 55*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 56*cdf0e10cSrcweir #include <tools/wldcrd.hxx> 57*cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 58*cdf0e10cSrcweir #include <cppuhelper/weakref.hxx> 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #ifndef __SGI_STL_DEQUE 61*cdf0e10cSrcweir #include <deque> 62*cdf0e10cSrcweir #endif 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 65*cdf0e10cSrcweir // namespace 66*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir namespace framework{ 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 71*cdf0e10cSrcweir // exported const 72*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir //_________________________________________________________ 75*cdf0e10cSrcweir // definitions 76*cdf0e10cSrcweir //_________________________________________________________ 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir /** @short implements a helper to support interception with additional functionality. 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir @descr This helper implements the complete XDispatchProviderInterception interface with 81*cdf0e10cSrcweir master/slave functionality AND using of optional features like registration of URL pattern! 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir @attention Don't use this class as direct member - use it dynamicly. Do not derive from this class. 84*cdf0e10cSrcweir We hold a weakreference to ouer owner not to ouer superclass. 85*cdf0e10cSrcweir */ 86*cdf0e10cSrcweir class InterceptionHelper : public css::frame::XDispatchProvider 87*cdf0e10cSrcweir , public css::frame::XDispatchProviderInterception 88*cdf0e10cSrcweir , public css::lang::XEventListener 89*cdf0e10cSrcweir // order of base classes is important for right initialization of mutex member! 90*cdf0e10cSrcweir , private ThreadHelpBase 91*cdf0e10cSrcweir , public ::cppu::OWeakObject 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir //_____________________________________________________ 94*cdf0e10cSrcweir // structs, helper 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir /** @short bind an interceptor component to it's URL pattern registration. */ 97*cdf0e10cSrcweir struct InterceptorInfo 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir /** @short reference to the interceptor component. */ 100*cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatchProvider > xInterceptor; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir /** @short it's registration for URL patterns. 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir @descr If the interceptor component does not support the optional interface 105*cdf0e10cSrcweir XInterceptorInfo, it will be registered for one pattern "*" by default. 106*cdf0e10cSrcweir That would make it possible to handle it in the same manner then real 107*cdf0e10cSrcweir registered interceptor objects and we must not implement any special code. */ 108*cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lURLPattern; 109*cdf0e10cSrcweir }; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir //_____________________________________________________ 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir /** @short implements a list of items of type InterceptorInfo, and provides some special 114*cdf0e10cSrcweir functions on it. 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir @descr Because interceptor objects can be registered for URL patterns, 117*cdf0e10cSrcweir it supports a wildcard search on all list items. 118*cdf0e10cSrcweir */ 119*cdf0e10cSrcweir class InterceptorList : public ::std::deque< InterceptorInfo > 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir public: 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir //_____________________________________________ 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir /** @short search for an interceptor inside this list using it's reference. 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir @param xInterceptor 128*cdf0e10cSrcweir points to the interceptor object, which should be located inside this list. 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir @return An iterator object, which points directly to the located item inside this list. 131*cdf0e10cSrcweir In case no interceptor could be found, it points to the end of this list! 132*cdf0e10cSrcweir */ 133*cdf0e10cSrcweir iterator findByReference(const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatchProviderInterceptor > xProviderInterface(xInterceptor, css::uno::UNO_QUERY); 136*cdf0e10cSrcweir iterator pIt; 137*cdf0e10cSrcweir for (pIt=begin(); pIt!=end(); ++pIt) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir if (pIt->xInterceptor == xProviderInterface) 140*cdf0e10cSrcweir return pIt; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir return end(); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir //_____________________________________________ 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir /** @short search for an interceptor inside this list using it's reference. 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir @param xInterceptor 150*cdf0e10cSrcweir points to the interceptor object, which should be located inside this list. 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir @return An iterator object, which points directly to the located item inside this list. 153*cdf0e10cSrcweir In case no interceptor could be found, it points to the end of this list! 154*cdf0e10cSrcweir */ 155*cdf0e10cSrcweir iterator findByPattern(const ::rtl::OUString& sURL) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir iterator pIt; 158*cdf0e10cSrcweir for (pIt=begin(); pIt!=end(); ++pIt) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir sal_Int32 c = pIt->lURLPattern.getLength(); 161*cdf0e10cSrcweir const ::rtl::OUString* pPattern = pIt->lURLPattern.getConstArray(); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir for (sal_Int32 i=0; i<c; ++i) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir WildCard aPattern(pPattern[i]); 166*cdf0e10cSrcweir if (aPattern.Matches(sURL)) 167*cdf0e10cSrcweir return pIt; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir return end(); 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir }; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir //_____________________________________________________ 175*cdf0e10cSrcweir // member 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir private: 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir /** @short reference to the frame, which uses this instance to implement it's own interception. 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir @descr We hold a weak reference only, to make disposing operations easy. */ 182*cdf0e10cSrcweir css::uno::WeakReference< css::frame::XFrame > m_xOwnerWeak; 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir /** @short this interception helper implements the top level master of an interceptor list ... 185*cdf0e10cSrcweir but this member is the lowest possible slave! */ 186*cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatchProvider > m_xSlave; 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir /** @short contains all registered interceptor objects. */ 189*cdf0e10cSrcweir InterceptorList m_lInterceptionRegs; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir /** @short it regulates, which interceptor is used first. 192*cdf0e10cSrcweir The last or the first registered one. */ 193*cdf0e10cSrcweir static sal_Bool m_bPreferrFirstInterceptor; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir //_____________________________________________________ 196*cdf0e10cSrcweir // native interface 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir public: 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir //_________________________________________________ 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir /** @short creates a new interception helper instance. 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir @param xOwner 205*cdf0e10cSrcweir points to the frame, which use this instances to support it's own interception interfaces. 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir @param xSlave 208*cdf0e10cSrcweir an outside creates dispatch provider, which has to be used here as lowest slave "interceptor". 209*cdf0e10cSrcweir */ 210*cdf0e10cSrcweir InterceptionHelper(const css::uno::Reference< css::frame::XFrame >& xOwner, 211*cdf0e10cSrcweir const css::uno::Reference< css::frame::XDispatchProvider >& xSlave); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir protected: 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir //_________________________________________________ 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir /** @short standard destructor. 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir @descr This method destruct an instance of this class and clear some member. 220*cdf0e10cSrcweir This method is protected, because its not allowed to use this class as a direct member! 221*cdf0e10cSrcweir You MUST use a dynamical instance (pointer). That's the reason for a protected dtor. 222*cdf0e10cSrcweir */ 223*cdf0e10cSrcweir virtual ~InterceptionHelper(); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir //_____________________________________________________ 226*cdf0e10cSrcweir // uno interface 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir public: 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir FWK_DECLARE_XINTERFACE 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir //_________________________________________________ 233*cdf0e10cSrcweir // XDispatchProvider 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir /** @short query for a dispatch, which implements the requested feature. 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir @descr We search inside our list of interception registrations, to locate 238*cdf0e10cSrcweir any interested interceptor. In case no interceptor exists or nobody is 239*cdf0e10cSrcweir interested on this URL our lowest slave will be used. 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir @param aURL 242*cdf0e10cSrcweir describes the requested dispatch functionality. 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir @param sTargetFrameName 245*cdf0e10cSrcweir the name of the target frame or a special name like "_blank", "_top" ... 246*cdf0e10cSrcweir Won't be used here ... but may by one of our registered interceptor objects 247*cdf0e10cSrcweir or our slave. 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir @param nSearchFlags 250*cdf0e10cSrcweir optional search parameter for targeting, if sTargetFrameName isn't a special one. 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir @return A valid dispatch object, if any interceptor or at least our slave is interested on the given URL; 253*cdf0e10cSrcweir or NULL otherwhise. 254*cdf0e10cSrcweir */ 255*cdf0e10cSrcweir virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL& aURL , 256*cdf0e10cSrcweir const ::rtl::OUString& sTargetFrameName, 257*cdf0e10cSrcweir sal_Int32 nSearchFlags ) 258*cdf0e10cSrcweir throw(css::uno::RuntimeException); 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir //_________________________________________________ 261*cdf0e10cSrcweir // XDispatchProvider 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir /** @short implements an optimized queryDispatch() for remote. 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir @descr It capsulate more then one queryDispatch() requests and return a lits of dispatch objects 266*cdf0e10cSrcweir as result. Because both lists (in and out) coreespond together, it's not allowed to 267*cdf0e10cSrcweir pack it - means supress NULL references! 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir @param lDescriptor 270*cdf0e10cSrcweir a list of queryDispatch() arguments. 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir @return A list of dispatch objects. 273*cdf0e10cSrcweir */ 274*cdf0e10cSrcweir virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptor) 275*cdf0e10cSrcweir throw(css::uno::RuntimeException); 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir //_________________________________________________ 278*cdf0e10cSrcweir // XDispatchProviderInterception 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir /** @short register an interceptor. 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir @descr Somebody can register himself to intercept all or some special dispatches. 283*cdf0e10cSrcweir It's depend from his supported interfaces. If he implement XInterceptorInfo 284*cdf0e10cSrcweir he his called for some special URLs only - otherwise we call it for every request! 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir @attention We don't check for double registrations here! 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir @param xInterceptor 289*cdf0e10cSrcweir reference to interceptor, which wish to be registered here. 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir @throw A RuntimeException if the given reference is NULL! 292*cdf0e10cSrcweir */ 293*cdf0e10cSrcweir virtual void SAL_CALL registerDispatchProviderInterceptor(const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor) 294*cdf0e10cSrcweir throw(css::uno::RuntimeException); 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir //_________________________________________________ 297*cdf0e10cSrcweir // XDispatchProviderInterception 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir /** @short release an interceptor. 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir @descr Remove the registered interceptor from our internal list 302*cdf0e10cSrcweir and delete all special informations about it. 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir @param xInterceptor 305*cdf0e10cSrcweir reference to the interceptor, which wish to be deregistered. 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir @throw A RuntimeException if the given reference is NULL! 308*cdf0e10cSrcweir */ 309*cdf0e10cSrcweir virtual void SAL_CALL releaseDispatchProviderInterceptor( const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor ) throw( css::uno::RuntimeException ); 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir //_________________________________________________ 312*cdf0e10cSrcweir // XEventListener 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir /** @short Is called from our owner frame, in case he will be disposed. 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir @descr We have to relaease all references to him then. 317*cdf0e10cSrcweir Normaly we will die by ref count too ... 318*cdf0e10cSrcweir */ 319*cdf0e10cSrcweir virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) 320*cdf0e10cSrcweir throw(css::uno::RuntimeException); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir }; // class InterceptionHelper 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir } // namespace framework 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir #endif // #ifndef __FRAMEWORK_HELPER_INTERCEPTIONHELPER_HXX_ 327