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