26 package org.nexusformat.nxvalidate;
28 import com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException;
30 import java.io.FileInputStream;
31 import java.io.FileNotFoundException;
32 import java.io.IOException;
33 import java.net.ConnectException;
34 import java.net.MalformedURLException;
35 import java.util.logging.Level;
36 import java.util.logging.Logger;
37 import javax.xml.parsers.DocumentBuilder;
38 import javax.xml.parsers.DocumentBuilderFactory;
39 import javax.xml.parsers.ParserConfigurationException;
40 import org.w3c.dom.Document;
41 import org.xml.sax.SAXException;
49 private DocumentBuilderFactory factory = null;
50 private DocumentBuilder builder = null;
53 factory = DocumentBuilderFactory.newInstance();
54 factory.setNamespaceAware(
true);
56 builder = factory.newDocumentBuilder();
57 }
catch (ParserConfigurationException ex) {
59 Level.SEVERE, null, ex);
77 }
else if (checkNexusXML(file)) {
80 }
catch (FileNotFoundException ex) {
82 }
catch (IOException ex) {
95 public boolean checkHDF5(File file)
throws FileNotFoundException,
98 byte[] b =
new byte[7];
99 FileInputStream stream =
new FileInputStream(file);
104 }
else if (b[1] != 72) {
106 }
else if (b[2] != 68) {
108 }
else if (b[3] != 70) {
110 }
else if (b[4] != 13) {
112 }
else if (b[5] != 10) {
114 }
else if (b[6] != 26) {
128 public boolean checkHDF4(File file)
throws FileNotFoundException,
131 byte[] b =
new byte[4];
132 FileInputStream stream =
new FileInputStream(file);
137 }
else if (b[1] != 3) {
139 }
else if (b[2] != 19) {
141 }
else if (b[3] != 1) {
156 private boolean checkNexusXML(File file) {
158 boolean result =
false;
161 Document resultsDoc = builder.parse(file);
162 if (resultsDoc.getDocumentElement().getNodeName().equals(
"NXroot")) {
165 }
catch (SAXException ex) {
169 }
catch (MalformedByteSequenceException ex) {
173 }
catch (ConnectException ex) {
177 }
catch (MalformedURLException ex) {
181 }
catch (FileNotFoundException ex) {
185 }
catch (IOException ex) {
205 boolean result =
false;
208 Document resultsDoc = builder.parse(file);
209 if (resultsDoc.getDocumentElement().getNodeName().equals(
"definition")) {
212 if (resultsDoc.getDocumentElement().getNodeName().equals(
"definitions")) {
215 }
catch (SAXException ex) {
219 }
catch (MalformedByteSequenceException ex) {
223 }
catch (ConnectException ex) {
227 }
catch (MalformedURLException ex) {
231 }
catch (FileNotFoundException ex) {
235 }
catch (IOException ex) {