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

Commit 1bd5042

Browse files
author
Emmanuel Hugonnet
committed
Correction for windows 7
git-svn-id: https://www.silverpeas.org/svn/silverpeas/services/office-online/trunk@957 a8e77078-a1c7-4fa5-b8fc-53c5178a176c
1 parent 81d2812 commit 1bd5042

File tree

6 files changed

+59
-50
lines changed

6 files changed

+59
-50
lines changed

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,43 +48,40 @@ public class Launcher {
4848

4949
static final String LAUNCHER_VERSION = "2.12";
5050
static final MimetypesFileTypeMap mimeTypes = new MimetypesFileTypeMap();
51-
static Logger logger = Logger.getLogger(Launcher.class.getName());
51+
static final Logger logger = Logger.getLogger(Launcher.class.getName());
5252

5353
/**
5454
* @param args the command line arguments
5555
*/
5656
public static void main(final String[] args) throws OfficeNotFoundException {
57-
logger.log(Level.INFO,
58-
MessageUtil.getMessage("app.title") + " version " + LAUNCHER_VERSION);
59-
logger.log(Level.INFO, MessageUtil.getMessage("info.url.encoded") + args[0]);
57+
logger.log(Level.INFO, "{0} version {1}", new Object[]{MessageUtil.getMessage("app.title"), LAUNCHER_VERSION});
58+
logger.log(Level.INFO, "{0}{1}", new Object[]{MessageUtil.getMessage("info.url.encoded"), args[0]});
6059
try {
6160
String url = UrlExtractor.extractUrl(args[0]);
62-
logger.log(Level.INFO, MessageUtil.getMessage("info.url.decoded") + url);
61+
logger.log(Level.INFO, "{0}{1}", new Object[]{MessageUtil.getMessage("info.url.decoded"), url});
6362
if (args[1] != null && !"".equals(args[1].trim())) {
64-
logger.log(Level.INFO, MessageUtil.getMessage("info.default.path")
65-
+ ' ' + UrlExtractor.decodePath(args[1]));
63+
logger.log(Level.INFO, "{0} {2}", new Object[]{MessageUtil.getMessage("info.default.path"), UrlExtractor.decodePath(args[1])});
6664
MsOfficePathFinder.basePath = UrlExtractor.decodePath(args[1]);
6765
}
6866
AuthenticationInfo authInfo = null;
6967
if (args.length >= 4) {
7068
authInfo = PasswordManager.extractAuthenticationInfo(args[2], args[3]);
7169
}
7270
MsOfficeType contentType = getContentType(UrlExtractor.decodeUrl(args[0]));
73-
logger.log(Level.FINE, MessageUtil.getMessage("info.document.type")
74-
+ contentType);
71+
logger.log(Level.FINE, "{0}{1}", new Object[]{MessageUtil.getMessage("info.document.type"), contentType});
7572
defineLookAndFeel();
7673
System.exit(OfficeLauncher.launch(contentType, url, authInfo));
7774
} catch (IOException ex) {
7875
logger.log(Level.SEVERE, MessageUtil.getMessage("error.message.general"),
79-
ex);
76+
ex);
8077
MessageDisplayer.displayError(ex);
8178
} catch (InterruptedException ex) {
8279
logger.log(Level.SEVERE, MessageUtil.getMessage("error.message.general"),
83-
ex);
80+
ex);
8481
MessageDisplayer.displayError(ex);
8582
} catch (Throwable ex) {
8683
logger.log(Level.SEVERE, MessageUtil.getMessage("error.message.general"),
87-
ex);
84+
ex);
8885
MessageDisplayer.displayError(ex);
8986
} finally {
9087
System.exit(0);
@@ -94,7 +91,8 @@ public static void main(final String[] args) throws OfficeNotFoundException {
9491
protected static void defineLookAndFeel() {
9592
try {
9693
try {
97-
if (OsEnum.getOS() == OsEnum.WINDOWS_VISTA || OsEnum.getOS() == OsEnum.WINDOWS_XP) {
94+
if (OsEnum.getOS() == OsEnum.WINDOWS_VISTA || OsEnum.getOS() == OsEnum.WINDOWS_XP
95+
|| OsEnum.getOS() == OsEnum.WINDOWS_SEVEN) {
9896
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
9997
}
10098
} catch (ClassNotFoundException ex) {
@@ -110,7 +108,7 @@ protected static void defineLookAndFeel() {
110108
}
111109

112110
protected static MsOfficeType getContentType(String url)
113-
throws MalformedURLException {
111+
throws MalformedURLException {
114112
String fileName = new URL(url).getFile();
115113
String contentType = mimeTypes.getContentType(fileName.toLowerCase());
116114
return MsOfficeType.valueOfMimeType(contentType);

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

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

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

4545
/*
4646
* If user is under Windows vista and use MS Office 2007. Disconnected mode must be activated : 1)
@@ -50,9 +50,11 @@ public class OfficeLauncher {
5050
public static int launch(MsOfficeType type, String url, AuthenticationInfo authInfo)
5151
throws IOException, InterruptedException, OfficeNotFoundException {
5252
OfficeFinder finder = FinderFactory.getFinder(type);
53+
logger.log(Level.INFO, "Are we using Office 2007 : {0}", finder.isMicrosoftOffice2007());
54+
logger.log(Level.INFO, "We are on {0} OS", OsEnum.getOS());
5355
boolean modeDisconnected = (OsEnum.getOS() == OsEnum.WINDOWS_VISTA ||
5456
OsEnum.getOS() == OsEnum.WINDOWS_SEVEN ||OsEnum.getOS() == OsEnum.MAC_OSX)
55-
&& (finder.isMicrosoftOffice2007());
57+
&& finder.isMicrosoftOffice2007();
5658
switch (type) {
5759
case EXCEL:
5860
return launch(finder.findSpreadsheet(), url, modeDisconnected, authInfo);
@@ -78,9 +80,9 @@ public static int launch(MsOfficeType type, String url, AuthenticationInfo authI
7880
*/
7981
public static int launch(String path, String url, boolean modeDisconnected,
8082
AuthenticationInfo auth) throws IOException, InterruptedException {
81-
logger.log(Level.INFO, "The path: " + path);
82-
logger.log(Level.INFO, "The url: " + url);
83-
logger.log(Level.INFO, "The command line: " + path + ' ' + url);
83+
logger.log(Level.INFO, "The path: {0}", path);
84+
logger.log(Level.INFO, "The url: {0}", url);
85+
logger.log(Level.INFO, "The command line: {0} {1}", new Object[]{path, url});
8486
if (modeDisconnected) {
8587
try {
8688
String webdavUrl = url;
@@ -89,7 +91,7 @@ public static int launch(String path, String url, boolean modeDisconnected,
8991
webdavUrl = url.substring(1, url.length() - 1);
9092
}
9193
String tmpFilePath = webdavAccessManager.retrieveFile(webdavUrl);
92-
logger.log(Level.INFO, "The exact exec line: " + path + ' ' + tmpFilePath);
94+
logger.log(Level.INFO, "The exact exec line: {0} {1}", new Object[]{path, tmpFilePath});
9395
Process process = Runtime.getRuntime().exec(path + ' ' + tmpFilePath);
9496
process.waitFor();
9597
webdavAccessManager.pushFile(tmpFilePath, url);
@@ -104,7 +106,7 @@ public static int launch(String path, String url, boolean modeDisconnected,
104106
}
105107
} else {
106108
// Standard mode : just open it
107-
logger.log(Level.INFO, "The exact exec line: " + path + ' ' + url);
109+
logger.log(Level.INFO, "The exact exec line: {0} {2}", new Object[]{path, url});
108110
Process process = Runtime.getRuntime().exec(path + ' ' + url);
109111
return process.waitFor();
110112
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.silverpeas.openoffice.OfficeFinder;
3131
import com.silverpeas.openoffice.linux.WhereisHelper;
3232
import com.silverpeas.openoffice.macosx.MacOsOfficeFinder;
33-
import com.silverpeas.openoffice.macosx.WhereisMacHelper;
3433
import com.silverpeas.openoffice.windows.MsOfficeRegistryHelper;
3534
import com.silverpeas.openoffice.windows.WindowsOpenOfficeFinder;
3635

@@ -44,6 +43,7 @@ public static OfficeFinder getFinder(final MsOfficeType contentType) {
4443
switch (os) {
4544
case WINDOWS_XP:
4645
case WINDOWS_VISTA:
46+
case WINDOWS_SEVEN:
4747
if (contentType.isMsOfficeCompatible()) {
4848
return new MsOfficeRegistryHelper();
4949
}

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import com.silverpeas.openoffice.OfficeFinder;
3131
import com.silverpeas.openoffice.OfficeNotFoundException;
3232
import com.silverpeas.openoffice.util.RegistryKeyReader;
33+
import java.util.logging.Level;
34+
import java.util.logging.Logger;
3335
import java.util.regex.Matcher;
3436
import java.util.regex.Pattern;
3537

@@ -38,22 +40,27 @@
3840
*/
3941
public class MsOfficeRegistryHelper implements OfficeFinder {
4042

41-
static final OfficeFinder msOfficeFinder = new MsOfficePathFinder();
43+
static final Logger logger = Logger.getLogger(MsOfficeRegistryHelper.class.getName());
4244

45+
static final OfficeFinder msOfficeFinder = new MsOfficePathFinder();
4346
static final String ACCESS = "Access.Application";
4447
static final String EXCEL = "Excel.Application";
4548
static final String OUTLOOK = "Outlook.Application";
4649
static final String POWERPOINT = "Powerpoint.Application";
4750
static final String WORD = "Word.Application";
4851
static final String FRONTPAGE = "FrontPage.Application";
4952
static final String BASE_APPLICATION_KEY =
50-
"\"HKEY_LOCAL_MACHINE\\Software\\Classes\\";
53+
"\"HKEY_LOCAL_MACHINE\\Software\\Classes\\";
5154
static final String BASE_KEY_CLSID =
52-
"\"HKEY_LOCAL_MACHINE\\Software\\Classes\\CLSID\\";
55+
"\"HKEY_LOCAL_MACHINE\\Software\\Classes\\CLSID\\";
5356
static final Pattern AUTOMATION = Pattern.compile(
54-
"\\s*/[aA][uU][tT][oO][mM][aA][tT][iI][oO][nN]\\s*");
55-
static final String BASE_MSOFFICE_2007_KEY =
56-
"\"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Office\\12.0\" /ve";
57+
"\\s*/[aA][uU][tT][oO][mM][aA][tT][iI][oO][nN]\\s*");
58+
static final String BASE_MSOFFICE_WORD_2007_KEY =
59+
"\"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Office\\12.0\\Word\\InstallRoot\" /ve";
60+
static final String BASE_MSOFFICE_EXCEL_2007_KEY =
61+
"\"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Office\\12.0\\Excel\\InstallRoot\" /ve";
62+
static final String BASE_MSOFFICE_POWERPOINT_2007_KEY =
63+
"\"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Office\\12.0\\PowerPoint\\InstallRoot\" /ve";
5764

5865
protected String getClsid(String type) {
5966
return RegistryKeyReader.readKey(BASE_APPLICATION_KEY + type + "\\CLSID\"");
@@ -62,8 +69,8 @@ protected String getClsid(String type) {
6269
protected String getPath(String type) {
6370
String clsid = getClsid(type);
6471
if (clsid != null) {
65-
String path = RegistryKeyReader.readKey(BASE_KEY_CLSID + clsid +
66-
"\\LocalServer32\"");
72+
String path = RegistryKeyReader.readKey(BASE_KEY_CLSID + clsid
73+
+ "\\LocalServer32\"");
6774
if (path != null) {
6875
return '"' + extractPath(path) + '"';
6976
}
@@ -116,7 +123,11 @@ public String findOther() throws OfficeNotFoundException {
116123

117124
@Override
118125
public boolean isMicrosoftOffice2007() {
119-
return (RegistryKeyReader.readKey(BASE_MSOFFICE_2007_KEY) != null);
126+
logger.log(Level.INFO, "Are we using Word 2007 : {0}", RegistryKeyReader.readKey(BASE_MSOFFICE_WORD_2007_KEY) != null);
127+
logger.log(Level.INFO, "Are we using Excel 2007 : {0}", RegistryKeyReader.readKey(BASE_MSOFFICE_EXCEL_2007_KEY) != null);
128+
logger.log(Level.INFO, "Are we using Powerpoint 2007 : {0}", RegistryKeyReader.readKey(BASE_MSOFFICE_POWERPOINT_2007_KEY) != null);
129+
return (RegistryKeyReader.readKey(BASE_MSOFFICE_WORD_2007_KEY) != null
130+
|| RegistryKeyReader.readKey(BASE_MSOFFICE_EXCEL_2007_KEY) != null
131+
|| RegistryKeyReader.readKey(BASE_MSOFFICE_POWERPOINT_2007_KEY) != null);
120132
}
121-
122133
}

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,37 @@
4141
public class WindowsOpenOfficeFinder extends OpenOfficeFinder {
4242

4343
static final Logger logger = Logger.getLogger(WindowsOpenOfficeFinder.class.getName());
44-
private static final String[] VERSIONS = new String[] { "3.2", "3.1", "3.0", "2.4",
45-
"2.3" };
44+
private static final String[] VERSIONS = new String[]{"3.2", "3.1", "3.0", "2.4",
45+
"2.3"};
4646
private static final String GLOBAL_OPEN_OFFICE_FOLDER =
47-
"\"HKEY_LOCAL_MACHINE\\SOFTWARE\\OpenOffice.org\\OpenOffice.org\\";
47+
"\"HKEY_LOCAL_MACHINE\\SOFTWARE\\OpenOffice.org\\OpenOffice.org\\";
4848
private static final String LOCAL_OPEN_OFFICE_FOLDER =
49-
"\"HKEY_CURRENT_USER\\SOFTWARE\\OpenOffice.org\\OpenOffice.org\\";
49+
"\"HKEY_CURRENT_USER\\SOFTWARE\\OpenOffice.org\\OpenOffice.org\\";
5050

5151
public String getOpenOfficePath(String version) {
5252
String key = null;
5353
try {
54-
key = RegistryKeyReader.readKey(LOCAL_OPEN_OFFICE_FOLDER + version +
55-
"\" /v Path");
54+
key = RegistryKeyReader.readKey(LOCAL_OPEN_OFFICE_FOLDER + version
55+
+ "\" /v Path");
5656
if (key == null) {
57-
key = RegistryKeyReader.readKey(GLOBAL_OPEN_OFFICE_FOLDER + version +
58-
"\" /v Path");
57+
key = RegistryKeyReader.readKey(GLOBAL_OPEN_OFFICE_FOLDER + version
58+
+ "\" /v Path");
5959
}
6060
} catch (Exception e) {
61-
logger.log(Level.SEVERE, MessageUtil.getMessage("error.reading.registry"),
62-
e);
61+
logger.log(Level.SEVERE, MessageUtil.getMessage("error.reading.registry"), e);
6362
}
6463
return key;
6564
}
6665

6766
@Override
6867
public String findOpenOffice() throws OpenOfficeNotFoundException {
6968
for (String version : VERSIONS) {
70-
logger.log(Level.FINE, MessageUtil.getMessage("info.openoffice.search") +
71-
MessageUtil.getMessage("info.openoffice.version") + version);
69+
logger.log(Level.FINE, "{0}{1}{2}", new Object[]{MessageUtil.getMessage(
70+
"info.openoffice.search"), MessageUtil.getMessage("info.openoffice.version"), version});
7271
String result = getOpenOfficePath(version);
7372
if (result != null) {
74-
logger.log(Level.FINE, MessageUtil.getMessage("info.openoffice.version")
75-
+ version + ' ' + MessageUtil.getMessage("info.openoffice.found"));
73+
logger.log(Level.FINE, "{0}{1}{2}{3}", new Object[]{MessageUtil.getMessage(
74+
"info.openoffice.version"), version, ' ', MessageUtil.getMessage("info.openoffice.found")});
7675
return '"' + result + '"';
7776
}
7877
}

src/main/java/com/silverpeas/openoffice/windows/webdav/WebdavManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
public class WebdavManager {
6666

6767
private HttpClient client;
68-
static Logger logger = Logger.getLogger(
69-
WebdavManager.class.getName());
68+
static final Logger logger = Logger.getLogger(WebdavManager.class.getName());
7069

7170
/**
7271
* Prepare HTTP connections to the WebDav server
@@ -102,7 +101,7 @@ public WebdavManager(String host, String login, String password) {
102101
public String lockFile(URI uri, String login) throws IOException {
103102
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.locking")
104103
+ ' ' + uri.getEscapedURI());
105-
// Let's lock the file
104+
// Let's lock the file
106105
LockMethod lockMethod = new LockMethod(uri.getEscapedURI(),
107106
Scope.EXCLUSIVE, Type.WRITE, login, 600000l, false);
108107
client.executeMethod(lockMethod);
@@ -196,7 +195,7 @@ public String getFile(URI uri, String lockToken) throws IOException {
196195
* @throws IOException
197196
*/
198197
public void putFile(URI uri, String localFilePath, String lockToken) throws IOException {
199-
// Checks if file still exists
198+
// Checks if file still exists
200199
try {
201200
executeGetFile(uri);
202201
} catch (IOException ioex) {

0 commit comments

Comments
 (0)