views:

10

answers:

0

Hi,

I'm writing an applet (java 6) which contains an OpenOffice text document (OOo 3.2) using the OfficeBean - http://api.openoffice.org/docs/DevelopersGuide/OfficeBean/OfficeBean.xhtml.

To tightly control the user's interaction with this document I want to disable all the OOo keyboard shortcuts, and have managed to use the following code to turn everything off apart from "New Text Document" (CTRL-N), "Help" (F1) and "Auto Text" (CTRL-F3).

String[] aCommandURLSet = {
                new String("Save"),
                new String("SaveAs"),
                new String("About"),
                new String("SelectAll"),
                new String("Quit"),
                new String("Print"),
                new String("Open"),
                new String("Exit"),
                new String("FullScreen"),
                new String("CloseWin"),
                new String("CloseDoc"),
                new String("Help"),   // Seems to do nothing
                new String("NewDoc"), // Seems to do nothing
                new String("NewWindow")}; // Seems to do nothing

XComponentContext xRemoteContext = null;
    XMultiServiceFactory xConfigProvider = null;

try {
        xRemoteContext = getOOoConnection().getComponentContext();
        XMultiComponentFactory xRemoteServiceManager = xRemoteContext.getServiceManager();
        xRemoteServiceManager = xRemoteContext.getServiceManager();

        Object configProvider = xRemoteServiceManager.createInstanceWithContext("com.sun.star.configuration.ConfigurationProvider", xRemoteContext);
        xConfigProvider = (com.sun.star.lang.XMultiServiceFactory) UnoRuntime.queryInterface(com.sun.star.lang.XMultiServiceFactory.class, configProvider);

        // Set the root path for our configuration access
        com.sun.star.beans.PropertyValue[] lParams = new com.sun.star.beans.PropertyValue[1];

        lParams[0] = new com.sun.star.beans.PropertyValue();
        lParams[0].Name = new String("nodepath");
        lParams[0].Value = "/org.openoffice.Office.Commands/Execute/Disabled";

        try {
            // Create configuration update access to have write access to the configuration
            Object xAccess = xConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", lParams);

            com.sun.star.lang.XSingleServiceFactory xSetElementFactory = (com.sun.star.lang.XSingleServiceFactory) UnoRuntime
                    .queryInterface(com.sun.star.lang.XSingleServiceFactory.class, xAccess);

            com.sun.star.container.XNameContainer xNameContainer = (com.sun.star.container.XNameContainer) UnoRuntime.queryInterface(com.sun.star.container.XNameContainer.class, xAccess);

            if(xSetElementFactory != null && xNameContainer != null) {
                Object[] aArgs = new Object[0];

                for(int i = 0; i < aCommandURLSet.length; i++) {
                    // Create the nodes with the XSingleServiceFactory of the configuration
                    Object xNewElement = xSetElementFactory.createInstanceWithArguments(aArgs);

                    if(xNewElement != null) {
                        // We have a new node. To set the properties of the node
                        // we need the XPropertySet interface.
                        com.sun.star.beans.XPropertySet xPropertySet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xNewElement);

                        if(xPropertySet != null) {
                            // Create a unique node name.
                            String aCmdNodeName = new String("Command-");
                            aCmdNodeName += i;

                            // Insert the node into the Disabled set
                            xPropertySet.setPropertyValue("Command", aCommandURLSet[i]);
                            xNameContainer.insertByName(aCmdNodeName, xNewElement);
                        }
                    }
                }

                // Commit our changes
                com.sun.star.util.XChangesBatch xFlush = (com.sun.star.util.XChangesBatch) UnoRuntime.queryInterface(com.sun.star.util.XChangesBatch.class, xAccess);
                xFlush.commitChanges();
            }
        } catch(com.sun.star.uno.Exception e) {
            System.err.println("Exception detected!" + e);
            e.printStackTrace();
        }

    } catch(NoConnectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch(Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Can anyone help? I've seen the list of commands at http://openofficetechnology.com/node/71 but none of these seems to provide the setting I need. TIA