1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: javainteractionhandler.cxx,v $
10 * $Revision: 1.7.152.1 $
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_svtools.hxx"
36 #include <svtools/svtools.hrc>
37 #include <tools/resid.hxx>
38 #include <com/sun/star/task/XInteractionContinuation.hpp>
39 #include <com/sun/star/task/XInteractionAbort.hpp>
40 #include <com/sun/star/task/XInteractionRetry.hpp>
41 #include <com/sun/star/java/JavaNotFoundException.hpp>
42 #include <com/sun/star/java/InvalidJavaSettingsException.hpp>
43 #include <com/sun/star/java/JavaDisabledException.hpp>
44 #include <com/sun/star/java/JavaVMCreationFailureException.hpp>
45 #include <com/sun/star/java/RestartRequiredException.hpp>
46 #include <vcl/svapp.hxx>
47 #include <vcl/msgbox.hxx>
48 #include <vos/mutex.hxx>
49 #include <tools/string.hxx>
50 #include <tools/rcid.h>
51 #include <jvmfwk/framework.h>
53 #include <svtools/svtdata.hxx>
54 #include <svtools/javainteractionhandler.hxx>
55 #include <svtools/javacontext.hxx>
57 using namespace com::sun::star::uno
;
58 using namespace com::sun::star::task
;
63 JavaInteractionHandler::JavaInteractionHandler():
65 m_bShowErrorsOnce(false),
66 m_bJavaDisabled_Handled(false),
67 m_bInvalidSettings_Handled(false),
68 m_bJavaNotFound_Handled(false),
69 m_bVMCreationFailure_Handled(false),
70 m_bRestartRequired_Handled(false),
71 m_nResult_JavaDisabled(RET_NO
)
75 JavaInteractionHandler::JavaInteractionHandler(bool bReportErrorOnce
) :
77 m_bShowErrorsOnce(bReportErrorOnce
),
78 m_bJavaDisabled_Handled(false),
79 m_bInvalidSettings_Handled(false),
80 m_bJavaNotFound_Handled(false),
81 m_bVMCreationFailure_Handled(false),
82 m_bRestartRequired_Handled(false),
83 m_nResult_JavaDisabled(RET_NO
)
87 JavaInteractionHandler::~JavaInteractionHandler()
91 Any SAL_CALL
JavaInteractionHandler::queryInterface(const Type
& aType
)
92 throw (RuntimeException
)
94 if (aType
== getCppuType(reinterpret_cast<Reference
<XInterface
>*>(0)))
95 return Any( static_cast<XInterface
*>(this), aType
);
96 else if (aType
== getCppuType(reinterpret_cast<Reference
<XInteractionHandler
>*>(0)))
97 return Any( static_cast<XInteractionHandler
*>(this), aType
);
101 void SAL_CALL
JavaInteractionHandler::acquire( ) throw ()
103 osl_incrementInterlockedCount( &m_aRefCount
);
106 void SAL_CALL
JavaInteractionHandler::release( ) throw ()
108 if (! osl_decrementInterlockedCount( &m_aRefCount
))
113 void SAL_CALL
JavaInteractionHandler::handle( const Reference
< XInteractionRequest
>& Request
) throw (RuntimeException
)
115 Any anyExc
= Request
->getRequest();
116 Sequence
< Reference
< XInteractionContinuation
> > aSeqCont
= Request
->getContinuations();
118 Reference
< XInteractionAbort
> abort
;
119 Reference
< XInteractionRetry
> retry
;
122 for ( i
= 0; i
< aSeqCont
.getLength(); i
++ )
124 abort
= Reference
< XInteractionAbort
>::query( aSeqCont
[i
]);
129 for ( i
= 0; i
< aSeqCont
.getLength(); i
++)
131 retry
= Reference
<XInteractionRetry
>::query( aSeqCont
[i
]);
136 com::sun::star::java::JavaNotFoundException e1
;
137 com::sun::star::java::InvalidJavaSettingsException e2
;
138 com::sun::star::java::JavaDisabledException e3
;
139 com::sun::star::java::JavaVMCreationFailureException e4
;
140 com::sun::star::java::RestartRequiredException e5
;
141 // Try to recover the Exception type in the any and
142 // react accordingly.
143 USHORT nResult
= RET_CANCEL
;
144 ::rtl::OUString aParameter
;
148 if( ! (m_bShowErrorsOnce
&& m_bJavaNotFound_Handled
))
150 // No suitable JRE found
151 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
152 m_bJavaNotFound_Handled
= true;
153 //We first try to get the patch resource svp680xxx.res
154 //If the resource is not found then svt680xxx.res is used
155 ResId idWBX
= SvtResId(WARNINGBOX_JAVANOTFOUND
);
156 SvpResId
pidPatchWBX(WARNINGBOX_JAVANOTFOUND
);
157 pidPatchWBX
.SetRT(RSC_WARNINGBOX
);
158 ResMgr
*pMgrWB
= pidPatchWBX
.GetResMgr();
159 if (pMgrWB
&& pMgrWB
->IsAvailable(pidPatchWBX
))
161 WarningBox
aWarningBox( NULL
, idWBX
);
164 SvpResId
pidString(STR_WARNING_JAVANOTFOUND
);
165 pidString
.SetRT(RSC_STRING
);
166 ResMgr
*pmgr
= pidString
.GetResMgr();
167 if ( pmgr
&& pmgr
->IsAvailable(pidString
))
168 aTitle
= String(pidString
);
170 aTitle
= String( SvtResId( STR_WARNING_JAVANOTFOUND
));
172 aWarningBox
.SetText( aTitle
);
173 nResult
= aWarningBox
.Execute();
181 else if ( anyExc
>>= e2
)
183 if( !(m_bShowErrorsOnce
&& m_bInvalidSettings_Handled
))
185 // javavendors.xml was updated and Java has not been configured yet
186 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
187 m_bInvalidSettings_Handled
= true;
188 //We first try to get the patch resource svp680xxx.res
189 //If the resource is not found then svt680xxx.res is used
190 ResId idWBX
= SvtResId(WARNINGBOX_INVALIDJAVASETTINGS
);
191 SvpResId
pidPatchWBX(WARNINGBOX_INVALIDJAVASETTINGS
);
192 pidPatchWBX
.SetRT(RSC_WARNINGBOX
);
193 ResMgr
*pMgrWB
= pidPatchWBX
.GetResMgr();
194 if (pMgrWB
&& pMgrWB
->IsAvailable(pidPatchWBX
))
196 WarningBox
aWarningBox( NULL
, idWBX
);
199 SvpResId
pidString(STR_WARNING_INVALIDJAVASETTINGS
);
200 pidString
.SetRT(RSC_STRING
);
201 ResMgr
*pmgr
= pidString
.GetResMgr();
202 if ( pmgr
&& pmgr
->IsAvailable(pidString
))
203 aTitle
= String(pidString
);
205 aTitle
= String( SvtResId(STR_WARNING_INVALIDJAVASETTINGS
));
207 aWarningBox
.SetText( aTitle
);
208 nResult
= aWarningBox
.Execute();
215 else if ( anyExc
>>= e3
)
217 if( !(m_bShowErrorsOnce
&& m_bJavaDisabled_Handled
))
219 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
220 m_bJavaDisabled_Handled
= true;
221 // Java disabled. Give user a chance to enable Java inside Office.
222 //We first try to get the patch resource svp680xxx.res
223 //If the resource is not found then svt680xxx.res is used
224 ResId idQBX
= SvtResId( QBX_JAVADISABLED
);
225 SvpResId
pidPatchQBX(QBX_JAVADISABLED
);
226 pidPatchQBX
.SetRT(RSC_QUERYBOX
);
227 ResMgr
*pMgrQB
= pidPatchQBX
.GetResMgr();
229 if (pMgrQB
&& pMgrQB
->IsAvailable(pidPatchQBX
))
232 QueryBox
aQueryBox(NULL
, idQBX
);
236 SvpResId
pidString(STR_QUESTION_JAVADISABLED
);
237 pidString
.SetRT(RSC_STRING
);
238 ResMgr
*pmgr
= pidString
.GetResMgr();
239 if ( pmgr
&& pmgr
->IsAvailable(pidString
))
240 aTitle
= String(pidString
);
242 aTitle
= String( SvtResId( STR_QUESTION_JAVADISABLED
));
244 aQueryBox
.SetText( aTitle
);
245 nResult
= aQueryBox
.Execute();
246 if ( nResult
== RET_YES
)
248 jfw_setEnabled(sal_True
);
251 m_nResult_JavaDisabled
= nResult
;
256 nResult
= m_nResult_JavaDisabled
;
259 else if ( anyExc
>>= e4
)
261 if( !(m_bShowErrorsOnce
&& m_bVMCreationFailure_Handled
))
263 // Java not correctly installed, or damaged
264 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
265 m_bVMCreationFailure_Handled
= true;
266 //We first try to get the patch resource svp680xxx.res
267 //If the resource is not found then svt680xxx.res is used
268 ResId idEBX
= SvtResId(ERRORBOX_JVMCREATIONFAILED
);
269 SvpResId
pidPatchEBX(ERRORBOX_JVMCREATIONFAILED
);
270 pidPatchEBX
.SetRT(RSC_ERRORBOX
);
271 ResMgr
*pMgrEB
= pidPatchEBX
.GetResMgr();
272 if (pMgrEB
&& pMgrEB
->IsAvailable(pidPatchEBX
))
274 ErrorBox
aErrorBox( NULL
, idEBX
);
277 SvpResId
pidString(STR_ERROR_JVMCREATIONFAILED
);
278 pidString
.SetRT(RSC_STRING
);
279 ResMgr
*pmgr
= pidString
.GetResMgr();
280 if ( pmgr
&& pmgr
->IsAvailable(pidString
))
281 aTitle
= String(pidString
);
283 aTitle
= String( SvtResId(STR_ERROR_JVMCREATIONFAILED
));
285 aErrorBox
.SetText( aTitle
);
286 nResult
= aErrorBox
.Execute();
293 else if ( anyExc
>>= e5
)
295 if( !(m_bShowErrorsOnce
&& m_bRestartRequired_Handled
))
297 // a new JRE was selected, but office needs to be restarted
298 //before it can be used.
299 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
300 m_bRestartRequired_Handled
= true;
301 //We first try to get the patch resource svp680xxx.res
302 //If the resource is not found then svt680xxx.res is used
303 ResId idEBX
= SvtResId(ERRORBOX_RESTARTREQUIRED
);
304 SvpResId
pidPatchEBX(ERRORBOX_RESTARTREQUIRED
);
305 pidPatchEBX
.SetRT(RSC_ERRORBOX
);
306 ResMgr
*pMgrEB
= pidPatchEBX
.GetResMgr();
307 if (pMgrEB
&& pMgrEB
->IsAvailable(pidPatchEBX
))
309 ErrorBox
aErrorBox(NULL
, idEBX
);
312 SvpResId
pidString(STR_ERROR_RESTARTREQUIRED
);
313 pidString
.SetRT(RSC_STRING
);
314 ResMgr
*pmgr
= pidString
.GetResMgr();
315 if ( pmgr
&& pmgr
->IsAvailable(pidString
))
316 aTitle
= String(pidString
);
318 aTitle
= String( SvtResId(STR_ERROR_RESTARTREQUIRED
));
320 aErrorBox
.SetText( aTitle
);
321 nResult
= aErrorBox
.Execute();
329 if ( nResult
== RET_CANCEL
|| nResult
== RET_NO
)
331 // Unknown exception type or user wants to cancel
335 else // nResult == RET_OK
337 // User selected OK => retry Java usage