else if(sReadLine.startsWith("EndUpdate"))
{
try
{
myprintln("COMMAND: " + sReadLine);
XChangesBatch xChangesBatch = (com.sun.star.util.XChangesBatch)UnoRuntime.queryInterface(com.sun.star.util.XChangesBatch.class, xCfgUpdateAccess);
if(xChangesBatch.hasPendingChanges())
{
xChangesBatch.commitChanges();
//myprintln("The changes have been commmitted");
}
else
{
myprintln("There are no changes to commmit");
}
}
catch(Exception e)
{
myprintln("Exception while commit the changes");
}
}
// DO //
else if(sReadLine.startsWith("Do"))
{
try
{
myprintln("COMMAND: " + sReadLine);
StringTokenizer st = new StringTokenizer(sReadLine.substring((sReadLine.indexOf("(")+1), sReadLine.lastIndexOf(")")), ";");
int noOfTokens = st.countTokens();
int noOfLoops = Integer.parseInt(st.nextToken());
String sCommand = st.nextToken();
for ( int i = 1; i <= noOfLoops ;i++)
{
if ( sCommand.startsWith("ReadNode") )
{
StringTokenizer st2 = new StringTokenizer(sCommand.substring((sCommand.indexOf("(")+1), sCommand.lastIndexOf(")")), ",");
myprintln("COMMAND: " + sCommand);
int noOfTokens2 = st2.countTokens();
String startNodeName=st2.nextToken();
int outputDepth = -1;
if(noOfTokens2 == 2)
{
String newString = st2.nextToken().trim();
outputDepth = Integer.parseInt(newString);
}
readNodes(startNodeName,outputDepth);
}
if ( sCommand.startsWith("ReadValue") )
{
StringTokenizer st2 = new StringTokenizer(sCommand.substring((sCommand.indexOf("(")+1), sCommand.lastIndexOf(")")), ",");
String startNodeName=st2.nextToken();
int outputDepth = -1;
myprintln("COMMAND: " + sCommand);
readValue(startNodeName);
}
else if ( sCommand.startsWith("UpdateNodeDirect"))
{
myprintln("COMMAND: " + sCommand);
StringTokenizer st2 = new StringTokenizer(sCommand.substring((sCommand.indexOf("(")+1), sCommand.lastIndexOf(")")), ",");
String sValueName=st2.nextToken();
String sNewValue=st2.nextToken();
updateNode(sValueName,sNewValue,1);
}
else if ( sCommand.startsWith("UpdateNode"))
{
myprintln("COMMAND: " + sReadLine);
StringTokenizer st2 = new StringTokenizer(sCommand.substring((sCommand.indexOf("(")+1), sCommand.lastIndexOf(")")), ",");
String sValueName=st2.nextToken();
String sNewValue=st2.nextToken();
updateNode(sValueName,sNewValue,2,xCfgUpdateAccess );
}
}
}
catch (Exception e)
{
System.out.println(e);
}
}
// WAIT //
else if(sReadLine.startsWith("Wait"))
{
myprintln("COMMAND: " + sReadLine);
StringTokenizer st = new StringTokenizer(sReadLine.substring((sReadLine.indexOf("(")+1), sReadLine.lastIndexOf(")")), ",");
int secToWait = Integer.parseInt(st.nextToken());
java.lang.Thread.sleep(secToWait * 1000);
}
// ADD NODE //
else if(sReadLine.startsWith("AddNode"))
{
try
{
myprintln("COMMAND: " + sReadLine);
StringTokenizer st = new StringTokenizer(sReadLine.substring((sReadLine.indexOf("(")+1), sReadLine.lastIndexOf(")")), ",");
String startNodeName = st.nextToken();
String sNewNodeName = st.nextToken();
XInterface myCfgUpdateAccess = (XInterface) myConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", new Object[]{startNodeName, new Integer(-1)});
com.sun.star.lang.XServiceInfo myServicex = (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(com.sun.star.lang.XServiceInfo.class, myCfgUpdateAccess);
String [] xx = myServicex.getSupportedServiceNames();
com.sun.star.lang.XServiceInfo myService = (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(com.sun.star.lang.XServiceInfo.class, myCfgUpdateAccess);
boolean bSupport = myService.supportsService("com.sun.star.configuration.ConfigurationContainer");
//boolean bSupport = true;
if(bSupport)
{
// create a new empty node
com.sun.star.lang.XSingleServiceFactory myFac = (com.sun.star.lang.XSingleServiceFactory)UnoRuntime.queryInterface(com.sun.star.lang.XSingleServiceFactory.class, myCfgUpdateAccess);
XInterface myNewChild = (XInterface)myFac.createInstance();
// query the namecontainer on the node and insert it
com.sun.star.container.XNameContainer myNameContainer = (com.sun.star.container.XNameContainer)UnoRuntime.queryInterface(com.sun.star.container.XNameContainer.class, myCfgUpdateAccess);
myNameContainer.insertByName(sNewNodeName,myNewChild);
// commit the changes
com.sun.star.util.XChangesBatch xChangesBatch = (com.sun.star.util.XChangesBatch)UnoRuntime.queryInterface(com.sun.star.util.XChangesBatch.class, myCfgUpdateAccess);
xChangesBatch.commitChanges();
}
else
{
myprintln("ERROR: " + startNodeName + " didn't support addNode");
}
}
catch (Exception e)
{
myprintln(e.toString());
myprintln(getTargetMessages(e));
}
}
// REMOVE NODE //
else if(sReadLine.startsWith("RemoveNode"))
{
try
{
myprintln("COMMAND: " + sReadLine);
StringTokenizer st = new StringTokenizer(sReadLine.substring((sReadLine.indexOf("(")+1), sReadLine.lastIndexOf(")")), ",");
String startNodeName = st.nextToken();
String sNodeName = st.nextToken();
XInterface myCfgUpdateAccess = (XInterface) myConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", new Object[]{startNodeName, new Integer(-1)});
com.sun.star.lang.XServiceInfo myServicex = (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(com.sun.star.lang.XServiceInfo.class, myCfgUpdateAccess);
String [] xx = myServicex.getSupportedServiceNames();
com.sun.star.lang.XServiceInfo myService = (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(com.sun.star.lang.XServiceInfo.class, myCfgUpdateAccess);
//boolean bSupport = myService.supportsService("com.sun.star.configuration.ConfigurationContainer");
boolean bSupport = true;
if(bSupport)
{
// query the namecontainer on the node and remove the given nodename
com.sun.star.container.XNameContainer myNameContainer = (com.sun.star.container.XNameContainer)UnoRuntime.queryInterface(com.sun.star.container.XNameContainer.class, myCfgUpdateAccess);
myNameContainer.removeByName(sNodeName);
// commit the changes
com.sun.star.util.XChangesBatch xChangesBatch = (com.sun.star.util.XChangesBatch)UnoRuntime.queryInterface(com.sun.star.util.XChangesBatch.class, myCfgUpdateAccess);
xChangesBatch.commitChanges();
}
else
{
myprintln("ERROR: " + startNodeName + " didn't support removeNode");
}