[Solved] Extension development: get OO version?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
verde2
Posts: 9
Joined: Mon Dec 23, 2013 3:40 pm

[Solved] Extension development: get OO version?

Post 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
Last edited by verde2 on Mon Jan 06, 2014 7:55 pm, edited 1 time in total.
OpenOffice on Ubuntu 13.10 64-bits
User avatar
Villeroy
Volunteer
Posts: 31349
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Extension development: get OO version?

Post 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
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
verde2
Posts: 9
Joined: Mon Dec 23, 2013 3:40 pm

Re: Extension development: get OO version?

Post by verde2 »

How is possible to make it from Java?
OpenOffice on Ubuntu 13.10 64-bits
User avatar
Villeroy
Volunteer
Posts: 31349
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Extension development: get OO version?

Post by Villeroy »

Simply do it using the same interfaces and methods.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
verde2
Posts: 9
Joined: Mon Dec 23, 2013 3:40 pm

Re: Extension development: get OO version?

Post 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
OpenOffice on Ubuntu 13.10 64-bits
User avatar
RoryOF
Moderator
Posts: 35104
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Extension development: get OO version?

Post 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?
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
verde2
Posts: 9
Joined: Mon Dec 23, 2013 3:40 pm

Re: Extension development: get OO version?

Post 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.
OpenOffice on Ubuntu 13.10 64-bits
verde2
Posts: 9
Joined: Mon Dec 23, 2013 3:40 pm

Re: Extension development: get OO version?

Post 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";
                    }
                }
            }
        }
    }

}
OpenOffice on Ubuntu 13.10 64-bits
Post Reply