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 package com.sun.star.comp.juhtest; 28 29 import com.sun.star.lang.XMultiComponentFactory; 30 import com.sun.star.lib.uno.helper.WeakBase; 31 import com.sun.star.uno.UnoRuntime; 32 import com.sun.star.uno.XComponentContext; 33 import com.sun.star.lang.XServiceInfo; 34 import com.sun.star.ucb.XCommandEnvironment; 35 36 /** This service is for use by the smoketest which checks the installation of 37 * extensions. The service provides the XCommandEnvironment interface, which 38 * is needed for adding extensions. 39 */ 40 public class SmoketestCommandEnvironment extends WeakBase 41 implements XServiceInfo, XCommandEnvironment { 42 43 static private final String __serviceName = 44 "com.sun.star.deployment.test.SmoketestCommandEnvironment"; 45 46 private XComponentContext m_cmpCtx; 47 private XMultiComponentFactory m_xMCF; 48 49 50 public SmoketestCommandEnvironment(XComponentContext xCompContext) { 51 try { 52 m_cmpCtx = xCompContext; 53 m_xMCF = m_cmpCtx.getServiceManager(); 54 } 55 catch( Exception e ) { 56 e.printStackTrace(); 57 } 58 } 59 60 public static String[] getServiceNames() { 61 String[] sSupportedServiceNames = { __serviceName}; 62 return sSupportedServiceNames; 63 } 64 65 //XServiceInfo ------------------------------------------------------------- 66 public String[] getSupportedServiceNames() { 67 return getServiceNames(); 68 } 69 70 71 public boolean supportsService( String sServiceName ) { 72 boolean bSupported = false; 73 if (sServiceName.equals(__serviceName)) 74 bSupported = true; 75 return bSupported; 76 } 77 78 public String getImplementationName() { 79 return SmoketestCommandEnvironment.class.getName(); 80 } 81 82 //XCommandEnvironment ================================================ 83 public com.sun.star.task.XInteractionHandler getInteractionHandler() 84 { 85 return new InteractionImpl(); 86 } 87 88 public com.sun.star.ucb.XProgressHandler getProgressHandler() 89 { 90 return new ProgressImpl(); 91 } 92 } 93 94 95 96 97 class InteractionImpl implements com.sun.star.task.XInteractionHandler 98 { 99 public void handle( com.sun.star.task.XInteractionRequest xRequest ) 100 { 101 Object request = xRequest.getRequest(); 102 103 boolean approve = true; 104 boolean abort = false; 105 // Object install_Exception = 106 // AnyConverter.toObject( 107 // com.sun.star.deployment.InstallException.class, request); 108 // if (install_Exception != null) 109 // { 110 // approve = true; 111 // } 112 113 com.sun.star.task.XInteractionContinuation[] conts = xRequest.getContinuations(); 114 for (int i = 0; i < conts.length; i++) 115 { 116 if (approve) 117 { 118 com.sun.star.task.XInteractionApprove xApprove = 119 UnoRuntime.queryInterface(com.sun.star.task.XInteractionApprove.class, conts[i]); 120 if (xApprove != null) 121 xApprove.select(); 122 //don't query again for ongoing extensions 123 approve = false; 124 } 125 else if (abort) 126 { 127 com.sun.star.task.XInteractionAbort xAbort = 128 UnoRuntime.queryInterface(com.sun.star.task.XInteractionAbort.class, conts[i]); 129 if (xAbort != null) 130 xAbort.select(); 131 //don't query again for ongoing extensions 132 abort = false; 133 } 134 } 135 } 136 } 137 138 class ProgressImpl implements com.sun.star.ucb.XProgressHandler 139 { 140 public void push(Object status) 141 { 142 } 143 144 public void update(Object status) 145 { 146 } 147 148 public void pop() 149 { 150 } 151 } 152