Update ooo320-m1
[ooovba.git] / ucbhelper / source / provider / handleinteractionrequest.cxx
blob67f4ebd3760da5cc4295892fc11a0a232341f7a4
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: handleinteractionrequest.cxx,v $
10 * $Revision: 1.6 $
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_ucbhelper.hxx"
33 #include "ucbhelper/handleinteractionrequest.hxx"
34 #include "com/sun/star/task/XInteractionAbort.hpp"
35 #include "com/sun/star/task/XInteractionHandler.hpp"
36 #include "com/sun/star/task/XInteractionRetry.hpp"
37 #include "com/sun/star/ucb/CommandFailedException.hpp"
38 #include "com/sun/star/ucb/XCommandEnvironment.hpp"
39 #include "com/sun/star/uno/Reference.hxx"
40 #include "com/sun/star/uno/RuntimeException.hpp"
41 #include "cppuhelper/exc_hlp.hxx"
42 #include "osl/diagnose.h"
43 #include "rtl/ustring.hxx"
44 #ifndef _UCBHELPER_INTERACTIONREQUEST_HXX
45 #include "ucbhelper/interactionrequest.hxx"
46 #endif
47 #include "ucbhelper/simpleauthenticationrequest.hxx"
48 #include "ucbhelper/simpleinteractionrequest.hxx"
49 #include "ucbhelper/simplecertificatevalidationrequest.hxx"
50 #ifndef INCLUDED_UTILITY
51 #include <utility>
52 #define INCLUDED_UTILITY
53 #endif
55 using namespace com::sun::star;
57 namespace {
59 void
60 handle(uno::Reference< task::XInteractionRequest > const & rRequest,
61 uno::Reference< ucb::XCommandEnvironment > const & rEnvironment)
62 SAL_THROW((uno::Exception))
64 OSL_ENSURE(rRequest.is(), "specification violation");
65 uno::Reference< task::XInteractionHandler > xHandler;
66 if (rEnvironment.is())
67 xHandler = rEnvironment->getInteractionHandler();
68 if (!xHandler.is())
69 cppu::throwException(rRequest->getRequest());
70 xHandler->handle(rRequest.get());
75 namespace ucbhelper {
77 sal_Int32
78 handleInteractionRequest(
79 rtl::Reference< ucbhelper::SimpleInteractionRequest > const & rRequest,
80 uno::Reference< ucb::XCommandEnvironment > const & rEnvironment,
81 bool bThrowOnAbort)
82 SAL_THROW((uno::Exception))
84 handle(rRequest.get(), rEnvironment);
85 sal_Int32 nResponse = rRequest->getResponse();
86 switch (nResponse)
88 case ucbhelper::CONTINUATION_UNKNOWN:
89 cppu::throwException(rRequest->getRequest());
90 break;
92 case ucbhelper::CONTINUATION_ABORT:
93 if (bThrowOnAbort)
94 throw ucb::CommandFailedException(
95 rtl::OUString(), 0, rRequest->getRequest());
96 break;
98 return nResponse;
101 std::pair< sal_Int32,
102 rtl::Reference< ucbhelper::InteractionSupplyAuthentication > >
103 handleInteractionRequest(
104 rtl::Reference< ucbhelper::SimpleAuthenticationRequest > const & rRequest,
105 uno::Reference< ucb::XCommandEnvironment > const & rEnvironment,
106 bool bThrowOnAbort)
107 SAL_THROW((uno::Exception))
109 handle(rRequest.get(), rEnvironment);
110 rtl::Reference< ucbhelper::InteractionContinuation >
111 xContinuation(rRequest->getSelection());
112 if (uno::Reference< task::XInteractionAbort >(
113 xContinuation.get(), uno::UNO_QUERY).
114 is())
115 if (bThrowOnAbort)
116 throw ucb::CommandFailedException(
117 rtl::OUString(), 0, rRequest->getRequest());
118 else
119 return std::make_pair(
120 ucbhelper::CONTINUATION_ABORT,
121 rtl::Reference<
122 ucbhelper::InteractionSupplyAuthentication >());
123 else if (uno::Reference< task::XInteractionRetry >(
124 xContinuation.get(), uno::UNO_QUERY).
125 is())
126 return std::make_pair(
127 ucbhelper::CONTINUATION_ABORT,
128 rtl::Reference<
129 ucbhelper::InteractionSupplyAuthentication >());
130 else
131 return std::make_pair(
132 ucbhelper::CONTINUATION_UNKNOWN,
133 rtl::Reference<
134 ucbhelper::InteractionSupplyAuthentication >(
135 rRequest->getAuthenticationSupplier()));
140 namespace ucbhelper {
142 sal_Int32
143 handleInteractionRequest(
144 rtl::Reference< ucbhelper::SimpleCertificateValidationRequest > const & rRequest,
145 uno::Reference< ucb::XCommandEnvironment > const & rEnvironment,
146 bool bThrowOnAbort)
147 SAL_THROW((uno::Exception))
149 handle(rRequest.get(), rEnvironment);
150 sal_Int32 nResponse = rRequest->getResponse();
151 switch (nResponse)
153 case ucbhelper::CONTINUATION_UNKNOWN:
154 cppu::throwException(rRequest->getRequest());
155 break;
157 case ucbhelper::CONTINUATION_ABORT:
158 if (bThrowOnAbort)
159 throw ucb::CommandFailedException(
160 rtl::OUString(), 0, rRequest->getRequest());
161 break;
163 return nResponse;