Search in sources :

Example 1 with BootstrapException

use of com.sun.star.comp.helper.BootstrapException in project jabref by JabRef.

the class OOBibBase method simpleBootstrap.

private XDesktop simpleBootstrap(String pathToExecutable) throws IllegalAccessException, InvocationTargetException, BootstrapException, CreationException, IOException {
    ClassLoader loader = ClassLoader.getSystemClassLoader();
    if (loader instanceof URLClassLoader) {
        URLClassLoader cl = (URLClassLoader) loader;
        Class<URLClassLoader> sysclass = URLClassLoader.class;
        try {
            Method method = sysclass.getDeclaredMethod("addURL", URL.class);
            method.setAccessible(true);
            method.invoke(cl, new File(pathToExecutable).toURI().toURL());
        } catch (SecurityException | NoSuchMethodException | MalformedURLException t) {
            LOGGER.error("Error, could not add URL to system classloader", t);
            cl.close();
            throw new IOException("Error, could not add URL to system classloader", t);
        }
    } else {
        LOGGER.error("Error occured, URLClassLoader expected but " + loader.getClass() + " received. Could not continue.");
    }
    //Get the office component context:
    XComponentContext xContext = Bootstrap.bootstrap();
    //Get the office service manager:
    XMultiComponentFactory xServiceManager = xContext.getServiceManager();
    //Create the desktop, which is the root frame of the
    //hierarchy of frames that contain viewable components:
    Object desktop;
    try {
        desktop = xServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
    } catch (Exception e) {
        throw new CreationException(e.getMessage());
    }
    XDesktop resultDesktop = UnoRuntime.queryInterface(XDesktop.class, desktop);
    UnoRuntime.queryInterface(XComponentLoader.class, desktop);
    return resultDesktop;
}
Also used : MalformedURLException(java.net.MalformedURLException) Method(java.lang.reflect.Method) IOException(java.io.IOException) XDesktop(com.sun.star.frame.XDesktop) XMultiComponentFactory(com.sun.star.lang.XMultiComponentFactory) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) PropertyVetoException(com.sun.star.beans.PropertyVetoException) IllegalArgumentException(com.sun.star.lang.IllegalArgumentException) IllegalTypeException(com.sun.star.beans.IllegalTypeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WrappedTargetException(com.sun.star.lang.WrappedTargetException) BootstrapException(com.sun.star.comp.helper.BootstrapException) DisposedException(com.sun.star.lang.DisposedException) NoSuchElementException(com.sun.star.container.NoSuchElementException) MalformedURLException(java.net.MalformedURLException) UndefinedParagraphFormatException(org.jabref.logic.openoffice.UndefinedParagraphFormatException) IOException(java.io.IOException) NotRemoveableException(com.sun.star.beans.NotRemoveableException) PropertyExistException(com.sun.star.beans.PropertyExistException) XComponentContext(com.sun.star.uno.XComponentContext) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File)

Aggregations

IllegalTypeException (com.sun.star.beans.IllegalTypeException)1 NotRemoveableException (com.sun.star.beans.NotRemoveableException)1 PropertyExistException (com.sun.star.beans.PropertyExistException)1 PropertyVetoException (com.sun.star.beans.PropertyVetoException)1 UnknownPropertyException (com.sun.star.beans.UnknownPropertyException)1 BootstrapException (com.sun.star.comp.helper.BootstrapException)1 NoSuchElementException (com.sun.star.container.NoSuchElementException)1 XDesktop (com.sun.star.frame.XDesktop)1 DisposedException (com.sun.star.lang.DisposedException)1 IllegalArgumentException (com.sun.star.lang.IllegalArgumentException)1 WrappedTargetException (com.sun.star.lang.WrappedTargetException)1 XMultiComponentFactory (com.sun.star.lang.XMultiComponentFactory)1 XComponentContext (com.sun.star.uno.XComponentContext)1 File (java.io.File)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1 URLClassLoader (java.net.URLClassLoader)1 UndefinedParagraphFormatException (org.jabref.logic.openoffice.UndefinedParagraphFormatException)1