Make importers more robust to preview errors when someone selects the

wrong importer/parser
This commit is contained in:
Tom Morris 2013-07-27 13:35:12 -04:00
parent 57ca70132c
commit 3003c1a709
2 changed files with 27 additions and 12 deletions

View File

@ -43,6 +43,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.POIXMLException;
import org.apache.poi.common.usermodel.Hyperlink;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@ -117,6 +118,8 @@ public class ExcelImporter extends TabularImportingParserBase {
logger.error("Error generating parser UI initialization data for Excel file", e);
} catch (IllegalArgumentException e) {
logger.error("Error generating parser UI initialization data for Excel file (only Excel 97 & later supported)", e);
} catch (POIXMLException e) {
logger.error("Error generating parser UI initialization data for Excel file - invalid XML", e);
}
return options;
@ -162,6 +165,13 @@ public class ExcelImporter extends TabularImportingParserBase {
e
));
return;
} catch (POIXMLException e) {
exceptions.add(new ImportException(
"Attempted to parse as an Excel file but failed. " +
"Invalid XML.",
e
));
return;
}
int[] sheets = JSONUtilities.getIntArray(options, "sheets");

View File

@ -86,18 +86,23 @@ public class RdfTripleImporter extends ImportingParserBase {
JSONObject options, List<Exception> exceptions) {
Graph graph;
switch (mode) {
case NT:
graph = rdfReader.parseNTriples(input);
break;
case N3:
graph = rdfReader.parseN3(input);
break;
case RDFXML:
graph = rdfReader.parseRdfXml(input);
break;
default:
throw new IllegalArgumentException("Unknown parsing mode");
try {
switch (mode) {
case NT:
graph = rdfReader.parseNTriples(input);
break;
case N3:
graph = rdfReader.parseN3(input);
break;
case RDFXML:
graph = rdfReader.parseRdfXml(input);
break;
default:
throw new IllegalArgumentException("Unknown parsing mode");
}
} catch (Exception e) {
exceptions.add(e);
return;
}
ClosableIterable<Triple> triples = graph.find(ANY_SUBJECT_NODE, ANY_PREDICATE_NODE, ANY_OBJECT_NODE);