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.FileNameParser; 22 import org.apache.commons.vfs.provider.URLFileNameParser; 23 import org.apache.commons.vfs.provider.UriParser; 24 import org.apache.commons.vfs.provider.VfsComponentContext; 25 26 29 public class SmbFileNameParser extends URLFileNameParser 30 { 31 private final static SmbFileNameParser INSTANCE = new SmbFileNameParser(); 32 33 public SmbFileNameParser() 34 { 35 super(139); 36 } 37 38 public static FileNameParser getInstance() 39 { 40 return INSTANCE; 41 } 42 43 public FileName parseUri(final VfsComponentContext context, FileName base, final String filename) throws FileSystemException 44 { 45 final StringBuffer name = new StringBuffer (); 46 47 String actualFilename = filename; 48 49 if (actualFilename.equals("smb://") || actualFilename.equals("smb:///")) { 50 actualFilename = "smb://_master_/_browser_/"; 52 } 53 final Authority auth = extractToPath(actualFilename, name); 55 56 String username = auth.userName; 58 String domain = extractDomain(username); 59 if (domain != null) { 60 username = username.substring(domain.length() + 1); 61 } 62 63 UriParser.canonicalizePath(name, 0, name.length(), this); 65 UriParser.fixSeparators(name); 66 67 String share = UriParser.extractFirstElement(name); 69 if (share == null || share.length() == 0) { 70 share = ""; 71 } 74 75 FileType fileType = UriParser.normalisePath(name); 78 final String path = name.toString(); 79 80 return new SmbFileName( 81 auth.scheme, 82 auth.hostName, 83 auth.port, 84 username, 85 auth.password, 86 domain, 87 share, 88 path, 89 fileType); 90 91 } 92 93 private String extractDomain(String username) 94 { 95 if (username == null) 96 { 97 return null; 98 } 99 100 for (int i = 0; i < username.length(); i++) 101 { 102 if (username.charAt(i) == '\\') 103 { 104 return username.substring(0, i); 105 } 106 } 107 108 return null; 109 } 110 } 111 | Popular Tags |