com.sun.star.comp.helper.Bootstrap Java Examples

The following examples show how to use com.sun.star.comp.helper.Bootstrap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OOPresentation.java    From Quelea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Connect to an office, if no office is running a new instance is
 * started. A new connection is established and the service manger from
 * the running office is returned.
 *
 * @param path the path to the openoffice install.
 */
private static XComponentContext connect(String path) throws BootstrapException, Exception {
    File progPath = new File(path, "program");
    xOfficeContext = BootstrapSocketConnector.bootstrap(progPath.getAbsolutePath());
    XComponentContext localContext = Bootstrap.createInitialComponentContext(null);
    XMultiComponentFactory localServiceManager = localContext.getServiceManager();
    XConnector connector = UnoRuntime.queryInterface(XConnector.class,
            localServiceManager.createInstanceWithContext("com.sun.star.connection.Connector",
                    localContext));
    connection = connector.connect(RUN_ARGS);
    XBridgeFactory bridgeFactory = UnoRuntime.queryInterface(XBridgeFactory.class,
            localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext));
    bridge = bridgeFactory.createBridge("", "urp", connection, null);
    bridgeComponent = UnoRuntime.queryInterface(XComponent.class, bridge);
    bridgeComponent.addEventListener(new com.sun.star.lang.XEventListener() {
        @Override
        public void disposing(EventObject eo) {
        }
    });
    return xOfficeContext;

}
 
Example #2
Source File: LocalOfficeConnectionGhost.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Establishes the connection to the office.
 * 
 * @return constructed component context
 * 
 * @author Andreas Bröker
 */
private XComponentContext connect() {
	try {
		if (officeProgressMonitor != null)
			officeProgressMonitor
					.beginSubTask(Messages
							.getString("LocalOfficeConnectionGhost_monitor_constructing_initial_context_message")); //$NON-NLS-1$

		XComponentContext xContext = null;
		if (officeArguments != null && officeArguments.length > 0)
			xContext = Bootstrap.bootstrap(officeArguments);
		else
			xContext = Bootstrap.bootstrap();
		return xContext;
	} catch (java.lang.Exception exception) {
		System.out.println("java.lang.Exception: "); //$NON-NLS-1$
		System.out.println(exception);
		exception.printStackTrace();
		System.out.println("--- end."); //$NON-NLS-1$
		throw new com.sun.star.uno.RuntimeException(exception.toString());
	}
}
 
Example #3
Source File: RemoteOfficeConnection.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Opens connection to OpenOffice.org.
 * 
 * @return information whether the connection is available
 * 
 * @throws Exception if any error occurs
 */
public boolean openConnection() throws Exception {
  String unoUrl = "uno:socket,host=" + host + ",port=" + port +";urp;StarOffice.ServiceManager";
  XComponentContext xLocalContext = Bootstrap.createInitialComponentContext(null);
  Object connector = xLocalContext.getServiceManager().createInstanceWithContext("com.sun.star.connection.Connector", xLocalContext);
  XConnector xConnector = (XConnector) UnoRuntime.queryInterface(XConnector.class, connector);
  
  String url[] = parseUnoUrl(unoUrl);
  if (null == url) {
    throw new com.sun.star.uno.Exception("Couldn't parse UNO URL "+ unoUrl);
  }
  
  XConnection connection = xConnector.connect(url[0]);
  Object bridgeFactory = xLocalContext.getServiceManager().createInstanceWithContext("com.sun.star.bridge.BridgeFactory", xLocalContext);
  XBridgeFactory xBridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(XBridgeFactory.class, bridgeFactory);
  xBridge = xBridgeFactory.createBridge("", url[1], connection ,null);
  bridgeFactory = xBridge.getInstance(url[2]);
  xMultiComponentFactory = (XMultiComponentFactory)UnoRuntime.queryInterface(XMultiComponentFactory.class, bridgeFactory);
  XPropertySet xProperySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xMultiComponentFactory);
  Object remoteContext = xProperySet.getPropertyValue("DefaultContext");
  xRemoteContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, remoteContext);
  xMultiServiceFactory = (XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xMultiComponentFactory);
  isConnectionEstablished = true;
  return true;      
}
 
Example #4
Source File: OfficeConnection.java    From kkFileViewOfficeEdit with Apache License 2.0 5 votes vote down vote up
public void connect() throws ConnectException {
    logger.fine(String.format("connecting with connectString '%s'", unoUrl));
    try {
        XComponentContext localContext = Bootstrap.createInitialComponentContext(null);
        XMultiComponentFactory localServiceManager = localContext.getServiceManager();
        XConnector connector = OfficeUtils.cast(XConnector.class, localServiceManager.createInstanceWithContext("com.sun.star.connection.Connector", localContext));
        XConnection connection = connector.connect(unoUrl.getConnectString());
        XBridgeFactory bridgeFactory = OfficeUtils.cast(XBridgeFactory.class, localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext));
        String bridgeName = "jodconverter_" + bridgeIndex.getAndIncrement();
        XBridge bridge = bridgeFactory.createBridge(bridgeName, "urp", connection, null);
        bridgeComponent = OfficeUtils.cast(XComponent.class, bridge);
        bridgeComponent.addEventListener(bridgeListener);
        serviceManager = OfficeUtils.cast(XMultiComponentFactory.class, bridge.getInstance("StarOffice.ServiceManager"));
        XPropertySet properties = OfficeUtils.cast(XPropertySet.class, serviceManager);
        componentContext = OfficeUtils.cast(XComponentContext.class, properties.getPropertyValue("DefaultContext"));
        connected = true;
        logger.info(String.format("connected: '%s'", unoUrl));
        OfficeConnectionEvent connectionEvent = new OfficeConnectionEvent(this);
        for (OfficeConnectionEventListener listener : connectionEventListeners) {
            listener.connected(connectionEvent);
        }
    } catch (NoConnectException connectException) {
        throw new ConnectException(String.format("connection failed: '%s'; %s", unoUrl, connectException.getMessage()));
    } catch (Exception exception) {
        throw new OfficeException("connection failed: "+ unoUrl, exception);
    }
}
 
Example #5
Source File: OfficeConnection.java    From kkFileView with Apache License 2.0 5 votes vote down vote up
public void connect() throws ConnectException {
    logger.fine(String.format("connecting with connectString '%s'", unoUrl));
    try {
        XComponentContext localContext = Bootstrap.createInitialComponentContext(null);
        XMultiComponentFactory localServiceManager = localContext.getServiceManager();
        XConnector connector = OfficeUtils.cast(XConnector.class, localServiceManager.createInstanceWithContext("com.sun.star.connection.Connector", localContext));
        XConnection connection = connector.connect(unoUrl.getConnectString());
        XBridgeFactory bridgeFactory = OfficeUtils.cast(XBridgeFactory.class, localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext));
        String bridgeName = "jodconverter_" + bridgeIndex.getAndIncrement();
        XBridge bridge = bridgeFactory.createBridge(bridgeName, "urp", connection, null);
        bridgeComponent = OfficeUtils.cast(XComponent.class, bridge);
        bridgeComponent.addEventListener(bridgeListener);
        serviceManager = OfficeUtils.cast(XMultiComponentFactory.class, bridge.getInstance("StarOffice.ServiceManager"));
        XPropertySet properties = OfficeUtils.cast(XPropertySet.class, serviceManager);
        componentContext = OfficeUtils.cast(XComponentContext.class, properties.getPropertyValue("DefaultContext"));
        connected = true;
        logger.info(String.format("connected: '%s'", unoUrl));
        OfficeConnectionEvent connectionEvent = new OfficeConnectionEvent(this);
        for (OfficeConnectionEventListener listener : connectionEventListeners) {
            listener.connected(connectionEvent);
        }
    } catch (NoConnectException connectException) {
        throw new ConnectException(String.format("connection failed: '%s'; %s", unoUrl, connectException.getMessage()));
    } catch (Exception exception) {
        throw new OfficeException("connection failed: "+ unoUrl, exception);
    }
}
 
Example #6
Source File: OfficeConnection.java    From wenku with MIT License 5 votes vote down vote up
public void connect() throws ConnectException {
    logger.fine(String.format("connecting with connectString '%s'", unoUrl));
    try {
        XComponentContext localContext = Bootstrap.createInitialComponentContext(null);
        XMultiComponentFactory localServiceManager = localContext.getServiceManager();
        XConnector connector = OfficeUtils.cast(XConnector.class, localServiceManager.createInstanceWithContext("com.sun.star.connection.Connector", localContext));
        XConnection connection = connector.connect(unoUrl.getConnectString());
        XBridgeFactory bridgeFactory = OfficeUtils.cast(XBridgeFactory.class, localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext));
        String bridgeName = "jodconverter_" + bridgeIndex.getAndIncrement();
        XBridge bridge = bridgeFactory.createBridge(bridgeName, "urp", connection, null);
        bridgeComponent = OfficeUtils.cast(XComponent.class, bridge);
        bridgeComponent.addEventListener(bridgeListener);
        serviceManager = OfficeUtils.cast(XMultiComponentFactory.class, bridge.getInstance("StarOffice.ServiceManager"));
        XPropertySet properties = OfficeUtils.cast(XPropertySet.class, serviceManager);
        componentContext = OfficeUtils.cast(XComponentContext.class, properties.getPropertyValue("DefaultContext"));
        connected = true;
        logger.info(String.format("connected: '%s'", unoUrl));
        OfficeConnectionEvent connectionEvent = new OfficeConnectionEvent(this);
        for (OfficeConnectionEventListener listener : connectionEventListeners) {
            listener.connected(connectionEvent);
        }
    } catch (NoConnectException connectException) {
        throw new ConnectException(String.format("connection failed: '%s'; %s", unoUrl, connectException.getMessage()));
    } catch (Exception exception) {
        throw new OfficeException("connection failed: "+ unoUrl, exception);
    }
}
 
Example #7
Source File: OPConnection.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * (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", localContext)); //$NON-NLS-1$
		XConnection connection = connector.connect(strConnection);
		XBridgeFactory bridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(XBridgeFactory.class,
				localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext)); //$NON-NLS-1$
		bridge = bridgeFactory.createBridge("ms2ooBridge", "urp", connection, null); //$NON-NLS-1$ //$NON-NLS-2$
		bgComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, bridge);
		// bgComponent.addEventListener(this);
		serviceMg = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class, bridge
				.getInstance("StarOffice.ServiceManager")); //$NON-NLS-1$
		XPropertySet properties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, serviceMg);
		componentContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, properties
				.getPropertyValue("DefaultContext")); //$NON-NLS-1$
		connected = true;
		if (connected) {
			System.out.println("has already connected"); //$NON-NLS-1$
		} else {
			System.out.println("connect to Openoffice fail,please check OpenOffice service that have to open"); //$NON-NLS-1$
		}

	} catch (NoConnectException connectException) {
		throw new ConnectException(MessageFormat.format(Messages.getString("ooconnect.OPConnection.msg"), strConnection + ": " + connectException.getMessage())); //$NON-NLS-1$ //$NON-NLS-2$
	} catch (Exception exception) {
		throw new OPException(MessageFormat.format(Messages.getString("ooconnect.OPConnection.msg"), strConnection), exception); //$NON-NLS-1$
	} catch (java.lang.Exception e) {
		if (Converter.DEBUG_MODE) {
			e.printStackTrace();
		}
	}
}
 
Example #8
Source File: OPConnection.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * (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", localContext)); //$NON-NLS-1$
		XConnection connection = connector.connect(strConnection);
		XBridgeFactory bridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(XBridgeFactory.class,
				localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext)); //$NON-NLS-1$
		bridge = bridgeFactory.createBridge("ms2ooBridge", "urp", connection, null); //$NON-NLS-1$ //$NON-NLS-2$
		bgComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, bridge);
		// bgComponent.addEventListener(this);
		serviceMg = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class, bridge
				.getInstance("StarOffice.ServiceManager")); //$NON-NLS-1$
		XPropertySet properties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, serviceMg);
		componentContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, properties
				.getPropertyValue("DefaultContext")); //$NON-NLS-1$
		connected = true;
		if (connected) {
			System.out.println("has already connected"); //$NON-NLS-1$
		} else {
			System.out.println("connect to Openoffice fail,please check OpenOffice service that have to open"); //$NON-NLS-1$
		}

	} catch (NoConnectException connectException) {
		throw new ConnectException(MessageFormat.format(Messages.getString("ooconnect.OPConnection.msg"), strConnection + ": " + connectException.getMessage())); //$NON-NLS-1$ //$NON-NLS-2$
	} catch (Exception exception) {
		throw new OPException(MessageFormat.format(Messages.getString("ooconnect.OPConnection.msg"), strConnection), exception); //$NON-NLS-1$
	} catch (java.lang.Exception e) {
		if (Converter.DEBUG_MODE) {
			e.printStackTrace();
		}
	}
}
 
Example #9
Source File: BootstrapConnector.java    From yarg with Apache License 2.0 5 votes vote down vote up
/**
 * Create default local component context.
 * 
 * @return      The default local component context
 */
protected XComponentContext getLocalContext() throws BootstrapException, Exception {

    XComponentContext xLocalContext = Bootstrap.createInitialComponentContext(null);
    if (xLocalContext == null) {
        throw new BootstrapException("no local component context!");
    }
    return xLocalContext;
}