7 package de.uni_hamburg.corpora;
9 import java.util.ArrayList;
10 import java.util.Collection;
11 import java.util.HashMap;
13 import javax.xml.parsers.DocumentBuilder;
14 import javax.xml.parsers.DocumentBuilderFactory;
15 import javax.xml.parsers.ParserConfigurationException;
16 import javax.xml.transform.TransformerConfigurationException;
17 import javax.xml.transform.TransformerException;
18 import org.w3c.dom.Attr;
19 import org.w3c.dom.Document;
20 import org.w3c.dom.Element;
28 private static Map<String, Collection<ExmaErrorListItem>> statistics;
34 statistics =
new HashMap<String, Collection<ExmaErrorListItem>>();
40 private Collection<ExmaErrorListItem> getOrCreateStatistic(String statId) {
41 if (!statistics.containsKey(statId)) {
42 statistics.put(statId,
new ArrayList<ExmaErrorListItem>());
44 return statistics.get(statId);
52 for (Map.Entry<String, Collection<ExmaErrorListItem>> kv
53 : sr.statistics.entrySet()) {
54 if (statistics.containsKey(kv.getKey())) {
55 Collection<ExmaErrorListItem> c
56 = statistics.get(kv.getKey());
57 c.addAll(kv.getValue());
58 statistics.put(kv.getKey(), c);
60 statistics.put(kv.getKey(), kv.getValue());
69 public void addError(String statId, String fileName, String tierID, String eventStart,
boolean done, String description) {
70 Collection<ExmaErrorListItem> stat = getOrCreateStatistic(statId);
77 public static Document
createFullErrorList() throws ParserConfigurationException, TransformerConfigurationException, TransformerException {
78 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
79 DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
80 Document doc = docBuilder.newDocument();
82 rootElement = doc.createElement(
"error-list");
83 doc.appendChild(rootElement);
84 Element secondElement = doc.createElement(
"errors");
85 rootElement.appendChild(secondElement);
86 for (Collection<ExmaErrorListItem> col : statistics.values()) {
88 Element error = doc.createElement(
"error");
89 Attr fl = doc.createAttribute(
"file");
90 fl.setValue(item.getFileName());
91 error.setAttributeNode(fl);
92 Attr tier = doc.createAttribute(
"tier");
93 tier.setValue(item.getTierID());
94 error.setAttributeNode(tier);
95 Attr start = doc.createAttribute(
"start");
96 start.setValue(item.getEventStart());
97 error.setAttributeNode(start);
98 Attr done = doc.createAttribute(
"done");
100 done.setValue(
"yes");
103 error.setAttributeNode(done);
104 error.appendChild(doc.createTextNode(item.getDescription()));
105 secondElement.appendChild(error);
void merge(ExmaErrorList sr)
void addError(String statId, String fileName, String tierID, String eventStart, boolean done, String description)
static Document createFullErrorList()