Produced by Araxis Merge on 6/5/2018 10:24:10 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | patch_205_build_9.zip\Java\ImagingCommon\main\src\java\gov\va\med | URLComponentMerger.java | Wed May 30 14:35:19 2018 UTC |
2 | patch_205_build_9.zip\Java\ImagingCommon\main\src\java\gov\va\med | URLComponentMerger.java | Fri Jun 1 20:57:32 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 3 | 1008 |
Changed | 2 | 4 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /** | |
2 | * Package : MAG - Vi stA Imagin g | |
3 | * WARNING : Per VHA Directive 2004-038, this routi ne should not be mod ified. | |
4 | * @date O ct 14, 201 0 | |
5 | * Site Na me: Washi ngton OI F ield Offic e, Silver Spring, MD | |
6 | * @author PII | |
7 | * @versio n 1.0 | |
8 | * | |
9 | * ------- ---------- ---------- ---------- ---------- ---------- ------- | |
10 | * Propert y of the U S Governme nt. | |
11 | * No perm ission to copy or re distribute this soft ware is gi ven. | |
12 | * Use of unreleased versions of this so ftware req uires the user | |
13 | * to exec ute a writ ten test a greement w ith the Vi stA Imagin g | |
14 | * Develop ment Offic e of the D epartment of Veteran s Affairs, | |
15 | * telepho ne (301) 7 34-0100. | |
16 | * | |
17 | * The Foo d and Drug Administr ation clas sifies thi s software as | |
18 | * a Class II medica l device. As such, it may not be change d | |
19 | * in any way. Modi fications to this so ftware may result in an | |
20 | * adulter ated medic al device under 21CF R820, the use of whi ch | |
21 | * is cons idered to be a viola tion of US Federal S tatutes. | |
22 | * ------- ---------- ---------- ---------- ---------- ---------- ------- | |
23 | */ | |
24 | ||
25 | package go v.va.med; | |
26 | ||
27 | import jav a.io.Seria lizable; | |
28 | import jav a.io.Unsup portedEnco dingExcept ion; | |
29 | import jav a.net.Malf ormedURLEx ception; | |
30 | import jav a.net.URL; | |
31 | import jav a.net.URLE ncoder; | |
32 | ||
33 | /** | |
34 | * @author PII | |
35 | * | |
36 | */ | |
37 | public cla ss URLComp onentMerge r | |
38 | implements Serializa ble | |
39 | { | |
40 | pr ivate stat ic final l ong serial VersionUID = 1L; | |
41 | ||
42 | pu blic enum URLCompone ntMergerPr ecedence | |
43 | im plements S erializabl e | |
44 | { | |
45 | URLF irst, // use the URL c omponents, add the m erger comp onents whe n the URL component does not e xist | |
46 | URLF irstOverri deProtocol , // always us e the merg er protoco l, otherwi se use the URL compo nents, add the merge r componen ts when th e URL comp onent does not exist | |
47 | Merg erComponen tsFirst // add or ov erride all URL compo nents with the merge r componen ts that ex ist | |
48 | } | |
49 | ||
50 | pr ivate fina l String p rotocol; | |
51 | pr ivate fina l String u sername; | |
52 | pr ivate fina l String p assword; | |
53 | pr ivate fina l String h ost; | |
54 | pr ivate fina l int port ; | |
55 | pr ivate fina l String f ile; | |
56 | pr ivate fina l URLCompo nentMerger Precedence precedenc e; | |
57 | ||
58 | /* * | |
59 | * Create an instance to merge t he compone nts into | |
60 | * URLs. Th e preceden ce paramet er control s whether the | |
61 | * URL or th e fields i n this cla ss take pr ecedence. | |
62 | * Any Strin g fields t hat are nu ll will no t be merge d, the URL | |
63 | * value wil l always b e used. | |
64 | * If the 'p ort' field is less t han 0 then the URL v alue will be used | |
65 | * or no val ue if the URL has no port spec ified. | |
66 | * | |
67 | * @param pr otocol | |
68 | * @param us ername | |
69 | * @param pa ssword | |
70 | * @param ho st | |
71 | * @param po rt | |
72 | * @param fi le | |
73 | * @param pr ecedence | |
74 | * / | |
75 | pu blic URLCo mponentMer ger( | |
76 | Stri ng protoco l, | |
77 | Stri ng usernam e, | |
78 | Stri ng passwor d, | |
79 | Stri ng host, | |
80 | int port, | |
81 | Stri ng file, | |
82 | URLC omponentMe rgerPreced ence prece dence) | |
83 | { | |
84 | supe r(); | |
85 | this .protocol = protocol ; | |
86 | this .username = username ; | |
87 | this .password = password ; | |
88 | this .host = ho st; | |
89 | this .port = po rt; | |
90 | this .file = fi le; | |
91 | this .precedenc e = preced ence; | |
92 | } | |
93 | ||
94 | ||
95 | /* * | |
96 | * @return t he protoco l | |
97 | * / | |
98 | pu blic Strin g getProto col() | |
99 | { | |
100 | retu rn this.pr otocol; | |
101 | } | |
102 | ||
103 | pr ivate fina l static S tring utf8 = "UTF-8" ; | |
104 | ||
105 | /* * | |
106 | * @return t he usernam e | |
107 | * / | |
108 | pu blic Strin g getUsern ame() | |
109 | { | |
110 | retu rn this.us ername; | |
111 | } | |
112 | ||
113 | /* * | |
114 | * return th e username URL (UTF- 8) encoded (if the u sername is not null) | |
115 | * @return | |
116 | * / | |
117 | pr ivate Stri ng getUser nameEncode d() | |
118 | { | |
119 | if(g etUsername () == null ) | |
120 | return null; | |
121 | try | |
122 | { | |
123 | return URLEncode r.encode(g etUsername (), utf8); | |
124 | } | |
125 | catc h (Unsuppo rtedEncodi ngExceptio n e) | |
126 | { | |
127 | return getUserna me(); | |
128 | } | |
129 | } | |
130 | ||
131 | /* * | |
132 | * @return t he passwor d | |
133 | * / | |
134 | pu blic Strin g getPassw ord() | |
135 | { | |
136 | retu rn this.pa ssword; | |
137 | } | |
138 | ||
139 | /* * | |
140 | * return th e password URL (UTF- 8) encoded (if the p assword is not null) | |
141 | * @return | |
142 | * / | |
143 | pr ivate Stri ng getPass wordEncode d() | |
144 | { | |
145 | if(g etPassword () == null ) | |
146 | return null; | |
147 | try | |
148 | { | |
149 | return URLEncode r.encode(g etPassword (), utf8); | |
150 | } | |
151 | catc h (Unsuppo rtedEncodi ngExceptio n e) | |
152 | { | |
153 | return getPasswo rd(); | |
154 | } | |
155 | } | |
156 | ||
157 | ||
158 | /* * | |
159 | * @return t he host | |
160 | * / | |
161 | pu blic Strin g getHost( ) | |
162 | { | |
163 | retu rn this.ho st; | |
164 | } | |
165 | ||
166 | ||
167 | /* * | |
168 | * @return t he port | |
169 | * / | |
170 | pu blic int g etPort() | |
171 | { | |
172 | retu rn this.po rt; | |
173 | } | |
174 | ||
175 | ||
176 | /* * | |
177 | * @return t he file | |
178 | * / | |
179 | pu blic Strin g getFile( ) | |
180 | { | |
181 | retu rn this.fi le; | |
182 | } | |
183 | ||
184 | ||
185 | /* * | |
186 | * @return t he precede nce | |
187 | * / | |
188 | pu blic URLCo mponentMer gerPrecede nce getPre cedence() | |
189 | { | |
190 | retu rn this.pr ecedence; | |
191 | } | |
192 | ||
193 | ||
194 | /* * | |
195 | * | |
196 | * @param ur l | |
197 | * @return | |
198 | * @throws M alformedUR LException | |
199 | * / | |
200 | pu blic URL m erge(URL u rl) | |
201 | th rows Malfo rmedURLExc eption | |
202 | { | |
203 | Stri ngBuilder sb = new S tringBuild er(); | |
204 | ||
205 | // t he protoco l | |
206 | sb.a ppend(sele ctProtocol (url)); | |
207 | sb.a ppend(":// "); | |
208 | ||
209 | // t he user ID and passw ord | |
210 | Stri ng userInf o = select UserInfo(u rl); | |
211 | if(u serInfo != null && u serInfo.le ngth() > 0 ) | |
212 | { | |
213 | sb.app end(userIn fo); | |
214 | sb.app end('@'); | |
215 | } | |
216 | ||
217 | // t he host s a required field | |
218 | sb.a ppend( sel ectHost(ur l) ); | |
219 | ||
220 | // t he port is not a req uired fiel d | |
221 | Stri ng selecte dPort = se lectPort(u rl); | |
222 | if(s electedPor t != null && selecte dPort.leng th() > 0) | |
223 | sb.app end( ":" + selectedP ort ); | |
224 | ||
225 | Stri ng selecte dFile = se lectFile(u rl); | |
226 | if(s electedFil e != null && selecte dFile.leng th() > 0) | |
227 | sb.app end( "/" + selectedF ile ); | |
228 | ||
229 | URL fixedUpUrl = new URL ( sb.toStr ing() ); | |
230 | retu rn fixedUp Url; | |
231 | } | |
232 | ||
233 | /* * | |
234 | * File is n ot a requi red field, this meth od may ret urn null. | |
235 | * | |
236 | * @return | |
237 | * / | |
238 | pr ivate Stri ng selectF ile(URL ur l) | |
239 | { | |
240 | Stri ng selecte d = null; | |
241 | swit ch(getPrec edence()) | |
242 | { | |
243 | case MergerCom ponentsFir st: | |
244 | select ed = | |
245 | getFile( ) != null ? getFile( ) : | |
246 | url.getF ile() != n ull && url .getFile() .length() > 0 ? url. getFile() : null; | |
247 | break; | |
248 | case URLFirst: | |
249 | case URLFirstO verridePro tocol: | |
250 | select ed = | |
251 | url.getF ile() != n ull && url .getFile() .length() > 0 ? url. getFile() : | |
252 | getFile( ) != null ? getFile( ) : null; | |
253 | break; | |
254 | } | |
255 | ||
256 | // r emove the starting s lash if it exists | |
257 | if(s elected != null && s elected.le ngth() > 0 && select ed.startsW ith("/")) | |
258 | select ed = selec ted.substr ing(1); | |
259 | ||
260 | retu rn selecte d; | |
261 | } | |
262 | ||
263 | ||
264 | /* * | |
265 | * Port is n ot a requi red field, this meth od may ret urn null. | |
266 | * Note that the merge r componen t port wil l override the URL p ort | |
267 | * if the mo de is URLF irstOverri deProtocol . | |
268 | * | |
269 | * @param ur l | |
270 | * @return | |
271 | * / | |
272 | pr ivate Stri ng selectP ort(URL ur l) | |
273 | { | |
274 | Stri ng selecte d = null; | |
275 | swit ch(getPrec edence()) | |
276 | { | |
277 | case MergerCom ponentsFir st: | |
278 | select ed = | |
279 | getPort( ) >= 0 ? I nteger.toS tring(getP ort()) : | |
280 | url.getP ort() >= 0 ? Integer .toString( url.getPor t()) : nul l; | |
281 | break; | |
282 | case URLFirst: | |
283 | select ed = | |
284 | url.getP ort() >= 0 ? Integer .toString( url.getPor t()) : | |
285 | getPort( ) >= 0 ? I nteger.toS tring(getP ort()) : n ull; | |
286 | break; | |
287 | case URLFirstO verridePro tocol: | |
288 | select ed = | |
289 | getPort( ) >= 0 ? I nteger.toS tring(getP ort()) : | |
290 | url.getP ort() >= 0 ? Integer .toString( url.getPor t()) : nul l; | |
291 | break; | |
292 | } | |
293 | retu rn selecte d; | |
294 | } | |
295 | ||
296 | ||
297 | /* * | |
298 | * The host is a requi red field, this meth od will ne ver return null. | |
299 | * | |
300 | * @param ur l | |
301 | * @return | |
302 | * / | |
303 | pr ivate Stri ng selectH ost(URL ur l) | |
304 | { | |
305 | Stri ng selecte d = null; | |
306 | swit ch(getPrec edence()) | |
307 | { | |
308 | case MergerCom ponentsFir st: | |
309 | select ed = getHo st() == nu ll ? url.g etHost() : getHost() ; | |
310 | break; | |
311 | case URLFirst: | |
312 | case URLFirstO verridePro tocol: | |
313 | select ed = url.g etHost(); | |
314 | } | |
315 | retu rn selecte d; | |
316 | } | |
317 | ||
318 | ||
319 | /* * | |
320 | * UserInfo is not a r equired fi eld, this method may return nu ll. | |
321 | * | |
322 | * @return | |
323 | * / | |
324 | pr ivate Stri ng selectU serInfo(UR L url) | |
325 | { | |
326 | Stri ngBuilder sbUserId = new Strin gBuilder() ; | |
327 | Stri ng urlUser Info = url .getUserIn fo(); | |
328 | Stri ng[] urlUs erInfoComp onents = | |
329 | urlUse rInfo != n ull && url UserInfo.l ength() > 0 ? | |
330 | urlUse rInfo.spli t(":") : n ew String[ ]{null, nu ll}; | |
331 | Stri ng urlUser Id = urlUs erInfoComp onents[0]; | |
332 | Stri ng urlUser Password = urlUserIn foComponen ts.length > 1 ? urlU serInfoCom ponents[1] : null; | |
333 | ||
334 | swit ch(getPrec edence()) | |
335 | { | |
336 | case MergerCom ponentsFir st: | |
337 | if( ge tUsername( ) != null && getUser name().len gth() > 0 ) | |
338 | sbUserId .append( g etUsername Encoded() ); | |
339 | else i f(urlUserI d != null && urlUser Id.length( ) > 0) | |
340 | sbUserId .append( u rlUserId ) ; | |
341 | ||
342 | // don 't add the password if the use r ID isn't specified | |
343 | if( sb UserId.len gth() > 0 ) | |
344 | if(getPa ssword() ! = null && getPasswor d().length () > 0) | |
345 | { | |
346 | sbUserId.a ppend( ':' ); | |
347 | sbUserId.a ppend(getP asswordEnc oded()); | |
348 | } | |
349 | else if( urlUserPas sword != n ull && url UserPasswo rd.length( ) > 0) | |
350 | { | |
351 | sbUserId.a ppend( ':' ); | |
352 | sbUserId.a ppend(urlU serPasswor d); | |
353 | } | |
354 | break; | |
355 | ||
356 | case URLFirst: | |
357 | case URLFirstO verridePro tocol: | |
358 | if(url UserId != null && ur lUserId.le ngth() > 0 ) | |
359 | sbUserId .append( u rlUserId ) ; | |
360 | else i f( getUser name() != null && ge tUsername( ).length() > 0 ) | |
361 | sbUserId .append( g etUsername Encoded() ); | |
362 | ||
363 | // don 't add the password if the use r ID isn't specified | |
364 | if( sb UserId.len gth() > 0 ) | |
365 | if(urlUs erPassword != null & & urlUserP assword.le ngth() > 0 ) | |
366 | { | |
367 | sbUserId.a ppend( ':' ); | |
368 | sbUserId.a ppend(urlU serPasswor d); | |
369 | } | |
370 | else if( getPasswor d() != nul l && getPa ssword().l ength() > 0) | |
371 | { | |
372 | sbUserId.a ppend( ':' ); | |
373 | sbUserId.a ppend(getP asswordEnc oded()); | |
374 | } | |
375 | break; | |
376 | } | |
377 | ||
378 | retu rn sbUserI d.length() > 0 ? sbU serId.toSt ring() : n ull; | |
379 | } | |
380 | ||
381 | /* * | |
382 | * Determine which pro tocol to u se, the pr otocol is a required field, | |
383 | * this meth od will ne ver return null. | |
384 | * | |
385 | * @param ur l | |
386 | * @return | |
387 | * / | |
388 | pr ivate Stri ng selectP rotocol(UR L url) | |
389 | { | |
390 | Stri ng selecte dProtocol = null; | |
391 | swit ch(getPrec edence()) | |
392 | { | |
393 | case MergerCom ponentsFir st: | |
394 | select edProtocol = getProt ocol() == null ? url .getProtoc ol() : get Protocol() ; | |
395 | break; | |
396 | case URLFirst: | |
397 | select edProtocol = url.get Protocol() ; | |
398 | break; | |
399 | case URLFirstO verridePro tocol: | |
400 | select edProtocol = getProt ocol() == null ? url .getProtoc ol() : get Protocol() ; | |
401 | break; | |
402 | } | |
403 | retu rn selecte dProtocol; | |
404 | } | |
405 | ||
406 | ||
407 | /* (non-Java doc) | |
408 | * @see java .lang.Obje ct#toStrin g() | |
409 | * / | |
410 | @O verride | |
411 | pu blic Strin g toString () | |
412 | { | |
413 | retu rn this.ge tPrecedenc e() + "(" + | |
414 | this.g etProtocol () + "://" + | |
415 | this.g etUsername () + ":" + | |
416 | this.g etPassword () + "@" + | |
417 | this.g etHost() + ":" + | |
418 | this.g etPort() + "/" + | |
419 | this.g etFile(); | |
420 | } | |
421 | ||
422 | // ========= ========== ========== ========== ========== ========== ========== ===== | |
423 | // Generated hashCode( ) and equa ls() | |
424 | // ========= ========== ========== ========== ========== ========== ========== ===== | |
425 | ||
426 | /* (non-Java doc) | |
427 | * @see java .lang.Obje ct#hashCod e() | |
428 | * / | |
429 | @O verride | |
430 | pu blic int h ashCode() | |
431 | { | |
432 | fina l int prim e = 31; | |
433 | int result = 1 ; | |
434 | resu lt = prime * result + ((this.f ile == nul l) ? 0 : t his.file.h ashCode()) ; | |
435 | resu lt = prime * result + ((this.h ost == nul l) ? 0 : t his.host.h ashCode()) ; | |
436 | resu lt = prime * result + ((this.p assword == null) ? 0 : this.pa ssword.has hCode()); | |
437 | resu lt = prime * result + this.por t; | |
438 | resu lt = prime * result + ((this.p recedence == null) ? 0 : this. precedence .hashCode( )); | |
439 | resu lt = prime * result + ((this.p rotocol == null) ? 0 : this.pr otocol.has hCode()); | |
440 | resu lt = prime * result + ((this.u sername == null) ? 0 : this.us ername.has hCode()); | |
441 | retu rn result; | |
442 | } | |
443 | ||
444 | ||
445 | /* (non-Java doc) | |
446 | * @see java .lang.Obje ct#equals( java.lang. Object) | |
447 | * / | |
448 | @O verride | |
449 | pu blic boole an equals( Object obj ) | |
450 | { | |
451 | if ( this == ob j) | |
452 | return true; | |
453 | if ( obj == nul l) | |
454 | return false; | |
455 | if ( getClass() != obj.ge tClass()) | |
456 | return false; | |
457 | fina l URLCompo nentMerger other = ( URLCompone ntMerger) obj; | |
458 | if ( this.file == null) | |
459 | { | |
460 | if (ot her.file ! = null) | |
461 | return f alse; | |
462 | } | |
463 | else if (!this .file.equa ls(other.f ile)) | |
464 | return false; | |
465 | if ( this.host == null) | |
466 | { | |
467 | if (ot her.host ! = null) | |
468 | return f alse; | |
469 | } | |
470 | else if (!this .host.equa ls(other.h ost)) | |
471 | return false; | |
472 | if ( this.passw ord == nul l) | |
473 | { | |
474 | if (ot her.passwo rd != null ) | |
475 | return f alse; | |
476 | } | |
477 | else if (!this .password. equals(oth er.passwor d)) | |
478 | return false; | |
479 | if ( this.port != other.p ort) | |
480 | return false; | |
481 | if ( this.prece dence == n ull) | |
482 | { | |
483 | if (ot her.preced ence != nu ll) | |
484 | return f alse; | |
485 | } | |
486 | else if (!this .precedenc e.equals(o ther.prece dence)) | |
487 | return false; | |
488 | if ( this.proto col == nul l) | |
489 | { | |
490 | if (ot her.protoc ol != null ) | |
491 | return f alse; | |
492 | } | |
493 | else if (!this .protocol. equals(oth er.protoco l)) | |
494 | return false; | |
495 | if ( this.usern ame == nul l) | |
496 | { | |
497 | if (ot her.userna me != null ) | |
498 | return f alse; | |
499 | } | |
500 | else if (!this .username. equals(oth er.usernam e)) | |
501 | return false; | |
502 | retu rn true; | |
503 | } | |
504 | ||
505 | ||
506 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.