Changeset 10240
- Timestamp:
- 2005-07-13T11:58:35+12:00 (19 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/GathererApplet.java
r10239 r10240 249 249 } 250 250 } 251 252 253 static public void download_url_zip(String col_name, String dir, GShell source, String accept_expr, String reject_expr)254 {255 try {256 String download_cgi = Gatherer.cgiBase + "download";257 258 // Send col_name and dir arguments to download cgi259 260 String col_name_encoded = URLEncoder.encode(col_name,"UTF-8");261 String dir_encoded = URLEncoder.encode(dir,"UTF-8");262 String cgi_args = "c=" + col_name_encoded;263 cgi_args += "&dir=" + dir_encoded + "&a=" + accept_expr + "&r=" + reject_expr;264 265 URL download_url = new URL(download_cgi);266 267 System.err.println("**** download cgi = '" + download_cgi + "'");268 System.err.println("**** cgi args = '" + cgi_args + "'");269 270 URLConnection dl_connection = download_url.openConnection();271 dl_connection.setDoOutput(true);272 OutputStream dl_os = dl_connection.getOutputStream();273 274 PrintWriter dl_out = new PrintWriter(dl_os);275 dl_out.println(cgi_args);276 dl_out.close();277 278 // Download result from running cgi script279 InputStream dl_is = dl_connection.getInputStream();280 BufferedInputStream dl_bis = new BufferedInputStream(dl_is);281 DataInputStream dl_dbis = new DataInputStream(dl_bis);282 283 // set up output stream for zip download284 String col_dir;285 if (col_name.startsWith("/")) {286 col_dir = Configuration.gsdl_path;287 }288 else {289 col_dir = Gatherer.getCollectDirectoryPath();290 }291 292 String zip_fname = col_dir + col_name + ".zip";293 FileOutputStream zip_fos = new FileOutputStream(zip_fname);294 BufferedOutputStream zip_bfos = new BufferedOutputStream(zip_fos);295 296 byte[] buf = new byte[1024];297 int len;298 299 while ((len = dl_dbis.read(buf)) >= 0 && !source.hasSignalledStop()) {300 zip_bfos.write(buf,0,len);301 }302 303 dl_dbis.close();304 dl_bis.close();305 dl_is.close();306 307 zip_bfos.close();308 zip_fos.close();309 310 if(source.hasSignalledStop()) {311 //A cancel has been called. Delete the zip file.312 DebugStream.println("download_url_zip() cancelled. Cleaning up.");313 if(new File(zip_fname).delete()) {314 DebugStream.println("Zip file " + zip_fname + " deleted");315 }316 else {317 DebugStream.println("Zip file " + zip_fname + " NOT deleted (no big deal). Does it exist?");318 }319 }320 }321 catch (Exception error) {322 error.printStackTrace();323 }324 DebugStream.println("Exited download_url_zip");325 }326 327 328 static public void upload_url_zip(String col_name, String dir, String delete_type, GShell source)329 {330 final String lineEnd = "\r\n";331 final String twoHyphens = "--";332 final String boundary = "*****";333 final int maxBufferSize = 1024;334 335 String col_dir;336 if (col_name.startsWith("/")) {337 col_dir = Configuration.gsdl_path;338 }339 else {340 col_dir = Gatherer.getCollectDirectoryPath();341 }342 343 String zip_fname = col_dir + col_name + ".zip";344 String upload_cgi = Gatherer.cgiBase + "upload";345 346 HttpURLConnection conn = null;347 348 try {349 // Send zip file to server350 351 File file = new File(zip_fname) ;352 353 FileInputStream fileInputStream = new FileInputStream(file);354 355 // open a URL connection to the Servlet356 URL url = new URL(upload_cgi);357 System.err.println("**** Uploading to: " + upload_cgi);358 359 // Open a HTTP connection to the URL360 conn = (HttpURLConnection) url.openConnection();361 362 conn.setDoInput(true); // Allow Inputs363 conn.setDoOutput(true); // Allow Outputs364 conn.setUseCaches(false); // Don't use a cached copy.365 conn.setRequestMethod("POST"); // Use a post method.366 367 conn.setRequestProperty("Connection", "Keep-Alive");368 conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);369 370 DataOutputStream dos = new DataOutputStream( conn.getOutputStream() );371 372 dos.writeBytes(twoHyphens + boundary + lineEnd);373 dos.writeBytes("Content-Disposition: form-data; name=\"c\"" + lineEnd + lineEnd);374 dos.writeBytes(col_name + lineEnd);375 System.err.println("**** c="+col_name);376 377 dos.writeBytes(twoHyphens + boundary + lineEnd);378 dos.writeBytes("Content-Disposition: form-data; name=\"dir\"" + lineEnd + lineEnd);379 dos.writeBytes(dir + lineEnd);380 System.err.println("**** dir="+dir);381 382 dos.writeBytes(twoHyphens + boundary + lineEnd);383 dos.writeBytes("Content-Disposition: form-data; name=\"del\"" + lineEnd + lineEnd);384 dos.writeBytes(delete_type + lineEnd);385 System.err.println("**** del="+delete_type);386 387 dos.writeBytes(twoHyphens + boundary + lineEnd);388 dos.writeBytes("Content-Disposition: form-data; name=\"zip\";"389 + " filename=\"" + zip_fname +"\"" + lineEnd);390 dos.writeBytes(lineEnd);391 System.err.println("**** zip (filename)="+zip_fname);392 393 394 395 // create a buffer of maximum size396 int bytesAvailable = fileInputStream.available();397 int bufferSize = Math.min(bytesAvailable, maxBufferSize);398 byte[] buffer = new byte[bufferSize];399 400 // read file and write it into form...401 int bytesRead = fileInputStream.read(buffer, 0, bufferSize);402 403 while (bytesRead > 0) {404 // Check to see if action has been cancelled.405 if (source != null && source.hasSignalledStop()) {406 break;407 }408 dos.write(buffer, 0, bufferSize);409 bytesAvailable = fileInputStream.available();410 bufferSize = Math.min(bytesAvailable, maxBufferSize);411 bytesRead = fileInputStream.read(buffer, 0, bufferSize);412 }413 414 // send multipart form data necesssary after file data...415 416 dos.writeBytes(lineEnd);417 dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);418 419 // close streams420 421 fileInputStream.close();422 dos.flush();423 dos.close();424 425 // delete zip file426 boolean file_deleted = file.delete();427 if (file_deleted) {428 System.err.println("Zip file " + file.toString() + " deleted");429 }430 else {431 System.err.println("Zip file " + file.toString() + " NOT deleted");432 }433 }434 catch (MalformedURLException ex) {435 System.err.println("Failed on: "+ex);436 }437 438 catch (IOException ioe) {439 System.err.println("Failed on: "+ioe);440 }441 442 // Read server response443 444 try {445 InputStreamReader isr = new InputStreamReader(conn.getInputStream() );446 BufferedReader bisr = new BufferedReader (isr);447 String str;448 while (( str = bisr.readLine()) != null) {449 System.err.println(str);450 }451 bisr.close();452 453 }454 catch (IOException ioex) {455 System.err.println("From (ServerResponse): "+ioex);456 }457 }458 251 } -
trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java
r10237 r10240 37 37 import org.greenstone.gatherer.Dictionary; 38 38 import org.greenstone.gatherer.Gatherer; 39 import org.greenstone.gatherer.GathererApplet;40 39 import org.greenstone.gatherer.LocalLibraryServer; 40 import org.greenstone.gatherer.RemoteGreenstoneServer; 41 41 import org.greenstone.gatherer.util.Utility; 42 42 import org.w3c.dom.*; … … 233 233 //upload etc/collect.cfg to the server to immediately reflect these changes. 234 234 Utility.zipup(Gatherer.getCollectDirectoryPath(), collection_name, Utility.CONFIG_FILE, null, "", ""); 235 GathererApplet.upload_url_zip(collection_name, "etc", "", null);235 RemoteGreenstoneServer.upload_url_zip(collection_name, "etc", "", null); 236 236 } 237 237 -
trunk/gli/src/org/greenstone/gatherer/gui/CreatePane.java
r10237 r10240 48 48 import org.greenstone.gatherer.Dictionary; 49 49 import org.greenstone.gatherer.Gatherer; 50 import org.greenstone.gatherer. GathererApplet;50 import org.greenstone.gatherer.RemoteGreenstoneServer; 51 51 import org.greenstone.gatherer.cdm.SearchTypeManager; 52 52 import org.greenstone.gatherer.cdm.CollectionDesignManager; … … 690 690 //First upload the collect.cfg file 691 691 Utility.zipup(Gatherer.getCollectDirectoryPath(), collection_name, Utility.CONFIG_FILE, null, "", ""); 692 GathererApplet.upload_url_zip(collection_name, "etc", "", null);692 RemoteGreenstoneServer.upload_url_zip(collection_name, "etc", "", null); 693 693 694 694 //Just run the buildcol command. -
trunk/gli/src/org/greenstone/gatherer/shell/GShell.java
r10237 r10240 49 49 import org.greenstone.gatherer.Dictionary; 50 50 import org.greenstone.gatherer.Gatherer; 51 import org.greenstone.gatherer. GathererApplet;51 import org.greenstone.gatherer.RemoteGreenstoneServer; 52 52 import org.greenstone.gatherer.cdm.CollectionConfiguration; 53 53 import org.greenstone.gatherer.cdm.CollectionDesignManager; … … 244 244 if(hasSignalledStop()) { return; } 245 245 // upload it to gsdl server 246 GathererApplet.upload_url_zip(col_name, "import", "files", this);246 RemoteGreenstoneServer.upload_url_zip(col_name, "import", "files", this); 247 247 248 248 Gatherer.c_man.getCollection().setFilesChanged(false); … … 255 255 if(hasSignalledStop()) { return; } 256 256 // upload it to gsdl server 257 GathererApplet.upload_url_zip(col_name, "import", "metadata", this);257 RemoteGreenstoneServer.upload_url_zip(col_name, "import", "metadata", this); 258 258 Gatherer.c_man.getCollection().setMetadataChanged(false); 259 259 System.err.println("Finished uploading metadata."); … … 265 265 266 266 if(hasSignalledStop()) { return; } 267 GathererApplet.upload_url_zip(col_name, "etc", "", this);267 RemoteGreenstoneServer.upload_url_zip(col_name, "etc", "", this); 268 268 269 269 String collection_directory_path = Gatherer.c_man.getCollectionDirectoryPath(col_name); … … 275 275 276 276 if(hasSignalledStop()) { return; } 277 GathererApplet.upload_url_zip(col_name, "images", "", this);277 RemoteGreenstoneServer.upload_url_zip(col_name, "images", "", this); 278 278 279 279 System.err.println("collect_directory_path: " + collect_directory_path); … … 552 552 if (type == NEW) { 553 553 if (Gatherer.isGsdlRemote) { 554 GathererApplet.download_url_zip(col_name, ".", this, "", "");554 RemoteGreenstoneServer.download_url_zip(col_name, ".", this, "", ""); 555 555 if (!hasSignalledStop()) { 556 556 Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name); … … 569 569 Utility.delete(Gatherer.c_man.getCollectionArchivesDirectoryPath()); // remove current archives 570 570 //new File(Gatherer.c_man.getCollectionArchivesDirectoryPath()).mkdir(); //Make a clean dir 571 GathererApplet.download_url_zip(col_name, "archives", this, ".*doc\\.xml", "");571 RemoteGreenstoneServer.download_url_zip(col_name, "archives", this, ".*doc\\.xml", ""); 572 572 if (hasSignalledStop()) { 573 573 // Clean up, then exit … … 609 609 Utility.delete(buildDir); // remove current build dir 610 610 //Only need build.cfg 611 GathererApplet.download_url_zip(col_name, "building", this, ".*build\\.cfg", "");611 RemoteGreenstoneServer.download_url_zip(col_name, "building", this, ".*build\\.cfg", ""); 612 612 if (!hasSignalledStop()) { 613 613 Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name); … … 652 652 653 653 Utility.delete(full_local_cd_dir); // remove current cd-rom dir, if it exists 654 GathererApplet.download_url_zip(user_tmp_dir,cd_dir,this,"","");654 RemoteGreenstoneServer.download_url_zip(user_tmp_dir,cd_dir,this,"",""); 655 655 656 656 Utility.unzip(Configuration.gsdl_path, user_tmp_dir.substring(1));
Note:
See TracChangeset
for help on using the changeset viewer.