Skip to content

Commit b855a45

Browse files
author
Emmanuel Hugonnet
committed
Refactoring the code
Updating the parent version Synchronizing the version with Silverpeas version for easier tracability
1 parent c8bc403 commit b855a45

40 files changed

+164
-138
lines changed

pom.xml

Lines changed: 2 additions & 8 deletions
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>23</version>
7+
<version>24</version>
88
</parent>
99
<scm>
1010
<connection>scm:git:git@github.com:Silverpeas/OfficeOnline.git</connection>
@@ -16,7 +16,7 @@
1616
<groupId>com.silverpeas.services</groupId>
1717
<artifactId>office-online</artifactId>
1818
<packaging>jar</packaging>
19-
<version>5.5-SNAPSHOT</version>
19+
<version>5.11.1-SNAPSHOT</version>
2020
<name>Online Office Editor</name>
2121
<build>
2222
<finalName>OpenOfficeLauncher</finalName>
@@ -65,12 +65,6 @@
6565
<artifactId>commons-collections</artifactId>
6666
<groupId>commons-collections</groupId>
6767
</exclusion>
68-
<!--
69-
<exclusion>
70-
<artifactId>jackrabbit-jcr-commons</artifactId>
71-
<groupId>org.apache.jackrabbit</groupId>
72-
</exclusion>
73-
-->
7468
</exclusions>
7569
</dependency>
7670
<dependency>

src/main/java/com/silverpeas/openoffice/AuthenticationInfo.java renamed to src/main/java/org/silverpeas/openoffice/AuthenticationInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2323
*/
2424

25-
package com.silverpeas.openoffice;
25+
package org.silverpeas.openoffice;
2626

2727
import java.util.Arrays;
2828

src/main/java/com/silverpeas/openoffice/Launcher.java renamed to src/main/java/org/silverpeas/openoffice/Launcher.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2323
*/
2424

25-
package com.silverpeas.openoffice;
25+
package org.silverpeas.openoffice;
2626

27-
import com.silverpeas.openoffice.util.MessageDisplayer;
28-
import com.silverpeas.openoffice.util.MessageUtil;
29-
import com.silverpeas.openoffice.util.MsOfficeType;
30-
import com.silverpeas.openoffice.util.OsEnum;
31-
import com.silverpeas.openoffice.util.PasswordManager;
32-
import com.silverpeas.openoffice.util.UrlExtractor;
33-
import com.silverpeas.openoffice.windows.MsOfficePathFinder;
27+
import org.silverpeas.openoffice.util.MessageDisplayer;
28+
import org.silverpeas.openoffice.util.MessageUtil;
29+
import org.silverpeas.openoffice.util.MsOfficeType;
30+
import org.silverpeas.openoffice.util.OsEnum;
31+
import org.silverpeas.openoffice.util.PasswordManager;
32+
import org.silverpeas.openoffice.util.UrlExtractor;
33+
import org.silverpeas.openoffice.windows.MsOfficePathFinder;
3434
import java.io.IOException;
3535
import java.net.MalformedURLException;
3636
import java.net.URL;
@@ -48,9 +48,10 @@ public class Launcher {
4848
static final String LAUNCHER_VERSION = "2.12";
4949
static final MimetypesFileTypeMap mimeTypes = new MimetypesFileTypeMap();
5050
static final Logger logger = Logger.getLogger(Launcher.class.getName());
51-
51+
5252
/**
5353
* @param args the command line arguments
54+
* @throws OfficeNotFoundException
5455
*/
5556
public static void main(final String[] args) throws OfficeNotFoundException {
5657
logger.log(Level.INFO, "{0} version {1}", new Object[] { MessageUtil.getMessage("app.title"),
@@ -70,14 +71,17 @@ public static void main(final String[] args) throws OfficeNotFoundException {
7071
if (args.length >= 4) {
7172
authInfo = PasswordManager.extractAuthenticationInfo(args[2], args[3]);
7273
}
74+
boolean useDeconnectedMode = false;
75+
if(args.length >= 5) {
76+
useDeconnectedMode = getBooleanValue(args[4]);
77+
}
7378
MsOfficeType contentType = getContentType(UrlExtractor.decodeUrl(args[0]));
7479
logger.log(Level.FINE, "{0}{1}", new Object[] { MessageUtil.getMessage("info.document.type"),
7580
contentType });
7681
defineLookAndFeel();
77-
System.exit(OfficeLauncher.launch(contentType, url, authInfo));
82+
System.exit(OfficeLauncher.launch(contentType, url, authInfo, useDeconnectedMode));
7883
} catch (IOException ex) {
79-
logger.log(Level.SEVERE, MessageUtil.getMessage("error.message.general"),
80-
ex);
84+
logger.log(Level.SEVERE, MessageUtil.getMessage("error.message.general"), ex);
8185
MessageDisplayer.displayError(ex);
8286
} catch (InterruptedException ex) {
8387
logger.log(Level.SEVERE, MessageUtil.getMessage("error.message.general"),
@@ -91,6 +95,12 @@ public static void main(final String[] args) throws OfficeNotFoundException {
9195
System.exit(0);
9296
}
9397
}
98+
99+
protected static boolean getBooleanValue(final String expression) {
100+
return "true".equalsIgnoreCase(expression) || "yes".equalsIgnoreCase(expression)
101+
|| "y".equalsIgnoreCase(expression) || "oui".equalsIgnoreCase(expression)
102+
|| "1".equalsIgnoreCase(expression);
103+
}
94104

95105
protected static void defineLookAndFeel() {
96106
try {
@@ -111,8 +121,7 @@ protected static void defineLookAndFeel() {
111121
}
112122
}
113123

114-
protected static MsOfficeType getContentType(String url)
115-
throws MalformedURLException {
124+
protected static MsOfficeType getContentType(String url) throws MalformedURLException {
116125
String fileName = new URL(url).getFile();
117126
String contentType = mimeTypes.getContentType(fileName.toLowerCase());
118127
return MsOfficeType.valueOfMimeType(contentType);

src/main/java/com/silverpeas/openoffice/MsOfficeNotFoundException.java renamed to src/main/java/org/silverpeas/openoffice/MsOfficeNotFoundException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* To change this template, choose Tools | Templates
2727
* and open the template in the editor.
2828
*/
29-
package com.silverpeas.openoffice;
29+
package org.silverpeas.openoffice;
3030

3131
/**
3232
* @author Emmanuel Hugonnet

src/main/java/com/silverpeas/openoffice/OfficeFinder.java renamed to src/main/java/org/silverpeas/openoffice/OfficeFinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* To change this template, choose Tools | Templates
2727
* and open the template in the editor.
2828
*/
29-
package com.silverpeas.openoffice;
29+
package org.silverpeas.openoffice;
3030

3131
/**
3232
* @author Emmanuel Hugonnet
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,67 @@
11
/**
22
* Copyright (C) 2000 - 2009 Silverpeas
33
*
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.
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.
87
*
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:
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:
1412
* "http://repository.silverpeas.com/legal/licensing"
1513
*
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.
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.
2017
*
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/>.
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/>.
2320
*/
21+
package org.silverpeas.openoffice;
2422

25-
package com.silverpeas.openoffice;
26-
27-
import com.silverpeas.openoffice.windows.FileWebDavAccessManager;
28-
import com.silverpeas.openoffice.util.MessageUtil;
29-
import com.silverpeas.openoffice.util.MessageDisplayer;
3023
import java.io.IOException;
3124
import java.util.logging.Level;
3225
import java.util.logging.Logger;
3326

34-
import com.silverpeas.openoffice.util.FinderFactory;
35-
import com.silverpeas.openoffice.util.MsOfficeType;
36-
import com.silverpeas.openoffice.util.OsEnum;
3727
import org.apache.commons.httpclient.HttpException;
3828

29+
import org.silverpeas.openoffice.util.FinderFactory;
30+
import org.silverpeas.openoffice.util.MessageDisplayer;
31+
import org.silverpeas.openoffice.util.MessageUtil;
32+
import org.silverpeas.openoffice.util.MsOfficeType;
33+
import org.silverpeas.openoffice.util.OsEnum;
34+
import org.silverpeas.openoffice.windows.FileWebDavAccessManager;
35+
3936
/**
4037
* @author Emmanuel Hugonnet
4138
*/
4239
public class OfficeLauncher {
4340

4441
static final Logger logger = Logger.getLogger(OfficeLauncher.class.getName());
4542

46-
/*
47-
* If user is under Windows vista and use MS Office 2007. Disconnected mode must be activated : 1)
48-
* download file using webdav to local temp directory 2) open it 3) after close, send it back to
49-
* silverpeas, still using webdav 4) delete temp file locally
43+
/**
44+
* Launch the document editor.
45+
* @param type type of editor for the document (word editor, presentation editor, etc.)
46+
* @param url the url to the document.
47+
* @param authInfo authentication parameters
48+
* @param useDeconnectedMode : set to true if you want to activate the Disconnected mode :
49+
* 1) download file using webdav to local temp directory
50+
* 2) open it
51+
* 3) after close, send it back to silverpeas, still using webdav
52+
* 4) delete temp file locally
53+
* @return the result of the process.
54+
* @throws IOException
55+
* @throws InterruptedException
56+
* @throws OfficeNotFoundException
5057
*/
51-
public static int launch(MsOfficeType type, String url, AuthenticationInfo authInfo)
52-
throws IOException, InterruptedException, OfficeNotFoundException {
58+
public static int launch(MsOfficeType type, String url, AuthenticationInfo authInfo,
59+
boolean useDeconnectedMode) throws IOException, InterruptedException, OfficeNotFoundException {
5360
OfficeFinder finder = FinderFactory.getFinder(type);
5461
logger.log(Level.INFO, "Are we using Office 2007 : {0}", finder.isMicrosoftOffice());
5562
logger.log(Level.INFO, "We are on {0} OS", OsEnum.getOS());
56-
boolean modeDisconnected = (OsEnum.isWindows() || OsEnum.getOS() == OsEnum.MAC_OSX)
57-
&& finder.isMicrosoftOffice();
63+
boolean modeDisconnected = ((OsEnum.isWindows() && useDeconnectedMode) || OsEnum.getOS()
64+
== OsEnum.MAC_OSX) && finder.isMicrosoftOffice();
5865
switch (type) {
5966
case EXCEL:
6067
return launch(finder.findSpreadsheet(), url, modeDisconnected, authInfo);
@@ -70,9 +77,10 @@ public static int launch(MsOfficeType type, String url, AuthenticationInfo authI
7077

7178
/**
7279
* Launch document edition
80+
*
7381
* @param path path to editor
7482
* @param url document url
75-
* @param modeDisconnected disconnected mode (used under vista + MS Office 2007)
83+
* @param modeDisconnected disconnected mode.
7684
* @param auth authentication info
7785
* @return status
7886
* @throws IOException
@@ -82,7 +90,7 @@ public static int launch(String path, String url, boolean modeDisconnected,
8290
AuthenticationInfo auth) throws IOException, InterruptedException {
8391
logger.log(Level.INFO, "The path: {0}", path);
8492
logger.log(Level.INFO, "The url: {0}", url);
85-
logger.log(Level.INFO, "The command line: {0} {1}", new Object[] { path, url });
93+
logger.log(Level.INFO, "The command line: {0} {1}", new Object[]{path, url});
8694
if (modeDisconnected) {
8795
try {
8896
String webdavUrl = url;
@@ -91,7 +99,7 @@ public static int launch(String path, String url, boolean modeDisconnected,
9199
webdavUrl = url.substring(1, url.length() - 1);
92100
}
93101
String tmpFilePath = webdavAccessManager.retrieveFile(webdavUrl);
94-
logger.log(Level.INFO, "The exact exec line: {0} {1}", new Object[] { path, tmpFilePath });
102+
logger.log(Level.INFO, "The exact exec line: {0} {1}", new Object[]{path, tmpFilePath});
95103
Process process = Runtime.getRuntime().exec(path + ' ' + tmpFilePath);
96104
process.waitFor();
97105
webdavAccessManager.pushFile(tmpFilePath, url);
@@ -106,9 +114,12 @@ public static int launch(String path, String url, boolean modeDisconnected,
106114
}
107115
} else {
108116
// Standard mode : just open it
109-
logger.log(Level.INFO, "The exact exec line: {0} {2}", new Object[] { path, url });
117+
logger.log(Level.INFO, "The exact exec line: {0} {2}", new Object[]{path, url});
110118
Process process = Runtime.getRuntime().exec(path + ' ' + url);
111119
return process.waitFor();
112120
}
113121
}
122+
123+
private OfficeLauncher() {
124+
}
114125
}

src/main/java/com/silverpeas/openoffice/OfficeNotFoundException.java renamed to src/main/java/org/silverpeas/openoffice/OfficeNotFoundException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* To change this template, choose Tools | Templates
2727
* and open the template in the editor.
2828
*/
29-
package com.silverpeas.openoffice;
29+
package org.silverpeas.openoffice;
3030

3131
/**
3232
* @author Emmanuel Hugonnet

src/main/java/com/silverpeas/openoffice/OpenOfficeFinder.java renamed to src/main/java/org/silverpeas/openoffice/OpenOfficeFinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* To change this template, choose Tools | Templates
2727
* and open the template in the editor.
2828
*/
29-
package com.silverpeas.openoffice;
29+
package org.silverpeas.openoffice;
3030

3131
/**
3232
* @author Emmanuel Hugonnet

src/main/java/com/silverpeas/openoffice/OpenOfficeLauncher.java renamed to src/main/java/org/silverpeas/openoffice/OpenOfficeLauncher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* To change this template, choose Tools | Templates
2727
* and open the template in the editor.
2828
*/
29-
package com.silverpeas.openoffice;
29+
package org.silverpeas.openoffice;
3030

3131
import java.io.IOException;
3232
import java.util.logging.Level;

src/main/java/com/silverpeas/openoffice/OpenOfficeNotFoundException.java renamed to src/main/java/org/silverpeas/openoffice/OpenOfficeNotFoundException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* To change this template, choose Tools | Templates
2727
* and open the template in the editor.
2828
*/
29-
package com.silverpeas.openoffice;
29+
package org.silverpeas.openoffice;
3030

3131
/**
3232
* @author Emmanuel Hugonnet

src/main/java/com/silverpeas/openoffice/linux/WhereisHelper.java renamed to src/main/java/org/silverpeas/openoffice/linux/WhereisHelper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
* To change this template, choose Tools | Templates
2727
* and open the template in the editor.
2828
*/
29-
package com.silverpeas.openoffice.linux;
29+
package org.silverpeas.openoffice.linux;
3030

31-
import com.silverpeas.openoffice.OpenOfficeFinder;
32-
import com.silverpeas.openoffice.OpenOfficeNotFoundException;
31+
import org.silverpeas.openoffice.OpenOfficeFinder;
32+
import org.silverpeas.openoffice.OpenOfficeNotFoundException;
3333
import java.io.IOException;
3434
import java.util.logging.Level;
3535
import java.util.logging.Logger;
36-
import com.silverpeas.openoffice.util.StreamReader;
36+
37+
import org.silverpeas.openoffice.util.StreamReader;
3738

3839
/**
3940
* @author Emmanuel Hugonnet

src/main/java/com/silverpeas/openoffice/macosx/MacOsOfficeFinder.java renamed to src/main/java/org/silverpeas/openoffice/macosx/MacOsOfficeFinder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
* To change this template, choose Tools | Templates
2424
* and open the template in the editor.
2525
*/
26-
package com.silverpeas.openoffice.macosx;
26+
package org.silverpeas.openoffice.macosx;
2727

28-
import com.silverpeas.openoffice.OfficeFinder;
29-
import com.silverpeas.openoffice.OfficeNotFoundException;
30-
import com.silverpeas.openoffice.OpenOfficeFinder;
28+
import org.silverpeas.openoffice.OfficeFinder;
29+
import org.silverpeas.openoffice.OfficeNotFoundException;
30+
import org.silverpeas.openoffice.OpenOfficeFinder;
3131
import java.io.File;
3232
import java.util.logging.Level;
3333
import java.util.logging.Logger;

src/main/java/com/silverpeas/openoffice/macosx/PlistHelper.java renamed to src/main/java/org/silverpeas/openoffice/macosx/PlistHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* To change this template, choose Tools | Templates
2727
* and open the template in the editor.
2828
*/
29-
package com.silverpeas.openoffice.macosx;
29+
package org.silverpeas.openoffice.macosx;
3030

3131
import java.io.IOException;
3232
import java.util.logging.Level;

src/main/java/com/silverpeas/openoffice/macosx/WhereisMacHelper.java renamed to src/main/java/org/silverpeas/openoffice/macosx/WhereisMacHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
* To change this template, choose Tools | Templates
2727
* and open the template in the editor.
2828
*/
29-
package com.silverpeas.openoffice.macosx;
29+
package org.silverpeas.openoffice.macosx;
3030

3131
import java.io.IOException;
3232
import java.util.logging.Level;
3333
import java.util.logging.Logger;
3434

35-
import com.silverpeas.openoffice.OpenOfficeFinder;
36-
import com.silverpeas.openoffice.OpenOfficeNotFoundException;
37-
import com.silverpeas.openoffice.util.StreamReader;
35+
import org.silverpeas.openoffice.OpenOfficeFinder;
36+
import org.silverpeas.openoffice.OpenOfficeNotFoundException;
37+
import org.silverpeas.openoffice.util.StreamReader;
3838

3939
/**
4040
* @author Emmanuel Hugonnet

src/main/java/com/silverpeas/openoffice/util/DirectoryFilter.java renamed to src/main/java/org/silverpeas/openoffice/util/DirectoryFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* and open the template in the editor.
2828
*/
2929

30-
package com.silverpeas.openoffice.util;
30+
package org.silverpeas.openoffice.util;
3131

3232
import java.io.File;
3333
import java.io.FileFilter;

0 commit comments

Comments
 (0)