1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider;
18
19 import org.apache.commons.vfs2.FileName;
20 import org.apache.commons.vfs2.FileSystemException;
21 import org.apache.commons.vfs2.FileType;
22
23
24
25
26
27
28
29 public class LayeredFileNameParser extends AbstractFileNameParser {
30 private static final LayeredFileNameParserleNameParser.html#LayeredFileNameParser">LayeredFileNameParser INSTANCE = new LayeredFileNameParser();
31
32
33
34
35
36
37 public static LayeredFileNameParser getInstance() {
38 return INSTANCE;
39 }
40
41
42
43
44
45
46
47 @Override
48 public boolean encodeCharacter(final char ch) {
49 return super.encodeCharacter(ch) || ch == '!';
50 }
51
52
53
54
55
56
57
58
59
60
61 @Override
62 public FileName parseUri(FileNameal VfsComponentContext context, final FileName baseFileName, final String fileName)
63 throws FileSystemException {
64 final StringBuilder name = new StringBuilder();
65
66
67 final String scheme = UriParser.extractScheme(context.getFileSystemManager().getSchemes(), fileName, name);
68
69
70 final String rootUriName = extractRootName(name);
71 FileName rootUri = null;
72 if (rootUriName != null) {
73 rootUri = context.parseURI(rootUriName);
74 }
75
76
77 UriParser.canonicalizePath(name, 0, name.length(), this);
78 UriParser.fixSeparators(name);
79 final FileType fileType = UriParser.normalisePath(name);
80 final String path = name.toString();
81
82 return new LayeredFileName(scheme, rootUri, path, fileType);
83 }
84
85
86
87
88
89
90
91 protected String extractRootName(final StringBuilder uri) {
92
93 final int maxlen = uri.length();
94 int pos = maxlen - 1;
95 for (; pos > 0 && uri.charAt(pos) != '!'; pos--) {
96 }
97
98 if (pos == 0 && uri.charAt(pos) != '!') {
99
100
101 pos = maxlen;
102 }
103
104
105 final String prefix = uri.substring(0, pos);
106 if (pos < maxlen) {
107 uri.delete(0, pos + 1);
108 } else {
109 uri.setLength(0);
110 }
111
112 return prefix;
113 }
114
115 }