Java Code Examples for com.sun.star.uno.AnyConverter#toObject()

The following examples show how to use com.sun.star.uno.AnyConverter#toObject() . 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: MemoryUsage.java    From kkFileViewOfficeEdit with Apache License 2.0 6 votes vote down vote up
private XSpreadsheet createSpreadsheet(XScriptContext ctxt)
    throws Exception
{
    XComponentLoader loader = (XComponentLoader)
        UnoRuntime.queryInterface(
            XComponentLoader.class, ctxt.getDesktop());

    XComponent comp = loader.loadComponentFromURL(
        "private:factory/scalc", "_blank", 4, new PropertyValue[0]);

    XSpreadsheetDocument doc = (XSpreadsheetDocument)
        UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);

    XIndexAccess index = (XIndexAccess)
        UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());

    XSpreadsheet sheet = (XSpreadsheet) AnyConverter.toObject(
        new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0));

    return sheet;
}
 
Example 2
Source File: MemoryUsage.java    From kkFileView with Apache License 2.0 6 votes vote down vote up
private XSpreadsheet createSpreadsheet(XScriptContext ctxt)
    throws Exception
{
    XComponentLoader loader = (XComponentLoader)
        UnoRuntime.queryInterface(
            XComponentLoader.class, ctxt.getDesktop());

    XComponent comp = loader.loadComponentFromURL(
        "private:factory/scalc", "_blank", 4, new PropertyValue[0]);

    XSpreadsheetDocument doc = (XSpreadsheetDocument)
        UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);

    XIndexAccess index = (XIndexAccess)
        UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());

    XSpreadsheet sheet = (XSpreadsheet) AnyConverter.toObject(
        new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0));

    return sheet;
}
 
Example 3
Source File: HighlightText.java    From kkFileViewOfficeEdit with Apache License 2.0 4 votes vote down vote up
private boolean tryLoadingLibrary(
    XMultiComponentFactory xmcf, XScriptContext context, String name)
{
    System.err.println("Try to load ScriptBindingLibrary");

    try {
        Object obj = xmcf.createInstanceWithContext(
           "com.sun.star.script.Application" + name + "LibraryContainer",
           context.getComponentContext());

        XLibraryContainer xLibraryContainer = (XLibraryContainer)
            UnoRuntime.queryInterface(XLibraryContainer.class, obj);

        System.err.println("Got XLibraryContainer");

        Object serviceObj = context.getComponentContext().getValueByName(
            "/singletons/com.sun.star.util.theMacroExpander");
                                                                            
        XMacroExpander xme = (XMacroExpander) AnyConverter.toObject(
            new Type(XMacroExpander.class), serviceObj);
                                                                            
        String bootstrapName = "bootstraprc";
        if (System.getProperty("os.name").startsWith("Windows")) {
            bootstrapName = "bootstrap.ini";
        }

        String libURL = xme.expandMacros(
            "${$OOO_BASE_DIR/program/" + bootstrapName + "::BaseInstallation}" +
            "/share/basic/ScriptBindingLibrary/" +
            name.toLowerCase() + ".xlb/");

        System.err.println("libURL is: " + libURL);

        xLibraryContainer.createLibraryLink(
            "ScriptBindingLibrary", libURL, false);

        System.err.println("liblink created");

    } catch (com.sun.star.uno.Exception e) {
        System.err.println("Got an exception loading lib: " + e.getMessage());
        return false;
    }
    return true;
}
 
Example 4
Source File: HighlightText.java    From kkFileView with Apache License 2.0 4 votes vote down vote up
private boolean tryLoadingLibrary(
    XMultiComponentFactory xmcf, XScriptContext context, String name)
{
    System.err.println("Try to load ScriptBindingLibrary");

    try {
        Object obj = xmcf.createInstanceWithContext(
           "com.sun.star.script.Application" + name + "LibraryContainer",
           context.getComponentContext());

        XLibraryContainer xLibraryContainer = (XLibraryContainer)
            UnoRuntime.queryInterface(XLibraryContainer.class, obj);

        System.err.println("Got XLibraryContainer");

        Object serviceObj = context.getComponentContext().getValueByName(
            "/singletons/com.sun.star.util.theMacroExpander");
                                                                            
        XMacroExpander xme = (XMacroExpander) AnyConverter.toObject(
            new Type(XMacroExpander.class), serviceObj);
                                                                            
        String bootstrapName = "bootstraprc";
        if (System.getProperty("os.name").startsWith("Windows")) {
            bootstrapName = "bootstrap.ini";
        }

        String libURL = xme.expandMacros(
            "${$OOO_BASE_DIR/program/" + bootstrapName + "::BaseInstallation}" +
            "/share/basic/ScriptBindingLibrary/" +
            name.toLowerCase() + ".xlb/");

        System.err.println("libURL is: " + libURL);

        xLibraryContainer.createLibraryLink(
            "ScriptBindingLibrary", libURL, false);

        System.err.println("liblink created");

    } catch (com.sun.star.uno.Exception e) {
        System.err.println("Got an exception loading lib: " + e.getMessage());
        return false;
    }
    return true;
}