diff options
Diffstat (limited to 'bean/com/sun/star/beans/LocalOfficeConnection.java')
-rw-r--r-- | bean/com/sun/star/beans/LocalOfficeConnection.java | 188 |
1 files changed, 94 insertions, 94 deletions
diff --git a/bean/com/sun/star/beans/LocalOfficeConnection.java b/bean/com/sun/star/beans/LocalOfficeConnection.java index 11283066cc34..cb2d61f0fbea 100644 --- a/bean/com/sun/star/beans/LocalOfficeConnection.java +++ b/bean/com/sun/star/beans/LocalOfficeConnection.java @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -48,36 +48,36 @@ import com.sun.star.lib.util.NativeLibraryLoader; public class LocalOfficeConnection implements OfficeConnection { - public static final String OFFICE_APP_NAME = "soffice"; - public static final String OFFICE_LIB_NAME = "officebean"; - public static final String OFFICE_ID_SUFFIX = "_Office"; - - private Process mProcess; - private ContainerFactory mContainerFactory; - private XComponentContext mContext; - - private String mURL; - private String mProgramPath; - private String mConnType; - private String mPipe; - private String mPort; - private String mProtocol; - private String mInitialObject; - - private List mComponents = new Vector(); - + public static final String OFFICE_APP_NAME = "soffice"; + public static final String OFFICE_LIB_NAME = "officebean"; + public static final String OFFICE_ID_SUFFIX = "_Office"; + + private Process mProcess; + private ContainerFactory mContainerFactory; + private XComponentContext mContext; + + private String mURL; + private String mProgramPath; + private String mConnType; + private String mPipe; + private String mPort; + private String mProtocol; + private String mInitialObject; + + private List mComponents = new Vector(); + /** * Constructor. - * Sets up paths to the office application and native libraries if - * values are available in <code>OFFICE_PROP_FILE</code> in the user + * Sets up paths to the office application and native libraries if + * values are available in <code>OFFICE_PROP_FILE</code> in the user * home directory.<br /> - * "com.sun.star.beans.path" - the office application directory;<br/> + * "com.sun.star.beans.path" - the office application directory;<br/> * "com.sun.star.beans.libpath" - native libraries directory. */ public LocalOfficeConnection() - { + { // init member vars - try + try { setUnoUrl( "uno:pipe,name=" + getPipeName() + ";urp;StarOffice.ServiceManager" ); } @@ -92,7 +92,7 @@ public class LocalOfficeConnection /** * Sets a connection URL. - * This implementation accepts a UNO URL with following format:<br /> + * This implementation accepts a UNO URL with following format:<br /> * <pre> * url := uno:localoffice[,<params>];urp;StarOffice.ServiceManager * params := <path>[,<pipe>] @@ -107,7 +107,7 @@ public class LocalOfficeConnection public void setUnoUrl(String url) throws java.net.MalformedURLException { - mURL = null; + mURL = null; String prefix = "uno:localoffice"; if ( url.startsWith(prefix) ) @@ -130,25 +130,25 @@ public class LocalOfficeConnection "Invalid UNO connection URL."); } } - mURL = url; + mURL = url; } /** * Sets an AWT container catory. * - * @param containerFactory This is a application provided AWT container - * factory. + * @param containerFactory This is a application provided AWT container + * factory. */ public void setContainerFactory(ContainerFactory containerFactory) { - mContainerFactory = containerFactory; + mContainerFactory = containerFactory; } /** * Retrives the UNO component context. - * Establishes a connection if necessary and initialises the + * Establishes a connection if necessary and initialises the * UNO service manager if it has not already been initialised. - * This method can return <code>null</code> if it fails to connect + * This method can return <code>null</code> if it fails to connect * to the office application. * * @return The office UNO component context. @@ -162,8 +162,8 @@ public class LocalOfficeConnection /** * Creates an office window. - * The window is either a sub-class of java.awt.Canvas (local) or - * java.awt.Container (RVP). + * The window is either a sub-class of java.awt.Canvas (local) or + * java.awt.Container (RVP). * * @param container This is an AWT container. * @return The office window instance. @@ -201,7 +201,7 @@ public class LocalOfficeConnection } /** - * Removes an event listener from the listener list. + * Removes an event listener from the listener list. * * @param listener is a listener object. */ @@ -215,15 +215,15 @@ public class LocalOfficeConnection */ private XComponentContext connect() { - try + try { // create default local component context XComponentContext xLocalContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null); - + // initial serviceManager XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager(); - + // create a urlresolver Object urlResolver = xLocalServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", xLocalContext ); @@ -234,7 +234,7 @@ public class LocalOfficeConnection // try to connect to soffice Object aInitialObject = null; - try + try { aInitialObject = xUrlResolver.resolve( mURL ); } @@ -243,12 +243,12 @@ public class LocalOfficeConnection // launch soffice OfficeService aSOffice = new OfficeService(); aSOffice.startupService(); - + // wait until soffice is started long nMaxMillis = System.currentTimeMillis() + 1000*aSOffice.getStartupTime(); while ( aInitialObject == null ) { - try + try { // try to connect to soffice Thread.currentThread().sleep( 500 ); @@ -263,16 +263,16 @@ public class LocalOfficeConnection } } } - finally - { + finally + { } - + // XComponentContext if( null != aInitialObject ) { XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, aInitialObject); - Object xContext = xPropertySet.getPropertyValue("DefaultContext"); + Object xContext = xPropertySet.getPropertyValue("DefaultContext"); XComponentContext xComponentContext = (XComponentContext) UnoRuntime.queryInterface( XComponentContext.class, xContext); return xComponentContext; @@ -320,14 +320,14 @@ public class LocalOfficeConnection */ private String getProgramPath() { - if (mProgramPath == null) + if (mProgramPath == null) { // determine name of executable soffice String aExec = OFFICE_APP_NAME; // default for UNIX String aOS = System.getProperty("os.name"); // running on Windows? - if (aOS.startsWith("Windows")) + if (aOS.startsWith("Windows")) aExec = OFFICE_APP_NAME + ".exe"; // add other non-UNIX operating systems here @@ -349,7 +349,7 @@ public class LocalOfficeConnection /** * Parses a connection URL. - * This method accepts a UNO URL with following format:<br /> + * This method accepts a UNO URL with following format:<br /> * <pre> * url := uno:localoffice[,<params>];urp;StarOffice.NamingService * params := <path>[,<pipe>] @@ -361,64 +361,64 @@ public class LocalOfficeConnection * * <h4>Examples</h4> * <ul> - * <li>"uno:localoffice,pipe=xyz_Office,path=/opt/openoffice11/program;urp;StarOffice.ServiceManager"; - * <li>"uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager"; + * <li>"uno:localoffice,pipe=xyz_Office,path=/opt/openoffice11/program;urp;StarOffice.ServiceManager"; + * <li>"uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager"; * </ul> * * @param url This is UNO URL which describes the type of a connection. - * @exception java.net.MalformedURLException when inappropreate URL was - * provided. + * @exception java.net.MalformedURLException when inappropreate URL was + * provided. */ private void parseUnoUrlWithOfficePath(String url, String prefix) throws java.net.MalformedURLException { // Extruct parameters. - int idx = url.indexOf(";urp;StarOffice.NamingService"); + int idx = url.indexOf(";urp;StarOffice.NamingService"); if (idx < 0) throw new java.net.MalformedURLException( "Invalid UNO connection URL."); - String params = url.substring(prefix.length(), idx + 1); + String params = url.substring(prefix.length(), idx + 1); // Parse parameters. - String name = null; - String path = null; - String pipe = null; - char ch; - int state = 0; - StringBuffer buffer = new StringBuffer(); + String name = null; + String path = null; + String pipe = null; + char ch; + int state = 0; + StringBuffer buffer = new StringBuffer(); for(idx = 0; idx < params.length(); idx += 1) { - ch = params.charAt(idx); + ch = params.charAt(idx); switch (state) { - case 0: // initial state + case 0: // initial state switch(ch) { case ',': buffer.delete(0, buffer.length()); - state = 1; + state = 1; break; case ';': - state = 7; + state = 7; break; default: buffer.delete(0, buffer.length()); buffer.append(ch); - state = 1; + state = 1; break; } break; - case 1: // parameter name + case 1: // parameter name switch(ch) { case ' ': case '=': - name = buffer.toString(); - state = (ch == ' ')? 2: 3; + name = buffer.toString(); + state = (ch == ' ')? 2: 3; break; case ',': case ';': - state = -6; // error: invalid name + state = -6; // error: invalid name break; default: @@ -427,22 +427,22 @@ public class LocalOfficeConnection } break; - case 2: // equal between the name and the value + case 2: // equal between the name and the value switch(ch) { case '=': - state = 3; + state = 3; break; case ' ': break; default: - state = -1; // error: missing '=' + state = -1; // error: missing '=' break; } break; - case 3: // value leading spaces + case 3: // value leading spaces switch(ch) { case ' ': break; @@ -450,30 +450,30 @@ public class LocalOfficeConnection default: buffer.delete(0, buffer.length()); buffer.append(ch); - state = 4; + state = 4; break; } break; - case 4: // value + case 4: // value switch(ch) { case ' ': case ',': case ';': - idx -= 1; // put back the last read character - state = 5; + idx -= 1; // put back the last read character + state = 5; if (name.equals("path")) { if (path == null) - path = buffer.toString(); + path = buffer.toString(); else - state = -3; // error: more then one 'path' + state = -3; // error: more then one 'path' } else if (name.equals("pipe")) { if (pipe == null) - pipe = buffer.toString(); + pipe = buffer.toString(); else - state = -4; // error: more then one 'pipe' + state = -4; // error: more then one 'pipe' } else - state = -2; // error: unknown parameter + state = -2; // error: unknown parameter buffer.delete(0, buffer.length()); break; @@ -483,26 +483,26 @@ public class LocalOfficeConnection } break; - case 5: // a delimeter after the value + case 5: // a delimeter after the value switch(ch) { case ' ': break; case ',': - state = 6; + state = 6; break; case ';': - state = 7; + state = 7; break; default: - state = -5; // error: ' ' inside the value + state = -5; // error: ' ' inside the value break; } break; - case 6: // leading spaces before next parameter name + case 6: // leading spaces before next parameter name switch(ch) { case ' ': break; @@ -510,7 +510,7 @@ public class LocalOfficeConnection default: buffer.delete(0, buffer.length()); buffer.append(ch); - state = 1; + state = 1; break; } break; @@ -532,7 +532,7 @@ public class LocalOfficeConnection } /* replaces each substring aSearch in aString by aReplace. - + StringBuffer.replaceAll() is not avaialable in Java 1.3.x. */ private static String replaceAll(String aString, String aSearch, String aReplace ) @@ -541,7 +541,7 @@ public class LocalOfficeConnection int nPos = aString.length(); int nOfs = aSearch.length(); - + while ( ( nPos = aString.lastIndexOf( aSearch, nPos - 1 ) ) > -1 ) aBuffer.replace( nPos, nPos+nOfs, aReplace ); @@ -558,8 +558,8 @@ public class LocalOfficeConnection aPipeName = replaceAll( aPipeName, "_", "%B7" ); return replaceAll( replaceAll( java.net.URLEncoder.encode(aPipeName), "\\+", "%20" ), "%", "_" ); } - - /** + + /** * @para This is an implementation of the native office service. * @deprecated */ @@ -572,8 +572,8 @@ public class LocalOfficeConnection * @return The identifier of the office service. */ public String getIdentifier() - { - if ( mPipe == null) + { + if ( mPipe == null) return getPipeName(); else return mPipe; |