26 package org.nexusformat.nxvalidate;
29 import java.io.FileInputStream;
30 import java.io.FileOutputStream;
31 import java.io.IOException;
32 import java.io.InputStream;
33 import java.io.OutputStream;
34 import java.util.ArrayList;
35 import java.util.Enumeration;
36 import java.util.ResourceBundle;
37 import org.w3c.dom.Document;
38 import org.xml.sax.SAXException;
39 import java.util.logging.Level;
40 import java.util.logging.Logger;
41 import javax.swing.JOptionPane;
42 import javax.swing.JTree;
43 import javax.xml.parsers.DocumentBuilder;
44 import javax.xml.parsers.DocumentBuilderFactory;
45 import org.nexusformat.nxvalidate.exceptions.NXvalidateException;
53 private File nxsFile = null;
54 private File nxdlFile = null;
55 private File reducedFile = null;
56 private File resultsFile = null;
57 private String nxconvertCommand = null;
58 private File saveDirectory = null;
59 private DocumentBuilderFactory factory = null;
60 private DocumentBuilder builder = null;
63 private int which = 1;
66 private Document reducedDoc = null;
67 private Document resultsDoc = null;
68 private JTree jTree = null;
69 private boolean validateResult =
false;
70 private ResourceBundle bundle = null;
71 private JOptionPane dialogReportProblem;
73 private File[] dataFiles = null;
74 private ArrayList<String> dataFileList = null;
75 private ArrayList<String> badDataFileList = null;
76 private boolean conversionFail =
false;
77 private boolean isNotBulk =
false;
83 this.domTree = domTree;
85 this.builder = builder;
89 bundle = ResourceBundle.getBundle(
90 "org/nexusformat/nxvalidate/resources/nxvalidate");
91 dialogReportProblem =
new JOptionPane();
101 this.nxsFile = nxsFile;
105 this.nxdlFile = nxdlFile;
109 this.nxconvertCommand = nxconvertCommand;
113 return nxconvertCommand;
117 this.reducedFile = reducedFile;
121 this.resultsDoc = resultsDoc;
125 this.reducedDoc = reducedDoc;
129 this.dataFiles = dataFiles;
133 return validateResult;
141 this.dataFileList = dataFileList;
145 return saveDirectory;
149 this.saveDirectory = saveDirectory;
153 return conversionFail;
157 return badDataFileList;
166 if (resultsDoc != null) {
174 if (nxconvertCommand != null) {
177 dialogReportProblem.showMessageDialog(
179 "Problem Validating file, nxconvert command is not set.");
187 resultsDoc = builder.parse(resultsFile);
199 Level.INFO,
"Finished Validating.");
202 dialogReportProblem.showMessageDialog(
204 bundle.getString(
"validationCompleteMessage"));
207 dialogReportProblem.showMessageDialog(
209 "Problem Validating file: " + nxsFile);
211 Level.WARNING, null, ex);
212 }
catch (SAXException ex) {
213 dialogReportProblem.showMessageDialog(
215 "Problem Validating file: " + nxsFile);
217 Level.WARNING, null, ex);
218 }
catch (IOException ex) {
219 dialogReportProblem.showMessageDialog(
221 "Problem Validating file: " + nxsFile);
223 Level.WARNING, null, ex);
224 }
catch (Exception ex) {
225 dialogReportProblem.showMessageDialog(
227 "Problem Validating file: " + nxsFile);
229 Level.WARNING, null, ex);
240 File reducedFile = convert.
convert();
242 if(reducedFile==null){
247 Document document = builder.parse(reducedFile);
248 document.setUserData(
"file", nxsFile, null);
250 document,
true, nxsFile);
252 this.reducedDoc = document;
254 if (nxdlFile != null) {
257 this.reducedFile = reducedFile;
265 conversionFail =
true;
266 badDataFileList.add(nxsFile.getAbsolutePath());
267 }
catch (InterruptedException ex) {
271 }
catch (SAXException ex) {
275 }
catch (IOException ex) {
282 private ArrayList<String> getSubFiles(String file) {
284 ArrayList<String> fileList =
new ArrayList<String>();
286 File tmpFile =
new File(file);
288 String[] files = tmpFile.list();
294 for (
int i = 0; i < files.length; ++i) {
295 if (
new File(tmpFile.getAbsolutePath() + tmpFile.separator + files[i]).isDirectory()) {
296 fileList.addAll(getSubFiles(tmpFile.getAbsolutePath() + tmpFile.separator + files[i]));
298 fileList.add(tmpFile.getAbsolutePath() + tmpFile.separator + files[i]);
307 if (dataFiles != null) {
309 dataFileList =
new ArrayList<String>();
311 for (
int i = 0; i < dataFiles.length; ++i) {
313 if (dataFiles[i].isDirectory()) {
314 dataFileList.addAll(getSubFiles(dataFiles[i].getAbsolutePath()));
316 dataFileList.add(dataFiles[i].getAbsolutePath());
320 this.dataFileList = dataFileList;
327 badDataFileList =
new ArrayList<String>();
328 if (dataFileList != null) {
329 for (
int i = 0; i < dataFileList.size(); ++i) {
330 nxsFile =
new File(dataFileList.get(i));
340 badDataFileList =
new ArrayList<String>();
341 if (dataFileList != null) {
342 for (
int i = 0; i < dataFileList.size(); ++i) {
343 nxsFile =
new File(dataFileList.get(i));
348 dialogReportProblem.showMessageDialog(
350 bundle.getString(
"validationCompleteMessage"));
355 private void copy(File src, File dst)
throws IOException {
356 InputStream in =
new FileInputStream(src);
357 OutputStream out =
new FileOutputStream(dst);
359 byte[] buf =
new byte[1024];
361 while ((len = in.read(buf)) > 0) {
362 out.write(buf, 0, len);
371 File tmpReduced = null;
372 File tmpResults = null;
373 Enumeration children = root.children();
375 while(children.hasMoreElements()){
381 tmpReduced =
new File(directory.getAbsolutePath() +
383 tmpResults =
new File(directory.getAbsolutePath() +
388 }
catch (IOException ex) {
390 FileActions.class.getName()).log(Level.SEVERE, null, ex);
403 }
else if (which == 2) {
408 }
else if (which == 3) {
410 }
else if (which == 4) {
412 }
else if (which == 5) {
414 }
else if (which == 6) {