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 1013efc523SAndrew Rist * 1113efc523SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1213efc523SAndrew Rist * 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. 1913efc523SAndrew Rist * 2013efc523SAndrew Rist *************************************************************/ 2113efc523SAndrew Rist 2213efc523SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package com.sun.star.wiki; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.awt.MessageBoxButtons; 2761161268SAriel Constenla-Haile import com.sun.star.awt.MessageBoxType; 28cdf0e10cSrcweir import com.sun.star.awt.XControl; 29cdf0e10cSrcweir import com.sun.star.awt.XControlContainer; 30cdf0e10cSrcweir import com.sun.star.awt.XDialog; 31cdf0e10cSrcweir import com.sun.star.awt.XMessageBox; 32cdf0e10cSrcweir import com.sun.star.awt.XMessageBoxFactory; 33cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer; 34cdf0e10cSrcweir import com.sun.star.beans.NamedValue; 35cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 36cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 37cdf0e10cSrcweir import com.sun.star.container.XContainerQuery; 38cdf0e10cSrcweir import com.sun.star.container.XEnumeration; 39cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 40cdf0e10cSrcweir import com.sun.star.container.XNameContainer; 41cdf0e10cSrcweir import com.sun.star.document.XDocumentInfoSupplier; 42cdf0e10cSrcweir import com.sun.star.frame.XModel; 43cdf0e10cSrcweir import com.sun.star.frame.XModuleManager; 44cdf0e10cSrcweir import com.sun.star.io.XInputStream; 45cdf0e10cSrcweir import com.sun.star.io.XOutputStream; 46cdf0e10cSrcweir import com.sun.star.io.XSeekable; 47cdf0e10cSrcweir import com.sun.star.io.XStream; 48cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 49cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 50cdf0e10cSrcweir import com.sun.star.lang.XComponent; 51cdf0e10cSrcweir import com.sun.star.system.SystemShellExecuteFlags; 52cdf0e10cSrcweir import com.sun.star.system.XSystemShellExecute; 53cdf0e10cSrcweir import com.sun.star.task.UrlRecord; 54cdf0e10cSrcweir import com.sun.star.task.XInteractionHandler; 55cdf0e10cSrcweir import com.sun.star.task.XMasterPasswordHandling; 56cdf0e10cSrcweir import com.sun.star.task.XPasswordContainer; 57cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 58cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 59cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 60cdf0e10cSrcweir import com.sun.star.util.XChangesBatch; 61cdf0e10cSrcweir import java.net.*; 62cdf0e10cSrcweir import java.io.*; 63cdf0e10cSrcweir import java.util.Hashtable; 64cdf0e10cSrcweir import java.util.Random; 65cdf0e10cSrcweir import javax.net.ssl.SSLException; 66cdf0e10cSrcweir import javax.swing.text.html.HTMLEditorKit; 67cdf0e10cSrcweir 68cdf0e10cSrcweir import org.apache.commons.httpclient.HttpClient; 69cdf0e10cSrcweir import org.apache.commons.httpclient.HostConfiguration; 70cdf0e10cSrcweir import org.apache.commons.httpclient.HttpMethodBase; 71cdf0e10cSrcweir import org.apache.commons.httpclient.cookie.CookiePolicy; 72cdf0e10cSrcweir import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; 73cdf0e10cSrcweir import org.apache.commons.httpclient.protocol.Protocol; 74cdf0e10cSrcweir import org.apache.commons.httpclient.URI; 75cdf0e10cSrcweir import org.apache.commons.httpclient.methods.GetMethod; 76cdf0e10cSrcweir import org.apache.commons.httpclient.methods.PostMethod; 77cdf0e10cSrcweir 78cdf0e10cSrcweir public class Helper 79cdf0e10cSrcweir { 80cdf0e10cSrcweir public final static int GENERALSEND_ERROR = 0; 81cdf0e10cSrcweir public final static int NOWIKIFILTER_ERROR = 1; 82cdf0e10cSrcweir public final static int NOURLCONNECTION_ERROR = 2; 83cdf0e10cSrcweir public final static int WRONGLOGIN_ERROR = 3; 84cdf0e10cSrcweir public final static int INVALIDURL_ERROR = 4; 85cdf0e10cSrcweir public final static int NOURL_ERROR = 5; 86cdf0e10cSrcweir 87cdf0e10cSrcweir public final static int DLG_SENDTITLE = 6; 88cdf0e10cSrcweir public final static int DLG_WIKIARTICLE = 7; 89cdf0e10cSrcweir public final static int DLG_NO = 8; 90cdf0e10cSrcweir public final static int DLG_OK = 9; 91cdf0e10cSrcweir public final static int DLG_YES = 10; 92cdf0e10cSrcweir // 11 is reserved 93cdf0e10cSrcweir public final static int DLG_ADDBUTTON = 12; 94cdf0e10cSrcweir public final static int DLG_EDITBUTTON = 13; 95cdf0e10cSrcweir public final static int DLG_SENDBUTTON = 14; 96cdf0e10cSrcweir public final static int DLG_REMOVEBUTTON = 15; 97cdf0e10cSrcweir 98cdf0e10cSrcweir public final static int DLG_EDITSETTING_URLLABEL = 16; 99cdf0e10cSrcweir public final static int DLG_EDITSETTING_USERNAMELABEL = 17; 100cdf0e10cSrcweir public final static int DLG_EDITSETTING_PASSWORDLABEL = 18; 101cdf0e10cSrcweir public final static int DLG_NEWWIKIPAGE_LABEL1 = 19; 102cdf0e10cSrcweir public final static int DLG_SENDTOMEDIAWIKI_LABEL1 = 20; 103cdf0e10cSrcweir public final static int DLG_SENDTOMEDIAWIKI_LABEL2 = 21; 104cdf0e10cSrcweir public final static int DLG_SENDTOMEDIAWIKI_LABEL3 = 22; 105cdf0e10cSrcweir public final static int DLG_SENDTOMEDIAWIKI_MINORCHECK = 23; 106cdf0e10cSrcweir public final static int DLG_SENDTOMEDIAWIKI_BROWSERCHECK = 24; 107cdf0e10cSrcweir public final static int UNKNOWNCERT_ERROR = 25; 108cdf0e10cSrcweir public final static int DLG_MEDIAWIKI_TITLE = 26; 109cdf0e10cSrcweir public final static int DLG_EDITSETTING_ACCOUNTLINE = 27; 110cdf0e10cSrcweir public final static int DLG_EDITSETTING_WIKILINE = 28; 111cdf0e10cSrcweir public final static int DLG_EDITSETTING_SAVEBOX = 29; 112cdf0e10cSrcweir public final static int CANCELSENDING_ERROR = 30; 113cdf0e10cSrcweir public final static int DLG_MEDIAWIKIEXTENSION_STRING = 31; 114cdf0e10cSrcweir public final static int DLG_WIKIPAGEEXISTS_LABEL1 = 32; 115cdf0e10cSrcweir 116cdf0e10cSrcweir public final static int STRINGS_NUM = 33; 117cdf0e10cSrcweir 118cdf0e10cSrcweir private final static String[] m_pEntryNames = { "GeneralSendError", 119cdf0e10cSrcweir "NoWikiFilter", 120cdf0e10cSrcweir "NoConnectionToURL", 121cdf0e10cSrcweir "WrongLogin", 122cdf0e10cSrcweir "InvalidURL", 123cdf0e10cSrcweir "NoURL", 124cdf0e10cSrcweir "Dlg_SendTitle", 125cdf0e10cSrcweir "Dlg_WikiArticle", 126cdf0e10cSrcweir "Dlg_No", 127cdf0e10cSrcweir "Dlg_OK", 128cdf0e10cSrcweir "Dlg_Yes", 129cdf0e10cSrcweir null, // reserved 130cdf0e10cSrcweir "Dlg_AddButton", 131cdf0e10cSrcweir "Dlg_EditButton", 132cdf0e10cSrcweir "Dlg_SendButton", 133cdf0e10cSrcweir "Dlg_RemoveButton", 134cdf0e10cSrcweir "Dlg_EditSetting_UrlLabel", 135cdf0e10cSrcweir "Dlg_EditSetting_UsernameLabel", 136cdf0e10cSrcweir "Dlg_EditSetting_PasswordLabel", 137cdf0e10cSrcweir "Dlg_NewWikiPage_Label1", 138cdf0e10cSrcweir "Dlg_SendToMediaWiki_Label1", 139cdf0e10cSrcweir "Dlg_SendToMediaWiki_Label2", 140cdf0e10cSrcweir "Dlg_SendToMediaWiki_Label3", 141cdf0e10cSrcweir "Dlg_SendToMediaWiki_MinorCheck", 142cdf0e10cSrcweir "Dlg_SendToMediaWiki_BrowserCheck", 143cdf0e10cSrcweir "UnknownCert", 144cdf0e10cSrcweir "Dlg_MediaWiki_Title", 145cdf0e10cSrcweir "Dlg_EditSetting_AccountLine", 146cdf0e10cSrcweir "Dlg_EditSetting_WikiLine", 147cdf0e10cSrcweir "Dlg_EditSetting_SaveBox", 148cdf0e10cSrcweir "CancelSending", 149cdf0e10cSrcweir "Dlg_MediaWiki_Extension_String", 150cdf0e10cSrcweir "Dlg_WikiPageExists_Label1" }; 151cdf0e10cSrcweir 152cdf0e10cSrcweir private static String[] m_pConfigStrings; 153cdf0e10cSrcweir 154cdf0e10cSrcweir private static final String sHTMLHeader = "<HTML><HEAD><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><TITLE></TITLE></HEAD><BODY>"; 155cdf0e10cSrcweir private static final String sHTMLFooter = "</BODY></HTML>"; 156cdf0e10cSrcweir 157cdf0e10cSrcweir private static Random m_aRandom; 158cdf0e10cSrcweir private static MultiThreadedHttpConnectionManager m_aConnectionManager; 159cdf0e10cSrcweir private static HttpClient m_aClient; 160cdf0e10cSrcweir private static boolean m_bAllowConnection = true; 161cdf0e10cSrcweir private static Hashtable m_aAcceptedUnknownCerts; 162cdf0e10cSrcweir 163cdf0e10cSrcweir private static Boolean m_bShowInBrowser = null; 164cdf0e10cSrcweir 165cdf0e10cSrcweir private static XPasswordContainer m_xPasswordContainer; 166cdf0e10cSrcweir private static XInteractionHandler m_xInteractionHandler; 167cdf0e10cSrcweir GetLocalizedString( XComponentContext xContext, int nID )168cdf0e10cSrcweir synchronized protected static String GetLocalizedString( XComponentContext xContext, int nID ) 169cdf0e10cSrcweir throws com.sun.star.uno.Exception 170cdf0e10cSrcweir { 171cdf0e10cSrcweir if ( nID >= STRINGS_NUM ) 172cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException(); 173cdf0e10cSrcweir 174cdf0e10cSrcweir if ( m_pConfigStrings == null ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir XNameAccess xNameAccess = GetConfigNameAccess( xContext, "org.openoffice.Office.Custom.WikiExtension/Strings" ); 177cdf0e10cSrcweir 178cdf0e10cSrcweir String[] pStrings = new String[STRINGS_NUM]; 179cdf0e10cSrcweir for ( int nInd = 0; nInd < STRINGS_NUM; nInd++ ) 180cdf0e10cSrcweir if ( m_pEntryNames[nInd] != null ) 181cdf0e10cSrcweir pStrings[nInd] = AnyConverter.toString( xNameAccess.getByName( m_pEntryNames[nInd] ) ); 182cdf0e10cSrcweir else 183cdf0e10cSrcweir pStrings[nInd] = ""; 184cdf0e10cSrcweir 185cdf0e10cSrcweir m_pConfigStrings = pStrings; 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir return m_pConfigStrings[nID]; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir GetHttpClient()191cdf0e10cSrcweir synchronized protected static HttpClient GetHttpClient() 192cdf0e10cSrcweir throws WikiCancelException 193cdf0e10cSrcweir { 194cdf0e10cSrcweir if ( !m_bAllowConnection ) 195cdf0e10cSrcweir throw new WikiCancelException(); 196cdf0e10cSrcweir 197cdf0e10cSrcweir if ( m_aConnectionManager == null ) 198cdf0e10cSrcweir m_aConnectionManager = new MultiThreadedHttpConnectionManager(); 199cdf0e10cSrcweir 200cdf0e10cSrcweir if ( m_aClient == null ) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir m_aClient = new HttpClient( m_aConnectionManager ); 203cdf0e10cSrcweir m_aClient.getParams().setParameter( "http.protocol.cookie-policy", CookiePolicy.BROWSER_COMPATIBILITY ); 204cdf0e10cSrcweir m_aClient.getParams().setParameter( "http.protocol.single-cookie-header", Boolean.TRUE ); 205cdf0e10cSrcweir m_aClient.getParams().setParameter( "http.protocol.content-charset", "UTF-8" ); 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir return m_aClient; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir AllowConnection( boolean bAllow )211cdf0e10cSrcweir synchronized protected static void AllowConnection( boolean bAllow ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir m_bAllowConnection = bAllow; 214cdf0e10cSrcweir if ( !bAllow && m_aConnectionManager != null ) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir m_aClient = null; 217cdf0e10cSrcweir m_aConnectionManager.shutdown(); 218cdf0e10cSrcweir m_aConnectionManager = null; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir } 221cdf0e10cSrcweir IsConnectionAllowed()222cdf0e10cSrcweir synchronized protected static boolean IsConnectionAllowed() 223cdf0e10cSrcweir { 224cdf0e10cSrcweir return m_bAllowConnection; 225cdf0e10cSrcweir } 226cdf0e10cSrcweir GetShowInBrowserByDefault( XComponentContext xContext )227cdf0e10cSrcweir synchronized protected static boolean GetShowInBrowserByDefault( XComponentContext xContext ) 228cdf0e10cSrcweir { 229cdf0e10cSrcweir if ( m_bShowInBrowser == null ) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir try 232cdf0e10cSrcweir { 233cdf0e10cSrcweir XNameAccess xAccess = Helper.GetConfigNameAccess( xContext, "org.openoffice.Office.Custom.WikiExtension/Settings" ); 234cdf0e10cSrcweir m_bShowInBrowser = new Boolean( AnyConverter.toBoolean( xAccess.getByName( "PreselectShowBrowser" ) ) ); 235cdf0e10cSrcweir } 236cdf0e10cSrcweir catch( com.sun.star.uno.Exception e ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir e.printStackTrace(); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir return m_bShowInBrowser.booleanValue(); 243cdf0e10cSrcweir } 244cdf0e10cSrcweir SetShowInBrowserByDefault( XComponentContext xContext, boolean bValue )245cdf0e10cSrcweir synchronized protected static void SetShowInBrowserByDefault( XComponentContext xContext, boolean bValue ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir try 248cdf0e10cSrcweir { 249cdf0e10cSrcweir m_bShowInBrowser = new Boolean( bValue ); 250cdf0e10cSrcweir 251cdf0e10cSrcweir XPropertySet xProps = Helper.GetConfigProps( xContext, "org.openoffice.Office.Custom.WikiExtension/Settings" ); 252cdf0e10cSrcweir xProps.setPropertyValue( "PreselectShowBrowser", new Boolean( bValue ) ); 253cdf0e10cSrcweir XChangesBatch xBatch = ( XChangesBatch ) UnoRuntime.queryInterface( XChangesBatch.class, xProps ); 254cdf0e10cSrcweir if ( xBatch != null ) 255cdf0e10cSrcweir xBatch.commitChanges(); 256cdf0e10cSrcweir } 257cdf0e10cSrcweir catch( Exception e ) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir e.printStackTrace(); 260cdf0e10cSrcweir } 261cdf0e10cSrcweir } 262cdf0e10cSrcweir GetPasswordContainer( XComponentContext xContext )263cdf0e10cSrcweir synchronized protected static XPasswordContainer GetPasswordContainer( XComponentContext xContext ) 264cdf0e10cSrcweir throws com.sun.star.uno.Exception 265cdf0e10cSrcweir { 266cdf0e10cSrcweir if ( m_xPasswordContainer == null && xContext != null ) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir XMultiComponentFactory xFactory = xContext.getServiceManager(); 269cdf0e10cSrcweir if ( xFactory != null ) 270cdf0e10cSrcweir m_xPasswordContainer = (XPasswordContainer)UnoRuntime.queryInterface( 271cdf0e10cSrcweir XPasswordContainer.class, 272cdf0e10cSrcweir xFactory.createInstanceWithContext( "com.sun.star.task.PasswordContainer", xContext ) ); 273cdf0e10cSrcweir } 274cdf0e10cSrcweir 275cdf0e10cSrcweir if ( m_xPasswordContainer == null ) 276cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException(); 277cdf0e10cSrcweir 278cdf0e10cSrcweir return m_xPasswordContainer; 279cdf0e10cSrcweir } 280cdf0e10cSrcweir GetInteractionHandler( XComponentContext xContext )281cdf0e10cSrcweir synchronized protected static XInteractionHandler GetInteractionHandler( XComponentContext xContext ) 282cdf0e10cSrcweir throws com.sun.star.uno.Exception 283cdf0e10cSrcweir { 284cdf0e10cSrcweir if ( m_xInteractionHandler == null && xContext != null ) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir XMultiComponentFactory xFactory = xContext.getServiceManager(); 287cdf0e10cSrcweir if ( xFactory != null ) 288cdf0e10cSrcweir m_xInteractionHandler = ( XInteractionHandler )UnoRuntime.queryInterface( 289cdf0e10cSrcweir XInteractionHandler.class, 290cdf0e10cSrcweir xFactory.createInstanceWithContext( "com.sun.star.task.InteractionHandler", xContext ) ); 291cdf0e10cSrcweir } 292cdf0e10cSrcweir 293cdf0e10cSrcweir if ( m_xInteractionHandler == null ) 294cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException(); 295cdf0e10cSrcweir 296cdf0e10cSrcweir return m_xInteractionHandler; 297cdf0e10cSrcweir } 298cdf0e10cSrcweir GetOwnHttps( int nPort )299cdf0e10cSrcweir protected static Protocol GetOwnHttps( int nPort ) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir return new Protocol( "https", new WikiProtocolSocketFactory(), ( ( nPort < 0 ) ? 443 : nPort ) ); 302cdf0e10cSrcweir } 303cdf0e10cSrcweir GetMainURL( String sWebPage, String sVURL )304cdf0e10cSrcweir protected static String GetMainURL( String sWebPage, String sVURL ) 305cdf0e10cSrcweir { 306cdf0e10cSrcweir String sResultURL = ""; 307cdf0e10cSrcweir try 308cdf0e10cSrcweir { 309cdf0e10cSrcweir StringReader aReader = new StringReader( sWebPage ); 310cdf0e10cSrcweir HTMLEditorKit.Parser aParser = GetHTMLParser(); 311cdf0e10cSrcweir EditPageParser aCallback = new EditPageParser(); 312cdf0e10cSrcweir 313cdf0e10cSrcweir aParser.parse( aReader, aCallback, true ); 314cdf0e10cSrcweir sResultURL = aCallback.m_sMainURL; 315cdf0e10cSrcweir 316cdf0e10cSrcweir if ( !sResultURL.startsWith( "http" ) ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir //if the url is only relative then complete it 319cdf0e10cSrcweir URL aURL = new URL( sVURL ); 320cdf0e10cSrcweir sResultURL = aURL.getProtocol() + "://" + aURL.getHost() + sResultURL; 321cdf0e10cSrcweir } 322cdf0e10cSrcweir } 323cdf0e10cSrcweir catch( Exception e ) 324cdf0e10cSrcweir { 325cdf0e10cSrcweir e.printStackTrace(); 326cdf0e10cSrcweir } 327cdf0e10cSrcweir 328cdf0e10cSrcweir if ( sResultURL.length() == 0 ) 329cdf0e10cSrcweir { 330cdf0e10cSrcweir // usually that should not happen 331cdf0e10cSrcweir // workaround: try to get index.php from the provided URL 332cdf0e10cSrcweir int nIndex = sVURL.indexOf( "index.php" ); 333cdf0e10cSrcweir if ( nIndex >= 0 ) 334cdf0e10cSrcweir sResultURL = sVURL.substring( 0, nIndex ); 335cdf0e10cSrcweir } 336cdf0e10cSrcweir 337cdf0e10cSrcweir return sResultURL; 338cdf0e10cSrcweir } 339cdf0e10cSrcweir GetRedirectURL( String sWebPage, String sURL )340cdf0e10cSrcweir protected static String GetRedirectURL( String sWebPage, String sURL ) 341cdf0e10cSrcweir { 342cdf0e10cSrcweir //scrape the HTML source and find the EditURL 343cdf0e10cSrcweir // TODO/LATER: Use parser in future 344cdf0e10cSrcweir 345cdf0e10cSrcweir String sResultURL = ""; 346cdf0e10cSrcweir int nInd = sWebPage.indexOf( "http-equiv=\"refresh\"" ); 347cdf0e10cSrcweir if ( nInd != -1 ) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir int nContent = sWebPage.indexOf( "content=", nInd ); 350cdf0e10cSrcweir if ( nContent > 0 ) 351cdf0e10cSrcweir { 352cdf0e10cSrcweir int nURL = sWebPage.indexOf( "URL=", nContent ); 353cdf0e10cSrcweir if ( nURL > 0 ) 354cdf0e10cSrcweir { 355cdf0e10cSrcweir int nEndURL = sWebPage.indexOf( "\"", nURL ); 356cdf0e10cSrcweir if ( nEndURL > 0 ) 357cdf0e10cSrcweir sResultURL = sWebPage.substring( nURL + 4, nEndURL ); 358cdf0e10cSrcweir } 359cdf0e10cSrcweir } 360cdf0e10cSrcweir 361cdf0e10cSrcweir try 362cdf0e10cSrcweir { 363cdf0e10cSrcweir URL aURL = new URL( sURL ); 364cdf0e10cSrcweir if ( !sResultURL.startsWith( aURL.getProtocol() )) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir //if the url is only relative then complete it 367cdf0e10cSrcweir if ( sResultURL.startsWith( "/" ) ) 368cdf0e10cSrcweir sResultURL = aURL.getProtocol() + "://" + aURL.getHost() + sResultURL; 369cdf0e10cSrcweir else 370cdf0e10cSrcweir sResultURL = aURL.getProtocol() + "://" + aURL.getHost() + aURL.getPath() + sResultURL; 371cdf0e10cSrcweir } 372cdf0e10cSrcweir } 373cdf0e10cSrcweir catch ( MalformedURLException ex ) 374cdf0e10cSrcweir { 375cdf0e10cSrcweir ex.printStackTrace(); 376cdf0e10cSrcweir } 377cdf0e10cSrcweir } 378cdf0e10cSrcweir 379cdf0e10cSrcweir return sResultURL; 380cdf0e10cSrcweir 381cdf0e10cSrcweir } 382cdf0e10cSrcweir SaveHTMLTemp( XComponentContext xContext, String sArticle )383cdf0e10cSrcweir protected static XInputStream SaveHTMLTemp( XComponentContext xContext, String sArticle ) 384cdf0e10cSrcweir { 385cdf0e10cSrcweir XInputStream xResult = null; 386cdf0e10cSrcweir 387cdf0e10cSrcweir if ( xContext != null ) 388cdf0e10cSrcweir { 389cdf0e10cSrcweir try 390cdf0e10cSrcweir { 391cdf0e10cSrcweir Object oTempFile = xContext.getServiceManager().createInstanceWithContext( "com.sun.star.io.TempFile", xContext ); 392cdf0e10cSrcweir XStream xStream = ( XStream ) UnoRuntime.queryInterface( XStream.class, oTempFile ); 393cdf0e10cSrcweir XSeekable xSeekable = ( XSeekable ) UnoRuntime.queryInterface( XSeekable.class, oTempFile ); 394cdf0e10cSrcweir if ( xStream != null && xSeekable != null ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir XOutputStream xOutputStream = xStream.getOutputStream(); 397cdf0e10cSrcweir XInputStream xInputStream = xStream.getInputStream(); 398cdf0e10cSrcweir if ( xOutputStream != null && xInputStream != null ) 399cdf0e10cSrcweir { 400cdf0e10cSrcweir String sHTML = sHTMLHeader.concat( sArticle ); 401cdf0e10cSrcweir sHTML = sHTML.concat( sHTMLFooter ); 402cdf0e10cSrcweir xOutputStream.writeBytes( sHTML.getBytes( "UTF-8" ) ); 403cdf0e10cSrcweir // xOutputStream.closeOutput(); 404cdf0e10cSrcweir xSeekable.seek( 0 ); 405cdf0e10cSrcweir 406cdf0e10cSrcweir xResult = xInputStream; 407cdf0e10cSrcweir } 408cdf0e10cSrcweir } 409cdf0e10cSrcweir } 410cdf0e10cSrcweir catch ( Exception ex ) 411cdf0e10cSrcweir { 412cdf0e10cSrcweir ex.printStackTrace(); 413cdf0e10cSrcweir } 414cdf0e10cSrcweir } 415cdf0e10cSrcweir 416cdf0e10cSrcweir return xResult; 417cdf0e10cSrcweir } 418cdf0e10cSrcweir 419cdf0e10cSrcweir CreateTempFile( XComponentContext xContext )420cdf0e10cSrcweir protected static String CreateTempFile( XComponentContext xContext ) 421cdf0e10cSrcweir { 422cdf0e10cSrcweir String sURL = ""; 423cdf0e10cSrcweir try 424cdf0e10cSrcweir { 425cdf0e10cSrcweir Object oTempFile = xContext.getServiceManager().createInstanceWithContext( "com.sun.star.io.TempFile", xContext ); 426cdf0e10cSrcweir XPropertySet xPropertySet = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, oTempFile ); 427cdf0e10cSrcweir xPropertySet.setPropertyValue( "RemoveFile", Boolean.FALSE ); 428cdf0e10cSrcweir sURL = ( String ) xPropertySet.getPropertyValue( "Uri" ); 429cdf0e10cSrcweir 430cdf0e10cSrcweir XInputStream xInputStream = ( XInputStream ) UnoRuntime.queryInterface( XInputStream.class, oTempFile ); 431cdf0e10cSrcweir xInputStream.closeInput(); 432cdf0e10cSrcweir XOutputStream xOutputStream = ( XOutputStream ) UnoRuntime.queryInterface( XOutputStream.class, oTempFile ); 433cdf0e10cSrcweir xOutputStream.closeOutput(); 434cdf0e10cSrcweir } catch ( com.sun.star.uno.Exception ex ) 435cdf0e10cSrcweir { 436cdf0e10cSrcweir ex.printStackTrace(); 437cdf0e10cSrcweir } 438cdf0e10cSrcweir return sURL; 439cdf0e10cSrcweir } 440cdf0e10cSrcweir EachLine( String sURL )441cdf0e10cSrcweir protected static String EachLine( String sURL ) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir String sText = ""; 444cdf0e10cSrcweir try 445cdf0e10cSrcweir { 446cdf0e10cSrcweir URL aURL = new URL( sURL ); 447cdf0e10cSrcweir File aFile = new File( aURL.getFile() ); 448cdf0e10cSrcweir InputStreamReader aInputReader = new InputStreamReader( new FileInputStream( aFile ), "UTF-8" ); 449cdf0e10cSrcweir BufferedReader aBufReader = new BufferedReader( aInputReader ); 450cdf0e10cSrcweir 451cdf0e10cSrcweir StringBuffer aBuf = new StringBuffer(); 452cdf0e10cSrcweir String sEachLine = aBufReader.readLine(); 453cdf0e10cSrcweir 454cdf0e10cSrcweir while( sEachLine != null ) 455cdf0e10cSrcweir { 456cdf0e10cSrcweir aBuf.append( sEachLine ); 457cdf0e10cSrcweir aBuf.append( "\n" ); 458cdf0e10cSrcweir 459cdf0e10cSrcweir sEachLine = aBufReader.readLine(); 460cdf0e10cSrcweir } 461cdf0e10cSrcweir sText = aBuf.toString(); 462cdf0e10cSrcweir } catch ( Exception e ) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir e.printStackTrace(); 465cdf0e10cSrcweir } 466cdf0e10cSrcweir return sText; 467cdf0e10cSrcweir } 468cdf0e10cSrcweir GetDocTitle( XModel xDoc )469cdf0e10cSrcweir protected static String GetDocTitle( XModel xDoc ) 470cdf0e10cSrcweir { 471cdf0e10cSrcweir String sTitle = ""; 472cdf0e10cSrcweir XDocumentInfoSupplier xDocInfoSup = ( XDocumentInfoSupplier ) UnoRuntime.queryInterface( XDocumentInfoSupplier.class, xDoc ); 473cdf0e10cSrcweir XPropertySet xPropSet = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, xDocInfoSup.getDocumentInfo() ); 474cdf0e10cSrcweir try 475cdf0e10cSrcweir { 476cdf0e10cSrcweir sTitle = ( String ) xPropSet.getPropertyValue( "Title" ); 477cdf0e10cSrcweir } catch ( Exception ex ) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir ex.printStackTrace(); 480cdf0e10cSrcweir } 481cdf0e10cSrcweir return sTitle; 482cdf0e10cSrcweir } 483cdf0e10cSrcweir SetDocTitle( XModel xDoc, String sTitle )484cdf0e10cSrcweir protected static void SetDocTitle( XModel xDoc, String sTitle ) 485cdf0e10cSrcweir { 486cdf0e10cSrcweir XDocumentInfoSupplier xDocInfoSup = ( XDocumentInfoSupplier ) UnoRuntime.queryInterface( XDocumentInfoSupplier.class, xDoc ); 487cdf0e10cSrcweir if ( xDocInfoSup != null ) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir XPropertySet xPropSet = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, xDocInfoSup.getDocumentInfo() ); 490cdf0e10cSrcweir if ( xPropSet != null ) 491cdf0e10cSrcweir { 492cdf0e10cSrcweir try 493cdf0e10cSrcweir { 494cdf0e10cSrcweir xPropSet.setPropertyValue( "Title", sTitle ); 495cdf0e10cSrcweir } 496cdf0e10cSrcweir catch ( Exception ex ) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir ex.printStackTrace(); 499cdf0e10cSrcweir } 500cdf0e10cSrcweir } 501cdf0e10cSrcweir } 502cdf0e10cSrcweir } 503cdf0e10cSrcweir GetDocServiceName( XComponentContext xContext, XModel xModel )504cdf0e10cSrcweir protected static String GetDocServiceName( XComponentContext xContext, XModel xModel ) 505cdf0e10cSrcweir { 506cdf0e10cSrcweir String aDocServiceName = ""; 507cdf0e10cSrcweir if ( xModel != null && xContext != null ) 508cdf0e10cSrcweir { 509cdf0e10cSrcweir try 510cdf0e10cSrcweir { 511cdf0e10cSrcweir XMultiComponentFactory xFactory = xContext.getServiceManager(); 512cdf0e10cSrcweir if ( xFactory == null ) 513cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException(); 514cdf0e10cSrcweir 515cdf0e10cSrcweir Object oModuleManager = xFactory.createInstanceWithContext( "com.sun.star.frame.ModuleManager", xContext ); 516cdf0e10cSrcweir XModuleManager xModuleManager = ( XModuleManager ) UnoRuntime.queryInterface( XModuleManager.class, oModuleManager ); 517cdf0e10cSrcweir if ( xModuleManager != null ) 518cdf0e10cSrcweir aDocServiceName = xModuleManager.identify( xModel ); 519cdf0e10cSrcweir } 520cdf0e10cSrcweir catch( java.lang.Exception e ) 521cdf0e10cSrcweir { 522cdf0e10cSrcweir e.printStackTrace(); 523cdf0e10cSrcweir } 524cdf0e10cSrcweir } 525cdf0e10cSrcweir 526cdf0e10cSrcweir return aDocServiceName; 527cdf0e10cSrcweir } 528cdf0e10cSrcweir GetFilterName( XComponentContext xContext, String aTypeName, String aDocServiceName )529cdf0e10cSrcweir protected static String GetFilterName( XComponentContext xContext, String aTypeName, String aDocServiceName ) 530cdf0e10cSrcweir { 531cdf0e10cSrcweir String aFilterName = ""; 532cdf0e10cSrcweir if ( xContext != null && aTypeName != null && aTypeName.length() != 0 533cdf0e10cSrcweir && aDocServiceName != null && aDocServiceName.length() != 0 ) 534cdf0e10cSrcweir { 535cdf0e10cSrcweir try 536cdf0e10cSrcweir { 537cdf0e10cSrcweir Object oFilterFactory = xContext.getServiceManager().createInstanceWithContext( "com.sun.star.document.FilterFactory", xContext ); 538cdf0e10cSrcweir XContainerQuery xQuery = ( XContainerQuery )UnoRuntime.queryInterface( XContainerQuery.class, oFilterFactory ); 539cdf0e10cSrcweir if ( xQuery != null ) 540cdf0e10cSrcweir { 541cdf0e10cSrcweir NamedValue[] aRequest = new NamedValue[2]; 542cdf0e10cSrcweir aRequest[0] = new NamedValue( "Type", aTypeName ); 543cdf0e10cSrcweir aRequest[1] = new NamedValue( "DocumentService", aDocServiceName ); 544cdf0e10cSrcweir 545cdf0e10cSrcweir XEnumeration xSet = xQuery.createSubSetEnumerationByProperties( aRequest ); 546cdf0e10cSrcweir if ( xSet != null ) 547cdf0e10cSrcweir { 548cdf0e10cSrcweir boolean bAcceptable = false; 549cdf0e10cSrcweir while ( xSet.hasMoreElements() && !bAcceptable ) 550cdf0e10cSrcweir { 551cdf0e10cSrcweir PropertyValue[] pFilterProps = ( PropertyValue[] )AnyConverter.toArray( xSet.nextElement() ); 552cdf0e10cSrcweir if ( pFilterProps != null ) 553cdf0e10cSrcweir { 554cdf0e10cSrcweir int nLen = pFilterProps.length; 555cdf0e10cSrcweir String aTmpFilter = null; 556cdf0e10cSrcweir 557cdf0e10cSrcweir for ( int nInd = 0; nInd < nLen; nInd++ ) 558cdf0e10cSrcweir { 559cdf0e10cSrcweir if ( pFilterProps[nInd].Name.equals( "Name" ) ) 560cdf0e10cSrcweir aTmpFilter = AnyConverter.toString( pFilterProps[nInd].Value ); 561cdf0e10cSrcweir else if ( pFilterProps[nInd].Name.equals( "Flags" ) ) 562cdf0e10cSrcweir bAcceptable = ( ( AnyConverter.toInt( pFilterProps[nInd].Value ) & 2 ) == 2 ); // must allow export 563cdf0e10cSrcweir } 564cdf0e10cSrcweir 565cdf0e10cSrcweir if ( bAcceptable ) 566cdf0e10cSrcweir aFilterName = aTmpFilter; 567cdf0e10cSrcweir } 568cdf0e10cSrcweir } 569cdf0e10cSrcweir } 570cdf0e10cSrcweir } 571cdf0e10cSrcweir } 572cdf0e10cSrcweir catch( java.lang.Exception e ) 573cdf0e10cSrcweir { 574cdf0e10cSrcweir e.printStackTrace(); 575cdf0e10cSrcweir } 576cdf0e10cSrcweir } 577cdf0e10cSrcweir 578cdf0e10cSrcweir return aFilterName; 579cdf0e10cSrcweir } 580cdf0e10cSrcweir GetConfigurationProvider( XComponentContext xContext )581cdf0e10cSrcweir protected static XMultiServiceFactory GetConfigurationProvider( XComponentContext xContext ) 582cdf0e10cSrcweir throws com.sun.star.uno.Exception 583cdf0e10cSrcweir { 584cdf0e10cSrcweir XMultiServiceFactory xConfigurationProvider = null; 585cdf0e10cSrcweir if ( xContext != null ) 586cdf0e10cSrcweir { 587cdf0e10cSrcweir XMultiComponentFactory xFactory = xContext.getServiceManager(); 588cdf0e10cSrcweir Object oConfigProvider = xFactory.createInstanceWithContext( "com.sun.star.configuration.ConfigurationProvider", xContext ); 589cdf0e10cSrcweir xConfigurationProvider = ( XMultiServiceFactory ) UnoRuntime.queryInterface( XMultiServiceFactory.class, oConfigProvider ); 590cdf0e10cSrcweir } 591cdf0e10cSrcweir 592cdf0e10cSrcweir if ( xConfigurationProvider == null ) 593cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException(); 594cdf0e10cSrcweir 595cdf0e10cSrcweir return xConfigurationProvider; 596cdf0e10cSrcweir } 597cdf0e10cSrcweir GetConfig( XComponentContext xContext, String sNodepath, boolean bWriteAccess )598cdf0e10cSrcweir protected static Object GetConfig( XComponentContext xContext, String sNodepath, boolean bWriteAccess ) 599cdf0e10cSrcweir throws com.sun.star.uno.Exception 600cdf0e10cSrcweir { 601cdf0e10cSrcweir if ( xContext == null || sNodepath == null ) 602cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException(); 603cdf0e10cSrcweir 604cdf0e10cSrcweir PropertyValue aVal = new PropertyValue(); 605cdf0e10cSrcweir aVal.Name = "nodepath"; 606cdf0e10cSrcweir aVal.Value = sNodepath; 607cdf0e10cSrcweir Object[] aArgs = new Object[1]; 608cdf0e10cSrcweir aArgs[0] = aVal; 609cdf0e10cSrcweir 610cdf0e10cSrcweir return GetConfigurationProvider( xContext ).createInstanceWithArguments( 611cdf0e10cSrcweir ( bWriteAccess ? "com.sun.star.configuration.ConfigurationUpdateAccess" 612cdf0e10cSrcweir : "com.sun.star.configuration.ConfigurationAccess" ), 613cdf0e10cSrcweir aArgs ); 614cdf0e10cSrcweir } 615cdf0e10cSrcweir GetConfigProps( XComponentContext xContext, String sNodepath )616cdf0e10cSrcweir protected static XPropertySet GetConfigProps( XComponentContext xContext, String sNodepath ) 617cdf0e10cSrcweir throws com.sun.star.uno.Exception 618cdf0e10cSrcweir { 619cdf0e10cSrcweir XPropertySet xProps = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, GetConfig( xContext, sNodepath, true ) ); 620cdf0e10cSrcweir if ( xProps == null ) 621cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException(); 622cdf0e10cSrcweir 623cdf0e10cSrcweir return xProps; 624cdf0e10cSrcweir } 625cdf0e10cSrcweir 626cdf0e10cSrcweir GetConfigNameContainer( XComponentContext xContext, String sNodepath )627cdf0e10cSrcweir protected static XNameContainer GetConfigNameContainer( XComponentContext xContext, String sNodepath ) 628cdf0e10cSrcweir throws com.sun.star.uno.Exception 629cdf0e10cSrcweir { 630cdf0e10cSrcweir XNameContainer xContainer = ( XNameContainer ) UnoRuntime.queryInterface( XNameContainer.class, GetConfig( xContext, sNodepath, true ) ); 631cdf0e10cSrcweir if ( xContainer == null ) 632cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException(); 633cdf0e10cSrcweir 634cdf0e10cSrcweir return xContainer; 635cdf0e10cSrcweir } 636cdf0e10cSrcweir GetConfigNameAccess( XComponentContext xContext, String sNodepath )637cdf0e10cSrcweir protected static XNameAccess GetConfigNameAccess( XComponentContext xContext, String sNodepath ) 638cdf0e10cSrcweir throws com.sun.star.uno.Exception 639cdf0e10cSrcweir { 640cdf0e10cSrcweir XNameAccess xNameAccess = ( XNameAccess ) UnoRuntime.queryInterface( XNameAccess.class, GetConfig( xContext, sNodepath, false ) ); 641cdf0e10cSrcweir if ( xNameAccess == null ) 642cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException(); 643cdf0e10cSrcweir 644cdf0e10cSrcweir return xNameAccess; 645cdf0e10cSrcweir } 646cdf0e10cSrcweir SetConfigurationProxy( HostConfiguration aHostConfig, XComponentContext xContext )647cdf0e10cSrcweir protected static void SetConfigurationProxy( HostConfiguration aHostConfig, XComponentContext xContext ) 648cdf0e10cSrcweir { 649cdf0e10cSrcweir if ( aHostConfig == null || xContext == null ) 650cdf0e10cSrcweir return; 651cdf0e10cSrcweir 652cdf0e10cSrcweir try 653cdf0e10cSrcweir { 654cdf0e10cSrcweir XNameAccess xNameAccess = GetConfigNameAccess( xContext, "org.openoffice.Inet/Settings" ); 655cdf0e10cSrcweir 656cdf0e10cSrcweir int nProxyType = AnyConverter.toInt( xNameAccess.getByName( "ooInetProxyType" ) ); 657cdf0e10cSrcweir if ( nProxyType == 0 ) 658cdf0e10cSrcweir aHostConfig.setProxyHost( null ); 659cdf0e10cSrcweir else 660cdf0e10cSrcweir { 661cdf0e10cSrcweir if ( nProxyType == 1 ) 662cdf0e10cSrcweir { 663cdf0e10cSrcweir // system proxy 664cdf0e10cSrcweir } 665cdf0e10cSrcweir else if ( nProxyType == 2 ) 666cdf0e10cSrcweir { 667cdf0e10cSrcweir String aProxyNameProp = "ooInetHTTPProxyName"; 668cdf0e10cSrcweir String aProxyPortProp = "ooInetHTTPProxyPort"; 669cdf0e10cSrcweir 670cdf0e10cSrcweir if ( aHostConfig.getProtocol().getScheme().equals( "https" ) ) 671cdf0e10cSrcweir { 672cdf0e10cSrcweir aProxyNameProp = "ooInetHTTPSProxyName"; 673cdf0e10cSrcweir aProxyPortProp = "ooInetHTTPSProxyPort"; 674cdf0e10cSrcweir } 675cdf0e10cSrcweir 676cdf0e10cSrcweir String aNoProxyList = AnyConverter.toString( xNameAccess.getByName( "ooInetNoProxy" ) ); 677cdf0e10cSrcweir String aProxyName = AnyConverter.toString( xNameAccess.getByName( aProxyNameProp ) ); 678cdf0e10cSrcweir 679cdf0e10cSrcweir int nProxyPort = 80; 680cdf0e10cSrcweir 681cdf0e10cSrcweir Object aPortNo = xNameAccess.getByName( aProxyPortProp ); 682cdf0e10cSrcweir if ( !AnyConverter.isVoid( aPortNo ) ) 683cdf0e10cSrcweir nProxyPort = AnyConverter.toInt( aPortNo ); 684cdf0e10cSrcweir 685cdf0e10cSrcweir if ( nProxyPort == -1 ) 686cdf0e10cSrcweir nProxyPort = 80; 687cdf0e10cSrcweir 688cdf0e10cSrcweir // TODO: check whether the URL is in the NoProxy list 689cdf0e10cSrcweir aHostConfig.setProxy( aProxyName, nProxyPort ); 690cdf0e10cSrcweir } 691cdf0e10cSrcweir } 692cdf0e10cSrcweir } 693cdf0e10cSrcweir catch( java.lang.Exception e ) 694cdf0e10cSrcweir { 695cdf0e10cSrcweir e.printStackTrace(); 696cdf0e10cSrcweir } 697cdf0e10cSrcweir } 698cdf0e10cSrcweir ShowURLInBrowser( XComponentContext xContext, String sURL )699cdf0e10cSrcweir protected static void ShowURLInBrowser( XComponentContext xContext, String sURL ) 700cdf0e10cSrcweir { 701cdf0e10cSrcweir if ( xContext != null && sURL != null && sURL.length() > 0 ) 702cdf0e10cSrcweir { 703cdf0e10cSrcweir try 704cdf0e10cSrcweir { 705*9807c9deSAriel Constenla-Haile XSystemShellExecute xSystemShell = com.sun.star.system.SystemShellExecute.create( xContext ); 706cdf0e10cSrcweir if ( xSystemShell != null ) 707cdf0e10cSrcweir xSystemShell.execute( sURL, "", SystemShellExecuteFlags.DEFAULTS ); 708cdf0e10cSrcweir } 709cdf0e10cSrcweir catch( Exception e ) 710cdf0e10cSrcweir { 711cdf0e10cSrcweir e.printStackTrace(); 712cdf0e10cSrcweir } 713cdf0e10cSrcweir } 714cdf0e10cSrcweir } 715cdf0e10cSrcweir ExecuteMethod( HttpMethodBase aMethod, HostConfiguration aHostConfig, URI aURI, XComponentContext xContext, boolean bSetHost )716cdf0e10cSrcweir protected static void ExecuteMethod( HttpMethodBase aMethod, HostConfiguration aHostConfig, URI aURI, XComponentContext xContext, boolean bSetHost ) 717cdf0e10cSrcweir throws WikiCancelException, IOException, SSLException 718cdf0e10cSrcweir { 719cdf0e10cSrcweir if ( aMethod != null && aHostConfig != null && aURI != null && xContext != null ) 720cdf0e10cSrcweir { 721cdf0e10cSrcweir if ( bSetHost ) 722cdf0e10cSrcweir { 723cdf0e10cSrcweir aHostConfig.setHost( aURI ); 724cdf0e10cSrcweir SetConfigurationProxy( aHostConfig, xContext ); 725cdf0e10cSrcweir } 726cdf0e10cSrcweir 727cdf0e10cSrcweir boolean bNoUnknownCertNotification = false; 728cdf0e10cSrcweir if ( aHostConfig.getProtocol().getScheme().equals( "https" ) 729cdf0e10cSrcweir && AllowUnknownCert( xContext, aURI.getHost() ) ) 730cdf0e10cSrcweir { 731cdf0e10cSrcweir // let unknown certificates be accepted 732cdf0e10cSrcweir { 733cdf0e10cSrcweir { 734cdf0e10cSrcweir aHostConfig.setHost( aHostConfig.getHost(), ( aURI.getPort() < 0 ? 443 : aURI.getPort() ), Helper.GetOwnHttps( aURI.getPort() ) ); 735cdf0e10cSrcweir Helper.GetHttpClient().executeMethod( aHostConfig, aMethod ); 736cdf0e10cSrcweir } 737cdf0e10cSrcweir } 738cdf0e10cSrcweir } 739cdf0e10cSrcweir else 740cdf0e10cSrcweir { 741cdf0e10cSrcweir Helper.GetHttpClient().executeMethod( aHostConfig, aMethod ); 742cdf0e10cSrcweir } 743cdf0e10cSrcweir } 744cdf0e10cSrcweir } 745cdf0e10cSrcweir 746cdf0e10cSrcweir static private class HTMLParse extends HTMLEditorKit 747cdf0e10cSrcweir { 748cdf0e10cSrcweir 749cdf0e10cSrcweir public HTMLEditorKit.Parser getParser() 750cdf0e10cSrcweir { 751cdf0e10cSrcweir return super.getParser(); 752cdf0e10cSrcweir } 753cdf0e10cSrcweir } 754cdf0e10cSrcweir 755cdf0e10cSrcweir static protected HTMLEditorKit.Parser GetHTMLParser() 756cdf0e10cSrcweir { 757cdf0e10cSrcweir return new HTMLParse().getParser(); 758cdf0e10cSrcweir } 759cdf0e10cSrcweir 760cdf0e10cSrcweir static protected boolean LoginReportsError( String sRespond ) 761cdf0e10cSrcweir { 762cdf0e10cSrcweir boolean bResult = true; 763cdf0e10cSrcweir if ( sRespond != null ) 764cdf0e10cSrcweir { 765cdf0e10cSrcweir try 766cdf0e10cSrcweir { 767cdf0e10cSrcweir StringReader aReader = new StringReader( sRespond ); 768cdf0e10cSrcweir HTMLEditorKit.Parser aParser = GetHTMLParser(); 769cdf0e10cSrcweir EditPageParser aCallback = new EditPageParser(); 770cdf0e10cSrcweir 771cdf0e10cSrcweir aParser.parse( aReader, aCallback, true ); 772cdf0e10cSrcweir bResult = ( aCallback.m_nErrorInd >= 0 ); 773cdf0e10cSrcweir } 774cdf0e10cSrcweir catch( Exception e ) 775cdf0e10cSrcweir { 776cdf0e10cSrcweir e.printStackTrace(); 777cdf0e10cSrcweir } 778cdf0e10cSrcweir } 779cdf0e10cSrcweir 780cdf0e10cSrcweir return bResult; 781cdf0e10cSrcweir } 782cdf0e10cSrcweir GetLoginToken( String sLoginPage )783cdf0e10cSrcweir static protected String GetLoginToken( String sLoginPage ) 784cdf0e10cSrcweir { 785cdf0e10cSrcweir String sResult = ""; 786cdf0e10cSrcweir if ( sLoginPage != null && sLoginPage.length() > 0 ) 787cdf0e10cSrcweir { 788cdf0e10cSrcweir try 789cdf0e10cSrcweir { 790cdf0e10cSrcweir StringReader aReader = new StringReader( sLoginPage ); 791cdf0e10cSrcweir HTMLEditorKit.Parser aParser = Helper.GetHTMLParser(); 792cdf0e10cSrcweir EditPageParser aCallbacks = new EditPageParser(); 793cdf0e10cSrcweir 794cdf0e10cSrcweir aParser.parse( aReader, aCallbacks, true ); 795cdf0e10cSrcweir sResult = aCallbacks.m_sLoginToken; 796cdf0e10cSrcweir } 797cdf0e10cSrcweir catch( Exception e ) 798cdf0e10cSrcweir { 799cdf0e10cSrcweir e.printStackTrace(); 800cdf0e10cSrcweir } 801cdf0e10cSrcweir } 802cdf0e10cSrcweir 803cdf0e10cSrcweir return sResult; 804cdf0e10cSrcweir } 805cdf0e10cSrcweir Login( URI aMainURL, String sWikiUser, String sWikiPass, XComponentContext xContext )806cdf0e10cSrcweir static protected HostConfiguration Login( URI aMainURL, String sWikiUser, String sWikiPass, XComponentContext xContext ) 807cdf0e10cSrcweir throws com.sun.star.uno.Exception, java.io.IOException, WikiCancelException 808cdf0e10cSrcweir { 809cdf0e10cSrcweir HostConfiguration aHostConfig = null; 810cdf0e10cSrcweir 811cdf0e10cSrcweir if ( sWikiUser != null && sWikiPass != null && xContext != null ) 812cdf0e10cSrcweir { 813cdf0e10cSrcweir HostConfiguration aNewHostConfig = new HostConfiguration(); 814cdf0e10cSrcweir 815cdf0e10cSrcweir URI aURI = new URI( aMainURL.toString() + "index.php?title=Special:Userlogin" ); 816cdf0e10cSrcweir GetMethod aGetCookie = new GetMethod( aURI.getEscapedPathQuery() ); 817cdf0e10cSrcweir 818cdf0e10cSrcweir ExecuteMethod( aGetCookie, aNewHostConfig, aURI, xContext, true ); 819cdf0e10cSrcweir 820cdf0e10cSrcweir int nResultCode = aGetCookie.getStatusCode(); 821cdf0e10cSrcweir String sLoginPage = null; 822cdf0e10cSrcweir if ( nResultCode == 200 ) 823cdf0e10cSrcweir sLoginPage = aGetCookie.getResponseBodyAsString(); 824cdf0e10cSrcweir 825cdf0e10cSrcweir aGetCookie.releaseConnection(); 826cdf0e10cSrcweir 827cdf0e10cSrcweir if ( sLoginPage != null ) 828cdf0e10cSrcweir { 829cdf0e10cSrcweir String sLoginToken = GetLoginToken( sLoginPage ); 830cdf0e10cSrcweir 831cdf0e10cSrcweir PostMethod aPost = new PostMethod(); 832cdf0e10cSrcweir URI aPostURI = new URI( aMainURL.getPath() + "index.php?title=Special:Userlogin&action=submitlogin" ); 833cdf0e10cSrcweir aPost.setPath( aPostURI.getEscapedPathQuery() ); 834cdf0e10cSrcweir 835cdf0e10cSrcweir aPost.addParameter( "wpName", sWikiUser ); 836cdf0e10cSrcweir aPost.addParameter( "wpRemember", "1" ); 837cdf0e10cSrcweir aPost.addParameter( "wpPassword", sWikiPass ); 838cdf0e10cSrcweir if ( sLoginToken.length() > 0 ) 839cdf0e10cSrcweir aPost.addParameter( "wpLoginToken", sLoginToken ); 840cdf0e10cSrcweir 841cdf0e10cSrcweir String[][] pArgs = GetSpecialArgs( xContext, aMainURL.getHost() ); 842cdf0e10cSrcweir if ( pArgs != null ) 843cdf0e10cSrcweir for ( int nArgInd = 0; nArgInd < pArgs.length; nArgInd++ ) 844cdf0e10cSrcweir if ( pArgs[nArgInd].length == 2 && pArgs[nArgInd][0] != null && pArgs[nArgInd][1] != null ) 845cdf0e10cSrcweir aPost.addParameter( pArgs[nArgInd][0], pArgs[nArgInd][1] ); 846cdf0e10cSrcweir 847cdf0e10cSrcweir ExecuteMethod( aPost, aNewHostConfig, aPostURI, xContext, false ); 848cdf0e10cSrcweir 849cdf0e10cSrcweir nResultCode = aPost.getStatusCode(); 850cdf0e10cSrcweir 851cdf0e10cSrcweir while( nResultCode >= 301 && nResultCode <= 303 || nResultCode == 307 ) 852cdf0e10cSrcweir { 853cdf0e10cSrcweir String sRedirectURL = aPost.getResponseHeader( "Location" ).getValue(); 854cdf0e10cSrcweir aPost.releaseConnection(); 855cdf0e10cSrcweir 856cdf0e10cSrcweir aURI = new URI( sRedirectURL ); 857cdf0e10cSrcweir aPost = new PostMethod(); 858cdf0e10cSrcweir aPost.setPath( aURI.getEscapedPathQuery() ); 859cdf0e10cSrcweir ExecuteMethod( aPost, aNewHostConfig, aURI, xContext, false ); 860cdf0e10cSrcweir 861cdf0e10cSrcweir nResultCode = aPost.getStatusCode(); 862cdf0e10cSrcweir } 863cdf0e10cSrcweir 864cdf0e10cSrcweir if ( nResultCode == 200 ) 865cdf0e10cSrcweir { 866cdf0e10cSrcweir String sResult = aPost.getResponseBodyAsString(); 867cdf0e10cSrcweir if ( !LoginReportsError( sResult ) ) 868cdf0e10cSrcweir aHostConfig = aNewHostConfig; 869cdf0e10cSrcweir } 870cdf0e10cSrcweir 871cdf0e10cSrcweir aPost.releaseConnection(); 872cdf0e10cSrcweir } 873cdf0e10cSrcweir } 874cdf0e10cSrcweir 875cdf0e10cSrcweir return aHostConfig; 876cdf0e10cSrcweir } 877cdf0e10cSrcweir GetControlFromDialog( XDialog xDialog, String aControlName )878cdf0e10cSrcweir private static XControl GetControlFromDialog( XDialog xDialog, String aControlName ) 879cdf0e10cSrcweir { 880cdf0e10cSrcweir XControl xResult = null; 881cdf0e10cSrcweir XControlContainer xControlCont = (XControlContainer) UnoRuntime.queryInterface( XControlContainer.class, xDialog ); 882cdf0e10cSrcweir 883cdf0e10cSrcweir if ( xControlCont != null ) 884cdf0e10cSrcweir { 885cdf0e10cSrcweir Object oControl = xControlCont.getControl( aControlName ); 886cdf0e10cSrcweir xResult = ( XControl ) UnoRuntime.queryInterface( XControl.class, oControl ); 887cdf0e10cSrcweir } 888cdf0e10cSrcweir 889cdf0e10cSrcweir return xResult; 890cdf0e10cSrcweir } 891cdf0e10cSrcweir GetSubControlPropSet( XDialog xDialog, String aControlName )892cdf0e10cSrcweir private static XPropertySet GetSubControlPropSet( XDialog xDialog, String aControlName ) 893cdf0e10cSrcweir { 894cdf0e10cSrcweir XControl xControl = GetControlFromDialog( xDialog, aControlName ); 895cdf0e10cSrcweir if ( xControl != null ) 896cdf0e10cSrcweir return ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, xControl.getModel() ); 897cdf0e10cSrcweir 898cdf0e10cSrcweir return null; 899cdf0e10cSrcweir } 900cdf0e10cSrcweir SetControlPropInDialog( XDialog xDialog, String aControlName, String aPropName, Object aPropValue )901cdf0e10cSrcweir protected static void SetControlPropInDialog( XDialog xDialog, String aControlName, String aPropName, Object aPropValue ) 902cdf0e10cSrcweir { 903cdf0e10cSrcweir if ( xDialog != null && aControlName != null && aPropName != null && aPropValue != null ) 904cdf0e10cSrcweir { 905cdf0e10cSrcweir try 906cdf0e10cSrcweir { 907cdf0e10cSrcweir XPropertySet xPropSet = GetSubControlPropSet( xDialog, aControlName ); 908cdf0e10cSrcweir if ( xPropSet != null ) 909cdf0e10cSrcweir xPropSet.setPropertyValue( aPropName, aPropValue ); 910cdf0e10cSrcweir } 911cdf0e10cSrcweir catch ( com.sun.star.uno.Exception e ) 912cdf0e10cSrcweir { 913cdf0e10cSrcweir e.printStackTrace(); 914cdf0e10cSrcweir } 915cdf0e10cSrcweir } 916cdf0e10cSrcweir } 917cdf0e10cSrcweir GetPasswordsForURLAndUser( XComponentContext xContext, String sURL, String sUserName )918cdf0e10cSrcweir protected static String[] GetPasswordsForURLAndUser( XComponentContext xContext, String sURL, String sUserName ) 919cdf0e10cSrcweir { 920cdf0e10cSrcweir String[] aResult = null; 921cdf0e10cSrcweir 922cdf0e10cSrcweir try 923cdf0e10cSrcweir { 924cdf0e10cSrcweir if ( xContext != null && sURL != null && sURL.length() > 0 && sUserName != null && sUserName.length() > 0 ) 925cdf0e10cSrcweir { 926cdf0e10cSrcweir UrlRecord aRec = GetPasswordContainer( xContext ).findForName( sURL, sUserName, GetInteractionHandler( xContext ) ); 927cdf0e10cSrcweir if ( aRec != null && aRec.UserList != null && aRec.UserList.length > 0 928cdf0e10cSrcweir && aRec.UserList[0].UserName.equals( sUserName ) ) 929cdf0e10cSrcweir aResult = aRec.UserList[0].Passwords; 930cdf0e10cSrcweir } 931cdf0e10cSrcweir } 932cdf0e10cSrcweir catch( Exception e ) 933cdf0e10cSrcweir { 934cdf0e10cSrcweir e.printStackTrace(); 935cdf0e10cSrcweir } 936cdf0e10cSrcweir 937cdf0e10cSrcweir return aResult; 938cdf0e10cSrcweir } 939cdf0e10cSrcweir PasswordStoringIsAllowed( XComponentContext xContext )940cdf0e10cSrcweir protected static boolean PasswordStoringIsAllowed( XComponentContext xContext ) 941cdf0e10cSrcweir { 942cdf0e10cSrcweir boolean bResult = false; 943cdf0e10cSrcweir try 944cdf0e10cSrcweir { 945cdf0e10cSrcweir XMasterPasswordHandling xMasterHdl = (XMasterPasswordHandling)UnoRuntime.queryInterface( XMasterPasswordHandling.class, GetPasswordContainer( xContext ) ); 946cdf0e10cSrcweir if ( xMasterHdl != null ) 947cdf0e10cSrcweir bResult = xMasterHdl.isPersistentStoringAllowed(); 948cdf0e10cSrcweir } 949cdf0e10cSrcweir catch( Exception e ) 950cdf0e10cSrcweir { 951cdf0e10cSrcweir e.printStackTrace(); 952cdf0e10cSrcweir } 953cdf0e10cSrcweir 954cdf0e10cSrcweir return bResult; 955cdf0e10cSrcweir } 956cdf0e10cSrcweir ShowError( XComponentContext xContext, XDialog xDialog, int nTitleID, int nErrorID, String sArg, boolean bQuery )957cdf0e10cSrcweir protected static void ShowError( XComponentContext xContext, XDialog xDialog, int nTitleID, int nErrorID, String sArg, boolean bQuery ) 958cdf0e10cSrcweir { 959cdf0e10cSrcweir XWindowPeer xPeer = null; 960cdf0e10cSrcweir XControl xControl = (XControl)UnoRuntime.queryInterface( XControl.class, xDialog ); 961cdf0e10cSrcweir if ( xControl != null ) 962cdf0e10cSrcweir xPeer = xControl.getPeer(); 963cdf0e10cSrcweir ShowError( xContext, xPeer, nTitleID, nErrorID, sArg, bQuery ); 964cdf0e10cSrcweir } 965cdf0e10cSrcweir ShowError( XComponentContext xContext, XWindowPeer xParentPeer, int nTitleID, int nErrorID, String sArg, boolean bQuery )966cdf0e10cSrcweir protected static boolean ShowError( XComponentContext xContext, XWindowPeer xParentPeer, int nTitleID, int nErrorID, String sArg, boolean bQuery ) 967cdf0e10cSrcweir { 968cdf0e10cSrcweir boolean bResult = false; 969cdf0e10cSrcweir 970cdf0e10cSrcweir if ( xContext != null && nErrorID >= 0 && nErrorID < STRINGS_NUM ) 971cdf0e10cSrcweir { 972cdf0e10cSrcweir boolean bShown = false; 973cdf0e10cSrcweir 974cdf0e10cSrcweir String sError = null; 975cdf0e10cSrcweir String sTitle = ""; 976cdf0e10cSrcweir 977cdf0e10cSrcweir try 978cdf0e10cSrcweir { 979cdf0e10cSrcweir sError = GetLocalizedString( xContext, nErrorID ); 980cdf0e10cSrcweir if ( sError != null && sArg != null ) 981cdf0e10cSrcweir sError = sError.replaceAll( "\\$ARG1", sArg ); 982cdf0e10cSrcweir 983cdf0e10cSrcweir sTitle = GetLocalizedString( xContext, nTitleID ); 984cdf0e10cSrcweir } 985cdf0e10cSrcweir catch( Exception e ) 986cdf0e10cSrcweir { 987cdf0e10cSrcweir e.printStackTrace(); 988cdf0e10cSrcweir } 989cdf0e10cSrcweir 990cdf0e10cSrcweir if ( sError == null ) 991cdf0e10cSrcweir sError = "Error: " + nErrorID; 992cdf0e10cSrcweir 993cdf0e10cSrcweir if ( xParentPeer != null ) 994cdf0e10cSrcweir { 995cdf0e10cSrcweir XMessageBoxFactory xMBFactory = null; 996cdf0e10cSrcweir XMessageBox xMB = null; 997cdf0e10cSrcweir try 998cdf0e10cSrcweir { 999cdf0e10cSrcweir XMultiComponentFactory xFactory = xContext.getServiceManager(); 1000cdf0e10cSrcweir if ( xFactory != null ) 1001cdf0e10cSrcweir xMBFactory = (XMessageBoxFactory)UnoRuntime.queryInterface( 1002cdf0e10cSrcweir XMessageBoxFactory.class, 1003cdf0e10cSrcweir xFactory.createInstanceWithContext( "com.sun.star.awt.Toolkit", xContext ) ); 1004cdf0e10cSrcweir 1005cdf0e10cSrcweir if ( xMBFactory != null ) 1006cdf0e10cSrcweir { 1007cdf0e10cSrcweir if ( bQuery ) 1008cdf0e10cSrcweir { 1009cdf0e10cSrcweir xMB = xMBFactory.createMessageBox( 1010cdf0e10cSrcweir xParentPeer, 101161161268SAriel Constenla-Haile MessageBoxType.QUERYBOX, 1012cdf0e10cSrcweir MessageBoxButtons.BUTTONS_YES_NO | MessageBoxButtons.DEFAULT_BUTTON_NO, 1013cdf0e10cSrcweir sTitle, 1014cdf0e10cSrcweir sError ); 1015cdf0e10cSrcweir } 1016cdf0e10cSrcweir else 1017cdf0e10cSrcweir { 1018cdf0e10cSrcweir xMB = xMBFactory.createMessageBox( 1019cdf0e10cSrcweir xParentPeer, 102061161268SAriel Constenla-Haile MessageBoxType.ERRORBOX, 1021cdf0e10cSrcweir MessageBoxButtons.BUTTONS_OK, 1022cdf0e10cSrcweir sTitle, 1023cdf0e10cSrcweir sError ); 1024cdf0e10cSrcweir } 1025cdf0e10cSrcweir if ( xMB != null ) 1026cdf0e10cSrcweir { 1027cdf0e10cSrcweir bResult = MainThreadDialogExecutor.Execute( xContext, xMB ); 1028cdf0e10cSrcweir bShown = true; 1029cdf0e10cSrcweir } 1030cdf0e10cSrcweir } 1031cdf0e10cSrcweir } 1032cdf0e10cSrcweir catch( Exception e ) 1033cdf0e10cSrcweir { 1034cdf0e10cSrcweir e.printStackTrace(); 1035cdf0e10cSrcweir } 1036cdf0e10cSrcweir finally 1037cdf0e10cSrcweir { 1038cdf0e10cSrcweir if ( xMB != null ) 1039cdf0e10cSrcweir Dispose( xMB ); 1040cdf0e10cSrcweir } 1041cdf0e10cSrcweir } 1042cdf0e10cSrcweir } 1043cdf0e10cSrcweir 1044cdf0e10cSrcweir return bResult; 1045cdf0e10cSrcweir } 1046cdf0e10cSrcweir AllowUnknownCert( XComponentContext xContext, String aURL )1047cdf0e10cSrcweir private static boolean AllowUnknownCert( XComponentContext xContext, String aURL ) 1048cdf0e10cSrcweir { 1049cdf0e10cSrcweir try 1050cdf0e10cSrcweir { 1051cdf0e10cSrcweir XNameAccess xNameAccess = GetConfigNameAccess( xContext, "org.openoffice.Office.Custom.WikiExtension/SpecialData" ); 1052cdf0e10cSrcweir if ( xNameAccess.hasByName( aURL ) ) 1053cdf0e10cSrcweir { 1054cdf0e10cSrcweir XNameAccess xEntry = (XNameAccess)UnoRuntime.queryInterface( XNameAccess.class, xNameAccess.getByName( aURL ) ); 1055cdf0e10cSrcweir if ( xEntry != null && xEntry.hasByName( "AllowUnknownCertificate" ) ) 1056cdf0e10cSrcweir return AnyConverter.toBoolean( xEntry.getByName( "AllowUnknownCertificate" ) ); 1057cdf0e10cSrcweir } 1058cdf0e10cSrcweir } 1059cdf0e10cSrcweir catch( Exception e ) 1060cdf0e10cSrcweir { 1061cdf0e10cSrcweir e.printStackTrace(); 1062cdf0e10cSrcweir } 1063cdf0e10cSrcweir 1064cdf0e10cSrcweir return false; 1065cdf0e10cSrcweir } 1066cdf0e10cSrcweir GetSpecialArgs( XComponentContext xContext, String aURL )1067cdf0e10cSrcweir private static String[][] GetSpecialArgs( XComponentContext xContext, String aURL ) 1068cdf0e10cSrcweir { 1069cdf0e10cSrcweir try 1070cdf0e10cSrcweir { 1071cdf0e10cSrcweir XNameAccess xNameAccess = GetConfigNameAccess( xContext, "org.openoffice.Office.Custom.WikiExtension/SpecialData" ); 1072cdf0e10cSrcweir if ( xNameAccess.hasByName( aURL ) ) 1073cdf0e10cSrcweir { 1074cdf0e10cSrcweir XNameAccess xEntry = (XNameAccess)UnoRuntime.queryInterface( XNameAccess.class, xNameAccess.getByName( aURL ) ); 1075cdf0e10cSrcweir if ( xEntry != null ) 1076cdf0e10cSrcweir { 1077cdf0e10cSrcweir XNameAccess xArgs = (XNameAccess)UnoRuntime.queryInterface( XNameAccess.class, xEntry.getByName( "AdditionalLoginArguments" ) ); 1078cdf0e10cSrcweir if ( xArgs != null ) 1079cdf0e10cSrcweir { 1080cdf0e10cSrcweir String[] pNames = xArgs.getElementNames(); 1081cdf0e10cSrcweir if ( pNames != null && pNames.length > 0 ) 1082cdf0e10cSrcweir { 1083cdf0e10cSrcweir String[][] pResult = new String[pNames.length][2]; 1084cdf0e10cSrcweir for ( int nInd = 0; nInd < pNames.length; nInd++ ) 1085cdf0e10cSrcweir { 1086cdf0e10cSrcweir XNameAccess xArgument = (XNameAccess)UnoRuntime.queryInterface( XNameAccess.class, xArgs.getByName( pNames[nInd] ) ); 1087cdf0e10cSrcweir if ( xArgument == null ) 1088cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException(); 1089cdf0e10cSrcweir 1090cdf0e10cSrcweir pResult[nInd][0] = pNames[nInd]; 1091cdf0e10cSrcweir pResult[nInd][1] = AnyConverter.toString( xArgument.getByName( "Value" ) ); 1092cdf0e10cSrcweir } 1093cdf0e10cSrcweir 1094cdf0e10cSrcweir return pResult; 1095cdf0e10cSrcweir } 1096cdf0e10cSrcweir } 1097cdf0e10cSrcweir } 1098cdf0e10cSrcweir } 1099cdf0e10cSrcweir } 1100cdf0e10cSrcweir catch( Exception e ) 1101cdf0e10cSrcweir { 1102cdf0e10cSrcweir e.printStackTrace(); 1103cdf0e10cSrcweir } 1104cdf0e10cSrcweir 1105cdf0e10cSrcweir return null; 1106cdf0e10cSrcweir } 1107cdf0e10cSrcweir AllowThreadUsage( XComponentContext xContext )1108cdf0e10cSrcweir protected static boolean AllowThreadUsage( XComponentContext xContext ) 1109cdf0e10cSrcweir { 1110cdf0e10cSrcweir if ( xContext != null ) 1111cdf0e10cSrcweir { 1112cdf0e10cSrcweir try 1113cdf0e10cSrcweir { 1114cdf0e10cSrcweir XMultiComponentFactory xFactory = xContext.getServiceManager(); 1115cdf0e10cSrcweir if ( xFactory == null ) 1116cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException(); 1117cdf0e10cSrcweir 1118cdf0e10cSrcweir Object oCheckCallback = xFactory.createInstanceWithContext( "com.sun.star.awt.AsyncCallback", xContext ); 1119cdf0e10cSrcweir return ( oCheckCallback != null ); 1120cdf0e10cSrcweir } 1121cdf0e10cSrcweir catch( Exception e ) 1122cdf0e10cSrcweir { 1123cdf0e10cSrcweir e.printStackTrace(); 1124cdf0e10cSrcweir } 1125cdf0e10cSrcweir } 1126cdf0e10cSrcweir 1127cdf0e10cSrcweir return false; 1128cdf0e10cSrcweir } 1129cdf0e10cSrcweir Dispose( Object oObject )1130cdf0e10cSrcweir public static void Dispose( Object oObject ) 1131cdf0e10cSrcweir { 1132cdf0e10cSrcweir if ( oObject != null ) 1133cdf0e10cSrcweir { 1134cdf0e10cSrcweir try 1135cdf0e10cSrcweir { 1136cdf0e10cSrcweir XComponent xComp = (XComponent)UnoRuntime.queryInterface( XComponent.class, oObject ); 1137cdf0e10cSrcweir if ( xComp != null ) 1138cdf0e10cSrcweir xComp.dispose(); 1139cdf0e10cSrcweir } 1140cdf0e10cSrcweir catch( Exception e ) 1141cdf0e10cSrcweir { 1142cdf0e10cSrcweir e.printStackTrace(); 1143cdf0e10cSrcweir } 1144cdf0e10cSrcweir } 1145cdf0e10cSrcweir } 1146cdf0e10cSrcweir } 1147cdf0e10cSrcweir 1148