corpus-services  1.0
ComaOverviewGeneration.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.URL;
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 javax.xml.xpath.XPathExpressionException;
23 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
24 import org.jdom.JDOMException;
25 import org.xml.sax.SAXException;
26 
34 public class ComaOverviewGeneration extends Checker implements CorpusFunction {
35 
36  boolean inel = false;
37  String xslpath = "/xsl/Output_metadata_summary.xsl";
38 
40  //no fixing available
41  super(false);
42  }
43 
44  @Override
45  public Report function(CorpusData cd, Boolean fix) {
46  Report r = new Report();
47  String xsl;
48  try {
49 
50  // get the XSLT stylesheet as String
51  xsl = TypeConverter.InputStream2String(getClass().getResourceAsStream(xslpath));
52  // create XSLTransformer and set the parameters
53  XSLTransformer xt = new XSLTransformer();
54  //set an parameter for INEL
55  if(inel){
56  xt.setParameter("mode", "inel");
57  }
58  // perform XSLT transformation
59  String result = xt.transform(cd.toSaveableString(), xsl);
60  //get location to save new result
61  URL overviewurl = new URL(cd.getParentURL(), "curation/coma_overview.html");
62  CorpusIO cio = new CorpusIO();
63  //save it
64  cio.write(result, overviewurl);
65  //everything worked
66  r.addCorrect(function, cd, "created html overview at " + overviewurl);
67 
68 
69  } catch (TransformerConfigurationException ex) {
70  r.addException(ex, function, cd, "Transformer configuration error");
71  } catch (TransformerException ex) {
72  r.addException(ex, function, cd, "Transformer error");
73  } catch (MalformedURLException ex) {
74  r.addException(ex, function, cd, "Malformed URL error");
75  } catch (IOException ex) {
76  r.addException(ex, function, cd, "Unknown input/output error");
77  } catch (ParserConfigurationException ex) {
78  r.addException(ex, function, cd, "Unknown Parser error");
79  } catch (SAXException ex) {
80  r.addException(ex, function, cd, "Unknown XML error");
81  } catch (XPathExpressionException ex) {
82  r.addException(ex, function, cd, "Unknown XPath error");
83  }
84 
85  return r;
86 
87  }
88 
89 
90  @Override
91  public Collection<Class<? extends CorpusData>> getIsUsableFor() {
92  Class cl1;
93  try {
94  cl1 = Class.forName("de.uni_hamburg.corpora.ComaData");
95  IsUsableFor.add(cl1);
96  } catch (ClassNotFoundException ex) {
97  report.addException(ex, "Usable class not found.");
98  }
99  return IsUsableFor;
100  }
101 
106  @Override
107  public String getDescription() {
108  String description = "This class creates a sort- and filterable html overview in table form "
109  + " of the content of the coma file to make error checking and harmonizing easier. ";
110  return description;
111  }
112 
113  public void setInel() {
114  inel = true;
115  }
116 
117  @Override
118  public Report function(Corpus c, Boolean fix) {
119  Report stats;
120  cd = c.getComaData();
121  stats = function(cd, fix);
122  return stats;
123  }
124 
125 }
Collection< Class<?extends CorpusData > > getIsUsableFor()
void setParameter(String parameterName, Object parameterValue)
static String InputStream2String(InputStream is)
void addCorrect(String statId, String description)
Definition: Report.java:217
void addException(Throwable e, String description)
Definition: Report.java:287