1 package com.sslexplorer.vfs.utils; 2 3 import com.sslexplorer.boot.Util; 4 import com.sslexplorer.vfs.utils.URI.MalformedURIException; 5 6 7 11 public class URIUserInfo { 12 13 private String host; 14 private String path; 15 private int port; 16 private String username; 17 private String password; 18 private String userInfo; 19 private String uri; 20 21 public URIUserInfo(String stScheme, String host, String stUri, int port, String stUsername, String 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 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 username = null; 58 String 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 getPassword() { 75 return password; 76 } 77 public void setPassword(String password) { 78 this.password = password; 79 } 80 public String getPath() { 81 return path; 82 } 83 public void setPath(String path) { 84 this.path = path; 85 } 86 public String getUsername() { 87 return username; 88 } 89 public void setUsername(String username) { 90 this.username = username; 91 } 92 93 public String getHost() { 94 return host; 95 } 96 97 public void setHost(String 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 getUserInfo() { 110 return userInfo; 111 } 112 113 public void setUserInfo(String userInfo) { 114 this.userInfo = userInfo; 115 } 116 117 public String getUri() { 118 return uri; 119 } 120 121 public void setUri(String uri) { 122 this.uri = uri; 123 } 124 125 126 } 127 | Popular Tags |