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 import org.apache.commons.vfs2.util.URIUtils;
23
24
25
26
27 public class GenericURLFileName extends GenericFileName {
28
29 private static final int BUFFER_SIZE = 250;
30
31 private final String queryString;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public GenericURLFileName(final String scheme, final String hostName, final int port, final int defaultPort,
47 final String userName, final String password, final String path, final FileType type,
48 final String queryString) {
49 super(scheme, hostName, port, defaultPort, userName, password, path, type);
50 this.queryString = queryString;
51 }
52
53
54
55
56
57
58
59
60 @Override
61 public FileName createName(final String absPath, final FileType type) {
62 return new GenericURLFileName(getScheme(), getHostName(), getPort(), getDefaultPort(), getUserName(), getPassword(),
63 absPath, type, getQueryString());
64 }
65
66
67
68
69
70
71 @Override
72 protected String createURI() {
73 if (getQueryString() != null) {
74 final StringBuilder sb = new StringBuilder(BUFFER_SIZE);
75 sb.append(super.createURI());
76 sb.append("?");
77 sb.append(getQueryString());
78
79 return sb.toString();
80 }
81
82 return super.createURI();
83 }
84
85
86
87
88
89
90 public String getPathQuery() {
91 final StringBuilder sb = new StringBuilder(BUFFER_SIZE);
92 sb.append(getPath());
93 sb.append("?");
94 sb.append(getQueryString());
95
96 return sb.toString();
97 }
98
99
100
101
102
103
104
105
106 public String getPathQueryEncoded(final String charset) throws FileSystemException {
107 if (getQueryString() == null) {
108 if (charset != null) {
109 return URIUtils.encodePath(getPathDecoded(), charset);
110 }
111 return URIUtils.encodePath(getPathDecoded());
112 }
113
114 final StringBuilder sb = new StringBuilder(BUFFER_SIZE);
115 if (charset != null) {
116 sb.append(URIUtils.encodePath(getPathDecoded(), charset));
117 } else {
118 sb.append(URIUtils.encodePath(getPathDecoded()));
119 }
120 sb.append("?");
121 sb.append(getQueryString());
122 return sb.toString();
123 }
124
125
126
127
128
129
130 public String getQueryString() {
131 return queryString;
132 }
133
134
135
136
137
138
139
140
141 public String getURIEncoded(final String charset) throws FileSystemException {
142 final StringBuilder sb = new StringBuilder(BUFFER_SIZE);
143 appendRootUri(sb, true);
144 sb.append(getPathQueryEncoded(charset));
145 return sb.toString();
146 }
147 }