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

Commit 291ba4f

Browse files
author
Emmanuel Hugonnet
committed
Corrections for Windows Vista
git-svn-id: https://www.silverpeas.org/svn/silverpeas/services/office-online/trunk@508 a8e77078-a1c7-4fa5-b8fc-53c5178a176c
1 parent 00f4c7e commit 291ba4f

File tree

4 files changed

+61
-48
lines changed

4 files changed

+61
-48
lines changed

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@
5353
<artifactId>commons-collections</artifactId>
5454
<groupId>commons-collections</groupId>
5555
</exclusion>
56+
<!--
5657
<exclusion>
5758
<artifactId>jackrabbit-jcr-commons</artifactId>
5859
<groupId>org.apache.jackrabbit</groupId>
5960
</exclusion>
61+
-->
6062
</exclusions>
6163
</dependency>
6264
<dependency>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.silverpeas.openoffice.util.FinderFactory;
3333
import com.silverpeas.openoffice.util.MsOfficeType;
3434
import com.silverpeas.openoffice.util.OsEnum;
35-
import com.silverpeas.openoffice.util.UrlExtractor;
3635
import org.apache.commons.httpclient.HttpException;
3736

3837
/**

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

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
import java.net.MalformedURLException;
3636
import java.net.URISyntaxException;
3737
import java.net.URL;
38-
38+
import java.net.URLDecoder;
3939
import java.net.URLEncoder;
4040
import java.util.StringTokenizer;
41+
4142
import java.util.logging.Level;
4243
import java.util.logging.Logger;
4344
import org.apache.commons.httpclient.Credentials;
@@ -47,6 +48,7 @@
4748
import org.apache.commons.httpclient.HttpException;
4849
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
4950
import org.apache.commons.httpclient.URI;
51+
import org.apache.commons.httpclient.URIException;
5052
import org.apache.commons.httpclient.UsernamePasswordCredentials;
5153
import org.apache.commons.httpclient.auth.AuthScope;
5254
import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
@@ -72,7 +74,7 @@ public class FileWebDavAccessManager {
7274
private String password;
7375
private String lockToken = null;
7476
static Logger logger = Logger.getLogger(
75-
FileWebDavAccessManager.class.getName());
77+
FileWebDavAccessManager.class.getName());
7678

7779
/**
7880
* The AccessManager is inited with authentication info to avoid login prompt
@@ -88,7 +90,7 @@ public HttpClient initConnection(URL url) {
8890
HostConfiguration hostConfig = new HostConfiguration();
8991
hostConfig.setHost(url.getHost());
9092
HttpConnectionManager connectionManager =
91-
new MultiThreadedHttpConnectionManager();
93+
new MultiThreadedHttpConnectionManager();
9294
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
9395
int maxHostConnections = 20;
9496
params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
@@ -111,40 +113,42 @@ public HttpClient initConnection(URL url) {
111113
* @throws IOException
112114
*/
113115
public String retrieveFile(String url) throws HttpException, IOException,
114-
URISyntaxException {
115-
URL formattedUrl = new URL(url);
116+
URISyntaxException {
117+
URI uri = getURI(url);
118+
URL formattedUrl = new URL(uri.getEscapedURI());
116119
HttpClient client = initConnection(formattedUrl);
117120

118-
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.locking") +
119-
' ' + encodeUrl(url));
121+
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.locking")
122+
+ ' ' + uri.getEscapedURI());
120123
//Let's lock the file
121-
LockMethod lockMethod = new LockMethod(encodeUrl(url),
122-
Scope.EXCLUSIVE, Type.WRITE,
123-
userName, 600000l, false);
124+
LockMethod lockMethod = new LockMethod(uri.getEscapedURI(),
125+
Scope.EXCLUSIVE, Type.WRITE,
126+
userName, 600000l, false);
124127
client.executeMethod(lockMethod);
125128
if (lockMethod.succeeded()) {
126129
lockToken = lockMethod.getLockToken();
127130
} else {
128-
throw new IOException(MessageUtil.getMessage("error.webdav.locking")
129-
+ ' ' + lockMethod.getStatusCode() + " - "
130-
+ lockMethod.getStatusText());
131+
throw new IOException(MessageUtil.getMessage("error.webdav.locking")
132+
+ ' ' + lockMethod.getStatusCode() + " - "
133+
+ lockMethod.getStatusText());
131134
}
132-
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.locked") + ' '
133-
+ lockToken);
135+
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.locked") + ' '
136+
+ lockToken);
134137
GetMethod method = new GetMethod();
135-
method.setURI(new URI(url, false));
138+
method.setURI(uri);
136139
client.executeMethod(method);
137140
if (method.getStatusCode() != 200) {
138-
throw new IOException(MessageUtil.getMessage("error.get.remote.file") +
139-
+' ' + method.getStatusCode() + " - " + method.getStatusText());
141+
throw new IOException(MessageUtil.getMessage("error.get.remote.file")
142+
+ +' ' + method.getStatusCode() + " - " + method.getStatusText());
140143
}
141144

142145
String fileName = formattedUrl.getFile();
143146
fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
147+
fileName = URLDecoder.decode(fileName, "UTF-8");
144148
fileName = fileName.replace(' ', '_');
145149
InputStream is = method.getResponseBodyAsStream();
146-
File tempDir = new File(System.getProperty("java.io.tmpdir"), "silver-" +
147-
System.currentTimeMillis());
150+
File tempDir = new File(System.getProperty("java.io.tmpdir"), "silver-"
151+
+ System.currentTimeMillis());
148152
tempDir.mkdirs();
149153
File tmpFile = new File(tempDir, fileName);
150154
FileOutputStream fos = new FileOutputStream(tmpFile);
@@ -155,7 +159,7 @@ public String retrieveFile(String url) throws HttpException, IOException,
155159
}
156160
fos.close();
157161
logger.log(Level.INFO, MessageUtil.getMessage(
158-
"info.webdav.file.locally.saved") + ' ' + tmpFile.getAbsolutePath());
162+
"info.webdav.file.locally.saved") + ' ' + tmpFile.getAbsolutePath());
159163
return tmpFile.getAbsolutePath();
160164
}
161165

@@ -169,47 +173,48 @@ public String retrieveFile(String url) throws HttpException, IOException,
169173
* @throws IOException
170174
*/
171175
public void pushFile(String tmpFilePath, String url) throws HttpException,
172-
IOException,
173-
MalformedURLException,
174-
UnsupportedEncodingException,
175-
URISyntaxException {
176+
IOException,
177+
MalformedURLException,
178+
UnsupportedEncodingException,
179+
URISyntaxException,
180+
URIException {
176181
/*
177182
* Build URL object to extract host
178183
*/
179-
URL formattedUrl = new URL(url);
180-
HttpClient client = initConnection(formattedUrl);
184+
URI uri = getURI(url);
185+
HttpClient client = initConnection(new URL(uri.getEscapedURI()));
186+
181187
/*
182188
* Checks if file still exists
183189
*/
184190
GetMethod method = new GetMethod();
185-
method.setURI(new URI(url, false));
191+
method.setURI(uri);
186192
client.executeMethod(method);
187193

188194
if (method.getStatusCode() == 200) {
189-
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.unlocking") +
190-
' ' + encodeUrl(url));
195+
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.unlocking")
196+
+ ' ' + uri.getEscapedURI());
191197
//Let's lock the file
192-
UnLockMethod unlockMethod = new UnLockMethod(encodeUrl(url), lockToken);
198+
UnLockMethod unlockMethod = new UnLockMethod(uri.getEscapedURI(), lockToken);
193199
client.executeMethod(unlockMethod);
194-
if (unlockMethod.getStatusCode() != 200 && unlockMethod.getStatusCode() !=
195-
204) {
200+
if (unlockMethod.getStatusCode() != 200 && unlockMethod.getStatusCode()
201+
!= 204) {
196202
logger.log(Level.INFO,
197-
MessageUtil.getMessage("error.webdav.unlocking") + ' ' + unlockMethod.
198-
getStatusCode());
203+
MessageUtil.getMessage("error.webdav.unlocking") + ' ' + unlockMethod.getStatusCode());
199204
}
200205
try {
201206
unlockMethod.checkSuccess();
202207
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.unlocked"));
203208
} catch (DavException ex) {
204209
logger.log(Level.SEVERE,
205-
MessageUtil.getMessage("error.webdav.unlocking"), ex);
210+
MessageUtil.getMessage("error.webdav.unlocking"), ex);
206211
throw new IOException(MessageUtil.getMessage("error.webdav.unlocking"),
207-
ex);
212+
ex);
208213
}
209-
URI uri = new URI(url, false);
214+
210215
PutMethod putMethod = new PutMethod(uri.getEscapedURI());
211-
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.put") +
212-
' ' + tmpFilePath);
216+
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.put")
217+
+ ' ' + tmpFilePath);
213218
File file = new File(tmpFilePath);
214219
InputStream is = new FileInputStream(file);
215220
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -230,21 +235,20 @@ public void pushFile(String tmpFilePath, String url) throws HttpException,
230235
logger.log(Level.INFO, MessageUtil.getMessage("info.file.deleted"));
231236
logger.log(Level.INFO, MessageUtil.getMessage("info.ok"));
232237
} else {
233-
throw new IOException(MessageUtil.getMessage("error.put.remote.file") +
234-
" - " + putMethod.getStatusCode() + " - " +
235-
putMethod.getStatusText());
238+
throw new IOException(MessageUtil.getMessage("error.put.remote.file")
239+
+ " - " + putMethod.getStatusCode() + " - "
240+
+ putMethod.getStatusText());
236241
}
237242
} else {
238243
logger.log(Level.SEVERE, MessageUtil.getMessage("error.remote.file"));
239244
throw new IOException(MessageUtil.getMessage("error.remote.file"));
240245
}
241246
}
242247

243-
public static String encodeUrl(String url) throws MalformedURLException,
244-
UnsupportedEncodingException,
245-
URISyntaxException {
248+
public static String encodeUrl(String url) throws UnsupportedEncodingException {
246249
int count = 0;
247-
StringTokenizer tokenizer = new StringTokenizer(url, "/", true);
250+
String urlToBeEncoded = url.replaceAll("%20", " ");
251+
StringTokenizer tokenizer = new StringTokenizer(urlToBeEncoded, "/", true);
248252
StringBuilder buffer = new StringBuilder();
249253
while (tokenizer.hasMoreTokens()) {
250254
String token = tokenizer.nextToken();
@@ -258,4 +262,8 @@ public static String encodeUrl(String url) throws MalformedURLException,
258262
String resultingUrl = buffer.toString();
259263
return resultingUrl.replace('+', ' ').replaceAll(" ", "%20");
260264
}
265+
266+
private static URI getURI(String url) throws URIException {
267+
return new URI(url.replaceAll("%20", " "), false, "UTF-8");
268+
}
261269
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public void testEncodeUrl() throws Exception {
5959
String expResult = "http://localhost:8000/silverpeas/toto/Ceci%20est%20un%20%26x%40pl%C3%A9.doc";
6060
String result = FileWebDavAccessManager.encodeUrl(url);
6161
assertEquals(expResult, result);
62+
String escapedUrl = "http://localhost:8000/silverpeas/toto/Ceci%20est%20un%20&x@plé.doc";
63+
assertEquals(escapedUrl.replaceAll("%20", " "), url);
64+
result = FileWebDavAccessManager.encodeUrl(escapedUrl);
65+
assertEquals(expResult, result);
6266
}
6367

6468
}

0 commit comments

Comments
 (0)