xref: /trunk/main/swext/mediawiki/src/com/sun/star/wiki/WikiEditorImpl.java (revision 6fd2419af095b9e12baf06e33db2129edf4d719b)
113efc523SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
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
10cdf0e10cSrcweir  *
1113efc523SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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.PropertyValue;
29cdf0e10cSrcweir import com.sun.star.frame.DispatchDescriptor;
30cdf0e10cSrcweir import com.sun.star.frame.XComponentLoader;
31cdf0e10cSrcweir import com.sun.star.frame.XController;
32cdf0e10cSrcweir import com.sun.star.frame.XDesktop;
33cdf0e10cSrcweir import com.sun.star.frame.XDispatch;
34cdf0e10cSrcweir import com.sun.star.frame.XDispatchProvider;
35cdf0e10cSrcweir import com.sun.star.frame.XFrame;
36cdf0e10cSrcweir import com.sun.star.frame.XModel;
37cdf0e10cSrcweir import com.sun.star.frame.XStatusListener;
38cdf0e10cSrcweir import com.sun.star.frame.XStorable;
39cdf0e10cSrcweir import com.sun.star.io.XInputStream;
40cdf0e10cSrcweir import com.sun.star.lang.XComponent;
41cdf0e10cSrcweir import com.sun.star.lang.XInitialization;
42cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
43cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
44cdf0e10cSrcweir import com.sun.star.lib.uno.helper.Factory;
45cdf0e10cSrcweir import com.sun.star.lang.XSingleComponentFactory;
46cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey;
47cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase;
48cdf0e10cSrcweir import com.sun.star.util.XCloseBroadcaster;
49cdf0e10cSrcweir import com.sun.star.view.XSelectionSupplier;
50cdf0e10cSrcweir import java.io.File;
51cdf0e10cSrcweir import java.net.URI;
52cdf0e10cSrcweir import java.net.URISyntaxException;
53cdf0e10cSrcweir import java.util.HashMap;
54cdf0e10cSrcweir import java.util.Hashtable;
55cdf0e10cSrcweir import java.util.Iterator;
56cdf0e10cSrcweir import java.util.Map;
57cdf0e10cSrcweir import java.util.Set;
58cdf0e10cSrcweir import javax.net.ssl.SSLException;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir public final class WikiEditorImpl extends WeakBase
62cdf0e10cSrcweir    implements com.sun.star.lang.XServiceInfo, XDispatchProvider, XDispatch, XInitialization
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     private final XComponentContext m_xContext;
66cdf0e10cSrcweir     private static final String m_implementationName = WikiEditorImpl.class.getName();
67cdf0e10cSrcweir     private static final String[] m_serviceNames = {"com.sun.star.wiki.WikiEditor" };
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     // information needed for component registration
70cdf0e10cSrcweir     public static final String[] supportedServiceNames = {"com.sun.star.frame.ProtocolHandler"};
71cdf0e10cSrcweir     public static final Class implementationClass = WikiEditorImpl.class;
72cdf0e10cSrcweir     // protocol name that this protocol handler handles
73cdf0e10cSrcweir     public static final String protocolName = "vnd.com.sun.star.wiki:";
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     private Map m_statusListeners = new HashMap();
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     private XComponent xComp;
79cdf0e10cSrcweir     private String sTempUrl;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     private XFrame m_xFrame;
82cdf0e10cSrcweir     private XModel m_xModel;
83cdf0e10cSrcweir     private Settings m_aSettings;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     private String m_aFilterName;
86cdf0e10cSrcweir 
WikiEditorImpl( XComponentContext xContext )87cdf0e10cSrcweir     public WikiEditorImpl( XComponentContext xContext )
88cdf0e10cSrcweir     {
89cdf0e10cSrcweir         // Helper.trustAllSSL();
90cdf0e10cSrcweir         m_xContext = xContext;
91cdf0e10cSrcweir         m_aSettings = Settings.getSettings( m_xContext );
92cdf0e10cSrcweir     };
93cdf0e10cSrcweir 
__getComponentFactory( String sImplementationName )94cdf0e10cSrcweir     public static XSingleComponentFactory __getComponentFactory( String sImplementationName )
95cdf0e10cSrcweir     {
96cdf0e10cSrcweir         XSingleComponentFactory xFactory = null;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         if ( sImplementationName.equals( m_implementationName ) )
99cdf0e10cSrcweir             xFactory = Factory.createComponentFactory( WikiEditorImpl.class, m_serviceNames );
100cdf0e10cSrcweir         else if ( sImplementationName.equals( WikiOptionsEventHandlerImpl.m_sImplementationName ) )
101cdf0e10cSrcweir             xFactory = Factory.createComponentFactory( WikiOptionsEventHandlerImpl.class,
102cdf0e10cSrcweir                                                        WikiOptionsEventHandlerImpl.m_pServiceNames );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         return xFactory;
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir 
__writeRegistryServiceInfo( XRegistryKey xRegistryKey )107cdf0e10cSrcweir     public static boolean __writeRegistryServiceInfo( XRegistryKey xRegistryKey )
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         boolean bResult = Factory.writeRegistryServiceInfo( m_implementationName,
110cdf0e10cSrcweir                                                             m_serviceNames,
111cdf0e10cSrcweir                                                             xRegistryKey );
112cdf0e10cSrcweir         return ( bResult && Factory.writeRegistryServiceInfo( WikiOptionsEventHandlerImpl.m_sImplementationName,
113cdf0e10cSrcweir                                                               WikiOptionsEventHandlerImpl.m_pServiceNames,
114cdf0e10cSrcweir                                                               xRegistryKey ) );
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     // com.sun.star.lang.XServiceInfo:
getImplementationName()118cdf0e10cSrcweir     public String getImplementationName()
119cdf0e10cSrcweir     {
120cdf0e10cSrcweir          return m_implementationName;
121cdf0e10cSrcweir     }
122cdf0e10cSrcweir 
supportsService( String sService )123cdf0e10cSrcweir     public boolean supportsService( String sService )
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir         int len = m_serviceNames.length;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         for( int i=0; i < len; i++ )
128cdf0e10cSrcweir         {
129cdf0e10cSrcweir             if ( sService.equals( m_serviceNames[i] ))
130cdf0e10cSrcweir                 return true;
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir         return false;
133cdf0e10cSrcweir     }
134cdf0e10cSrcweir 
getSupportedServiceNames()135cdf0e10cSrcweir     public String[] getSupportedServiceNames()
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir         return m_serviceNames;
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     private XSelectionSupplier m_sel;
142cdf0e10cSrcweir     private XController m_ctrl;
143cdf0e10cSrcweir     private boolean m_bInitialized;
initialize( Object[] args )144cdf0e10cSrcweir     public synchronized void initialize( Object[] args ) throws com.sun.star.uno.Exception
145cdf0e10cSrcweir     {
146cdf0e10cSrcweir         if ( m_bInitialized )
147cdf0e10cSrcweir         {
148cdf0e10cSrcweir             //logger.log( Level.SEVERE, "Extension instance was initialized again" );
149cdf0e10cSrcweir         }
150cdf0e10cSrcweir         if ( args.length > 0 )
151cdf0e10cSrcweir         {
152cdf0e10cSrcweir             m_bInitialized = true;
153cdf0e10cSrcweir             m_xFrame = ( XFrame )UnoRuntime.queryInterface( XFrame.class, args[0] );
154cdf0e10cSrcweir             // become close listener
155cdf0e10cSrcweir             XCloseBroadcaster cb = ( XCloseBroadcaster )UnoRuntime.queryInterface(
156cdf0e10cSrcweir                 XCloseBroadcaster.class, m_xFrame );
157cdf0e10cSrcweir         }
158cdf0e10cSrcweir     }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 
dispatch( final com.sun.star.util.URL aURL, com.sun.star.beans.PropertyValue[] propertyValue )162cdf0e10cSrcweir     public void dispatch(
163cdf0e10cSrcweir         final com.sun.star.util.URL aURL,
164cdf0e10cSrcweir         com.sun.star.beans.PropertyValue[] propertyValue )
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         final com.sun.star.util.URL myURL = aURL;
167cdf0e10cSrcweir         //logger.log( Level.INFO, "received dispatch request for: "+aURL.Complete );
168cdf0e10cSrcweir         if ( aURL.Protocol.compareTo( protocolName ) == 0 )
169cdf0e10cSrcweir         {
170cdf0e10cSrcweir             /*
171cdf0e10cSrcweir             synchronized( this )
172cdf0e10cSrcweir             {
173cdf0e10cSrcweir                 if( m_bClosing ) return;
174cdf0e10cSrcweir                 else m_bActive = true;
175cdf0e10cSrcweir             }
176cdf0e10cSrcweir              **/
177cdf0e10cSrcweir 
178cdf0e10cSrcweir             try
179cdf0e10cSrcweir             {
180cdf0e10cSrcweir                 if ( myURL.Path.compareTo( "send" ) == 0 )
181cdf0e10cSrcweir                 {
182cdf0e10cSrcweir                     sendArticle();
183cdf0e10cSrcweir                 }
184cdf0e10cSrcweir             } catch( java.lang.Throwable t )
185cdf0e10cSrcweir             {
186*86b5339aSmseidel                 //logger.log( Level.WARNING, "exception while handling dispatch", t );
187cdf0e10cSrcweir             }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir             /*
190cdf0e10cSrcweir             synchronized( this )
191cdf0e10cSrcweir             {
192cdf0e10cSrcweir                 m_bActive = false;
193cdf0e10cSrcweir                 // if we became owner while we were active
194cdf0e10cSrcweir                 // we are responsible for closing the m_xFrame now
195cdf0e10cSrcweir                 if ( m_bOwner && m_xFrame != null )
196cdf0e10cSrcweir                 {
197cdf0e10cSrcweir                     try
198cdf0e10cSrcweir                     {
199cdf0e10cSrcweir                         XCloseable xclose = ( XCloseable )UnoRuntime.queryInterface(
200cdf0e10cSrcweir                             XCloseable.class, m_xFrame );
201cdf0e10cSrcweir                         xclose.close( true );
202cdf0e10cSrcweir                     } catch ( CloseVetoException cve )
203cdf0e10cSrcweir                     {
204cdf0e10cSrcweir                         logger.log( Level.SEVERE, "cannot close owned frame" );
205cdf0e10cSrcweir                     }
206cdf0e10cSrcweir                     // relase reference to the m_xFrame;
207cdf0e10cSrcweir                     m_xFrame = null;
208cdf0e10cSrcweir                 }
209cdf0e10cSrcweir             }
210cdf0e10cSrcweir              */
211cdf0e10cSrcweir         }
212cdf0e10cSrcweir     }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 
queryDispatch( com.sun.star.util.URL aURL, String str, int param )215cdf0e10cSrcweir     public com.sun.star.frame.XDispatch queryDispatch(
216cdf0e10cSrcweir         com.sun.star.util.URL aURL,
217cdf0e10cSrcweir         String str,
218cdf0e10cSrcweir         int param )
219cdf0e10cSrcweir     {
220cdf0e10cSrcweir             if ( aURL.Protocol.equals( protocolName ))
221cdf0e10cSrcweir             {
222cdf0e10cSrcweir 
223cdf0e10cSrcweir                 // by default, we are responsible
224cdf0e10cSrcweir                 return this;
225cdf0e10cSrcweir             } else
226cdf0e10cSrcweir             {
227cdf0e10cSrcweir                 return null;
228cdf0e10cSrcweir             }
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir 
queryDispatches( DispatchDescriptor[] seqDescripts )231cdf0e10cSrcweir     public XDispatch[] queryDispatches( DispatchDescriptor[] seqDescripts )
232cdf0e10cSrcweir     {
233cdf0e10cSrcweir         int nCount = seqDescripts.length;
234cdf0e10cSrcweir         XDispatch[] lDispatcher = new XDispatch[nCount];
235cdf0e10cSrcweir 
236cdf0e10cSrcweir         for( int i=0; i<nCount; ++i )
237cdf0e10cSrcweir             lDispatcher[i] = queryDispatch(
238cdf0e10cSrcweir                 seqDescripts[i].FeatureURL,
239cdf0e10cSrcweir                 seqDescripts[i].FrameName,
240cdf0e10cSrcweir                 seqDescripts[i].SearchFlags );
241cdf0e10cSrcweir         return lDispatcher;
242cdf0e10cSrcweir    }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 
removeStatusListener( com.sun.star.frame.XStatusListener xStatusListener, com.sun.star.util.URL aURL )245cdf0e10cSrcweir     public void removeStatusListener(
246cdf0e10cSrcweir         com.sun.star.frame.XStatusListener xStatusListener,
247cdf0e10cSrcweir         com.sun.star.util.URL aURL )
248cdf0e10cSrcweir     {
249cdf0e10cSrcweir     }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 
addStatusListener( com.sun.star.frame.XStatusListener listener, com.sun.star.util.URL url )252cdf0e10cSrcweir     public void addStatusListener(
253cdf0e10cSrcweir         com.sun.star.frame.XStatusListener listener,
254cdf0e10cSrcweir         com.sun.star.util.URL url )
255cdf0e10cSrcweir     {
256cdf0e10cSrcweir         String urlstring = url.Complete;
257cdf0e10cSrcweir         m_statusListeners.put( urlstring, listener );
258*86b5339aSmseidel         // synchronous callback required!
259cdf0e10cSrcweir         callStatusListener( urlstring, listener );
260cdf0e10cSrcweir     }
261cdf0e10cSrcweir 
callStatusListeners()262cdf0e10cSrcweir     public void callStatusListeners()
263cdf0e10cSrcweir     {
264cdf0e10cSrcweir         Set entries = m_statusListeners.entrySet();
265cdf0e10cSrcweir         Iterator iter = entries.iterator();
266cdf0e10cSrcweir         while ( iter.hasNext() )
267cdf0e10cSrcweir         {
268cdf0e10cSrcweir             Map.Entry entry = ( Map.Entry ) iter.next();
269cdf0e10cSrcweir             String uristring = ( String ) entry.getKey();
270cdf0e10cSrcweir             XStatusListener listener = ( XStatusListener ) entry.getValue();
271cdf0e10cSrcweir             callStatusListener( uristring, listener );
272cdf0e10cSrcweir         }
273cdf0e10cSrcweir     }
274cdf0e10cSrcweir 
callStatusListener( String uristring, XStatusListener listener )275cdf0e10cSrcweir     public void callStatusListener( String uristring, XStatusListener listener )
276cdf0e10cSrcweir     {
277cdf0e10cSrcweir         try
278cdf0e10cSrcweir         {
279cdf0e10cSrcweir 
280cdf0e10cSrcweir             URI uri = new URI( uristring );
281cdf0e10cSrcweir 
282cdf0e10cSrcweir             // check whether any blogs are live...
283cdf0e10cSrcweir             setListenerState( listener, "command", false );
284cdf0e10cSrcweir         } catch ( URISyntaxException ex )
285cdf0e10cSrcweir         {
286cdf0e10cSrcweir             ex.printStackTrace();
287cdf0e10cSrcweir         }
288cdf0e10cSrcweir     }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 
setListenerState( XStatusListener listener, String urlstring, boolean state )291cdf0e10cSrcweir     private void setListenerState( XStatusListener listener, String urlstring, boolean state )
292cdf0e10cSrcweir     {
293cdf0e10cSrcweir         com.sun.star.util.URL url = new com.sun.star.util.URL();
294cdf0e10cSrcweir         url.Complete = urlstring;
295cdf0e10cSrcweir         //listener.statusChanged( new FeatureStateEvent( this, url, "", state, false, null ));
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     }
298cdf0e10cSrcweir 
sendArticle()299cdf0e10cSrcweir     public void sendArticle()
300cdf0e10cSrcweir     {
301cdf0e10cSrcweir         if ( m_xFrame != null )
302cdf0e10cSrcweir         {
303cdf0e10cSrcweir             WikiPropDialog aSendDialog = null;
304cdf0e10cSrcweir             try
305cdf0e10cSrcweir             {
306cdf0e10cSrcweir                 if ( m_xModel == null )
307cdf0e10cSrcweir                 {
308cdf0e10cSrcweir                     XController xController = m_xFrame.getController();
309cdf0e10cSrcweir                     if ( xController != null )
310cdf0e10cSrcweir                         m_xModel = xController.getModel();
311cdf0e10cSrcweir                 }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir                 if ( m_xModel != null )
314cdf0e10cSrcweir                 {
315cdf0e10cSrcweir                     // The related Wiki filter must be detected from the typename
316cdf0e10cSrcweir                     String aServiceName = Helper.GetDocServiceName( m_xContext, m_xModel );
317cdf0e10cSrcweir                     m_aFilterName = Helper.GetFilterName( m_xContext, "MediaWiki", aServiceName );
318cdf0e10cSrcweir 
319cdf0e10cSrcweir                     if ( m_aFilterName == null || m_aFilterName.length() == 0 )
320cdf0e10cSrcweir                     {
321cdf0e10cSrcweir                         Helper.ShowError( m_xContext,
322cdf0e10cSrcweir                                           (XWindowPeer)UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow() ),
323cdf0e10cSrcweir                                           Helper.DLG_SENDTITLE,
324cdf0e10cSrcweir                                           Helper.NOWIKIFILTER_ERROR,
325cdf0e10cSrcweir                                           null,
326cdf0e10cSrcweir                                           false );
327cdf0e10cSrcweir                         throw new com.sun.star.uno.RuntimeException();
328cdf0e10cSrcweir                     }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir                     m_aSettings.loadConfiguration(); // throw away all the noncommited changes
331cdf0e10cSrcweir                     // show the send dialog
332cdf0e10cSrcweir                     aSendDialog = new WikiPropDialog( m_xContext, "vnd.sun.star.script:WikiEditor.SendToMediaWiki?location=application", this );
333cdf0e10cSrcweir                     aSendDialog.fillWikiList();
334cdf0e10cSrcweir                     aSendDialog.SetWikiTitle( Helper.GetDocTitle( m_xModel ) );
335cdf0e10cSrcweir                     aSendDialog.show(); // triggers the sending
336cdf0e10cSrcweir                 }
337cdf0e10cSrcweir             }
338cdf0e10cSrcweir             catch ( Exception e )
339cdf0e10cSrcweir             {
340cdf0e10cSrcweir                 // TODO: Error handling here
341cdf0e10cSrcweir                 e.printStackTrace();
342cdf0e10cSrcweir             }
343cdf0e10cSrcweir             finally
344cdf0e10cSrcweir             {
345cdf0e10cSrcweir                 if ( aSendDialog != null )
346cdf0e10cSrcweir                     aSendDialog.DisposeDialog();
347cdf0e10cSrcweir             }
348cdf0e10cSrcweir         }
349cdf0e10cSrcweir     }
350cdf0e10cSrcweir 
SendArticleImpl( WikiPropDialog aSendDialog, Hashtable aWikiSetting )351cdf0e10cSrcweir     public boolean SendArticleImpl( WikiPropDialog aSendDialog, Hashtable aWikiSetting )
352cdf0e10cSrcweir     {
353cdf0e10cSrcweir         boolean bResult = false;
354cdf0e10cSrcweir 
355cdf0e10cSrcweir         if ( aSendDialog != null )
356cdf0e10cSrcweir         {
357cdf0e10cSrcweir             String sTemp2Url = null;
358cdf0e10cSrcweir 
359cdf0e10cSrcweir             try
360cdf0e10cSrcweir             {
361cdf0e10cSrcweir                 // TODO: stop progress spinning
362cdf0e10cSrcweir                 WikiArticle aArticle = new WikiArticle( m_xContext, aSendDialog.GetWikiTitle(), aWikiSetting, true, aSendDialog );
363cdf0e10cSrcweir 
364cdf0e10cSrcweir                 boolean bAllowSending = true;
365cdf0e10cSrcweir                 if ( !aArticle.NotExist() )
366cdf0e10cSrcweir                 {
367cdf0e10cSrcweir                     // ask whether creation of a new page is allowed
368cdf0e10cSrcweir                     aSendDialog.SetThrobberActive( false );
369cdf0e10cSrcweir                     bAllowSending = Helper.ShowError(
370cdf0e10cSrcweir                                       m_xContext,
371cdf0e10cSrcweir                                       (XWindowPeer)UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow() ),
372cdf0e10cSrcweir                                       Helper.DLG_SENDTITLE,
373cdf0e10cSrcweir                                       Helper.DLG_WIKIPAGEEXISTS_LABEL1,
374cdf0e10cSrcweir                                       aSendDialog.GetWikiTitle(),
375cdf0e10cSrcweir                                       true );
376cdf0e10cSrcweir                     aSendDialog.SetThrobberActive( true );
377cdf0e10cSrcweir                 }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir                 if ( bAllowSending )
380cdf0e10cSrcweir                 {
381cdf0e10cSrcweir                     PropertyValue[] lProperties = new PropertyValue[2];
382cdf0e10cSrcweir                     lProperties[0]       = new PropertyValue();
383cdf0e10cSrcweir                     lProperties[0].Name  = "FilterName";
384cdf0e10cSrcweir                     lProperties[0].Value = m_aFilterName;
385cdf0e10cSrcweir                     lProperties[1]       = new PropertyValue();
386cdf0e10cSrcweir                     lProperties[1].Name  = "Overwrite";
387cdf0e10cSrcweir                     lProperties[1].Value = new Boolean( true );
388cdf0e10cSrcweir 
389cdf0e10cSrcweir                     sTemp2Url = Helper.CreateTempFile( m_xContext );
390cdf0e10cSrcweir 
391cdf0e10cSrcweir                     XStorable xStore = ( com.sun.star.frame.XStorable )UnoRuntime.queryInterface ( XStorable.class, m_xModel );
392cdf0e10cSrcweir                     if ( xStore == null )
393cdf0e10cSrcweir                         throw new com.sun.star.uno.RuntimeException();
394cdf0e10cSrcweir 
395cdf0e10cSrcweir                     xStore.storeToURL( sTemp2Url, lProperties );
396cdf0e10cSrcweir                     String sWikiCode = Helper.EachLine( sTemp2Url );
397cdf0e10cSrcweir 
398cdf0e10cSrcweir                     if ( aArticle.setArticle( sWikiCode, aSendDialog.m_sWikiComment, aSendDialog.m_bWikiMinorEdit ) )
399cdf0e10cSrcweir                     {
400cdf0e10cSrcweir                         bResult = true;
401cdf0e10cSrcweir                         Object desktop = m_xContext.getServiceManager().createInstanceWithContext( "com.sun.star.frame.Desktop", m_xContext );
402cdf0e10cSrcweir                         XDesktop xDesktop = ( XDesktop ) UnoRuntime.queryInterface( com.sun.star.frame.XDesktop.class, desktop );
403cdf0e10cSrcweir                         Helper.SetDocTitle( m_xModel, aArticle.GetTitle() );
404cdf0e10cSrcweir                         Hashtable aDocInfo = new Hashtable();
405cdf0e10cSrcweir                         aDocInfo.put( "Doc", aArticle.GetTitle() );
406cdf0e10cSrcweir                         aDocInfo.put( "Url", aArticle.GetMainURL() );
407cdf0e10cSrcweir                         aDocInfo.put( "CompleteUrl", aArticle.GetMainURL() + aArticle.GetTitle() );
408cdf0e10cSrcweir                         m_aSettings.addWikiDoc( aDocInfo );
409cdf0e10cSrcweir                         m_aSettings.storeConfiguration();
410cdf0e10cSrcweir                     }
411cdf0e10cSrcweir                     else
412cdf0e10cSrcweir                     {
413cdf0e10cSrcweir                         Helper.ShowError( m_xContext,
414cdf0e10cSrcweir                                           (XWindowPeer)UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow() ),
415cdf0e10cSrcweir                                           Helper.DLG_SENDTITLE,
416cdf0e10cSrcweir                                           Helper.GENERALSEND_ERROR,
417cdf0e10cSrcweir                                           null,
418cdf0e10cSrcweir                                           false );
419cdf0e10cSrcweir                     }
420cdf0e10cSrcweir                 }
421cdf0e10cSrcweir             }
422cdf0e10cSrcweir             catch( WikiCancelException ec )
423cdf0e10cSrcweir             {
424*86b5339aSmseidel                 // nothing to do, the sending was canceled
425cdf0e10cSrcweir             }
426cdf0e10cSrcweir             catch( SSLException essl )
427cdf0e10cSrcweir             {
428cdf0e10cSrcweir                 if ( Helper.IsConnectionAllowed() )
429cdf0e10cSrcweir                 {
430*86b5339aSmseidel                     // report the error only if sending was not canceled
431cdf0e10cSrcweir                     Helper.ShowError( m_xContext,
432cdf0e10cSrcweir                                       (XWindowPeer)UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow() ),
433cdf0e10cSrcweir                                       Helper.DLG_SENDTITLE,
434cdf0e10cSrcweir                                       Helper.UNKNOWNCERT_ERROR,
435cdf0e10cSrcweir                                       null,
436cdf0e10cSrcweir                                       false );
437cdf0e10cSrcweir                 }
438cdf0e10cSrcweir             }
439cdf0e10cSrcweir             catch( Exception e )
440cdf0e10cSrcweir             {
441cdf0e10cSrcweir                 if ( Helper.IsConnectionAllowed() )
442cdf0e10cSrcweir                 {
443*86b5339aSmseidel                     // report the error only if sending was not canceled
444cdf0e10cSrcweir                     Helper.ShowError( m_xContext,
445cdf0e10cSrcweir                                       (XWindowPeer)UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow() ),
446cdf0e10cSrcweir                                       Helper.DLG_SENDTITLE,
447cdf0e10cSrcweir                                       Helper.GENERALSEND_ERROR,
448cdf0e10cSrcweir                                       null,
449cdf0e10cSrcweir                                       false );
450cdf0e10cSrcweir                 }
451cdf0e10cSrcweir                 e.printStackTrace();
452cdf0e10cSrcweir             }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir             if ( sTemp2Url != null )
455cdf0e10cSrcweir             {
456cdf0e10cSrcweir                 try
457cdf0e10cSrcweir                 {
458cdf0e10cSrcweir                     // remove the temporary file
459cdf0e10cSrcweir                     File aFile = new File( new URI( sTemp2Url ) );
460cdf0e10cSrcweir                     aFile.delete();
461cdf0e10cSrcweir                 }
462cdf0e10cSrcweir                 catch ( java.lang.Exception e )
463cdf0e10cSrcweir                 {
464cdf0e10cSrcweir                     e.printStackTrace();
465cdf0e10cSrcweir                 }
466cdf0e10cSrcweir             }
467cdf0e10cSrcweir         }
468cdf0e10cSrcweir 
469cdf0e10cSrcweir         return bResult;
470cdf0e10cSrcweir     }
471cdf0e10cSrcweir }
472