1 16 package org.apache.commons.vfs.provider.local; 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.AbstractFileNameParser; 22 import org.apache.commons.vfs.provider.UriParser; 23 import org.apache.commons.vfs.provider.VfsComponentContext; 24 25 30 public abstract class LocalFileNameParser extends AbstractFileNameParser 31 { 32 35 public boolean isAbsoluteName(final String name) 36 { 37 StringBuffer b = new StringBuffer (name); 39 try 40 { 41 UriParser.fixSeparators(b); 42 extractRootPrefix(name, b); 43 return true; 44 } 45 catch (FileSystemException e) 46 { 47 return false; 48 } 49 } 50 51 54 protected abstract String extractRootPrefix(final String uri, 55 final StringBuffer name) 56 throws FileSystemException; 57 58 59 public FileName parseUri(final VfsComponentContext context, FileName base, final String filename) throws FileSystemException 60 { 61 final StringBuffer name = new StringBuffer (); 62 63 String scheme = UriParser.extractScheme(filename, name); 65 if (scheme == null) 66 { 67 scheme = "file"; 68 } 69 70 UriParser.canonicalizePath(name, 0, name.length(), this); 72 73 UriParser.fixSeparators(name); 74 75 final String rootFile = extractRootPrefix(filename, name); 77 78 FileType fileType = UriParser.normalisePath(name); 80 81 final String path = name.toString(); 82 83 return createFileName( 84 scheme, 85 rootFile, 86 path, 87 fileType); 88 } 89 90 protected abstract FileName createFileName(String scheme, final String rootFile, final String path, final FileType type); 91 } 92 | Popular Tags |