Page 1 of 1
[Solved] Extension development: get OO version?
Posted: Fri Dec 27, 2013 9:06 pm
by verde2
Hello,
I'm just starting to develop an extension for OpenOffice in Java, and I need to find a way to get the version of OpenOffice running this plugin. I can't find documentations on how to do it. Can I have some directions?
Thanks in advance
Re: Extension development: get OO version?
Posted: Fri Dec 27, 2013 9:15 pm
by Villeroy
You specify the required office version in the configuration files of your extension so it can't be installed with a wrong office version.
If you want to get the version during runtime, you have to access the configuration hierarchy.
Basic example:
Code: Select all
Function getOOoVersion() As String
getOOoVersion = getOOoSetupValue("/org.openoffice.Setup/Product","ooSetupVersion")
end Function
Function getOOoSetupValue(sNodePath$,sProperty$)
Dim oNode
oNode = getOOoSetupNode(sNodePath)
getOOoSetupValue = oNode.getbyname(sProperty)
End Function
Function getOOoSetupNode(sNodePath$)
Dim aConfigProvider, oNode, args(0) As new com.sun.star.beans.PropertyValue
aConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider")
args(0).Name = "nodepath"
args(0).Value = sNodePath
getOOoSetupNode = aConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", args())
End Function
Re: Extension development: get OO version?
Posted: Mon Dec 30, 2013 12:50 pm
by verde2
How is possible to make it from Java?
Re: Extension development: get OO version?
Posted: Mon Dec 30, 2013 1:05 pm
by Villeroy
Simply do it using the same interfaces and methods.
Re: Extension development: get OO version?
Posted: Mon Dec 30, 2013 2:42 pm
by verde2
I'm sorry, I'm not familiar at all with that language. Can you make it clearer, or at least explain the most important steps there? Thanks
Re: Extension development: get OO version?
Posted: Mon Dec 30, 2013 2:47 pm
by RoryOF
You have to convert the code given to its equivalent in Java. If you are trying to write and extension using Java you surely have sufficient familiarity with the language to do such a simple conversion?
Re: Extension development: get OO version?
Posted: Mon Dec 30, 2013 2:55 pm
by verde2
I'm not familiar with the UNO API to make an equivalent conversion to Java, and I don't know which language was used in the given code. For example is args(0) an array? How and what is the method getOOoSetupNode returning a value? I'm sorry to be so annoying, but as you can see I'm really beginner with OpenOffice.
My first try to get the version was to make Java run the command "openoffice --version" and print it where it's supposed to show. It was working but only in my machine.
Re: Extension development: get OO version?
Posted: Mon Jan 06, 2014 7:54 pm
by verde2
This solution works for me:
Code: Select all
public class OSUtils {
private OSUtils() {
}
public static String execute(String cmd) throws IOException, InterruptedException {
String saida = "";
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
while (line != null) {
saida += line;
line = reader.readLine();
}
return saida;
}
public static String getLibreOfficeVersion() {
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
try {
String version = null;
FileInputStream fis = new FileInputStream(System.getenv("ProgramFiles") + "\\LibreOffice 4\\program\\version.ini");
DataInputStream dis = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
while ((version = br.readLine()) != null) {
if (version.startsWith("MsiProductVersion")) {
version = version.substring(18);
break;
}
}
br.close();
return version;
} catch (IOException | NullPointerException e) {
return "LibreOffice is not on default installation dir or is not installed";
}
} else {
try {
return OSUtils.execute("soffice --version");
} catch (IOException | InterruptedException e) {
try {
return OSUtils.execute("/usr/lib/libreoffice/program/soffice --version");
} catch (IOException | InterruptedException ex1) {
try {
return OSUtils.execute("/opt/libreoffice4.1/program/soffice --version");
} catch (IOException | InterruptedException ex2) {
return "LibreOffice is not on default installation dir or is not installed";
}
}
}
}
}
}