Changeset 4580


Ignore:
Timestamp:
2003-06-11T16:35:01+12:00 (21 years ago)
Author:
jmt12
Message:

2030124: Argument parsing now doesn't begin until the '<?xml' is detected, so as to avoid poorly formed XML errors because of PERL messages. Classifier argument harvesting could fail silently or give less than useful error messages. Now it displays a handy message dialog. How handy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/ClassifierManager.java

    r4578 r4580  
    3535 *########################################################################
    3636 */
    37 
    38  
    39 
    40 
    41 
    42 
    43 /* GPL_HEADER */
    4437package org.greenstone.gatherer.cdm;
    45 /**************************************************************************************
    46  * Title:        Gatherer
    47  * Description:  The Gatherer: a tool for gathering and enriching a digital collection.
    48  * Company:      The University of Waikato
    49  * Written:      01/05/02
    50  * Revised:      16/08/02 Optimized and Commented.
    51  **************************************************************************************/
     38
    5239import java.awt.BorderLayout;
    5340import java.awt.Color;
     
    289276        Runtime runtime = Runtime.getRuntime();
    290277        Process process = runtime.exec(args);
    291         InputStream input_stream = process.getErrorStream();
    292278        BufferedReader error_in = new BufferedReader(new InputStreamReader(process.getErrorStream()));
    293279        String line = "";
    294280        StringBuffer xml = new StringBuffer("");
     281        boolean xml_content = false;
    295282        while((line = error_in.readLine()) != null) {
    296         xml.append(line);
    297         xml.append("\n");
    298         }
    299         // Then read the xml from the piped input stream.
    300         InputSource source = new InputSource(new StringReader(xml.toString()));
    301         DOMParser parser = new DOMParser();
    302         parser.parse(source);
    303         document = parser.getDocument();
     283        if(xml_content) {
     284            xml.append(line);
     285            xml.append("\n");
     286        }
     287        else if(line.trim().startsWith("<?xml")) {
     288            xml_content = true;
     289            xml.append(line);
     290            xml.append("\n");
     291        }
     292        }
     293        error_in = null;
     294        process = null;
     295        runtime = null;
     296        // If something has gone horribly wrong then xml will be empty.
     297        if(xml.length() != 0) {
     298        // Then read the xml from the piped input stream.
     299        InputSource source = new InputSource(new StringReader(xml.toString()));
     300        DOMParser parser = new DOMParser();
     301        parser.parse(source);
     302        document = parser.getDocument();
     303        parser = null;
     304        source = null;
     305        }
     306        else {
     307        String classifier_name = getClassifierName(classifier);
     308        Gatherer.println("Zero length argument xml detected for: " + classifier_name);
     309        JOptionPane.showMessageDialog(Gatherer.g_man, get("Classifier_XML_Parse_Failed", classifier_name), get("General.Error"), JOptionPane.ERROR_MESSAGE);
     310        classifier_name = null;
     311        }
    304312    }
    305313    catch (Exception error) {
     
    537545      * @see org.greenstone.gatherer.Gatherer
    538546      */
    539     private String get(String key, String args[]) {
     547    private String get(String key, String arg) {
     548    String[] args = null;
     549    if(arg != null) {
     550        args = new String[1];
     551        args[0] = arg;
     552    }
    540553    if(key.indexOf(".") == -1) {
    541554        key = "CDM.ClassifierManager." + key;
Note: See TracChangeset for help on using the changeset viewer.