Repository: metamodel Updated Branches: refs/heads/master 39947f559 -> c7cc4acf0
METAMODEL-1174: Updated POI dependency (and using code) to latest closes apache/metamodel#173 Project: http://git-wip-us.apache.org/repos/asf/metamodel/repo Commit: http://git-wip-us.apache.org/repos/asf/metamodel/commit/c7cc4acf Tree: http://git-wip-us.apache.org/repos/asf/metamodel/tree/c7cc4acf Diff: http://git-wip-us.apache.org/repos/asf/metamodel/diff/c7cc4acf Branch: refs/heads/master Commit: c7cc4acf0525bb895662bc83be1211f87aeaadab Parents: 39947f5 Author: Kasper Sørensen <[email protected]> Authored: Fri Dec 8 23:16:38 2017 +0100 Committer: Dennis Du Krøger <[email protected]> Committed: Fri Dec 8 23:20:10 2017 +0100 ---------------------------------------------------------------------- CHANGES.md | 1 + excel/pom.xml | 2 +- .../metamodel/excel/ExcelDataContext.java | 4 +- .../metamodel/excel/ExcelInsertBuilder.java | 16 +++--- .../org/apache/metamodel/excel/ExcelUtils.java | 58 +++++++++++--------- 5 files changed, 44 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/metamodel/blob/c7cc4acf/CHANGES.md ---------------------------------------------------------------------- diff --git a/CHANGES.md b/CHANGES.md index f442440..860c0b7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,7 @@ * [METAMODEL-1169] - Fixed issue with SQL Server milliseconds precision in WHERE. * [METAMODEL-1173] - Fixed parsing and handling of scalar functions in WHERE clause. * [METAMODEL-1171] - Fixed parsing of query operators with DATE, TIME, TIMESTAMP prefix to operand date/time values. + * [METAMODEL-1174] - Upgraded Excel module's dependency on Apache POI to latest stable version (3.17). ### Apache MetaModel 5.0 http://git-wip-us.apache.org/repos/asf/metamodel/blob/c7cc4acf/excel/pom.xml ---------------------------------------------------------------------- diff --git a/excel/pom.xml b/excel/pom.xml index 6ec11b3..4cea4c9 100644 --- a/excel/pom.xml +++ b/excel/pom.xml @@ -40,7 +40,7 @@ under the License. <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> - <version>3.13</version> + <version>3.17</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> http://git-wip-us.apache.org/repos/asf/metamodel/blob/c7cc4acf/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java ---------------------------------------------------------------------- diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java index b5e6fca..b1f8149 100644 --- a/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java +++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java @@ -35,7 +35,7 @@ import org.apache.metamodel.schema.Schema; import org.apache.metamodel.schema.Table; import org.apache.metamodel.util.FileResource; import org.apache.metamodel.util.Resource; -import org.apache.poi.POIXMLDocument; +import org.apache.poi.poifs.filesystem.FileMagic; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -189,7 +189,7 @@ public final class ExcelDataContext extends QueryPostprocessDataContext implemen if (_spreadsheetReaderDelegate == null) { _spreadsheetReaderDelegate = _resource.read(in -> { try { - if (POIXMLDocument.hasOOXMLHeader(in)) { + if (FileMagic.valueOf(in) == FileMagic.OOXML) { return new XlsxSpreadsheetReaderDelegate(_resource, _configuration); } else { return new DefaultSpreadsheetReaderDelegate(_resource, _configuration); http://git-wip-us.apache.org/repos/asf/metamodel/blob/c7cc4acf/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java ---------------------------------------------------------------------- diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java index dd0d0ea..b584e76 100644 --- a/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java +++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java @@ -22,7 +22,9 @@ import java.util.Date; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.Row; import org.apache.metamodel.data.Style; import org.apache.metamodel.data.Style.Color; @@ -87,7 +89,7 @@ final class ExcelInsertBuilder extends }; if (style.isBold()) { - font.get().setBoldweight(Font.BOLDWEIGHT_BOLD); + font.get().setBold(true); } if (style.isItalic()) { font.get().setItalic(true); @@ -120,7 +122,7 @@ final class ExcelInsertBuilder extends final Color backgroundColor = style.getBackgroundColor(); if (backgroundColor != null) { cellStyle.get().setFillPattern( - CellStyle.SOLID_FOREGROUND); + FillPatternType.SOLID_FOREGROUND); cellStyle.get().setFillForegroundColor( getUpdateCallback().getColorIndex( backgroundColor)); @@ -161,16 +163,16 @@ final class ExcelInsertBuilder extends return d.intValue(); } - private short getAlignment(TextAlignment alignment) { + private HorizontalAlignment getAlignment(TextAlignment alignment) { switch (alignment) { case LEFT: - return CellStyle.ALIGN_LEFT; + return HorizontalAlignment.LEFT; case RIGHT: - return CellStyle.ALIGN_RIGHT; + return HorizontalAlignment.RIGHT; case CENTER: - return CellStyle.ALIGN_CENTER; + return HorizontalAlignment.CENTER; case JUSTIFY: - return CellStyle.ALIGN_JUSTIFY; + return HorizontalAlignment.JUSTIFY; default: throw new IllegalArgumentException("Unknown alignment type: " + alignment); http://git-wip-us.apache.org/repos/asf/metamodel/blob/c7cc4acf/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java ---------------------------------------------------------------------- diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java index 85cc79b..c7fe930 100644 --- a/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java +++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java @@ -54,6 +54,7 @@ import org.apache.poi.ss.formula.FormulaParseException; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Color; +import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.FontUnderline; import org.apache.poi.ss.usermodel.FormulaError; @@ -142,8 +143,8 @@ final class ExcelUtils { } /** - * Writes the {@link Workbook} to a {@link Resource}. The {@link Workbook} - * will be closed as a result of this operation! + * Writes the {@link Workbook} to a {@link Resource}. The {@link Workbook} will be closed as a result of this + * operation! * * @param dataContext * @param wb @@ -188,14 +189,15 @@ final class ExcelUtils { final String result; - switch (cell.getCellType()) { - case Cell.CELL_TYPE_BLANK: + switch (cell.getCellTypeEnum()) { + case BLANK: + case _NONE: result = null; break; - case Cell.CELL_TYPE_BOOLEAN: + case BOOLEAN: result = Boolean.toString(cell.getBooleanCellValue()); break; - case Cell.CELL_TYPE_ERROR: + case ERROR: String errorResult; try { byte errorCode = cell.getErrorCellValue(); @@ -214,11 +216,11 @@ final class ExcelUtils { } result = errorResult; break; - case Cell.CELL_TYPE_FORMULA: + case FORMULA: // result = cell.getCellFormula(); result = getFormulaCellValue(wb, cell); break; - case Cell.CELL_TYPE_NUMERIC: + case NUMERIC: if (HSSFDateUtil.isCellDateFormatted(cell)) { Date date = cell.getDateCellValue(); if (date == null) { @@ -232,11 +234,11 @@ final class ExcelUtils { result = _numberFormat.format(cell.getNumericCellValue()); } break; - case Cell.CELL_TYPE_STRING: + case STRING: result = cell.getRichStringCellValue().getString(); break; default: - throw new IllegalStateException("Unknown cell type: " + cell.getCellType()); + throw new IllegalStateException("Unknown cell type: " + cell.getCellTypeEnum()); } logger.debug("cell {} resolved to value: {}", cellCoordinate, result); @@ -260,8 +262,8 @@ final class ExcelUtils { // evaluate cell first, if possible try { if (logger.isInfoEnabled()) { - logger.info("cell({},{}) is a formula. Attempting to evaluate: {}", new Object[] { cell.getRowIndex(), - cell.getColumnIndex(), cell.getCellFormula() }); + logger.info("cell({},{}) is a formula. Attempting to evaluate: {}", + new Object[] { cell.getRowIndex(), cell.getColumnIndex(), cell.getCellFormula() }); } final FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); @@ -271,8 +273,8 @@ final class ExcelUtils { return getCellValue(wb, evaluatedCell); } catch (RuntimeException e) { - logger.warn("Exception occurred while evaluating formula at position ({},{}): {}", new Object[] { cell - .getRowIndex(), cell.getColumnIndex(), e.getMessage() }); + logger.warn("Exception occurred while evaluating formula at position ({},{}): {}", + new Object[] { cell.getRowIndex(), cell.getColumnIndex(), e.getMessage() }); // Some exceptions we simply log - result will be then be the // actual formula if (e instanceof FormulaParseException) { @@ -299,7 +301,7 @@ final class ExcelUtils { final StyleBuilder styleBuilder = new StyleBuilder(); // Font bold, italic, underline - if (font.getBoldweight() >= Font.BOLDWEIGHT_BOLD) { + if (font.getBold()) { styleBuilder.bold(); } if (font.getItalic()) { @@ -342,7 +344,7 @@ final class ExcelUtils { } // Background color - if (cellStyle.getFillPattern() == 1) { + if (cellStyle.getFillPatternEnum() == FillPatternType.SOLID_FOREGROUND) { Color color = cellStyle.getFillForegroundColorColor(); if (color instanceof HSSFColor) { short[] triplet = ((HSSFColor) color).getTriplet(); @@ -355,25 +357,28 @@ final class ExcelUtils { styleBuilder.background(argb.substring(2)); } } else { - throw new IllegalStateException("Unexpected color type: " + (color == null ? "null" : color.getClass()) - + ")"); + throw new IllegalStateException( + "Unexpected color type: " + (color == null ? "null" : color.getClass()) + ")"); } } // alignment - switch (cellStyle.getAlignment()) { - case CellStyle.ALIGN_LEFT: + switch (cellStyle.getAlignmentEnum()) { + case LEFT: styleBuilder.leftAligned(); break; - case CellStyle.ALIGN_RIGHT: + case RIGHT: styleBuilder.rightAligned(); break; - case CellStyle.ALIGN_CENTER: + case CENTER: styleBuilder.centerAligned(); break; - case CellStyle.ALIGN_JUSTIFY: + case JUSTIFY: styleBuilder.justifyAligned(); break; + default: + // we currently don't support other alignment styles + break; } return styleBuilder.create(); @@ -413,8 +418,7 @@ final class ExcelUtils { * * @param workbook * @param row - * @param selectItems - * select items of the columns in the table + * @param selectItems select items of the columns in the table * @return */ public static DefaultRow createRow(Workbook workbook, Row row, DataSetHeader header) { @@ -436,8 +440,8 @@ final class ExcelUtils { } public static DataSet getDataSet(Workbook workbook, Sheet sheet, Table table, ExcelConfiguration configuration) { - final List<SelectItem> selectItems = table.getColumns().stream().map(SelectItem::new).collect(Collectors - .toList()); + final List<SelectItem> selectItems = + table.getColumns().stream().map(SelectItem::new).collect(Collectors.toList()); final Iterator<Row> rowIterator = getRowIterator(sheet, configuration, true); if (!rowIterator.hasNext()) { // no more rows!
