NXvalidate  1
 All Classes Namespaces Files Functions Variables
ValidatorUtils.java
Go to the documentation of this file.
1 /* NeXus - Neutron & X-ray Common Data Format
2  *
3  * NeXus file validation GUI tool.
4  *
5  * Copyright (C) 2010 Stephen Rankin
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * For further information, see <http://www.nexusformat.org/>
22  *
23  * ValidatorUtils.java
24  *
25  */
26 package org.nexusformat.nxvalidate;
27 
28 import java.io.File;
30 import java.util.logging.Level;
31 import java.util.logging.Logger;
32 
37 public class ValidatorUtils {
38 
39  private File reduced = null;
40  private File nxsFile = null;
41  private boolean keepTemp = false;
42  private File schematronFile = null;
43  private boolean convertNxs = false;
44  private String nxconvertCommand = null;
45 
46 
47  public ValidatorUtils(File nxsFile, String nxconvertCommand) {
48 
49  this.nxconvertCommand = nxconvertCommand;
50  this.nxsFile = nxsFile;
51  }
52 
58  public void setReduced(File reduced) {
59  this.reduced = reduced;
60  }
61 
68  public File getReduced() {
69  return reduced;
70  }
71 
77  public void setNXS(File nxsFile) {
78  this.nxsFile = nxsFile;
79  }
80 
87  public File getNXS() {
88  return nxsFile;
89  }
90 
97  public void setSchematron(File schematronFile) {
98  this.schematronFile = schematronFile;
99  }
100 
107  public File getSchematron() {
108  return schematronFile;
109  }
110 
117  public void doConversion(boolean convertNxs) {
118  this.convertNxs = convertNxs;
119  }
120 
128  public void setKeepTemp(boolean keepTemp) {
129  this.keepTemp = keepTemp;
130  }
131 
138  public File validate() throws NXvalidateException {
139 
140  File result = null;
141 
142  //Do the conversion to the reduced format.
143  if (convertNxs && nxsFile != null) {
144  try {
145  NXconvert converter = new NXconvert(nxsFile, keepTemp, nxconvertCommand);
146  reduced = converter.convert();
147  } catch (Exception e) {
148  Logger.getLogger(ValidatorUtils.class.getName()).log(Level.SEVERE,
149  "While converting \"" + nxsFile
150  + "\" to reduced xml format");
151  throw new NXvalidateException("While converting \"" + nxsFile
152  + "\" to reduced xml format");
153  }
154  }
155 
156  //Do the validation.
157  if (reduced != null && schematronFile != null) {
158 
159  // create the validation setup
160  NXschematron schematron = new NXschematron(nxsFile, reduced,
161  schematronFile, keepTemp);
162 
163  try {
164  result = schematron.validate();
165  } catch (Exception e) {
166  Logger.getLogger(ValidatorUtils.class.getName()).log(Level.SEVERE,
167  "While creating validation report");
168  throw new NXvalidateException("While creating validation report", e);
169  }
170  }
171 
172  return result;
173 
174  }
175 }
void setReduced(File reduced)
Set the File object pointing to the reduced NEXUS file.
ValidatorUtils(File nxsFile, String nxconvertCommand)
void setKeepTemp(boolean keepTemp)
Set a flag that indicates that the temporary files (such as the reduced document and the validation r...
void setNXS(File nxsFile)
Set the File object pointing to the NEXUS file.
File getNXS()
Get the File object pointing to the NEXUS file.
File getReduced()
Get the File object pointing to the reduced NEXUS file.
A class the wraps the conversion and validation processes.
void setSchematron(File schematronFile)
Set the File object pointing to the Schematron file that contains the rules for checking the reduced ...
File getSchematron()
Get the File object pointing to the Schematron file that contains the rules for checking the reduced ...
File validate()
This methods performs the validation using the NEXUS (or reduced) file and the Schematron file...
void doConversion(boolean convertNxs)
Set a flag that indicates that the conversion of a NEXUS file to a reduced document should be perform...