Search in sources :

Example 1 with XBridgeFactory

use of com.sun.star.bridge.XBridgeFactory in project translationstudio8 by heartsome.

the class OPConnection method connect.

/**
	 * (non-Javadoc)
	 * @see net.heartsome.cat.converter.ooconnect.OPconnect#connect()
	 * @throws ConnectException
	 */
public void connect() throws ConnectException {
    try {
        XComponentContext localContext;
        localContext = Bootstrap.createInitialComponentContext(null);
        XMultiComponentFactory localServiceManager = localContext.getServiceManager();
        XConnector connector = (XConnector) UnoRuntime.queryInterface(XConnector.class, localServiceManager.createInstanceWithContext("com.sun.star.connection.Connector", //$NON-NLS-1$
        localContext));
        XConnection connection = connector.connect(strConnection);
        XBridgeFactory bridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(XBridgeFactory.class, //$NON-NLS-1$
        localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext));
        //$NON-NLS-1$ //$NON-NLS-2$
        bridge = bridgeFactory.createBridge("ms2ooBridge", "urp", connection, null);
        bgComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, bridge);
        // bgComponent.addEventListener(this);
        serviceMg = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class, bridge.getInstance(//$NON-NLS-1$
        "StarOffice.ServiceManager"));
        XPropertySet properties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, serviceMg);
        componentContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, properties.getPropertyValue(//$NON-NLS-1$
        "DefaultContext"));
        connected = true;
        if (connected) {
            //$NON-NLS-1$
            System.out.println("has already connected");
        } else {
            //$NON-NLS-1$
            System.out.println("connect to Openoffice fail,please check OpenOffice service that have to open");
        }
    } catch (NoConnectException connectException) {
        //$NON-NLS-1$ //$NON-NLS-2$
        throw new ConnectException(MessageFormat.format(Messages.getString("ooconnect.OPConnection.msg"), strConnection + ": " + connectException.getMessage()));
    } catch (Exception exception) {
        //$NON-NLS-1$
        throw new OPException(MessageFormat.format(Messages.getString("ooconnect.OPConnection.msg"), strConnection), exception);
    } catch (java.lang.Exception e) {
        if (Converter.DEBUG_MODE) {
            e.printStackTrace();
        }
    }
}
Also used : XPropertySet(com.sun.star.beans.XPropertySet) XComponentContext(com.sun.star.uno.XComponentContext) NoConnectException(com.sun.star.connection.NoConnectException) XConnection(com.sun.star.connection.XConnection) XBridgeFactory(com.sun.star.bridge.XBridgeFactory) XMultiComponentFactory(com.sun.star.lang.XMultiComponentFactory) Exception(com.sun.star.uno.Exception) ConnectException(java.net.ConnectException) NoConnectException(com.sun.star.connection.NoConnectException) XConnector(com.sun.star.connection.XConnector) ConnectException(java.net.ConnectException) NoConnectException(com.sun.star.connection.NoConnectException)

Aggregations

XPropertySet (com.sun.star.beans.XPropertySet)1 XBridgeFactory (com.sun.star.bridge.XBridgeFactory)1 NoConnectException (com.sun.star.connection.NoConnectException)1 XConnection (com.sun.star.connection.XConnection)1 XConnector (com.sun.star.connection.XConnector)1 XMultiComponentFactory (com.sun.star.lang.XMultiComponentFactory)1 Exception (com.sun.star.uno.Exception)1 XComponentContext (com.sun.star.uno.XComponentContext)1 ConnectException (java.net.ConnectException)1