Changeset 4581


Ignore:
Timestamp:
2003-06-11T16:35:29+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. PlugIn 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/PlugInManager.java

    r4476 r4581  
    5151 * @version 2.1
    5252 */
    53 import java.awt.BorderLayout;
    54 import java.awt.Color;
    55 import java.awt.Component;
    56 import java.awt.Dimension;
    57 import java.awt.GridLayout;
    58 import java.awt.event.ActionEvent;
    59 import java.awt.event.ActionListener;
    60 import java.awt.event.KeyEvent;
    61 import java.awt.event.MouseAdapter;
    62 import java.awt.event.MouseEvent;
    63 import java.io.BufferedReader;
    64 import java.io.File;
    65 import java.io.FileInputStream;
    66 import java.io.FileOutputStream;
    67 import java.io.InputStream;
    68 import java.io.InputStreamReader;
    69 import java.io.ObjectInputStream;
    70 import java.io.ObjectOutputStream;
    71 import java.io.StringReader;
    72 import java.util.Collections;
    73 import java.util.Vector;
    74 import javax.swing.BorderFactory;
    75 import javax.swing.Box;
    76 import javax.swing.BoxLayout;
    77 import javax.swing.ComboBoxModel;
    78 import javax.swing.DefaultListCellRenderer;
    79 import javax.swing.JButton;
    80 import javax.swing.JComboBox;
    81 import javax.swing.JLabel;
    82 import javax.swing.JList;
    83 import javax.swing.JOptionPane;
    84 import javax.swing.JPanel;
    85 import javax.swing.JPopupMenu;
    86 import javax.swing.JScrollPane;
    87 import javax.swing.JSeparator;
    88 import javax.swing.JTextArea;
    89 import javax.swing.event.ListSelectionEvent;
    90 import javax.swing.event.ListSelectionListener;
     53import java.awt.*;
     54import java.awt.event.*;
     55import java.io.*;
     56import java.util.*;
     57import javax.swing.*;
     58import javax.swing.event.*;
    9159import javax.swing.plaf.basic.BasicArrowButton;
    9260import org.apache.xerces.parsers.DOMParser;
     
    9866import org.greenstone.gatherer.cdm.PlugIn;
    9967import org.greenstone.gatherer.util.Utility;
    100 import org.w3c.dom.Document;
    101 import org.w3c.dom.Node;
     68import org.w3c.dom.*;
    10269import org.xml.sax.InputSource;
    10370/** This class is resposible for maintaining a list of known plug-ins, and importing new plugins using the parser. */
     
    217184        args[2] = getPlugInName(plugin);
    218185        }
    219         for(int i = 0; i < args.length; i++) {
    220         ///ystem.out.print(args[i] + " ");
    221         }
    222                 ///ystem.out.print("\n");
    223                 // Create the process.
     186        // Create the process.
    224187        Runtime runtime = Runtime.getRuntime();
    225188        Process process = runtime.exec(args);
    226                 //InputStream input_stream = process.getErrorStream();
     189        //InputStream input_stream = process.getErrorStream();
    227190        BufferedReader error_in = new BufferedReader(new InputStreamReader(process.getErrorStream()));
    228191        String line = "";
    229192        StringBuffer xml = new StringBuffer("");
     193        boolean xml_content = false;
    230194        while((line = error_in.readLine()) != null) {
    231         xml.append(line);
    232         xml.append("\n");
    233         }
    234         line = null;
     195        if(xml_content) {
     196            xml.append(line);
     197            xml.append("\n");
     198        }
     199        else if(line.trim().startsWith("<?xml")) {
     200            xml_content = true;
     201            xml.append(line);
     202            xml.append("\n");
     203        }
     204        }
    235205        error_in = null;
    236                 ///ystem.out.println("\n");
    237                 // Then read the xml from the piped input stream.
    238         InputSource source = new InputSource(new StringReader(xml.toString()));
    239         DOMParser parser = new DOMParser();
    240         parser.parse(source);
    241         document = parser.getDocument();
     206        process = null;
     207        runtime = null;
     208        args = null;
     209        // If something has gone horribly wrong then xml will be empty.
     210        if(xml.length() != 0) {
     211        // Then read the xml from the piped input stream.
     212        InputSource source = new InputSource(new StringReader(xml.toString()));
     213        DOMParser parser = new DOMParser();
     214        parser.parse(source);
     215        document = parser.getDocument();
     216        parser = null;
     217        source = null;
     218        }
     219        else {
     220        String plugin_name = getPlugInName(plugin);
     221        Gatherer.println("Zero length argument xml detected for: " + plugin_name);
     222        JOptionPane.showMessageDialog(Gatherer.g_man, get("PlugIn_XML_Parse_Failed", plugin_name), get("General.Error"), JOptionPane.ERROR_MESSAGE);
     223        }
    242224    }
    243225    catch (Exception error) {
     
    462444      */
    463445    private String get(String key) {
    464     return get(key, null);
    465     }
     446    return get(key, (String[])null);
     447    }
     448
     449    private String get(String key, String arg) {
     450    String args[] = new String[1];
     451    args[0] = arg;
     452    return get(key, args);
     453    }
     454
    466455    /* Retrieve a phrase from the dictionary based on a certain key and arguments.
    467456      * @param key The search <strong>String</strong>.
Note: See TracChangeset for help on using the changeset viewer.