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