Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit c8bc403

Browse files
author
Emmanuel Hugonnet
committed
Adding support for LibreOffice on Windows
1 parent cb47dfb commit c8bc403

File tree

3 files changed

+160
-91
lines changed

3 files changed

+160
-91
lines changed

src/main/java/com/silverpeas/openoffice/OpenOfficeFinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ public boolean isMicrosoftOffice() {
5858
return false;
5959
}
6060

61-
public abstract String findOpenOffice() throws OfficeNotFoundException;
61+
public abstract String findOpenOffice() throws OpenOfficeNotFoundException;
6262
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Copyright (C) 2000 - 2009 Silverpeas
3+
*
4+
* This program is free software: you can redistribute it and/or modify it under the terms of the
5+
* GNU Affero General Public License as published by the Free Software Foundation, either version 3
6+
* of the License, or (at your option) any later version.
7+
*
8+
* As a special exception to the terms and conditions of version 3.0 of the GPL, you may
9+
* redistribute this Program in connection with Free/Libre Open Source Software ("FLOSS")
10+
* applications as described in Silverpeas's FLOSS exception. You should have received a copy of the
11+
* text describing the FLOSS exception, and it is also available here:
12+
* "http://www.silverpeas.org/legal/licensing"
13+
*
14+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
15+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License along with this program.
19+
* If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
package com.silverpeas.openoffice.windows;
22+
23+
import java.util.logging.Level;
24+
import java.util.logging.Logger;
25+
26+
import com.silverpeas.openoffice.OpenOfficeFinder;
27+
import com.silverpeas.openoffice.OpenOfficeNotFoundException;
28+
import com.silverpeas.openoffice.util.MessageUtil;
29+
import com.silverpeas.openoffice.util.RegistryKeyReader;
30+
31+
32+
public class WindowsLibreOfficeFinder extends OpenOfficeFinder {
33+
34+
static final Logger logger = Logger.getLogger(WindowsLibreOfficeFinder.class.getName());
35+
private static final String[] VERSIONS = new String[]{"3.5"};
36+
private static final String GLOBAL_LIBRE_OFFICE_FOLDER =
37+
"\"HKEY_LOCAL_MACHINE\\SOFTWARE\\LibreOffice\\LibreOffice\\";
38+
private static final String GLOBAL_LIBRE_OFFICE_FOLDER_64 =
39+
"\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LibreOffice\\LibreOffice\\";
40+
private static final String LOCAL_LIBRE_OFFICE_FOLDER_64 =
41+
"\"HKEY_CURRENT_USER\\SOFTWARE\\Wow6432Node\\LibreOffice\\LibreOffice\\";
42+
private static final String LOCAL_LIBRE_OFFICE_FOLDER =
43+
"\"HKEY_CURRENT_USER\\SOFTWARE\\LibreOffice\\LibreOffice\\";
44+
45+
public String getOpenOfficePath(String version) {
46+
String key = null;
47+
try {
48+
key = RegistryKeyReader.readKey(LOCAL_LIBRE_OFFICE_FOLDER + version + "\" /v Path");
49+
if (key == null) {
50+
key = RegistryKeyReader.readKey(GLOBAL_LIBRE_OFFICE_FOLDER + version + "\" /v Path");
51+
}
52+
if (key == null) {
53+
key = RegistryKeyReader.readKey(LOCAL_LIBRE_OFFICE_FOLDER_64 + version + "\" /v Path");
54+
}
55+
if (key == null) {
56+
key = RegistryKeyReader.readKey(GLOBAL_LIBRE_OFFICE_FOLDER_64 + version + "\" /v Path");
57+
}
58+
} catch (Exception e) {
59+
logger.log(Level.SEVERE, MessageUtil.getMessage("error.reading.registry"), e);
60+
}
61+
return key;
62+
}
63+
64+
@Override
65+
public String findOpenOffice() throws OpenOfficeNotFoundException {
66+
for (String version : VERSIONS) {
67+
logger.log(Level.FINE, "{0}{1}{2}", new Object[]{MessageUtil.getMessage(
68+
"info.openoffice.search"), MessageUtil.getMessage("info.openoffice.version"), version});
69+
String result = getOpenOfficePath(version);
70+
if (result != null) {
71+
logger.log(Level.FINE, "{0}{1}{2}{3}", new Object[]{MessageUtil.getMessage(
72+
"info.openoffice.version"), version, ' ', MessageUtil.getMessage(
73+
"info.openoffice.found")});
74+
return '"' + result + '"';
75+
}
76+
}
77+
throw new OpenOfficeNotFoundException();
78+
}
79+
}
Lines changed: 80 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,80 @@
1-
/**
2-
* Copyright (C) 2000 - 2009 Silverpeas
3-
*
4-
* This program is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU Affero General Public License as
6-
* published by the Free Software Foundation, either version 3 of the
7-
* License, or (at your option) any later version.
8-
*
9-
* As a special exception to the terms and conditions of version 3.0 of
10-
* the GPL, you may redistribute this Program in connection with Free/Libre
11-
* Open Source Software ("FLOSS") applications as described in Silverpeas's
12-
* FLOSS exception. You should have received a copy of the text describing
13-
* the FLOSS exception, and it is also available here:
14-
* "http://repository.silverpeas.com/legal/licensing"
15-
*
16-
* This program is distributed in the hope that it will be useful,
17-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19-
* GNU Affero General Public License for more details.
20-
*
21-
* You should have received a copy of the GNU Affero General Public License
22-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23-
*/
24-
25-
package com.silverpeas.openoffice.windows;
26-
27-
import java.util.logging.Level;
28-
import java.util.logging.Logger;
29-
30-
import com.silverpeas.openoffice.OpenOfficeFinder;
31-
import com.silverpeas.openoffice.OpenOfficeNotFoundException;
32-
import com.silverpeas.openoffice.util.MessageUtil;
33-
import com.silverpeas.openoffice.util.RegistryKeyReader;
34-
35-
/**
36-
* @author Emvnd.sun.star.webdavel Hugonnet
37-
*/
38-
public class WindowsOpenOfficeFinder extends OpenOfficeFinder {
39-
40-
static final Logger logger = Logger.getLogger(WindowsOpenOfficeFinder.class.getName());
41-
private static final String[] VERSIONS = new String[] {"3.3", "3.2", "3.1", "3.0", "2.4",
42-
"2.3" };
43-
private static final String GLOBAL_OPEN_OFFICE_FOLDER =
44-
"\"HKEY_LOCAL_MACHINE\\SOFTWARE\\OpenOffice.org\\OpenOffice.org\\";
45-
private static final String GLOBAL_OPEN_OFFICE_FOLDER_64 =
46-
"\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\OpenOffice.org\\OpenOffice.org\\";
47-
private static final String LOCAL_OPEN_OFFICE_FOLDER_64 =
48-
"\"HKEY_CURRENT_USER\\SOFTWARE\\Wow6432Node\\OpenOffice.org\\OpenOffice.org\\";
49-
private static final String LOCAL_OPEN_OFFICE_FOLDER =
50-
"\"HKEY_CURRENT_USER\\SOFTWARE\\OpenOffice.org\\OpenOffice.org\\";
51-
52-
public String getOpenOfficePath(String version) {
53-
String key = null;
54-
try {
55-
key = RegistryKeyReader.readKey(LOCAL_OPEN_OFFICE_FOLDER + version
56-
+ "\" /v Path");
57-
if (key == null) {
58-
key = RegistryKeyReader.readKey(GLOBAL_OPEN_OFFICE_FOLDER + version
59-
+ "\" /v Path");
60-
}
61-
if (key == null) {
62-
key = RegistryKeyReader.readKey(LOCAL_OPEN_OFFICE_FOLDER_64 + version
63-
+ "\" /v Path");
64-
}
65-
if (key == null) {
66-
key = RegistryKeyReader.readKey(GLOBAL_OPEN_OFFICE_FOLDER_64 + version
67-
+ "\" /v Path");
68-
}
69-
} catch (Exception e) {
70-
logger.log(Level.SEVERE, MessageUtil.getMessage("error.reading.registry"), e);
71-
}
72-
return key;
73-
}
74-
75-
@Override
76-
public String findOpenOffice() throws OpenOfficeNotFoundException {
77-
for (String version : VERSIONS) {
78-
logger.log(Level.FINE, "{0}{1}{2}", new Object[] { MessageUtil.getMessage(
79-
"info.openoffice.search"), MessageUtil.getMessage("info.openoffice.version"), version });
80-
String result = getOpenOfficePath(version);
81-
if (result != null) {
82-
logger.log(Level.FINE, "{0}{1}{2}{3}", new Object[] { MessageUtil.getMessage(
83-
"info.openoffice.version"), version, ' ',
84-
MessageUtil.getMessage("info.openoffice.found") });
85-
return '"' + result + '"';
86-
}
87-
}
88-
throw new OpenOfficeNotFoundException();
89-
}
90-
}
1+
/**
2+
* Copyright (C) 2000 - 2009 Silverpeas
3+
*
4+
* This program is free software: you can redistribute it and/or modify it under the terms of the
5+
* GNU Affero General Public License as published by the Free Software Foundation, either version 3
6+
* of the License, or (at your option) any later version.
7+
*
8+
* As a special exception to the terms and conditions of version 3.0 of the GPL, you may
9+
* redistribute this Program in connection with Free/Libre Open Source Software ("FLOSS")
10+
* applications as described in Silverpeas's FLOSS exception. You should have received a copy of the
11+
* text describing the FLOSS exception, and it is also available here:
12+
* "http://www.silverpeas.org/legal/licensing"
13+
*
14+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
15+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License along with this program.
19+
* If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
package com.silverpeas.openoffice.windows;
22+
23+
import java.util.logging.Level;
24+
import java.util.logging.Logger;
25+
26+
import com.silverpeas.openoffice.OpenOfficeFinder;
27+
import com.silverpeas.openoffice.OpenOfficeNotFoundException;
28+
import com.silverpeas.openoffice.util.MessageUtil;
29+
import com.silverpeas.openoffice.util.RegistryKeyReader;
30+
31+
32+
public class WindowsOpenOfficeFinder extends OpenOfficeFinder {
33+
private static final OpenOfficeFinder libreOfficeFinder = new WindowsLibreOfficeFinder();
34+
static final Logger logger = Logger.getLogger(WindowsOpenOfficeFinder.class.getName());
35+
private static final String[] VERSIONS = new String[]{"3.4.1", "3.3", "3.2", "3.1", "3.0", "2.4",
36+
"2.3"};
37+
private static final String GLOBAL_OPEN_OFFICE_FOLDER =
38+
"\"HKEY_LOCAL_MACHINE\\SOFTWARE\\OpenOffice.org\\OpenOffice.org\\";
39+
private static final String GLOBAL_OPEN_OFFICE_FOLDER_64 =
40+
"\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\OpenOffice.org\\OpenOffice.org\\";
41+
private static final String LOCAL_OPEN_OFFICE_FOLDER_64 =
42+
"\"HKEY_CURRENT_USER\\SOFTWARE\\Wow6432Node\\OpenOffice.org\\OpenOffice.org\\";
43+
private static final String LOCAL_OPEN_OFFICE_FOLDER =
44+
"\"HKEY_CURRENT_USER\\SOFTWARE\\OpenOffice.org\\OpenOffice.org\\";
45+
46+
public String getOpenOfficePath(String version) {
47+
String key = null;
48+
try {
49+
key = RegistryKeyReader.readKey(LOCAL_OPEN_OFFICE_FOLDER + version + "\" /v Path");
50+
if (key == null) {
51+
key = RegistryKeyReader.readKey(GLOBAL_OPEN_OFFICE_FOLDER + version + "\" /v Path");
52+
}
53+
if (key == null) {
54+
key = RegistryKeyReader.readKey(LOCAL_OPEN_OFFICE_FOLDER_64 + version + "\" /v Path");
55+
}
56+
if (key == null) {
57+
key = RegistryKeyReader.readKey(GLOBAL_OPEN_OFFICE_FOLDER_64 + version + "\" /v Path");
58+
}
59+
} catch (Exception e) {
60+
logger.log(Level.SEVERE, MessageUtil.getMessage("error.reading.registry"), e);
61+
}
62+
return key;
63+
}
64+
65+
@Override
66+
public String findOpenOffice() throws OpenOfficeNotFoundException {
67+
for (String version : VERSIONS) {
68+
logger.log(Level.FINE, "{0}{1}{2}", new Object[]{MessageUtil.getMessage(
69+
"info.openoffice.search"), MessageUtil.getMessage("info.openoffice.version"), version});
70+
String result = getOpenOfficePath(version);
71+
if (result != null) {
72+
logger.log(Level.FINE, "{0}{1}{2}{3}", new Object[]{MessageUtil.getMessage(
73+
"info.openoffice.version"), version, ' ', MessageUtil.getMessage(
74+
"info.openoffice.found")});
75+
return '"' + result + '"';
76+
}
77+
}
78+
return libreOfficeFinder.findOpenOffice();
79+
}
80+
}

0 commit comments

Comments
 (0)