Holger's Java API

## com.antelmann.ooffice
Class OfficeConnector

    java.lang.Object
      com.antelmann.ooffice.OfficeConnector

    @ThirdParty(value="using OpenOffice libraries")
    public class OfficeConnector

extends Object

provides methods to setup the context for OpenOffice connections for all other classes in this package.

Since:
  14.08.2009, 01:44:11
Author:
  Holger Antelmann

Method Summary
`static com.sun.star.uno.XComponentContext` `createRemoteContext(String host)`
`static com.sun.star.uno.XComponentContext` `createRemoteContext(String host, int port)`
`static com.sun.star.uno.XComponentContext` `createSocketContext(File ooProgramDir)`
`static com.sun.star.uno.XComponentContext` `createSocketContext(File ooProgramDir, long timeout)` transparently creates a local office process (if required), drains its output and connects to it
`static File` `findOfficeDir()`
`static com.sun.star.uno.XComponentContext` `getContext()` returns the cached context maintained in this class.
`static com.sun.star.uno.XComponentContext` `getCurrentContext()` may return null if not yet initialized
`static com.sun.star.frame.XDesktop` `getDesktop()`
`static File` `getOfficeProgramPath()` if non-null, it is used to set the context via sockets; if null, the standard pipe mechanism is used.
`static String` `getStandardAcceptOptions(String host, int port)`
`static String[]` `getStandardProcessOptions()`
`static boolean` `isContextAvailable()` determines whether a context has already been set or not
`static void` `setContext(com.sun.star.uno.XComponentContext context)` allows to manually set the context; calls `terminate()` before the new context is set
`static void` `setContextFactory(Factory<com.sun.star.uno.XComponentContext> factory)` allows to provide a custom way to initialize the context used in `getContext()`
`static void` `setOfficeProgramPath(File officeProgramPath)` sets the program path for OpenOffice and determines whether (in case of a non-null value) the socket connection method is to be used upon creating the context, or the standard pipe mechanism.
`static void` `setSocketContext(File ooProgramDir)` creates a socket context on the given path and directly sets the same to be available upon subsequent calls to `getContext()`
`static Process` `startOfficeProcess(File ooProgramFolder)`
`static Process` `startOfficeProcess(File ooProgramFolder, String acceptOption)` uses the standard options; see `getStandardProcessOptions()`
`static Process` `startOfficeProcess(File ooProgramFolder, String acceptOption, String[] options)`
`static boolean` `terminate()` terminates all current OpenOffice related desktop activities (if the context has been set before); all OpenOffice windows (including those started separately by a user) will be closed

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### setContext

    public static void setContext(com.sun.star.uno.XComponentContext context)

  allows to manually set the context; calls `terminate()` before the new context is set

  See Also:
    `createRemoteContext(String)`, `createSocketContext(File)`

### setContextFactory

    public static void setContextFactory(Factory<com.sun.star.uno.XComponentContext> factory)

  allows to provide a custom way to initialize the context used in `getContext()`

### findOfficeDir

    public static File findOfficeDir()

### setSocketContext

    public static void setSocketContext(File ooProgramDir)
                                 throws OfficeException,
                                        IOException

  creates a socket context on the given path and directly sets the same to be available upon subsequent calls to `getContext()`

  Throws:
    `OfficeException`
    `IOException`
  See Also:
    `createSocketContext(File)`

### isContextAvailable

    public static boolean isContextAvailable()

  determines whether a context has already been set or not

### getOfficeProgramPath

    public static File getOfficeProgramPath()

  if non-null, it is used to set the context via sockets; if null, the standard pipe mechanism is used.

  See Also:
    `getContext()`, `setOfficeProgramPath(File)`

### setOfficeProgramPath

    public static void setOfficeProgramPath(File officeProgramPath)

  sets the program path for OpenOffice and determines whether (in case of a non-null value) the socket connection method is to be used upon creating the context, or the standard pipe mechanism.

  Parameters:
    `officeProgramPath` - the directory that contains the soffice executable within the OpenOffice directory tree
  See Also:
    `getOfficeProgramPath()`, `getContext()`

### getCurrentContext

    public static com.sun.star.uno.XComponentContext getCurrentContext()

  may return null if not yet initialized

### getContext

    public static com.sun.star.uno.XComponentContext getContext()
                                                         throws OfficeException

  returns the cached context maintained in this class. Upon first call it is initialized via the standard pipe mechanism if the officeProgramPath is null, or via sockets using the path given. If a factory is given, it will be used first (a factory could allow to always connect remotely to another server). This method will always be used by classes of this package to obtain a context.

  Throws:
    `OfficeException`
  See Also:
    `setContextFactory(Factory)`, `setContext(XComponentContext)`, `getOfficeProgramPath()`, `isContextAvailable()`

### createRemoteContext

    public static com.sun.star.uno.XComponentContext createRemoteContext(String host)
                                                                  throws OfficeException

  Throws:
    `OfficeException`

### createRemoteContext

    public static com.sun.star.uno.XComponentContext createRemoteContext(String host,
                                                                         int port)
                                                                  throws OfficeException

  Throws:
    `OfficeException`

### createSocketContext

    public static com.sun.star.uno.XComponentContext createSocketContext(File ooProgramDir)
                                                                  throws OfficeException,
                                                                         IOException

  Throws:
    `OfficeException`
    `IOException`

### createSocketContext

    public static com.sun.star.uno.XComponentContext createSocketContext(File ooProgramDir,
                                                                         long timeout)
                                                                  throws OfficeException,
                                                                         IOException

  transparently creates a local office process (if required), drains its output and connects to it

  Throws:
    `OfficeException`
    `IOException`

### getStandardProcessOptions

    public static String[] getStandardProcessOptions()

### getStandardAcceptOptions

    public static String getStandardAcceptOptions(String host,
                                                  int port)

### startOfficeProcess

    public static Process startOfficeProcess(File ooProgramFolder)
                                      throws OfficeException,
                                             IOException

  Throws:
    `OfficeException`
    `IOException`

### startOfficeProcess

    public static Process startOfficeProcess(File ooProgramFolder,
                                             String acceptOption)
                                      throws OfficeException,
                                             IOException

  uses the standard options; see `getStandardProcessOptions()`

  Throws:
    `OfficeException`
    `IOException`

### startOfficeProcess

    public static Process startOfficeProcess(File ooProgramFolder,
                                             String acceptOption,
                                             String[] options)
                                      throws OfficeException,
                                             IOException,
                                             IllegalArgumentException

  Throws:
    `OfficeException`
    `IOException`
    `IllegalArgumentException`

### getDesktop

    public static com.sun.star.frame.XDesktop getDesktop()
                                                  throws OfficeException

  Throws:
    `OfficeException`

### terminate

    public static boolean terminate()

  terminates all current OpenOffice related desktop activities (if the context has been set before); all OpenOffice windows (including those started separately by a user) will be closed

  Returns:
    true only if the terminate() method of XDesktop was actually called

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads