Changeset 466 in tmcsimulator for trunk/src/tmcsim/cadsimulator/Coordinator.java


Ignore:
Timestamp:
07/27/2019 02:06:02 PM (7 years ago)
Author:
jdalbey
Message:

Add copyXMLfile method to Coordinator to fix #178.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/cadsimulator/Coordinator.java

    r465 r466  
    33import java.io.File; 
    44import java.io.FileWriter; 
     5import java.io.IOException; 
    56import java.io.PrintWriter; 
     7import java.nio.file.Files; 
     8import java.nio.file.Path; 
     9import java.nio.file.Paths; 
     10import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; 
    611import java.rmi.RemoteException; 
    712import java.rmi.server.UnicastRemoteObject; 
     
    7782import tmcsim.interfaces.SimulationManagerInterface; 
    7883import tmcsim.simulationmanager.SimulationManagerView; 
     84import tmcsim.simulationmanager.actions.LoadScriptAction; 
    7985 
    8086/** 
     
    107113    private String kCADcommentLog; 
    108114    /** 
     115     * Filename where copy of incident script is written to be used by 
     116     * EI notebook.  The same path as kSimClockFilename is used. 
     117     */ 
     118    private final static String kIncidentScriptFilename = "incident_script.xml"; 
     119    /** 
    109120     * Error logger. 
    110121     */ 
     
    540551        } 
    541552    } 
    542  
     553    /** Helper method to copy a file.   
     554     *  
     555     * @param selectedFile is the name of source file (without a path). 
     556     * The path will be extracted from kSimClockFilename and prefixed to the  
     557     * selectedFile.  Fixes #178. 
     558     */ 
     559    private void copyXMLfile(String selectedFile) 
     560    { 
     561        int ptr = kSimClockFilename.lastIndexOf(System.getProperty("file.separator")); 
     562        String foldername = kSimClockFilename.substring(0, ptr+1); 
     563        try { 
     564            Path destination = Paths.get(foldername + kIncidentScriptFilename); 
     565            Path source = Paths.get(selectedFile); 
     566            Files.copy(source, destination,REPLACE_EXISTING); 
     567            Logger.getLogger(Coordinator.class.getName()).log(Level.INFO,   
     568                    "Loaded script copied to " + destination); 
     569        } catch (IOException ex) { 
     570            Logger.getLogger(Coordinator.class.getName()).log(Level.SEVERE, null, ex); 
     571        }         
     572    } 
     573     
     574    /** Load and parse the XML script from the given file */ 
    543575    public void loadScriptFile(File scriptFile) throws RemoteException, ScriptException 
    544576    { 
    545  
    546  
     577        // Make a copy of the xml file to be used by EI notebook. 
     578        copyXMLfile(scriptFile.getPath()); 
    547579        try 
    548580        { 
Note: See TracChangeset for help on using the changeset viewer.