corpus-services  1.0
Checker.java
Go to the documentation of this file.
1 /*
2  * A command-line interface for checking corpus files.
3  *
4  * @author Anne Ferger
5  * @author HZSK
6  */
7 package de.uni_hamburg.corpora.validation;
8 
13 import java.io.IOException;
14 import java.net.URISyntaxException;
15 import java.security.NoSuchAlgorithmException;
16 import java.util.ArrayList;
17 import java.util.Collection;
18 import javax.xml.parsers.ParserConfigurationException;
19 import javax.xml.transform.TransformerException;
20 import javax.xml.xpath.XPathExpressionException;
21 import org.exmaralda.partitureditor.fsm.FSMException;
22 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
23 import org.jdom.JDOMException;
24 import org.xml.sax.SAXException;
25 
36 public abstract class Checker implements CorpusFunction {
37 
38  CorpusData cd;
39  Report report = new Report();
40  Collection<Class<? extends CorpusData>> IsUsableFor = new ArrayList<Class<? extends CorpusData>>();
41  final String function;
42  Boolean canfix;
43 
44  Checker(boolean hasfixingoption) {
45  function = this.getClass().getSimpleName();
46  canfix = hasfixingoption;
47 
48  }
49 
50  public Report execute(Corpus c) {
51  return execute(c, false);
52  }
53 
54  public Report execute(CorpusData cd) {
55  return execute(cd, false);
56  }
57 
58  public Report execute(CorpusData cd, boolean fix) {
59  report = new Report();
60  try {
61  if (fix) {
62 
63  if (canfix) {
64  report = function(cd, fix);
65  } else {
66  report.addCritical(function,
67  "Automatic fix is not available, doing check instead.");
68  report = function(cd, false);
69  }
70 
71  return report;
72  } else {
73  report = function(cd, fix);
74  }
75  } catch (JexmaraldaException je) {
76  report.addException(je, function, cd, "Unknown parsing error");
77  } catch (JDOMException jdome) {
78  report.addException(jdome, function, cd, "Unknown parsing error");
79  } catch (SAXException saxe) {
80  report.addException(saxe, function, cd, "Unknown parsing error");
81  } catch (IOException ioe) {
82  report.addException(ioe, function, cd, "File reading error");
83  } catch (FSMException ex) {
84  report.addException(ex, function, cd, "File reading error");
85  } catch (URISyntaxException ex) {
86  report.addException(ex, function, cd, "File reading erro");
87  } catch (ParserConfigurationException ex) {
88  report.addException(ex, function, cd, "File reading error");
89  } catch (TransformerException ex) {
90  report.addException(ex, function, cd, "File reading error");
91  } catch (XPathExpressionException ex) {
92  report.addException(ex, function, cd, "File reading error");
93  } catch (ClassNotFoundException ex) {
94  report.addException(ex, function, cd, "File reading error");
95  } catch (NoSuchAlgorithmException ex) {
96  report.addException(ex, function, cd, "File reading error");
97  }
98  return report;
99  }
100 
101  public Report execute(Corpus c, boolean fix) {
102  report = new Report();
103  try {
104  if (fix) {
105 
106  if (canfix) {
107  report = function(c, fix);
108  } else {
109  report.addCritical(function,
110  "Automatic fix is not yet supported.");
111  }
112  return report;
113  } else {
114  report = function(c, fix);
115  }
116  } catch (JexmaraldaException je) {
117  report.addException(je, function, cd, "Unknown parsing error");
118  } catch (JDOMException jdome) {
119  report.addException(jdome, function, cd, "Unknown parsing error");
120  } catch (SAXException saxe) {
121  report.addException(saxe, function, cd, "Unknown parsing error");
122  } catch (IOException ioe) {
123  report.addException(ioe, function, cd, "File reading error");
124  } catch (FSMException ex) {
125  report.addException(ex, function, cd, "File reading error");
126  } catch (URISyntaxException ex) {
127  report.addException(ex, function, cd, "File reading erro");
128  } catch (ParserConfigurationException ex) {
129  report.addException(ex, function, cd, "File reading error");
130  } catch (TransformerException ex) {
131  report.addException(ex, function, cd, "File reading error");
132  } catch (XPathExpressionException ex) {
133  report.addException(ex, function, cd, "File reading error");
134  } catch (ClassNotFoundException ex) {
135  report.addException(ex, function, cd, "File reading error");
136  } catch (NoSuchAlgorithmException ex) {
137  report.addException(ex, function, cd, "File reading error");
138  }
139  return report;
140  }
141 
142  //To implement in the class
143  public abstract Report function(CorpusData cd, Boolean fix) throws NoSuchAlgorithmException, ClassNotFoundException, FSMException, URISyntaxException, SAXException, IOException, ParserConfigurationException, JexmaraldaException, TransformerException, XPathExpressionException, JDOMException;
144 
145  //To implement in the class
146  public abstract Report function(Corpus c, Boolean fix) throws NoSuchAlgorithmException, ClassNotFoundException, FSMException, URISyntaxException, SAXException, IOException, ParserConfigurationException, JexmaraldaException, TransformerException, XPathExpressionException, JDOMException;
147 
148  public abstract Collection<Class<? extends CorpusData>> getIsUsableFor();
149 
150  public void setIsUsableFor(Collection<Class<? extends CorpusData>> cdc) {
151  for (Class<? extends CorpusData> cl : cdc) {
152  IsUsableFor.add(cl);
153  }
154  }
155 
156  public String getFunction() {
157  return function;
158  }
159 
160  public Boolean getCanFix() {
161  return canfix;
162  }
163 }
Report execute(Corpus c, boolean fix)
Definition: Checker.java:101
Report execute(CorpusData cd, boolean fix)
Definition: Checker.java:58
void addCritical(String description)
Definition: Report.java:104
abstract Collection< Class<?extends CorpusData > > getIsUsableFor()
void addException(Throwable e, String description)
Definition: Report.java:287
void setIsUsableFor(Collection< Class<?extends CorpusData >> cdc)
Definition: Checker.java:150