Code: Select all
XComponentContext xLocalContext =
com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
Code: Select all
private void disableCommands()
{
string[] aCommandURLTestSet = { "Open", "About", "SelectAll", "Quit", "SaveAs" };
// Set the root path for our configuration access
PropertyValue[] lParams = new PropertyValue[1];
lParams[0] = new PropertyValue();
lParams[0].Name = "nodepath";
lParams[0].Value = new uno.Any("/org.openoffice.Office.Commands/Execute/Disabled");
XComponentContext xRemoteContext = null;
XMultiComponentFactory xRemoteServiceManager = null;
XURLTransformer xTransformer = null;
// // Create configuration update access to have write access to the configuration
// connect
XComponentContext xLocalContext = createInitialComponentContext(null); //this wont work obviously
XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
Object urlResolver = xLocalServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", xLocalContext);
XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver)urlResolver;
Object initialObject = xUnoUrlResolver.resolve(
"uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager");
XPropertySet xPropertySet = (XPropertySet)initialObject;
Object context = xPropertySet.getPropertyValue("DefaultContext");
xRemoteContext = (XComponentContext)context;
xRemoteServiceManager = xRemoteContext.getServiceManager();
Object transformer = xRemoteServiceManager.createInstanceWithContext(
"com.sun.star.util.URLTransformer", xRemoteContext);
xTransformer = (XURLTransformer)transformer;
Object configProvider = xRemoteServiceManager.createInstanceWithContext(
"com.sun.star.configuration.ConfigurationProvider", xRemoteContext);
XMultiServiceFactory xConfigProvider = (XMultiServiceFactory)configProvider;
Object xAccess = xConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", lParams);
XSingleServiceFactory xSetElementFactory =
(XSingleServiceFactory)xAccess;
XNameContainer xNameContainer = (XNameContainer)xAccess;
if (xSetElementFactory != null && xNameContainer != null)
{
Object[] aArgs = { };
for (int i = 0; i < aCommandURLTestSet.Length; i++)
{
// Create the nodes with the XSingleServiceFactory of the configuration
Object xNewElement = xSetElementFactory.createInstanceWithArguments(new uno.Any(aArgs)); //can't use aArgs as an argument for uno.Any()
if (xNewElement != null)
{
// We have a new node. To set the properties of the node we need
// the XPropertySet interface.
XPropertySet xPropertySet1 = (XPropertySet)xNewElement;
if (xPropertySet1 != null)
{
// Create a unique node name.
String aCmdNodeName = "Command-";
aCmdNodeName += i;
// Insert the node into the Disabled set
xPropertySet.setPropertyValue("Command", new uno.Any(aCommandURLTestSet[i]));
xNameContainer.insertByName(aCmdNodeName, new uno.Any(xNewElement)); //can't use aArgs as an argument for uno.Any()
}
}
}
// Commit our changes
XChangesBatch xFlush = (XChangesBatch)xAccess;
xFlush.commitChanges();
}
}