1 16 package org.apache.commons.vfs.provider; 17 18 import org.apache.commons.vfs.FileName; 19 import org.apache.commons.vfs.FileType; 20 21 29 public class GenericFileName extends AbstractFileName 30 { 31 private final String userName; 32 private final String hostName; 33 private final int defaultPort; 34 private final String password; 35 private final int port; 36 private static final char[] RESERVED = {':', '@', '/', '?', '[', ']', '#'}; 37 39 protected GenericFileName(final String scheme, 40 final String hostName, 41 final int port, 42 final int defaultPort, 43 final String userName, 44 final String password, 45 final String path, 46 final FileType type 47 ) 48 { 49 super(scheme, path, type); 50 this.hostName = hostName; 51 this.defaultPort = defaultPort; 52 this.password = password; 53 this.userName = userName; 54 if (port > 0) 55 { 56 this.port = port; 57 } 58 else 59 { 60 this.port = getDefaultPort(); 61 } 62 } 63 64 67 public String getUserName() 68 { 69 return userName; 70 } 71 72 75 public String getPassword() 76 { 77 return password; 78 } 79 80 83 public String getHostName() 84 { 85 return hostName; 86 } 87 88 91 public int getPort() 92 { 93 return port; 94 } 95 96 99 public int getDefaultPort() 100 { 101 return defaultPort; 102 } 103 104 public FileName createName(String absPath, FileType type) 105 { 106 return new GenericFileName( 107 getScheme(), 108 hostName, 109 port, 110 defaultPort, 111 userName, 112 password, 113 absPath, 114 type); 115 } 116 117 120 protected void appendRootUri(final StringBuffer buffer) 121 { 122 buffer.append(getScheme()); 123 buffer.append("://"); 124 appendCredentials(buffer); 125 buffer.append(hostName); 126 if (port != getDefaultPort()) 127 { 128 buffer.append(':'); 129 buffer.append(port); 130 } 131 } 132 133 136 protected void appendCredentials(StringBuffer buffer) 137 { 138 if (userName != null && userName.length() != 0) 139 { 140 UriParser.appendEncoded(buffer, userName, RESERVED); 141 if (password != null && password.length() != 0) 142 { 143 buffer.append(':'); 144 UriParser.appendEncoded(buffer, password, RESERVED); 145 } 146 buffer.append('@'); 147 } 148 } 149 } 150 | Popular Tags |