Changeset 8250
- Timestamp:
- 2004-10-08T14:33:22+13:00 (20 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/GathererApplet.java
r7991 r8250 211 211 gatherer.run(size, splash, g_man); 212 212 } 213 214 215 static public void download_url_zip(String col_name, String dir) 216 { 217 try { 218 String download_cgi = Gatherer.cgiBase + "download"; 219 220 // Send col_name and dir arguments to download cgi 221 222 String col_name_encoded = URLEncoder.encode(col_name,"UTF-8"); 223 String dir_encoded = URLEncoder.encode(dir,"UTF-8"); 224 String cgi_args = "c=" + col_name_encoded; 225 cgi_args += "&dir=" + dir_encoded; 226 227 URL download_url = new URL(download_cgi); 228 229 System.err.println("**** download cgi = '" + download_cgi + "'"); 230 System.err.println("**** cgi args = '" + cgi_args + "'"); 231 232 URLConnection dl_connection = download_url.openConnection(); 233 dl_connection.setDoOutput(true); 234 OutputStream dl_os = dl_connection.getOutputStream(); 235 236 PrintWriter dl_out = new PrintWriter(dl_os); 237 dl_out.println(cgi_args); 238 dl_out.close(); 239 240 // Download result from running cgi script 241 InputStream dl_is = dl_connection.getInputStream(); 242 BufferedInputStream dl_bis = new BufferedInputStream(dl_is); 243 DataInputStream dl_dbis = new DataInputStream(dl_bis); 244 245 // set up output stream for zip download 246 String col_dir = Utility.getCollectDir(Configuration.gsdl_path); 247 String zip_fname = col_dir + col_name + ".zip"; 248 FileOutputStream zip_fos = new FileOutputStream(zip_fname); 249 BufferedOutputStream zip_bfos = new BufferedOutputStream(zip_fos); 250 251 byte[] buf = new byte[1024]; 252 int len; 253 254 while ((len = dl_dbis.read(buf)) >= 0) { 255 zip_bfos.write(buf,0,len); 256 } 257 258 dl_dbis.close(); 259 zip_bfos.close(); 260 261 } 262 catch (Exception error) { 263 error.printStackTrace(); 264 } 265 } 266 267 268 static public void upload_url_zip(String col_name, String dir) 269 { 270 final String lineEnd = "\r\n"; 271 final String twoHyphens = "--"; 272 final String boundary = "*****"; 273 final int maxBufferSize = 1024; 274 275 String col_dir = Utility.getCollectDir(Configuration.gsdl_path); 276 String zip_fname = col_dir + col_name + ".zip"; 277 String upload_cgi = Gatherer.cgiBase + "upload"; 278 279 HttpURLConnection conn = null; 280 281 try { 282 // Send zip file to server 283 284 File file = new File(zip_fname) ; 285 FileInputStream fileInputStream = new FileInputStream(file); 286 287 // open a URL connection to the Servlet 288 URL url = new URL(upload_cgi); 289 System.err.println("**** Uploading to: " + upload_cgi); 290 291 // Open a HTTP connection to the URL 292 conn = (HttpURLConnection) url.openConnection(); 293 294 conn.setDoInput(true); // Allow Inputs 295 conn.setDoOutput(true); // Allow Outputs 296 conn.setUseCaches(false); // Don't use a cached copy. 297 conn.setRequestMethod("POST"); // Use a post method. 298 299 conn.setRequestProperty("Connection", "Keep-Alive"); 300 conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary); 301 302 DataOutputStream dos = new DataOutputStream( conn.getOutputStream() ); 303 304 dos.writeBytes(twoHyphens + boundary + lineEnd); 305 dos.writeBytes("Content-Disposition: form-data; name=\"c\"" + lineEnd + lineEnd); 306 dos.writeBytes(col_name + lineEnd); 307 System.err.println("**** c="+col_name); 308 309 dos.writeBytes(twoHyphens + boundary + lineEnd); 310 dos.writeBytes("Content-Disposition: form-data; name=\"dir\"" + lineEnd + lineEnd); 311 dos.writeBytes(dir + lineEnd); 312 System.err.println("**** dir="+dir); 313 314 dos.writeBytes(twoHyphens + boundary + lineEnd); 315 dos.writeBytes("Content-Disposition: form-data; name=\"zip\";" 316 + " filename=\"" + zip_fname +"\"" + lineEnd); 317 dos.writeBytes(lineEnd); 318 System.err.println("**** zip (filename)="+zip_fname); 319 320 // create a buffer of maximum size 321 int bytesAvailable = fileInputStream.available(); 322 int bufferSize = Math.min(bytesAvailable, maxBufferSize); 323 byte[] buffer = new byte[bufferSize]; 324 325 // read file and write it into form... 326 int bytesRead = fileInputStream.read(buffer, 0, bufferSize); 327 328 while (bytesRead > 0) { 329 dos.write(buffer, 0, bufferSize); 330 bytesAvailable = fileInputStream.available(); 331 bufferSize = Math.min(bytesAvailable, maxBufferSize); 332 bytesRead = fileInputStream.read(buffer, 0, bufferSize); 333 } 334 335 // send multipart form data necesssary after file data... 336 337 dos.writeBytes(lineEnd); 338 dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); 339 340 // close streams 341 342 fileInputStream.close(); 343 dos.flush(); 344 dos.close(); 345 346 347 } 348 catch (MalformedURLException ex) { 349 System.err.println("Failed on: "+ex); 350 } 351 352 catch (IOException ioe) { 353 System.err.println("Failed on: "+ioe); 354 } 355 356 // Read server response 357 358 try { 359 InputStreamReader isr = new InputStreamReader(conn.getInputStream() ); 360 BufferedReader bisr = new BufferedReader (isr); 361 String str; 362 while (( str = bisr.readLine()) != null) { 363 System.err.println(str); 364 } 365 bisr.close(); 366 367 } 368 catch (IOException ioex) { 369 System.err.println("From (ServerResponse): "+ioex); 370 } 371 } 213 372 } -
trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java
r8249 r8250 37 37 import org.greenstone.gatherer.Dictionary; 38 38 import org.greenstone.gatherer.Gatherer; 39 import org.greenstone.gatherer.GathererApplet; 39 40 import org.greenstone.gatherer.util.GSDLSiteConfig; 40 41 import org.greenstone.gatherer.util.Utility; … … 226 227 // upload etc/collect.cfg to server to reflect changes 227 228 Utility.zipup(col_name,Utility.CONFIG_FILE); 228 Utility.upload_url_zip(col_name,"etc");229 GathererApplet.upload_url_zip(col_name,"etc"); 229 230 } 230 231 } -
trunk/gli/src/org/greenstone/gatherer/shell/GShell.java
r8243 r8250 48 48 import org.greenstone.gatherer.Dictionary; 49 49 import org.greenstone.gatherer.Gatherer; 50 import org.greenstone.gatherer.GathererApplet; 50 51 import org.greenstone.gatherer.cdm.CollectionConfiguration; 51 52 import org.greenstone.gatherer.cdm.CollectionDesignManager; … … 466 467 Utility.zipup(col_name,"import"); 467 468 // upload it to gsdl server 468 Utility.upload_url_zip(col_name,"import");469 GathererApplet.upload_url_zip(col_name,"import"); 469 470 470 471 // upload etc folder to server (need collect.cfg and any hfiles) 471 472 Utility.zipup(col_name, "etc"); 472 Utility.upload_url_zip(col_name,"etc");473 GathererApplet.upload_url_zip(col_name,"etc"); 473 474 474 475 String col_dir = Utility.getCollectionDir(Configuration.gsdl_path, col_name); … … 477 478 // upload images/ directory to server 478 479 Utility.zipup(col_name,"images"); 479 Utility.upload_url_zip(col_name,"images");480 GathererApplet.upload_url_zip(col_name,"images"); 480 481 } 481 482 … … 518 519 if (type == NEW) { 519 520 if (Gatherer.isGsdlRemote) { 520 Utility.download_url_zip(col_name,".");521 GathererApplet.download_url_zip(col_name,"."); 521 522 Utility.unzip(col_name); 522 523 } … … 533 534 534 535 Utility.delete(Gatherer.c_man.getCollectionArchive()); // remove current archives 535 Utility.download_url_zip(col_name,"archives");536 GathererApplet.download_url_zip(col_name,"archives"); 536 537 Utility.unzip(col_name); 537 538 … … 556 557 557 558 Utility.delete(Gatherer.c_man.getCollectionBuild()); // remove current build dir 558 Utility.download_url_zip(col_name,"building");559 GathererApplet.download_url_zip(col_name,"building"); 559 560 Utility.unzip(col_name); 560 561 -
trunk/gli/src/org/greenstone/gatherer/util/Utility.java
r8249 r8250 768 768 769 769 770 static public void download_url_zip(String col_name, String dir)771 {772 try {773 String download_cgi = Gatherer.cgiBase + "download";774 775 // Send col_name and dir arguments to download cgi776 777 String col_name_encoded = URLEncoder.encode(col_name,"UTF-8");778 String dir_encoded = URLEncoder.encode(dir,"UTF-8");779 String cgi_args = "c=" + col_name_encoded;780 cgi_args += "&dir=" + dir_encoded;781 782 URL download_url = new URL(download_cgi);783 784 System.err.println("**** download cgi = '" + download_cgi + "'");785 System.err.println("**** cgi args = '" + cgi_args + "'");786 787 URLConnection dl_connection = download_url.openConnection();788 dl_connection.setDoOutput(true);789 OutputStream dl_os = dl_connection.getOutputStream();790 791 PrintWriter dl_out = new PrintWriter(dl_os);792 dl_out.println(cgi_args);793 dl_out.close();794 795 // Download result from running cgi script796 InputStream dl_is = dl_connection.getInputStream();797 BufferedInputStream dl_bis = new BufferedInputStream(dl_is);798 DataInputStream dl_dbis = new DataInputStream(dl_bis);799 800 // set up output stream for zip download801 String col_dir = Utility.getCollectDir(Configuration.gsdl_path);802 String zip_fname = col_dir + col_name + ".zip";803 FileOutputStream zip_fos = new FileOutputStream(zip_fname);804 BufferedOutputStream zip_bfos = new BufferedOutputStream(zip_fos);805 806 byte[] buf = new byte[1024];807 int len;808 809 while ((len = dl_dbis.read(buf)) >= 0) {810 zip_bfos.write(buf,0,len);811 }812 813 dl_dbis.close();814 zip_bfos.close();815 816 }817 catch (Exception error) {818 error.printStackTrace();819 }820 }821 822 823 static public void upload_url_zip(String col_name, String dir)824 {825 final String lineEnd = "\r\n";826 final String twoHyphens = "--";827 final String boundary = "*****";828 final int maxBufferSize = 1024;829 830 String col_dir = Utility.getCollectDir(Configuration.gsdl_path);831 String zip_fname = col_dir + col_name + ".zip";832 String upload_cgi = Gatherer.cgiBase + "upload";833 834 HttpURLConnection conn = null;835 836 try {837 // Send zip file to server838 839 File file = new File(zip_fname) ;840 FileInputStream fileInputStream = new FileInputStream(file);841 842 // open a URL connection to the Servlet843 URL url = new URL(upload_cgi);844 System.err.println("**** Uploading to: " + upload_cgi);845 846 // Open a HTTP connection to the URL847 conn = (HttpURLConnection) url.openConnection();848 849 conn.setDoInput(true); // Allow Inputs850 conn.setDoOutput(true); // Allow Outputs851 conn.setUseCaches(false); // Don't use a cached copy.852 conn.setRequestMethod("POST"); // Use a post method.853 854 conn.setRequestProperty("Connection", "Keep-Alive");855 conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);856 857 DataOutputStream dos = new DataOutputStream( conn.getOutputStream() );858 859 dos.writeBytes(twoHyphens + boundary + lineEnd);860 dos.writeBytes("Content-Disposition: form-data; name=\"c\"" + lineEnd + lineEnd);861 dos.writeBytes(col_name + lineEnd);862 System.err.println("**** c="+col_name);863 864 dos.writeBytes(twoHyphens + boundary + lineEnd);865 dos.writeBytes("Content-Disposition: form-data; name=\"dir\"" + lineEnd + lineEnd);866 dos.writeBytes(dir + lineEnd);867 System.err.println("**** dir="+dir);868 869 dos.writeBytes(twoHyphens + boundary + lineEnd);870 dos.writeBytes("Content-Disposition: form-data; name=\"zip\";"871 + " filename=\"" + zip_fname +"\"" + lineEnd);872 dos.writeBytes(lineEnd);873 System.err.println("**** zip (filename)="+zip_fname);874 875 // create a buffer of maximum size876 int bytesAvailable = fileInputStream.available();877 int bufferSize = Math.min(bytesAvailable, maxBufferSize);878 byte[] buffer = new byte[bufferSize];879 880 // read file and write it into form...881 int bytesRead = fileInputStream.read(buffer, 0, bufferSize);882 883 while (bytesRead > 0) {884 dos.write(buffer, 0, bufferSize);885 bytesAvailable = fileInputStream.available();886 bufferSize = Math.min(bytesAvailable, maxBufferSize);887 bytesRead = fileInputStream.read(buffer, 0, bufferSize);888 }889 890 // send multipart form data necesssary after file data...891 892 dos.writeBytes(lineEnd);893 dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);894 895 // close streams896 897 fileInputStream.close();898 dos.flush();899 dos.close();900 901 902 }903 catch (MalformedURLException ex) {904 System.err.println("Failed on: "+ex);905 }906 907 catch (IOException ioe) {908 System.err.println("Failed on: "+ioe);909 }910 911 // Read server response912 913 try {914 InputStreamReader isr = new InputStreamReader(conn.getInputStream() );915 BufferedReader bisr = new BufferedReader (isr);916 String str;917 while (( str = bisr.readLine()) != null) {918 System.err.println(str);919 }920 bisr.close();921 922 }923 catch (IOException ioex) {924 System.err.println("From (ServerResponse): "+ioex);925 }926 }927 928 770 static protected String unixStylePath(String path) 929 771 {
Note:
See TracChangeset
for help on using the changeset viewer.