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

Commit 3e772dd

Browse files
committed
Take into account the changes in the authentication is performed to access by WebDAV the content of the JCR repository in Silverpeas
1 parent cd2a7d9 commit 3e772dd

File tree

10 files changed

+319
-185
lines changed

10 files changed

+319
-185
lines changed

.gitignore

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
.idea
2+
*.iws
3+
*.ipr
4+
*.iml
5+
*.merge*
6+
catalog.xml
7+
target
8+
.settings
9+
.classpath
10+
.project
11+
.idea
12+
.sonar-ide.properties
113
nbactions.xml
214
nb-configuration.xml
3-
/target/
15+
nbactions.xml
16+
/web-core/src/main/java/META-INF
17+
/war-core/src/main/webapp/META-INF
18+
/ejb-core/channels/src/main/resources/META-INF/MANIFEST.MF
19+
/ejb-core/pdc/src/main/resources/META-INF/MANIFEST.MF
20+
/ejb-core/publication/src/main/resources/META-INF/MANIFEST.MF
21+
/ejb-core/node/src/main/resources/META-INF/MANIFEST.MF
22+
/ejb-core/versioning/src/main/resources/META-INF/MANIFEST.MF
23+
/ejb-core/calendar/src/main/resources/META-INF/MANIFEST.MF
24+
/ejb-core/questioncontainer/src/main/resources/META-INF/MANIFEST.MF
25+
web-core/@ErrorDir@/
26+
27+
/ejb-core/formtemplate/src/main/resources/META-INF/MANIFEST.MF
28+
/ejb-core/searchengine/src/main/resources/META-INF/MANIFEST.MF
29+
/ejb-core/statistic/src/main/resources/META-INF/MANIFEST.MF
30+
/ejb-core/silverstatistics/src/main/resources/META-INF/MANIFEST.MF

pom.xml

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<parent>
5-
<groupId>com.silverpeas</groupId>
5+
<groupId>org.silverpeas</groupId>
66
<artifactId>parent</artifactId>
7-
<version>26</version>
7+
<version>28-SNAPSHOT</version>
88
</parent>
99
<scm>
1010
<connection>scm:git:git@github.com:Silverpeas/OfficeOnline.git</connection>
@@ -13,32 +13,25 @@
1313
<tag>HEAD</tag>
1414
</scm>
1515

16-
<groupId>com.silverpeas.services</groupId>
16+
<groupId>org.silverpeas.services</groupId>
1717
<artifactId>office-online</artifactId>
1818
<packaging>jar</packaging>
19-
<version>5.14-SNAPSHOT</version>
19+
<version>6.0-SNAPSHOT</version>
2020
<name>Online Office Editor - ${project.version}</name>
21+
<description>
22+
A Java program to find an installation of an Office Suite and to launch it with as argument
23+
the webDAV URL of the document to open. Currently, only MS-Office and
24+
OpenOffice.org/LibreOffice suites are supported.
25+
</description>
2126
<build>
2227
<finalName>OpenOfficeLauncher</finalName>
2328
</build>
2429

2530
<dependencies>
26-
<dependency>
27-
<groupId>junit</groupId>
28-
<artifactId>junit</artifactId>
29-
</dependency>
30-
<dependency>
31-
<groupId>org.hamcrest</groupId>
32-
<artifactId>hamcrest-all</artifactId>
33-
</dependency>
3431
<dependency>
3532
<groupId>commons-codec</groupId>
3633
<artifactId>commons-codec</artifactId>
3734
</dependency>
38-
<dependency>
39-
<groupId>commons-httpclient</groupId>
40-
<artifactId>commons-httpclient</artifactId>
41-
</dependency>
4235
<dependency>
4336
<groupId>org.slf4j</groupId>
4437
<artifactId>slf4j-api</artifactId>
@@ -50,34 +43,30 @@
5043
<dependency>
5144
<groupId>org.slf4j</groupId>
5245
<artifactId>slf4j-log4j12</artifactId>
53-
<exclusions>
54-
<exclusion>
55-
<artifactId>mail</artifactId>
56-
<groupId>javax.mail</groupId>
57-
</exclusion>
58-
</exclusions>
5946
</dependency>
6047
<dependency>
6148
<groupId>org.apache.jackrabbit</groupId>
6249
<artifactId>jackrabbit-webdav</artifactId>
63-
<version>2.6.5</version>
64-
<exclusions>
65-
<exclusion>
66-
<artifactId>commons-collections</artifactId>
67-
<groupId>commons-collections</groupId>
68-
</exclusion>
69-
</exclusions>
7050
</dependency>
7151
<dependency>
7252
<artifactId>jackrabbit-jcr-commons</artifactId>
7353
<groupId>org.apache.jackrabbit</groupId>
74-
<version>2.6.5</version>
7554
</dependency>
7655
<dependency>
7756
<groupId>xerces</groupId>
7857
<artifactId>xercesImpl</artifactId>
7958
<scope>runtime</scope>
8059
</dependency>
60+
<dependency>
61+
<groupId>junit</groupId>
62+
<artifactId>junit</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.hamcrest</groupId>
67+
<artifactId>hamcrest-all</artifactId>
68+
<scope>test</scope>
69+
</dependency>
8170
</dependencies>
8271
<profiles>
8372
<profile>

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

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
*/
2121
package org.silverpeas.openoffice;
2222

23-
import java.io.IOException;
24-
import java.util.logging.Level;
25-
import java.util.logging.Logger;
26-
23+
import org.silverpeas.openoffice.util.ApplicationArguments;
2724
import org.silverpeas.openoffice.util.FinderFactory;
2825
import org.silverpeas.openoffice.util.MessageDisplayer;
2926
import org.silverpeas.openoffice.util.MessageUtil;
@@ -32,7 +29,9 @@
3229
import org.silverpeas.openoffice.windows.FileWebDavAccessManager;
3330
import org.silverpeas.openoffice.windows.MsOfficeVersion;
3431

35-
import org.apache.commons.httpclient.HttpException;
32+
import java.io.IOException;
33+
import java.util.logging.Level;
34+
import java.util.logging.Logger;
3635

3736
/**
3837
* @author Emmanuel Hugonnet
@@ -42,89 +41,105 @@ public class OfficeLauncher {
4241
static final Logger logger = Logger.getLogger(OfficeLauncher.class.getName());
4342

4443
/**
45-
* Launch the document editor.
44+
* Launches the document editor corresponding to the type of the document to open.
45+
*
46+
* @see org.silverpeas.openoffice.util.ApplicationArguments
4647
*
47-
* @param type type of editor for the document (word editor, presentation editor, etc.)
48-
* @param url the url to the document.
49-
* @param authInfo authentication parameters
50-
* @param useDeconnectedMode : set to true if you want to activate the Disconnected mode : 1)
51-
* download file using webdav to local temp directory 2) open it 3) after close, send it back to
52-
* silverpeas, still using webdav 4) delete temp file locally
53-
* @return the result of the process.
48+
* @param arguments the arguments required to launch the document editor.
49+
* @return the process execution status.
5450
* @throws IOException
5551
* @throws InterruptedException
5652
* @throws OfficeNotFoundException
5753
*/
58-
public static int launch(MsOfficeType type, String url, AuthenticationInfo authInfo,
59-
boolean useDeconnectedMode) throws IOException, InterruptedException, OfficeNotFoundException {
60-
OfficeFinder finder = FinderFactory.getFinder(type);
54+
public static int launch(ApplicationArguments arguments)
55+
throws IOException, InterruptedException, OfficeNotFoundException {
56+
OfficeFinder finder = FinderFactory.getFinder(arguments.getContentType());
6157
logger.log(Level.INFO, "We are on {0} OS", OsEnum.getOS());
62-
String webdavUrl = url;
63-
boolean modeDisconnected = ((OsEnum.isWindows() && useDeconnectedMode) || OsEnum.getOS()
64-
== OsEnum.MAC_OSX) && finder.isMicrosoftOffice();
65-
if (!modeDisconnected) {
58+
String webdavUrl = arguments.getUrl();
59+
boolean disconnectedMode = ((OsEnum.isWindows() && arguments.isDisconnectedMode()) ||
60+
OsEnum.getOS() == OsEnum.MAC_OSX) && finder.isMicrosoftOffice();
61+
if (!disconnectedMode) {
6662
if (finder.isMicrosoftOffice() && (OsEnum.getOS() == OsEnum.WINDOWS_XP || (OsEnum
67-
.isWindows() && MsOfficeVersion.isOldOffice(type)))) {
63+
.isWindows() && MsOfficeVersion.isOldOffice(arguments.getContentType())))) {
6864
webdavUrl = webdavUrl.replace("/repository/", "/repository2000/");
6965
}
7066
}
71-
switch (type) {
67+
switch (arguments.getContentType()) {
7268
case EXCEL:
73-
return launch(type, finder.findSpreadsheet(), webdavUrl, modeDisconnected, authInfo);
69+
return launch(arguments.getContentType(), finder.findSpreadsheet(), webdavUrl,
70+
disconnectedMode, arguments.getLogin(), arguments.getToken());
7471
case POWERPOINT:
75-
return launch(type, finder.findPresentation(), webdavUrl, modeDisconnected, authInfo);
72+
return launch(arguments.getContentType(), finder.findPresentation(), webdavUrl,
73+
disconnectedMode, arguments.getLogin(), arguments.getToken());
7674
case WORD:
77-
return launch(type, finder.findWordEditor(), webdavUrl, modeDisconnected, authInfo);
75+
return launch(arguments.getContentType(), finder.findWordEditor(), webdavUrl,
76+
disconnectedMode, arguments.getLogin(), arguments.getToken());
7877
case NONE:
7978
default:
80-
return launch(type, finder.findOther(), webdavUrl, modeDisconnected, authInfo);
79+
return launch(arguments.getContentType(), finder.findOther(), webdavUrl, disconnectedMode,
80+
arguments.getLogin(), arguments.getToken());
8181
}
8282
}
8383

8484
/**
8585
* Launch document edition
8686
*
87-
* @param path path to editor
88-
* @param url document url
89-
* @param modeDisconnected disconnected mode.
90-
* @param auth authentication info
91-
* @return status
87+
* @param path the path of the editor to launch.
88+
* @param url the URL at which the document is located.
89+
* @param disconnectedMode is the document should be accessed in disconnected mode.
90+
* @param authToken the authentication token required to access the document.
91+
* @return status the process execution status.
9292
* @throws IOException
9393
* @throws InterruptedException
9494
*/
95-
protected static int launch(MsOfficeType type, String path, String url, boolean modeDisconnected,
96-
AuthenticationInfo auth) throws IOException, InterruptedException {
95+
protected static int launch(MsOfficeType type, String path, String url, boolean disconnectedMode,
96+
String login, String authToken) throws IOException, InterruptedException {
9797
logger.log(Level.INFO, "The path: {0}", path);
9898
logger.log(Level.INFO, "The url: {0}", url);
99-
if (modeDisconnected) {
99+
logger.log(Level.INFO, "The token: {0}", authToken);
100+
String authenticatedUrl = getAuthenticatedUrl(url, authToken);
101+
if (disconnectedMode) {
100102
try {
101-
String webdavUrl = url;
102-
final FileWebDavAccessManager webdavAccessManager = new FileWebDavAccessManager(auth);
103-
if ('"' == url.charAt(0)) {
104-
webdavUrl = url.substring(1, url.length() - 1);
105-
}
106-
String tmpFilePath = webdavAccessManager.retrieveFile(webdavUrl);
103+
String webDavUrl = getAuthenticatedUrl(unquoteUrl(url), authToken);
104+
final FileWebDavAccessManager webdavAccessManager =
105+
new FileWebDavAccessManager(login, authToken);
106+
String tmpFilePath = webdavAccessManager.retrieveFile(webDavUrl);
107107
logger.log(Level.INFO, "The exact exec line: {0} {1}", new Object[]{path, tmpFilePath});
108108
Process process = Runtime.getRuntime().exec(path + ' ' + tmpFilePath);
109109
process.waitFor();
110-
webdavAccessManager.pushFile(tmpFilePath, url);
110+
webdavAccessManager.pushFile(tmpFilePath, authenticatedUrl);
111111
MessageDisplayer.displayMessage(MessageUtil.getMessage("info.ok"));
112112
return 0;
113-
} catch (HttpException ex) {
114-
logger.log(Level.SEVERE, null, ex);
115-
throw new IOException(ex);
116113
} catch (IOException ex) {
117114
logger.log(Level.SEVERE, null, ex);
118115
throw ex;
119116
}
120117
} else {
121-
// Standard mode : just open it
118+
// Standard mode: just open it
122119
logger.log(Level.INFO, "The exact exec line: {0} {1}", new Object[]{path, url});
123-
Process process = Runtime.getRuntime().exec(path + ' ' + url);
120+
Process process = Runtime.getRuntime().exec(path + ' ' + authenticatedUrl);
124121
return process.waitFor();
125122
}
126123
}
127124

128125
private OfficeLauncher() {
129126
}
127+
128+
private static String unquoteUrl(String url) {
129+
String unquotedUrl = url;
130+
if ('"' == url.charAt(0)) {
131+
unquotedUrl = url.substring(1, url.length() - 1);
132+
}
133+
return unquotedUrl;
134+
}
135+
136+
private static String getAuthenticatedUrl(String url, String authToken) {
137+
String authUrl;
138+
if ('"' == url.charAt(0)) {
139+
authUrl = "\"" + unquoteUrl(url) + "?_=" + authToken + "\"";
140+
} else {
141+
authUrl = url + "?_=" + authToken;
142+
}
143+
return authUrl;
144+
}
130145
}

0 commit comments

Comments
 (0)