I have developed an application in java which handles file opening and controls certain commands like save and save as in libreoffice with the help of uno commands :- “Disable Commands - Apache OpenOffice Wiki”.
This is my code snippet to initialize libreoffice at a certain port:-
"try{
if (UtilFunctions.getOsName().equalsIgnoreCase(“Windows”)) {
builder = new ProcessBuilder(
“cmd.exe”, “/c”, “soffice --accept=socket,host=localhost,port=8100;urp”);
builder.directory(new File(“C:\Program Files\siccuraoffice\program\”));
builder.redirectErrorStream(true);
Process p = builder.start();
Thread.sleep(1000);
}
try {
xLocalContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
} catch (java.lang.Exception e) {
e.printStackTrace();
}
XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
Object urlResolver = xLocalServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", xLocalContext);
XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(
XUnoUrlResolver.class, urlResolver);
int retryCount = 0;
while (true) {
try {
initialObject = xUnoUrlResolver.resolve(
"uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
break;
} catch (Exception e) {
if (retryCount > 50) {
System.out.println("Siccura Exception " + e.toString());
}
retryCount++;
continue;
}
}
XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, initialObject);
Object context = xPropertySet.getPropertyValue("DefaultContext");
xRemoteContext = (XComponentContext) UnoRuntime.queryInterface(
XComponentContext.class, context);
xRemoteServiceManager = xRemoteContext.getServiceManager();
Object transformer = xRemoteServiceManager.createInstanceWithContext(
"com.sun.star.util.URLTransformer", xRemoteContext);
xTransformer = (com.sun.star.util.XURLTransformer) UnoRuntime.queryInterface(
com.sun.star.util.XURLTransformer.class, transformer);
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);
Object oDesktop = null;
try {
oDesktop = xRemoteServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", xRemoteContext);
} catch (Exception ex) {
ex.printStackTrace();
}
XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, oDesktop);
com.sun.star.frame.XComponentLoader xCompLoader =
UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class, oDesktop);
xComp = xDesktop.getCurrentComponent();
}catch(Exception ex){
ex.printStackTrace();
}"
this works perfectly on a 64 bit machine but not on 32 bit machine. Please help!!