com.sun.star.uno.Exception Java Examples

The following examples show how to use com.sun.star.uno.Exception. 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: DialogHelper.java    From libreoffice-starter-extension with MIT License 6 votes vote down vote up
/** Returns a URL to be used with XDialogProvider to create a dialog */
public static String convertToURL(XComponentContext xContext, File dialogFile) {
	String sURL = null;
	try {
		com.sun.star.ucb.XFileIdentifierConverter xFileConverter = (com.sun.star.ucb.XFileIdentifierConverter) UnoRuntime
				.queryInterface(com.sun.star.ucb.XFileIdentifierConverter.class, xContext.getServiceManager()
						.createInstanceWithContext("com.sun.star.ucb.FileContentProvider", xContext));
		sURL = xFileConverter.getFileURLFromSystemPath("", dialogFile.getAbsolutePath());
	} catch (com.sun.star.uno.Exception ex) {
		return null;
	}
	return sURL;
}
 
Example #2
Source File: DialogHelper.java    From libreoffice-starter-extension with MIT License 6 votes vote down vote up
public static void showMessageBox(XComponentContext context, XDialog dialog, MessageBoxType type, String sTitle, String sMessage) {
	XToolkit xToolkit;
	try {
		xToolkit = UnoRuntime.queryInterface(XToolkit.class,
					context.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", context));
	} catch (Exception e) {
		return;
	}
	XMessageBoxFactory xMessageBoxFactory = UnoRuntime.queryInterface(XMessageBoxFactory.class, xToolkit);
	XWindowPeer xParentWindowPeer = UnoRuntime.queryInterface(XWindowPeer.class, dialog);
       XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox(xParentWindowPeer, type,
       		com.sun.star.awt.MessageBoxButtons.BUTTONS_OK, sTitle, sMessage);
       if (xMessageBox == null)
       	return;
       
       xMessageBox.execute();
}
 
Example #3
Source File: DialogHelper.java    From libreoffice-starter-extension with MIT License 5 votes vote down vote up
/**
 * Create a dialog from an xdl file.
 *
 * @param xdlFile
 *            The filename in the `dialog` folder
 * @param context
 * @return XDialog
 */
public static XDialog createDialog(String xdlFile, XComponentContext context, XDialogEventHandler handler) {
	Object oDialogProvider;
	try {
		oDialogProvider = context.getServiceManager().createInstanceWithContext("com.sun.star.awt.DialogProvider2",
				context);
		XDialogProvider2 xDialogProv = (XDialogProvider2) UnoRuntime.queryInterface(XDialogProvider2.class,
				oDialogProvider);
		File dialogFile = FileHelper.getDialogFilePath(xdlFile, context);
		return xDialogProv.createDialogWithHandler(convertToURL(context, dialogFile), handler);
	} catch (Exception e) {
		return null;
	}
}
 
Example #4
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 #5
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#getFileContentProvider()
 * @return
 */
public XFileIdentifierConverter getFileContentProvider() {
	XFileIdentifierConverter xf = null;
	try {
		xf = (XFileIdentifierConverter) UnoRuntime.queryInterface(XFileIdentifierConverter.class,
				getService("com.sun.star.ucb.FileContentProvider")); //$NON-NLS-1$
	} catch (Exception e) {
		if (Converter.DEBUG_MODE) {
			e.printStackTrace();
		}
	}
	return xf;
}
 
Example #6
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 #7
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#getFileContentProvider()
 * @return
 */
public XFileIdentifierConverter getFileContentProvider() {
	XFileIdentifierConverter xf = null;
	try {
		xf = (XFileIdentifierConverter) UnoRuntime.queryInterface(XFileIdentifierConverter.class,
				getService("com.sun.star.ucb.FileContentProvider")); //$NON-NLS-1$
	} catch (Exception e) {
		if (Converter.DEBUG_MODE) {
			e.printStackTrace();
		}
	}
	return xf;
}
 
Example #8
Source File: OfficeResourceProvider.java    From yarg with Apache License 2.0 5 votes vote down vote up
public XDispatchHelper getXDispatchHelper() {
    try {
        return createXDispatchHelper();
    } catch (Exception e) {
        throw new OpenOfficeException("Unable to create Open office components.", e);
    }
}
 
Example #9
Source File: OfficeResourceProvider.java    From yarg with Apache License 2.0 5 votes vote down vote up
public XComponentLoader getXComponentLoader() {
    try {
        return as(XComponentLoader.class, createDesktop());
    } catch (Exception e) {
        throw new OpenOfficeException("Unable to create Open office components.", e);
    }
}
 
Example #10
Source File: OfficeResourceProvider.java    From yarg with Apache License 2.0 4 votes vote down vote up
public OfficeResourceProvider(XComponentContext xComponentContext, OfficeIntegration officeIntegration) throws Exception {
    this.xComponentContext = xComponentContext;
    this.officeIntegration = officeIntegration;
}
 
Example #11
Source File: OfficeResourceProvider.java    From yarg with Apache License 2.0 4 votes vote down vote up
protected XDispatchHelper createXDispatchHelper() throws Exception {
    Object o = xComponentContext.getServiceManager().createInstanceWithContext(
            "com.sun.star.frame.DispatchHelper", xComponentContext);
    return as(XDispatchHelper.class, o);
}
 
Example #12
Source File: OfficeResourceProvider.java    From yarg with Apache License 2.0 4 votes vote down vote up
protected XDesktop createDesktop() throws com.sun.star.uno.Exception {
    Object o = xComponentContext.getServiceManager().createInstanceWithContext(
            "com.sun.star.frame.Desktop", xComponentContext);
    return as(XDesktop.class, o);
}
 
Example #13
Source File: OPConnection.java    From translationstudio8 with GNU General Public License v2.0 votes vote down vote up
/**
 * Gets the service.
 * @param className
 *            the class name
 * @return the service
 * @throws Exception
 *             the exception
 */
private Object getService(String className) throws Exception {

	return serviceMg.createInstanceWithContext(className, componentContext);

}
 
Example #14
Source File: OPConnection.java    From tmxeditor8 with GNU General Public License v2.0 votes vote down vote up
/**
 * Gets the service.
 * @param className
 *            the class name
 * @return the service
 * @throws Exception
 *             the exception
 */
private Object getService(String className) throws Exception {

	return serviceMg.createInstanceWithContext(className, componentContext);

}