113efc523SAndrew Rist /**************************************************************
2*c2e1856cSmseidel  *
313efc523SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
413efc523SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
513efc523SAndrew Rist  * distributed with this work for additional information
613efc523SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
713efc523SAndrew Rist  * to you under the Apache License, Version 2.0 (the
813efc523SAndrew Rist  * "License"); you may not use this file except in compliance
913efc523SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c2e1856cSmseidel  *
1113efc523SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c2e1856cSmseidel  *
1313efc523SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1413efc523SAndrew Rist  * software distributed under the License is distributed on an
1513efc523SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1613efc523SAndrew Rist  * KIND, either express or implied.  See the License for the
1713efc523SAndrew Rist  * specific language governing permissions and limitations
1813efc523SAndrew Rist  * under the License.
19*c2e1856cSmseidel  *
2013efc523SAndrew Rist  *************************************************************/
2113efc523SAndrew Rist 
2213efc523SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.wiki;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.awt.XDialog;
27cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer;
28cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
29cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
30cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
31cdf0e10cSrcweir import com.sun.star.lang.EventObject;
32cdf0e10cSrcweir import java.util.Hashtable;
33cdf0e10cSrcweir import javax.net.ssl.SSLException;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir import org.apache.commons.httpclient.*;
36cdf0e10cSrcweir import org.apache.commons.httpclient.methods.*;
37cdf0e10cSrcweir 
38*c2e1856cSmseidel public class WikiEditSettingDialog extends WikiDialog
39cdf0e10cSrcweir {
40*c2e1856cSmseidel 
41cdf0e10cSrcweir     private final String sOKMethod = "OK";
42cdf0e10cSrcweir 
43*c2e1856cSmseidel     String[] Methods =
44cdf0e10cSrcweir     {sOKMethod };
45cdf0e10cSrcweir     private Hashtable setting;
46cdf0e10cSrcweir     private boolean addMode;
47cdf0e10cSrcweir     private boolean m_bAllowURLChange = true;
48cdf0e10cSrcweir 
WikiEditSettingDialog( XComponentContext xContext, String DialogURL )49*c2e1856cSmseidel     public WikiEditSettingDialog( XComponentContext xContext, String DialogURL )
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         super( xContext, DialogURL );
52cdf0e10cSrcweir         super.setMethods( Methods );
53cdf0e10cSrcweir         setting = new Hashtable();
54cdf0e10cSrcweir         addMode = true;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir         InsertThrobber( 184, 20, 10, 10 );
57cdf0e10cSrcweir         InitStrings( xContext );
58*c2e1856cSmseidel         InitSaveCheckbox( xContext, false );
59cdf0e10cSrcweir     }
60*c2e1856cSmseidel 
WikiEditSettingDialog( XComponentContext xContext, String DialogURL, Hashtable ht, boolean bAllowURLChange )61*c2e1856cSmseidel     public WikiEditSettingDialog( XComponentContext xContext, String DialogURL, Hashtable ht, boolean bAllowURLChange )
62cdf0e10cSrcweir     {
63cdf0e10cSrcweir         super( xContext, DialogURL );
64cdf0e10cSrcweir         super.setMethods( Methods );
65cdf0e10cSrcweir         setting = ht;
66*c2e1856cSmseidel 
67cdf0e10cSrcweir         boolean bInitSaveCheckBox = false;
68*c2e1856cSmseidel 
69*c2e1856cSmseidel         try
70cdf0e10cSrcweir         {
71cdf0e10cSrcweir             XPropertySet xUrlField = GetPropSet( "UrlField" );
72*c2e1856cSmseidel 
73cdf0e10cSrcweir             xUrlField.setPropertyValue( "Text", ht.get( "Url" ) );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir             GetPropSet( "UsernameField" ).setPropertyValue( "Text", ht.get( "Username" ) );
76cdf0e10cSrcweir 
77cdf0e10cSrcweir             if ( Helper.PasswordStoringIsAllowed( m_xContext ) )
78cdf0e10cSrcweir             {
79cdf0e10cSrcweir                 String[] pPasswords = Helper.GetPasswordsForURLAndUser( m_xContext, (String)ht.get( "Url" ), (String)ht.get( "Username" ) );
80cdf0e10cSrcweir                 bInitSaveCheckBox = ( pPasswords != null && pPasswords.length > 0 && pPasswords[0].equals( (String)ht.get( "Password" ) ) );
81cdf0e10cSrcweir             }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir             // the password should be entered by the user or the Cancel should be pressed
84cdf0e10cSrcweir             // GetPropSet( "PasswordField" ).setPropertyValue( "Text", ht.get( "Password" ));
85cdf0e10cSrcweir         }
86*c2e1856cSmseidel         catch ( Exception ex )
87cdf0e10cSrcweir         {
88cdf0e10cSrcweir             ex.printStackTrace();
89*c2e1856cSmseidel         }
90cdf0e10cSrcweir 
91*c2e1856cSmseidel         addMode = false;
92cdf0e10cSrcweir         m_bAllowURLChange = bAllowURLChange;
93*c2e1856cSmseidel 
94cdf0e10cSrcweir         InsertThrobber( 184, 20, 10, 10 );
95cdf0e10cSrcweir         InitStrings( xContext );
96cdf0e10cSrcweir         InitSaveCheckbox( xContext, bInitSaveCheckBox );
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
show( )99*c2e1856cSmseidel     public boolean show( )
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         SetThrobberVisible( false );
102cdf0e10cSrcweir         EnableControls( true );
103cdf0e10cSrcweir         boolean bResult = super.show();
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         try
106cdf0e10cSrcweir         {
107cdf0e10cSrcweir             if ( bResult && Helper.PasswordStoringIsAllowed( m_xContext )
108cdf0e10cSrcweir               && ( (Short)( GetPropSet( "SaveBox" ).getPropertyValue("State") ) ).shortValue() != (short)0 )
109cdf0e10cSrcweir             {
110cdf0e10cSrcweir                 String sURL = (String)setting.get( "Url" );
111cdf0e10cSrcweir                 String sUserName = (String)setting.get( "Username" );
112cdf0e10cSrcweir                 String sPassword = (String)setting.get( "Password" );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir                 if ( sURL != null && sURL.length() > 0 && sUserName != null && sUserName.length() > 0 && sPassword != null && sPassword.length() > 0 )
115cdf0e10cSrcweir                 {
116cdf0e10cSrcweir                     String[] pPasswords = { sPassword };
117cdf0e10cSrcweir                     Helper.GetPasswordContainer( m_xContext ).addPersistent( sURL, sUserName, pPasswords, Helper.GetInteractionHandler( m_xContext ) );
118cdf0e10cSrcweir                 }
119cdf0e10cSrcweir             }
120cdf0e10cSrcweir         }
121cdf0e10cSrcweir         catch( Exception e )
122cdf0e10cSrcweir         {
123cdf0e10cSrcweir             e.printStackTrace();
124cdf0e10cSrcweir         }
125*c2e1856cSmseidel 
126cdf0e10cSrcweir         return bResult;
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir 
EnableControls( boolean bEnable )129cdf0e10cSrcweir     public void EnableControls( boolean bEnable )
130cdf0e10cSrcweir     {
131cdf0e10cSrcweir         if ( !bEnable )
132cdf0e10cSrcweir             SetFocusTo( "CancelButton" );
133cdf0e10cSrcweir 
134*c2e1856cSmseidel         try
135cdf0e10cSrcweir         {
136cdf0e10cSrcweir             GetPropSet( "UsernameField" ).setPropertyValue( "Enabled", new Boolean( bEnable ) );
137cdf0e10cSrcweir             GetPropSet( "PasswordField" ).setPropertyValue( "Enabled", new Boolean( bEnable ) );
138cdf0e10cSrcweir             GetPropSet( "OkButton" ).setPropertyValue( "Enabled", new Boolean( bEnable ) );
139cdf0e10cSrcweir             GetPropSet( "HelpButton" ).setPropertyValue( "Enabled", new Boolean( bEnable ) );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir             if ( bEnable )
142cdf0e10cSrcweir             {
143cdf0e10cSrcweir                 GetPropSet( "UrlField" ).setPropertyValue( "Enabled", new Boolean( m_bAllowURLChange ) );
144cdf0e10cSrcweir                 GetPropSet( "SaveBox" ).setPropertyValue( "Enabled", new Boolean( Helper.PasswordStoringIsAllowed( m_xContext ) ) );
145cdf0e10cSrcweir                 if ( m_bAllowURLChange )
146cdf0e10cSrcweir                     SetFocusTo( "UrlField" );
147cdf0e10cSrcweir                 else
148cdf0e10cSrcweir                     SetFocusTo( "UsernameField" );
149cdf0e10cSrcweir             }
150cdf0e10cSrcweir             else
151cdf0e10cSrcweir             {
152cdf0e10cSrcweir                 GetPropSet( "UrlField" ).setPropertyValue( "Enabled", Boolean.FALSE );
153cdf0e10cSrcweir                 GetPropSet( "SaveBox" ).setPropertyValue( "Enabled", Boolean.FALSE );
154cdf0e10cSrcweir             }
155cdf0e10cSrcweir         }
156*c2e1856cSmseidel         catch ( Exception ex )
157cdf0e10cSrcweir         {
158cdf0e10cSrcweir             ex.printStackTrace();
159*c2e1856cSmseidel         }
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir 
InitStrings( XComponentContext xContext )162cdf0e10cSrcweir     private void InitStrings( XComponentContext xContext )
163cdf0e10cSrcweir     {
164cdf0e10cSrcweir         try
165cdf0e10cSrcweir         {
166cdf0e10cSrcweir             SetTitle( Helper.GetLocalizedString( xContext, Helper.DLG_MEDIAWIKI_TITLE ) );
167cdf0e10cSrcweir             GetPropSet( "UrlLabel" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_EDITSETTING_URLLABEL ) );
168cdf0e10cSrcweir             GetPropSet( "UsernameLabel" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_EDITSETTING_USERNAMELABEL ) );
169cdf0e10cSrcweir             GetPropSet( "PasswordLabel" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_EDITSETTING_PASSWORDLABEL ) );
170cdf0e10cSrcweir             GetPropSet( "AccountLine" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_EDITSETTING_ACCOUNTLINE ) );
171cdf0e10cSrcweir             GetPropSet( "WikiLine" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_EDITSETTING_WIKILINE ) );
172cdf0e10cSrcweir             GetPropSet( "SaveBox" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_EDITSETTING_SAVEBOX ) );
173cdf0e10cSrcweir             GetPropSet( "OkButton" ).setPropertyValue( "Label", Helper.GetLocalizedString( xContext, Helper.DLG_OK ) );
174cdf0e10cSrcweir         }
175cdf0e10cSrcweir         catch( Exception e )
176cdf0e10cSrcweir         {
177cdf0e10cSrcweir             e.printStackTrace();
178cdf0e10cSrcweir         }
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir 
InitSaveCheckbox( XComponentContext xContext, boolean bInitSaveCheckBox )181cdf0e10cSrcweir     private void InitSaveCheckbox( XComponentContext xContext, boolean bInitSaveCheckBox )
182cdf0e10cSrcweir     {
183cdf0e10cSrcweir         XPropertySet xSaveCheck = GetPropSet( "SaveBox" );
184cdf0e10cSrcweir         try
185cdf0e10cSrcweir         {
186cdf0e10cSrcweir             xSaveCheck.setPropertyValue( "State", new Short( bInitSaveCheckBox ? (short)1 : (short)0 ) );
187cdf0e10cSrcweir             xSaveCheck.setPropertyValue( "Enabled", new Boolean( Helper.PasswordStoringIsAllowed( xContext ) ) );
188cdf0e10cSrcweir         }
189cdf0e10cSrcweir         catch( Exception e )
190cdf0e10cSrcweir         {
191cdf0e10cSrcweir             e.printStackTrace();
192*c2e1856cSmseidel         }
193cdf0e10cSrcweir     }
194*c2e1856cSmseidel 
DoLogin( XDialog xDialog )195cdf0e10cSrcweir     public void DoLogin( XDialog xDialog )
196cdf0e10cSrcweir     {
197cdf0e10cSrcweir         String sRedirectURL = "";
198cdf0e10cSrcweir         String sURL = "";
199cdf0e10cSrcweir         try
200cdf0e10cSrcweir         {
201cdf0e10cSrcweir             sURL = ( String ) GetPropSet( "UrlField" ).getPropertyValue( "Text" );
202cdf0e10cSrcweir             String sUserName = ( String ) GetPropSet( "UsernameField" ).getPropertyValue( "Text" );
203cdf0e10cSrcweir             String sPassword = ( String ) GetPropSet( "PasswordField" ).getPropertyValue( "Text" );
204cdf0e10cSrcweir 
205cdf0e10cSrcweir             HostConfiguration aHostConfig = new HostConfiguration();
206cdf0e10cSrcweir             boolean bInitHost = true;
207cdf0e10cSrcweir             boolean bAllowIndex = true;
208cdf0e10cSrcweir 
209cdf0e10cSrcweir             do
210cdf0e10cSrcweir             {
211cdf0e10cSrcweir                 if ( sRedirectURL.length() > 0 )
212cdf0e10cSrcweir                 {
213cdf0e10cSrcweir                     sURL = sRedirectURL;
214cdf0e10cSrcweir                     sRedirectURL = "";
215cdf0e10cSrcweir                 }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir                 if ( sURL.length() > 0 )
218cdf0e10cSrcweir                 {
219cdf0e10cSrcweir                     URI aURI = new URI( sURL );
220cdf0e10cSrcweir                     GetMethod aRequest = new GetMethod( aURI.getEscapedPathQuery() );
221cdf0e10cSrcweir                     aRequest.setFollowRedirects( false );
222cdf0e10cSrcweir                     Helper.ExecuteMethod( aRequest, aHostConfig, aURI, m_xContext, bInitHost );
223cdf0e10cSrcweir                     bInitHost = false;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir                     int nResultCode = aRequest.getStatusCode();
226cdf0e10cSrcweir                     String sWebPage = null;
227cdf0e10cSrcweir                     if ( nResultCode == 200 )
228cdf0e10cSrcweir                         sWebPage = aRequest.getResponseBodyAsString();
229cdf0e10cSrcweir                     else if ( nResultCode >= 301 && nResultCode <= 303 || nResultCode == 307 )
230cdf0e10cSrcweir                         sRedirectURL = aRequest.getResponseHeader( "Location" ).getValue();
231cdf0e10cSrcweir 
232cdf0e10cSrcweir                     aRequest.releaseConnection();
233*c2e1856cSmseidel 
234cdf0e10cSrcweir                     if ( sWebPage != null && sWebPage.length() > 0 )
235cdf0e10cSrcweir                     {
236cdf0e10cSrcweir                         //the URL is valid
237cdf0e10cSrcweir                         String sMainURL = Helper.GetMainURL( sWebPage, sURL );
238*c2e1856cSmseidel 
239cdf0e10cSrcweir                         if ( sMainURL.equals( "" ) )
240cdf0e10cSrcweir                         {
241cdf0e10cSrcweir                             // TODO:
242cdf0e10cSrcweir                             // it's not a Wiki Page, check first whether a redirect is requested
243cdf0e10cSrcweir                             // happens usually in case of https
244cdf0e10cSrcweir                             sRedirectURL = Helper.GetRedirectURL( sWebPage, sURL );
245cdf0e10cSrcweir                             if ( sRedirectURL.equals( "" ) )
246cdf0e10cSrcweir                             {
247cdf0e10cSrcweir                                 // show error
248cdf0e10cSrcweir                                 Helper.ShowError( m_xContext,
249cdf0e10cSrcweir                                                   m_xDialog,
250cdf0e10cSrcweir                                                   Helper.DLG_MEDIAWIKI_TITLE,
251cdf0e10cSrcweir                                                   Helper.NOURLCONNECTION_ERROR,
252cdf0e10cSrcweir                                                   sURL,
253cdf0e10cSrcweir                                                   false );
254cdf0e10cSrcweir                             }
255cdf0e10cSrcweir                         }
256cdf0e10cSrcweir                         else
257cdf0e10cSrcweir                         {
258cdf0e10cSrcweir                             URI aMainURI = new URI( sMainURL, true ); // it must be an escaped URL, otherwise an exception should be thrown
259cdf0e10cSrcweir 
260cdf0e10cSrcweir                             if ( ( sUserName.length() > 0 || sPassword.length() > 0 )
261cdf0e10cSrcweir                               && Helper.Login( aMainURI, sUserName, sPassword, m_xContext ) == null )
262cdf0e10cSrcweir                             {
263cdf0e10cSrcweir                                 // a wrong login information is provided
264cdf0e10cSrcweir                                 // show error
265cdf0e10cSrcweir                                 Helper.ShowError( m_xContext,
266cdf0e10cSrcweir                                                   m_xDialog,
267cdf0e10cSrcweir                                                   Helper.DLG_MEDIAWIKI_TITLE,
268cdf0e10cSrcweir                                                   Helper.WRONGLOGIN_ERROR,
269cdf0e10cSrcweir                                                   null,
270cdf0e10cSrcweir                                                   false );
271cdf0e10cSrcweir                             }
272cdf0e10cSrcweir                             else
273cdf0e10cSrcweir                             {
274cdf0e10cSrcweir                                 setting.put( "Url", aMainURI.getEscapedURI() );
275cdf0e10cSrcweir                                 setting.put( "Username", sUserName );
276cdf0e10cSrcweir                                 setting.put( "Password", sPassword );
277cdf0e10cSrcweir                                 if ( addMode )
278cdf0e10cSrcweir                                 {
279cdf0e10cSrcweir                                     // no cleaning of the settings is necessary
280cdf0e10cSrcweir                                     Settings.getSettings( m_xContext ).addWikiCon( setting );
281cdf0e10cSrcweir                                     Settings.getSettings( m_xContext ).storeConfiguration();
282cdf0e10cSrcweir                                 }
283*c2e1856cSmseidel 
284cdf0e10cSrcweir                                 m_bAction = true;
285cdf0e10cSrcweir                             }
286cdf0e10cSrcweir                         }
287cdf0e10cSrcweir                     }
288cdf0e10cSrcweir                     else if ( sRedirectURL == null || sRedirectURL.length() == 0 )
289cdf0e10cSrcweir                     {
290cdf0e10cSrcweir                         if ( sURL.length() > 0 && !sURL.endsWith( "index.php" ) && bAllowIndex )
291cdf0e10cSrcweir                         {
292*c2e1856cSmseidel                             // the used MainURL is not always directly accessible
293cdf0e10cSrcweir                             // add the suffix as workaround, but only once
294cdf0e10cSrcweir                             sRedirectURL = sURL + "/index.php";
295cdf0e10cSrcweir                             bAllowIndex = false;
296cdf0e10cSrcweir                         }
297cdf0e10cSrcweir                         else
298cdf0e10cSrcweir                         {
299cdf0e10cSrcweir                             // URL invalid
300cdf0e10cSrcweir                             // show error
301cdf0e10cSrcweir                             Helper.ShowError( m_xContext,
302cdf0e10cSrcweir                                               m_xDialog,
303cdf0e10cSrcweir                                               Helper.DLG_MEDIAWIKI_TITLE,
304cdf0e10cSrcweir                                               Helper.INVALIDURL_ERROR,
305cdf0e10cSrcweir                                               null,
306cdf0e10cSrcweir                                               false );
307cdf0e10cSrcweir                         }
308cdf0e10cSrcweir                     }
309cdf0e10cSrcweir                 }
310cdf0e10cSrcweir                 else
311cdf0e10cSrcweir                 {
312cdf0e10cSrcweir                     // URL field empty
313cdf0e10cSrcweir                     // show error
314cdf0e10cSrcweir                     Helper.ShowError( m_xContext,
315cdf0e10cSrcweir                                       m_xDialog,
316cdf0e10cSrcweir                                       Helper.DLG_MEDIAWIKI_TITLE,
317cdf0e10cSrcweir                                       Helper.NOURL_ERROR,
318cdf0e10cSrcweir                                       null,
319cdf0e10cSrcweir                                       false );
320cdf0e10cSrcweir                 }
321cdf0e10cSrcweir             } while ( sRedirectURL.length() > 0 );
322cdf0e10cSrcweir         }
323cdf0e10cSrcweir         catch ( WikiCancelException ce )
324cdf0e10cSrcweir         {
325cdf0e10cSrcweir         }
326cdf0e10cSrcweir         catch ( SSLException essl )
327cdf0e10cSrcweir         {
328cdf0e10cSrcweir             if ( Helper.IsConnectionAllowed() )
329cdf0e10cSrcweir             {
330cdf0e10cSrcweir                 Helper.ShowError( m_xContext,
331cdf0e10cSrcweir                                   m_xDialog,
332cdf0e10cSrcweir                                   Helper.DLG_MEDIAWIKI_TITLE,
333cdf0e10cSrcweir                                   Helper.UNKNOWNCERT_ERROR,
334cdf0e10cSrcweir                                   null,
335cdf0e10cSrcweir                                   false );
336cdf0e10cSrcweir             }
337cdf0e10cSrcweir             essl.printStackTrace();
338cdf0e10cSrcweir         }
339*c2e1856cSmseidel         catch ( Exception ex )
340cdf0e10cSrcweir         {
341cdf0e10cSrcweir             if ( Helper.IsConnectionAllowed() )
342cdf0e10cSrcweir             {
343cdf0e10cSrcweir                 Helper.ShowError( m_xContext,
344cdf0e10cSrcweir                                   m_xDialog,
345cdf0e10cSrcweir                                   Helper.DLG_MEDIAWIKI_TITLE,
346cdf0e10cSrcweir                                   Helper.NOURLCONNECTION_ERROR,
347cdf0e10cSrcweir                                   sURL,
348cdf0e10cSrcweir                                   false );
349cdf0e10cSrcweir             }
350cdf0e10cSrcweir             ex.printStackTrace();
351*c2e1856cSmseidel         }
352cdf0e10cSrcweir     }
353*c2e1856cSmseidel 
callHandlerMethod( XDialog xDialog, Object EventObject, String MethodName )354cdf0e10cSrcweir     public boolean callHandlerMethod( XDialog xDialog, Object EventObject, String MethodName )
355cdf0e10cSrcweir     {
356cdf0e10cSrcweir         if ( MethodName.equals( sOKMethod ) )
357cdf0e10cSrcweir         {
358cdf0e10cSrcweir             EnableControls( false );
359cdf0e10cSrcweir             SetThrobberVisible( true );
360cdf0e10cSrcweir             SetThrobberActive( true );
361cdf0e10cSrcweir 
362cdf0e10cSrcweir             if ( Helper.AllowThreadUsage( m_xContext ) )
363cdf0e10cSrcweir             {
364cdf0e10cSrcweir                 final XDialog xDialogForThread = xDialog;
365cdf0e10cSrcweir                 final XComponentContext xContext = m_xContext;
366cdf0e10cSrcweir                 final WikiEditSettingDialog aThis = this;
367*c2e1856cSmseidel 
368cdf0e10cSrcweir                 // the thread name is used to allow the error dialogs
369cdf0e10cSrcweir                 m_bThreadFinished = false;
370cdf0e10cSrcweir                 m_aThread = new Thread( "com.sun.star.thread.WikiEditorSendingThread" )
371cdf0e10cSrcweir                 {
372cdf0e10cSrcweir                     public void run()
373cdf0e10cSrcweir                     {
374cdf0e10cSrcweir                         try
375cdf0e10cSrcweir                         {
376cdf0e10cSrcweir                             Thread.yield();
377cdf0e10cSrcweir                         } catch( java.lang.Exception e ){}
378cdf0e10cSrcweir 
379cdf0e10cSrcweir                         DoLogin( xDialogForThread );
380cdf0e10cSrcweir                         aThis.EnableControls( true );
381cdf0e10cSrcweir                         aThis.SetThrobberActive( false );
382cdf0e10cSrcweir                         aThis.SetThrobberVisible( false );
383cdf0e10cSrcweir 
384cdf0e10cSrcweir                         ThreadStop( true );
385*c2e1856cSmseidel 
386cdf0e10cSrcweir                         if ( m_bAction )
387cdf0e10cSrcweir                             MainThreadDialogExecutor.Close( xContext, xDialogForThread );
388cdf0e10cSrcweir                     }
389cdf0e10cSrcweir                 };
390cdf0e10cSrcweir 
391cdf0e10cSrcweir                 m_aThread.start();
392cdf0e10cSrcweir             }
393cdf0e10cSrcweir             else
394cdf0e10cSrcweir             {
395cdf0e10cSrcweir                 try
396cdf0e10cSrcweir                 {
397cdf0e10cSrcweir                     DoLogin( xDialog );
398cdf0e10cSrcweir                 } catch( java.lang.Exception e )
399cdf0e10cSrcweir                 {}
400cdf0e10cSrcweir                 finally
401cdf0e10cSrcweir                 {
402cdf0e10cSrcweir                     EnableControls( true );
403cdf0e10cSrcweir                     SetThrobberActive( false );
404cdf0e10cSrcweir                     SetThrobberVisible( false );
405cdf0e10cSrcweir 
406cdf0e10cSrcweir                     if ( m_bAction )
407cdf0e10cSrcweir                         xDialog.endExecute();
408cdf0e10cSrcweir 
409cdf0e10cSrcweir                     Helper.AllowConnection( true );
410cdf0e10cSrcweir                 }
411cdf0e10cSrcweir             }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir             return true;
414cdf0e10cSrcweir         }
415cdf0e10cSrcweir 
416cdf0e10cSrcweir         return false;
417cdf0e10cSrcweir     }
418*c2e1856cSmseidel 
windowClosed( EventObject e )419cdf0e10cSrcweir     public void windowClosed( EventObject e )
420cdf0e10cSrcweir     {
421cdf0e10cSrcweir         ThreadStop( false );
422cdf0e10cSrcweir     }
423cdf0e10cSrcweir }
424cdf0e10cSrcweir 
425