Produced by Araxis Merge on 12/5/2017 12:06:43 PM Central Standard 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 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingCommon\main\src\java\gov\va\med\interactive | CommandFileCommandSource.java | Mon Dec 4 21:34:26 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingCommon\main\src\java\gov\va\med\interactive | CommandFileCommandSource.java | Mon Dec 4 22:02:06 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 704 |
| Changed | 1 | 2 |
| 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 | package go v.va.med.i nteractive ; | |
| 2 | ||
| 3 | ||
| 4 | import gov .va.med.in teractive. commands.E xitCommand ; | |
| 5 | import jav a.io.*; | |
| 6 | import jav a.net.Malf ormedURLEx ception; | |
| 7 | import jav a.net.URL; | |
| 8 | import jav a.util.Arr ayList; | |
| 9 | import jav a.util.Lis t; | |
| 10 | import jav a.util.con current.Bl ockingQueu e; | |
| 11 | import jav a.util.reg ex.Matcher ; | |
| 12 | import jav a.util.reg ex.Pattern ; | |
| 13 | ||
| 14 | import org .apache.lo gging.log4 j.LogManag er; | |
| 15 | import org .apache.lo gging.log4 j.Logger; | |
| 16 | ||
| 17 | /** | |
| 18 | * This cl ass: | |
| 19 | * | |
| 20 | * @author
|
|
| 21 | * | |
| 22 | */ | |
| 23 | public cla ss Command FileComman dSource<M> | |
| 24 | implements CommandSo urce<M> | |
| 25 | { | |
| 26 | pr ivate fina l Logger l ogger = Lo gManager.g etLogger(t his.getCla ss()); | |
| 27 | pr ivate fina l String s ourceUrl; | |
| 28 | pr ivate fina l String[] substitut ionStrings ; | |
| 29 | pr ivate fina l InputStr eam inStre am; | |
| 30 | pr ivate Comm andFactory <M> comman dFactory; | |
| 31 | pr ivate Comm andControl ler<M> com mandContro ller; | |
| 32 | pr ivate bool ean exitRe quested; | |
| 33 | ||
| 34 | /* * | |
| 35 | * Creates a CommandFi leCommandS ource inst ance. | |
| 36 | * This meth od opens t he URL or resource b efore retu rning. | |
| 37 | * If the UR L or resou rce refere nces an in valid reso urce then | |
| 38 | * no Comman dFileComma ndSource i s created and null i s returned . | |
| 39 | * | |
| 40 | * @param so urceUrl | |
| 41 | * @param su bstitution Strings | |
| 42 | * @return | |
| 43 | * @throws I OException | |
| 44 | * / | |
| 45 | pu blic stati c CommandF ileCommand Source<?> create(Str ing source Url, Strin g[] substi tutionStri ngs) | |
| 46 | th rows IOExc eption | |
| 47 | { | |
| 48 | Inpu tStream in Stream; | |
| 49 | ||
| 50 | try | |
| 51 | { | |
| 52 | try | |
| 53 | { | |
| 54 | URL url = new URL( sourceUrl) ; | |
| 55 | inStream = url.ope nStream(); | |
| 56 | if(inStr eam == nul l) | |
| 57 | throw new IOExceptio n("Unable to open '" + sourceU rl + "' as a URL."); | |
| 58 | return n ew Command FileComman dSource(in Stream, so urceUrl, s ubstitutio nStrings); | |
| 59 | } | |
| 60 | catch (Malformed URLExcepti on x) | |
| 61 | { | |
| 62 | // if we can't ope n the stre am as a UR L then try it as a r esource | |
| 63 | if(sourc eUrl.start sWith(RESO URCE_PROTO COL)) | |
| 64 | sourceUrl = sourceUr l.substrin g(RESOURCE _PROTOCOL. length()); | |
| 65 | inStream = Command FileComman dSource.cl ass.getCla ssLoader() .getResour ceAsStream (sourceUrl ); | |
| 66 | if(inStr eam == nul l) | |
| 67 | throw new IOExceptio n("Unable to open '" + sourceU rl + "' as a resourc e."); | |
| 68 | return n ew Command FileComman dSource(in Stream, so urceUrl, s ubstitutio nStrings); | |
| 69 | } | |
| 70 | } | |
| 71 | catc h(IOExcept ion ioX) | |
| 72 | { | |
| 73 | LogMan ager.getLo gger(Comma ndFileComm andSource. class).err or("Unable to open c ommand fil e '" + sou rceUrl + " ', " + ioX .getMessag e()); | |
| 74 | return null; | |
| 75 | } | |
| 76 | } | |
| 77 | /* * | |
| 78 | * Pass the command fi le and the remainder of the co mmand line arguments . | |
| 79 | * The comma nd line ar guments af ter the fi le name ma y be used as substit ution | |
| 80 | * strings. | |
| 81 | * / | |
| 82 | pr ivate Comm andFileCom mandSource (InputStre am inStrea m, String sourceUrl, String[] substituti onStrings) | |
| 83 | { | |
| 84 | asse rt(inStrea m != null) ; | |
| 85 | this .inStream = inStream ; | |
| 86 | this .sourceUrl = sourceU rl; | |
| 87 | this .substitut ionStrings = substit utionStrin gs; | |
| 88 | } | |
| 89 | ||
| 90 | /* * | |
| 91 | * @return t he inStrea m | |
| 92 | * / | |
| 93 | pu blic Input Stream get InStream() | |
| 94 | { | |
| 95 | retu rn this.in Stream; | |
| 96 | } | |
| 97 | /* * | |
| 98 | * @return t he sourceU rl | |
| 99 | * / | |
| 100 | pu blic Strin g getSourc eUrl() | |
| 101 | { | |
| 102 | retu rn this.so urceUrl; | |
| 103 | } | |
| 104 | ||
| 105 | /* * | |
| 106 | * @return t he substit utionStrin gs | |
| 107 | * / | |
| 108 | pu blic Strin g[] getSub stitutionS trings() | |
| 109 | { | |
| 110 | retu rn this.su bstitution Strings; | |
| 111 | } | |
| 112 | ||
| 113 | @O verride | |
| 114 | pu blic void commandQue ueAvailabl e(){queueS avedComman ds();} | |
| 115 | @O verride | |
| 116 | pu blic void commandQue ueUnavaila ble(){} | |
| 117 | @O verride | |
| 118 | pu blic void managedObj ectAvailab le(){} | |
| 119 | @O verride | |
| 120 | pu blic void managedObj ectUnavail able(){} | |
| 121 | ||
| 122 | pu blic Block ingQueue<C ommand<M>> getComman dQueue(){r eturn this .commandCo ntroller.g etCommandQ ueue();} | |
| 123 | @O verride | |
| 124 | pu blic void setCommand Controller (CommandCo ntroller<M > commandC ontroller) {this.comm andControl ler = comm andControl ler;} | |
| 125 | ||
| 126 | @O verride | |
| 127 | pu blic void setCommand Factory(Co mmandFacto ry<M> comm andFactory ){this.com mandFactor y = comman dFactory;} | |
| 128 | ||
| 129 | @O verride | |
| 130 | pu blic Comma ndFactory< M> getComm andFactory (){return this.comma ndFactory; } | |
| 131 | ||
| 132 | /* * | |
| 133 | * @param co mmandLine | |
| 134 | * @throws C ommandLine ParseExcep tion | |
| 135 | * / | |
| 136 | @O verride | |
| 137 | pu blic void pushComman ds(String[ ] commandL ine) | |
| 138 | th rows Comma ndLinePars eException | |
| 139 | {} | |
| 140 | ||
| 141 | pu blic boole an isExitR equested() | |
| 142 | { | |
| 143 | retu rn this.ex itRequeste d; | |
| 144 | } | |
| 145 | ||
| 146 | pr ivate void setExitRe quested(bo olean exit Requested) | |
| 147 | { | |
| 148 | this .exitReque sted = exi tRequested ; | |
| 149 | } | |
| 150 | ||
| 151 | pu blic Logge r getLogge r() | |
| 152 | { | |
| 153 | retu rn this.lo gger; | |
| 154 | } | |
| 155 | ||
| 156 | /* * | |
| 157 | * Read the command fi le, parse and add co mmands to the queue | |
| 158 | * / | |
| 159 | @O verride | |
| 160 | pu blic void run() | |
| 161 | { | |
| 162 | Stri ng[][] com mandsText = getComma ndsText(); | |
| 163 | for( String[] c ommandText : command sText) | |
| 164 | { | |
| 165 | if(com mandText.l ength == 0 ) | |
| 166 | continue ; | |
| 167 | ||
| 168 | String commandNa me = comma ndText[0]; | |
| 169 | String [] command Parameters = null; | |
| 170 | ||
| 171 | if(com mandText.l ength > 1) | |
| 172 | { | |
| 173 | commandP arameters = new Stri ng[command Text.lengt h-1]; | |
| 174 | System.a rraycopy(c ommandText , 1, comma ndParamete rs, 0, com mandParame ters.lengt h); | |
| 175 | } | |
| 176 | ||
| 177 | try | |
| 178 | { | |
| 179 | Command< M> command = getComm andFactory ().createC ommand( co mmandName, commandPa rameters ) ; | |
| 180 | getLogge r().debug( "Created c ommand of type '" + command.ge tClass().g etName() + "'."); | |
| 181 | queueCom mand(comma nd); | |
| 182 | if(comma nd.exitAft erProcessi ng()) | |
| 183 | setExitReq uested(tru e); | |
| 184 | } | |
| 185 | catch (Exception x) | |
| 186 | { | |
| 187 | System.e rr.println ("Unable t o create a valid '" + commandN ame + "' c ommand, " + x.getMes sage()); | |
| 188 | } | |
| 189 | } | |
| 190 | ||
| 191 | // i f the user didn't as k for an e xit, we'll add one f or them | |
| 192 | if(! isExitReq uested()) | |
| 193 | { | |
| 194 | queueC ommand(new ExitComma nd()); | |
| 195 | setExi tRequested (true); | |
| 196 | } | |
| 197 | } | |
| 198 | ||
| 199 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== == | |
| 200 | // local com mand queue ing | |
| 201 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== == | |
| 202 | ||
| 203 | pr ivate List <Command<M >> savedCo mmands = n ew ArrayLi st<Command <M>>(); | |
| 204 | /* * | |
| 205 | * | |
| 206 | * @param co mmands | |
| 207 | * / | |
| 208 | pr ivate sync hronized v oid queueC ommand(Com mand<M> co mmand) | |
| 209 | { | |
| 210 | if(g etCommandQ ueue() != null) | |
| 211 | { | |
| 212 | getCom mandQueue( ).add(comm and); | |
| 213 | if(com mand.exitA fterProces sing()) | |
| 214 | setExitR equested(t rue); | |
| 215 | } | |
| 216 | else | |
| 217 | { | |
| 218 | synchr onized (sa vedCommand s) | |
| 219 | { | |
| 220 | savedCom mands.add( command); | |
| 221 | } | |
| 222 | } | |
| 223 | } | |
| 224 | pr ivate void queueSave dCommands( ) | |
| 225 | { | |
| 226 | sync hronized ( savedComma nds) | |
| 227 | { | |
| 228 | if(get CommandQue ue() != nu ll) | |
| 229 | { | |
| 230 | for(Comm and<M> com mand : sav edCommands ) | |
| 231 | queueComma nd(command ); | |
| 232 | ||
| 233 | savedCom mands.clea r(); | |
| 234 | } | |
| 235 | } | |
| 236 | } | |
| 237 | ||
| 238 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== == | |
| 239 | // File read ing and pa rsing | |
| 240 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== == | |
| 241 | pr ivate stat ic final S tring RESO URCE_PROTO COL = "res ource://"; | |
| 242 | pr ivate Stri ng[][] com mandsText; | |
| 243 | /* * | |
| 244 | * @return t he command sText | |
| 245 | * / | |
| 246 | pu blic synch ronized St ring[][] g etCommands Text() | |
| 247 | { | |
| 248 | if(t his.comman dsText == null) | |
| 249 | this.c ommandsTex t = readCo mmandText( getInStrea m(), getSu bstitution Strings()) ; | |
| 250 | ||
| 251 | retu rn this.co mmandsText ; | |
| 252 | } | |
| 253 | ||
| 254 | /* * | |
| 255 | * Do NOT ca ll this fr om anywher e but the getCommand sText() me thod !!! | |
| 256 | * @return | |
| 257 | * / | |
| 258 | pu blic stati c String[] [] readCom mandText(I nputStream inStream, String[] substituti onStrings) | |
| 259 | { | |
| 260 | Stre amTokenize r tokenize r = new St reamTokeni zer( new I nputStream Reader(inS tream) ); | |
| 261 | toke nizer.rese tSyntax(); | |
| 262 | toke nizer.whit espaceChar s(0x0A, 0x 0A); | |
| 263 | toke nizer.whit espaceChar s(0x0D, 0x 0D); | |
| 264 | toke nizer.word Chars(0x20 , 0x20); // <sp ace> | |
| 265 | toke nizer.comm entChar(0x 21); // ! | |
| 266 | toke nizer.quot eChar(0x22 ); // doubl e quote | |
| 267 | toke nizer.word Chars(0x23 , 0x2B); // pun ctuation | |
| 268 | toke nizer.whit espaceChar s(0x2C, 0x 2C); // c omma | |
| 269 | toke nizer.word Chars(0x2D , 0x2F); // pun ctuation | |
| 270 | toke nizer.word Chars(0x30 , 0x39); // 0 . .. 9 | |
| 271 | toke nizer.word Chars(0x3A , 0x40); // pun ctuation | |
| 272 | toke nizer.word Chars(0x41 , 0x5A); // A . .. Z | |
| 273 | toke nizer.word Chars(0x5B , 0x60); // pun ctuation | |
| 274 | toke nizer.word Chars(0x61 , 0x7A); // a . .. z | |
| 275 | toke nizer.word Chars(0x7B , 0x7E); // pun ctuation | |
| 276 | toke nizer.eolI sSignifica nt(true); | |
| 277 | ||
| 278 | List <String[]> commands = new Arra yList<Stri ng[]>(); | |
| 279 | try | |
| 280 | { | |
| 281 | List<S tring> com mand = new ArrayList <String>() ; | |
| 282 | while( StreamTok enizer.TT_ EOF != tok enizer.nex tToken() ) | |
| 283 | { | |
| 284 | if( Stre amTokenize r.TT_EOL = = tokenize r.ttype) | |
| 285 | { | |
| 286 | String[] c ommandText = command .toArray(n ew String[ command.si ze()]); | |
| 287 | doStringSu bstitution (commandTe xt, substi tutionStri ngs); | |
| 288 | commands.a dd( comman dText ); | |
| 289 | ||
| 290 | command.cl ear(); | |
| 291 | } | |
| 292 | else if( 0x22 == t okenizer.t type ) // a quote d string | |
| 293 | { | |
| 294 | String tok en = token izer.sval == null ? "" : token izer.sval. trim(); | |
| 295 | command.ad d(token); | |
| 296 | } | |
| 297 | else | |
| 298 | { | |
| 299 | String tok en = token izer.sval == null ? "" : token izer.sval. trim(); | |
| 300 | command.ad d(token); | |
| 301 | } | |
| 302 | } | |
| 303 | // add the last line read | |
| 304 | String [] command Text = com mand.toArr ay(new Str ing[comman d.size()]) ; | |
| 305 | doStri ngSubstitu tion(comma ndText, su bstitution Strings); | |
| 306 | comman ds.add( co mmandText ); | |
| 307 | } | |
| 308 | catc h (IOExcep tion ioX) | |
| 309 | { | |
| 310 | LogMan ager.getLo gger(Comma ndFileComm andSource. class).err or("Error reading co mmand file ', " + io X.getMessa ge()); | |
| 311 | ioX.pr intStackTr ace(); | |
| 312 | } | |
| 313 | ||
| 314 | retu rn command s.toArray( new String [commands. size()][]) ; | |
| 315 | } | |
| 316 | ||
| 317 | /* * | |
| 318 | * Substitut e instance s of %n wi th the com mand param eter value s | |
| 319 | * | |
| 320 | * @param co mmandText | |
| 321 | * @param su bstitution Strings | |
| 322 | * / | |
| 323 | pr otected st atic void doStringSu bstitution (String[] commandTex t, String[ ] substitu tionString s) | |
| 324 | { | |
| 325 | if(c ommandText == null | | substitu tionString s == null || substit utionStrin gs.length < 1) | |
| 326 | return ; | |
| 327 | ||
| 328 | // a shortcut to avoid R EGEX calls if no str ing substi tution | |
| 329 | bool ean subStr ingFound = false; | |
| 330 | for( String com mandElemen t : comman dText) | |
| 331 | if( co mmandEleme nt != null && comman dElement.i ndexOf('%' ) >= 0 ) | |
| 332 | { | |
| 333 | subStrin gFound = t rue; | |
| 334 | break; | |
| 335 | } | |
| 336 | if(! subStringF ound) | |
| 337 | return ; | |
| 338 | ||
| 339 | // | |
| 340 | for( int substi tutionStri ngindex = substituti onStrings. length; su bstitution Stringinde x >= 1; -- substituti onStringin dex) | |
| 341 | { | |
| 342 | String substitut ionString = substitu tionString s[substitu tionString index-1]; // -1 because of 0 versus 1 based in dexing | |
| 343 | String substitut ionRegex = "\\x25" + substitut ionStringi ndex; // make a regex of a percent s ign and th e index | |
| 344 | Patter n substitu tionPatter n = Patter n.compile( substituti onRegex); | |
| 345 | ||
| 346 | for(in t commandI ndex=0; co mmandIndex < command Text.lengt h; ++comma ndIndex) | |
| 347 | { | |
| 348 | Matcher substituti onMatcher = substitu tionPatter n.matcher( commandTex t[commandI ndex]); | |
| 349 | commandT ext[comman dIndex] = substituti onMatcher. replaceAll (substitut ionString) ; | |
| 350 | } | |
| 351 | } | |
| 352 | } | |
| 353 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.