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

Commit 8738c1d

Browse files
author
Emmanuel Hugonnet
committed
Managing space for openoffice
git-svn-id: https://www.silverpeas.org/svn/silverpeas/services/office-online/trunk@224 a8e77078-a1c7-4fa5-b8fc-53c5178a176c
1 parent e18fa49 commit 8738c1d

File tree

9 files changed

+37
-18
lines changed

9 files changed

+37
-18
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
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-
/*
25-
* To change this template, choose Tools | Templates
26-
* and open the template in the editor.
27-
*/
2824
package com.silverpeas.openoffice;
2925

3026
import com.silverpeas.openoffice.util.MessageDisplayer;
@@ -41,7 +37,6 @@
4137
import com.silverpeas.openoffice.util.PasswordManager;
4238
import com.silverpeas.openoffice.util.UrlExtractor;
4339
import com.silverpeas.openoffice.windows.MsOfficePathFinder;
44-
import java.io.File;
4540

4641
/**
4742
*

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
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-
/*
25-
* To change this template, choose Tools | Templates
26-
* and open the template in the editor.
27-
*/
2824
package com.silverpeas.openoffice;
2925

3026
import com.silverpeas.openoffice.windows.FileWebDavAccessManager;
@@ -36,6 +32,7 @@
3632
import com.silverpeas.openoffice.util.FinderFactory;
3733
import com.silverpeas.openoffice.util.MsOfficeType;
3834
import com.silverpeas.openoffice.util.OsEnum;
35+
import com.silverpeas.openoffice.util.UrlExtractor;
3936
import org.apache.commons.httpclient.HttpException;
4037

4138
/**
@@ -59,7 +56,7 @@ public class OfficeLauncher {
5956
public static int launch(MsOfficeType type, String url,
6057
AuthenticationInfo authInfo) throws IOException,
6158
InterruptedException, OfficeNotFoundException {
62-
OfficeFinder finder = FinderFactory.getFinder(type);
59+
OfficeFinder finder = FinderFactory.getFinder(type);
6360
boolean modeDisconnected = (OsEnum.getOS() ==
6461
OsEnum.WINDOWS_VISTA || OsEnum.getOS() ==
6562
OsEnum.MAC_OSX) && (finder.isMicrosoftOffice2007());
@@ -115,6 +112,7 @@ public static int launch(String path, String url, boolean modeDisconnected,
115112
}
116113
} else {
117114
//Standard mode : just open it
115+
logger.log(Level.INFO, "The exact exec line: " + path + ' ' + url);
118116
Process process = Runtime.getRuntime().exec(path + ' ' + url);
119117
return process.waitFor();
120118
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ public String findOther() throws OfficeNotFoundException {
5757
public boolean isMicrosoftOffice2007() {
5858
return false;
5959
}
60-
60+
6161
public abstract String findOpenOffice() throws OfficeNotFoundException;
6262
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@
2828
package com.silverpeas.openoffice;
2929

3030
import java.io.IOException;
31+
import java.util.logging.Level;
32+
import java.util.logging.Logger;
3133

3234
/**
3335
*
3436
* @author Emmanuel Hugonnet
3537
*/
3638
public class OpenOfficeLauncher {
3739

40+
static Logger logger = Logger.getLogger(OfficeLauncher.class.getName());
41+
3842
public static int launch(String path, String url)
3943
throws IOException, InterruptedException {
44+
logger.log(Level.INFO, "The exact exec line: " + '"' + path + "\" " + url);
4045
Process process = Runtime.getRuntime().exec('"' + path + "\" " + url);
4146
return process.waitFor();
4247
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,5 @@ protected boolean isMsOfficePresent() {
8686
File officeDir = new File(OFFICE_PATH);
8787
return officeDir.exists();
8888
}
89+
8990
}

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static String decodeUrl(String encodedUrl) {
5959
}
6060

6161
/**
62-
* Escape the rl to manage whitespaces.
62+
* Escape the url to manage whitespaces.
6363
* If we are on Windows the url is surrounded with quotes.
6464
* If we are on Unix the whitespaces are escaped with %20.
6565
* @param url the url with whitespaces.
@@ -70,15 +70,26 @@ public static String escapeUrl(String url) {
7070
switch (os) {
7171
case WINDOWS_XP:
7272
case WINDOWS_VISTA:
73-
return '"' + url + '"';
73+
return '"' + escapeWhiteSpaces(url) + '"';
7474
case LINUX:
7575
case MAC_OSX:
76-
return url.replaceAll(" ", "%20");
76+
return escapeWhiteSpaces(url);
7777
default:
78-
return url.replaceAll(" ", "%20");
78+
return escapeWhiteSpaces(url);
7979
}
8080
}
8181

82+
/**
83+
* Escape the url to manage whitespaces.
84+
* If we are on Windows the url is surrounded with quotes.
85+
* If we are on Unix the whitespaces are escaped with %20.
86+
* @param url the url with whitespaces.
87+
* @return the url with whitespaces escaped.
88+
*/
89+
public static String escapeWhiteSpaces(String url) {
90+
return url.replaceAll(" ", "%20");
91+
}
92+
8293
/**
8394
* Decode and espace whitespaces from the url.
8495
* @param encodedUrl the genuine encoded url.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
*/
3939
public class MsOfficePathFinder implements OfficeFinder {
4040

41+
private boolean isOpenOffice = true;
4142
static final OpenOfficeFinder openOffice = new WindowsOpenOfficeFinder();
4243
public static String basePath = "C:\\Program Files\\Microsoft Office\\OFFICE11";
4344
private static final String EXCEL = "EXCEL.EXE";
@@ -50,29 +51,36 @@ public MsOfficePathFinder() {
5051
@Override
5152
public String findSpreadsheet() throws OfficeNotFoundException {
5253
if (exists(EXCEL)) {
54+
isOpenOffice = false;
5355
return basePath + File.separator + EXCEL;
5456
}
57+
isOpenOffice = true;
5558
return openOffice.findSpreadsheet();
5659
}
5760

5861
@Override
5962
public String findPresentation() throws OfficeNotFoundException {
6063
if (exists(POWERPOINT)) {
64+
isOpenOffice = false;
6165
return basePath + File.separator + POWERPOINT;
6266
}
67+
isOpenOffice = true;
6368
return openOffice.findPresentation();
6469
}
6570

6671
@Override
6772
public String findWordEditor() throws OfficeNotFoundException {
6873
if (exists(WORDS)) {
74+
isOpenOffice = false;
6975
return basePath + File.separator + WORDS + " /m";
7076
}
77+
isOpenOffice = true;
7178
return openOffice.findWordEditor();
7279
}
7380

7481
@Override
7582
public String findOther() throws OfficeNotFoundException {
83+
isOpenOffice = true;
7684
return openOffice.findOther();
7785
}
7886

@@ -85,4 +93,5 @@ protected boolean exists(String exe) {
8593
File executable = new File(basePath, exe);
8694
return executable.exists() && executable.isFile();
8795
}
96+
8897
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import com.silverpeas.openoffice.OfficeFinder;
3131
import com.silverpeas.openoffice.OfficeNotFoundException;
32-
import com.silverpeas.openoffice.OpenOfficeFinder;
3332
import com.silverpeas.openoffice.util.RegistryKeyReader;
3433
import java.util.regex.Matcher;
3534
import java.util.regex.Pattern;
@@ -120,4 +119,5 @@ public String findOther() throws OfficeNotFoundException {
120119
public boolean isMicrosoftOffice2007() {
121120
return (RegistryKeyReader.readKey(BASE_MSOFFICE_2007_KEY) != null);
122121
}
122+
123123
}

src/test/java/com/silverpeas/openoffice/util/UrlExtractorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void testDecodeUrl() {
6464
*/
6565
public void testEscapeUrl() {
6666
String url = "http://dsr-preprod-3/silverpeas/repository/jackrabbit/attachments/kmelia34/Attachment/Images/44733/Atelier en classe.doc";
67-
String expResult = "\"http://dsr-preprod-3/silverpeas/repository/jackrabbit/attachments/kmelia34/Attachment/Images/44733/Atelier en classe.doc\"";
67+
String expResult = "\"http://dsr-preprod-3/silverpeas/repository/jackrabbit/attachments/kmelia34/Attachment/Images/44733/Atelier%20en%20classe.doc\"";
6868
String expResultUnix = "http://dsr-preprod-3/silverpeas/repository/jackrabbit/attachments/kmelia34/Attachment/Images/44733/Atelier%20en%20classe.doc";
6969
System.setProperty("os.name", "Windows XP");
7070
String result = UrlExtractor.escapeUrl(url);
@@ -80,7 +80,7 @@ public void testEscapeUrl() {
8080
public void testExtractUrl() {
8181
System.setProperty("os.name", "Windows XP");
8282
String encodedUrl = "http%3A%2F%2Fdsr-preprod-3%2Fsilverpeas%2Frepository%2Fjackrabbit%2Fattachments%2Fkmelia34%2FAttachment%2FImages%2F44733%2FAtelier+en+classe.doc";
83-
String expResult = "\"http://dsr-preprod-3/silverpeas/repository/jackrabbit/attachments/kmelia34/Attachment/Images/44733/Atelier en classe.doc\"";
83+
String expResult = "\"http://dsr-preprod-3/silverpeas/repository/jackrabbit/attachments/kmelia34/Attachment/Images/44733/Atelier%20en%20classe.doc\"";
8484
String result = UrlExtractor.extractUrl(encodedUrl);
8585
assertEquals(expResult, result);
8686
}

0 commit comments

Comments
 (0)