You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@any23.apache.org by ha...@apache.org on 2018/07/11 20:16:42 UTC
any23 git commit: ANY23-364 resolved POI deprecation warnings
Repository: any23
Updated Branches:
refs/heads/master 40619343d -> 5a2613b84
ANY23-364 resolved POI deprecation warnings
Project: http://git-wip-us.apache.org/repos/asf/any23/repo
Commit: http://git-wip-us.apache.org/repos/asf/any23/commit/5a2613b8
Tree: http://git-wip-us.apache.org/repos/asf/any23/tree/5a2613b8
Diff: http://git-wip-us.apache.org/repos/asf/any23/diff/5a2613b8
Branch: refs/heads/master
Commit: 5a2613b848b317c54381bcc8d7b23ca1e27e3725
Parents: 4061934
Author: Hans <fi...@gmail.com>
Authored: Wed Jul 11 15:10:46 2018 -0500
Committer: Hans <fi...@gmail.com>
Committed: Wed Jul 11 15:10:46 2018 -0500
----------------------------------------------------------------------
.../plugin/officescraper/ExcelExtractor.java | 42 +++++++++++---------
.../main/java/org/apache/any23/vocab/Excel.java | 9 ++---
2 files changed, 28 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/any23/blob/5a2613b8/plugins/office-scraper/src/main/java/org/apache/any23/plugin/officescraper/ExcelExtractor.java
----------------------------------------------------------------------
diff --git a/plugins/office-scraper/src/main/java/org/apache/any23/plugin/officescraper/ExcelExtractor.java b/plugins/office-scraper/src/main/java/org/apache/any23/plugin/officescraper/ExcelExtractor.java
index 4c8826c..d4e7918 100644
--- a/plugins/office-scraper/src/main/java/org/apache/any23/plugin/officescraper/ExcelExtractor.java
+++ b/plugins/office-scraper/src/main/java/org/apache/any23/plugin/officescraper/ExcelExtractor.java
@@ -27,6 +27,7 @@ import org.apache.any23.rdf.RDFUtils;
import org.apache.any23.vocab.Excel;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@@ -87,9 +88,9 @@ public class ExcelExtractor implements Extractor.ContentExtractor {
// TODO: this should be done by Tika, the extractors should be split.
private Workbook createWorkbook(IRI document, InputStream is) throws IOException {
final String documentIRI = document.toString();
- if(documentIRI.endsWith(".xlsx")) {
+ if (documentIRI.endsWith(".xlsx")) {
return new XSSFWorkbook(is);
- } else if(documentIRI.endsWith("xls")) {
+ } else if (documentIRI.endsWith("xls")) {
return new HSSFWorkbook(is);
} else {
throw new IllegalArgumentException("Unsupported extension for resource [" + documentIRI + "]");
@@ -121,7 +122,7 @@ public class ExcelExtractor implements Extractor.ContentExtractor {
final int lastRowNum = sheet.getLastRowNum();
er.writeTriple(sheetIRI, excel.sheetName, RDFUtils.literal(sheetName));
er.writeTriple(sheetIRI, excel.firstRow, RDFUtils.literal(firstRowNum));
- er.writeTriple(sheetIRI, excel.lastRow , RDFUtils.literal(lastRowNum ));
+ er.writeTriple(sheetIRI, excel.lastRow, RDFUtils.literal(lastRowNum));
}
private void writeRowMetadata(IRI rowIRI, Row row, ExtractionResult er) {
@@ -132,8 +133,9 @@ public class ExcelExtractor implements Extractor.ContentExtractor {
}
private void writeCell(IRI rowIRI, Cell cell, ExtractionResult er) {
- final IRI cellType = cellTypeToType(cell.getCellType());
- if(cellType == null) return; // Skip unsupported cells.
+ final IRI cellType = cellTypeToType(cell.getCellTypeEnum());
+ if (cellType == null)
+ return; // Skip unsupported cells.
final IRI cellIRI = getCellIRI(rowIRI, cell);
er.writeTriple(rowIRI, excel.containsCell, cellIRI);
er.writeTriple(cellIRI, RDF.TYPE, excel.cell);
@@ -157,20 +159,24 @@ public class ExcelExtractor implements Extractor.ContentExtractor {
String.format("/%d/", cell.getColumnIndex()));
}
- private IRI cellTypeToType(int cellType) {
+ private IRI cellTypeToType(CellType cellType) {
final String postfix;
- switch (cellType) {
- case Cell.CELL_TYPE_STRING:
- postfix = "string";
- break;
- case Cell.CELL_TYPE_BOOLEAN:
- postfix = "boolean";
- break;
- case Cell.CELL_TYPE_NUMERIC:
- postfix = "numeric";
- break;
- default:
- postfix = null;
+ if (cellType == null) {
+ postfix = null;
+ } else {
+ switch (cellType) {
+ case STRING:
+ postfix = "string";
+ break;
+ case BOOLEAN:
+ postfix = "boolean";
+ break;
+ case NUMERIC:
+ postfix = "numeric";
+ break;
+ default:
+ postfix = null;
+ }
}
return postfix == null ? null : RDFUtils.iri(excel.getNamespace().toString() + postfix);
}
http://git-wip-us.apache.org/repos/asf/any23/blob/5a2613b8/plugins/office-scraper/src/main/java/org/apache/any23/vocab/Excel.java
----------------------------------------------------------------------
diff --git a/plugins/office-scraper/src/main/java/org/apache/any23/vocab/Excel.java b/plugins/office-scraper/src/main/java/org/apache/any23/vocab/Excel.java
index 2ce8874..3295469 100644
--- a/plugins/office-scraper/src/main/java/org/apache/any23/vocab/Excel.java
+++ b/plugins/office-scraper/src/main/java/org/apache/any23/vocab/Excel.java
@@ -109,13 +109,12 @@ public class Excel extends Vocabulary {
*/
public static final String NS = "http://any23.apache.org/excel/";
- private static Excel instance;
+ private static final class InstanceHolder {
+ private static final Excel instance = new Excel();
+ }
public static Excel getInstance() {
- if (instance == null) {
- instance = new Excel();
- }
- return instance;
+ return InstanceHolder.instance;
}
public IRI createResource(String localName) {