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

Commit 955b634

Browse files
author
Emmanuel Hugonnet
committed
Adding support for Office 2010 and transparent authentication with MS Office
git-svn-id: https://www.silverpeas.org/svn/silverpeas/services/office-online/trunk@2845 a8e77078-a1c7-4fa5-b8fc-53c5178a176c
1 parent f5dc02c commit 955b634

File tree

9 files changed

+29
-56
lines changed

9 files changed

+29
-56
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.silverpeas</groupId>
66
<artifactId>parent</artifactId>
7-
<version>14</version>
7+
<version>16-SNAPSHOT</version>
88
</parent>
99

1010
<scm>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ public interface OfficeFinder {
4141

4242
public String findOther() throws OfficeNotFoundException;
4343

44-
public boolean isMicrosoftOffice2007();
44+
public boolean isMicrosoftOffice();
4545
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ public class OfficeLauncher {
5151
public static int launch(MsOfficeType type, String url, AuthenticationInfo authInfo)
5252
throws IOException, InterruptedException, OfficeNotFoundException {
5353
OfficeFinder finder = FinderFactory.getFinder(type);
54-
logger.log(Level.INFO, "Are we using Office 2007 : {0}", finder.isMicrosoftOffice2007());
54+
logger.log(Level.INFO, "Are we using Office 2007 : {0}", finder.isMicrosoftOffice());
5555
logger.log(Level.INFO, "We are on {0} OS", OsEnum.getOS());
56-
boolean modeDisconnected = (OsEnum.getOS() == OsEnum.WINDOWS_VISTA ||
57-
OsEnum.getOS() == OsEnum.WINDOWS_SEVEN || OsEnum.getOS() == OsEnum.MAC_OSX)
58-
&& finder.isMicrosoftOffice2007();
56+
boolean modeDisconnected = (OsEnum.isWindows() || OsEnum.getOS() == OsEnum.MAC_OSX)
57+
&& finder.isMicrosoftOffice();
5958
switch (type) {
6059
case EXCEL:
6160
return launch(finder.findSpreadsheet(), url, modeDisconnected, authInfo);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public String findOther() throws OfficeNotFoundException {
5454
}
5555

5656
@Override
57-
public boolean isMicrosoftOffice2007() {
57+
public boolean isMicrosoftOffice() {
5858
return false;
5959
}
6060

src/main/java/com/silverpeas/openoffice/macosx/MacOsOfficeFinder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*/
4141
public class MacOsOfficeFinder implements OfficeFinder {
4242

43-
static Logger logger = Logger.getLogger(MacOsOfficeFinder.class.getName());
43+
static final Logger logger = Logger.getLogger(MacOsOfficeFinder.class.getName());
4444

4545
protected static final OpenOfficeFinder finder = new WhereisMacHelper();
4646
protected static final String OFFICE_PATH =
@@ -82,13 +82,13 @@ public String findOther() throws OfficeNotFoundException {
8282
}
8383

8484
@Override
85-
public boolean isMicrosoftOffice2007() {
85+
public boolean isMicrosoftOffice() {
8686
return isMsOfficePresent();
8787
}
8888

8989
protected boolean isMsOfficePresent() {
9090
File officeDir = new File(OFFICE_PATH);
91-
logger.log(Level.INFO, "Looking for file " + OFFICE_PATH + " but found " + officeDir.exists());
91+
logger.log(Level.INFO, "Looking for file " + OFFICE_PATH + " but found {0}", officeDir.exists());
9292
return officeDir.exists();
9393
}
9494

src/main/java/com/silverpeas/openoffice/util/OsEnum.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,14 @@ public static OsEnum getOS() {
6767
public String getProfilesDirectory() {
6868
return System.getProperty("user.home") + File.separator + profilesDir;
6969
}
70+
71+
72+
public static boolean isWindows() {
73+
OsEnum currentOS = getOS();
74+
return currentOS == WINDOWS_SEVEN || currentOS == WINDOWS_XP || currentOS == WINDOWS_VISTA;
75+
}
76+
77+
public static boolean isLinux() {
78+
return getOS() == LINUX;
79+
}
7080
}

src/main/java/com/silverpeas/openoffice/windows/MsOfficePathFinder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public String findOther() throws OfficeNotFoundException {
8585
}
8686

8787
@Override
88-
public boolean isMicrosoftOffice2007() {
89-
return false;
88+
public boolean isMicrosoftOffice() {
89+
return !isOpenOffice;
9090
}
9191

9292
protected boolean exists(String exe) {

src/main/java/com/silverpeas/openoffice/windows/MsOfficeRegistryHelper.java

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
* You should have received a copy of the GNU Affero General Public License
2222
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2323
*/
24-
2524
package com.silverpeas.openoffice.windows;
2625

2726
import com.silverpeas.openoffice.OfficeFinder;
2827
import com.silverpeas.openoffice.OfficeNotFoundException;
2928
import com.silverpeas.openoffice.util.RegistryKeyReader;
30-
import java.util.logging.Level;
3129
import java.util.logging.Logger;
3230
import java.util.regex.Matcher;
3331
import java.util.regex.Pattern;
@@ -45,26 +43,11 @@ public class MsOfficeRegistryHelper implements OfficeFinder {
4543
static final String POWERPOINT = "Powerpoint.Application";
4644
static final String WORD = "Word.Application";
4745
static final String FRONTPAGE = "FrontPage.Application";
48-
static final String BASE_APPLICATION_KEY =
49-
"\"HKEY_LOCAL_MACHINE\\Software\\Classes\\";
50-
static final String BASE_KEY_CLSID =
51-
"\"HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Classes\\CLSID\\";
52-
static final String BASE_KEY_64_CLSID =
53-
"\"HKEY_LOCAL_MACHINE\\Software\\Classes\\CLSID\\";
46+
static final String BASE_APPLICATION_KEY = "\"HKEY_LOCAL_MACHINE\\Software\\Classes\\";
47+
static final String BASE_KEY_64_CLSID = "\"HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Classes\\CLSID\\";
48+
static final String BASE_KEY_CLSID = "\"HKEY_LOCAL_MACHINE\\Software\\Classes\\CLSID\\";
5449
static final Pattern AUTOMATION = Pattern.compile(
5550
"\\s*/[aA][uU][tT][oO][mM][aA][tT][iI][oO][nN]\\s*");
56-
static final String BASE_MSOFFICE_WORD_2007_KEY =
57-
"\"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Office\\12.0\\Word\\InstallRoot\" /ve";
58-
static final String BASE_MSOFFICE_EXCEL_2007_KEY =
59-
"\"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Office\\12.0\\Excel\\InstallRoot\" /ve";
60-
static final String BASE_MSOFFICE_POWERPOINT_2007_KEY =
61-
"\"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Office\\12.0\\PowerPoint\\InstallRoot\" /ve";
62-
static final String BASE_MSOFFICE_WORD_2007_KEY_64 =
63-
"\"HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Microsoft\\Office\\12.0\\Word\\InstallRoot\" /ve";
64-
static final String BASE_MSOFFICE_EXCEL_2007_KEY_64 =
65-
"\"HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Microsoft\\Office\\12.0\\Excel\\InstallRoot\" /ve";
66-
static final String BASE_MSOFFICE_POWERPOINT_2007_KEY_64 =
67-
"\"HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Microsoft\\Office\\12.0\\PowerPoint\\InstallRoot\" /ve";
6851

6952
protected String getClsid(String type) {
7053
return RegistryKeyReader.readKey(BASE_APPLICATION_KEY + type + "\\CLSID\"");
@@ -73,11 +56,9 @@ protected String getClsid(String type) {
7356
protected String getPath(String type) {
7457
String clsid = getClsid(type);
7558
if (clsid != null) {
76-
String path = RegistryKeyReader.readKey(BASE_KEY_CLSID + clsid
77-
+ "\\LocalServer32\"");
59+
String path = RegistryKeyReader.readKey(BASE_KEY_CLSID + clsid + "\\LocalServer32\"");
7860
if (path == null) {
79-
path = RegistryKeyReader.readKey(BASE_KEY_64_CLSID + clsid
80-
+ "\\LocalServer32\"");
61+
path = RegistryKeyReader.readKey(BASE_KEY_64_CLSID + clsid + "\\LocalServer32\"");
8162
}
8263
if (path != null) {
8364
return '"' + extractPath(path) + '"';
@@ -130,24 +111,7 @@ public String findOther() throws OfficeNotFoundException {
130111
}
131112

132113
@Override
133-
public boolean isMicrosoftOffice2007() {
134-
logger.log(Level.INFO, "Are we using Word 2007 : {0}", RegistryKeyReader
135-
.readKey(BASE_MSOFFICE_WORD_2007_KEY) != null
136-
||
137-
RegistryKeyReader.readKey(BASE_MSOFFICE_WORD_2007_KEY_64) != null);
138-
logger.log(Level.INFO, "Are we using Excel 2007 : {0}", RegistryKeyReader
139-
.readKey(BASE_MSOFFICE_EXCEL_2007_KEY) != null
140-
||
141-
RegistryKeyReader.readKey(BASE_MSOFFICE_EXCEL_2007_KEY_64) != null);
142-
logger.log(Level.INFO, "Are we using Powerpoint 2007 : {0}", RegistryKeyReader
143-
.readKey(BASE_MSOFFICE_POWERPOINT_2007_KEY) != null
144-
||
145-
RegistryKeyReader.readKey(BASE_MSOFFICE_POWERPOINT_2007_KEY_64) != null);
146-
return (RegistryKeyReader.readKey(BASE_MSOFFICE_WORD_2007_KEY) != null
147-
|| RegistryKeyReader.readKey(BASE_MSOFFICE_EXCEL_2007_KEY) != null
148-
|| RegistryKeyReader.readKey(BASE_MSOFFICE_POWERPOINT_2007_KEY) != null
149-
|| RegistryKeyReader.readKey(BASE_MSOFFICE_WORD_2007_KEY_64) != null
150-
|| RegistryKeyReader.readKey(BASE_MSOFFICE_EXCEL_2007_KEY_64) != null || RegistryKeyReader
151-
.readKey(BASE_MSOFFICE_POWERPOINT_2007_KEY_64) != null);
114+
public boolean isMicrosoftOffice() {
115+
return getPath(EXCEL) != null || getPath(POWERPOINT) != null || getPath(WORD) != null;
152116
}
153117
}

src/test/java/com/silverpeas/openoffice/windows/MsOfficeFinderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ public void testIsMicrosoftOffice2007() throws Exception {
9292
if (!System.getProperty("os.name").startsWith("Windows")) {
9393
return;
9494
}
95-
assertTrue(helper.isMicrosoftOffice2007());
95+
assertTrue(helper.isMicrosoftOffice());
9696
}
9797
}

0 commit comments

Comments
 (0)