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_desktop.hxx"
26
27 #include "com/sun/star/deployment/VersionException.hpp"
28 #include "com/sun/star/deployment/LicenseException.hpp"
29 #include "com/sun/star/deployment/InstallException.hpp"
30 #include "com/sun/star/deployment/DependencyException.hpp"
31 #include "com/sun/star/deployment/PlatformException.hpp"
32 #include "com/sun/star/task/XInteractionApprove.hpp"
33 #include "com/sun/star/task/XInteractionAbort.hpp"
34 #include "com/sun/star/task/XInteractionHandler.hpp"
35 #include "com/sun/star/ucb/XCommandEnvironment.hpp"
36 #include "com/sun/star/uno/XComponentContext.hpp"
37 #include "dp_commandenvironments.hxx"
38
39 namespace deployment = com::sun::star::deployment;
40 namespace lang = com::sun::star::lang;
41 namespace task = com::sun::star::task;
42 namespace ucb = com::sun::star::ucb;
43 namespace uno = com::sun::star::uno;
44 namespace css = com::sun::star;
45
46 #define OUSTR(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
47
48 using ::com::sun::star::uno::Reference;
49 using ::rtl::OUString;
50
51 namespace dp_manager {
52
BaseCommandEnv()53 BaseCommandEnv::BaseCommandEnv()
54 {
55 }
56
BaseCommandEnv(Reference<task::XInteractionHandler> const & handler)57 BaseCommandEnv::BaseCommandEnv(
58 Reference< task::XInteractionHandler> const & handler)
59 : m_forwardHandler(handler)
60 {
61 }
62
~BaseCommandEnv()63 BaseCommandEnv::~BaseCommandEnv()
64 {
65 }
66 // XCommandEnvironment
67 //______________________________________________________________________________
getInteractionHandler()68 Reference<task::XInteractionHandler> BaseCommandEnv::getInteractionHandler()
69 throw (uno::RuntimeException)
70 {
71 return this;
72 }
73
74 //______________________________________________________________________________
getProgressHandler()75 Reference<ucb::XProgressHandler> BaseCommandEnv::getProgressHandler()
76 throw (uno::RuntimeException)
77 {
78 return this;
79 }
80
handle(Reference<task::XInteractionRequest> const &)81 void BaseCommandEnv::handle(
82 Reference< task::XInteractionRequest> const & /*xRequest*/ )
83 throw (uno::RuntimeException)
84 {
85 }
86
handle_(bool approve,bool abort,Reference<task::XInteractionRequest> const & xRequest)87 void BaseCommandEnv::handle_(bool approve, bool abort,
88 Reference< task::XInteractionRequest> const & xRequest )
89 {
90 if (approve == false && abort == false)
91 {
92 //not handled so far -> forwarding
93 if (m_forwardHandler.is())
94 m_forwardHandler->handle(xRequest);
95 else
96 return; //cannot handle
97 }
98 else
99 {
100 // select:
101 uno::Sequence< Reference< task::XInteractionContinuation > > conts(
102 xRequest->getContinuations() );
103 Reference< task::XInteractionContinuation > const * pConts =
104 conts.getConstArray();
105 sal_Int32 len = conts.getLength();
106 for ( sal_Int32 pos = 0; pos < len; ++pos )
107 {
108 if (approve) {
109 Reference< task::XInteractionApprove > xInteractionApprove(
110 pConts[ pos ], uno::UNO_QUERY );
111 if (xInteractionApprove.is()) {
112 xInteractionApprove->select();
113 // don't query again for ongoing continuations:
114 approve = false;
115 }
116 }
117 else if (abort) {
118 Reference< task::XInteractionAbort > xInteractionAbort(
119 pConts[ pos ], uno::UNO_QUERY );
120 if (xInteractionAbort.is()) {
121 xInteractionAbort->select();
122 // don't query again for ongoing continuations:
123 abort = false;
124 }
125 }
126 }
127 }
128
129 }
130
131 // XProgressHandler
push(uno::Any const &)132 void BaseCommandEnv::push( uno::Any const & /*Status*/ )
133 throw (uno::RuntimeException)
134 {
135 }
136
137
update(uno::Any const &)138 void BaseCommandEnv::update( uno::Any const & /*Status */)
139 throw (uno::RuntimeException)
140 {
141 }
142
pop()143 void BaseCommandEnv::pop() throw (uno::RuntimeException)
144 {
145 }
146 //==============================================================================
147
TmpRepositoryCommandEnv()148 TmpRepositoryCommandEnv::TmpRepositoryCommandEnv()
149 {
150 }
151
TmpRepositoryCommandEnv(css::uno::Reference<css::task::XInteractionHandler> const & handler)152 TmpRepositoryCommandEnv::TmpRepositoryCommandEnv(
153 css::uno::Reference< css::task::XInteractionHandler> const & handler):
154 BaseCommandEnv(handler)
155 {
156 }
157 // XInteractionHandler
handle(Reference<task::XInteractionRequest> const & xRequest)158 void TmpRepositoryCommandEnv::handle(
159 Reference< task::XInteractionRequest> const & xRequest )
160 throw (uno::RuntimeException)
161 {
162 uno::Any request( xRequest->getRequest() );
163 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
164
165 deployment::VersionException verExc;
166 deployment::LicenseException licExc;
167 deployment::InstallException instExc;
168
169 bool approve = false;
170 bool abort = false;
171
172 if ((request >>= verExc)
173 || (request >>= licExc)
174 || (request >>= instExc))
175 {
176 approve = true;
177 }
178
179 handle_(approve, abort, xRequest);
180 }
181 //================================================================================
182
LicenseCommandEnv(css::uno::Reference<css::task::XInteractionHandler> const & handler,bool bSuppressLicense,OUString const & repository)183 LicenseCommandEnv::LicenseCommandEnv(
184 css::uno::Reference< css::task::XInteractionHandler> const & handler,
185 bool bSuppressLicense,
186 OUString const & repository):
187 BaseCommandEnv(handler), m_repository(repository),
188 m_bSuppressLicense(bSuppressLicense)
189 {
190 }
191 // XInteractionHandler
handle(Reference<task::XInteractionRequest> const & xRequest)192 void LicenseCommandEnv::handle(
193 Reference< task::XInteractionRequest> const & xRequest )
194 throw (uno::RuntimeException)
195 {
196 uno::Any request( xRequest->getRequest() );
197 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
198
199
200 deployment::LicenseException licExc;
201
202 bool approve = false;
203 bool abort = false;
204
205 if (request >>= licExc)
206 {
207 if (m_bSuppressLicense
208 || m_repository.equals(OUSTR("bundled"))
209 || licExc.AcceptBy.equals(OUSTR("admin")))
210 {
211 //always approve in bundled case, because we do not support
212 //showing licenses anyway.
213 //The "admin" already accepted the license when installing the
214 // shared extension
215 approve = true;
216 }
217 }
218
219 handle_(approve, abort, xRequest);
220 }
221
222 //================================================================================
223 //================================================================================
224
NoLicenseCommandEnv(css::uno::Reference<css::task::XInteractionHandler> const & handler)225 NoLicenseCommandEnv::NoLicenseCommandEnv(
226 css::uno::Reference< css::task::XInteractionHandler> const & handler):
227 BaseCommandEnv(handler)
228 {
229 }
230 // XInteractionHandler
handle(Reference<task::XInteractionRequest> const & xRequest)231 void NoLicenseCommandEnv::handle(
232 Reference< task::XInteractionRequest> const & xRequest )
233 throw (uno::RuntimeException)
234 {
235 uno::Any request( xRequest->getRequest() );
236 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
237
238
239 deployment::LicenseException licExc;
240
241 bool approve = false;
242 bool abort = false;
243
244 if (request >>= licExc)
245 {
246 approve = true;
247 }
248 handle_(approve, abort, xRequest);
249 }
250
251 // SilentCheckPrerequisitesCommandEnv::SilentCheckPrerequisitesCommandEnv(
252 // css::uno::Reference< css::task::XInteractionHandler> const & handler):
253 // BaseCommandEnv(handler)
254 // {
255 // }
SilentCheckPrerequisitesCommandEnv()256 SilentCheckPrerequisitesCommandEnv::SilentCheckPrerequisitesCommandEnv()
257 {
258 }
259
handle(Reference<task::XInteractionRequest> const & xRequest)260 void SilentCheckPrerequisitesCommandEnv::handle(
261 Reference< task::XInteractionRequest> const & xRequest )
262 throw (uno::RuntimeException)
263 {
264 uno::Any request( xRequest->getRequest() );
265 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
266
267 deployment::LicenseException licExc;
268 deployment::PlatformException platformExc;
269 deployment::DependencyException depExc;
270 bool approve = false;
271 bool abort = false;
272
273 if (request >>= licExc)
274 {
275 approve = true;
276 handle_(approve, abort, xRequest);
277 }
278 else if ((request >>= platformExc)
279 || (request >>= depExc))
280 {
281 m_Exception = request;
282 }
283 else
284 {
285 m_UnknownException = request;
286 }
287 }
288 // NoExceptionCommandEnv::NoExceptionCommandEnv(
289 // css::uno::Reference< css::task::XInteractionHandler> const & handler,
290 // css::uno::Type const & type):
291 // BaseCommandEnv(handler),
292 // m_type(type)
293 // {
294 // }
295 // // XInteractionHandler
296 // void NoExceptionCommandEnv::handle(
297 // Reference< task::XInteractionRequest> const & xRequest )
298 // throw (uno::RuntimeException)
299 // {
300 // uno::Any request( xRequest->getRequest() );
301 // OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
302
303
304 // deployment::LicenseException licExc;
305
306 // bool approve = false;
307 // bool abort = false;
308
309 // if (request.getValueType() == m_type)
310 // {
311 // approve = true;
312 // }
313 // handle_(approve, abort, xRequest);
314 // }
315
316
317
318 } // namespace dp_manager
319
320
321