01: package org.openi.feeds.client;
02:
03: import java.net.MalformedURLException;
04: import java.net.URL;
05:
06: import org.openi.project.ProjectContext;
07:
08: public class FeedsServiceFactory {
09: public static FeedsService createLocal(ProjectContext projectContext) {
10: return new FeedsServiceLocalClient(projectContext);
11: }
12:
13: public static FeedsService createRemote(String uri,
14: String remoteDir, String user, String password)
15: throws FeedsServiceException {
16: URL url = null;
17: try {
18: url = new URL(uri);
19: } catch (MalformedURLException ex) {
20: throw new FeedsServiceException(ex);
21: }
22: if (user != null && !user.equals("") && password != null
23: && !password.endsWith("")) {
24: String newUri = url.getProtocol() + "://" + user;
25: newUri += ":" + password;
26: int port = url.getPort() < 0 ? 80 : url.getPort();
27: newUri += "@" + url.getHost() + ":" + port + url.getPath();
28: try {
29: url = new URL(newUri);
30: } catch (MalformedURLException ex) {
31: throw new FeedsServiceException(ex);
32: }
33: }
34: return new FeedsServiceWSClient(url, remoteDir);
35: }
36: }
|