Changeset 7962


Ignore:
Timestamp:
2004-08-16T22:43:33+12:00 (20 years ago)
Author:
davidb
Message:

Additional functions added to support using pluginfo.pl and classinfo.pl
on remove server (GLI applet)

Code for Zipping up files altered to explicitly use '/' as this, believe it
or not, is more cross-platform dependant. Even on windows!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r7926 r7962  
    676676    }
    677677
    678     static public void extractFromJar(String filename, String dst_dir)
     678    static public void extractFromJar(String filename, String dst_dir, boolean must_be_present)
    679679    {
    680680    try {
     
    701701    }
    702702    catch (Exception error) {
    703         error.printStackTrace();
     703        if (must_be_present) {
     704        error.printStackTrace();
     705        }
    704706    }
    705707    }
     
    718720    }
    719721
    720     extractFromJar(jar_zip_fname,dst_dir);
     722    extractFromJar(jar_zip_fname,dst_dir,true);
    721723
    722724    String zip_ofname = dst_dir + jar_zip_fname;
     
    787789        URL download_url = new URL(download_cgi);
    788790
    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 + "'");
    791793
    792794        URLConnection dl_connection = download_url.openConnection();
     
    847849        // open a URL connection to the Servlet
    848850        URL url = new URL(upload_cgi);
    849                
     851        System.err.println("**** Uploading to: " + upload_cgi);
     852
    850853        // Open a HTTP connection to the URL
    851854        conn = (HttpURLConnection) url.openConnection();
     
    864867        dos.writeBytes("Content-Disposition: form-data; name=\"c\"" + lineEnd + lineEnd);
    865868        dos.writeBytes(col_name + lineEnd);
     869        System.err.println("**** c="+col_name);
    866870
    867871        dos.writeBytes(twoHyphens + boundary + lineEnd);
    868872        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   
    871876        dos.writeBytes(twoHyphens + boundary + lineEnd);
    872877        dos.writeBytes("Content-Disposition: form-data; name=\"zip\";"
    873878               + " filename=\"" + zip_fname +"\"" + lineEnd);
    874879        dos.writeBytes(lineEnd);
    875        
     880        System.err.println("**** zip (filename)="+zip_fname);
    876881               
    877         // create a buffer of maximum size
    878                    
     882        // create a buffer of maximum size                 
    879883        int bytesAvailable = fileInputStream.available();
    880884        int bufferSize = Math.min(bytesAvailable, maxBufferSize);
     
    882886       
    883887        // read file and write it into form...
    884 
    885888        int bytesRead = fileInputStream.read(buffer, 0, bufferSize);
    886889       
     
    930933    }
    931934
     935    static protected String unixStylePath(String path)
     936    {
     937    String unix_path = path.replace('\\','/');
     938    return unix_path;
     939    }
     940
    932941    static protected void zipFunc (ZipOutputStream zos, String file_path, int prefix_strip)
    933942    {
     
    938947        // Strip off col_dir prefix
    939948        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);
    942952        zos.putNextEntry(fileEntry);
    943953
     
    977987            String dir_path = file.getPath();
    978988            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);
    981993
    982994            try {
     
    10341046            if (ch.equals(File.separator)) {
    10351047                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);
    10381052                zos.putNextEntry(dirEntry);
    10391053            }
     
    12721286        // URL url = ClassLoader.getSystemResource(filename);
    12731287        // 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);
    12751289        InputStream is = base.getResourceAsStream("/"+filename);
    12761290
     
    13071321    Document document = null;
    13081322    try {
    1309         System.err.println("file = " + file);
     1323        Gatherer.println("Parsing XML file: " + file);
    13101324        FileInputStream fis   = new FileInputStream(file);
    13111325        document = parse(fis,noisey);
     
    13861400    }
    13871401
     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
    13881466    /** 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.
    13891467     * @param original The <strong>String</strong> to justify.
Note: See TracChangeset for help on using the changeset viewer.