1 16 package org.apache.commons.vfs.provider; 17 18 import org.apache.commons.vfs.FileName; 19 import org.apache.commons.vfs.FileSystemException; 20 import org.apache.commons.vfs.FileType; 21 22 27 public class LayeredFileNameParser extends AbstractFileNameParser 28 { 29 private final static LayeredFileNameParser INSTANCE = new LayeredFileNameParser(); 30 31 public static LayeredFileNameParser getInstance() 32 { 33 return INSTANCE; 34 } 35 36 public boolean encodeCharacter(char ch) 37 { 38 return super.encodeCharacter(ch) || ch == '!'; 39 } 40 41 public FileName parseUri(final VfsComponentContext context, FileName base, final String filename) throws FileSystemException 42 { 43 final StringBuffer name = new StringBuffer (); 44 45 final String scheme = UriParser.extractScheme(filename, name); 47 48 final String rootUriName = extractRootName(name); 50 FileName rootUri = null; 51 if (rootUriName != null) 52 { 53 rootUri = context.parseURI(rootUriName); 54 } 55 56 UriParser.canonicalizePath(name, 0, name.length(), this); 58 UriParser.fixSeparators(name); 59 FileType fileType = UriParser.normalisePath(name); 60 final String path = name.toString(); 61 62 return new LayeredFileName(scheme, rootUri, path, fileType); 63 } 64 65 68 protected String extractRootName(final StringBuffer uri) 69 throws FileSystemException 70 { 71 int maxlen = uri.length(); 73 int pos = maxlen - 1; 74 for (; pos > 0 && uri.charAt(pos) != '!'; pos--) 75 { 76 } 77 78 if (pos == 0 && uri.charAt(pos) != '!') 79 { 80 pos = maxlen; 83 } 84 85 String prefix = uri.substring(0, pos); 87 if (pos < maxlen) 88 { 89 uri.delete(0, pos + 1); 90 } 91 else 92 { 93 uri.setLength(0); 94 } 95 96 return prefix; 97 } 98 99 } 100 | Popular Tags |