9 package de.uni_hamburg.corpora.validation;
17 import java.io.IOException;
19 import java.util.Collection;
20 import javax.xml.parsers.ParserConfigurationException;
21 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
22 import org.jdom.JDOMException;
23 import org.w3c.dom.Document;
24 import org.w3c.dom.Element;
25 import org.w3c.dom.Node;
26 import org.w3c.dom.NodeList;
27 import org.w3c.dom.Text;
28 import org.xml.sax.SAXException;
31 import java.net.URISyntaxException;
32 import java.nio.file.Paths;
33 import javax.xml.transform.TransformerException;
34 import javax.xml.xpath.XPathExpressionException;
41 String referencePath =
"./";
43 String communicationname;
51 public Report function(
Corpus c, Boolean fix)
throws SAXException, JDOMException, IOException, JexmaraldaException, ParserConfigurationException, URISyntaxException, TransformerException, XPathExpressionException {
54 stats =
function(cd, fix);
60 throws SAXException, IOException, ParserConfigurationException, URISyntaxException, TransformerException, XPathExpressionException {
62 NodeList nslinks = doc.getElementsByTagName(
"NSLink");
65 for (
int i = 0; i < nslinks.getLength(); i++) {
66 Element nslink = (Element) nslinks.item(i);
67 Node communication = nslink.getParentNode();
68 if (communication.getNodeName() != null && communication.getNodeName().equals(
"Transcription")) {
69 communicationname = communication.getParentNode().getAttributes().getNamedItem(
"Name").getTextContent();
70 }
else if (communication.getNodeName() != null && communication.getNodeName().equals(
"Media")) {
71 communicationname = communication.getParentNode().getParentNode().getAttributes().getNamedItem(
"Name").getTextContent();
74 communicationname =
"Could not figure out Communication name";
76 NodeList nstexts = nslink.getChildNodes();
77 for (
int j = 0; j < nstexts.getLength(); j++) {
78 Node maybeText = nstexts.item(j);
79 if (maybeText.getNodeType() != Node.TEXT_NODE) {
80 System.out.println(
"This is not a text node: " 84 Text nstext = (Text) nstexts.item(j);
85 String nspath = nstext.getWholeText().replace(
"/", File.separator);
86 File justFile =
new File(nspath);
87 boolean found =
false;
88 if (justFile.exists()) {
91 String absPath = referencePath + File.separator + nspath;
93 File absFile =
new File(absPath);
94 if (absFile.exists()) {
97 if (cd.getURL() != null) {
98 URL urlPath = cd.getURL();
100 URL urlAbsPath =
new URL(urlPath, nspath.replace(File.separator,
"/"));
102 File dataFile =
new File(urlAbsPath.toURI());
103 if (dataFile.exists()) {
110 URI parentURI = uri.getPath().endsWith(
"/") ? uri.resolve(
"..") : uri.resolve(
".");
112 = Paths.get(parentURI).toString()
113 + File.separator + nspath;
114 File baseFile =
new File(basePath);
115 if (baseFile.exists()) {
121 "In Communication: " + communicationname +
" File in NSLink not found: " + nspath);
124 "File in NSLink was found: " + nspath);
128 NodeList relpathnodes = doc.getElementsByTagName(
"relPath");
129 for (
int i = 0; i < relpathnodes.getLength(); i++) {
130 Element relpathnode = (Element) relpathnodes.item(i);
131 NodeList reltexts = relpathnode.getChildNodes();
132 for (
int j = 0; j < reltexts.getLength(); j++) {
133 Node maybeText = reltexts.item(j);
134 Node communicationrel = maybeText.getParentNode().getParentNode();
135 if (communicationrel.getNodeName() != null && communicationrel.getNodeName().equals(
"File") && communicationrel.getParentNode().hasAttributes() && communicationrel.getParentNode().getAttributes().getNamedItem(
"Name") != null) {
136 communicationname = communicationrel.getParentNode().getAttributes().getNamedItem(
"Name").getTextContent();
139 communicationname =
"Could not figure out Communication name";
141 if (maybeText.getNodeType() != Node.TEXT_NODE) {
142 System.out.println(
"This is not a text node: " 146 Text reltext = (Text) reltexts.item(j);
147 String relpath = reltext.getWholeText().replace(
"/", File.separator);
148 File justFile =
new File(relpath);
149 boolean found =
false;
150 if (justFile.exists()) {
153 String absPath = referencePath + File.separator + relpath;
154 File absFile =
new File(absPath);
155 if (absFile.exists()) {
158 if (cd.getURL() != null) {
159 URL urlPath = cd.getURL();
160 URL urlRelPath =
new URL(urlPath, relpath.replace(
"\\",
"/"));
161 File dataFile =
new File(urlRelPath.toURI());
162 if (dataFile.exists()) {
168 URI parentURI = uri.getPath().endsWith(
"/") ? uri.resolve(
"..") : uri.resolve(
".");
170 = Paths.get(parentURI).toString()
171 + File.separator + relpath;
172 File baseFile =
new File(basePath);
173 if (baseFile.exists()) {
179 "In Communication: " + communicationname +
" File in relPath not found: " + relpath);
182 "File in relPath was found: " + relpath);
192 Class cl = Class.forName(
"de.uni_hamburg.corpora.ComaData");
194 }
catch (ClassNotFoundException ex) {
206 String description =
"This class checks for existence of files linked in the "
Collection< Class<?extends CorpusData > > getIsUsableFor()
void addCritical(String description)
static org.w3c.dom.Document JdomDocument2W3cDocument(org.jdom.Document jdomDoc)
void addCorrect(String statId, String description)
static org.jdom.Document String2JdomDocument(String stringRespresentingDocument)
void addException(Throwable e, String description)