1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <ucbhelper/interceptedinteraction.hxx>
22 #include <osl/diagnose.h>
26 InterceptedInteraction::InterceptedInteraction()
30 void InterceptedInteraction::setInterceptedHandler(const css::uno::Reference
< css::task::XInteractionHandler
>& xInterceptedHandler
)
32 m_xInterceptedHandler
= xInterceptedHandler
;
35 void InterceptedInteraction::setInterceptions(const ::std::vector
< InterceptedRequest
>& lInterceptions
)
37 m_lInterceptions
= lInterceptions
;
40 InterceptedInteraction::EInterceptionState
InterceptedInteraction::intercepted(
41 const InterceptedRequest
&,
42 const css::uno::Reference
< css::task::XInteractionRequest
>&)
44 // default behaviour! see impl_interceptRequest() for further information ...
45 return E_NOT_INTERCEPTED
;
48 css::uno::Reference
< css::task::XInteractionContinuation
> InterceptedInteraction::extractContinuation(const css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> >& lContinuations
,
49 const css::uno::Type
& aType
)
51 const css::uno::Reference
< css::task::XInteractionContinuation
>* pContinuations
= lContinuations
.getConstArray();
53 sal_Int32 c
= lContinuations
.getLength();
58 css::uno::Reference
< css::uno::XInterface
> xCheck(pContinuations
[i
], css::uno::UNO_QUERY
);
59 if (xCheck
->queryInterface(aType
).hasValue())
60 return pContinuations
[i
];
63 return css::uno::Reference
< css::task::XInteractionContinuation
>();
66 void SAL_CALL
InterceptedInteraction::handle(const css::uno::Reference
< css::task::XInteractionRequest
>& xRequest
)
68 impl_handleDefault(xRequest
);
71 void InterceptedInteraction::impl_handleDefault(const css::uno::Reference
< css::task::XInteractionRequest
>& xRequest
)
73 EInterceptionState eState
= impl_interceptRequest(xRequest
);
77 case E_NOT_INTERCEPTED
:
79 // Non of the intercepted requests match to the given one.
80 // => forward request to the internal wrapped handler - if there is one.
81 if (m_xInterceptedHandler
.is())
82 m_xInterceptedHandler
->handle(xRequest
);
86 case E_NO_CONTINUATION_FOUND
:
88 // Runtime error! The defined continuation could not be located
89 // inside the set of available continuations of the incoming request.
90 // What's wrong - the interception list or the request?
91 OSL_FAIL("InterceptedInteraction::handle()\nCould intercept this interaction request - but can't locate the right continuation!");
100 InterceptedInteraction::EInterceptionState
InterceptedInteraction::impl_interceptRequest(const css::uno::Reference
< css::task::XInteractionRequest
>& xRequest
)
102 css::uno::Any aRequest
= xRequest
->getRequest();
103 const css::uno::Type
& aRequestType
= aRequest
.getValueType();
104 css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > lContinuations
= xRequest
->getContinuations();
106 // check against the list of static requests
107 auto pIt
= std::find_if(m_lInterceptions
.begin(), m_lInterceptions
.end(),
108 [&aRequestType
](const InterceptedRequest
& rInterception
) {
110 // don't change intercepted and request type here -> it will check the wrong direction!
111 return rInterception
.Request
.getValueType().isAssignableFrom(aRequestType
);
114 if (pIt
!= m_lInterceptions
.end()) // intercepted ...
116 const InterceptedRequest
& rInterception
= *pIt
;
118 // Call they might existing derived class, so they can handle that by its own.
119 // If it's not interested on that (maybe it's not overwritten and the default implementation
120 // returns E_NOT_INTERCEPTED as default) -> search required continuation
121 EInterceptionState eState
= intercepted(rInterception
, xRequest
);
122 if (eState
!= E_NOT_INTERCEPTED
)
125 css::uno::Reference
< css::task::XInteractionContinuation
> xContinuation
= InterceptedInteraction::extractContinuation(lContinuations
, rInterception
.Continuation
);
126 if (xContinuation
.is())
128 xContinuation
->select();
129 return E_INTERCEPTED
;
132 // Can be reached only, if the request does not support the given continuation!
134 return E_NO_CONTINUATION_FOUND
;
137 return E_NOT_INTERCEPTED
;
140 } // namespace ucbhelper
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */