1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svtools/svtools.hrc>
21 #include <tools/resid.hxx>
22 #include <com/sun/star/task/XInteractionContinuation.hpp>
23 #include <com/sun/star/task/XInteractionAbort.hpp>
24 #include <com/sun/star/task/XInteractionRetry.hpp>
25 #include <com/sun/star/java/JavaNotFoundException.hpp>
26 #include <com/sun/star/java/InvalidJavaSettingsException.hpp>
27 #include <com/sun/star/java/JavaDisabledException.hpp>
28 #include <com/sun/star/java/JavaVMCreationFailureException.hpp>
29 #include <com/sun/star/java/RestartRequiredException.hpp>
30 #include <comphelper/processfactory.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/msgbox.hxx>
33 #include <osl/mutex.hxx>
34 #include <tools/string.hxx>
35 #include <tools/rcid.h>
36 #include <jvmfwk/framework.h>
38 #include <svtools/restartdialog.hxx>
39 #include <svtools/svtresid.hxx>
40 #include <svtools/javainteractionhandler.hxx>
41 #include <svtools/javacontext.hxx>
43 using namespace com::sun::star::uno
;
44 using namespace com::sun::star::task
;
49 JavaInteractionHandler::JavaInteractionHandler(bool bReportErrorOnce
) :
51 m_bShowErrorsOnce(bReportErrorOnce
),
52 m_bJavaDisabled_Handled(false),
53 m_bInvalidSettings_Handled(false),
54 m_bJavaNotFound_Handled(false),
55 m_bVMCreationFailure_Handled(false),
56 m_bRestartRequired_Handled(false),
57 m_nResult_JavaDisabled(RET_NO
)
61 JavaInteractionHandler::~JavaInteractionHandler()
65 Any SAL_CALL
JavaInteractionHandler::queryInterface(const Type
& aType
)
66 throw (RuntimeException
)
68 if (aType
== getCppuType(reinterpret_cast<Reference
<XInterface
>*>(0)))
69 return Any( static_cast<XInterface
*>(this), aType
);
70 else if (aType
== getCppuType(reinterpret_cast<Reference
<XInteractionHandler
>*>(0)))
71 return Any( static_cast<XInteractionHandler
*>(this), aType
);
75 void SAL_CALL
JavaInteractionHandler::acquire( ) throw ()
77 osl_atomic_increment( &m_aRefCount
);
80 void SAL_CALL
JavaInteractionHandler::release( ) throw ()
82 if (! osl_atomic_decrement( &m_aRefCount
))
87 void SAL_CALL
JavaInteractionHandler::handle( const Reference
< XInteractionRequest
>& Request
) throw (RuntimeException
)
89 Any anyExc
= Request
->getRequest();
90 Sequence
< Reference
< XInteractionContinuation
> > aSeqCont
= Request
->getContinuations();
92 Reference
< XInteractionAbort
> abort
;
93 Reference
< XInteractionRetry
> retry
;
96 for ( i
= 0; i
< aSeqCont
.getLength(); i
++ )
98 abort
= Reference
< XInteractionAbort
>::query( aSeqCont
[i
]);
103 for ( i
= 0; i
< aSeqCont
.getLength(); i
++)
105 retry
= Reference
<XInteractionRetry
>::query( aSeqCont
[i
]);
110 com::sun::star::java::JavaNotFoundException e1
;
111 com::sun::star::java::InvalidJavaSettingsException e2
;
112 com::sun::star::java::JavaDisabledException e3
;
113 com::sun::star::java::JavaVMCreationFailureException e4
;
114 com::sun::star::java::RestartRequiredException e5
;
115 // Try to recover the Exception type in the any and
116 // react accordingly.
117 sal_uInt16 nResult
= RET_CANCEL
;
121 if( ! (m_bShowErrorsOnce
&& m_bJavaNotFound_Handled
))
123 // No suitable JRE found
124 SolarMutexGuard aSolarGuard
;
125 m_bJavaNotFound_Handled
= true;
126 WarningBox
aWarningBox( NULL
, SvtResId( WARNINGBOX_JAVANOTFOUND
) );
127 aWarningBox
.SetText(SvtResId(STR_WARNING_JAVANOTFOUND
).toString());
128 nResult
= aWarningBox
.Execute();
135 else if ( anyExc
>>= e2
)
137 if( !(m_bShowErrorsOnce
&& m_bInvalidSettings_Handled
))
139 // javavendors.xml was updated and Java has not been configured yet
140 SolarMutexGuard aSolarGuard
;
141 m_bInvalidSettings_Handled
= true;
143 WarningBox
aWarningBox( NULL
, SvtResId( WARNINGBOX_INVALIDJAVASETTINGS_MAC
) );
145 WarningBox
aWarningBox( NULL
, SvtResId( WARNINGBOX_INVALIDJAVASETTINGS
) );
147 aWarningBox
.SetText(SvtResId(STR_WARNING_INVALIDJAVASETTINGS
).toString());
148 nResult
= aWarningBox
.Execute();
155 else if ( anyExc
>>= e3
)
157 if( !(m_bShowErrorsOnce
&& m_bJavaDisabled_Handled
))
159 SolarMutexGuard aSolarGuard
;
160 m_bJavaDisabled_Handled
= true;
161 // Java disabled. Give user a chance to enable Java inside Office.
162 QueryBox
aQueryBox( NULL
, SvtResId( QBX_JAVADISABLED
) );
163 aQueryBox
.SetText(SvtResId( STR_QUESTION_JAVADISABLED
).toString());
164 nResult
= aQueryBox
.Execute();
165 if ( nResult
== RET_YES
)
167 jfw_setEnabled(sal_True
);
170 m_nResult_JavaDisabled
= nResult
;
175 nResult
= m_nResult_JavaDisabled
;
178 else if ( anyExc
>>= e4
)
180 if( !(m_bShowErrorsOnce
&& m_bVMCreationFailure_Handled
))
182 // Java not correctly installed, or damaged
183 SolarMutexGuard aSolarGuard
;
184 m_bVMCreationFailure_Handled
= true;
186 ErrorBox
aErrorBox( NULL
, SvtResId( ERRORBOX_JVMCREATIONFAILED_MAC
) );
188 ErrorBox
aErrorBox( NULL
, SvtResId( ERRORBOX_JVMCREATIONFAILED
) );
190 aErrorBox
.SetText(SvtResId( STR_ERROR_JVMCREATIONFAILED
).toString());
191 nResult
= aErrorBox
.Execute();
198 else if ( anyExc
>>= e5
)
200 if( !(m_bShowErrorsOnce
&& m_bRestartRequired_Handled
))
202 // a new JRE was selected, but office needs to be restarted
203 //before it can be used.
204 SolarMutexGuard aSolarGuard
;
205 m_bRestartRequired_Handled
= true;
206 svtools::executeRestartDialog(
207 comphelper::getProcessComponentContext(), 0,
208 svtools::RESTART_REASON_JAVA
);
213 if ( nResult
== RET_CANCEL
|| nResult
== RET_NO
)
215 // Unknown exception type or user wants to cancel
219 else // nResult == RET_OK
221 // User selected OK => retry Java usage
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */