corpus-services  1.0
ExbMP3Next2WavAdder.java
Go to the documentation of this file.
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 package de.uni_hamburg.corpora.validation;
7 
15 import java.io.IOException;
16 import java.net.MalformedURLException;
17 import java.net.URISyntaxException;
18 import java.util.Collection;
19 import javax.xml.parsers.ParserConfigurationException;
20 import javax.xml.transform.TransformerConfigurationException;
21 import javax.xml.transform.TransformerException;
22 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
23 import org.jdom.JDOMException;
24 import org.xml.sax.SAXException;
25 import javax.xml.xpath.XPathExpressionException;
26 
35 public class ExbMP3Next2WavAdder extends Checker implements CorpusFunction {
36 
38  //fixing option available
39  super(true);
40  }
41 
42  @Override
43  public Report function(CorpusData cd, Boolean fix) throws TransformerConfigurationException, TransformerException, ParserConfigurationException, SAXException, IOException, XPathExpressionException {
44  Report r = new Report();
45  // get the XSLT stylesheet
46  String xsl = TypeConverter.InputStream2String(getClass().getResourceAsStream("/xsl/AddMP3next2WavExb.xsl"));
47  // create XSLTransformer and set the parameters
48  XSLTransformer xt = new XSLTransformer();
49 
50  // perform XSLT transformation
51  String result = xt.transform(cd.toSaveableString(), xsl);
52  CorpusIO cio = new CorpusIO();
53  //update the xml of the cd object
54 
55  if (fix) {
56  cd.updateUnformattedString(result);
57  //save it - overwrite exb
58  cio.write(cd, cd.getURL());
59  //everything worked
60  r.addFix(function, cd, "Added mp3 next to wav.");
61  } else {
62  r.addCritical(function, cd, "Checking function is not available");
63  }
64  return r;
65 
66  }
67 
68  @Override
69  public Collection<Class<? extends CorpusData>> getIsUsableFor() {
70  Class cl1;
71  try {
72  cl1 = Class.forName("de.uni_hamburg.corpora.BasicTranscriptionData");
73  IsUsableFor.add(cl1);
74  } catch (ClassNotFoundException ex) {
75  report.addException(ex, "Usable class not found.");
76  }
77  return IsUsableFor;
78  }
79 
84  @Override
85  public String getDescription() {
86  String description = "This class adds the path to an MP3 file next to the WAV file "
87  + "linked as a recording in an exb file.";
88  return description;
89  }
90 
91  @Override
92  public Report function(Corpus c, Boolean fix) throws SAXException, IOException, ParserConfigurationException, URISyntaxException, JDOMException, TransformerException, XPathExpressionException {
93  Report stats = new Report();
94  for (CorpusData cdata : c.getBasicTranscriptionData()) {
95  stats.merge(function(cdata, fix));
96  }
97  return stats;
98  }
99 
100 }
void merge(Report sr)
Definition: Report.java:73
Collection< Class<?extends CorpusData > > getIsUsableFor()
void addCritical(String description)
Definition: Report.java:104
static String InputStream2String(InputStream is)
void addException(Throwable e, String description)
Definition: Report.java:287
void write(CorpusData cd, URL url)
Definition: CorpusIO.java:66
void addFix(String statId, CorpusData cd, String description)
Definition: Report.java:155