1 package emissary.util.web;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import javax.annotation.Nullable;
6
7
8
9
10
11
12 public class UrlData {
13
14 String password;
15 List<UrlRequestProperty> props;
16 String referer;
17 int responseCode;
18 byte[] theContent;
19 String theUrl;
20 int theMethod;
21 String userName;
22 String userAgent;
23
24
25
26
27
28 public UrlData(final String theUrl, final byte[] theContent, final int responseCode, final List<UrlRequestProperty> props) {
29 this.theUrl = theUrl;
30 this.theContent = theContent;
31 this.responseCode = responseCode;
32 this.theMethod = Url.GET;
33 this.props = new ArrayList<>(props);
34 }
35
36 public UrlData() {}
37
38 public UrlData(final String theUrl) {
39 this.theUrl = theUrl;
40 }
41
42
43
44
45
46
47 public int getResponseCode() {
48 return this.responseCode;
49 }
50
51
52
53
54
55
56 public void setResponseCode(final int v) {
57 this.responseCode = v;
58 }
59
60
61
62
63
64
65 public String getTheUrl() {
66 return this.theUrl;
67 }
68
69
70
71
72
73
74 public void setTheUrl(final String v) {
75 this.theUrl = v;
76 }
77
78
79
80
81
82
83 public byte[] getTheContent() {
84 return this.theContent;
85 }
86
87 public int getContentLength() {
88 return (this.theContent == null) ? 0 : this.theContent.length;
89 }
90
91
92
93
94
95
96 public void setTheContent(final byte[] v) {
97 this.theContent = v;
98 }
99
100
101
102
103
104
105 public String getReferer() {
106 return this.referer;
107 }
108
109
110
111
112
113
114 public void setReferer(final String v) {
115 this.referer = v;
116 }
117
118
119
120
121
122
123 public String getUserAgent() {
124 return this.userAgent;
125 }
126
127
128
129
130
131
132 public void setUserAgent(final String v) {
133 this.userAgent = v;
134 }
135
136
137
138
139
140
141 public String getUserName() {
142 return this.userName;
143 }
144
145
146
147
148
149
150 public void setUserName(final String v) {
151 this.userName = v;
152 }
153
154
155
156
157
158
159 public String getPassword() {
160 return this.password;
161 }
162
163
164
165
166
167
168 public void setPassword(final String v) {
169 this.password = v;
170 }
171
172
173
174
175
176
177 public int getTheMethod() {
178 return this.theMethod;
179 }
180
181
182
183
184
185
186 @Nullable
187 public List<UrlRequestProperty> getProps() {
188 return this.props == null ? null : new ArrayList<>(this.props);
189 }
190
191 public int getNumberOfProperties() {
192 return (this.props == null) ? 0 : this.props.size();
193 }
194
195
196
197
198
199
200 public void setProps(final List<UrlRequestProperty> v) {
201 this.props = new ArrayList<>(v);
202 }
203
204
205
206
207
208
209 public void addProp(@Nullable final UrlRequestProperty v) {
210
211 if (v == null) {
212 return;
213 }
214
215 if (this.props == null) {
216 this.props = new ArrayList<>();
217 }
218
219 this.props.add(v);
220 }
221
222
223
224
225
226
227 public void addProps(@Nullable final List<UrlRequestProperty> v) {
228 if (v == null) {
229 return;
230 }
231 if (v.isEmpty()) {
232 return;
233 }
234
235 if (this.props == null) {
236 this.props = new ArrayList<>();
237 }
238
239 this.props.addAll(v);
240 }
241
242
243
244
245
246
247 public void setTheMethod(final int v) {
248 this.theMethod = v;
249 }
250
251
252
253
254 private StringBuilder toStringBuilder(final boolean headers) {
255 final StringBuilder sb = new StringBuilder();
256 sb.append(Url.theMethodString[this.theMethod]).append(": ").append(this.theUrl).append(" ").append(this.responseCode).append("/")
257 .append(this.theContent.length);
258 if (headers && (this.props != null)) {
259 for (UrlRequestProperty prop : this.props) {
260 sb.append(prop.toString());
261 }
262 }
263 sb.append("\n\n").append(new String(this.theContent)).append("\n");
264 return sb;
265 }
266
267 @Override
268 public String toString() {
269 return this.toStringBuilder(false).toString();
270 }
271
272 public String toString(final boolean headers) {
273 return this.toStringBuilder(headers).toString();
274 }
275 }