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