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_svtools.hxx" 26 27 28 29 #include <svtools/svtools.hrc> 30 #include <tools/resid.hxx> 31 #include <com/sun/star/task/XInteractionContinuation.hpp> 32 #include <com/sun/star/task/XInteractionAbort.hpp> 33 #include <com/sun/star/task/XInteractionRetry.hpp> 34 #include <com/sun/star/java/JavaNotFoundException.hpp> 35 #include <com/sun/star/java/InvalidJavaSettingsException.hpp> 36 #include <com/sun/star/java/JavaDisabledException.hpp> 37 #include <com/sun/star/java/JavaVMCreationFailureException.hpp> 38 #include <com/sun/star/java/RestartRequiredException.hpp> 39 #include <vcl/svapp.hxx> 40 #include <vcl/msgbox.hxx> 41 #include <vos/mutex.hxx> 42 #include <tools/string.hxx> 43 #include <tools/rcid.h> 44 #include <jvmfwk/framework.h> 45 46 #include <svtools/svtdata.hxx> 47 #include <svtools/javainteractionhandler.hxx> 48 #include <svtools/javacontext.hxx> 49 50 using namespace com::sun::star::uno; 51 using namespace com::sun::star::task; 52 53 namespace svt 54 { 55 56 JavaInteractionHandler::JavaInteractionHandler(): 57 m_aRefCount(0), 58 m_bShowErrorsOnce(false), 59 m_bJavaDisabled_Handled(false), 60 m_bInvalidSettings_Handled(false), 61 m_bJavaNotFound_Handled(false), 62 m_bVMCreationFailure_Handled(false), 63 m_bRestartRequired_Handled(false), 64 m_nResult_JavaDisabled(RET_NO) 65 { 66 } 67 68 JavaInteractionHandler::JavaInteractionHandler(bool bReportErrorOnce) : 69 m_aRefCount(0), 70 m_bShowErrorsOnce(bReportErrorOnce), 71 m_bJavaDisabled_Handled(false), 72 m_bInvalidSettings_Handled(false), 73 m_bJavaNotFound_Handled(false), 74 m_bVMCreationFailure_Handled(false), 75 m_bRestartRequired_Handled(false), 76 m_nResult_JavaDisabled(RET_NO) 77 { 78 } 79 80 JavaInteractionHandler::~JavaInteractionHandler() 81 { 82 } 83 84 Any SAL_CALL JavaInteractionHandler::queryInterface(const Type& aType ) 85 { 86 if (aType == getCppuType(reinterpret_cast<Reference<XInterface>*>(0))) 87 return Any( static_cast<XInterface*>(this), aType); 88 else if (aType == getCppuType(reinterpret_cast<Reference<XInteractionHandler>*>(0))) 89 return Any( static_cast<XInteractionHandler*>(this), aType); 90 return Any(); 91 } 92 93 void SAL_CALL JavaInteractionHandler::acquire( ) throw () 94 { 95 osl_incrementInterlockedCount( &m_aRefCount ); 96 } 97 98 void SAL_CALL JavaInteractionHandler::release( ) throw () 99 { 100 if (! osl_decrementInterlockedCount( &m_aRefCount )) 101 delete this; 102 } 103 104 105 void SAL_CALL JavaInteractionHandler::handle( const Reference< XInteractionRequest >& Request ) 106 { 107 Any anyExc = Request->getRequest(); 108 Sequence< Reference< XInteractionContinuation > > aSeqCont = Request->getContinuations(); 109 110 Reference< XInteractionAbort > abort; 111 Reference< XInteractionRetry > retry; 112 sal_Int32 i; 113 114 for ( i = 0; i < aSeqCont.getLength(); i++ ) 115 { 116 abort = Reference< XInteractionAbort>::query( aSeqCont[i]); 117 if ( abort.is() ) 118 break; 119 } 120 121 for ( i= 0; i < aSeqCont.getLength(); i++) 122 { 123 retry= Reference<XInteractionRetry>::query( aSeqCont[i]); 124 if ( retry.is() ) 125 break; 126 } 127 128 com::sun::star::java::JavaNotFoundException e1; 129 com::sun::star::java::InvalidJavaSettingsException e2; 130 com::sun::star::java::JavaDisabledException e3; 131 com::sun::star::java::JavaVMCreationFailureException e4; 132 com::sun::star::java::RestartRequiredException e5; 133 // Try to recover the Exception type in the any and 134 // react accordingly. 135 sal_uInt16 nResult = RET_CANCEL; 136 ::rtl::OUString aParameter; 137 138 if ( anyExc >>= e1 ) 139 { 140 if( ! (m_bShowErrorsOnce && m_bJavaNotFound_Handled)) 141 { 142 // No suitable JRE found 143 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 144 m_bJavaNotFound_Handled = true; 145 WarningBox aWarningBox( NULL, SvtResId( WARNINGBOX_JAVANOTFOUND ) ); 146 String aTitle( SvtResId( STR_WARNING_JAVANOTFOUND ) ); 147 aWarningBox.SetText( aTitle ); 148 nResult = aWarningBox.Execute(); 149 } 150 else 151 { 152 nResult = RET_OK; 153 } 154 } 155 else if ( anyExc >>= e2 ) 156 { 157 if( !(m_bShowErrorsOnce && m_bInvalidSettings_Handled)) 158 { 159 // javavendors.xml was updated and Java has not been configured yet 160 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 161 m_bInvalidSettings_Handled = true; 162 WarningBox aWarningBox( NULL, SvtResId( WARNINGBOX_INVALIDJAVASETTINGS ) ); 163 String aTitle( SvtResId(STR_WARNING_INVALIDJAVASETTINGS)); 164 aWarningBox.SetText( aTitle ); 165 nResult = aWarningBox.Execute(); 166 } 167 else 168 { 169 nResult = RET_OK; 170 } 171 } 172 else if ( anyExc >>= e3 ) 173 { 174 if( !(m_bShowErrorsOnce && m_bJavaDisabled_Handled)) 175 { 176 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 177 m_bJavaDisabled_Handled = true; 178 // Java disabled. Give user a chance to enable Java inside Office. 179 QueryBox aQueryBox( NULL, SvtResId( QBX_JAVADISABLED ) ); 180 String aTitle( SvtResId( STR_QUESTION_JAVADISABLED ) ); 181 aQueryBox.SetText( aTitle ); 182 nResult = aQueryBox.Execute(); 183 if ( nResult == RET_YES ) 184 { 185 jfw_setEnabled(sal_True); 186 } 187 188 m_nResult_JavaDisabled = nResult; 189 190 } 191 else 192 { 193 nResult = m_nResult_JavaDisabled; 194 } 195 } 196 else if ( anyExc >>= e4 ) 197 { 198 if( !(m_bShowErrorsOnce && m_bVMCreationFailure_Handled)) 199 { 200 // Java not correctly installed, or damaged 201 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 202 m_bVMCreationFailure_Handled = true; 203 ErrorBox aErrorBox( NULL, SvtResId( ERRORBOX_JVMCREATIONFAILED ) ); 204 String aTitle( SvtResId( STR_ERROR_JVMCREATIONFAILED ) ); 205 aErrorBox.SetText( aTitle ); 206 nResult = aErrorBox.Execute(); 207 } 208 else 209 { 210 nResult = RET_OK; 211 } 212 } 213 else if ( anyExc >>= e5 ) 214 { 215 if( !(m_bShowErrorsOnce && m_bRestartRequired_Handled)) 216 { 217 // a new JRE was selected, but office needs to be restarted 218 //before it can be used. 219 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 220 m_bRestartRequired_Handled = true; 221 ErrorBox aErrorBox(NULL, SvtResId( ERRORBOX_RESTARTREQUIRED ) ); 222 String aTitle( SvtResId( STR_ERROR_RESTARTREQUIRED ) ); 223 aErrorBox.SetText( aTitle ); 224 nResult = aErrorBox.Execute(); 225 } 226 else 227 { 228 nResult = RET_OK; 229 } 230 } 231 232 if ( nResult == RET_CANCEL || nResult == RET_NO) 233 { 234 // Unknown exception type or user wants to cancel 235 if ( abort.is() ) 236 abort->select(); 237 } 238 else // nResult == RET_OK 239 { 240 // User selected OK => retry Java usage 241 if ( retry.is() ) 242 retry->select(); 243 } 244 } 245 246 } 247