Ignore:
Timestamp:
02/09/10 18:26:36 (21 months ago)
Author:
Stephen Rankin
Message:

Added save results feature and single file checking (NXDL). Update of Javadocs. ref#236.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/applications/NXvalidate/src/org/nexusformat/nxvalidate/FileActions.java

    r1519 r1520  
    2121 * For further information, see <http://www.neutron.anl.gov/NeXus/> 
    2222 * 
    23  * FileLoadingActions.java 
     23 * FileActions.java 
    2424 * 
    2525 */ 
     
    2727 
    2828import java.io.File; 
     29import java.io.FileInputStream; 
     30import java.io.FileOutputStream; 
    2931import java.io.IOException; 
     32import java.io.InputStream; 
     33import java.io.OutputStream; 
    3034import java.util.ArrayList; 
     35import java.util.Enumeration; 
    3136import java.util.ResourceBundle; 
    3237import org.w3c.dom.Document; 
     
    4449 * @author Stephen Rankin 
    4550 */ 
    46 public class FileLoadingActions implements Runnable { 
     51public class FileActions implements Runnable { 
    4752 
    4853    private File nxsFile = null; 
     
    5156    private File resultsFile = null; 
    5257    private File nxconvertFile = null; 
     58    private File saveDirectory = null; 
    5359    private DocumentBuilderFactory factory = null; 
    5460    private DocumentBuilder builder = null; 
     
    7177    private boolean isNotBulk = false; 
    7278 
    73     public FileLoadingActions(NXvalidateFrame frame, JTree jTree, 
     79    public FileActions(NXvalidateFrame frame, JTree jTree, 
    7480            DocumentBuilder builder, NXReducedToTree domTree, 
    7581            NXNodeMapper root) { 
     
    134140    public void setDataFileList(ArrayList<String> dataFileList) { 
    135141        this.dataFileList = dataFileList; 
     142    } 
     143 
     144    public File getSaveDirectory() { 
     145        return saveDirectory; 
     146    } 
     147 
     148    public void setSaveDirectory(File saveDirectory) { 
     149        this.saveDirectory = saveDirectory; 
    136150    } 
    137151 
     
    159173            //Do the validation. 
    160174            if (nxconvertFile != null) { 
    161                 validator = new ValidatorUtils(nxconvertFile); 
     175                validator = new ValidatorUtils(nxsFile,nxconvertFile); 
    162176            } else { 
    163177                dialogReportProblem.showMessageDialog( 
     
    232246        } catch (InterruptedException ex) { 
    233247            Logger.getLogger( 
    234                     NXvalidateFrame.class.getName()).log(Level.SEVERE, 
     248                    FileActions.class.getName()).log(Level.SEVERE, 
    235249                    null, ex); 
    236250        } catch (SAXException ex) { 
    237251            Logger.getLogger( 
    238                     NXvalidateFrame.class.getName()).log(Level.SEVERE, 
     252                    FileActions.class.getName()).log(Level.SEVERE, 
    239253                    null, ex); 
    240254        } catch (IOException ex) { 
    241255            Logger.getLogger( 
    242                     NXvalidateFrame.class.getName()).log(Level.SEVERE, 
     256                    FileActions.class.getName()).log(Level.SEVERE, 
    243257                    null, ex); 
    244258        } 
     
    316330        } 
    317331 
     332    } 
     333 
     334    private void copy(File src, File dst) throws IOException { 
     335        InputStream in = new FileInputStream(src); 
     336        OutputStream out = new FileOutputStream(dst); 
     337 
     338        byte[] buf = new byte[1024]; 
     339        int len; 
     340        while ((len = in.read(buf)) > 0) { 
     341            out.write(buf, 0, len); 
     342        } 
     343        in.close(); 
     344        out.close(); 
     345    } 
     346 
     347    public void saveResults(File directory){ 
     348 
     349        NXNodeMapper tmpNode = null; 
     350        File tmpReduced = null; 
     351        File tmpResults = null; 
     352        Enumeration children = root.children(); 
     353         
     354        while(children.hasMoreElements()){ 
     355 
     356            tmpNode = (NXNodeMapper)children.nextElement(); 
     357             
     358            if(tmpNode.getReducedFile()!=null){ 
     359 
     360                tmpReduced = new File(directory.getAbsolutePath() + 
     361                        directory.separator + tmpNode.getReducedFile().getName()); 
     362                tmpResults = new File(directory.getAbsolutePath() + 
     363                        directory.separator + tmpNode.getResultsFile().getName()); 
     364                try{ 
     365                    copy(tmpNode.getReducedFile(),tmpReduced); 
     366                    copy(tmpNode.getResultsFile(),tmpResults); 
     367                } catch (IOException ex) { 
     368                    Logger.getLogger( 
     369                    FileActions.class.getName()).log(Level.SEVERE, null, ex); 
     370                } 
     371            } 
     372        } 
    318373    } 
    319374 
     
    336391        }else if (which == 5) { 
    337392            bulkValidate(); 
    338         } 
    339  
     393        } else if (which == 6) { 
     394            saveResults(saveDirectory); 
     395        } 
    340396    } 
    341397} 
Note: See TracChangeset for help on using the changeset viewer.