Changeset 12498
- Timestamp:
- 2006-08-22T15:18:13+12:00 (18 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/download/DownloadJob.java
r12468 r12498 47 47 import org.greenstone.gatherer.Gatherer; 48 48 import org.greenstone.gatherer.GAuthenticator; 49 import org.greenstone.gatherer.LocalGreenstone; 49 50 import org.greenstone.gatherer.file.WorkspaceTree; 50 51 import org.greenstone.gatherer.util.AppendLineOnlyFileDocument; … … 115 116 116 117 this.proxy_url = proxy_url; 117 118 118 119 download_option = downloadToHashMap(download); 119 if (!mode.equals("Z3950") && !mode.equals("SRW")) 120 { 121 Argument url_arg = (Argument)download_option.get((String)"url"); 122 123 download_url = url_arg.getValue(); 124 125 } 126 else 127 { 128 Argument host_arg = (Argument)download_option.get((String)"host"); 129 Argument port_arg = (Argument)download_option.get((String)"port"); 130 download_url = host_arg.getValue() + ":" +port_arg.getValue(); 131 } 120 if (!mode.equals("Z3950") && !mode.equals("SRW")) { 121 Argument url_arg = (Argument)download_option.get((String)"url"); 122 download_url = url_arg.getValue(); 123 124 } 125 else { 126 Argument host_arg = (Argument)download_option.get((String)"host"); 127 Argument port_arg = (Argument)download_option.get((String)"port"); 128 download_url = host_arg.getValue() + ":" +port_arg.getValue(); 129 } 132 130 133 131 folder_hash = download_url.hashCode(); … … 163 161 HashMap download_option = new HashMap(); 164 162 ArrayList arguments = download.getArguments(true, false); 165 for(int i = 0; i < arguments.size(); i++) 166 { 167 Argument argument = (Argument) arguments.get(i); 168 download_option.put(argument.getName(), argument); 169 } 163 for(int i = 0; i < arguments.size(); i++) { 164 Argument argument = (Argument) arguments.get(i); 165 download_option.put(argument.getName(), argument); 166 } 170 167 return download_option; 171 168 } … … 202 199 203 200 public void callDownload() { 204 205 String script =""; 201 202 ArrayList command_list = new ArrayList(); 206 203 if (Utility.isWindows()) { 207 script = "perl -S \"" + Configuration.gsdl_path + "bin" + File.separator + "script" + File.separator + "downloadfrom.pl\""; 208 } 204 command_list.add(Configuration.perl_path); 205 command_list.add("-S"); 206 } 207 command_list.add(LocalGreenstone.getBinScriptDirectoryPath()+"downloadfrom.pl"); 208 command_list.add("-download_mode"); 209 command_list.add(mode); 210 command_list.add("-cache_dir"); 211 212 String user_home = System.getProperty("user.home"); 213 if (Utility.isWindows()){ 214 command_list.add(user_home + File.separator+"gli"+File.separator + "cache"); 215 } 209 216 else{ 210 script =Configuration.gsdl_path + "bin" + File.separator + "script" + File.separator + "downloadfrom.pl"; 211 } 212 213 String mode_arg = "-download_mode"; 214 String mode_par = mode; 215 216 Vector command = new Vector(); 217 command.add(script); 218 command.add(mode_arg); 219 command.add(mode_par); 220 221 String cache_arg = "-cache_dir"; 222 String user_home = System.getProperty("user.home"); 223 String cache_par = ""; 224 225 if (Utility.isWindows()){ 226 cache_par = "\""+ user_home + File.separator+"gli"+File.separator + "cache"+"\""; 227 } 228 else{ 229 cache_par = user_home + File.separator+".gli"+File.separator +"cache"; 230 } 231 232 command.add(cache_arg); 233 command.add(cache_par); 217 command_list.add(user_home + File.separator+".gli"+File.separator +"cache"); 218 } 234 219 235 220 ArrayList all_arg = download.getArguments(true,false); 236 221 for(int i = 0; i < all_arg.size(); i++) { 237 222 Argument argument = (Argument) all_arg.get(i); 238 if(argument.isAssigned()) 239 { 240 command.add("-" + argument.getName()); 241 if(argument.getType() != Argument.FLAG) 242 { 243 command.add(argument.getValue()); 244 } 223 if(argument.isAssigned()) { 224 command_list.add("-" + argument.getName()); 225 if(argument.getType() != Argument.FLAG) { 226 command_list.add(argument.getValue()); 245 227 } 246 247 } 248 249 String [] cmd = new String[command.size()]; 250 String newcmd =""; 251 for(int temp = 0 ; temp < command.size(); temp++) 252 { 253 cmd[temp] = (String)command.get(temp); 254 //System.out.println(cmd[temp]); 255 newcmd +=cmd[temp]+" "; 256 } 257 258 if(previous_state == DownloadJob.COMPLETE) { 228 } 229 } 230 231 String [] cmd = (String []) command_list.toArray(new String[0]); 232 DebugStream.println("Download job, "+command_list); 233 234 if (previous_state == DownloadJob.COMPLETE) { 259 235 progress.mirrorBegun(true, true); 260 236 } … … 266 242 Runtime rt = Runtime.getRuntime(); 267 243 268 244 String [] env = null; 269 245 270 246 Process prcs = null; 271 247 272 248 273 249 if (Utility.isWindows()) { 274 prcs = rt.exec( newcmd);250 prcs = rt.exec(cmd); 275 251 } 276 else{ 277 //for lunix 252 else { 278 253 if (proxy_url != null && !proxy_url.equals("")) { 279 254 env = new String[4]; … … 283 258 env[2] = "GSDLHOME="+Configuration.gsdl_path; 284 259 env[3] = "GSDLOS="+System.getProperty("os.name"); 285 prcs = rt.exec( newcmd,env);260 prcs = rt.exec(cmd,env); 286 261 } 287 else {262 else { 288 263 env = new String[2]; 289 264 290 265 env[0] = "GSDLHOME="+Configuration.gsdl_path; 291 266 env[1] = "GSDLOS="+System.getProperty("os.name"); 292 prcs = rt.exec( newcmd,env);267 prcs = rt.exec(cmd,env); 293 268 } 294 269 … … 307 282 while ((line = br.readLine()) != null && !line.trim().equals("<<Finished>>") && state != STOPPED) { 308 283 309 if( max_download == DownloadJob.UNKNOWN_MAX) 310 { 311 if(line.lastIndexOf("<<Defined Maximum>>") != -1) 312 { 313 max_download = DownloadJob.DEFINED_MAX; 314 } 315 else if(line.lastIndexOf("<<Undefined Maximum>>") != -1) 316 { 317 max_download = DownloadJob.UNDEFINED_MAX; 318 } 319 } 320 else if(max_download == DownloadJob.UNDEFINED_MAX) 321 { 322 DebugStream.println(line); 323 download_log.appendLine(line); 324 // The first magic special test is to see if we've just 325 // asked for the robots.txt file. If so we ignore 326 // the next add and then the next complete/error. 327 if(line.lastIndexOf("robots.txt;") != -1) { 328 DebugStream.println("***** Requesting robot.txt"); 329 ignore_for_robots = true; 284 if ( max_download == DownloadJob.UNKNOWN_MAX) { 285 if(line.lastIndexOf("<<Defined Maximum>>") != -1) { 286 max_download = DownloadJob.DEFINED_MAX; 287 } 288 else if (line.lastIndexOf("<<Undefined Maximum>>") != -1) { 289 max_download = DownloadJob.UNDEFINED_MAX; 290 } 291 } 292 else if(max_download == DownloadJob.UNDEFINED_MAX) { 293 DebugStream.println(line); 294 download_log.appendLine(line); 295 // The first magic special test is to see if we've just 296 // asked for the robots.txt file. If so we ignore 297 // the next add and then the next complete/error. 298 if(line.lastIndexOf("robots.txt;") != -1) { 299 DebugStream.println("***** Requesting robot.txt"); 300 ignore_for_robots = true; 301 } 302 // If line contains "=> `" display text as the 303 // currently downloading url. Unique to add download. 304 else if(line.lastIndexOf("=> `") != -1) { 305 if(!ignore_for_robots) { 306 // Add download 307 String new_url = line.substring(line.indexOf("`") + 1, line.lastIndexOf("'")); 308 //addDownload("http:/" + new_url); 330 309 } 331 // If line contains "=> `" display text as the 332 // currently downloading url. Unique to add download. 333 else if(line.lastIndexOf("=> `") != -1) { 310 } 311 // If line contains "/s) - `" set currently 312 // downloading url to "Download Complete". 313 else if(line.lastIndexOf("/s) - `") != -1) { 314 String current_file_downloading = line.substring(line.indexOf("`") + 1, line.lastIndexOf("'")); 315 if(!ignore_for_robots) { 316 DebugStream.println("Not ignore for robots"); 317 // Download complete 318 downloadComplete(current_file_downloading); 319 } 320 else { 321 DebugStream.println("Ignore for robots"); 322 ignore_for_robots = false; 323 } 324 } 325 // The already there line begins "File `..." However this 326 // is only true in english, so instead I looked and there 327 // are few (if any at all) other messages than those above 328 // and not overwriting messages that use " `" so we'll 329 // look for that. Note this method is not guarenteed to be 330 // unique like the previous two. 331 else if(line.lastIndexOf(" `") != -1) { 332 // Not Overwriting 333 DebugStream.println("Already there."); 334 String new_url = 335 line.substring(line.indexOf("`") + 1, line.lastIndexOf("'")); 336 //addDownload("http:/" + new_url); 337 downloadWarning(); 338 } 339 // Any other important message starts with the time in the form hh:mm:ss 340 else if(line.length() > 7) { 341 if(line.charAt(2) == ':' && line.charAt(5) == ':') { 334 342 if(!ignore_for_robots) { 335 // Add download 336 String new_url = line.substring(line.indexOf("`") + 1, line.lastIndexOf("'")); 337 //addDownload("http:/" + new_url); 338 } 339 } 340 // If line contains "/s) - `" set currently 341 // downloading url to "Download Complete". 342 else if(line.lastIndexOf("/s) - `") != -1) { 343 String current_file_downloading = line.substring(line.indexOf("`") + 1, line.lastIndexOf("'")); 344 if(!ignore_for_robots) { 345 DebugStream.println("Not ignore for robots"); 346 // Download complete 347 downloadComplete(current_file_downloading); 343 DebugStream.println("Error."); 344 downloadFailed(); 348 345 } 349 346 else { 350 DebugStream.println("Ignore for robots");351 347 ignore_for_robots = false; 352 348 } 353 349 } 354 // The already there line begins "File `..." However this 355 // is only true in english, so instead I looked and there 356 // are few (if any at all) other messages than those above 357 // and not overwriting messages that use " `" so we'll 358 // look for that. Note this method is not guarenteed to be 359 // unique like the previous two. 360 else if(line.lastIndexOf(" `") != -1) { 361 // Not Overwriting 362 DebugStream.println("Already there."); 363 String new_url = 364 line.substring(line.indexOf("`") + 1, line.lastIndexOf("'")); 365 //addDownload("http:/" + new_url); 366 downloadWarning(); 367 } 368 // Any other important message starts with the time in the form hh:mm:ss 369 else if(line.length() > 7) { 370 if(line.charAt(2) == ':' && line.charAt(5) == ':') { 371 if(!ignore_for_robots) { 372 DebugStream.println("Error."); 373 downloadFailed(); 374 } 375 else { 376 ignore_for_robots = false; 377 } 378 } 379 } 380 } 381 else if(max_download == DownloadJob.DEFINED_MAX) 382 { 383 if(line.lastIndexOf("<<Total number of record(s):") != -1) 384 { 385 String total_ID = line.substring(line.indexOf(":") + 1, line.indexOf(">")); 386 progress.setTotalDownload((Integer.valueOf(total_ID)).intValue()); 387 progress.resetFileCount(); 388 } 389 else if(line.lastIndexOf("<<Done>>") != -1) 390 { 391 392 progress.increaseFileCount(); 393 } 394 else if(line.lastIndexOf("<<Done:") != -1) 395 { 396 String completed_amount = line.substring(line.indexOf(":") + 1, line.indexOf(">")); 397 progress.increaseFileCount((Integer.valueOf(completed_amount)).intValue()); 398 } 399 400 DebugStream.println(line); 401 download_log.appendLine(line); 402 } 403 else 404 { 405 System.out.println("Error!!"); 406 System.exit(-1); 407 } 350 } 351 } 352 else if (max_download == DownloadJob.DEFINED_MAX) { 353 if (line.lastIndexOf("<<Total number of record(s):") != -1) { 354 String total_ID = line.substring(line.indexOf(":") + 1, line.indexOf(">")); 355 progress.setTotalDownload((Integer.valueOf(total_ID)).intValue()); 356 progress.resetFileCount(); 357 } 358 else if (line.lastIndexOf("<<Done>>") != -1) { 359 progress.increaseFileCount(); 360 } 361 else if(line.lastIndexOf("<<Done:") != -1) { 362 String completed_amount = line.substring(line.indexOf(":") + 1, line.indexOf(">")); 363 progress.increaseFileCount((Integer.valueOf(completed_amount)).intValue()); 364 } 365 366 DebugStream.println(line); 367 download_log.appendLine(line); 368 } 369 else { 370 System.out.println("Error!!"); 371 System.exit(-1); 372 } 408 373 } 409 374 if(state == STOPPED) { … … 508 473 } 509 474 510 /** A conv inence call.475 /** A convenience call. 511 476 * @return A String representing the url of the initial url (root node of the mirrored tree). 512 477 */ -
trunk/gli/src/org/greenstone/gatherer/gui/DownloadPane.java
r12470 r12498 49 49 import org.greenstone.gatherer.Dictionary; 50 50 import org.greenstone.gatherer.Gatherer; 51 import org.greenstone.gatherer.LocalGreenstone; 51 52 import org.greenstone.gatherer.file.WorkspaceTree; 52 53 import org.greenstone.gatherer.util.StaticStrings; … … 227 228 try { 228 229 if (Gatherer.isGsdlRemote) { 229 String launch = Gatherer.cgiBase + "launch"; 230 launch += "?cmd=downloadinfo.pl"; 231 launch += "&xml=&language="+lang; 232 launch += "&plug=" + download_name; 233 230 StringBuffer launch_str = new StringBuffer(); 231 launch_str.append(Gatherer.cgiBase); 232 launch_str.append("launch"); 233 launch_str.append("?cmd=downloadinfo.pl&xml=&language="); 234 launch_str.append(lang); 235 launch_str.append("&plug="); 236 launch_str.append(download_name); 237 238 String launch = launch_str.toString(); 234 239 System.err.println("*** launch = " + launch); 235 240 … … 239 244 } 240 245 else { 246 ArrayList args_list = new ArrayList(); 241 247 String args[] = null; 242 248 if(Utility.isWindows()) { 243 args = new String[6];244 249 if(Configuration.perl_path != null) { 245 args [0] = Configuration.perl_path;250 args_list.add(Configuration.perl_path); 246 251 } 247 252 else { 248 args [0] = "Perl.exe";253 args_list.add("Perl.exe"); 249 254 } 250 args[1] = Configuration.gsdl_path + "bin" + File.separator + "script" + File.separator + "downloadinfo.pl";251 args[2] = "-xml";252 args[3] = "-language";253 args[4] = lang;254 args[5] = download_name;255 255 } 256 else { 257 args = new String[5]; 258 args[0] = "downloadinfo.pl"; 259 args[1] = "-xml"; 260 args[2] = "-language"; 261 args[3] = lang; 262 args[4] = download_name; 263 } 264 256 args_list.add(LocalGreenstone.getBinScriptDirectoryPath()+"downloadinfo.pl"); 257 args_list.add("-xml"); 258 args_list.add("-language"); 259 args_list.add(lang); 260 args_list.add(download_name); 261 265 262 // Create the process. 266 263 args = (String []) args_list.toArray(new String[0]); 267 264 Runtime runtime = Runtime.getRuntime(); 265 DebugStream.println("Getting Download Info: "+args_list); 268 266 Process process = runtime.exec(args); 269 267 … … 525 523 public void actionPerformed(ActionEvent event) { 526 524 527 if(checkURL(true) && checkProxy() == true) 528 {529 530 525 if(checkURL(true) && checkProxy() == true) { 526 527 getter.newDownloadJob((Download)download_map.get(mode) ,mode,proxy_url); 528 } 531 529 } 532 530 } … … 646 644 647 645 648 if(server_info != null) 649 { 650 server_info.dispose(); 651 } 646 if(server_info != null) { 647 server_info.dispose(); 648 } 652 649 653 650 … … 655 652 String str_url = ""; 656 653 657 if( arg_url!= null && arg_url.isAssigned()) 658 { 659 str_url = arg_url.getValue(); 660 } 654 if( arg_url!= null && arg_url.isAssigned()) { 655 str_url = arg_url.getValue(); 656 } 661 657 662 658 663 659 server_info = new ServerInfoDialog(str_url ,proxy_url, mode,(Download)download_map.get(mode)); 664 server_info.setVisible(true);660 665 661 } 666 662 }
Note:
See TracChangeset
for help on using the changeset viewer.