Changeset 207 in tmcsimulator-scriptbuilder


Ignore:
Timestamp:
02/03/2020 05:42:22 PM (6 years ago)
Author:
jdalbey
Message:

SimulationScript?.java modified to catch exception caused when external DTD not found during load xml and display helpful message to user. Fixes #240.

Location:
trunk/src/scriptbuilder
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scriptbuilder/gui/ScriptBuilderFrame.java

    r193 r207  
    18401840            script = new SimulationScript(); 
    18411841            script.loadScriptFromFile(fc.getSelectedFile()); 
    1842             script.saveFile = fc.getSelectedFile(); 
    18431842        } 
    18441843         
  • trunk/src/scriptbuilder/structures/SimulationScript.java

    r206 r207  
    1818import java.nio.file.Paths; 
    1919import java.util.TreeMap; 
     20import javax.swing.JOptionPane; 
    2021import static scriptbuilder.structures.XMLBuilder.prettyPrintXML; 
    2122 
     
    176177     * Load in an existing script from an XML file. 
    177178     * 
    178      * @param f the file containing the script 
    179      */ 
    180     public void loadScriptFromFile(File f) 
     179     * @param infile the file containing the script 
     180     */ 
     181    public void loadScriptFromFile(File infile) 
    181182    { 
    182183        try 
    183184        { 
    184185 
    185             SAXParserFactory.newInstance().newSAXParser().parse(f, sh); 
     186            SAXParserFactory.newInstance().newSAXParser().parse(infile, sh); 
    186187 
    187188            Vector<ScriptIncident> inc = sh.getIncidents(); 
     
    191192                addIncident(sci); 
    192193            } 
     194            saveFile = infile; 
     195 
    193196        } 
    194197        catch (Exception ex) 
    195198        { 
    196             System.out.println("ERROR LOADING SCRIPT"); 
    197             ex.printStackTrace(); 
    198         } 
    199         System.out.println("H"); 
    200         for(Unit testUnit : units){ 
    201             System.out.println(testUnit.toXML()); 
     199            String errMsg = ex.getMessage(); 
     200            if (ex.getMessage().endsWith(".dtd (No such file or directory)")) 
     201            { 
     202                errMsg += "\nThe required external DTD file must be placed in\n" 
     203                        + " the same folder as the xml file."; 
     204            } 
     205            JOptionPane.showMessageDialog(null, errMsg, 
     206                "Unable to load xml file", 
     207                JOptionPane.INFORMATION_MESSAGE); 
    202208        } 
    203209        this.update(); 
Note: See TracChangeset for help on using the changeset viewer.