xref: /trunk/main/ucbhelper/source/client/interceptedinteraction.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_ucbhelper.hxx"
26 #include <ucbhelper/interceptedinteraction.hxx>
27 
28 //_______________________________________________
29 // includes
30 
31 //_______________________________________________
32 // namespace
33 
34 namespace ucbhelper{
35 
36 namespace css = ::com::sun::star;
37 
38 //_______________________________________________
39 // definitions
40 
41 /*-----------------------------------------------
42     17.03.2004 11:00
43 -----------------------------------------------*/
InterceptedInteraction()44 InterceptedInteraction::InterceptedInteraction()
45 {
46 }
47 
48 /*-----------------------------------------------
49     17.03.2004 14:55
50 -----------------------------------------------*/
setInterceptedHandler(const css::uno::Reference<css::task::XInteractionHandler> & xInterceptedHandler)51 void InterceptedInteraction::setInterceptedHandler(const css::uno::Reference< css::task::XInteractionHandler >& xInterceptedHandler)
52 {
53     m_xInterceptedHandler = xInterceptedHandler;
54 }
55 
56 /*-----------------------------------------------
57     17.03.2004 14:55
58 -----------------------------------------------*/
setInterceptions(const::std::vector<InterceptedRequest> & lInterceptions)59 void InterceptedInteraction::setInterceptions(const ::std::vector< InterceptedRequest >& lInterceptions)
60 {
61     m_lInterceptions = lInterceptions;
62 }
63 
64 /*-----------------------------------------------
65     18.03.2004 10:10
66 -----------------------------------------------*/
intercepted(const InterceptedRequest &,const::com::sun::star::uno::Reference<::com::sun::star::task::XInteractionRequest> &)67 InterceptedInteraction::EInterceptionState InterceptedInteraction::intercepted(
68     const InterceptedRequest&,
69     const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >&)
70 {
71     // default behaviour! see impl_interceptRequest() for further informations ...
72     return E_NOT_INTERCEPTED;
73 }
74 
75 /*-----------------------------------------------
76     18.03.2004 09:46
77 -----------------------------------------------*/
extractContinuation(const css::uno::Sequence<css::uno::Reference<css::task::XInteractionContinuation>> & lContinuations,const css::uno::Type & aType)78 css::uno::Reference< css::task::XInteractionContinuation > InterceptedInteraction::extractContinuation(const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > >& lContinuations,
79                                                                                                        const css::uno::Type&                                                                   aType         )
80 {
81     const css::uno::Reference< css::task::XInteractionContinuation >* pContinuations = lContinuations.getConstArray();
82 
83     sal_Int32 c = lContinuations.getLength();
84     sal_Int32 i = 0;
85 
86     for (i=0; i<c; ++i)
87     {
88         css::uno::Reference< css::uno::XInterface > xCheck(pContinuations[i], css::uno::UNO_QUERY);
89         if (xCheck->queryInterface(aType).hasValue())
90             return pContinuations[i];
91     }
92 
93     return css::uno::Reference< css::task::XInteractionContinuation >();
94 }
95 
96 /*-----------------------------------------------
97     18.03.2004 10:03
98 -----------------------------------------------*/
handle(const css::uno::Reference<css::task::XInteractionRequest> & xRequest)99 void SAL_CALL InterceptedInteraction::handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
100 {
101     impl_handleDefault(xRequest);
102 }
103 
104 /*-----------------------------------------------
105     18.03.2004 10:02
106 -----------------------------------------------*/
impl_handleDefault(const::com::sun::star::uno::Reference<::com::sun::star::task::XInteractionRequest> & xRequest)107 void InterceptedInteraction::impl_handleDefault(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest)
108 {
109     EInterceptionState eState = impl_interceptRequest(xRequest);
110 
111     switch(eState)
112     {
113         case E_NOT_INTERCEPTED:
114         {
115             // Non of the intercepted requests match to the given one.
116             // => forward request to the internal wrapped handler - if there is one.
117             if (m_xInterceptedHandler.is())
118                 m_xInterceptedHandler->handle(xRequest);
119         }
120         break;
121 
122         case E_NO_CONTINUATION_FOUND:
123         {
124             // Runtime error! The defined continuation could not be located
125             // inside the set of available continuations of the incoming request.
126             // Whats wrong - the interception list or the request?
127             OSL_ENSURE(sal_False, "InterceptedInteraction::handle()\nCould intercept this interaction request - but can't locate the right continuation!");
128         }
129         break;
130 
131         case E_INTERCEPTED:
132         break;
133     }
134 }
135 
136 /*-----------------------------------------------
137     18.03.2004 09:48
138 -----------------------------------------------*/
impl_interceptRequest(const::com::sun::star::uno::Reference<::com::sun::star::task::XInteractionRequest> & xRequest)139 InterceptedInteraction::EInterceptionState InterceptedInteraction::impl_interceptRequest(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest)
140 {
141     css::uno::Any                                                                    aRequest       = xRequest->getRequest();
142     css::uno::Type                                                                   aRequestType   = aRequest.getValueType();
143     css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
144 
145     // check against the list of static requests
146     sal_Int32 nHandle = 0;
147     ::std::vector< InterceptedRequest >::const_iterator pIt;
148     for (  pIt  = m_lInterceptions.begin();
149            pIt != m_lInterceptions.end()  ;
150          ++pIt                            )
151     {
152         const InterceptedRequest& rInterception = *pIt;
153         css::uno::Type aInterceptedType = rInterception.Request.getValueType();
154 
155         // check the request
156         sal_Bool bMatch = sal_False;
157         if (rInterception.MatchExact)
158             bMatch = aInterceptedType.equals(aRequestType);
159         else
160             bMatch = aInterceptedType.isAssignableFrom(aRequestType); // dont change intercepted and request type here -> it will check the wrong direction!
161 
162         // intercepted ...
163         // Call they might existing derived class, so they can handle that by its own.
164         // If its not interested on that (may be its not overwritten and the default implementation
165         // returns E_NOT_INTERCEPTED as default) -> break this loop and search for the right continuation.
166         if (bMatch)
167         {
168             EInterceptionState eState = intercepted(rInterception, xRequest);
169             if (eState == E_NOT_INTERCEPTED)
170                 break;
171             return eState;
172         }
173 
174         ++nHandle;
175     }
176 
177     if (pIt != m_lInterceptions.end()) // => can be true only if bMatch=TRUE!
178     {
179         // match -> search required continuation
180         const InterceptedRequest& rInterception = *pIt;
181         css::uno::Reference< css::task::XInteractionContinuation > xContinuation = InterceptedInteraction::extractContinuation(lContinuations, rInterception.Continuation);
182         if (xContinuation.is())
183         {
184             xContinuation->select();
185             return E_INTERCEPTED;
186         }
187 
188         // Can be reached only, if the request does not support the given continuation!
189         // => RuntimeError!?
190         return E_NO_CONTINUATION_FOUND;
191     }
192 
193     return E_NOT_INTERCEPTED;
194 }
195 
196 } // namespace ucbhelper
197