1*b3b486c3SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b3b486c3SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b3b486c3SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b3b486c3SAndrew Rist * distributed with this work for additional information 6*b3b486c3SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b3b486c3SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b3b486c3SAndrew Rist * "License"); you may not use this file except in compliance 9*b3b486c3SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b3b486c3SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b3b486c3SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b3b486c3SAndrew Rist * software distributed under the License is distributed on an 15*b3b486c3SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b3b486c3SAndrew Rist * KIND, either express or implied. See the License for the 17*b3b486c3SAndrew Rist * specific language governing permissions and limitations 18*b3b486c3SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b3b486c3SAndrew Rist *************************************************************/ 21*b3b486c3SAndrew Rist 22*b3b486c3SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _UCBHELPER_INTERCEPTEDINTERACTION_HXX_ 25cdf0e10cSrcweir #define _UCBHELPER_INTERCEPTEDINTERACTION_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir //_______________________________________________ 28cdf0e10cSrcweir // includes 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <vector> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #ifndef __COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP__ 33cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 34cdf0e10cSrcweir #endif 35cdf0e10cSrcweir 36cdf0e10cSrcweir #ifndef __COM_SUN_STAR_TASK_XINTERACTIONREQUEST_HPP__ 37cdf0e10cSrcweir #include <com/sun/star/task/XInteractionRequest.hpp> 38cdf0e10cSrcweir #endif 39cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 40cdf0e10cSrcweir #include "ucbhelper/ucbhelperdllapi.h" 41cdf0e10cSrcweir 42cdf0e10cSrcweir //_______________________________________________ 43cdf0e10cSrcweir // namespace 44cdf0e10cSrcweir 45cdf0e10cSrcweir namespace ucbhelper{ 46cdf0e10cSrcweir 47cdf0e10cSrcweir //_______________________________________________ 48cdf0e10cSrcweir // definitions 49cdf0e10cSrcweir 50cdf0e10cSrcweir /** @short it wraps any other interaction handler and intercept 51cdf0e10cSrcweir its handle() requests. 52cdf0e10cSrcweir 53cdf0e10cSrcweir @descr This class can be used as: 54cdf0e10cSrcweir - instance if special interactions must be supressed 55cdf0e10cSrcweir only 56cdf0e10cSrcweir - or as base class if interactions must be modified. 57cdf0e10cSrcweir */ 58cdf0e10cSrcweir class UCBHELPER_DLLPUBLIC InterceptedInteraction : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionHandler > 59cdf0e10cSrcweir { 60cdf0e10cSrcweir //------------------------------------------- 61cdf0e10cSrcweir // types 62cdf0e10cSrcweir public: 63cdf0e10cSrcweir 64cdf0e10cSrcweir struct InterceptedRequest 65cdf0e10cSrcweir { 66cdf0e10cSrcweir //----------------------------------- 67cdf0e10cSrcweir /** @short marks an Handle as invalid. 68cdf0e10cSrcweir */ 69cdf0e10cSrcweir static const sal_Int32 INVALID_HANDLE = -1; 70cdf0e10cSrcweir 71cdf0e10cSrcweir //----------------------------------- 72cdf0e10cSrcweir /** @short contains the interaction request, which should be intercepted. */ 73cdf0e10cSrcweir ::com::sun::star::uno::Any Request; 74cdf0e10cSrcweir 75cdf0e10cSrcweir //----------------------------------- 76cdf0e10cSrcweir /** @short specify the fix continuation, which must be selected, if the 77cdf0e10cSrcweir interaction could be intercepted successfully. 78cdf0e10cSrcweir */ 79cdf0e10cSrcweir ::com::sun::star::uno::Type Continuation; 80cdf0e10cSrcweir 81cdf0e10cSrcweir //----------------------------------- 82cdf0e10cSrcweir /** @short specify, if both interactions must have the same type 83cdf0e10cSrcweir or can be derived from. 84cdf0e10cSrcweir 85cdf0e10cSrcweir @descr Interaction base on exceptions - and exceptions are real types. 86cdf0e10cSrcweir So they can be checked in its type. These parameter "MatchExact" 87cdf0e10cSrcweir influence the type-check in the following way: 88cdf0e10cSrcweir TRUE => the exception will be intercepted only 89cdf0e10cSrcweir if it supports exactly the same type ... 90cdf0e10cSrcweir or 91cdf0e10cSrcweir FALSE => derived exceptions will be intercepted too. 92cdf0e10cSrcweir 93cdf0e10cSrcweir @attention This parameter does not influence the check of the continuation 94cdf0e10cSrcweir type! The continuation must be matched exactly everytimes ... 95cdf0e10cSrcweir */ 96cdf0e10cSrcweir sal_Bool MatchExact; 97cdf0e10cSrcweir 98cdf0e10cSrcweir //----------------------------------- 99cdf0e10cSrcweir /** @short its an unique identifier, which must be managed by the outside code. 100cdf0e10cSrcweir 101cdf0e10cSrcweir @descr If there is a derived class, which overwrites the InterceptedInteraction::intercepted() 102cdf0e10cSrcweir method, it will be called with a reference to an InterceptedRequest struct. 103cdf0e10cSrcweir Then it can use the handle to react without checking the request type again. 104cdf0e10cSrcweir */ 105cdf0e10cSrcweir sal_Int32 Handle; 106cdf0e10cSrcweir 107cdf0e10cSrcweir //----------------------------------- 108cdf0e10cSrcweir /** @short default ctor. 109cdf0e10cSrcweir 110cdf0e10cSrcweir @descr Such constructed object cant be used realy. 111cdf0e10cSrcweir Might it will crash if its used! 112cdf0e10cSrcweir Dont forget to initialize all(!) members ... 113cdf0e10cSrcweir */ InterceptedRequestucbhelper::InterceptedInteraction::InterceptedRequest114cdf0e10cSrcweir InterceptedRequest() 115cdf0e10cSrcweir { 116cdf0e10cSrcweir MatchExact = sal_False; 117cdf0e10cSrcweir Handle = INVALID_HANDLE; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir //----------------------------------- 121cdf0e10cSrcweir /** @short initialize this instance. 122cdf0e10cSrcweir 123cdf0e10cSrcweir @param nHandle 124cdf0e10cSrcweir used to identify every intercepted request 125cdf0e10cSrcweir 126cdf0e10cSrcweir @param aRequest 127cdf0e10cSrcweir must contain an exception object, which can be checked 128cdf0e10cSrcweir in its uno-type against the later handled interaction. 129cdf0e10cSrcweir 130cdf0e10cSrcweir @param aContinuation 131cdf0e10cSrcweir must contain a continuation object, which is used 132cdf0e10cSrcweir in its uno-type to locate the same continuation 133cdf0e10cSrcweir inside the list of possible ones. 134cdf0e10cSrcweir 135cdf0e10cSrcweir @param bMatchExact 136cdf0e10cSrcweir influence the type check of the interception request. 137cdf0e10cSrcweir Its not used to check the continuation! 138cdf0e10cSrcweir */ InterceptedRequestucbhelper::InterceptedInteraction::InterceptedRequest139cdf0e10cSrcweir InterceptedRequest( sal_Int32 nHandle , 140cdf0e10cSrcweir const ::com::sun::star::uno::Any& aRequest , 141cdf0e10cSrcweir const ::com::sun::star::uno::Type& aContinuation, 142cdf0e10cSrcweir sal_Bool bMatchExact ) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir Handle = nHandle; 145cdf0e10cSrcweir Request = aRequest; 146cdf0e10cSrcweir Continuation = aContinuation; 147cdf0e10cSrcweir MatchExact = bMatchExact; 148cdf0e10cSrcweir } 149cdf0e10cSrcweir }; 150cdf0e10cSrcweir 151cdf0e10cSrcweir //--------------------------------------- 152cdf0e10cSrcweir /** @short represent the different states, which can occure 153cdf0e10cSrcweir as result of an interception. 154cdf0e10cSrcweir 155cdf0e10cSrcweir @see impl_interceptRequest() 156cdf0e10cSrcweir */ 157cdf0e10cSrcweir enum EInterceptionState 158cdf0e10cSrcweir { 159cdf0e10cSrcweir /** none of the specified interceptions match the incoming request */ 160cdf0e10cSrcweir E_NOT_INTERCEPTED, 161cdf0e10cSrcweir /** the request could be intercepted - but the specified continuation could not be located. 162cdf0e10cSrcweir Thats normaly an error of the programmer. May be the interaction request does not use 163cdf0e10cSrcweir the right set of continuations ... or the interception list contains the wrong continuation. */ 164cdf0e10cSrcweir E_NO_CONTINUATION_FOUND, 165cdf0e10cSrcweir /** the request could be intercepted and the specified continuation could be selected successfully. */ 166cdf0e10cSrcweir E_INTERCEPTED 167cdf0e10cSrcweir }; 168cdf0e10cSrcweir 169cdf0e10cSrcweir //------------------------------------------- 170cdf0e10cSrcweir // member 171cdf0e10cSrcweir protected: 172cdf0e10cSrcweir 173cdf0e10cSrcweir //--------------------------------------- 174cdf0e10cSrcweir /** @short reference to the intercepted interaction handler. 175cdf0e10cSrcweir 176cdf0e10cSrcweir @descr NULL is allowed for this member! 177cdf0e10cSrcweir All interaction will be aborted then ... 178cdf0e10cSrcweir expecting th handle() was overwritten by 179cdf0e10cSrcweir a derived class. 180cdf0e10cSrcweir */ 181cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > m_xInterceptedHandler; 182cdf0e10cSrcweir 183cdf0e10cSrcweir //--------------------------------------- 184cdf0e10cSrcweir /** @short these list contains the requests, which should be intercepted. 185cdf0e10cSrcweir */ 186cdf0e10cSrcweir ::std::vector< InterceptedRequest > m_lInterceptions; 187cdf0e10cSrcweir 188cdf0e10cSrcweir //------------------------------------------- 189cdf0e10cSrcweir // native interface 190cdf0e10cSrcweir public: 191cdf0e10cSrcweir 192cdf0e10cSrcweir //--------------------------------------- 193cdf0e10cSrcweir /** @short initialize a new instance with default values. 194cdf0e10cSrcweir */ 195cdf0e10cSrcweir InterceptedInteraction(); 196cdf0e10cSrcweir 197cdf0e10cSrcweir //--------------------------------------- 198cdf0e10cSrcweir /** @short initialize a new instance with real values. 199cdf0e10cSrcweir 200cdf0e10cSrcweir @param xInterceptedHandler 201cdf0e10cSrcweir the outside interaction handler, which should 202cdf0e10cSrcweir be intercepted here. 203cdf0e10cSrcweir 204cdf0e10cSrcweir @param lInterceptions 205cdf0e10cSrcweir the list of intercepted requests. 206cdf0e10cSrcweir */ 207cdf0e10cSrcweir InterceptedInteraction(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xInterceptedHandler, 208cdf0e10cSrcweir const ::std::vector< InterceptedRequest >& lInterceptions ); 209cdf0e10cSrcweir 210cdf0e10cSrcweir //--------------------------------------- 211cdf0e10cSrcweir /** @short initialize a new instance with the interaction handler, 212cdf0e10cSrcweir which should be intercepted. 213cdf0e10cSrcweir 214cdf0e10cSrcweir @attention If such interaction handler isnt set here, 215cdf0e10cSrcweir all incoming requests will be aborted ... 216cdf0e10cSrcweir if the right continuation is available! 217cdf0e10cSrcweir 218cdf0e10cSrcweir @param xInterceptedHandler 219cdf0e10cSrcweir the outside interaction handler, which should 220cdf0e10cSrcweir be intercepted here. 221cdf0e10cSrcweir */ 222cdf0e10cSrcweir void setInterceptedHandler(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xInterceptedHandler); 223cdf0e10cSrcweir 224cdf0e10cSrcweir //--------------------------------------- 225cdf0e10cSrcweir /** @short set a new list of intercepted interactions. 226cdf0e10cSrcweir 227cdf0e10cSrcweir @attention If the interface method handle() will be overwritten by 228cdf0e10cSrcweir a derived class, the functionality behind these static list 229cdf0e10cSrcweir cant be used. 230cdf0e10cSrcweir 231cdf0e10cSrcweir @param lInterceptions 232cdf0e10cSrcweir the list of intercepted requests. 233cdf0e10cSrcweir */ 234cdf0e10cSrcweir void setInterceptions(const ::std::vector< InterceptedRequest >& lInterceptions); 235cdf0e10cSrcweir 236cdf0e10cSrcweir //--------------------------------------- 237cdf0e10cSrcweir /** @short extract a requested continuation from te list of available ones. 238cdf0e10cSrcweir 239cdf0e10cSrcweir @param lContinuations 240cdf0e10cSrcweir the list of available continuations. 241cdf0e10cSrcweir 242cdf0e10cSrcweir @param aType 243cdf0e10cSrcweir is used to locate the right continuation, 244cdf0e10cSrcweir by checking its interface type. 245cdf0e10cSrcweir 246cdf0e10cSrcweir @return A valid reference to the continuation, if it could be located ... 247cdf0e10cSrcweir or an empty reference otherwhise. 248cdf0e10cSrcweir */ 249cdf0e10cSrcweir static ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > extractContinuation( 250cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& lContinuations, 251cdf0e10cSrcweir const ::com::sun::star::uno::Type& aType ); 252cdf0e10cSrcweir 253cdf0e10cSrcweir //------------------------------------------- 254cdf0e10cSrcweir // useable for derived classes 255cdf0e10cSrcweir protected: 256cdf0e10cSrcweir 257cdf0e10cSrcweir //--------------------------------------- 258cdf0e10cSrcweir /** @short can be overwritten by a derived class to handle interceptions 259cdf0e10cSrcweir outside. 260cdf0e10cSrcweir 261cdf0e10cSrcweir @descr This base implementation checks, if the request could be intercepted 262cdf0e10cSrcweir successfully. Then this method intercepted() is called. 263cdf0e10cSrcweir The default implementation returns "NOT_INTERCEPTED" everytimes. 264cdf0e10cSrcweir So the method impl_interceptRequest() uses the right continuation automaticly. 265cdf0e10cSrcweir 266cdf0e10cSrcweir If this method was overwritten and something different "NO_INTERCEPTED" 267cdf0e10cSrcweir is returned, the method impl_interceptRequest() will return immediatly with 268cdf0e10cSrcweir the result, which is returned by this intercepted() method. 269cdf0e10cSrcweir Then the continuations must be selected inside the intercepted() call! 270cdf0e10cSrcweir 271cdf0e10cSrcweir @param rRequest 272cdf0e10cSrcweir it points to the intercepted request (means the item of the 273cdf0e10cSrcweir set interception list). e.g. its "Handle" member can be used 274cdf0e10cSrcweir to identify it and react very easy, without the need to check the 275cdf0e10cSrcweir type of the exception ... 276cdf0e10cSrcweir 277cdf0e10cSrcweir @param xOrgRequest 278cdf0e10cSrcweir points to the original interaction, which was intercepted. 279cdf0e10cSrcweir It provides access to the exception and the list of possible 280cdf0e10cSrcweir continuations. 281cdf0e10cSrcweir 282cdf0e10cSrcweir @return The result of this operation. 283cdf0e10cSrcweir Note: If E_NOT_INTERCEPTED is returned the default handling of the base class 284cdf0e10cSrcweir will be used automaticly for this request! 285cdf0e10cSrcweir */ 286cdf0e10cSrcweir virtual EInterceptionState intercepted(const InterceptedRequest& rRequest , 287cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xOrgRequest); 288cdf0e10cSrcweir 289cdf0e10cSrcweir //------------------------------------------- 290cdf0e10cSrcweir // uno interface 291cdf0e10cSrcweir public: 292cdf0e10cSrcweir 293cdf0e10cSrcweir //--------------------------------------- 294cdf0e10cSrcweir /** @short implements the default handling of this class .... 295cdf0e10cSrcweir or can be overwritten by any derived class. 296cdf0e10cSrcweir 297cdf0e10cSrcweir @descr If no further class is derived from this one 298cdf0e10cSrcweir -> the default implementation is used. Then the 299cdf0e10cSrcweir internal list of requests is used to handle different 300cdf0e10cSrcweir interactions automaticly. 301cdf0e10cSrcweir (see impl_interceptRequest()) 302cdf0e10cSrcweir 303cdf0e10cSrcweir If this method was overwritten by a derived implementation 304cdf0e10cSrcweir -> the new implementation has to do everything by itself. 305cdf0e10cSrcweir Of course it can access all members/helpers and work with it. 306cdf0e10cSrcweir But the default implementation isnt used automaticly then. 307cdf0e10cSrcweir 308cdf0e10cSrcweir @param xRequest 309cdf0e10cSrcweir the interaction request, which should be intercepted. 310cdf0e10cSrcweir */ 311cdf0e10cSrcweir virtual void SAL_CALL handle(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest) 312cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 313cdf0e10cSrcweir 314cdf0e10cSrcweir //------------------------------------------- 315cdf0e10cSrcweir // helper 316cdf0e10cSrcweir private: 317cdf0e10cSrcweir 318cdf0e10cSrcweir //--------------------------------------- 319cdf0e10cSrcweir /** @short implements the default handling: 320cdf0e10cSrcweir - intercept or forward to internal handler. 321cdf0e10cSrcweir */ 322cdf0e10cSrcweir UCBHELPER_DLLPRIVATE void impl_handleDefault(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest); 323cdf0e10cSrcweir 324cdf0e10cSrcweir //--------------------------------------- 325cdf0e10cSrcweir /** @short implements the interception of requests. 326cdf0e10cSrcweir 327cdf0e10cSrcweir @descr The incoming request will be analyzed, if it match 328cdf0e10cSrcweir any request of the m_lIntercepions list. 329cdf0e10cSrcweir If an interception could be found, its continuation will be 330cdf0e10cSrcweir searched and selected. 331cdf0e10cSrcweir 332cdf0e10cSrcweir The method return the state of that operation. 333cdf0e10cSrcweir But it doesnt call the intercepted and here set 334cdf0e10cSrcweir interaction handler. That has to be done in the outside method. 335cdf0e10cSrcweir 336cdf0e10cSrcweir @param xRequest 337cdf0e10cSrcweir the interaction request, which should be intercepted. 338cdf0e10cSrcweir 339cdf0e10cSrcweir @return A identifier, which inidicates if the request was intercepted, 340cdf0e10cSrcweir the continuation was found and selected ... or not. 341cdf0e10cSrcweir */ 342cdf0e10cSrcweir UCBHELPER_DLLPRIVATE EInterceptionState impl_interceptRequest(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest); 343cdf0e10cSrcweir }; 344cdf0e10cSrcweir 345cdf0e10cSrcweir } // namespace ucbhelper 346cdf0e10cSrcweir 347cdf0e10cSrcweir #endif // _UCBHELPER_INTERCEPTEDINTERACTION_HXX_ 348