1 16 package org.apache.commons.vfs.provider.smb; 17 18 import org.apache.commons.vfs.FileName; 19 import org.apache.commons.vfs.FileSystemException; 20 import org.apache.commons.vfs.FileType; 21 import org.apache.commons.vfs.provider.GenericFileName; 22 23 28 public class SmbFileName 29 extends GenericFileName 30 { 31 private static final int DEFAULT_PORT = 139; 32 33 private final String share; 34 private final String domain; 35 private String uriWithoutAuth; 36 37 protected SmbFileName( 38 final String scheme, 39 final String hostName, 40 final int port, 41 final String userName, 42 final String password, 43 final String domain, 44 final String share, 45 final String path, 46 final FileType type) 47 { 48 super(scheme, hostName, port, DEFAULT_PORT, userName, password, path, type); 49 this.share = share; 50 this.domain = domain; 51 } 52 53 56 public String getShare() 57 { 58 return share; 59 } 60 61 64 protected void appendRootUri(final StringBuffer buffer) 65 { 66 super.appendRootUri(buffer); 67 if(share!=null && !share.equals("")) { 68 if (buffer.charAt(buffer.length() - 1) != '/') 69 buffer.append('/'); 70 buffer.append(share); 71 } 72 } 73 74 77 protected void appendCredentials(StringBuffer buffer) 78 { 79 if (getDomain() != null && getDomain().length() != 0 && 80 getUserName() != null && getUserName().length() != 0) 81 { 82 buffer.append(getDomain()); 83 buffer.append("\\"); 84 } 85 super.appendCredentials(buffer); 86 } 87 88 91 public FileName createName(final String path, FileType type) 92 { 93 return new SmbFileName( 94 getScheme(), 95 getHostName(), 96 getPort(), 97 getUserName(), 98 getPassword(), 99 domain, 100 share, 101 path, 102 type); 103 } 104 105 108 public String getUriWithoutAuth() throws FileSystemException 109 { 110 if (uriWithoutAuth != null) 111 { 112 return uriWithoutAuth; 113 } 114 115 StringBuffer sb = new StringBuffer (120); 116 sb.append(getScheme()); 117 sb.append("://"); 118 sb.append(getHostName()); 119 sb.append("/"); 120 sb.append(getShare()); 121 if(!getPathDecoded().equals("/")) 122 sb.append(getPathDecoded()); 123 uriWithoutAuth = sb.toString(); 124 return uriWithoutAuth; 125 } 126 127 130 public String getDomain() 131 { 132 return domain; 133 } 134 } 135 | Popular Tags |