1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_desktop.hxx" 30 31 #include "com/sun/star/deployment/VersionException.hpp" 32 #include "com/sun/star/deployment/LicenseException.hpp" 33 #include "com/sun/star/deployment/InstallException.hpp" 34 #include "com/sun/star/deployment/DependencyException.hpp" 35 #include "com/sun/star/deployment/PlatformException.hpp" 36 #include "com/sun/star/task/XInteractionApprove.hpp" 37 #include "com/sun/star/task/XInteractionAbort.hpp" 38 #include "com/sun/star/task/XInteractionHandler.hpp" 39 #include "com/sun/star/ucb/XCommandEnvironment.hpp" 40 #include "com/sun/star/uno/XComponentContext.hpp" 41 #include "dp_commandenvironments.hxx" 42 43 namespace deployment = com::sun::star::deployment; 44 namespace lang = com::sun::star::lang; 45 namespace task = com::sun::star::task; 46 namespace ucb = com::sun::star::ucb; 47 namespace uno = com::sun::star::uno; 48 namespace css = com::sun::star; 49 50 #define OUSTR(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) 51 52 using ::com::sun::star::uno::Reference; 53 using ::rtl::OUString; 54 55 namespace dp_manager { 56 57 BaseCommandEnv::BaseCommandEnv() 58 { 59 } 60 61 BaseCommandEnv::BaseCommandEnv( 62 Reference< task::XInteractionHandler> const & handler) 63 : m_forwardHandler(handler) 64 { 65 } 66 67 BaseCommandEnv::~BaseCommandEnv() 68 { 69 } 70 // XCommandEnvironment 71 //______________________________________________________________________________ 72 Reference<task::XInteractionHandler> BaseCommandEnv::getInteractionHandler() 73 throw (uno::RuntimeException) 74 { 75 return this; 76 } 77 78 //______________________________________________________________________________ 79 Reference<ucb::XProgressHandler> BaseCommandEnv::getProgressHandler() 80 throw (uno::RuntimeException) 81 { 82 return this; 83 } 84 85 void BaseCommandEnv::handle( 86 Reference< task::XInteractionRequest> const & /*xRequest*/ ) 87 throw (uno::RuntimeException) 88 { 89 } 90 91 void BaseCommandEnv::handle_(bool approve, bool abort, 92 Reference< task::XInteractionRequest> const & xRequest ) 93 { 94 if (approve == false && abort == false) 95 { 96 //not handled so far -> forwarding 97 if (m_forwardHandler.is()) 98 m_forwardHandler->handle(xRequest); 99 else 100 return; //cannot handle 101 } 102 else 103 { 104 // select: 105 uno::Sequence< Reference< task::XInteractionContinuation > > conts( 106 xRequest->getContinuations() ); 107 Reference< task::XInteractionContinuation > const * pConts = 108 conts.getConstArray(); 109 sal_Int32 len = conts.getLength(); 110 for ( sal_Int32 pos = 0; pos < len; ++pos ) 111 { 112 if (approve) { 113 Reference< task::XInteractionApprove > xInteractionApprove( 114 pConts[ pos ], uno::UNO_QUERY ); 115 if (xInteractionApprove.is()) { 116 xInteractionApprove->select(); 117 // don't query again for ongoing continuations: 118 approve = false; 119 } 120 } 121 else if (abort) { 122 Reference< task::XInteractionAbort > xInteractionAbort( 123 pConts[ pos ], uno::UNO_QUERY ); 124 if (xInteractionAbort.is()) { 125 xInteractionAbort->select(); 126 // don't query again for ongoing continuations: 127 abort = false; 128 } 129 } 130 } 131 } 132 133 } 134 135 // XProgressHandler 136 void BaseCommandEnv::push( uno::Any const & /*Status*/ ) 137 throw (uno::RuntimeException) 138 { 139 } 140 141 142 void BaseCommandEnv::update( uno::Any const & /*Status */) 143 throw (uno::RuntimeException) 144 { 145 } 146 147 void BaseCommandEnv::pop() throw (uno::RuntimeException) 148 { 149 } 150 //============================================================================== 151 152 TmpRepositoryCommandEnv::TmpRepositoryCommandEnv() 153 { 154 } 155 156 TmpRepositoryCommandEnv::TmpRepositoryCommandEnv( 157 css::uno::Reference< css::task::XInteractionHandler> const & handler): 158 BaseCommandEnv(handler) 159 { 160 } 161 // XInteractionHandler 162 void TmpRepositoryCommandEnv::handle( 163 Reference< task::XInteractionRequest> const & xRequest ) 164 throw (uno::RuntimeException) 165 { 166 uno::Any request( xRequest->getRequest() ); 167 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION ); 168 169 deployment::VersionException verExc; 170 deployment::LicenseException licExc; 171 deployment::InstallException instExc; 172 173 bool approve = false; 174 bool abort = false; 175 176 if ((request >>= verExc) 177 || (request >>= licExc) 178 || (request >>= instExc)) 179 { 180 approve = true; 181 } 182 183 handle_(approve, abort, xRequest); 184 } 185 //================================================================================ 186 187 LicenseCommandEnv::LicenseCommandEnv( 188 css::uno::Reference< css::task::XInteractionHandler> const & handler, 189 bool bSuppressLicense, 190 OUString const & repository): 191 BaseCommandEnv(handler), m_repository(repository), 192 m_bSuppressLicense(bSuppressLicense) 193 { 194 } 195 // XInteractionHandler 196 void LicenseCommandEnv::handle( 197 Reference< task::XInteractionRequest> const & xRequest ) 198 throw (uno::RuntimeException) 199 { 200 uno::Any request( xRequest->getRequest() ); 201 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION ); 202 203 204 deployment::LicenseException licExc; 205 206 bool approve = false; 207 bool abort = false; 208 209 if (request >>= licExc) 210 { 211 if (m_bSuppressLicense 212 || m_repository.equals(OUSTR("bundled")) 213 || licExc.AcceptBy.equals(OUSTR("admin"))) 214 { 215 //always approve in bundled case, because we do not support 216 //showing licenses anyway. 217 //The "admin" already accepted the license when installing the 218 // shared extension 219 approve = true; 220 } 221 } 222 223 handle_(approve, abort, xRequest); 224 } 225 226 //================================================================================ 227 //================================================================================ 228 229 NoLicenseCommandEnv::NoLicenseCommandEnv( 230 css::uno::Reference< css::task::XInteractionHandler> const & handler): 231 BaseCommandEnv(handler) 232 { 233 } 234 // XInteractionHandler 235 void NoLicenseCommandEnv::handle( 236 Reference< task::XInteractionRequest> const & xRequest ) 237 throw (uno::RuntimeException) 238 { 239 uno::Any request( xRequest->getRequest() ); 240 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION ); 241 242 243 deployment::LicenseException licExc; 244 245 bool approve = false; 246 bool abort = false; 247 248 if (request >>= licExc) 249 { 250 approve = true; 251 } 252 handle_(approve, abort, xRequest); 253 } 254 255 // SilentCheckPrerequisitesCommandEnv::SilentCheckPrerequisitesCommandEnv( 256 // css::uno::Reference< css::task::XInteractionHandler> const & handler): 257 // BaseCommandEnv(handler) 258 // { 259 // } 260 SilentCheckPrerequisitesCommandEnv::SilentCheckPrerequisitesCommandEnv() 261 { 262 } 263 264 void SilentCheckPrerequisitesCommandEnv::handle( 265 Reference< task::XInteractionRequest> const & xRequest ) 266 throw (uno::RuntimeException) 267 { 268 uno::Any request( xRequest->getRequest() ); 269 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION ); 270 271 deployment::LicenseException licExc; 272 deployment::PlatformException platformExc; 273 deployment::DependencyException depExc; 274 bool approve = false; 275 bool abort = false; 276 277 if (request >>= licExc) 278 { 279 approve = true; 280 handle_(approve, abort, xRequest); 281 } 282 else if ((request >>= platformExc) 283 || (request >>= depExc)) 284 { 285 m_Exception = request; 286 } 287 else 288 { 289 m_UnknownException = request; 290 } 291 } 292 // NoExceptionCommandEnv::NoExceptionCommandEnv( 293 // css::uno::Reference< css::task::XInteractionHandler> const & handler, 294 // css::uno::Type const & type): 295 // BaseCommandEnv(handler), 296 // m_type(type) 297 // { 298 // } 299 // // XInteractionHandler 300 // void NoExceptionCommandEnv::handle( 301 // Reference< task::XInteractionRequest> const & xRequest ) 302 // throw (uno::RuntimeException) 303 // { 304 // uno::Any request( xRequest->getRequest() ); 305 // OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION ); 306 307 308 // deployment::LicenseException licExc; 309 310 // bool approve = false; 311 // bool abort = false; 312 313 // if (request.getValueType() == m_type) 314 // { 315 // approve = true; 316 // } 317 // handle_(approve, abort, xRequest); 318 // } 319 320 321 322 } // namespace dp_manager 323 324 325