Changeset 7962
- Timestamp:
- 2004-08-16T22:43:33+12:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/Utility.java
r7926 r7962 676 676 } 677 677 678 static public void extractFromJar(String filename, String dst_dir )678 static public void extractFromJar(String filename, String dst_dir, boolean must_be_present) 679 679 { 680 680 try { … … 701 701 } 702 702 catch (Exception error) { 703 error.printStackTrace(); 703 if (must_be_present) { 704 error.printStackTrace(); 705 } 704 706 } 705 707 } … … 718 720 } 719 721 720 extractFromJar(jar_zip_fname,dst_dir );722 extractFromJar(jar_zip_fname,dst_dir,true); 721 723 722 724 String zip_ofname = dst_dir + jar_zip_fname; … … 787 789 URL download_url = new URL(download_cgi); 788 790 789 System.err.println("*** download cgi = '" + download_cgi + "'");790 System.err.println("*** cgi args = '" + cgi_args + "'");791 System.err.println("**** download cgi = '" + download_cgi + "'"); 792 System.err.println("**** cgi args = '" + cgi_args + "'"); 791 793 792 794 URLConnection dl_connection = download_url.openConnection(); … … 847 849 // open a URL connection to the Servlet 848 850 URL url = new URL(upload_cgi); 849 851 System.err.println("**** Uploading to: " + upload_cgi); 852 850 853 // Open a HTTP connection to the URL 851 854 conn = (HttpURLConnection) url.openConnection(); … … 864 867 dos.writeBytes("Content-Disposition: form-data; name=\"c\"" + lineEnd + lineEnd); 865 868 dos.writeBytes(col_name + lineEnd); 869 System.err.println("**** c="+col_name); 866 870 867 871 dos.writeBytes(twoHyphens + boundary + lineEnd); 868 872 dos.writeBytes("Content-Disposition: form-data; name=\"dir\"" + lineEnd + lineEnd); 869 dos.writeBytes(dir + lineEnd); 870 873 dos.writeBytes(dir + lineEnd); 874 System.err.println("**** dir="+dir); 875 871 876 dos.writeBytes(twoHyphens + boundary + lineEnd); 872 877 dos.writeBytes("Content-Disposition: form-data; name=\"zip\";" 873 878 + " filename=\"" + zip_fname +"\"" + lineEnd); 874 879 dos.writeBytes(lineEnd); 875 880 System.err.println("**** zip (filename)="+zip_fname); 876 881 877 // create a buffer of maximum size 878 882 // create a buffer of maximum size 879 883 int bytesAvailable = fileInputStream.available(); 880 884 int bufferSize = Math.min(bytesAvailable, maxBufferSize); … … 882 886 883 887 // read file and write it into form... 884 885 888 int bytesRead = fileInputStream.read(buffer, 0, bufferSize); 886 889 … … 930 933 } 931 934 935 static protected String unixStylePath(String path) 936 { 937 String unix_path = path.replace('\\','/'); 938 return unix_path; 939 } 940 932 941 static protected void zipFunc (ZipOutputStream zos, String file_path, int prefix_strip) 933 942 { … … 938 947 // Strip off col_dir prefix 939 948 String zip_path = file_path.substring(prefix_strip); 940 941 ZipEntry fileEntry = new ZipEntry(zip_path); 949 // Zip files use '/' for directory separator 950 String unix_style_path = unixStylePath(zip_path); 951 ZipEntry fileEntry = new ZipEntry(unix_style_path); 942 952 zos.putNextEntry(fileEntry); 943 953 … … 977 987 String dir_path = file.getPath(); 978 988 String zip_path = dir_path.substring(prefix_strip); 979 // use of "/" here instead of File.separator intentional 980 ZipEntry dirEntry = new ZipEntry(zip_path+"/"); 989 // Zip files use '/' for directory separator 990 String unix_style_path 991 = unixStylePath(zip_path+File.separator); 992 ZipEntry dirEntry = new ZipEntry(unix_style_path); 981 993 982 994 try { … … 1034 1046 if (ch.equals(File.separator)) { 1035 1047 String dir_path = zip_path.substring(0,i); 1036 // use of "/" here instead of File.separation intentional 1037 ZipEntry dirEntry = new ZipEntry(dir_path+"/"); 1048 // Zip files use '/' for directory separator 1049 String unix_style_path 1050 = unixStylePath(dir_path+File.separator); 1051 ZipEntry dirEntry = new ZipEntry(unix_style_path); 1038 1052 zos.putNextEntry(dirEntry); 1039 1053 } … … 1272 1286 // URL url = ClassLoader.getSystemResource(filename); 1273 1287 // URL url = base.getResource("/"+filename); 1274 System.err.println("*** looking for resource as stream: " + filename);1288 // System.err.println("*** looking for resource as stream: " + filename); 1275 1289 InputStream is = base.getResourceAsStream("/"+filename); 1276 1290 … … 1307 1321 Document document = null; 1308 1322 try { 1309 System.err.println("file =" + file);1323 Gatherer.println("Parsing XML file: " + file); 1310 1324 FileInputStream fis = new FileInputStream(file); 1311 1325 document = parse(fis,noisey); … … 1386 1400 } 1387 1401 1402 1403 static public StringBuffer readXMLStream(InputStream input_stream) 1404 { 1405 StringBuffer xml = new StringBuffer(""); 1406 1407 try { 1408 InputStreamReader isr = new InputStreamReader(input_stream, "UTF-8"); 1409 BufferedReader buffered_in = new BufferedReader(isr); 1410 1411 String line = ""; 1412 boolean xml_content = false; 1413 while((line = buffered_in.readLine()) != null) { 1414 if(xml_content) { 1415 xml.append(line); 1416 xml.append("\n"); 1417 } 1418 else if(line.trim().startsWith("<?xml")) { 1419 xml_content = true; 1420 xml.append(line); 1421 xml.append("\n"); 1422 } 1423 } 1424 buffered_in = null; 1425 } 1426 catch (Exception error) { 1427 System.err.println("Failed when trying to parse XML stream"); 1428 error.printStackTrace(); 1429 } 1430 1431 return xml; 1432 } 1433 1434 1435 static public Document XMLStringToDOM(StringBuffer xml, String form) 1436 { 1437 Document document = null; 1438 1439 // If something has gone horribly wrong then xml will be empty. 1440 if(xml.length() > 0) { 1441 try { 1442 // Then read the xml from the piped input stream. 1443 StringReader xml_sr = new StringReader(xml.toString()); 1444 InputSource source = new InputSource(xml_sr); 1445 DOMParser parser = new DOMParser(); 1446 parser.parse(source); 1447 document = parser.getDocument(); 1448 } 1449 catch (Exception error) { 1450 System.err.println("Failed when trying to parse XML stream "); 1451 error.printStackTrace(); 1452 } 1453 } 1454 else { 1455 //Gatherer.println("Zero length argument xml detected for: " + form); 1456 String[] margs = new String[1]; 1457 margs[0] = form; 1458 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.PlugInManager.PlugIn_XML_Parse_Failed", margs), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 1459 } 1460 1461 return document; 1462 } 1463 1464 1465 1388 1466 /** Method to spread out a line of text so that is is justified to the given width, by attempting to widen white-spacing in a balanced way. 1389 1467 * @param original The <strong>String</strong> to justify.
Note:
See TracChangeset
for help on using the changeset viewer.