KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > vfs > utils > URIUserInfo


1 package com.sslexplorer.vfs.utils;
2
3 import com.sslexplorer.boot.Util;
4 import com.sslexplorer.vfs.utils.URI.MalformedURIException;
5
6
7 /**
8  * URIUserInfo allows to slit all information of a network placement (host, path, userinfo, ...)
9  * @author Sebastien Belin <a HREF="mailto:seb@3sp.com">&lt;seb@3sp.com&gt;</a>
10  */

11 public class URIUserInfo {
12     
13     private String JavaDoc host;
14     private String JavaDoc path;
15     private int port;
16     private String JavaDoc username;
17     private String JavaDoc password;
18     private String JavaDoc userInfo;
19     private String JavaDoc uri;
20     
21     public URIUserInfo(String JavaDoc stScheme, String JavaDoc host, String JavaDoc stUri, int port, String JavaDoc stUsername, String JavaDoc stPassword) throws MalformedURIException {
22            
23         try {
24             URI uri;
25
26             if ("file".equals(stScheme)) {
27                 stUri.replace("://", ":///");
28                 uri = new URI((!stUri.startsWith(stScheme + ":///") ? stScheme + ":///" : "") + stUri);
29             } else {
30                 host = host.replace("\\\\", "").replace("\\", "").replace("/", "");
31                 stUri = stUri.replace("\\\\", "").replace("\\", "/");
32                 uri = new URI((!stUri.startsWith(stScheme + "://") ? stScheme + "://" : "") + (!host.equals("") ? host + "/" : "") + stUri);
33             }
34             
35             setUri(uri.toString());
36             String JavaDoc userInfo = uri.getUserinfo();
37             setUserInfo(userInfo);
38             setHost(uri.getHost());
39             if (null != uri.getPath() && uri.getPath().startsWith("/")) {
40                 setPath(uri.getPath().substring(1));
41             } else {
42                 setPath(uri.getPath());
43             }
44             
45             if (port > 0) {
46                 setPort(port);
47             } else if (uri.getPort() >= 0) {
48                 setPort(uri.getPort());
49             } else {
50                 setPort(0);
51             }
52             if (!"".equals(stUsername)) {
53                 setUsername(stUsername);
54                 if (!"".equals(stPassword))
55                     setPassword(stPassword);
56             } else if (userInfo != null && !userInfo.equals("")) {
57                 String JavaDoc username = null;
58                 String JavaDoc pw = "";
59                 userInfo = Util.urlDecode(userInfo);
60                 int idx = userInfo.indexOf(":");
61                 username = userInfo;
62                 if (idx != -1) {
63                     username = userInfo.substring(0, idx);
64                     pw = userInfo.substring(idx + 1);
65                 }
66                 setUsername(username);
67                 setPassword(pw);
68             }
69         } catch (MalformedURIException e) {
70             throw e;
71         }
72     }
73        
74     public String JavaDoc getPassword() {
75         return password;
76     }
77     public void setPassword(String JavaDoc password) {
78         this.password = password;
79     }
80     public String JavaDoc getPath() {
81         return path;
82     }
83     public void setPath(String JavaDoc path) {
84         this.path = path;
85     }
86     public String JavaDoc getUsername() {
87         return username;
88     }
89     public void setUsername(String JavaDoc username) {
90         this.username = username;
91     }
92
93     public String JavaDoc getHost() {
94         return host;
95     }
96
97     public void setHost(String JavaDoc host) {
98         this.host = host;
99     }
100
101     public int getPort() {
102         return port;
103     }
104
105     public void setPort(int port) {
106         this.port = port;
107     }
108
109     public String JavaDoc getUserInfo() {
110         return userInfo;
111     }
112
113     public void setUserInfo(String JavaDoc userInfo) {
114         this.userInfo = userInfo;
115     }
116
117     public String JavaDoc getUri() {
118         return uri;
119     }
120
121     public void setUri(String JavaDoc uri) {
122         this.uri = uri;
123     }
124     
125     
126 }
127
Popular Tags