From b0215121b20a4483f9e8c1ea0ac12a5fcce048b2 Mon Sep 17 00:00:00 2001 From: David North Date: Sun, 11 Sep 2016 18:50:26 +0000 Subject: [PATCH 01/43] prepare for 3.16-beta1 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760273 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.xml b/build.xml index 545a8d153..633607618 100644 --- a/build.xml +++ b/build.xml @@ -40,7 +40,7 @@ under the License. The Apache POI project Ant build. - + From 494b54161aef665c9e8bc681d9aca1949e6e36bb Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 12 Sep 2016 23:10:27 +0000 Subject: [PATCH 02/43] Disabled unit test for #60010 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760458 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/streaming/TestSXSSFWorkbook.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java index bdd858b06..7b5a67de5 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; @@ -35,6 +36,8 @@ import java.util.Arrays; import org.apache.poi.POIDataSamples; import org.apache.poi.POITestCase; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.openxml4j.opc.PackageAccess; import org.apache.poi.ss.usermodel.BaseTestXWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; @@ -536,4 +539,40 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { swb.dispose(); swb.close(); } + + /** + * To avoid accident changes to the template, you should be able + * to create a SXSSFWorkbook from a read-only XSSF one, then + * change + save that (only). See bug #60010 + * TODO Fix this to work! + */ + @Test + @Ignore + public void createFromReadOnlyWorkbook() throws Exception { + File input = XSSFTestDataSamples.getSampleFile("sample.xlsx"); + OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ); + XSSFWorkbook xssf = new XSSFWorkbook(pkg); + SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2); + + String sheetName = "Test SXSSF"; + Sheet s = wb.createSheet(sheetName); + for (int i=0; i<10; i++) { + Row r = s.createRow(i); + r.createCell(0).setCellValue(true); + r.createCell(1).setCellValue(2.4); + r.createCell(2).setCellValue("Test Row " + i); + } + assertEquals(10, s.getLastRowNum()); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + wb.write(bos); + wb.dispose(); + wb.close(); + + xssf = new XSSFWorkbook(new ByteArrayInputStream(bos.toByteArray())); + s = xssf.getSheet(sheetName); + assertEquals(10, s.getLastRowNum()); + assertEquals(true, s.getRow(0).getCell(0).getBooleanCellValue()); + assertEquals("Test Row 9", s.getRow(9).getCell(2).getStringCellValue()); + } } From 3c97d9700ae96e1b19de2eebda6501bb52ecac70 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Tue, 13 Sep 2016 23:24:56 +0000 Subject: [PATCH 03/43] change CellValue#getCellType() to return an int instead of an enum for backwards compatibility (source and binary) with POI 3.14. This reverts the behavior introduced in POI 3.15 beta 3 in r1751237. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760607 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/usermodel/HSSFFormulaEvaluator.java | 4 ++-- .../poi/ss/formula/BaseFormulaEvaluator.java | 2 +- .../org/apache/poi/ss/usermodel/CellValue.java | 14 +++++++++++++- .../poi/ss/usermodel/charts/DataSources.java | 4 ++-- .../xssf/usermodel/BaseXSSFFormulaEvaluator.java | 4 ++-- .../poi/ss/formula/TestStructuredReferences.java | 4 ++-- .../poi/ss/formula/functions/TestProper.java | 2 +- .../xssf/usermodel/TestFormulaEvaluatorOnXSSF.java | 10 +++++----- .../TestMultiSheetFormulaEvaluatorOnXSSF.java | 10 +++++----- .../apache/poi/xssf/usermodel/TestXSSFBugs.java | 4 ++-- .../poi/hssf/model/TestFormulaParserEval.java | 2 +- .../poi/hssf/record/TestSharedFormulaRecord.java | 2 +- .../hssf/usermodel/TestHSSFFormulaEvaluator.java | 4 ++-- .../poi/ss/formula/TestWorkbookEvaluator.java | 12 ++++++------ .../org/apache/poi/ss/formula/atp/TestIfError.java | 6 +++--- .../formula/eval/BaseTestCircularReferences.java | 14 +++++++------- .../poi/ss/formula/eval/TestFormulaBugs.java | 8 ++++---- .../formula/eval/TestFormulasFromSpreadsheet.java | 10 +++++----- .../poi/ss/formula/eval/TestMultiSheetEval.java | 10 +++++----- .../poi/ss/formula/eval/TestPercentEval.java | 2 +- .../BaseTestFunctionsFromSpreadsheet.java | 6 +++--- .../poi/ss/formula/functions/TestAddress.java | 2 +- .../functions/TestCalendarFieldFunction.java | 2 +- .../apache/poi/ss/formula/functions/TestClean.java | 2 +- .../apache/poi/ss/formula/functions/TestDate.java | 2 +- .../apache/poi/ss/formula/functions/TestFind.java | 4 ++-- .../apache/poi/ss/formula/functions/TestFixed.java | 4 ++-- .../poi/ss/formula/functions/TestIndirect.java | 4 ++-- .../apache/poi/ss/formula/functions/TestIrr.java | 2 +- .../poi/ss/formula/functions/TestIsBlank.java | 4 ++-- .../apache/poi/ss/formula/functions/TestMirr.java | 2 +- .../poi/ss/usermodel/BaseTestBugzillaIssues.java | 4 ++-- 32 files changed, 89 insertions(+), 77 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java index 8d7d781f9..a0a932d07 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java @@ -163,7 +163,7 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator { CellValue cv = evaluateFormulaCellValue(cell); // cell remains a formula cell, but the cached value is changed setCellValue(cell, cv); - return cv.getCellType(); + return cv.getCellTypeEnum(); } /** @@ -196,7 +196,7 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator { } private static void setCellValue(Cell cell, CellValue cv) { - CellType cellType = cv.getCellType(); + CellType cellType = cv.getCellTypeEnum(); switch (cellType) { case BOOLEAN: cell.setCellValue(cv.getBooleanValue()); diff --git a/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java b/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java index 8746ba7fa..fb0c4d68d 100644 --- a/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java +++ b/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java @@ -132,7 +132,7 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook } protected static void setCellType(Cell cell, CellValue cv) { - CellType cellType = cv.getCellType(); + CellType cellType = cv.getCellTypeEnum(); switch (cellType) { case BOOLEAN: case ERROR: diff --git a/src/java/org/apache/poi/ss/usermodel/CellValue.java b/src/java/org/apache/poi/ss/usermodel/CellValue.java index 52fea225a..301accfca 100644 --- a/src/java/org/apache/poi/ss/usermodel/CellValue.java +++ b/src/java/org/apache/poi/ss/usermodel/CellValue.java @@ -78,10 +78,22 @@ public final class CellValue { } /** * @return Returns the cellType. + * @since POI 3.15 */ - public CellType getCellType() { + public CellType getCellTypeEnum() { return _cellType; } + /** + * @return Returns the cellType. + * @deprecated POI 3.15. Use {@link #getCellTypeEnum()} instead. + * In the future, the signature of this method will be changed to return a + * {@link CellType}. + */ + @Deprecated + public int getCellType() { + return _cellType.getCode(); + } + /** * @return Returns the errorValue. */ diff --git a/src/java/org/apache/poi/ss/usermodel/charts/DataSources.java b/src/java/org/apache/poi/ss/usermodel/charts/DataSources.java index 3bf891e0a..75e7fd9a8 100644 --- a/src/java/org/apache/poi/ss/usermodel/charts/DataSources.java +++ b/src/java/org/apache/poi/ss/usermodel/charts/DataSources.java @@ -42,7 +42,7 @@ public class DataSources { return new AbstractCellRangeDataSource(sheet, cellRangeAddress) { public Number getPointAt(int index) { CellValue cellValue = getCellValueAt(index); - if (cellValue != null && cellValue.getCellType() == CellType.NUMERIC) { + if (cellValue != null && cellValue.getCellTypeEnum() == CellType.NUMERIC) { return Double.valueOf(cellValue.getNumberValue()); } else { return null; @@ -59,7 +59,7 @@ public class DataSources { return new AbstractCellRangeDataSource(sheet, cellRangeAddress) { public String getPointAt(int index) { CellValue cellValue = getCellValueAt(index); - if (cellValue != null && cellValue.getCellType() == CellType.STRING) { + if (cellValue != null && cellValue.getCellTypeEnum() == CellType.STRING) { return cellValue.getStringValue(); } else { return null; diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java index c6c030b95..726ae87e4 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java @@ -77,7 +77,7 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator { CellValue cv = evaluateFormulaCellValue(cell); // cell remains a formula cell, but the cached value is changed setCellValue(cell, cv); - return cv.getCellType(); + return cv.getCellTypeEnum(); } /** @@ -97,7 +97,7 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator { } private static void setCellValue(Cell cell, CellValue cv) { - CellType cellType = cv.getCellType(); + CellType cellType = cv.getCellTypeEnum(); switch (cellType) { case BOOLEAN: cell.setCellValue(cv.getBooleanValue()); diff --git a/src/ooxml/testcases/org/apache/poi/ss/formula/TestStructuredReferences.java b/src/ooxml/testcases/org/apache/poi/ss/formula/TestStructuredReferences.java index 4e176257f..b60664ad0 100644 --- a/src/ooxml/testcases/org/apache/poi/ss/formula/TestStructuredReferences.java +++ b/src/ooxml/testcases/org/apache/poi/ss/formula/TestStructuredReferences.java @@ -110,7 +110,7 @@ public class TestStructuredReferences { private static void confirm(FormulaEvaluator fe, Cell cell, double expectedResult) { fe.clearAllCachedResultValues(); CellValue cv = fe.evaluate(cell); - if (cv.getCellType() != CellType.NUMERIC) { + if (cv.getCellTypeEnum() != CellType.NUMERIC) { fail("expected numeric cell type but got " + cv.formatAsString()); } assertEquals(expectedResult, cv.getNumberValue(), 0.0); @@ -119,7 +119,7 @@ public class TestStructuredReferences { private static void confirm(FormulaEvaluator fe, Cell cell, String expectedResult) { fe.clearAllCachedResultValues(); CellValue cv = fe.evaluate(cell); - if (cv.getCellType() != CellType.STRING) { + if (cv.getCellTypeEnum() != CellType.STRING) { fail("expected String cell type but got " + cv.formatAsString()); } assertEquals(expectedResult, cv.getStringValue()); diff --git a/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java b/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java index d86079eca..a24fd8879 100644 --- a/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java +++ b/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java @@ -96,7 +96,7 @@ public final class TestProper { cell11.setCellFormula(formulaText); evaluator.clearAllCachedResultValues(); CellValue cv = evaluator.evaluate(cell11); - if (cv.getCellType() != CellType.STRING) { + if (cv.getCellTypeEnum() != CellType.STRING) { throw new AssertionFailedError("Wrong result type: " + cv.formatAsString()); } String actualValue = cv.getStringValue(); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java index 4cbc7c4e6..ad8b49028 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java @@ -205,14 +205,14 @@ public final class TestFormulaEvaluatorOnXSSF { final CellType expectedCellType = expValue.getCellTypeEnum(); switch (expectedCellType) { case BLANK: - assertEquals(msg, CellType.BLANK, actValue.getCellType()); + assertEquals(msg, CellType.BLANK, actValue.getCellTypeEnum()); break; case BOOLEAN: - assertEquals(msg, CellType.BOOLEAN, actValue.getCellType()); + assertEquals(msg, CellType.BOOLEAN, actValue.getCellTypeEnum()); assertEquals(msg, expValue.getBooleanCellValue(), actValue.getBooleanValue()); break; case ERROR: - assertEquals(msg, CellType.ERROR, actValue.getCellType()); + assertEquals(msg, CellType.ERROR, actValue.getCellTypeEnum()); // if(false) { // TODO: fix ~45 functions which are currently returning incorrect error values // assertEquals(msg, expValue.getErrorCellValue(), actValue.getErrorValue()); // } @@ -220,14 +220,14 @@ public final class TestFormulaEvaluatorOnXSSF { case FORMULA: // will never be used, since we will call method after formula evaluation fail("Cannot expect formula as result of formula evaluation: " + msg); case NUMERIC: - assertEquals(msg, CellType.NUMERIC, actValue.getCellType()); + assertEquals(msg, CellType.NUMERIC, actValue.getCellTypeEnum()); TestMathX.assertEquals(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR); // double delta = Math.abs(expValue.getNumericCellValue()-actValue.getNumberValue()); // double pctExpValue = Math.abs(0.00001*expValue.getNumericCellValue()); // assertTrue(msg, delta <= pctExpValue); break; case STRING: - assertEquals(msg, CellType.STRING, actValue.getCellType()); + assertEquals(msg, CellType.STRING, actValue.getCellTypeEnum()); assertEquals(msg, expValue.getRichStringCellValue().getString(), actValue.getStringValue()); break; default: diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java index f33d96e63..b8926a3cf 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java @@ -188,14 +188,14 @@ public final class TestMultiSheetFormulaEvaluatorOnXSSF { final CellType expectedCellType = expValue.getCellTypeEnum(); switch (expectedCellType) { case BLANK: - assertEquals(msg, CellType.BLANK, actValue.getCellType()); + assertEquals(msg, CellType.BLANK, actValue.getCellTypeEnum()); break; case BOOLEAN: - assertEquals(msg, CellType.BOOLEAN, actValue.getCellType()); + assertEquals(msg, CellType.BOOLEAN, actValue.getCellTypeEnum()); assertEquals(msg, expValue.getBooleanCellValue(), actValue.getBooleanValue()); break; case ERROR: - assertEquals(msg, CellType.ERROR, actValue.getCellType()); + assertEquals(msg, CellType.ERROR, actValue.getCellTypeEnum()); // if(false) { // TODO: fix ~45 functions which are currently returning incorrect error values // assertEquals(msg, expected.getErrorCellValue(), actual.getErrorValue()); // } @@ -203,14 +203,14 @@ public final class TestMultiSheetFormulaEvaluatorOnXSSF { case FORMULA: // will never be used, since we will call method after formula evaluation fail("Cannot expect formula as result of formula evaluation: " + msg); case NUMERIC: - assertEquals(msg, CellType.NUMERIC, actValue.getCellType()); + assertEquals(msg, CellType.NUMERIC, actValue.getCellTypeEnum()); TestMathX.assertEquals(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR); // double delta = Math.abs(expected.getNumericCellValue()-actual.getNumberValue()); // double pctExpected = Math.abs(0.00001*expected.getNumericCellValue()); // assertTrue(msg, delta <= pctExpected); break; case STRING: - assertEquals(msg, CellType.STRING, actValue.getCellType()); + assertEquals(msg, CellType.STRING, actValue.getCellTypeEnum()); assertEquals(msg, expValue.getRichStringCellValue().getString(), actValue.getStringValue()); break; default: diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 2be21e830..e695f385f 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -304,7 +304,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { if(c.getCellTypeEnum() == CellType.FORMULA) { CellValue cv = eval.evaluate(c); - if(cv.getCellType() == CellType.NUMERIC) { + if(cv.getCellTypeEnum() == CellType.NUMERIC) { // assert that the calculated value agrees with // the cached formula result calculated by Excel String formula = c.getCellFormula(); @@ -2187,7 +2187,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { assertEquals("E4+E5", cell.getCellFormula()); CellValue value = evaluator.evaluate(cell); - assertEquals(CellType.ERROR, value.getCellType()); + assertEquals(CellType.ERROR, value.getCellTypeEnum()); assertEquals(-60, value.getErrorValue()); assertEquals("~CIRCULAR~REF~", FormulaError.forInt(value.getErrorValue()).getString()); assertEquals("CIRCULAR_REF", FormulaError.forInt(value.getErrorValue()).toString()); diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java index 53f5f4ac7..291b3a500 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java +++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java @@ -99,7 +99,7 @@ public final class TestFormulaParserEval extends TestCase { } throw e; } - assertEquals(CellType.NUMERIC, result.getCellType()); + assertEquals(CellType.NUMERIC, result.getCellTypeEnum()); assertEquals(42.0, result.getNumberValue(), 0.0); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java index bf7b813d0..b61f9ed67 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java @@ -228,7 +228,7 @@ public final class TestSharedFormulaRecord extends TestCase { private static void confirmCellEvaluation(HSSFWorkbook wb, HSSFCell cell, double expectedValue) { HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); CellValue cv = fe.evaluate(cell); - assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(expectedValue, cv.getNumberValue(), 0.0); } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFormulaEvaluator.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFormulaEvaluator.java index 4c762fa90..d8987496f 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFormulaEvaluator.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFormulaEvaluator.java @@ -55,7 +55,7 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator { HSSFCell cell = sheet.getRow(8).getCell(0); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); CellValue cv = fe.evaluate(cell); - assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(3.72, cv.getNumberValue(), 0.0); wb.close(); } @@ -127,7 +127,7 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator { try { value = hsf.evaluate(cellA1); - assertEquals(CellType.NUMERIC, value.getCellType()); + assertEquals(CellType.NUMERIC, value.getCellTypeEnum()); assertEquals(5.33, value.getNumberValue(), 0.0); } catch (RuntimeException e) { diff --git a/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java b/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java index c97face94..7c8936362 100644 --- a/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java +++ b/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java @@ -203,7 +203,7 @@ public class TestWorkbookEvaluator { } catch (RuntimeException e) { fail("Missing arg result not being handled correctly."); } - assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(CellType.NUMERIC, cv.getCellTypeEnum()); // adding blank to 1.0 gives 1.0 assertEquals(1.0, cv.getNumberValue(), 0.0); @@ -211,7 +211,7 @@ public class TestWorkbookEvaluator { cell.setCellFormula("\"abc\"&IF(1,,)"); fe.notifySetFormula(cell); cv = fe.evaluate(cell); - assertEquals(CellType.STRING, cv.getCellType()); + assertEquals(CellType.STRING, cv.getCellTypeEnum()); // adding blank to "abc" gives "abc" assertEquals("abc", cv.getStringValue()); @@ -219,7 +219,7 @@ public class TestWorkbookEvaluator { cell.setCellFormula("\"abc\"&CHOOSE(2,5,,9)"); fe.notifySetFormula(cell); cv = fe.evaluate(cell); - assertEquals(CellType.STRING, cv.getCellType()); + assertEquals(CellType.STRING, cv.getCellTypeEnum()); // adding blank to "abc" gives "abc" assertEquals("abc", cv.getStringValue()); } @@ -245,14 +245,14 @@ public class TestWorkbookEvaluator { } throw new RuntimeException(e); } - assertEquals(CellType.ERROR, cv.getCellType()); + assertEquals(CellType.ERROR, cv.getCellTypeEnum()); assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), cv.getErrorValue()); // verify circular refs are still detected properly fe.clearAllCachedResultValues(); cell.setCellFormula("OFFSET(A1,0,0)"); cv = fe.evaluate(cell); - assertEquals(CellType.ERROR, cv.getCellType()); + assertEquals(CellType.ERROR, cv.getCellTypeEnum()); assertEquals(ErrorEval.CIRCULAR_REF_ERROR.getErrorCode(), cv.getErrorValue()); } finally { wb.close(); @@ -396,7 +396,7 @@ public class TestWorkbookEvaluator { assertEquals(CellType.FORMULA, D1.getCellTypeEnum()); assertEquals(expectedFormula, D1.getCellFormula()); - assertEquals(CellType.NUMERIC, result.getCellType()); + assertEquals(CellType.NUMERIC, result.getCellTypeEnum()); assertEquals(expectedResult, result.getNumberValue(), EPSILON); testIFEqualsFormulaEvaluation_teardown(wb); diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java b/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java index 1d956c76f..ebf6951f0 100644 --- a/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java +++ b/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java @@ -78,18 +78,18 @@ public class TestIfError extends TestCase { FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); assertEquals("Checks that the cell is numeric", - CellType.NUMERIC, evaluator.evaluate(cell1).getCellType()); + CellType.NUMERIC, evaluator.evaluate(cell1).getCellTypeEnum()); assertEquals("Divides 210 by 35 and returns 6.0", 6.0, evaluator.evaluate(cell1).getNumberValue(), accuracy); assertEquals("Checks that the cell is numeric", - CellType.STRING, evaluator.evaluate(cell2).getCellType()); + CellType.STRING, evaluator.evaluate(cell2).getCellTypeEnum()); assertEquals("Rounds -10 to a nearest multiple of -3 (-9)", "Error in calculation", evaluator.evaluate(cell2).getStringValue()); assertEquals("Check that C1 returns string", - CellType.STRING, evaluator.evaluate(cell3).getCellType()); + CellType.STRING, evaluator.evaluate(cell3).getCellTypeEnum()); assertEquals("Check that C1 returns string \"error\"", "error", evaluator.evaluate(cell3).getStringValue()); } diff --git a/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java b/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java index 4c0223afd..ec3aa9107 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java @@ -66,7 +66,7 @@ public abstract class BaseTestCircularReferences { * Makes sure that the specified evaluated cell value represents a circular reference error. */ private static void confirmCycleErrorCode(CellValue cellValue) { - assertTrue(cellValue.getCellType() == CellType.ERROR); + assertTrue(cellValue.getCellTypeEnum() == CellType.ERROR); assertEquals(ErrorEval.CIRCULAR_REF_ERROR.getErrorCode(), cellValue.getErrorValue()); } @@ -96,7 +96,7 @@ public abstract class BaseTestCircularReferences { CellValue cellValue = evaluateWithCycles(wb, testCell); - assertTrue(cellValue.getCellType() == CellType.NUMERIC); + assertTrue(cellValue.getCellTypeEnum() == CellType.NUMERIC); assertEquals(2, cellValue.getNumberValue(), 0); wb.close(); } @@ -166,24 +166,24 @@ public abstract class BaseTestCircularReferences { // Happy day flow - evaluate A1 first cv = fe.evaluate(cellA1); - assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(42.0, cv.getNumberValue(), 0.0); cv = fe.evaluate(cellB1); // no circ-ref-error because A1 result is cached - assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(46.0, cv.getNumberValue(), 0.0); // Show the bug - evaluate another cell from the loop first fe.clearAllCachedResultValues(); cv = fe.evaluate(cellB1); // Identified bug 46898 - assertNotEquals(cv.getCellType(), ErrorEval.CIRCULAR_REF_ERROR.getErrorCode()); - assertEquals(CellType.NUMERIC, cv.getCellType()); + assertNotEquals(cv.getCellTypeEnum(), ErrorEval.CIRCULAR_REF_ERROR.getErrorCode()); + assertEquals(CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(46.0, cv.getNumberValue(), 0.0); // start evaluation on another cell fe.clearAllCachedResultValues(); cv = fe.evaluate(cellE1); - assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(43.0, cv.getNumberValue(), 0.0); wb.close(); diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java index 561ce4bfd..98fe73169 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java @@ -58,7 +58,7 @@ public final class TestFormulaBugs { FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); CellValue cv = fe.evaluate(cell); - assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(3.0, cv.getNumberValue(), 0.0); wb.close(); @@ -106,11 +106,11 @@ public final class TestFormulaBugs { FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); CellValue cv; cv = fe.evaluate(cell); - assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(1.0, cv.getNumberValue(), 0.0); cv = fe.evaluate(row.getCell(1)); - assertEquals(CellType.BOOLEAN, cv.getCellType()); + assertEquals(CellType.BOOLEAN, cv.getCellTypeEnum()); assertEquals(true, cv.getBooleanValue()); wb.close(); @@ -161,7 +161,7 @@ public final class TestFormulaBugs { FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); CellValue cv = fe.evaluate(cell); - assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(expectedResult, cv.getNumberValue(), 0.0); wb.close(); diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java index fb3b6a928..9ce0488f9 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java @@ -190,24 +190,24 @@ public final class TestFormulasFromSpreadsheet { final CellType cellType = expValue.getCellTypeEnum(); switch (cellType) { case BLANK: - assertEquals(msg, CellType.BLANK, actValue.getCellType()); + assertEquals(msg, CellType.BLANK, actValue.getCellTypeEnum()); break; case BOOLEAN: - assertEquals(msg, CellType.BOOLEAN, actValue.getCellType()); + assertEquals(msg, CellType.BOOLEAN, actValue.getCellTypeEnum()); assertEquals(msg, expValue.getBooleanCellValue(), actValue.getBooleanValue()); break; case ERROR: - assertEquals(msg, CellType.ERROR, actValue.getCellType()); + assertEquals(msg, CellType.ERROR, actValue.getCellTypeEnum()); assertEquals(msg, ErrorEval.getText(expValue.getErrorCellValue()), ErrorEval.getText(actValue.getErrorValue())); break; case FORMULA: // will never be used, since we will call method after formula evaluation fail("Cannot expect formula as result of formula evaluation: " + msg); case NUMERIC: - assertEquals(msg, CellType.NUMERIC, actValue.getCellType()); + assertEquals(msg, CellType.NUMERIC, actValue.getCellTypeEnum()); TestMathX.assertEquals(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR); break; case STRING: - assertEquals(msg, CellType.STRING, actValue.getCellType()); + assertEquals(msg, CellType.STRING, actValue.getCellTypeEnum()); assertEquals(msg, expValue.getRichStringCellValue().getString(), actValue.getStringValue()); break; default: diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java index 429f5616e..b1b66c00d 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java @@ -110,24 +110,24 @@ public final class TestMultiSheetEval extends TestCase { switch (cellType) { case BLANK: - assertEquals(msg, CellType.BLANK, actual.getCellType()); + assertEquals(msg, CellType.BLANK, actual.getCellTypeEnum()); break; case BOOLEAN: - assertEquals(msg, CellType.BOOLEAN, actual.getCellType()); + assertEquals(msg, CellType.BOOLEAN, actual.getCellTypeEnum()); assertEquals(msg, expected.getBooleanCellValue(), actual.getBooleanValue()); break; case ERROR: - assertEquals(msg, CellType.ERROR, actual.getCellType()); + assertEquals(msg, CellType.ERROR, actual.getCellTypeEnum()); assertEquals(msg, ErrorEval.getText(expected.getErrorCellValue()), ErrorEval.getText(actual.getErrorValue())); break; case FORMULA: // will never be used, since we will call method after formula evaluation throw new AssertionFailedError("Cannot expect formula as result of formula evaluation: " + msg); case NUMERIC: - assertEquals(msg, CellType.NUMERIC, actual.getCellType()); + assertEquals(msg, CellType.NUMERIC, actual.getCellTypeEnum()); TestMathX.assertEquals(msg, expected.getNumericCellValue(), actual.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR); break; case STRING: - assertEquals(msg, CellType.STRING, actual.getCellType()); + assertEquals(msg, CellType.STRING, actual.getCellTypeEnum()); assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getStringValue()); break; default: diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java index c3a5eec23..71cf649dd 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java @@ -78,7 +78,7 @@ public final class TestPercentEval extends TestCase { // else some other unexpected error throw e; } - assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(0.5, cv.getNumberValue(), 0.0); } } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java index 8c40581e4..e32f3e05b 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java @@ -155,7 +155,7 @@ public abstract class BaseTestFunctionsFromSpreadsheet { if (expectedCell.getCellTypeEnum() == CellType.ERROR) { int expectedErrorCode = expectedCell.getErrorCellValue(); - assertEquals(msg, CellType.ERROR, actualValue.getCellType()); + assertEquals(msg, CellType.ERROR, actualValue.getCellTypeEnum()); assertEquals(msg, ErrorEval.getText(expectedErrorCode), actualValue.formatAsString()); assertEquals(msg, expectedErrorCode, actualValue.getErrorValue()); assertEquals(msg, ErrorEval.getText(expectedErrorCode), ErrorEval.getText(actualValue.getErrorValue())); @@ -163,11 +163,11 @@ public abstract class BaseTestFunctionsFromSpreadsheet { } // unexpected error - assertNotEquals(msg, CellType.ERROR, actualValue.getCellType()); + assertNotEquals(msg, CellType.ERROR, actualValue.getCellTypeEnum()); assertNotEquals(msg, formatValue(expectedCell), ErrorEval.getText(actualValue.getErrorValue())); // wrong type error - assertEquals(msg, expectedCell.getCellTypeEnum(), actualValue.getCellType()); + assertEquals(msg, expectedCell.getCellTypeEnum(), actualValue.getCellTypeEnum()); final CellType expectedCellType = expectedCell.getCellTypeEnum(); switch (expectedCellType) { diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestAddress.java b/src/testcases/org/apache/poi/ss/formula/functions/TestAddress.java index 8f3951aa9..84c1778f3 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestAddress.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestAddress.java @@ -73,7 +73,7 @@ public final class TestAddress extends TestCase { cell.setCellFormula(formulaText); fe.notifyUpdateCell(cell); CellValue result = fe.evaluate(cell); - assertEquals(result.getCellType(), CellType.STRING); + assertEquals(result.getCellTypeEnum(), CellType.STRING); assertEquals(expectedResult, result.getStringValue()); } } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java b/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java index 3f8823729..337ad8518 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java @@ -103,7 +103,7 @@ public final class TestCalendarFieldFunction extends TestCase { cell11.setCellFormula(formulaText); evaluator.clearAllCachedResultValues(); CellValue cv = evaluator.evaluate(cell11); - if (cv.getCellType() != CellType.NUMERIC) { + if (cv.getCellTypeEnum() != CellType.NUMERIC) { throw new AssertionFailedError("Wrong result type: " + cv.formatAsString()); } double actualValue = cv.getNumberValue(); diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestClean.java b/src/testcases/org/apache/poi/ss/formula/functions/TestClean.java index fe6c6a6ed..e0137aee4 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestClean.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestClean.java @@ -60,7 +60,7 @@ public final class TestClean extends TestCase { cell.setCellFormula(formulaText); fe.notifyUpdateCell(cell); CellValue result = fe.evaluate(cell); - assertEquals(result.getCellType(), CellType.STRING); + assertEquals(result.getCellTypeEnum(), CellType.STRING); assertEquals(expectedResult, result.getStringValue()); } } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java index db0f6b080..0051f72e7 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java @@ -81,7 +81,7 @@ public final class TestDate extends TestCase { cell11.setCellFormula(formulaText); evaluator.clearAllCachedResultValues(); CellValue cv = evaluator.evaluate(cell11); - if (cv.getCellType() != CellType.NUMERIC) { + if (cv.getCellTypeEnum() != CellType.NUMERIC) { throw new AssertionFailedError("Wrong result type: " + cv.formatAsString()); } double actualValue = cv.getNumberValue(); diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestFind.java b/src/testcases/org/apache/poi/ss/formula/functions/TestFind.java index 0bfff626a..5ac75d62a 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestFind.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestFind.java @@ -66,7 +66,7 @@ public final class TestFind { cell.setCellFormula(formulaText); fe.notifyUpdateCell(cell); CellValue result = fe.evaluate(cell); - assertEquals(result.getCellType(), CellType.NUMERIC); + assertEquals(result.getCellTypeEnum(), CellType.NUMERIC); assertEquals(expectedResult, result.getNumberValue(), 0.0); } @@ -75,7 +75,7 @@ public final class TestFind { cell.setCellFormula(formulaText); fe.notifyUpdateCell(cell); CellValue result = fe.evaluate(cell); - assertEquals(result.getCellType(), CellType.ERROR); + assertEquals(result.getCellTypeEnum(), CellType.ERROR); assertEquals(expectedErrorCode.getCode(), result.getErrorValue()); } } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java b/src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java index e14ea3c45..f6e1f3809 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java @@ -117,7 +117,7 @@ public final class TestFixed { cell11.setCellFormula(formulaText); evaluator.clearAllCachedResultValues(); CellValue cv = evaluator.evaluate(cell11); - assertEquals("Wrong result type: " + cv.formatAsString(), CellType.STRING, cv.getCellType()); + assertEquals("Wrong result type: " + cv.formatAsString(), CellType.STRING, cv.getCellTypeEnum()); String actualValue = cv.getStringValue(); assertEquals(expectedResult, actualValue); } @@ -127,7 +127,7 @@ public final class TestFixed { evaluator.clearAllCachedResultValues(); CellValue cv = evaluator.evaluate(cell11); assertTrue("Wrong result type: " + cv.formatAsString(), - cv.getCellType() == CellType.ERROR + cv.getCellTypeEnum() == CellType.ERROR && cv.getErrorValue() == FormulaError.VALUE.getCode()); } } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java index ea5ac9c7a..99d370bd6 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java @@ -185,7 +185,7 @@ public final class TestIndirect { fe.clearAllCachedResultValues(); cell.setCellFormula(formula); CellValue cv = fe.evaluate(cell); - if (cv.getCellType() != CellType.NUMERIC) { + if (cv.getCellTypeEnum() != CellType.NUMERIC) { fail("expected numeric cell type but got " + cv.formatAsString()); } assertEquals(expectedResult, cv.getNumberValue(), 0.0); @@ -196,7 +196,7 @@ public final class TestIndirect { fe.clearAllCachedResultValues(); cell.setCellFormula(formula); CellValue cv = fe.evaluate(cell); - if (cv.getCellType() != CellType.ERROR) { + if (cv.getCellTypeEnum() != CellType.ERROR) { fail("expected error cell type but got " + cv.formatAsString()); } int expCode = expectedResult.getErrorCode(); diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java index 2fb108ead..40fac0dea 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java @@ -128,7 +128,7 @@ public final class TestIrr extends TestCase { private static void assertFormulaResult(CellValue cv, HSSFCell cell){ double actualValue = cv.getNumberValue(); double expectedValue = cell.getNumericCellValue(); // cached formula result calculated by Excel - assertEquals("Invalid formula result: " + cv.toString(), CellType.NUMERIC, cv.getCellType()); + assertEquals("Invalid formula result: " + cv.toString(), CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(expectedValue, actualValue, 1E-4); // should agree within 0.01% } } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIsBlank.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIsBlank.java index 51b80876e..e723711cc 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestIsBlank.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIsBlank.java @@ -47,13 +47,13 @@ public final class TestIsBlank extends TestCase { HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); CellValue result = fe.evaluate(cell); - assertEquals(CellType.BOOLEAN, result.getCellType()); + assertEquals(CellType.BOOLEAN, result.getCellTypeEnum()); assertEquals(true, result.getBooleanValue()); cell.setCellFormula("isblank(D7:D7)"); result = fe.evaluate(cell); - assertEquals(CellType.BOOLEAN, result.getCellType()); + assertEquals(CellType.BOOLEAN, result.getCellTypeEnum()); assertEquals(true, result.getBooleanValue()); } } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java b/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java index fc4c3c927..6a925511f 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java @@ -162,7 +162,7 @@ public final class TestMirr extends TestCase { private static void assertFormulaResult(CellValue cv, HSSFCell cell) { double actualValue = cv.getNumberValue(); double expectedValue = cell.getNumericCellValue(); // cached formula result calculated by Excel - assertEquals("Invalid formula result: " + cv.toString(), CellType.NUMERIC, cv.getCellType()); + assertEquals("Invalid formula result: " + cv.toString(), CellType.NUMERIC, cv.getCellTypeEnum()); assertEquals(expectedValue, actualValue, 1E-8); } } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java index bdd09bfd6..f9725ba8a 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java @@ -1133,8 +1133,8 @@ public abstract class BaseTestBugzillaIssues { cfs.setCellFormula("B1"); FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); - assertEquals(CellType.NUMERIC, fe.evaluate(cfn).getCellType()); - assertEquals(CellType.STRING, fe.evaluate(cfs).getCellType()); + assertEquals(CellType.NUMERIC, fe.evaluate(cfn).getCellTypeEnum()); + assertEquals(CellType.STRING, fe.evaluate(cfs).getCellTypeEnum()); fe.evaluateFormulaCellEnum(cfn); fe.evaluateFormulaCellEnum(cfs); From 0977e51818d0e0ba6b6788232684886f0a8d5e58 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 02:41:01 +0000 Subject: [PATCH 04/43] bug 59907: restore ClientAnchor#setAnchorType(int) that was removed in POI 3.14 beta 1 and broke backwards compatibility without a 2 release deprecation notice git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760617 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/usermodel/HSSFClientAnchor.java | 10 ++++++++++ .../org/apache/poi/ss/usermodel/ClientAnchor.java | 8 ++++++++ .../apache/poi/xssf/usermodel/XSSFClientAnchor.java | 12 ++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java b/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java index 4b8a25e30..e71e362b8 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java @@ -250,6 +250,7 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor { /** * Gets the anchor type + * Changed from returning an int to an enum in POI 3.14 beta 1. * @return the anchor type */ @Override @@ -260,11 +261,20 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor { /** * Sets the anchor type * @param anchorType the anchor type to set + * @since POI 3.14 */ @Override public void setAnchorType(AnchorType anchorType) { _escherClientAnchor.setFlag(anchorType.value); } + /** + * Sets the anchor type + * @param anchorType the anchor type to set + * @deprecated POI 3.15. Use {@link #setAnchorType(AnchorType)} instead. + */ + public void setAnchorType(int anchorType) { + _escherClientAnchor.setFlag((short) anchorType); + } private void checkRange(int value, int minRange, int maxRange, String varName) { if (value < minRange || value > maxRange) diff --git a/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java b/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java index 672c1e230..65e69d87d 100644 --- a/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java +++ b/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java @@ -288,11 +288,19 @@ public interface ClientAnchor { /** * Sets the anchor type * @param anchorType the anchor type to set + * @since POI 3.14 */ public void setAnchorType( AnchorType anchorType ); + /** + * Sets the anchor type + * @param anchorType the anchor type to set + * @deprecated POI 3.15. Use {@link #setAnchorType(AnchorType)} instead. + */ + public void setAnchorType( int anchorType ); /** * Gets the anchor type + * Changed from returning an int to an enum in POI 3.14 beta 1. * @return the anchor type */ public AnchorType getAnchorType(); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java index 8045912ab..19d7d8109 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java @@ -218,15 +218,27 @@ public final class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { /** * Sets the anchor type * @param anchorType the anchor type to set + * @since POI 3.14 */ @Override public void setAnchorType( AnchorType anchorType ) { this.anchorType = anchorType; } + /** + * Sets the anchor type + * @param anchorType the anchor type to set + * @deprecated POI 3.15. Use {@link #setAnchorType(AnchorType)} instead + */ + @Override + public void setAnchorType( int anchorType ) + { + this.anchorType = AnchorType.byId(anchorType); + } /** * Gets the anchor type + * Changed from returning an int to an enum in POI 3.14 beta 1. * @return the anchor type */ @Override From 9ea59153136522e4af3faef3e48dcc053130b655 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 02:55:52 +0000 Subject: [PATCH 05/43] bug 59907: add @Removal annotations to deprecated ClientAnchor#setAnchorType(int) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760619 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java | 3 +++ src/java/org/apache/poi/ss/usermodel/ClientAnchor.java | 2 ++ .../java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java | 2 ++ 3 files changed, 7 insertions(+) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java b/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java index e71e362b8..d4c8c6d68 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java @@ -21,6 +21,7 @@ import org.apache.poi.ddf.EscherClientAnchorRecord; import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.usermodel.ClientAnchor; +import org.apache.poi.util.Removal; /** * A client anchor is attached to an excel worksheet. It anchors against a @@ -272,6 +273,8 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor { * @param anchorType the anchor type to set * @deprecated POI 3.15. Use {@link #setAnchorType(AnchorType)} instead. */ + @Removal(version="3.17") + @Override public void setAnchorType(int anchorType) { _escherClientAnchor.setFlag((short) anchorType); } diff --git a/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java b/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java index 65e69d87d..705c53bba 100644 --- a/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java +++ b/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java @@ -17,6 +17,7 @@ package org.apache.poi.ss.usermodel; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; /** * A client anchor is attached to an excel worksheet. It anchors against a @@ -296,6 +297,7 @@ public interface ClientAnchor { * @param anchorType the anchor type to set * @deprecated POI 3.15. Use {@link #setAnchorType(AnchorType)} instead. */ + @Removal(version="3.17") public void setAnchorType( int anchorType ); /** diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java index 19d7d8109..df47fc227 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java @@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel; import org.apache.poi.ss.usermodel.ClientAnchor; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker; /** @@ -230,6 +231,7 @@ public final class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { * @param anchorType the anchor type to set * @deprecated POI 3.15. Use {@link #setAnchorType(AnchorType)} instead */ + @Removal(version="3.17") @Override public void setAnchorType( int anchorType ) { From b91b5c57155f21e5b17c8ac4eb91bcd08ec13027 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 03:06:51 +0000 Subject: [PATCH 06/43] bug 59907: add @Removal annotations to AnchorType static aliases in ClientAnchor git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760620 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/ss/usermodel/ClientAnchor.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java b/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java index 705c53bba..702970c69 100644 --- a/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java +++ b/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java @@ -36,6 +36,7 @@ public interface ClientAnchor { *

* @deprecated since POI 3.14beta1 (circa 2015-11-24). Use {@link AnchorType#MOVE_AND_RESIZE} instead. */ + @Removal(version="3.17") public static final AnchorType MOVE_AND_RESIZE = AnchorType.MOVE_AND_RESIZE; /** @@ -51,6 +52,7 @@ public interface ClientAnchor { *

* @deprecated since POI 3.14beta1 (circa 2015-11-24). Use {@link AnchorType#MOVE_DONT_RESIZE} instead. */ + @Removal(version="3.17") public static final AnchorType MOVE_DONT_RESIZE = AnchorType.MOVE_DONT_RESIZE; /** @@ -67,6 +69,7 @@ public interface ClientAnchor { *

* @deprecated since POI 3.14beta1 (circa 2015-11-24). Use {@link AnchorType#DONT_MOVE_AND_RESIZE} instead. */ + @Removal(version="3.17") public static final AnchorType DONT_MOVE_AND_RESIZE = AnchorType.DONT_MOVE_AND_RESIZE; /** From 808996a68357c9905f22f4d2157c119db670b691 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 03:17:51 +0000 Subject: [PATCH 07/43] bug 59873: add @Removal annotations for deprecated CreationHelper#createHyperlink(int) and Hyperlink static aliases to HyperlinkType enum values git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760621 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/common/usermodel/Hyperlink.java | 7 +++++++ .../org/apache/poi/hssf/usermodel/HSSFCreationHelper.java | 2 ++ src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java | 2 ++ .../java/org/apache/poi/xslf/usermodel/XSLFHyperlink.java | 4 ++++ .../org/apache/poi/xssf/streaming/SXSSFCreationHelper.java | 2 ++ .../org/apache/poi/xssf/usermodel/XSSFCreationHelper.java | 2 ++ .../java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java | 1 + 7 files changed, 20 insertions(+) diff --git a/src/java/org/apache/poi/common/usermodel/Hyperlink.java b/src/java/org/apache/poi/common/usermodel/Hyperlink.java index 132a3eb4c..abcdd112a 100644 --- a/src/java/org/apache/poi/common/usermodel/Hyperlink.java +++ b/src/java/org/apache/poi/common/usermodel/Hyperlink.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.common.usermodel; +import org.apache.poi.util.Removal; + /** * Represents a hyperlink. */ @@ -25,6 +27,7 @@ public interface Hyperlink { * * @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#URL} instead. */ + @Removal(version="3.17") public static final int LINK_URL = 1; // HyperlinkType.URL.getCode() /** @@ -32,6 +35,7 @@ public interface Hyperlink { * * @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#DOCUMENT} instead. */ + @Removal(version="3.17") public static final int LINK_DOCUMENT = 2; // HyperlinkType.DOCUMENT.getCode() /** @@ -39,6 +43,7 @@ public interface Hyperlink { * * @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#EMAIL} instead. */ + @Removal(version="3.17") public static final int LINK_EMAIL = 3; // HyperlinkType.EMAIL.getCode() /** @@ -46,6 +51,7 @@ public interface Hyperlink { * * @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#FILE} instead. */ + @Removal(version="3.17") public static final int LINK_FILE = 4; // HyperlinkType.FILE.getCode() @@ -83,6 +89,7 @@ public interface Hyperlink { * @return the type of this hyperlink * @see HyperlinkType#forInt(int) * @deprecated POI 3.15 beta 3. Use {@link #getTypeEnum()} + * getType will return a HyperlinkType enum in the future. */ public int getType(); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java index 7ce7ef1be..863d1a004 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java @@ -21,6 +21,7 @@ import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.hssf.record.common.ExtendedColor; import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; public class HSSFCreationHelper implements CreationHelper { private final HSSFWorkbook workbook; @@ -50,6 +51,7 @@ public class HSSFCreationHelper implements CreationHelper { * @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead. */ @Deprecated + @Removal(version="3.17") @Override public HSSFHyperlink createHyperlink(int type) { return new HSSFHyperlink(type); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java b/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java index 1847bfc0f..084a6bfe0 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java @@ -273,6 +273,8 @@ public class HSSFHyperlink implements Hyperlink { * * @return the type of this hyperlink * @see HyperlinkType#forInt + * @deprecated POI 3.15. Use {@link #getTypeEnum()} instead. + * getType will return a HyperlinkType enum in the future. */ @Override public int getType() { diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFHyperlink.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFHyperlink.java index 09b883c00..2f300623f 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFHyperlink.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFHyperlink.java @@ -69,6 +69,10 @@ public class XSLFHyperlink implements Hyperlink { _link.setTooltip(label); } + /* (non-Javadoc) + * @deprecated POI 3.15. Use {@link #getTypeEnum()} instead. + * Will return a HyperlinkType enum in the future + */ @Override public int getType() { return getTypeEnum().getCode(); diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java index 201879702..f2687ff1d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java @@ -26,6 +26,7 @@ import org.apache.poi.ss.usermodel.Hyperlink; import org.apache.poi.util.Internal; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; +import org.apache.poi.util.Removal; import org.apache.poi.xssf.usermodel.XSSFCreationHelper; import org.apache.poi.xssf.usermodel.XSSFRichTextString; @@ -72,6 +73,7 @@ public class SXSSFCreationHelper implements CreationHelper { * @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead. */ @Deprecated + @Removal(version="3.17") @Override public Hyperlink createHyperlink(int type) { return helper.createHyperlink(type); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java index 63dc78069..cb11a73b2 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java @@ -20,6 +20,7 @@ import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.ss.usermodel.Hyperlink; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; public class XSSFCreationHelper implements CreationHelper { private final XSSFWorkbook workbook; @@ -61,6 +62,7 @@ public class XSSFCreationHelper implements CreationHelper { * @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead. */ @Deprecated + @Removal(version="3.17") @Override public XSSFHyperlink createHyperlink(int type) { return new XSSFHyperlink(type); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java index 1f1c8421f..9d26a6658 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java @@ -168,6 +168,7 @@ public class XSSFHyperlink implements Hyperlink { * @return the type of this hyperlink * @see HyperlinkType#forInt * @deprecated POI 3.15 beta 3. Use {@link #getTypeEnum()} instead. + * getType will return a HyperlinkType enum in the future. */ @Override public int getType() { From 6839a52aa382ff2f57cc6dc6e245fab14475f69f Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 03:24:15 +0000 Subject: [PATCH 08/43] bug 59837,59833,59264: add @Removal annotations to CellStyle constants for which enums now exist git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760622 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/ss/usermodel/CellStyle.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/java/org/apache/poi/ss/usermodel/CellStyle.java b/src/java/org/apache/poi/ss/usermodel/CellStyle.java index b6c971979..17a5d0e75 100644 --- a/src/java/org/apache/poi/ss/usermodel/CellStyle.java +++ b/src/java/org/apache/poi/ss/usermodel/CellStyle.java @@ -17,270 +17,316 @@ package org.apache.poi.ss.usermodel; +import org.apache.poi.util.Removal; + public interface CellStyle { /** * general (normal) horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#GENERAL} instead. */ + @Removal(version="3.17") static final short ALIGN_GENERAL = 0x0; //HorizontalAlignment.GENERAL.getCode(); /** * left-justified horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#LEFT} instead. */ + @Removal(version="3.17") static final short ALIGN_LEFT = 0x1; //HorizontalAlignment.LEFT.getCode(); /** * center horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#CENTER} instead. */ + @Removal(version="3.17") static final short ALIGN_CENTER = 0x2; //HorizontalAlignment.CENTER.getCode(); /** * right-justified horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#RIGHT} instead. */ + @Removal(version="3.17") static final short ALIGN_RIGHT = 0x3; //HorizontalAlignment.RIGHT.getCode(); /** * fill? horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#FILL} instead. */ + @Removal(version="3.17") static final short ALIGN_FILL = 0x4; //HorizontalAlignment.FILL.getCode(); /** * justified horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#JUSTIFY} instead. */ + @Removal(version="3.17") static final short ALIGN_JUSTIFY = 0x5; //HorizontalAlignment.JUSTIFY.getCode(); /** * center-selection? horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#CENTER_SELECTION} instead. */ + @Removal(version="3.17") static final short ALIGN_CENTER_SELECTION = 0x6; //HorizontalAlignment.CENTER_SELECTION.getCode(); /** * top-aligned vertical alignment * @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#TOP} instead. */ + @Removal(version="3.17") static final short VERTICAL_TOP = 0x0; //VerticalAlignment.TOP.getCode(); /** * center-aligned vertical alignment * @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#CENTER} instead. */ + @Removal(version="3.17") static final short VERTICAL_CENTER = 0x1; //VerticalAlignment.CENTER.getCode(); /** * bottom-aligned vertical alignment * @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#BOTTOM} instead. */ + @Removal(version="3.17") static final short VERTICAL_BOTTOM = 0x2; //VerticalAlignment.BOTTOM.getCode(); /** * vertically justified vertical alignment * @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#JUSTIFY} instead. */ + @Removal(version="3.17") static final short VERTICAL_JUSTIFY = 0x3; //VerticalAlignment.JUSTIFY.getCode(); /** * No border * @deprecated 3.15 beta 2. Use {@link BorderStyle#NONE} instead. */ + @Removal(version="3.17") static final short BORDER_NONE = 0x0; //BorderStyle.NONE.getCode(); /** * Thin border * @deprecated 3.15 beta 2. Use {@link BorderStyle#THIN} instead. */ + @Removal(version="3.17") static final short BORDER_THIN = 0x1; //BorderStyle.THIN.getCode(); /** * Medium border * @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM} instead. */ + @Removal(version="3.17") static final short BORDER_MEDIUM = 0x2; //BorderStyle.MEDIUM.getCode(); /** * dash border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DASHED} instead. */ + @Removal(version="3.17") static final short BORDER_DASHED = 0x3; //BorderStyle.DASHED.getCode(); /** * dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DOTTED} instead. */ + @Removal(version="3.17") static final short BORDER_DOTTED = 0x4; //BorderStyle.DOTTED.getCode(); /** * Thick border * @deprecated 3.15 beta 2. Use {@link BorderStyle#THICK} instead. */ + @Removal(version="3.17") static final short BORDER_THICK = 0x5; //BorderStyle.THICK.getCode(); /** * double-line border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DOUBLE} instead. */ + @Removal(version="3.17") static final short BORDER_DOUBLE = 0x6; //BorderStyle.DOUBLE.getCode(); /** * hair-line border * @deprecated 3.15 beta 2. Use {@link BorderStyle#HAIR} instead. */ + @Removal(version="3.17") static final short BORDER_HAIR = 0x7; //BorderStyle.HAIR.getCode(); /** * Medium dashed border * @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASHED} instead. */ + @Removal(version="3.17") static final short BORDER_MEDIUM_DASHED = 0x8; //BorderStyle.MEDIUM_DASHED.getCode(); /** * dash-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT} instead. */ + @Removal(version="3.17") static final short BORDER_DASH_DOT = 0x9; //BorderStyle.DASH_DOT.getCode(); /** * medium dash-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT} instead. */ + @Removal(version="3.17") static final short BORDER_MEDIUM_DASH_DOT = 0xA; //BorderStyle.MEDIUM_DASH_DOT.getCode(); /** * dash-dot-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT_DOT} instead. */ + @Removal(version="3.17") static final short BORDER_DASH_DOT_DOT = 0xB; //BorderStyle.DASH_DOT_DOT.getCode(); /** * medium dash-dot-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT_DOT} instead. */ + @Removal(version="3.17") static final short BORDER_MEDIUM_DASH_DOT_DOT = 0xC; //BorderStyle.MEDIUM_DASH_DOT_DOT.getCode(); /** * slanted dash-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#SLANTED_DASH_DOT} instead. */ + @Removal(version="3.17") static final short BORDER_SLANTED_DASH_DOT = 0xD; //BorderStyle.SLANTED_DASH_DOT.getCode(); /** * Fill Pattern: No background * @deprecated 3.15 beta 3. Use {@link FillPatternType#NO_FILL} instead. */ + @Removal(version="3.17") static final short NO_FILL = 0; //FillPatternType.NO_FILL.getCode(); /** * Fill Pattern: Solidly filled * @deprecated 3.15 beta 3. Use {@link FillPatternType#SOLID_FOREGROUND} instead. */ + @Removal(version="3.17") static final short SOLID_FOREGROUND = 1; //FillPatternType.SOLID_FOREGROUND.getCode(); /** * Fill Pattern: Small fine dots * @deprecated 3.15 beta 3. Use {@link FillPatternType#FINE_DOTS} instead. */ + @Removal(version="3.17") static final short FINE_DOTS = 2; //FillPatternType.FINE_DOTS.getCode(); /** * Fill Pattern: Wide dots * @deprecated 3.15 beta 3. Use {@link FillPatternType#ALT_BARS} instead. */ + @Removal(version="3.17") static final short ALT_BARS = 3; //FillPatternType.ALT_BARS.getCode(); /** * Fill Pattern: Sparse dots * @deprecated 3.15 beta 3. Use {@link FillPatternType#SPARSE_DOTS} instead. */ + @Removal(version="3.17") static final short SPARSE_DOTS = 4; //FillPatternType.SPARSE_DOTS.getCode(); /** * Fill Pattern: Thick horizontal bands * @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_HORZ_BANDS} instead. */ + @Removal(version="3.17") static final short THICK_HORZ_BANDS = 5; //FillPatternType.THICK_HORZ_BANDS.getCode(); /** * Fill Pattern: Thick vertical bands * @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_VERT_BANDS} instead. */ + @Removal(version="3.17") static final short THICK_VERT_BANDS = 6; //FillPatternType.THICK_VERT_BANDS.getCode(); /** * Fill Pattern: Thick backward facing diagonals * @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_BACKWARD_DIAG} instead. */ + @Removal(version="3.17") static final short THICK_BACKWARD_DIAG = 7; //FillPatternType.THICK_BACKWARD_DIAG.getCode(); /** * Fill Pattern: Thick forward facing diagonals * @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_FORWARD_DIAG} instead. */ + @Removal(version="3.17") static final short THICK_FORWARD_DIAG = 8; //FillPatternType.THICK_FORWARD_DIAG.getCode(); /** * Fill Pattern: Large spots * @deprecated 3.15 beta 3. Use {@link FillPatternType#BIG_SPOTS} instead. */ + @Removal(version="3.17") static final short BIG_SPOTS = 9; //FillPatternType.BIG_SPOTS.getCode(); /** * Fill Pattern: Brick-like layout * @deprecated 3.15 beta 3. Use {@link FillPatternType#BRICKS} instead. */ + @Removal(version="3.17") static final short BRICKS = 10; //FillPatternType.BRICKS.getCode(); /** * Fill Pattern: Thin horizontal bands * @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_HORZ_BANDS} instead. */ + @Removal(version="3.17") static final short THIN_HORZ_BANDS = 11; //FillPatternType.THIN_HORZ_BANDS.getCode(); /** * Fill Pattern: Thin vertical bands * @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_VERT_BANDS} instead. */ + @Removal(version="3.17") static final short THIN_VERT_BANDS = 12; //FillPatternType.THIN_VERT_BANDS.getCode(); /** * Fill Pattern: Thin backward diagonal * @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_BACKWARD_DIAG} instead. */ + @Removal(version="3.17") static final short THIN_BACKWARD_DIAG = 13; //FillPatternType.THIN_BACKWARD_DIAG.getCode(); /** * Fill Pattern: Thin forward diagonal * @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_FORWARD_DIAG} instead. */ + @Removal(version="3.17") static final short THIN_FORWARD_DIAG = 14; //FillPatternType.THIN_FORWARD_DIAG.getCode(); /** * Fill Pattern: Squares * @deprecated 3.15 beta 3. Use {@link FillPatternType#SQUARES} instead. */ + @Removal(version="3.17") static final short SQUARES = 15; //FillPatternType.SQUARES.getCode(); /** * Fill Pattern: Diamonds * @deprecated 3.15 beta 3. Use {@link FillPatternType#DIAMONDS} instead. */ + @Removal(version="3.17") static final short DIAMONDS = 16; //FillPatternType.DIAMONDS.getCode(); /** * Fill Pattern: Less Dots * @deprecated 3.15 beta 3. Use {@link FillPatternType#LESS_DOTS} instead. */ + @Removal(version="3.17") static final short LESS_DOTS = 17; //FillPatternType.LESS_DOTS.getCode(); /** * Fill Pattern: Least Dots * @deprecated 3.15 beta 3. Use {@link FillPatternType#LEAST_DOTS} instead. */ + @Removal(version="3.17") static final short LEAST_DOTS = 18; //FillPatternType.LEAST_DOTS.getCode(); /** From 5d1ae2cbae7b9445b8735e4871aee45a3c02e051 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 03:33:52 +0000 Subject: [PATCH 09/43] bug 59833: add @Removal annotation to deprecated methods git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760623 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java | 2 ++ .../java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java index 6e6c05504..4fbbdf62e 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java @@ -32,6 +32,7 @@ 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.VerticalAlignment; +import org.apache.poi.util.Removal; /** * High level representation of the style of a cell in a sheet of a workbook. @@ -254,6 +255,7 @@ public final class HSSFCellStyle implements CellStyle { * @see #ALIGN_CENTER_SELECTION * @deprecated POI 3.15 beta 3. Use {@link #setAlignment(HorizontalAlignment)} instead. */ + @Removal(version="3.17") @Override public void setAlignment(short align) { diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java index 760c21537..1e7dc5040 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java @@ -28,6 +28,7 @@ import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.VerticalAlignment; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; import org.apache.poi.xssf.model.StylesTable; import org.apache.poi.xssf.model.ThemesTable; import org.apache.poi.xssf.usermodel.extensions.XSSFCellAlignment; @@ -1121,7 +1122,9 @@ public class XSSFCellStyle implements CellStyle { * @see #setFillBackgroundColor(short) * @see #setFillForegroundColor(short) * @param fp fill pattern (set to {@link org.apache.poi.ss.usermodel.CellStyle#SOLID_FOREGROUND} to fill w/foreground color) + * @deprecated POI 3.15. Use {@link #setFillPattern(FillPatternType)} instead. */ + @Removal(version="3.17") @Override public void setFillPattern(short fp) { setFillPattern(FillPatternType.forInt(fp)); From 2644cae41839fc4c9554e54a63a9e4588e645e3a Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 03:51:45 +0000 Subject: [PATCH 10/43] bug 59790: add @Removal annotations to deprecated methods git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760624 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/hssf/model/HSSFFormulaParser.java | 7 +++++-- .../apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java | 1 + .../org/apache/poi/ss/formula/OperandClassTransformer.java | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/java/org/apache/poi/hssf/model/HSSFFormulaParser.java b/src/java/org/apache/poi/hssf/model/HSSFFormulaParser.java index b54b27ad4..774eb788f 100644 --- a/src/java/org/apache/poi/hssf/model/HSSFFormulaParser.java +++ b/src/java/org/apache/poi/hssf/model/HSSFFormulaParser.java @@ -17,8 +17,6 @@ package org.apache.poi.hssf.model; -import org.apache.poi.ss.formula.ptg.Ptg; -import org.apache.poi.util.Internal; import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.formula.FormulaParseException; @@ -26,6 +24,9 @@ import org.apache.poi.ss.formula.FormulaParser; import org.apache.poi.ss.formula.FormulaParsingWorkbook; import org.apache.poi.ss.formula.FormulaRenderer; import org.apache.poi.ss.formula.FormulaType; +import org.apache.poi.ss.formula.ptg.Ptg; +import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; /** * HSSF wrapper for the {@link FormulaParser} and {@link FormulaRenderer} @@ -61,6 +62,7 @@ public final class HSSFFormulaParser { * * @deprecated POI 3.15 beta 3. Use {@link #parse(String, HSSFWorkbook, FormulaType)} instead. */ + @Removal(version="3.17") public static Ptg[] parse(String formula, HSSFWorkbook workbook, int formulaType) throws FormulaParseException { return parse(formula, workbook, FormulaType.forInt(formulaType)); } @@ -87,6 +89,7 @@ public final class HSSFFormulaParser { * @throws FormulaParseException if the formula has incorrect syntax or is otherwise invalid * @deprecated POI 3.15 beta 3. Use {@link #parse(String, HSSFWorkbook, FormulaType, int)} instead. */ + @Removal(version="3.17") public static Ptg[] parse(String formula, HSSFWorkbook workbook, int formulaType, int sheetIndex) throws FormulaParseException { return parse(formula, workbook, FormulaType.forInt(formulaType), sheetIndex); } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java index a0a932d07..b43228740 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java @@ -35,6 +35,7 @@ import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; /** * Evaluates formula cells.

diff --git a/src/java/org/apache/poi/ss/formula/OperandClassTransformer.java b/src/java/org/apache/poi/ss/formula/OperandClassTransformer.java index a45d5a2d1..8e438c966 100644 --- a/src/java/org/apache/poi/ss/formula/OperandClassTransformer.java +++ b/src/java/org/apache/poi/ss/formula/OperandClassTransformer.java @@ -28,6 +28,7 @@ import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.RangePtg; import org.apache.poi.ss.formula.ptg.UnionPtg; import org.apache.poi.ss.formula.ptg.ValueOperatorPtg; +import org.apache.poi.util.Removal; /** * This class performs 'operand class' transformation. Non-base tokens are classified into three @@ -59,7 +60,10 @@ final class OperandClassTransformer { private final FormulaType _formulaType; - /** @deprecated POI 3.15 beta 3. */ + /** + * @deprecated POI 3.15 beta 3. Use {@code OperandClassTransformer(FormulaType)} instead. + */ + @Removal(version="3.17") public OperandClassTransformer(int formulaType) { this(FormulaType.forInt(formulaType)); } From 292d7ec27c9a91c45aeec8387e7fd9f249d1b1e2 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 04:35:45 +0000 Subject: [PATCH 11/43] bug 59264: revert getBorder[Top|Bottom|Left|Right|Diagonal]() to return short and add getBorder[Top|Bottom|Left|Right|Diagonal]Enum() returns BorderStyle enum for backwards compatibility with POI 3.14 and earlier git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760627 13f79535-47bb-0310-9956-ffa450edef68 --- .../hssf/usermodel/HSSFBorderFormatting.java | 65 +++++++++++++++++-- .../poi/ss/usermodel/BorderFormatting.java | 58 +++++++++++++++-- .../xssf/usermodel/XSSFBorderFormatting.java | 65 +++++++++++++++++-- .../apache/poi/hssf/usermodel/TestBugs.java | 4 +- .../BaseTestConditionalFormatting.java | 58 ++++++++--------- 5 files changed, 203 insertions(+), 47 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java b/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java index d06c9f179..c4113b615 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java @@ -42,28 +42,83 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B return borderFormatting; } + /** + * @deprecated POI 3.15. Use {@link #getBorderBottomEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderBottom() { + public short getBorderBottom() { + return (short)borderFormatting.getBorderBottom(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderBottomEnum() { return BorderStyle.valueOf((short)borderFormatting.getBorderBottom()); } + /** + * @deprecated POI 3.15. Use {@link #getBorderDiagonalEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderDiagonal() { + public short getBorderDiagonal() { + return (short)borderFormatting.getBorderDiagonal(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderDiagonalEnum() { return BorderStyle.valueOf((short)borderFormatting.getBorderDiagonal()); } + /** + * @deprecated POI 3.15. Use {@link #getBorderLeftEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderLeft() { + public short getBorderLeft() { + return (short)borderFormatting.getBorderLeft(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderLeftEnum() { return BorderStyle.valueOf((short)borderFormatting.getBorderLeft()); } + /** + * @deprecated POI 3.15. Use {@link #getBorderRightEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderRight() { + public short getBorderRight() { + return (short)borderFormatting.getBorderRight(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderRightEnum() { return BorderStyle.valueOf((short)borderFormatting.getBorderRight()); } + /** + * @deprecated POI 3.15. Use {@link #getBorderTopEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderTop() { + public short getBorderTop() { + return (short)borderFormatting.getBorderTop(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderTopEnum() { return BorderStyle.valueOf((short)borderFormatting.getBorderTop()); } diff --git a/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java b/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java index 059cdd065..949cc3d00 100644 --- a/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java +++ b/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java @@ -19,6 +19,8 @@ package org.apache.poi.ss.usermodel; +import org.apache.poi.util.Removal; + /** * High level representation for Border Formatting component * of Conditional Formatting settings @@ -27,84 +29,128 @@ public interface BorderFormatting { /** No border * @deprecated 3.15 beta 2. Use {@link BorderStyle#NONE} */ + @Removal(version="3.17") short BORDER_NONE = 0x0; /** Thin border * @deprecated 3.15 beta 2. Use {@link BorderStyle#THIN} */ + @Removal(version="3.17") short BORDER_THIN = 0x1; /** Medium border * @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM} */ + @Removal(version="3.17") short BORDER_MEDIUM = 0x2; /** dash border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DASHED} */ + @Removal(version="3.17") short BORDER_DASHED = 0x3; /** dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DOTTED} */ + @Removal(version="3.17") short BORDER_DOTTED = 0x4; /** Thick border * @deprecated 3.15 beta 2. Use {@link BorderStyle#THICK} */ + @Removal(version="3.17") short BORDER_THICK = 0x5; /** double-line border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DOUBLE} */ + @Removal(version="3.17") short BORDER_DOUBLE = 0x6; /** hair-line border * @deprecated 3.15 beta 2. Use {@link BorderStyle#HAIR} */ + @Removal(version="3.17") short BORDER_HAIR = 0x7; /** Medium dashed border * @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASHED} */ + @Removal(version="3.17") short BORDER_MEDIUM_DASHED = 0x8; - /** dash-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT} */ + @Removal(version="3.17") short BORDER_DASH_DOT = 0x9; /** medium dash-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT} */ + @Removal(version="3.17") short BORDER_MEDIUM_DASH_DOT = 0xA; /** dash-dot-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT_DOT} */ + @Removal(version="3.17") short BORDER_DASH_DOT_DOT = 0xB; /** medium dash-dot-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT_DOT} */ + @Removal(version="3.17") short BORDER_MEDIUM_DASH_DOT_DOT = 0xC; /** slanted dash-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#SLANTED_DASH_DOT} */ + @Removal(version="3.17") short BORDER_SLANTED_DASH_DOT = 0xD; - BorderStyle getBorderBottom(); + /** + * @deprecated POI 3.15. Use {@link #getBorderBottomEnum()}. + * This method will return an BorderStyle enum in the future. + */ + short getBorderBottom(); + /** @since POI 3.15 */ + BorderStyle getBorderBottomEnum(); - BorderStyle getBorderDiagonal(); + /** + * @deprecated POI 3.15. Use {@link #getBorderDiagonalEnum()}. + * This method will return an BorderStyle enum in the future. + */ + short getBorderDiagonal(); + /** @since POI 3.15 */ + BorderStyle getBorderDiagonalEnum(); - BorderStyle getBorderLeft(); + /** + * @deprecated POI 3.15. Use {@link #getBorderLeftEnum()}. + * This method will return an BorderStyle enum in the future. + */ + short getBorderLeft(); + /** @since POI 3.15 */ + BorderStyle getBorderLeftEnum(); - BorderStyle getBorderRight(); + /** + * @deprecated POI 3.15. Use {@link #getBorderRightEnum()}. + * This method will return an BorderStyle enum in the future. + */ + short getBorderRight(); + /** @since POI 3.15 */ + BorderStyle getBorderRightEnum(); - BorderStyle getBorderTop(); + /** + * @deprecated POI 3.15. Use {@link #getBorderTopEnum()}. + * This method will return an BorderStyle enum in the future. + */ + short getBorderTop(); + /** @since POI 3.15 */ + BorderStyle getBorderTopEnum(); + short getBottomBorderColor(); Color getBottomBorderColorColor(); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java index e48fe948e..edea8cda9 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java @@ -35,32 +35,87 @@ public class XSSFBorderFormatting implements BorderFormatting { _border = border; } + /** + * @deprecated POI 3.15. Use {@link #getBorderBottomEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderBottom() { + public short getBorderBottom() { + return getBorderBottomEnum().getCode(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderBottomEnum() { STBorderStyle.Enum ptrn = _border.isSetBottom() ? _border.getBottom().getStyle() : null; return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1)); } + /** + * @deprecated POI 3.15. Use {@link #getBorderDiagonalEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderDiagonal() { + public short getBorderDiagonal() { + return getBorderDiagonalEnum().getCode(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderDiagonalEnum() { STBorderStyle.Enum ptrn = _border.isSetDiagonal() ? _border.getDiagonal().getStyle() : null; return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1)); } + /** + * @deprecated POI 3.15. Use {@link #getBorderLeftEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderLeft() { + public short getBorderLeft() { + return getBorderLeftEnum().getCode(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderLeftEnum() { STBorderStyle.Enum ptrn = _border.isSetLeft() ? _border.getLeft().getStyle() : null; return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1)); } + /** + * @deprecated POI 3.15. Use {@link #getBorderRightEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderRight() { + public short getBorderRight() { + return getBorderRightEnum().getCode(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderRightEnum() { STBorderStyle.Enum ptrn = _border.isSetRight() ? _border.getRight().getStyle() : null; return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1)); } + /** + * @deprecated POI 3.15. Use {@link #getBorderTopEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderTop() { + public short getBorderTop() { + return getBorderTopEnum().getCode(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderTopEnum() { STBorderStyle.Enum ptrn = _border.isSetTop() ? _border.getTop().getStyle() : null; return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1)); } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 466964acf..dca98f620 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -3051,7 +3051,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFBorderFormatting bord = rule.createBorderFormatting(); bord.setBorderDiagonal(BorderStyle.THICK); - assertEquals(BorderStyle.THICK, bord.getBorderDiagonal()); + assertEquals(BorderStyle.THICK, bord.getBorderDiagonalEnum()); bord.setBackwardDiagonalOn(true); assertTrue(bord.isBackwardDiagonalOn()); @@ -3064,7 +3064,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { // Create the bottom border style so we know what a border is supposed to look like bord.setBorderBottom(BorderStyle.THICK); - assertEquals(BorderStyle.THICK, bord.getBorderBottom()); + assertEquals(BorderStyle.THICK, bord.getBorderBottomEnum()); bord.setBottomBorderColor(BLUE); assertEquals(BLUE, bord.getBottomBorderColor()); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java index 5509cbf71..28cfb2cf7 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java @@ -363,10 +363,10 @@ public abstract class BaseTestConditionalFormatting { BorderFormatting r1bf = rule1.getBorderFormatting(); assertNotNull(r1bf); - assertEquals(BorderStyle.THIN, r1bf.getBorderBottom()); - assertEquals(BorderStyle.THICK,r1bf.getBorderTop()); - assertEquals(BorderStyle.DASHED,r1bf.getBorderLeft()); - assertEquals(BorderStyle.DOTTED,r1bf.getBorderRight()); + assertEquals(BorderStyle.THIN, r1bf.getBorderBottomEnum()); + assertEquals(BorderStyle.THICK,r1bf.getBorderTopEnum()); + assertEquals(BorderStyle.DASHED,r1bf.getBorderLeftEnum()); + assertEquals(BorderStyle.DOTTED,r1bf.getBorderRightEnum()); PatternFormatting r1pf = rule1.getPatternFormatting(); assertNotNull(r1pf); @@ -1021,19 +1021,19 @@ public abstract class BaseTestConditionalFormatting { for (BorderStyle border : BorderStyle.values()) { borderFmt.setBorderTop(border); - assertEquals(border, borderFmt.getBorderTop()); + assertEquals(border, borderFmt.getBorderTopEnum()); borderFmt.setBorderBottom(border); - assertEquals(border, borderFmt.getBorderBottom()); + assertEquals(border, borderFmt.getBorderBottomEnum()); borderFmt.setBorderLeft(border); - assertEquals(border, borderFmt.getBorderLeft()); + assertEquals(border, borderFmt.getBorderLeftEnum()); borderFmt.setBorderRight(border); - assertEquals(border, borderFmt.getBorderRight()); + assertEquals(border, borderFmt.getBorderRightEnum()); borderFmt.setBorderDiagonal(border); - assertEquals(border, borderFmt.getBorderDiagonal()); + assertEquals(border, borderFmt.getBorderDiagonalEnum()); } workbook.close(); @@ -1049,37 +1049,37 @@ public abstract class BaseTestConditionalFormatting { ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "7"); BorderFormatting borderFmt = rule1.createBorderFormatting(); - assertEquals(BorderStyle.NONE, borderFmt.getBorderBottom()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderBottomEnum()); borderFmt.setBorderBottom(BorderStyle.DOTTED); - assertEquals(BorderStyle.DOTTED, borderFmt.getBorderBottom()); + assertEquals(BorderStyle.DOTTED, borderFmt.getBorderBottomEnum()); borderFmt.setBorderBottom(BorderStyle.NONE); - assertEquals(BorderStyle.NONE, borderFmt.getBorderBottom()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderBottomEnum()); borderFmt.setBorderBottom(BorderStyle.THICK); - assertEquals(BorderStyle.THICK, borderFmt.getBorderBottom()); + assertEquals(BorderStyle.THICK, borderFmt.getBorderBottomEnum()); - assertEquals(BorderStyle.NONE, borderFmt.getBorderTop()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderTopEnum()); borderFmt.setBorderTop(BorderStyle.DOTTED); - assertEquals(BorderStyle.DOTTED, borderFmt.getBorderTop()); + assertEquals(BorderStyle.DOTTED, borderFmt.getBorderTopEnum()); borderFmt.setBorderTop(BorderStyle.NONE); - assertEquals(BorderStyle.NONE, borderFmt.getBorderTop()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderTopEnum()); borderFmt.setBorderTop(BorderStyle.THICK); - assertEquals(BorderStyle.THICK, borderFmt.getBorderTop()); + assertEquals(BorderStyle.THICK, borderFmt.getBorderTopEnum()); - assertEquals(BorderStyle.NONE, borderFmt.getBorderLeft()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderLeftEnum()); borderFmt.setBorderLeft(BorderStyle.DOTTED); - assertEquals(BorderStyle.DOTTED, borderFmt.getBorderLeft()); + assertEquals(BorderStyle.DOTTED, borderFmt.getBorderLeftEnum()); borderFmt.setBorderLeft(BorderStyle.NONE); - assertEquals(BorderStyle.NONE, borderFmt.getBorderLeft()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderLeftEnum()); borderFmt.setBorderLeft(BorderStyle.THIN); - assertEquals(BorderStyle.THIN, borderFmt.getBorderLeft()); + assertEquals(BorderStyle.THIN, borderFmt.getBorderLeftEnum()); - assertEquals(BorderStyle.NONE, borderFmt.getBorderRight()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderRightEnum()); borderFmt.setBorderRight(BorderStyle.DOTTED); - assertEquals(BorderStyle.DOTTED, borderFmt.getBorderRight()); + assertEquals(BorderStyle.DOTTED, borderFmt.getBorderRightEnum()); borderFmt.setBorderRight(BorderStyle.NONE); - assertEquals(BorderStyle.NONE, borderFmt.getBorderRight()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderRightEnum()); borderFmt.setBorderRight(BorderStyle.HAIR); - assertEquals(BorderStyle.HAIR, borderFmt.getBorderRight()); + assertEquals(BorderStyle.HAIR, borderFmt.getBorderRightEnum()); ConditionalFormattingRule [] cfRules = { rule1 }; @@ -1095,10 +1095,10 @@ public abstract class BaseTestConditionalFormatting { BorderFormatting r1fp = cf.getRule(0).getBorderFormatting(); assertNotNull(r1fp); - assertEquals(BorderStyle.THICK, r1fp.getBorderBottom()); - assertEquals(BorderStyle.THICK, r1fp.getBorderTop()); - assertEquals(BorderStyle.THIN, r1fp.getBorderLeft()); - assertEquals(BorderStyle.HAIR, r1fp.getBorderRight()); + assertEquals(BorderStyle.THICK, r1fp.getBorderBottomEnum()); + assertEquals(BorderStyle.THICK, r1fp.getBorderTopEnum()); + assertEquals(BorderStyle.THIN, r1fp.getBorderLeftEnum()); + assertEquals(BorderStyle.HAIR, r1fp.getBorderRightEnum()); workbook.close(); } From 38cd94d676d748560c931ee626e1a1088d579c1c Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 05:22:23 +0000 Subject: [PATCH 12/43] bug 59264: revert CellStyle#getBorder[Top|Bottom|Left|Right]() to return short and add getBorder[Top|Bottom|Left|Right]Enum() returns BorderStyle enum for backwards compatibility with POI 3.14 and earlier git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760630 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/view/SVTableCellRenderer.java | 4 +- .../poi/ss/examples/ExcelComparator.java | 16 ++--- .../apache/poi/ss/examples/html/ToHtml.java | 8 +-- .../poi/hssf/usermodel/HSSFCellStyle.java | 62 +++++++++++++++++-- .../apache/poi/ss/usermodel/CellStyle.java | 48 ++++++++++++-- src/java/org/apache/poi/ss/util/CellUtil.java | 8 +-- .../poi/xssf/usermodel/XSSFCellStyle.java | 61 +++++++++++------- .../poi/xssf/usermodel/TestXSSFCellStyle.java | 38 ++++++------ .../hssf/converter/ExcelToFoConverter.java | 16 ++--- .../hssf/converter/ExcelToHtmlConverter.java | 8 +-- .../apache/poi/hssf/usermodel/TestBugs.java | 2 +- .../poi/hssf/usermodel/TestCellStyle.java | 26 ++++---- .../poi/hssf/usermodel/TestHSSFOptimiser.java | 6 +- .../poi/hssf/usermodel/TestRowStyle.java | 8 +-- .../poi/ss/usermodel/BaseTestBorderStyle.java | 8 +-- .../apache/poi/ss/usermodel/BaseTestCell.java | 8 +-- .../apache/poi/ss/util/BaseTestCellUtil.java | 4 +- 17 files changed, 222 insertions(+), 109 deletions(-) diff --git a/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java b/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java index ac0075b16..8a59b8306 100644 --- a/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java +++ b/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java @@ -160,8 +160,8 @@ public class SVTableCellRenderer extends JLabel SVTableUtils.getAWTColor(s.getRightBorderColor(), SVTableUtils.black), SVTableUtils.getAWTColor(s.getBottomBorderColor(), SVTableUtils.black), SVTableUtils.getAWTColor(s.getLeftBorderColor(), SVTableUtils.black), - s.getBorderTop(), s.getBorderRight(), - s.getBorderBottom(), s.getBorderLeft(), + s.getBorderTopEnum(), s.getBorderRightEnum(), + s.getBorderBottomEnum(), s.getBorderLeftEnum(), hasFocus); setBorder(cellBorder); isBorderSet=true; diff --git a/src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java b/src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java index dce4b0196..d6f846a6b 100644 --- a/src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java +++ b/src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java @@ -367,23 +367,23 @@ public class ExcelComparator { String borderName; switch (borderSide) { case 't': default: - b1 = style1.getBorderTop() == BorderStyle.THIN; - b2 = style2.getBorderTop() == BorderStyle.THIN; + b1 = style1.getBorderTopEnum() == BorderStyle.THIN; + b2 = style2.getBorderTopEnum() == BorderStyle.THIN; borderName = "TOP"; break; case 'b': - b1 = style1.getBorderBottom() == BorderStyle.THIN; - b2 = style2.getBorderBottom() == BorderStyle.THIN; + b1 = style1.getBorderBottomEnum() == BorderStyle.THIN; + b2 = style2.getBorderBottomEnum() == BorderStyle.THIN; borderName = "BOTTOM"; break; case 'l': - b1 = style1.getBorderLeft() == BorderStyle.THIN; - b2 = style2.getBorderLeft() == BorderStyle.THIN; + b1 = style1.getBorderLeftEnum() == BorderStyle.THIN; + b2 = style2.getBorderLeftEnum() == BorderStyle.THIN; borderName = "LEFT"; break; case 'r': - b1 = style1.getBorderRight() == BorderStyle.THIN; - b2 = style2.getBorderRight() == BorderStyle.THIN; + b1 = style1.getBorderRightEnum() == BorderStyle.THIN; + b2 = style2.getBorderRightEnum() == BorderStyle.THIN; borderName = "RIGHT"; break; } diff --git a/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java b/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java index c5fdc1da9..f5d2ecba8 100644 --- a/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java +++ b/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java @@ -298,10 +298,10 @@ public class ToHtml { } private void borderStyles(CellStyle style) { - styleOut("border-left", style.getBorderLeft(), BORDER); - styleOut("border-right", style.getBorderRight(), BORDER); - styleOut("border-top", style.getBorderTop(), BORDER); - styleOut("border-bottom", style.getBorderBottom(), BORDER); + styleOut("border-left", style.getBorderLeftEnum(), BORDER); + styleOut("border-right", style.getBorderRightEnum(), BORDER); + styleOut("border-top", style.getBorderTopEnum(), BORDER); + styleOut("border-bottom", style.getBorderBottomEnum(), BORDER); } private void fontStyle(CellStyle style) { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java index 4fbbdf62e..0fd7cf2ad 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java @@ -331,6 +331,7 @@ public final class HSSFCellStyle implements CellStyle { * @see VerticalAlignment * @deprecated POI 3.15 beta 3. Use {@link #setVerticalAlignment(VerticalAlignment)} instead. */ + @Removal(version="3.17") @Override public void setVerticalAlignment(short align) { @@ -461,6 +462,7 @@ public final class HSSFCellStyle implements CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderLeft(BorderStyle)} instead. */ + @Removal(version="3.17") @Override public void setBorderLeft(short border) { @@ -471,6 +473,7 @@ public final class HSSFCellStyle implements CellStyle { /** * set the type of border to use for the left border of the cell * @param border type + * @since POI 3.15 */ @Override public void setBorderLeft(BorderStyle border) @@ -481,9 +484,20 @@ public final class HSSFCellStyle implements CellStyle { /** * get the type of border to use for the left border of the cell * @return border type + * @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderLeftEnum()}. */ @Override - public BorderStyle getBorderLeft() + public short getBorderLeft() + { + return _format.getBorderLeft(); + } + /** + * get the type of border to use for the left border of the cell + * @return border type + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderLeftEnum() { return BorderStyle.valueOf(_format.getBorderLeft()); } @@ -507,6 +521,7 @@ public final class HSSFCellStyle implements CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderRight(BorderStyle)} instead. */ + @Removal(version="3.17") @Override public void setBorderRight(short border) { @@ -517,6 +532,7 @@ public final class HSSFCellStyle implements CellStyle { /** * set the type of border to use for the right border of the cell * @param border type + * @since POI 3.15 */ @Override public void setBorderRight(BorderStyle border) @@ -527,9 +543,20 @@ public final class HSSFCellStyle implements CellStyle { /** * get the type of border to use for the right border of the cell * @return border type + * @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderRightEnum()}. */ @Override - public BorderStyle getBorderRight() + public short getBorderRight() + { + return _format.getBorderRight(); + } + /** + * get the type of border to use for the right border of the cell + * @return border type + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderRightEnum() { return BorderStyle.valueOf(_format.getBorderRight()); } @@ -553,6 +580,7 @@ public final class HSSFCellStyle implements CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderTop(BorderStyle)} instead. */ + @Removal(version="3.17") @Override public void setBorderTop(short border) { @@ -563,6 +591,7 @@ public final class HSSFCellStyle implements CellStyle { /** * set the type of border to use for the top border of the cell * @param border type + * @since POI 3.15 */ @Override public void setBorderTop(BorderStyle border) @@ -573,9 +602,20 @@ public final class HSSFCellStyle implements CellStyle { /** * get the type of border to use for the top border of the cell * @return border type + * @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderTopEnum()}. */ @Override - public BorderStyle getBorderTop() + public short getBorderTop() + { + return _format.getBorderTop(); + } + /** + * get the type of border to use for the top border of the cell + * @return border type + * @since 3.15 + */ + @Override + public BorderStyle getBorderTopEnum() { return BorderStyle.valueOf(_format.getBorderTop()); } @@ -599,6 +639,7 @@ public final class HSSFCellStyle implements CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderBottom(BorderStyle)} instead. */ + @Removal(version="3.17") @Override public void setBorderBottom(short border) { @@ -609,6 +650,7 @@ public final class HSSFCellStyle implements CellStyle { /** * set the type of border to use for the bottom border of the cell * @param border type + * @since 3.15 beta 2 */ @Override public void setBorderBottom(BorderStyle border) @@ -619,9 +661,20 @@ public final class HSSFCellStyle implements CellStyle { /** * get the type of border to use for the bottom border of the cell * @return border type + * @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderBottomEnum()}. */ @Override - public BorderStyle getBorderBottom() + public short getBorderBottom() + { + return _format.getBorderBottom(); + } + /** + * get the type of border to use for the bottom border of the cell + * @return border type + * @since 3.15 + */ + @Override + public BorderStyle getBorderBottomEnum() { return BorderStyle.valueOf(_format.getBorderBottom()); } @@ -735,6 +788,7 @@ public final class HSSFCellStyle implements CellStyle { * @param fp fill pattern (set to 1 to fill w/foreground color) * @deprecated POI 3.15 beta 3. Use {@link #setFillPattern(FillPatternType)} instead. */ + @Removal(version="3.17") @Override public void setFillPattern(short fp) { diff --git a/src/java/org/apache/poi/ss/usermodel/CellStyle.java b/src/java/org/apache/poi/ss/usermodel/CellStyle.java index 17a5d0e75..df3d57259 100644 --- a/src/java/org/apache/poi/ss/usermodel/CellStyle.java +++ b/src/java/org/apache/poi/ss/usermodel/CellStyle.java @@ -541,19 +541,29 @@ public interface CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link #setBorderLeft(BorderStyle)} instead */ + @Removal(version="3.17") void setBorderLeft(short border); /** * set the type of border to use for the left border of the cell * @param border type + * @since POI 3.15 */ void setBorderLeft(BorderStyle border); /** * get the type of border to use for the left border of the cell * @return border type + * @deprecated POI 3.15. Use {@link #getBorderLeftEnum()} instead. + * This will return a BorderStyle enum in the future. */ - BorderStyle getBorderLeft(); + short getBorderLeft(); + /** + * get the type of border to use for the left border of the cell + * @return border type + * @since POI 3.15 + */ + BorderStyle getBorderLeftEnum(); /** * set the type of border to use for the right border of the cell @@ -574,19 +584,29 @@ public interface CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link #setBorderRight(BorderStyle)} instead */ + @Removal(version="3.17") void setBorderRight(short border); /** * set the type of border to use for the right border of the cell * @param border type + * @since POI 3.15 */ void setBorderRight(BorderStyle border); /** * get the type of border to use for the right border of the cell * @return border type + * @deprecated POI 3.15. Use {@link #getBorderRightEnum()} instead. + * This will return a BorderStyle enum in the future. */ - BorderStyle getBorderRight(); + short getBorderRight(); + /** + * get the type of border to use for the right border of the cell + * @return border type + * @since POI 3.15 + */ + BorderStyle getBorderRightEnum(); /** * set the type of border to use for the top border of the cell @@ -607,19 +627,29 @@ public interface CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link #setBorderTop(BorderStyle)} instead */ + @Removal(version="3.17") void setBorderTop(short border); /** * set the type of border to use for the top border of the cell * @param border type + * @since POI 3.15 */ void setBorderTop(BorderStyle border); /** * get the type of border to use for the top border of the cell * @return border type + * @deprecated POI 3.15. Use {@link #getBorderTopEnum()} instead. + * This will return a BorderStyle enum in the future. */ - BorderStyle getBorderTop(); + short getBorderTop(); + /** + * get the type of border to use for the top border of the cell + * @return border type + * @since POI 3.15 + */ + BorderStyle getBorderTopEnum(); /** * set the type of border to use for the bottom border of the cell @@ -640,19 +670,29 @@ public interface CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link #setBorderBottom(BorderStyle)} instead. */ + @Removal(version="3.17") void setBorderBottom(short border); /** * set the type of border to use for the bottom border of the cell * @param border type + * @since POI 3.15 */ void setBorderBottom(BorderStyle border); /** * get the type of border to use for the bottom border of the cell * @return border type + * @deprecated POI 3.15. Use {@link #getBorderBottomEnum()} instead. + * This will return a BorderStyle enum in the future. */ - BorderStyle getBorderBottom(); + short getBorderBottom(); + /** + * get the type of border to use for the bottom border of the cell + * @return border type + * @since POI 3.15 + */ + BorderStyle getBorderBottomEnum(); /** * set the color to use for the left border diff --git a/src/java/org/apache/poi/ss/util/CellUtil.java b/src/java/org/apache/poi/ss/util/CellUtil.java index 4f446c10d..3dad83aab 100644 --- a/src/java/org/apache/poi/ss/util/CellUtil.java +++ b/src/java/org/apache/poi/ss/util/CellUtil.java @@ -405,10 +405,10 @@ public final class CellUtil { Map properties = new HashMap(); put(properties, ALIGNMENT, style.getAlignmentEnum()); put(properties, VERTICAL_ALIGNMENT, style.getVerticalAlignmentEnum()); - put(properties, BORDER_BOTTOM, style.getBorderBottom()); - put(properties, BORDER_LEFT, style.getBorderLeft()); - put(properties, BORDER_RIGHT, style.getBorderRight()); - put(properties, BORDER_TOP, style.getBorderTop()); + put(properties, BORDER_BOTTOM, style.getBorderBottomEnum()); + put(properties, BORDER_LEFT, style.getBorderLeftEnum()); + put(properties, BORDER_RIGHT, style.getBorderRightEnum()); + put(properties, BORDER_TOP, style.getBorderTopEnum()); put(properties, BOTTOM_BORDER_COLOR, style.getBottomBorderColor()); put(properties, DATA_FORMAT, style.getDataFormat()); put(properties, FILL_PATTERN, style.getFillPatternEnum()); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java index 1e7dc5040..9eec21ec6 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java @@ -252,11 +252,13 @@ public class XSSFCellStyle implements CellStyle { /** * Get the type of border to use for the bottom border of the cell + * Will be removed when {@link #getBorderBottom()} returns a BorderStyle enum * * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE} + * @since POI 3.15 */ @Override - public BorderStyle getBorderBottom() { + public BorderStyle getBorderBottomEnum() { if(!_cellXf.getApplyBorder()) return BorderStyle.NONE; int idx = (int)_cellXf.getBorderId(); @@ -267,24 +269,26 @@ public class XSSFCellStyle implements CellStyle { } return BorderStyle.valueOf((short)(ptrn.intValue() - 1)); } - /** * Get the type of border to use for the bottom border of the cell + * This will return a BorderStyle enum in the future. * - * @return border type as Java enum - * @deprecated 3.15 beta 2. Use {@link #getBorderBottom} + * @return border type code + * @deprecated 3.15 beta 2. Use {@link #getBorderBottomEnum()} */ - public BorderStyle getBorderBottomEnum() { - return getBorderBottom(); + public short getBorderBottom() { + return getBorderBottomEnum().getCode(); } /** * Get the type of border to use for the left border of the cell + * Will be removed when {@link #getBorderLeft()} returns a BorderStyle enum * * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE} + * @since POI 3.15 */ @Override - public BorderStyle getBorderLeft() { + public BorderStyle getBorderLeftEnum() { if(!_cellXf.getApplyBorder()) return BorderStyle.NONE; int idx = (int)_cellXf.getBorderId(); @@ -298,21 +302,24 @@ public class XSSFCellStyle implements CellStyle { /** * Get the type of border to use for the left border of the cell + * This will return a BorderStyle enum in the future. * - * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE} - * @deprecated 3.15 beta 2. Use {@link #getBorderLeft} + * @return border type code + * @deprecated 3.15 beta 2. Use {@link #getBorderLeftEnum()} */ - public BorderStyle getBorderLeftEnum() { - return getBorderLeft(); + public short getBorderLeft() { + return getBorderLeftEnum().getCode(); } /** * Get the type of border to use for the right border of the cell + * Will be removed when {@link #getBorderRight()} returns a BorderStyle enum * * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE} + * @since POI 3.15 */ @Override - public BorderStyle getBorderRight() { + public BorderStyle getBorderRightEnum() { if(!_cellXf.getApplyBorder()) return BorderStyle.NONE; int idx = (int)_cellXf.getBorderId(); @@ -323,24 +330,26 @@ public class XSSFCellStyle implements CellStyle { } return BorderStyle.valueOf((short)(ptrn.intValue() - 1)); } - /** * Get the type of border to use for the right border of the cell + * This will return a BorderStyle enum in the future. * * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE} - * @deprecated 3.15 beta 2. Use {@link #getBorderRight} + * @deprecated 3.15 beta 2. Use {@link #getBorderRightEnum()} instead */ - public BorderStyle getBorderRightEnum() { - return getBorderRight(); + public short getBorderRight() { + return getBorderRightEnum().getCode(); } /** * Get the type of border to use for the top border of the cell + * Will be removed when {@link #getBorderTop()} returns a BorderStyle enum * * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE} + * @since POI 3.15 */ @Override - public BorderStyle getBorderTop() { + public BorderStyle getBorderTopEnum() { if(!_cellXf.getApplyBorder()) return BorderStyle.NONE; int idx = (int)_cellXf.getBorderId(); @@ -351,15 +360,15 @@ public class XSSFCellStyle implements CellStyle { } return BorderStyle.valueOf((short) (ptrn.intValue() - 1)); } - /** * Get the type of border to use for the top border of the cell + * This will return a BorderStyle enum in the future. * * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE} - * @deprecated 3.15 beta 2. Use {@link #getBorderTop} + * @deprecated 3.15 beta 2. Use {@link #getBorderTopEnum()} instead. */ - public BorderStyle getBorderTopEnum() { - return getBorderTop(); + public short getBorderTop() { + return getBorderTopEnum().getCode(); } /** @@ -776,6 +785,7 @@ public class XSSFCellStyle implements CellStyle { * @see org.apache.poi.ss.usermodel.CellStyle#ALIGN_CENTER_SELECTION * @deprecated POI 3.15 beta 3. Use {@link #setAlignment(HorizontalAlignment)} instead. */ + @Removal(version="3.17") @Override public void setAlignment(short align) { setAlignment(HorizontalAlignment.forInt(align)); @@ -797,6 +807,7 @@ public class XSSFCellStyle implements CellStyle { * @param border the type of border to use * @deprecated 3.15 beta 2. Use {@link #setBorderBottom(BorderStyle)} */ + @Removal(version="3.17") @Override public void setBorderBottom(short border) { setBorderBottom(BorderStyle.valueOf(border)); @@ -807,6 +818,7 @@ public class XSSFCellStyle implements CellStyle { * * @param border - type of border to use * @see org.apache.poi.ss.usermodel.BorderStyle + * @since POI 3.15 */ @Override public void setBorderBottom(BorderStyle border) { @@ -826,6 +838,7 @@ public class XSSFCellStyle implements CellStyle { * @param border the type of border to use * @deprecated 3.15 beta 2. Use {@link #setBorderLeft(BorderStyle)} */ + @Removal(version="3.17") @Override public void setBorderLeft(short border) { setBorderLeft(BorderStyle.valueOf(border)); @@ -835,6 +848,7 @@ public class XSSFCellStyle implements CellStyle { * Set the type of border to use for the left border of the cell * * @param border the type of border to use + * @since POI 3.15 */ @Override public void setBorderLeft(BorderStyle border) { @@ -855,6 +869,7 @@ public class XSSFCellStyle implements CellStyle { * @param border the type of border to use * @deprecated 3.15 beta 2. Use {@link #setBorderRight(BorderStyle)} */ + @Removal(version="3.17") @Override public void setBorderRight(short border) { setBorderRight(BorderStyle.valueOf(border)); @@ -864,6 +879,7 @@ public class XSSFCellStyle implements CellStyle { * Set the type of border to use for the right border of the cell * * @param border the type of border to use + * @since POI 3.15 */ @Override public void setBorderRight(BorderStyle border) { @@ -884,6 +900,7 @@ public class XSSFCellStyle implements CellStyle { * @param border the type of border to use * @deprecated 3.15 beta 2. Use {@link #setBorderTop(BorderStyle)} */ + @Removal(version="3.17") @Override public void setBorderTop(short border) { setBorderTop(BorderStyle.valueOf(border)); @@ -893,6 +910,7 @@ public class XSSFCellStyle implements CellStyle { * Set the type of border to use for the top border of the cell * * @param border the type of border to use + * @since POI 3.15 */ @Override public void setBorderTop(BorderStyle border) { @@ -1338,6 +1356,7 @@ public class XSSFCellStyle implements CellStyle { * @see org.apache.poi.ss.usermodel.VerticalAlignment * @deprecated POI 3.15 beta 3. Use {@link #setVerticalAlignment(VerticalAlignment)} instead. */ + @Removal(version="3.17") @Override public void setVerticalAlignment(short align) { setVerticalAlignment(VerticalAlignment.forInt(align)); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java index 94e40a3a7..c907d40db 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java @@ -104,11 +104,11 @@ public class TestXSSFCellStyle { @Test public void testGetSetBorderBottom() { //default values - assertEquals(BorderStyle.NONE, cellStyle.getBorderBottom()); + assertEquals(BorderStyle.NONE, cellStyle.getBorderBottomEnum()); int num = stylesTable.getBorders().size(); cellStyle.setBorderBottom(BorderStyle.MEDIUM); - assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottom()); + assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottomEnum()); //a new border has been added assertEquals(num + 1, stylesTable.getBorders().size()); //id of the created border @@ -122,7 +122,7 @@ public class TestXSSFCellStyle { //setting the same border multiple times should not change borderId for (int i = 0; i < 3; i++) { cellStyle.setBorderBottom(BorderStyle.MEDIUM); - assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottom()); + assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottomEnum()); } assertEquals(borderId, cellStyle.getCoreXf().getBorderId()); assertEquals(num, stylesTable.getBorders().size()); @@ -139,11 +139,11 @@ public class TestXSSFCellStyle { @Test public void testGetSetBorderRight() { //default values - assertEquals(BorderStyle.NONE, cellStyle.getBorderRight()); + assertEquals(BorderStyle.NONE, cellStyle.getBorderRightEnum()); int num = stylesTable.getBorders().size(); cellStyle.setBorderRight(BorderStyle.MEDIUM); - assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRight()); + assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRightEnum()); //a new border has been added assertEquals(num + 1, stylesTable.getBorders().size()); //id of the created border @@ -157,7 +157,7 @@ public class TestXSSFCellStyle { //setting the same border multiple times should not change borderId for (int i = 0; i < 3; i++) { cellStyle.setBorderRight(BorderStyle.MEDIUM); - assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRight()); + assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRightEnum()); } assertEquals(borderId, cellStyle.getCoreXf().getBorderId()); assertEquals(num, stylesTable.getBorders().size()); @@ -174,11 +174,11 @@ public class TestXSSFCellStyle { @Test public void testGetSetBorderLeft() { //default values - assertEquals(BorderStyle.NONE, cellStyle.getBorderLeft()); + assertEquals(BorderStyle.NONE, cellStyle.getBorderLeftEnum()); int num = stylesTable.getBorders().size(); cellStyle.setBorderLeft(BorderStyle.MEDIUM); - assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeft()); + assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeftEnum()); //a new border has been added assertEquals(num + 1, stylesTable.getBorders().size()); //id of the created border @@ -192,7 +192,7 @@ public class TestXSSFCellStyle { //setting the same border multiple times should not change borderId for (int i = 0; i < 3; i++) { cellStyle.setBorderLeft(BorderStyle.MEDIUM); - assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeft()); + assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeftEnum()); } assertEquals(borderId, cellStyle.getCoreXf().getBorderId()); assertEquals(num, stylesTable.getBorders().size()); @@ -209,11 +209,11 @@ public class TestXSSFCellStyle { @Test public void testGetSetBorderTop() { //default values - assertEquals(BorderStyle.NONE, cellStyle.getBorderTop()); + assertEquals(BorderStyle.NONE, cellStyle.getBorderTopEnum()); int num = stylesTable.getBorders().size(); cellStyle.setBorderTop(BorderStyle.MEDIUM); - assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTop()); + assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTopEnum()); //a new border has been added assertEquals(num + 1, stylesTable.getBorders().size()); //id of the created border @@ -227,7 +227,7 @@ public class TestXSSFCellStyle { //setting the same border multiple times should not change borderId for (int i = 0; i < 3; i++) { cellStyle.setBorderTop(BorderStyle.MEDIUM); - assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTop()); + assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTopEnum()); } assertEquals(borderId, cellStyle.getCoreXf().getBorderId()); assertEquals(num, stylesTable.getBorders().size()); @@ -243,7 +243,7 @@ public class TestXSSFCellStyle { private void testGetSetBorderXMLBean(BorderStyle border, STBorderStyle.Enum expected) { cellStyle.setBorderTop(border); - assertEquals(border, cellStyle.getBorderTop()); + assertEquals(border, cellStyle.getBorderTopEnum()); int borderId = (int)cellStyle.getCoreXf().getBorderId(); assertTrue(borderId > 0); //check changes in the underlying xml bean @@ -256,7 +256,7 @@ public class TestXSSFCellStyle { @Test public void testGetSetBorderNone() { cellStyle.setBorderTop(BorderStyle.NONE); - assertEquals(BorderStyle.NONE, cellStyle.getBorderTop()); + assertEquals(BorderStyle.NONE, cellStyle.getBorderTopEnum()); int borderId = (int)cellStyle.getCoreXf().getBorderId(); assertTrue(borderId > 0); //check changes in the underlying xml bean @@ -562,10 +562,10 @@ public class TestXSSFCellStyle { assertEquals(style2.getRightBorderColor(), style1.getRightBorderColor()); assertEquals(style2.getBottomBorderColor(), style1.getBottomBorderColor()); - assertEquals(style2.getBorderBottom(), style1.getBorderBottom()); - assertEquals(style2.getBorderLeft(), style1.getBorderLeft()); - assertEquals(style2.getBorderRight(), style1.getBorderRight()); - assertEquals(style2.getBorderTop(), style1.getBorderTop()); + assertEquals(style2.getBorderBottomEnum(), style1.getBorderBottomEnum()); + assertEquals(style2.getBorderLeftEnum(), style1.getBorderLeftEnum()); + assertEquals(style2.getBorderRightEnum(), style1.getBorderRightEnum()); + assertEquals(style2.getBorderTopEnum(), style1.getBorderTopEnum()); wb2.close(); } @@ -999,7 +999,7 @@ public class TestXSSFCellStyle { Workbook copy = XSSFTestDataSamples.writeOutAndReadBack(target); // previously this failed because the border-element was not copied over - copy.getCellStyleAt((short)1).getBorderBottom(); + copy.getCellStyleAt((short)1).getBorderBottomEnum(); copy.close(); diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java index 1c32edabe..29d7ffce0 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java @@ -193,10 +193,10 @@ public class ExcelToFoConverter extends AbstractExcelConverter protected boolean isEmptyStyle( CellStyle cellStyle ) { return cellStyle == null || ( cellStyle.getFillPattern() == 0 - && cellStyle.getBorderTop() == BorderStyle.NONE - && cellStyle.getBorderRight() == BorderStyle.NONE - && cellStyle.getBorderBottom() == BorderStyle.NONE - && cellStyle.getBorderLeft() == BorderStyle.NONE + && cellStyle.getBorderTopEnum() == BorderStyle.NONE + && cellStyle.getBorderRightEnum() == BorderStyle.NONE + && cellStyle.getBorderBottomEnum() == BorderStyle.NONE + && cellStyle.getBorderLeftEnum() == BorderStyle.NONE ); } @@ -361,13 +361,13 @@ public class ExcelToFoConverter extends AbstractExcelConverter } processCellStyleBorder( workbook, cellTarget, "top", - cellStyle.getBorderTop(), cellStyle.getTopBorderColor() ); + cellStyle.getBorderTopEnum(), cellStyle.getTopBorderColor() ); processCellStyleBorder( workbook, cellTarget, "right", - cellStyle.getBorderRight(), cellStyle.getRightBorderColor() ); + cellStyle.getBorderRightEnum(), cellStyle.getRightBorderColor() ); processCellStyleBorder( workbook, cellTarget, "bottom", - cellStyle.getBorderBottom(), cellStyle.getBottomBorderColor() ); + cellStyle.getBorderBottomEnum(), cellStyle.getBottomBorderColor() ); processCellStyleBorder( workbook, cellTarget, "left", - cellStyle.getBorderLeft(), cellStyle.getLeftBorderColor() ); + cellStyle.getBorderLeftEnum(), cellStyle.getLeftBorderColor() ); HSSFFont font = cellStyle.getFont( workbook ); processCellStyleFont( workbook, blockTarget, font ); diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java index 54dc4d319..5019339d3 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java @@ -175,13 +175,13 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter break; } - buildStyle_border( workbook, style, "top", cellStyle.getBorderTop(), + buildStyle_border( workbook, style, "top", cellStyle.getBorderTopEnum(), cellStyle.getTopBorderColor() ); buildStyle_border( workbook, style, "right", - cellStyle.getBorderRight(), cellStyle.getRightBorderColor() ); + cellStyle.getBorderRightEnum(), cellStyle.getRightBorderColor() ); buildStyle_border( workbook, style, "bottom", - cellStyle.getBorderBottom(), cellStyle.getBottomBorderColor() ); - buildStyle_border( workbook, style, "left", cellStyle.getBorderLeft(), + cellStyle.getBorderBottomEnum(), cellStyle.getBottomBorderColor() ); + buildStyle_border( workbook, style, "left", cellStyle.getBorderLeftEnum(), cellStyle.getLeftBorderColor() ); HSSFFont font = cellStyle.getFont( workbook ); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index dca98f620..2ce6e1de8 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -2567,7 +2567,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row = sheet.getRow(0); HSSFCellStyle rstyle = row.getRowStyle(); - assertEquals(BorderStyle.DOUBLE, rstyle.getBorderBottom()); + assertEquals(BorderStyle.DOUBLE, rstyle.getBorderBottomEnum()); wb.close(); } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java index 7e6d8a3bc..eec69b211 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java @@ -348,40 +348,40 @@ public final class TestCellStyle extends TestCase { HSSFCellStyle cs; cs = s.getRow(0).getCell(0).getCellStyle(); - assertEquals(BorderStyle.HAIR, cs.getBorderRight()); + assertEquals(BorderStyle.HAIR, cs.getBorderRightEnum()); cs = s.getRow(1).getCell(1).getCellStyle(); - assertEquals(BorderStyle.DOTTED, cs.getBorderRight()); + assertEquals(BorderStyle.DOTTED, cs.getBorderRightEnum()); cs = s.getRow(2).getCell(2).getCellStyle(); - assertEquals(BorderStyle.DASH_DOT_DOT, cs.getBorderRight()); + assertEquals(BorderStyle.DASH_DOT_DOT, cs.getBorderRightEnum()); cs = s.getRow(3).getCell(3).getCellStyle(); - assertEquals(BorderStyle.DASHED, cs.getBorderRight()); + assertEquals(BorderStyle.DASHED, cs.getBorderRightEnum()); cs = s.getRow(4).getCell(4).getCellStyle(); - assertEquals(BorderStyle.THIN, cs.getBorderRight()); + assertEquals(BorderStyle.THIN, cs.getBorderRightEnum()); cs = s.getRow(5).getCell(5).getCellStyle(); - assertEquals(BorderStyle.MEDIUM_DASH_DOT_DOT, cs.getBorderRight()); + assertEquals(BorderStyle.MEDIUM_DASH_DOT_DOT, cs.getBorderRightEnum()); cs = s.getRow(6).getCell(6).getCellStyle(); - assertEquals(BorderStyle.SLANTED_DASH_DOT, cs.getBorderRight()); + assertEquals(BorderStyle.SLANTED_DASH_DOT, cs.getBorderRightEnum()); cs = s.getRow(7).getCell(7).getCellStyle(); - assertEquals(BorderStyle.MEDIUM_DASH_DOT, cs.getBorderRight()); + assertEquals(BorderStyle.MEDIUM_DASH_DOT, cs.getBorderRightEnum()); cs = s.getRow(8).getCell(8).getCellStyle(); - assertEquals(BorderStyle.MEDIUM_DASHED, cs.getBorderRight()); + assertEquals(BorderStyle.MEDIUM_DASHED, cs.getBorderRightEnum()); cs = s.getRow(9).getCell(9).getCellStyle(); - assertEquals(BorderStyle.MEDIUM, cs.getBorderRight()); + assertEquals(BorderStyle.MEDIUM, cs.getBorderRightEnum()); cs = s.getRow(10).getCell(10).getCellStyle(); - assertEquals(BorderStyle.THICK, cs.getBorderRight()); + assertEquals(BorderStyle.THICK, cs.getBorderRightEnum()); cs = s.getRow(11).getCell(11).getCellStyle(); - assertEquals(BorderStyle.DOUBLE, cs.getBorderRight()); + assertEquals(BorderStyle.DOUBLE, cs.getBorderRightEnum()); } public void testShrinkToFit() { @@ -500,7 +500,7 @@ public final class TestCellStyle extends TestCase { newCell.setCellValue("2testtext2"); CellStyle newStyle = newCell.getCellStyle(); - assertEquals(BorderStyle.DOTTED, newStyle.getBorderBottom()); + assertEquals(BorderStyle.DOTTED, newStyle.getBorderBottomEnum()); assertEquals(Font.COLOR_RED, ((HSSFCellStyle)newStyle).getFont(wb).getColor()); // OutputStream out = new FileOutputStream("/tmp/56959.xls"); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java index 059ab3f38..acb4974c1 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java @@ -308,8 +308,8 @@ public final class TestHSSFOptimiser extends TestCase { // Check assertEquals(23, wb.getNumCellStyles()); - assertEquals(BorderStyle.THICK, r.getCell(0).getCellStyle().getBorderBottom()); - assertEquals(BorderStyle.DASH_DOT, r.getCell(1).getCellStyle().getBorderBottom()); - assertEquals(BorderStyle.THICK, r.getCell(2).getCellStyle().getBorderBottom()); + assertEquals(BorderStyle.THICK, r.getCell(0).getCellStyle().getBorderBottomEnum()); + assertEquals(BorderStyle.DASH_DOT, r.getCell(1).getCellStyle().getBorderBottomEnum()); + assertEquals(BorderStyle.THICK, r.getCell(2).getCellStyle().getBorderBottomEnum()); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java index ba65d063a..35519d36c 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java @@ -151,10 +151,10 @@ public final class TestRowStyle extends TestCase { assertNotNull("Row is not null", r); cs = r.getRowStyle(); - assertEquals("Bottom Border Style for row:", BorderStyle.THIN, cs.getBorderBottom()); - assertEquals("Left Border Style for row:", BorderStyle.THIN, cs.getBorderLeft()); - assertEquals("Right Border Style for row:", BorderStyle.THIN, cs.getBorderRight()); - assertEquals("Top Border Style for row:", BorderStyle.THIN, cs.getBorderTop()); + assertEquals("Bottom Border Style for row:", BorderStyle.THIN, cs.getBorderBottomEnum()); + assertEquals("Left Border Style for row:", BorderStyle.THIN, cs.getBorderLeftEnum()); + assertEquals("Right Border Style for row:", BorderStyle.THIN, cs.getBorderRightEnum()); + assertEquals("Top Border Style for row:", BorderStyle.THIN, cs.getBorderTopEnum()); assertEquals("FillForegroundColor for row:", 0xA, cs.getFillForegroundColor()); assertEquals("FillPattern for row:", 0x1, cs.getFillPattern()); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBorderStyle.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBorderStyle.java index 5ea2280b2..2fd2c37bf 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBorderStyle.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBorderStyle.java @@ -73,10 +73,10 @@ public class BaseTestBorderStyle { protected void assertBorderStyleEquals(BorderStyle expected, Cell cell) { CellStyle style = cell.getCellStyle(); - assertEquals(expected, style.getBorderTop()); - assertEquals(expected, style.getBorderBottom()); - assertEquals(expected, style.getBorderLeft()); - assertEquals(expected, style.getBorderRight()); + assertEquals(expected, style.getBorderTopEnum()); + assertEquals(expected, style.getBorderBottomEnum()); + assertEquals(expected, style.getBorderLeftEnum()); + assertEquals(expected, style.getBorderRightEnum()); } } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java index 406816958..a19cf6684 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java @@ -278,10 +278,10 @@ public abstract class BaseTestCell { assertNotNull("Formula Cell Style", cs); assertEquals("Font Index Matches", f.getIndex(), cs.getFontIndex()); - assertEquals("Top Border", BorderStyle.THIN, cs.getBorderTop()); - assertEquals("Left Border", BorderStyle.THIN, cs.getBorderLeft()); - assertEquals("Right Border", BorderStyle.THIN, cs.getBorderRight()); - assertEquals("Bottom Border", BorderStyle.THIN, cs.getBorderBottom()); + assertEquals("Top Border", BorderStyle.THIN, cs.getBorderTopEnum()); + assertEquals("Left Border", BorderStyle.THIN, cs.getBorderLeftEnum()); + assertEquals("Right Border", BorderStyle.THIN, cs.getBorderRightEnum()); + assertEquals("Bottom Border", BorderStyle.THIN, cs.getBorderBottomEnum()); wb2.close(); } diff --git a/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java b/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java index a63ce5a60..91c204da3 100644 --- a/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java +++ b/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java @@ -99,11 +99,11 @@ public class BaseTestCellUtil { // A valid BorderStyle constant, as a Short CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, BorderStyle.DASH_DOT.getCode()); - assertEquals(BorderStyle.DASH_DOT, c.getCellStyle().getBorderBottom()); + assertEquals(BorderStyle.DASH_DOT, c.getCellStyle().getBorderBottomEnum()); // A valid BorderStyle constant, as an Enum CellUtil.setCellStyleProperty(c, CellUtil.BORDER_TOP, BorderStyle.MEDIUM_DASH_DOT); - assertEquals(BorderStyle.MEDIUM_DASH_DOT, c.getCellStyle().getBorderTop()); + assertEquals(BorderStyle.MEDIUM_DASH_DOT, c.getCellStyle().getBorderTopEnum()); wb.close(); } From ca78ec28785cef64b1c651b519cf3324efca0117 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 05:31:48 +0000 Subject: [PATCH 13/43] bug 58671: add @Removal annotation to deprecated fields git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760632 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/ss/usermodel/Row.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/poi/ss/usermodel/Row.java b/src/java/org/apache/poi/ss/usermodel/Row.java index b17edcd30..f58775704 100644 --- a/src/java/org/apache/poi/ss/usermodel/Row.java +++ b/src/java/org/apache/poi/ss/usermodel/Row.java @@ -19,6 +19,8 @@ package org.apache.poi.ss.usermodel; import java.util.Iterator; +import org.apache.poi.util.Removal; + /** * High level representation of a row of a spreadsheet. */ @@ -240,8 +242,10 @@ public interface Row extends Iterable { CREATE_NULL_AS_BLANK(3); /** - * @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - the id has no function and will be removed + * @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - the id has no function and will be removed. + * The {@code id} is only kept only for backwards compatibility with applications that hard-coded the number */ + @Removal(version="3.17") @Deprecated public final int id; private MissingCellPolicy(int id) { @@ -254,6 +258,7 @@ public interface Row extends Iterable { * * @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - use the MissingCellPolicy enum **/ + @Removal(version="3.17") @Deprecated public static final MissingCellPolicy RETURN_NULL_AND_BLANK = MissingCellPolicy.RETURN_NULL_AND_BLANK; /** @@ -261,6 +266,7 @@ public interface Row extends Iterable { * * @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - use the MissingCellPolicy enum **/ + @Removal(version="3.17") @Deprecated public static final MissingCellPolicy RETURN_BLANK_AS_NULL = MissingCellPolicy.RETURN_BLANK_AS_NULL; /** @@ -268,6 +274,7 @@ public interface Row extends Iterable { * * @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - use the MissingCellPolicy enum **/ + @Removal(version="3.17") @Deprecated public static final MissingCellPolicy CREATE_NULL_AS_BLANK = MissingCellPolicy.CREATE_NULL_AS_BLANK; From 430ea9abfd90574b123e5381978dbd75395563ca Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 05:41:40 +0000 Subject: [PATCH 14/43] bug 58190: add @since annotations to SlideShow.addPicture and findPicture git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760633 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/sl/usermodel/SlideShow.java | 3 +++ src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java | 3 +++ .../src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/java/org/apache/poi/sl/usermodel/SlideShow.java b/src/java/org/apache/poi/sl/usermodel/SlideShow.java index e46ce243f..228925d1c 100644 --- a/src/java/org/apache/poi/sl/usermodel/SlideShow.java +++ b/src/java/org/apache/poi/sl/usermodel/SlideShow.java @@ -83,6 +83,7 @@ public interface SlideShow< * @param format The format of the picture. * * @return the picture data reference. + * @since 3.15 beta 1 */ PictureData addPicture(InputStream is, PictureType format) throws IOException; @@ -93,6 +94,7 @@ public interface SlideShow< * @param format The format of the picture. * * @return the picture data reference + * @since 3.15 beta 1 */ PictureData addPicture(File pict, PictureType format) throws IOException; @@ -101,6 +103,7 @@ public interface SlideShow< * * @param pictureData The picture data to find in the SlideShow * @return {@code null} if picture data is not found in this slideshow + * @since 3.15 beta 3 */ PictureData findPictureData(byte[] pictureData); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java index fe969d36b..14b656b53 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java @@ -471,6 +471,7 @@ implements SlideShow { * @param format The format of the picture * * @return the picture data + * @since 3.15 beta 2 */ @Override public XSLFPictureData addPicture(InputStream is, PictureType format) throws IOException @@ -486,6 +487,7 @@ implements SlideShow { * @param format The format of the picture. * * @return the picture data + * @since 3.15 beta 2 */ @Override public XSLFPictureData addPicture(File pict, PictureType format) throws IOException @@ -507,6 +509,7 @@ implements SlideShow { * * @param pictureData The picture data to find in the SlideShow * @return {@code null} if picture data is not found in this slideshow + * @since 3.15 beta 2 */ @Override public XSLFPictureData findPictureData(byte[] pictureData) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java index ad0e5aa9a..a17c61143 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java @@ -804,6 +804,7 @@ public final class HSLFSlideShow implements SlideShow Date: Wed, 14 Sep 2016 05:51:52 +0000 Subject: [PATCH 15/43] bug 59791: add deprecation and removal annotations git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760634 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/ss/format/CellFormat.java | 32 +++++++++++-------- .../apache/poi/xssf/streaming/SXSSFCell.java | 3 ++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/java/org/apache/poi/ss/format/CellFormat.java b/src/java/org/apache/poi/ss/format/CellFormat.java index e47d40c4f..bad849712 100644 --- a/src/java/org/apache/poi/ss/format/CellFormat.java +++ b/src/java/org/apache/poi/ss/format/CellFormat.java @@ -35,7 +35,6 @@ import org.apache.poi.ss.usermodel.ConditionalFormattingRule; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.util.DateFormatConverter; -import org.apache.poi.util.Internal; /** * Format a value according to the standard Excel behavior. This "standard" is @@ -44,28 +43,35 @@ import org.apache.poi.util.Internal; *

* An Excel format has up to four parts, separated by semicolons. Each part * specifies what to do with particular kinds of values, depending on the number - * of parts given:

One part (example: [Green]#.##)
If the - * value is a number, display according to this one part (example: green text, - * with up to two decimal points). If the value is text, display it as is. - *
Two parts (example: [Green]#.##;[Red]#.##)
If the value is a - * positive number or zero, display according to the first part (example: green + * of parts given: + *
+ *
One part (example: [Green]#.##)
+ *
If the value is a number, display according to this one part (example: green text, + * with up to two decimal points). If the value is text, display it as is.
+ * + *
Two parts (example: [Green]#.##;[Red]#.##)
+ *
If the value is a positive number or zero, display according to the first part (example: green * text, with up to two decimal points); if it is a negative number, display * according to the second part (example: red text, with up to two decimal - * points). If the value is text, display it as is.
Three parts (example: - * [Green]#.##;[Black]#.##;[Red]#.##)
If the value is a positive + * points). If the value is text, display it as is.
+ * + *
Three parts (example: [Green]#.##;[Black]#.##;[Red]#.##)
+ *
If the value is a positive * number, display according to the first part (example: green text, with up to * two decimal points); if it is zero, display according to the second part * (example: black text, with up to two decimal points); if it is a negative * number, display according to the third part (example: red text, with up to - * two decimal points). If the value is text, display it as is.
Four parts - * (example: [Green]#.##;[Black]#.##;[Red]#.##;[@])
If the value is - * a positive number, display according to the first part (example: green text, + * two decimal points). If the value is text, display it as is.
+ * + *
Four parts (example: [Green]#.##;[Black]#.##;[Red]#.##;[@])
+ *
If the value is a positive number, display according to the first part (example: green text, * with up to two decimal points); if it is zero, display according to the * second part (example: black text, with up to two decimal points); if it is a * negative number, display according to the third part (example: red text, with * up to two decimal points). If the value is text, display according to the * fourth part (example: text in the cell's usual color, with the text value - * surround by brackets).
+ * surround by brackets).
+ *
*

* A given format part may specify a given Locale, by including something * like [$$-409] or [$£-809] or [$-40C]. These @@ -421,6 +427,7 @@ public class CellFormat { * @param cell The cell. * * @return The ultimate type of this cell. + * @deprecated POI 3.15. This will return a CellType enum in the future */ public static int ultimateType(Cell cell) { return ultimateTypeEnum(cell).getCode(); @@ -439,7 +446,6 @@ public class CellFormat { * @deprecated POI 3.15 beta 3 * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") public static CellType ultimateTypeEnum(Cell cell) { CellType type = cell.getCellTypeEnum(); if (type == CellType.FORMULA) diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java index 6174af54b..99a4648a7 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java @@ -43,6 +43,7 @@ import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.NotImplemented; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; +import org.apache.poi.util.Removal; import org.apache.poi.xssf.usermodel.XSSFHyperlink; import org.apache.poi.xssf.usermodel.XSSFRichTextString; @@ -61,6 +62,8 @@ public class SXSSFCell implements Cell { * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ + @Removal(version="3.17") + @Deprecated public SXSSFCell(SXSSFRow row, int cellType) { this(row, CellType.forInt((cellType))); From b0f814f83f6936846fab22a956202581fb8268ba Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 06:22:38 +0000 Subject: [PATCH 16/43] bug 59791: add deprecation warnings git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760639 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java | 1 - .../org/apache/poi/ss/formula/BaseFormulaEvaluator.java | 1 + src/java/org/apache/poi/ss/formula/EvaluationCell.java | 2 ++ .../poi/ss/formula/eval/forked/ForkedEvaluationCell.java | 4 ++-- src/java/org/apache/poi/ss/usermodel/Cell.java | 4 ++-- src/java/org/apache/poi/ss/usermodel/CreationHelper.java | 9 +++++---- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java index b43228740..7154d7450 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java @@ -155,7 +155,6 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator { * @since POI 3.15 beta 3 * @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal @Override public CellType evaluateFormulaCellEnum(Cell cell) { if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) { diff --git a/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java b/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java index fb0c4d68d..7c459abb4 100644 --- a/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java +++ b/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java @@ -125,6 +125,7 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook * replaced with the result of the formula, use {@link #evaluateInCell(org.apache.poi.ss.usermodel.Cell)} * @param cell The cell to evaluate * @return -1 for non-formula cells, or the type of the formula result + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override public int evaluateFormulaCell(Cell cell) { diff --git a/src/java/org/apache/poi/ss/formula/EvaluationCell.java b/src/java/org/apache/poi/ss/formula/EvaluationCell.java index 3695fe280..a7e855c44 100644 --- a/src/java/org/apache/poi/ss/formula/EvaluationCell.java +++ b/src/java/org/apache/poi/ss/formula/EvaluationCell.java @@ -42,6 +42,7 @@ public interface EvaluationCell { * For forwards compatibility, do not hard-code cell type literals in your code. * * @return cell type + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ int getCellType(); /** @@ -61,6 +62,7 @@ public interface EvaluationCell { * For forwards compatibility, do not hard-code cell type literals in your code. * * @return cell type of cached formula result + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ int getCachedFormulaResultType(); /** diff --git a/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java b/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java index 0521e0889..db01b0640 100644 --- a/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java +++ b/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java @@ -108,6 +108,7 @@ final class ForkedEvaluationCell implements EvaluationCell { * For forwards compatibility, do not hard-code cell type literals in your code. * * @return cell type + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override public int getCellType() { @@ -118,7 +119,6 @@ final class ForkedEvaluationCell implements EvaluationCell { * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCellTypeEnum() { return _cellType; @@ -160,6 +160,7 @@ final class ForkedEvaluationCell implements EvaluationCell { * For forwards compatibility, do not hard-code cell type literals in your code. * * @return cell type of cached formula result + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override public int getCachedFormulaResultType() { @@ -170,7 +171,6 @@ final class ForkedEvaluationCell implements EvaluationCell { * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCachedFormulaResultTypeEnum() { return _masterCell.getCachedFormulaResultTypeEnum(); diff --git a/src/java/org/apache/poi/ss/usermodel/Cell.java b/src/java/org/apache/poi/ss/usermodel/Cell.java index 48b74789a..13d860823 100644 --- a/src/java/org/apache/poi/ss/usermodel/Cell.java +++ b/src/java/org/apache/poi/ss/usermodel/Cell.java @@ -167,6 +167,7 @@ public interface Cell { * For forwards compatibility, do not hard-code cell type literals in your code. * * @return the cell type + * @deprecated POI 3.15. Will return a {@link CellType} enum in the future. */ int getCellType(); @@ -178,7 +179,6 @@ public interface Cell { * @deprecated POI 3.15 beta 3 * Will be renamed to getCellType() when we make the CellType enum transition in POI 4.0. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Removal(version="4.2") CellType getCellTypeEnum(); @@ -191,6 +191,7 @@ public interface Cell { * @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING}, * {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending * on the cached value of the formula + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ int getCachedFormulaResultType(); @@ -203,7 +204,6 @@ public interface Cell { * @deprecated POI 3.15 beta 3 * Will be renamed to getCachedFormulaResultType() when we make the CellType enum transition in POI 4.0. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") CellType getCachedFormulaResultTypeEnum(); /** diff --git a/src/java/org/apache/poi/ss/usermodel/CreationHelper.java b/src/java/org/apache/poi/ss/usermodel/CreationHelper.java index 25e1cdaae..53462c1d4 100644 --- a/src/java/org/apache/poi/ss/usermodel/CreationHelper.java +++ b/src/java/org/apache/poi/ss/usermodel/CreationHelper.java @@ -17,18 +17,18 @@ package org.apache.poi.ss.usermodel; import org.apache.poi.common.usermodel.HyperlinkType; +import org.apache.poi.util.Removal; /** * An object that handles instantiating concrete * classes of the various instances one needs for * HSSF and XSSF. - * Works around a major shortcoming in Java, where we - * can't have static methods on interfaces or abstract + * Works around a limitation in Java where we + * cannot have static methods on interfaces or abstract * classes. * This allows you to get the appropriate class for * a given interface, without you having to worry - * about if you're dealing with HSSF or XSSF, despite - * Java being quite rubbish. + * about if you're dealing with HSSF or XSSF. */ public interface CreationHelper { /** @@ -46,6 +46,7 @@ public interface CreationHelper { * Creates a new Hyperlink, of the given type * @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead. */ + @Removal(version="3.17") @Deprecated Hyperlink createHyperlink(int type); From f71ae8036d555757eb397de5452f86c79a1e6501 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 06:42:20 +0000 Subject: [PATCH 17/43] bug 59791: add deprecation and removal annotations git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760641 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/hssf/usermodel/HSSFCell.java | 4 ++-- .../org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java | 4 ++-- .../apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java | 2 -- src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java | 3 ++- .../org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index 44427fce7..cfe998e05 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -446,6 +446,7 @@ public class HSSFCell implements Cell { * * Will return {@link CellType} in a future version of POI. * For forwards compatibility, do not hard-code cell type literals in your code. + * @deprecated 3.15. Will be return a {@link CellType} enum in the future. */ @Override public int getCellType() @@ -459,7 +460,6 @@ public class HSSFCell implements Cell { * @deprecated POI 3.15 beta 3 * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCellTypeEnum() { @@ -1154,6 +1154,7 @@ public class HSSFCell implements Cell { * @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING}, * {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending * on the cached value of the formula + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override public int getCachedFormulaResultType() { @@ -1169,7 +1170,6 @@ public class HSSFCell implements Cell { * @deprecated POI 3.15 beta 3 * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCachedFormulaResultTypeEnum() { if (_cellType != CellType.FORMULA) { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java index b524cc149..1771b2e35 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java @@ -55,6 +55,7 @@ final class HSSFEvaluationCell implements EvaluationCell { * For forwards compatibility, do not hard-code cell type literals in your code. * * @return cell type + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override public int getCellType() { @@ -65,7 +66,6 @@ final class HSSFEvaluationCell implements EvaluationCell { * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCellTypeEnum() { return _cell.getCellTypeEnum(); @@ -99,6 +99,7 @@ final class HSSFEvaluationCell implements EvaluationCell { * For forwards compatibility, do not hard-code cell type literals in your code. * * @return cell type of cached formula result + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override public int getCachedFormulaResultType() { @@ -109,7 +110,6 @@ final class HSSFEvaluationCell implements EvaluationCell { * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCachedFormulaResultTypeEnum() { return _cell.getCachedFormulaResultTypeEnum(); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java index 726ae87e4..e5bd1a27c 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java @@ -28,7 +28,6 @@ import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; -import org.apache.poi.util.Internal; /** * Internal POI use only - parent of XSSF and SXSSF formula evaluators @@ -69,7 +68,6 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator { * @since POI 3.15 beta 3 * @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") public CellType evaluateFormulaCellEnum(Cell cell) { if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) { return CellType._NONE; diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java index 4aa2f037e..7d2d6d25b 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -668,6 +668,7 @@ public final class XSSFCell implements Cell { * For forwards compatibility, do not hard-code cell type literals in your code. * * @return the cell type + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override public int getCellType() { @@ -699,6 +700,7 @@ public final class XSSFCell implements Cell { * @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING}, * {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending * on the cached value of the formula + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override public int getCachedFormulaResultType() { @@ -714,7 +716,6 @@ public final class XSSFCell implements Cell { * @deprecated POI 3.15 beta 3 * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCachedFormulaResultTypeEnum() { if (! isFormulaCell()) { diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java index e85b58017..129052e79 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java @@ -58,6 +58,7 @@ final class XSSFEvaluationCell implements EvaluationCell { * For forwards compatibility, do not hard-code cell type literals in your code. * * @return cell type + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override public int getCellType() { @@ -68,7 +69,6 @@ final class XSSFEvaluationCell implements EvaluationCell { * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCellTypeEnum() { return _cell.getCellTypeEnum(); From 8842d7bffdb76d9d774b91fbfd3b1e336a0b2a55 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 07:33:20 +0000 Subject: [PATCH 18/43] move BaseXSSFFormulaEvaluator#evaluateFormulaCellEnum(Cell) and HSSFFormulaEvaluator#evaluateFormulaCellEnum(Cell) up to BaseFormulaEvaluator class to reduce duplicated code git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760647 13f79535-47bb-0310-9956-ffa450edef68 --- .../hssf/usermodel/HSSFFormulaEvaluator.java | 60 ++---------------- .../poi/ss/formula/BaseFormulaEvaluator.java | 62 +++++++++++++++++++ .../poi/ss/usermodel/FormulaEvaluator.java | 1 + .../usermodel/BaseXSSFFormulaEvaluator.java | 60 ++---------------- 4 files changed, 74 insertions(+), 109 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java index 7154d7450..7eb1cfc5f 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java @@ -33,9 +33,8 @@ import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.FormulaEvaluator; +import org.apache.poi.ss.usermodel.RichTextString; import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.util.Internal; -import org.apache.poi.util.Removal; /** * Evaluates formula cells.

@@ -82,6 +81,11 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator { public static HSSFFormulaEvaluator create(HSSFWorkbook workbook, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) { return new HSSFFormulaEvaluator(workbook, stabilityClassifier, udfFinder); } + + @Override + protected RichTextString createRichTextString(String str) { + return new HSSFRichTextString(str); + } /** @@ -138,34 +142,6 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator { _bookEvaluator.notifyUpdateCell(new HSSFEvaluationCell((HSSFCell)cell)); } - /** - * If cell contains formula, it evaluates the formula, and saves the result of the formula. The - * cell remains as a formula cell. If the cell does not contain formula, rather than throwing an - * exception, this method returns {@link CellType#_NONE} and leaves the cell unchanged. - * - * Note that the type of the formula result is returned, so you know what kind of - * cached formula result is also stored with the formula. - *

-     * CellType evaluatedCellType = evaluator.evaluateFormulaCell(cell);
-     * 
- * Be aware that your cell will hold both the formula, and the result. If you want the cell - * replaced with the result of the formula, use {@link #evaluateInCell(org.apache.poi.ss.usermodel.Cell)} - * @param cell The cell to evaluate - * @return {@link CellType#_NONE} for non-formula cells, or the type of the formula result - * @since POI 3.15 beta 3 - * @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791. - */ - @Override - public CellType evaluateFormulaCellEnum(Cell cell) { - if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) { - return CellType._NONE; - } - CellValue cv = evaluateFormulaCellValue(cell); - // cell remains a formula cell, but the cached value is changed - setCellValue(cell, cv); - return cv.getCellTypeEnum(); - } - /** * If cell contains formula, it evaluates the formula, and * puts the formula result back into the cell, in place @@ -195,30 +171,6 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator { return result; } - private static void setCellValue(Cell cell, CellValue cv) { - CellType cellType = cv.getCellTypeEnum(); - switch (cellType) { - case BOOLEAN: - cell.setCellValue(cv.getBooleanValue()); - break; - case ERROR: - cell.setCellErrorValue(cv.getErrorValue()); - break; - case NUMERIC: - cell.setCellValue(cv.getNumberValue()); - break; - case STRING: - cell.setCellValue(new HSSFRichTextString(cv.getStringValue())); - break; - case BLANK: - // never happens - blanks eventually get translated to zero - case FORMULA: - // this will never happen, we have already evaluated the formula - default: - throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); - } - } - /** * Loops over all cells in all sheets of the supplied * workbook. diff --git a/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java b/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java index 7c459abb4..c52c41f9b 100644 --- a/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java +++ b/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java @@ -19,10 +19,13 @@ package org.apache.poi.ss.formula; import java.util.Map; +import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; +import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.ss.usermodel.FormulaEvaluator; +import org.apache.poi.ss.usermodel.RichTextString; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; @@ -131,6 +134,38 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook public int evaluateFormulaCell(Cell cell) { return evaluateFormulaCellEnum(cell).getCode(); } + + /** + * If cell contains formula, it evaluates the formula, + * and saves the result of the formula. The cell + * remains as a formula cell. + * Else if cell does not contain formula, this method leaves + * the cell unchanged. + * Note that the type of the formula result is returned, + * so you know what kind of value is also stored with + * the formula. + *
+     * CellType evaluatedCellType = evaluator.evaluateFormulaCellEnum(cell);
+     * 
+ * Be aware that your cell will hold both the formula, + * and the result. If you want the cell replaced with + * the result of the formula, use {@link #evaluate(org.apache.poi.ss.usermodel.Cell)} } + * @param cell The cell to evaluate + * @return The type of the formula result (the cell's type remains as CellType.FORMULA however) + * If cell is not a formula cell, returns {@link CellType#_NONE} rather than throwing an exception. + * @since POI 3.15 beta 3 + * @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791. + */ + @Override + public CellType evaluateFormulaCellEnum(Cell cell) { + if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) { + return CellType._NONE; + } + CellValue cv = evaluateFormulaCellValue(cell); + // cell remains a formula cell, but the cached value is changed + setCellValue(cell, cv); + return cv.getCellTypeEnum(); + } protected static void setCellType(Cell cell, CellValue cv) { CellType cellType = cv.getCellTypeEnum(); @@ -151,6 +186,33 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); } } + + protected abstract RichTextString createRichTextString(String str); + + protected void setCellValue(Cell cell, CellValue cv) { + CellType cellType = cv.getCellTypeEnum(); + switch (cellType) { + case BOOLEAN: + cell.setCellValue(cv.getBooleanValue()); + break; + case ERROR: + cell.setCellErrorValue(cv.getErrorValue()); + break; + case NUMERIC: + cell.setCellValue(cv.getNumberValue()); + break; + case STRING: + cell.setCellValue(createRichTextString(cv.getStringValue())); + break; + case BLANK: + // never happens - blanks eventually get translated to zero + case FORMULA: + // this will never happen, we have already evaluated the formula + default: + throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); + } + } + /** * Loops over all cells in all sheets of the supplied diff --git a/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java b/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java index be75ff9d5..357bd073a 100644 --- a/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java +++ b/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java @@ -101,6 +101,7 @@ public interface FormulaEvaluator { * or one of {@link CellType#NUMERIC}, {@link CellType#STRING}, * {@link CellType#BOOLEAN}, {@link CellType#ERROR} * Note: the cell's type remains as CellType.FORMULA however. + * @deprecated 3.15. Will return a {@link CellType} enum in the future */ int evaluateFormulaCell(Cell cell); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java index e5bd1a27c..3c72dfe79 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java @@ -28,6 +28,7 @@ import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; +import org.apache.poi.ss.usermodel.RichTextString; /** * Internal POI use only - parent of XSSF and SXSSF formula evaluators @@ -36,6 +37,10 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator { protected BaseXSSFFormulaEvaluator(WorkbookEvaluator bookEvaluator) { super(bookEvaluator); } + @Override + protected RichTextString createRichTextString(String str) { + return new XSSFRichTextString(str); + } public void notifySetFormula(Cell cell) { _bookEvaluator.notifyUpdateCell(new XSSFEvaluationCell((XSSFCell)cell)); @@ -47,37 +52,6 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator { _bookEvaluator.notifyUpdateCell(new XSSFEvaluationCell((XSSFCell)cell)); } - /** - * If cell contains formula, it evaluates the formula, - * and saves the result of the formula. The cell - * remains as a formula cell. - * Else if cell does not contain formula, this method leaves - * the cell unchanged. - * Note that the type of the formula result is returned, - * so you know what kind of value is also stored with - * the formula. - *
-     * CellType evaluatedCellType = evaluator.evaluateFormulaCellEnum(cell);
-     * 
- * Be aware that your cell will hold both the formula, - * and the result. If you want the cell replaced with - * the result of the formula, use {@link #evaluate(org.apache.poi.ss.usermodel.Cell)} } - * @param cell The cell to evaluate - * @return The type of the formula result (the cell's type remains as CellType.FORMULA however) - * If cell is not a formula cell, returns {@link CellType#_NONE} rather than throwing an exception. - * @since POI 3.15 beta 3 - * @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791. - */ - public CellType evaluateFormulaCellEnum(Cell cell) { - if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) { - return CellType._NONE; - } - CellValue cv = evaluateFormulaCellValue(cell); - // cell remains a formula cell, but the cached value is changed - setCellValue(cell, cv); - return cv.getCellTypeEnum(); - } - /** * If cell contains formula, it evaluates the formula, and * puts the formula result back into the cell, in place @@ -94,30 +68,6 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator { } } - private static void setCellValue(Cell cell, CellValue cv) { - CellType cellType = cv.getCellTypeEnum(); - switch (cellType) { - case BOOLEAN: - cell.setCellValue(cv.getBooleanValue()); - break; - case ERROR: - cell.setCellErrorValue(cv.getErrorValue()); - break; - case NUMERIC: - cell.setCellValue(cv.getNumberValue()); - break; - case STRING: - cell.setCellValue(new XSSFRichTextString(cv.getStringValue())); - break; - case BLANK: - // never happens - blanks eventually get translated to zero - case FORMULA: - // this will never happen, we have already evaluated the formula - default: - throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); - } - } - /** * Turns a XSSFCell / SXSSFCell into a XSSFEvaluationCell */ From ed7258906f625a311b51c3e2e93f896af8a4ed88 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 07:53:58 +0000 Subject: [PATCH 19/43] move HSSFFormulaEvaluator#evaluateInCell and BaseXSSFFormulaEvaluator#evaluateInCell(Cell) up to BaseFormulaEvaluator to reduce duplicated code git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760651 13f79535-47bb-0310-9956-ffa450edef68 --- .../hssf/usermodel/HSSFFormulaEvaluator.java | 29 ++-------------- .../poi/ss/formula/BaseFormulaEvaluator.java | 33 +++++++++++++++++-- .../xssf/streaming/SXSSFFormulaEvaluator.java | 19 ++--------- .../usermodel/BaseXSSFFormulaEvaluator.java | 16 --------- .../xssf/usermodel/XSSFFormulaEvaluator.java | 29 +++++----------- .../usermodel/TestXSSFFormulaEvaluation.java | 11 +++++++ .../usermodel/BaseTestFormulaEvaluator.java | 12 +++++++ 7 files changed, 66 insertions(+), 83 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java index 7eb1cfc5f..20c7ffa1e 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java @@ -30,7 +30,6 @@ import org.apache.poi.ss.formula.eval.StringValueEval; import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.RichTextString; @@ -141,34 +140,10 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator { public void notifySetFormula(Cell cell) { _bookEvaluator.notifyUpdateCell(new HSSFEvaluationCell((HSSFCell)cell)); } - - /** - * If cell contains formula, it evaluates the formula, and - * puts the formula result back into the cell, in place - * of the old formula. - * Else if cell does not contain formula, this method leaves - * the cell unchanged. - * Note that the same instance of HSSFCell is returned to - * allow chained calls like: - *
-     * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
-     * 
- * Be aware that your cell value will be changed to hold the - * result of the formula. If you simply want the formula - * value computed for you, use {@link #evaluateFormulaCellEnum(Cell)}} - */ + @Override public HSSFCell evaluateInCell(Cell cell) { - if (cell == null) { - return null; - } - HSSFCell result = (HSSFCell) cell; - if (cell.getCellTypeEnum() == CellType.FORMULA) { - CellValue cv = evaluateFormulaCellValue(cell); - setCellValue(cell, cv); - setCellType(cell, cv); // cell will no longer be a formula cell - } - return result; + return (HSSFCell) super.evaluateInCell(cell); } /** diff --git a/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java b/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java index c52c41f9b..6cd19f5bf 100644 --- a/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java +++ b/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java @@ -19,11 +19,9 @@ package org.apache.poi.ss.formula; import java.util.Map; -import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; -import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.RichTextString; import org.apache.poi.ss.usermodel.Row; @@ -111,6 +109,37 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook throw new IllegalStateException("Bad cell type (" + cell.getCellTypeEnum() + ")"); } } + + /** + * If cell contains formula, it evaluates the formula, and + * puts the formula result back into the cell, in place + * of the old formula. + * Else if cell does not contain formula, this method leaves + * the cell unchanged. + * Note that the same instance of HSSFCell is returned to + * allow chained calls like: + *
+     * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
+     * 
+ * Be aware that your cell value will be changed to hold the + * result of the formula. If you simply want the formula + * value computed for you, use {@link #evaluateFormulaCellEnum(Cell)}} + * @param cell + * @return the {@code cell} that was passed in, allowing for chained calls + */ + @Override + public Cell evaluateInCell(Cell cell) { + if (cell == null) { + return null; + } + Cell result = cell; + if (cell.getCellTypeEnum() == CellType.FORMULA) { + CellValue cv = evaluateFormulaCellValue(cell); + setCellValue(cell, cv); + setCellType(cell, cv); // cell will no longer be a formula cell + } + return result; + } protected abstract CellValue evaluateFormulaCellValue(Cell cell); diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFFormulaEvaluator.java index ac72bc7f3..0ac776ffc 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFFormulaEvaluator.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFFormulaEvaluator.java @@ -72,24 +72,9 @@ public final class SXSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator { return new SXSSFEvaluationCell((SXSSFCell)cell); } - /** - * If cell contains formula, it evaluates the formula, and - * puts the formula result back into the cell, in place - * of the old formula. - * Else if cell does not contain formula, this method leaves - * the cell unchanged. - * Note that the same instance of SXSSFCell is returned to - * allow chained calls like: - *
-     * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
-     * 
- * Be aware that your cell value will be changed to hold the - * result of the formula. If you simply want the formula - * value computed for you, use {@link #evaluateFormulaCellEnum(org.apache.poi.ss.usermodel.Cell)} } - */ + @Override public SXSSFCell evaluateInCell(Cell cell) { - doEvaluateInCell(cell); - return (SXSSFCell)cell; + return (SXSSFCell) super.evaluateInCell(cell); } /** diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java index 3c72dfe79..780126c3d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java @@ -52,22 +52,6 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator { _bookEvaluator.notifyUpdateCell(new XSSFEvaluationCell((XSSFCell)cell)); } - /** - * If cell contains formula, it evaluates the formula, and - * puts the formula result back into the cell, in place - * of the old formula. - * Else if cell does not contain formula, this method leaves - * the cell unchanged. - */ - protected void doEvaluateInCell(Cell cell) { - if (cell == null) return; - if (cell.getCellTypeEnum() == CellType.FORMULA) { - CellValue cv = evaluateFormulaCellValue(cell); - setCellType(cell, cv); // cell will no longer be a formula cell - setCellValue(cell, cv); - } - } - /** * Turns a XSSFCell / SXSSFCell into a XSSFEvaluationCell */ diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java index fc456b7e5..e63f47b46 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java @@ -23,6 +23,8 @@ import org.apache.poi.ss.formula.IStabilityClassifier; import org.apache.poi.ss.formula.WorkbookEvaluator; import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.CellValue; /** * Evaluates formula cells.

@@ -55,27 +57,6 @@ public final class XSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator { return new XSSFFormulaEvaluator(workbook, stabilityClassifier, udfFinder); } - /** - * If cell contains formula, it evaluates the formula, and - * puts the formula result back into the cell, in place - * of the old formula. - * Else if cell does not contain formula, this method leaves - * the cell unchanged. - * Note that the same instance of XSSFCell is returned to - * allow chained calls like: - *

-     * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
-     * 
- * Be aware that your cell value will be changed to hold the - * result of the formula. If you simply want the formula - * value computed for you, use {@link #evaluateFormulaCellEnum(org.apache.poi.ss.usermodel.Cell)} } - * @param cell - */ - public XSSFCell evaluateInCell(Cell cell) { - doEvaluateInCell(cell); - return (XSSFCell)cell; - } - /** * Loops over all cells in all sheets of the supplied * workbook. @@ -90,6 +71,12 @@ public final class XSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator { public static void evaluateAllFormulaCells(XSSFWorkbook wb) { BaseFormulaEvaluator.evaluateAllFormulaCells(wb); } + + @Override + public XSSFCell evaluateInCell(Cell cell) { + return (XSSFCell) super.evaluateInCell(cell); + } + /** * Loops over all cells in all sheets of the supplied * workbook. diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java index 6dcaef960..84a4aa680 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java @@ -682,4 +682,15 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator { value = evaluator.evaluate(cell); assertEquals(1, value.getNumberValue(), 0.001); } + + @Test + public void evaluateInCellReturnsSameDataType() throws IOException { + XSSFWorkbook wb = new XSSFWorkbook(); + wb.createSheet().createRow(0).createCell(0); + XSSFFormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); + XSSFCell cell = wb.getSheetAt(0).getRow(0).getCell(0); + XSSFCell same = evaluator.evaluateInCell(cell); + assertSame(cell, same); + wb.close(); + } } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java index 8a16d3a64..c4922a7c8 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java @@ -19,6 +19,7 @@ package org.apache.poi.ss.usermodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import java.io.IOException; @@ -326,4 +327,15 @@ public abstract class BaseTestFormulaEvaluator { wb.close(); } + + @Test + public void evaluateInCellReturnsSameCell() throws IOException { + Workbook wb = _testDataProvider.createWorkbook(); + wb.createSheet().createRow(0).createCell(0); + FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); + Cell cell = wb.getSheetAt(0).getRow(0).getCell(0); + Cell same = evaluator.evaluateInCell(cell); + assertSame(cell, same); + wb.close(); + } } \ No newline at end of file From 6219cc6664d2e2c2488c8ea2f28b58b19831aeec Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 14 Sep 2016 12:35:34 +0000 Subject: [PATCH 20/43] Unit test for bug #60128, showing that calling close on a broken package cleans up file or stream git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760693 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/openxml4j/util/ZipEntrySource.java | 5 ++ .../openxml4j/util/ZipFileZipEntrySource.java | 3 ++ .../util/ZipInputStreamZipEntrySource.java | 3 ++ .../poi/openxml4j/opc/TestZipPackage.java | 50 +++++++++++++++++++ .../poi/poifs/crypt/TestSecureTempZip.java | 8 +++ 5 files changed, 69 insertions(+) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipEntrySource.java b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipEntrySource.java index 1d64ffe4e..51ad32ce6 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipEntrySource.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipEntrySource.java @@ -45,4 +45,9 @@ public interface ZipEntrySource { * resources may be freed */ public void close() throws IOException; + + /** + * Has close been called already? + */ + public boolean isClosed(); } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java index f4117f44b..09317d361 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java @@ -39,6 +39,9 @@ public class ZipFileZipEntrySource implements ZipEntrySource { } zipArchive = null; } + public boolean isClosed() { + return (zipArchive == null); + } public Enumeration getEntries() { if (zipArchive == null) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java index 36b69ac25..4c2b9df3e 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java @@ -76,6 +76,9 @@ public class ZipInputStreamZipEntrySource implements ZipEntrySource { // Free the memory zipEntries = null; } + public boolean isClosed() { + return (zipEntries == null); + } /** * Why oh why oh why are Iterator and Enumeration diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestZipPackage.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestZipPackage.java index 7f174e07a..698f194c4 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestZipPackage.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestZipPackage.java @@ -33,11 +33,14 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; +import org.apache.poi.POIDataSamples; import org.apache.poi.POITextExtractor; import org.apache.poi.POIXMLException; import org.apache.poi.extractor.ExtractorFactory; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; +import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException; +import org.apache.poi.openxml4j.exceptions.ODFNotOfficeXmlFileException; import org.apache.poi.sl.usermodel.SlideShow; import org.apache.poi.sl.usermodel.SlideShowFactory; import org.apache.poi.ss.usermodel.Workbook; @@ -194,6 +197,53 @@ public class TestZipPackage { } catch (Exception e) { } assertTrue("Can't delete tmp file", tmp.delete()); + } + + /** + * If ZipPackage is passed an invalid file, a call to close + * (eg from the OPCPackage open method) should tidy up the + * stream / file the broken file is being read from. + * See bug #60128 for more + */ + @Test + public void testTidyStreamOnInvalidFile() throws Exception { + // Spreadsheet has a good mix of alternate file types + POIDataSamples files = POIDataSamples.getSpreadSheetInstance(); + + File[] notValidF = new File[] { + files.getFile("SampleSS.ods"), files.getFile("SampleSS.txt") + }; + InputStream[] notValidS = new InputStream[] { + files.openResourceAsStream("SampleSS.ods"), files.openResourceAsStream("SampleSS.txt") + }; + for (File notValid : notValidF) { + ZipPackage pkg = new ZipPackage(notValid, PackageAccess.READ); + assertNotNull(pkg.getZipArchive()); + assertFalse(pkg.getZipArchive().isClosed()); + try { + pkg.getParts(); + fail("Shouldn't work"); + } catch (ODFNotOfficeXmlFileException e) { + } catch (NotOfficeXmlFileException ne) {} + pkg.close(); + + assertNotNull(pkg.getZipArchive()); + assertTrue(pkg.getZipArchive().isClosed()); + } + for (InputStream notValid : notValidS) { + ZipPackage pkg = new ZipPackage(notValid, PackageAccess.READ); + assertNotNull(pkg.getZipArchive()); + assertFalse(pkg.getZipArchive().isClosed()); + try { + pkg.getParts(); + fail("Shouldn't work"); + } catch (ODFNotOfficeXmlFileException e) { + } catch (NotOfficeXmlFileException ne) {} + pkg.close(); + + assertNotNull(pkg.getZipArchive()); + assertTrue(pkg.getZipArchive().isClosed()); + } } } diff --git a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSecureTempZip.java b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSecureTempZip.java index 4d4c5df34..868a38227 100644 --- a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSecureTempZip.java +++ b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSecureTempZip.java @@ -149,10 +149,12 @@ public class TestSecureTempZip { static class AesZipFileZipEntrySource implements ZipEntrySource { final ZipFile zipFile; final Cipher ci; + boolean closed; AesZipFileZipEntrySource(ZipFile zipFile, Cipher ci) { this.zipFile = zipFile; this.ci = ci; + this.closed = false; } /** @@ -172,6 +174,12 @@ public class TestSecureTempZip { @Override public void close() throws IOException { zipFile.close(); + closed = true; + } + + @Override + public boolean isClosed() { + return closed; } } } From ed5cd06fb740b26eb91d5cde0f95adc1c6478ef0 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 12:57:39 +0000 Subject: [PATCH 21/43] bug 60128: close open file descriptors when exceptions are thrown from OPCPackage.open git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760702 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/openxml4j/opc/OPCPackage.java | 17 ++- .../apache/poi/openxml4j/opc/ZipPackage.java | 118 ++++++++++++------ .../poi/openxml4j/util/ZipSecureFile.java | 6 +- .../poi/extractor/TestExtractorFactory.java | 6 +- .../apache/poi/openxml4j/opc/TestPackage.java | 18 +++ .../poi/openxml4j/opc/TestZipPackage.java | 6 + test-data/openxml4j/invalid.xlsx | Bin 0 -> 22 bytes 7 files changed, 130 insertions(+), 41 deletions(-) create mode 100644 test-data/openxml4j/invalid.xlsx diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java index e029d7dec..b7720ee42 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java @@ -248,9 +248,10 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { * @throws InvalidFormatException * If the specified file doesn't exist, and a parsing error * occur. + * @throws InvalidOperationException */ public static OPCPackage open(String path, PackageAccess access) - throws InvalidFormatException { + throws InvalidFormatException, InvalidOperationException { if (path == null || "".equals(path.trim())) { throw new IllegalArgumentException("'path' must be given"); } @@ -261,8 +262,20 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { } OPCPackage pack = new ZipPackage(path, access); + boolean success = false; if (pack.partList == null && access != PackageAccess.WRITE) { - pack.getParts(); + try { + pack.getParts(); + success = true; + } finally { + if (! success) { + try { + pack.close(); + } catch (final IOException e) { + throw new InvalidOperationException("Could not close OPCPackage while cleaning up", e); + } + } + } } pack.originalPackagePath = new File(path).getAbsolutePath(); return pack; diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java index fe4d6f1ed..8f7efa02c 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java @@ -19,6 +19,7 @@ package org.apache.poi.openxml4j.opc; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -88,9 +89,18 @@ public final class ZipPackage extends OPCPackage { */ ZipPackage(InputStream in, PackageAccess access) throws IOException { super(access); - @SuppressWarnings("resource") ThresholdInputStream zis = ZipHelper.openZipStream(in); - this.zipArchive = new ZipInputStreamZipEntrySource(zis); + try { + this.zipArchive = new ZipInputStreamZipEntrySource(zis); + } catch (final IOException e) { + try { + zis.close(); + } catch (final IOException e2) { + e2.addSuppressed(e); + throw new IOException("Failed to close zip input stream while cleaning up", e2); + } + throw new IOException("Failed to read zip entry source", e); + } } /** @@ -100,8 +110,9 @@ public final class ZipPackage extends OPCPackage { * The path of the file to open or create. * @param access * The package access mode. + * @throws InvalidOperationException */ - ZipPackage(String path, PackageAccess access) { + ZipPackage(String path, PackageAccess access) throws InvalidOperationException { this(new File(path), access); } @@ -112,9 +123,9 @@ public final class ZipPackage extends OPCPackage { * The file to open or create. * @param access * The package access mode. + * @throws InvalidOperationException */ - @SuppressWarnings("resource") - ZipPackage(File file, PackageAccess access) { + ZipPackage(File file, PackageAccess access) throws InvalidOperationException { super(access); ZipEntrySource ze; @@ -127,36 +138,72 @@ public final class ZipPackage extends OPCPackage { throw new InvalidOperationException("Can't open the specified file: '" + file + "'", e); } logger.log(POILogger.ERROR, "Error in zip file "+file+" - falling back to stream processing (i.e. ignoring zip central directory)"); - // some zips can't be opened via ZipFile in JDK6, as the central directory - // contains either non-latin entries or the compression type can't be handled - // the workaround is to iterate over the stream and not the directory - FileInputStream fis = null; - ThresholdInputStream zis = null; - try { - fis = new FileInputStream(file); - zis = ZipHelper.openZipStream(fis); - ze = new ZipInputStreamZipEntrySource(zis); - } catch (IOException e2) { - if (zis != null) { - try { - zis.close(); - } catch (IOException e3) { - throw new InvalidOperationException("Can't open the specified file: '" + file + "'"+ - " and couldn't close the file input stream", e); - } - } else if (fis != null) { - try { - fis.close(); - } catch (IOException e3) { - throw new InvalidOperationException("Can't open the specified file: '" + file + "'"+ - " and couldn't close the file input stream", e); - } - } - throw new InvalidOperationException("Can't open the specified file: '" + file + "'", e); - } + ze = openZipEntrySourceStream(file); } this.zipArchive = ze; } + + private static ZipEntrySource openZipEntrySourceStream(File file) throws InvalidOperationException { + final FileInputStream fis; + // Acquire a resource that is needed to read the next level of openZipEntrySourceStream + try { + // open the file input stream + fis = new FileInputStream(file); + } catch (final FileNotFoundException e) { + // If the source cannot be acquired, abort (no resources to free at this level) + throw new InvalidOperationException("Can't open the specified file input stream from file: '" + file + "'", e); + } + + // If an error occurs while reading the next level of openZipEntrySourceStream, free the acquired resource + try { + // read from the file input stream + return openZipEntrySourceStream(fis); + } catch (final Exception e) { + try { + // abort: close the file input stream + fis.close(); + } catch (final IOException e2) { + throw new InvalidOperationException("Could not close the specified file input stream from file: '" + file + "'", e2); + } + throw new InvalidOperationException("Failed to read the file input stream from file: '" + file + "'", e); + } + } + + private static ZipEntrySource openZipEntrySourceStream(FileInputStream fis) throws InvalidOperationException { + final ThresholdInputStream zis; + // Acquire a resource that is needed to read the next level of openZipEntrySourceStream + try { + // open the zip input stream + zis = ZipHelper.openZipStream(fis); + } catch (final IOException e) { + // If the source cannot be acquired, abort (no resources to free at this level) + throw new InvalidOperationException("Could not open the file input stream", e); + } + + // If an error occurs while reading the next level of openZipEntrySourceStream, free the acquired resource + try { + // read from the zip input stream + return openZipEntrySourceStream(zis); + } catch (final Exception e) { + try { + // abort: close the zip input stream + zis.close(); + } catch (final IOException e2) { + throw new InvalidOperationException("Failed to read the zip entry source stream and could not close the zip input stream", e2); + } + throw new InvalidOperationException("Failed to read the zip entry source stream"); + } + } + + private static ZipEntrySource openZipEntrySourceStream(ThresholdInputStream zis) throws InvalidOperationException { + // Acquire the final level resource. If this is acquired successfully, the zip package was read successfully from the input stream + try { + // open the zip entry source stream + return new ZipInputStreamZipEntrySource(zis); + } catch (IOException e) { + throw new InvalidOperationException("Could not open the specified zip entry source stream", e); + } + } /** * Constructor. Opens a Zip based Open XML document from @@ -220,11 +267,12 @@ public final class ZipPackage extends OPCPackage { boolean hasSettingsXML = false; entries = this.zipArchive.getEntries(); while (entries.hasMoreElements()) { - ZipEntry entry = entries.nextElement(); - if (entry.getName().equals("mimetype")) { + final ZipEntry entry = entries.nextElement(); + final String name = entry.getName(); + if ("mimetype".equals(name)) { hasMimetype = true; } - if (entry.getName().equals("settings.xml")) { + if ("settings.xml".equals(name)) { hasSettingsXML = true; } numEntries++; diff --git a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipSecureFile.java b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipSecureFile.java index 13369a5ed..9000656e5 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipSecureFile.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipSecureFile.java @@ -134,15 +134,15 @@ public class ZipSecureFile extends ZipFile { return MAX_TEXT_SIZE; } - public ZipSecureFile(File file, int mode) throws IOException { + public ZipSecureFile(File file, int mode) throws ZipException, IOException { super(file, mode); } - public ZipSecureFile(File file) throws IOException { + public ZipSecureFile(File file) throws ZipException, IOException { super(file); } - public ZipSecureFile(String name) throws IOException { + public ZipSecureFile(String name) throws ZipException, IOException { super(name); } diff --git a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java index 0aa022332..9d206f719 100644 --- a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java +++ b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java @@ -682,9 +682,12 @@ public class TestExtractorFactory { // Text try { ExtractorFactory.createExtractor(OPCPackage.open(txt.toString())); - fail(); + fail("TestExtractorFactory.testPackage() failed on " + txt.toString()); } catch(UnsupportedFileFormatException e) { // Good + } catch (Exception e) { + System.out.println("TestExtractorFactory.testPackage() failed on " + txt.toString()); + throw e; } } @@ -942,6 +945,7 @@ public class TestExtractorFactory { "openxml4j/OPCCompliance_CoreProperties_OnlyOneCorePropertiesPartFAIL.docx", "openxml4j/OPCCompliance_CoreProperties_UnauthorizedXMLLangAttributeFAIL.docx", "openxml4j/OPCCompliance_DerivedPartNameFAIL.docx", + "openxml4j/invalid.xlsx", "spreadsheet/54764-2.xlsx", // see TestXSSFBugs.bug54764() "spreadsheet/54764.xlsx", // see TestXSSFBugs.bug54764() "spreadsheet/Simple.xlsb", diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java index d84ecab81..5f83bc52d 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java @@ -943,4 +943,22 @@ public final class TestPackage { ZipSecureFile.setMaxTextSize(before); } } + + // bug 60128 + @Test + public void testCorruptFile() throws IOException { + OPCPackage pkg = null; + File file = OpenXML4JTestDataSamples.getSampleFile("invalid.xlsx"); + try { + pkg = OPCPackage.open(file, PackageAccess.READ); + } catch (Exception e) { + System.out.println(e.getClass().getName()); + System.out.println(e.getMessage()); + e.printStackTrace(); + } finally { + if (pkg != null) { + pkg.close(); + } + } + } } diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestZipPackage.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestZipPackage.java index 698f194c4..0989d10cb 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestZipPackage.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestZipPackage.java @@ -184,6 +184,7 @@ public class TestZipPackage { public void testClosingStreamOnException() throws IOException { InputStream is = OpenXML4JTestDataSamples.openSampleStream("dcterms_bug_56479.zip"); File tmp = File.createTempFile("poi-test-truncated-zip", ""); + // create a corrupted zip file by truncating a valid zip file to the first 100 bytes OutputStream os = new FileOutputStream(tmp); for (int i = 0; i < 100; i++) { os.write(is.read()); @@ -192,10 +193,15 @@ public class TestZipPackage { os.close(); is.close(); + // feed the corrupted zip file to OPCPackage try { OPCPackage.open(tmp, PackageAccess.READ); } catch (Exception e) { + // expected: the zip file is invalid + // this test does not care if open() throws an exception or not. } + // If the stream is not closed on exception, it will keep a file descriptor to tmp, + // and requests to the OS to delete the file will fail. assertTrue("Can't delete tmp file", tmp.delete()); } diff --git a/test-data/openxml4j/invalid.xlsx b/test-data/openxml4j/invalid.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..15cb0ecb3e219d1701294bfdf0fe3f5cb5d208e7 GIT binary patch literal 22 NcmWIWW@Tf*000g10H*)| literal 0 HcmV?d00001 From d34b6a995b8ef138212746f2459135e6854b8f68 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 13:28:27 +0000 Subject: [PATCH 22/43] give more helpful exceptions rather than returning null when zip file cannot be opened git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760708 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/openxml4j/opc/internal/ZipHelper.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java index 632d2af26..b674b3ad2 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java @@ -19,6 +19,7 @@ package org.apache.poi.openxml4j.opc.internal; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.PushbackInputStream; @@ -239,10 +240,15 @@ public final class ZipHelper { * @param file * The file to open. * @return The zip archive freshly open. + * @throws IOException if the zip file cannot be opened or closed to read the header signature + * @throws NotOfficeXmlFileException if stream does not start with zip header signature */ - public static ZipFile openZipFile(File file) throws IOException { + public static ZipFile openZipFile(File file) throws IOException, NotOfficeXmlFileException { if (!file.exists()) { - return null; + throw new FileNotFoundException("File does not exist"); + } + if (file.isDirectory()) { + throw new IOException("File is a directory"); } // Peek at the first few bytes to sanity check From 2104b1d585d6b14c206ddcbd06bb7ac5d0825f36 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 13:55:39 +0000 Subject: [PATCH 23/43] bug 60128: close opened resources to avoid leaks; add exception as cause where available for more context for raised exceptions. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760710 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/openxml4j/opc/ZipPackage.java | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java index 8f7efa02c..e2f4c8e70 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java @@ -53,6 +53,9 @@ import org.apache.poi.util.TempFile; * Physical zip package. */ public final class ZipPackage extends OPCPackage { + private static final String MIMETYPE = "mimetype"; + private static final String SETTINGS_XML = "settings.xml"; + private static POILogger logger = POILogFactory.getLogger(ZipPackage.class); /** @@ -191,7 +194,7 @@ public final class ZipPackage extends OPCPackage { } catch (final IOException e2) { throw new InvalidOperationException("Failed to read the zip entry source stream and could not close the zip input stream", e2); } - throw new InvalidOperationException("Failed to read the zip entry source stream"); + throw new InvalidOperationException("Failed to read the zip entry source stream", e); } } @@ -253,7 +256,7 @@ public final class ZipPackage extends OPCPackage { this.contentTypeManager = new ZipContentTypeManager( getZipArchive().getInputStream(entry), this); } catch (IOException e) { - throw new InvalidFormatException(e.getMessage()); + throw new InvalidFormatException(e.getMessage(), e); } break; } @@ -269,10 +272,10 @@ public final class ZipPackage extends OPCPackage { while (entries.hasMoreElements()) { final ZipEntry entry = entries.nextElement(); final String name = entry.getName(); - if ("mimetype".equals(name)) { + if (MIMETYPE.equals(name)) { hasMimetype = true; } - if ("settings.xml".equals(name)) { + if (SETTINGS_XML.equals(name)) { hasSettingsXML = true; } numEntries++; @@ -307,10 +310,10 @@ public final class ZipPackage extends OPCPackage { String contentType = contentTypeManager.getContentType(partName); if (contentType != null && contentType.equals(ContentTypes.RELATIONSHIPS_PART)) { try { - partList.put(partName, new ZipPackagePart(this, entry, - partName, contentType)); + PackagePart part = new ZipPackagePart(this, entry, partName, contentType); + partList.put(partName, part); } catch (InvalidOperationException e) { - throw new InvalidFormatException(e.getMessage()); + throw new InvalidFormatException(e.getMessage(), e); } } } @@ -322,17 +325,16 @@ public final class ZipPackage extends OPCPackage { PackagePartName partName = buildPartName(entry); if(partName == null) continue; - String contentType = contentTypeManager - .getContentType(partName); + String contentType = contentTypeManager.getContentType(partName); if (contentType != null && contentType.equals(ContentTypes.RELATIONSHIPS_PART)) { // Already handled } else if (contentType != null) { try { - partList.put(partName, new ZipPackagePart(this, entry, - partName, contentType)); + PackagePart part = new ZipPackagePart(this, entry, partName, contentType); + partList.put(partName, part); } catch (InvalidOperationException e) { - throw new InvalidFormatException(e.getMessage()); + throw new InvalidFormatException(e.getMessage(), e); } } else { throw new InvalidFormatException( @@ -440,20 +442,22 @@ public final class ZipPackage extends OPCPackage { // Save the final package to a temporary file try { save(tempFile); - - // Close the current zip file, so we can - // overwrite it on all platforms - this.zipArchive.close(); - // Copy the new file over the old one - FileHelper.copyFile(tempFile, targetFile); } finally { - // Either the save operation succeed or not, we delete the - // temporary file - if (!tempFile.delete()) { - logger - .log(POILogger.WARN,"The temporary file: '" - + targetFile.getAbsolutePath() - + "' cannot be deleted ! Make sure that no other application use it."); + try { + // Close the current zip file, so we can + // overwrite it on all platforms + this.zipArchive.close(); + // Copy the new file over the old one + FileHelper.copyFile(tempFile, targetFile); + } finally { + // Either the save operation succeed or not, we delete the + // temporary file + if (!tempFile.delete()) { + logger + .log(POILogger.WARN,"The temporary file: '" + + targetFile.getAbsolutePath() + + "' cannot be deleted ! Make sure that no other application use it."); + } } } } else { From 6ed8aaada619d8c5a880449481ea894986af9af9 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 13:56:03 +0000 Subject: [PATCH 24/43] make logger final git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760711 13f79535-47bb-0310-9956-ffa450edef68 --- src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java index e2f4c8e70..3872e7381 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java @@ -56,7 +56,7 @@ public final class ZipPackage extends OPCPackage { private static final String MIMETYPE = "mimetype"; private static final String SETTINGS_XML = "settings.xml"; - private static POILogger logger = POILogFactory.getLogger(ZipPackage.class); + private static final POILogger logger = POILogFactory.getLogger(ZipPackage.class); /** * Zip archive, as either a file on disk, From 5fc5680d157600ea499990cf4f90270a99964c03 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 14 Sep 2016 14:59:00 +0000 Subject: [PATCH 25/43] Patches from Patrick Zimmermann from bugs #60130 and #60131 - DGET fix for empty cells and D* coding improvements git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760717 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/ss/formula/functions/DGet.java | 19 ++- .../poi/ss/formula/functions/DStarRunner.java | 142 +++++++----------- test-data/spreadsheet/DGet.xls | Bin 51712 -> 53760 bytes 3 files changed, 67 insertions(+), 94 deletions(-) diff --git a/src/java/org/apache/poi/ss/formula/functions/DGet.java b/src/java/org/apache/poi/ss/formula/functions/DGet.java index 91a9934b5..0bf9cc262 100644 --- a/src/java/org/apache/poi/ss/formula/functions/DGet.java +++ b/src/java/org/apache/poi/ss/formula/functions/DGet.java @@ -17,7 +17,10 @@ package org.apache.poi.ss.formula.functions; +import org.apache.poi.ss.formula.eval.BlankEval; import org.apache.poi.ss.formula.eval.ErrorEval; +import org.apache.poi.ss.formula.eval.EvaluationException; +import org.apache.poi.ss.formula.eval.OperandResolver; import org.apache.poi.ss.formula.eval.ValueEval; /** @@ -46,8 +49,18 @@ public final class DGet implements IDStarAlgorithm { public ValueEval getResult() { if(result == null) { return ErrorEval.VALUE_INVALID; - } else { - return result; - } + } else if(result instanceof BlankEval) { + return ErrorEval.VALUE_INVALID; + } else + try { + if(OperandResolver.coerceValueToString(OperandResolver.getSingleValue(result, 0, 0)).equals("")) { + return ErrorEval.VALUE_INVALID; + } + else { + return result; + } + } catch (EvaluationException e) { + return e.getErrorEval(); + } } } diff --git a/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java b/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java index 6a87a67a6..2901abc95 100644 --- a/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java +++ b/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java @@ -17,13 +17,13 @@ package org.apache.poi.ss.formula.functions; -import org.apache.poi.ss.formula.TwoDEval; +import org.apache.poi.ss.formula.eval.AreaEval; import org.apache.poi.ss.formula.eval.BlankEval; import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.EvaluationException; import org.apache.poi.ss.formula.eval.NotImplementedException; import org.apache.poi.ss.formula.eval.NumericValueEval; -import org.apache.poi.ss.formula.eval.RefEval; +import org.apache.poi.ss.formula.eval.OperandResolver; import org.apache.poi.ss.formula.eval.StringEval; import org.apache.poi.ss.formula.eval.StringValueEval; import org.apache.poi.ss.formula.eval.ValueEval; @@ -62,11 +62,17 @@ public final class DStarRunner implements Function3Arg { public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval database, ValueEval filterColumn, ValueEval conditionDatabase) { // Input processing and error checks. - if(!(database instanceof TwoDEval) || !(conditionDatabase instanceof TwoDEval)) { + if(!(database instanceof AreaEval) || !(conditionDatabase instanceof AreaEval)) { return ErrorEval.VALUE_INVALID; } - TwoDEval db = (TwoDEval)database; - TwoDEval cdb = (TwoDEval)conditionDatabase; + AreaEval db = (AreaEval)database; + AreaEval cdb = (AreaEval)conditionDatabase; + + try { + filterColumn = OperandResolver.getSingleValue(filterColumn, srcRowIndex, srcColumnIndex); + } catch (EvaluationException e) { + return e.getErrorEval(); + } int fc; try { @@ -100,15 +106,11 @@ public final class DStarRunner implements Function3Arg { } // Filter each entry. if(matches) { - try { - ValueEval currentValueEval = solveReference(db.getValue(row, fc)); - // Pass the match to the algorithm and conditionally abort the search. - boolean shouldContinue = algorithm.processMatch(currentValueEval); - if(! shouldContinue) { - break; - } - } catch (EvaluationException e) { - return e.getErrorEval(); + ValueEval currentValueEval = resolveReference(db, row, fc); + // Pass the match to the algorithm and conditionally abort the search. + boolean shouldContinue = algorithm.processMatch(currentValueEval); + if(! shouldContinue) { + break; } } } @@ -126,56 +128,16 @@ public final class DStarRunner implements Function3Arg { } /** - * Resolve reference(-chains) until we have a normal value. + * * - * @param field a ValueEval which can be a RefEval. - * @return a ValueEval which is guaranteed not to be a RefEval - * @throws EvaluationException If a multi-sheet reference was found along the way. - */ - private static ValueEval solveReference(ValueEval field) throws EvaluationException { - if (field instanceof RefEval) { - RefEval refEval = (RefEval)field; - if (refEval.getNumberOfSheets() > 1) { - throw new EvaluationException(ErrorEval.VALUE_INVALID); - } - return solveReference(refEval.getInnerValueEval(refEval.getFirstSheetIndex())); - } - else { - return field; - } - } - - /** - * Returns the first column index that matches the given name. The name can either be - * a string or an integer, when it's an integer, then the respective column - * (1 based index) is returned. - * @param nameValueEval + * @param nameValueEval Must not be a RefEval or AreaEval. Thus make sure resolveReference() is called on the value first! * @param db - * @return the first column index that matches the given name (or int) + * @return * @throws EvaluationException */ - @SuppressWarnings("unused") - private static int getColumnForTag(ValueEval nameValueEval, TwoDEval db) + private static int getColumnForName(ValueEval nameValueEval, AreaEval db) throws EvaluationException { - int resultColumn = -1; - - // Numbers as column indicator are allowed, check that. - if(nameValueEval instanceof NumericValueEval) { - double doubleResultColumn = ((NumericValueEval)nameValueEval).getNumberValue(); - resultColumn = (int)doubleResultColumn; - // Floating comparisions are usually not possible, but should work for 0.0. - if(doubleResultColumn - resultColumn != 0.0) - throw new EvaluationException(ErrorEval.VALUE_INVALID); - resultColumn -= 1; // Numbers are 1-based not 0-based. - } else { - resultColumn = getColumnForName(nameValueEval, db); - } - return resultColumn; - } - - private static int getColumnForName(ValueEval nameValueEval, TwoDEval db) - throws EvaluationException { - String name = getStringFromValueEval(nameValueEval); + String name = OperandResolver.coerceValueToString(nameValueEval); return getColumnForString(db, name); } @@ -187,16 +149,19 @@ public final class DStarRunner implements Function3Arg { * @return Corresponding column number. * @throws EvaluationException If it's not possible to turn all headings into strings. */ - private static int getColumnForString(TwoDEval db,String name) + private static int getColumnForString(AreaEval db,String name) throws EvaluationException { int resultColumn = -1; final int width = db.getWidth(); for(int column = 0; column < width; ++column) { - ValueEval columnNameValueEval = db.getValue(0, column); - if(solveReference(columnNameValueEval) instanceof BlankEval) { + ValueEval columnNameValueEval = resolveReference(db, 0, column); + if(columnNameValueEval instanceof BlankEval) { continue; } - String columnName = getStringFromValueEval(columnNameValueEval); + if(columnNameValueEval instanceof ErrorEval) { + continue; + } + String columnName = OperandResolver.coerceValueToString(columnNameValueEval); if(name.equals(columnName)) { resultColumn = column; break; @@ -215,7 +180,7 @@ public final class DStarRunner implements Function3Arg { * @throws EvaluationException If references could not be resolved or comparison * operators and operands didn't match. */ - private static boolean fullfillsConditions(TwoDEval db, int row, TwoDEval cdb) + private static boolean fullfillsConditions(AreaEval db, int row, AreaEval cdb) throws EvaluationException { // Only one row must match to accept the input, so rows are ORed. // Each row is made up of cells where each cell is a condition, @@ -229,20 +194,15 @@ public final class DStarRunner implements Function3Arg { // special column that accepts formulas. boolean columnCondition = true; ValueEval condition = null; - try { - // The condition to apply. - condition = solveReference(cdb.getValue(conditionRow, column)); - } catch (java.lang.RuntimeException e) { - // It might be a special formula, then it is ok if it fails. - columnCondition = false; - } + + // The condition to apply. + condition = resolveReference(cdb, conditionRow, column); + // If the condition is empty it matches. if(condition instanceof BlankEval) continue; // The column in the DB to apply the condition to. - ValueEval targetHeader = solveReference(cdb.getValue(0, column)); - targetHeader = solveReference(targetHeader); - + ValueEval targetHeader = resolveReference(cdb, 0, column); if(!(targetHeader instanceof StringValueEval)) { throw new EvaluationException(ErrorEval.VALUE_INVALID); @@ -254,14 +214,14 @@ public final class DStarRunner implements Function3Arg { if(columnCondition == true) { // normal column condition // Should not throw, checked above. - ValueEval value = db.getValue( - row, getColumnForName(targetHeader, db)); + ValueEval value = resolveReference(db, row, getColumnForName(targetHeader, db)); if(!testNormalCondition(value, condition)) { matches = false; break; } } else { // It's a special formula condition. - if(getStringFromValueEval(condition).isEmpty()) { + // TODO: Check whether the condition cell contains a formula and return #VALUE! if it doesn't. + if(OperandResolver.coerceValueToString(condition).isEmpty()) { throw new EvaluationException(ErrorEval.VALUE_INVALID); } throw new NotImplementedException( @@ -328,7 +288,7 @@ public final class DStarRunner implements Function3Arg { if(itsANumber) { return testNumericCondition(value, operator.equal, stringOrNumber); } else { // It's a string. - String valueString = value instanceof BlankEval ? "" : getStringFromValueEval(value); + String valueString = value instanceof BlankEval ? "" : OperandResolver.coerceValueToString(value); return stringOrNumber.equals(valueString); } } else { // It's a text starts-with condition. @@ -336,7 +296,7 @@ public final class DStarRunner implements Function3Arg { return value instanceof StringEval; } else { - String valueString = value instanceof BlankEval ? "" : getStringFromValueEval(value); + String valueString = value instanceof BlankEval ? "" : OperandResolver.coerceValueToString(value); return valueString.startsWith(conditionString); } } @@ -424,20 +384,20 @@ public final class DStarRunner implements Function3Arg { return null; } } - + /** - * Takes a ValueEval and tries to retrieve a String value from it. - * It tries to resolve references if there are any. + * Resolve a ValueEval that's in an AreaEval. * - * @param value ValueEval to retrieve the string from. - * @return String corresponding to the given ValueEval. - * @throws EvaluationException If it's not possible to retrieve a String value. + * @param db AreaEval from which the cell to resolve is retrieved. + * @param dbRow Relative row in the AreaEval. + * @param dbCol Relative column in the AreaEval. + * @return A ValueEval that is a NumberEval, StringEval, BoolEval, BlankEval or ErrorEval. */ - private static String getStringFromValueEval(ValueEval value) - throws EvaluationException { - value = solveReference(value); - if(!(value instanceof StringValueEval)) - throw new EvaluationException(ErrorEval.VALUE_INVALID); - return ((StringValueEval)value).getStringValue(); + private static ValueEval resolveReference(AreaEval db, int dbRow, int dbCol) { + try { + return OperandResolver.getSingleValue(db.getValue(dbRow, dbCol), db.getFirstRow()+dbRow, db.getFirstColumn()+dbCol); + } catch (EvaluationException e) { + return e.getErrorEval(); + } } } diff --git a/test-data/spreadsheet/DGet.xls b/test-data/spreadsheet/DGet.xls index 5d254febeb15659303de31134301f5446aaa2924..729e974e4dfd4bf2e06b10c620cbb17b4b6bf719 100644 GIT binary patch delta 4726 zcmZ`+YitzP75--ZUTp8Oez1Nr2GdfY0z?{;7KjZt)CHRYHjl+%)_AaYz1}r`qyn`} z67rB*wFNF!E5(3$l(d2H$TmqIX|w5{kbhAc5z!Y_f3%gVs>+|Xs!F!!+_^LMtjA-m z@0|19d%kndJ@?+Z&z#SD=33sFHQM0WwRQQ&0NmYmTT5p(UDFl_J+En=|6!5ID8p^zG43+oYBaH4}Jogq_SEJ<$vCS#jX4j_4a{$`>pKrKZRF{O$B9ylS%*M zc-yB8vE9dJ?4BuLyWFS5>68Ab;EsRupHN9d01Y~DL_-S;zKrhH2f?t1J_uc$3Wf`N zFlC&4H$4^nVx>5;Fr@7k3m2}@_Q?O;^uIBEzqvnD_5MCKUxeL8bU^PkUO*{+6A_*3 zZxmgtC?(&2na-~N&O$NO(I`Ibc*!gPjFHia6V#56MvoeKz{Vv@$l)<#d@?biA2kvQ zJvOe(PStbNQC*G-%>l?r4Y0JUwX^*xJ(kobh75foIyPunCc}j7ZQaphwm0b=NqxW= z(<3n>agx}Kd>*&Dl{{M7)zjHjq`I~@RapR=a}8i)+>d-M+Y+@ zz3kbs!vjpP;oa?9n>+#_qm#+WabrL?#>P@(`Vgg?f_OTbm^8*IPfAXvCZxO3iD-Xx z+{ohBD8?Ti2h9qwd_7F?bnRacyhQDAQQDFpUy0$!wi zeD*0|Z!xf|1$d?e*xE|o_<_33z*iOkr>T9N+7GDBQv1g(Kv@}ZzYQoT2R>=1VhaFk zwmt^*(M!)Z;CZUR-&4C_A<+9};9Jz*q4puQLmj~PX_Eg*ZDU2cZ2O(k!iW2TgAwr{ zGL`PzKj5pLAjd!H1KybgE_@rhII*3DaltCQ! z&`~w~pT1Xw~fC#7m}>wJxP`usW#=~vGOiW)|tW$Uo)AbL@VGAzo& z&ZHs50D|KF%NrUZ^Y#d#Lad%TWo|)(_6U9)Bm-?Y&CW?FfX#T8q*Fe|f`rl2VqqbL zSyBaIFFWI^6jtCXrg7DT1(f};3#lPwh4!dhlGVAOdV-qOphg$6m=N3DCWTl|EFpxQ zFT`5(irW|KSGw|1MV_?&9qd#u9WDXoR4?+-il2xJ7y8Vtm{vjbQYyM}*^vTh$McR9 z#5TO(NFf(iLD-aoRk^Tg!Y(*i*oD<#n~6&fSmy%kY2ZZ%Yjk0Y37dAXCKtAZFb;xK za){2ffDHT~vRT?T=G4UkyL7^+5x=`wtGzD%b+I|<%3>Yr#fnR{HEG3om~2{A!jo{A zYVOdb*&C7w&HPCiks7`W@_Uwcm{*wZ_~>ca3%0;1h80?U7l4yQS{4B zt(R+ey-gjgj&=d@HWO9bOmPdBY`R=XuV)(RS*7jL|?x8Wm+CZB!OER=!6#4RL5Qf;2L3?{UCJp{r zj9+cv!OjfIVZ61r$>fq5KAU0~C#yw#Hg$h3MPeNOjGt4>d-33`En!d^d`-M@wZmkC zLpgpB!8`^_Go`cUO6QagNyA)+mc+r|k^!zo%<XY}&4tXUc6?W3yb1Nmp+x z>oE#&W*3Z6ux)tG!Tjiy=P3ITqmRkiQn^bCI+Dpyqk~#2Jm} z1Wt*_30%c(BA5x4d4P`=h3WjA0=xc@Ma9F0`4P||ptnPNg8I~!qtBy`9V!5H1 z6N>K|Q?ZUH)&|mXyyV3^ ztks!nn{>pKtk#Fth-AH^SVtr)f5!0g9g(a7jWe6Hn6x6rM9lLrg)?EBDJhAHWMY$& z=%-9%Ql68NiD#dgl9FkKWJ)QfMT&`-=V7YN)Y?ob$+So^r6kkORY)mG#2;8plwu;2 zK0i4o`o5;w@@Y^^#5@mEeWu=K8kJ0tOrw(NXNqZ5GEFO{Q5lkzWIlWYXjc7>o7AyG z)-$_woI37-m83C=aBVX(CQVpD@iyBo>zt8sLgAR`I!O_2vB(3E89J^p+>~Tzlf&^#_F; zp8LW5vJcY_uN!(N-vjyH$M-zG*L|AJX8GF2*EGJC@imOEUA^?FFD}Ud delta 2383 zcmZ`)ZA_C_6n<{MpcQCg1xjnNL`ckFnGQeL1_%ncITb|tuzb|kR+~66VPR&3SzL4` zYNm35WSIj|KHMA?eX}J?_GA9ruZfA#jkpiDW&5!#+kPxF+oU`9?b}z1FSmJn?tPwf z&$;K^d+zNY*Y^+V&#h+r&aZJ90syY>yvC#$^Dt)P9(}-?wic3x>rC!S1N*5fmsVo2Cs``GR| zqp&M<%&Lxb$2eng^rhO-mrAqL)`;SsPd7+E*eqEU7!b6?r1jAzqk6O zZ3Xp{kV?Ic@BzDe>V$sbAnMzUc8;3W^8Wk8rhyI&6cOosX@fVWeC zZIwVXE&lb5K))F{SOxT0fU0U>>oVX9$r~j9A{is8-wdRu1OKk0jxhtssRcY%poyf9 zWN#gC+y<~Mz_Lu>7|GKlza;rprc|+gCe3uM87OY$=8g-}S#MC66Q+gU>;TTb1{^vK z+9)pdoD6)2%#s4**2bvEpz?qaM_1KXv6?bg7=J}tIK zi%nn=)v?I+V#QVsY>x)!)xg>`u=XdgXKkP~J>j@h1M>+?@(%20%)@VTuik^r{LcXw ze}1r(`ZaR@)Zi;74=Lgi_n)!z-v_HndCgFR(SvfN^9MtDd~~RSuy2OEGWL{=H4T@_ zqa6P2a2}r=E@d8RZrGaQZUKwAP}GKYnCMvM>QUbnl7|^onx>I*cl(kWnaJY4k)x3s zxY;9E(1r|b!ZBLhQJolBQ6pAb73VS)E1#JHIWYbZuWi_+0aY(p$YWwvB!c4YJWqfR!#{~q;4w&0?& z)OHH77RS|*6`y11ga>1*>XWRw zk&o(MA$H6su5o3@e9)sBR}?$Gq;&a6E1s@SlR+6fATaJ3FL|7)PKs1iMf>E#(=7^u$> zrk}yUznCtQ{)qOlf#}z!>W|;J`~7X{yJ*N$F&~S?#1kZ*9Pz}6Cq=v<;>8dzgy6*s vAZ~nd!HWysN8euh{QUf_!{_(f24)}Xx-ap6W_wv9@3|dG6VC{paJl^t&%dF} From 41b0462f502772cb15911c764c5421b714c13844 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 14 Sep 2016 15:01:57 +0000 Subject: [PATCH 26/43] Javadoc fix git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760719 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/ss/formula/functions/DStarRunner.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java b/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java index 2901abc95..8418c4f74 100644 --- a/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java +++ b/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java @@ -131,8 +131,8 @@ public final class DStarRunner implements Function3Arg { * * * @param nameValueEval Must not be a RefEval or AreaEval. Thus make sure resolveReference() is called on the value first! - * @param db - * @return + * @param db Database + * @return Corresponding column number. * @throws EvaluationException */ private static int getColumnForName(ValueEval nameValueEval, AreaEval db) From 753ca9b8119b4bdd4c65e297b23e877f013c1ab0 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 17:21:31 +0000 Subject: [PATCH 27/43] bug 60128: make code Java 6 compatible. Throwable#addSuppressed not available until Java 7 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760732 13f79535-47bb-0310-9956-ffa450edef68 --- src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java index 3872e7381..ca54fa9f4 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java @@ -99,8 +99,8 @@ public final class ZipPackage extends OPCPackage { try { zis.close(); } catch (final IOException e2) { - e2.addSuppressed(e); - throw new IOException("Failed to close zip input stream while cleaning up", e2); + e.printStackTrace(); + throw new IOException("Failed to close zip input stream while cleaning up. " + e.getMessage(), e2); } throw new IOException("Failed to read zip entry source", e); } From 97b94f5dcd7beb2d89b1983fbba3c7e40f4923d0 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 17:25:03 +0000 Subject: [PATCH 28/43] javadocs git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760733 13f79535-47bb-0310-9956-ffa450edef68 --- src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java index ca54fa9f4..da053e6d1 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java @@ -89,6 +89,8 @@ public final class ZipPackage extends OPCPackage { * @throws IllegalArgumentException * If the specified input stream not an instance of * ZipInputStream. + * @throws IOException + * if input stream cannot be opened, read, or closed */ ZipPackage(InputStream in, PackageAccess access) throws IOException { super(access); From 9ac461596f5d7cd0e5abe9da99dd64c39721c750 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 17:48:00 +0000 Subject: [PATCH 29/43] bug 60128: add test-data/openxml4j/invalid.xlsx to expected failures for integration test git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760735 13f79535-47bb-0310-9956-ffa450edef68 --- src/integrationtest/org/apache/poi/TestAllFiles.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/integrationtest/org/apache/poi/TestAllFiles.java b/src/integrationtest/org/apache/poi/TestAllFiles.java index 6183c185c..be3fb6636 100644 --- a/src/integrationtest/org/apache/poi/TestAllFiles.java +++ b/src/integrationtest/org/apache/poi/TestAllFiles.java @@ -240,6 +240,7 @@ public class TestAllFiles { EXPECTED_FAILURES.add("openxml4j/OPCCompliance_CoreProperties_OnlyOneCorePropertiesPartFAIL.docx"); EXPECTED_FAILURES.add("openxml4j/OPCCompliance_CoreProperties_UnauthorizedXMLLangAttributeFAIL.docx"); EXPECTED_FAILURES.add("openxml4j/OPCCompliance_DerivedPartNameFAIL.docx"); + EXPECTED_FAILURES.add("openxml4j/invalid.xlsx"); EXPECTED_FAILURES.add("spreadsheet/54764-2.xlsx"); // see TestXSSFBugs.bug54764() EXPECTED_FAILURES.add("spreadsheet/54764.xlsx"); // see TestXSSFBugs.bug54764() EXPECTED_FAILURES.add("spreadsheet/Simple.xlsb"); From 3445bcbc8fb06d94c1164d848e26624cadc456aa Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 17:55:51 +0000 Subject: [PATCH 30/43] add compile-examples dependency to compile-integration. o.a.p.xssf.eventusermodel.XLSX2CSV and o.a.p.xssf.eventusermodel.examples.FromHowTo are needed for o.a.p.stress.XSSFFileHandler. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760736 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.xml b/build.xml index 633607618..d3623395d 100644 --- a/build.xml +++ b/build.xml @@ -1092,7 +1092,7 @@ under the License. - + Date: Wed, 14 Sep 2016 18:41:21 +0000 Subject: [PATCH 31/43] bug 60128: exclude openxml4j/invalid.xlsx from additional integration (stress) tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760743 13f79535-47bb-0310-9956-ffa450edef68 --- src/integrationtest/org/apache/poi/TestAllFiles.java | 5 ++++- .../org/apache/poi/stress/XSSFFileHandler.java | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/integrationtest/org/apache/poi/TestAllFiles.java b/src/integrationtest/org/apache/poi/TestAllFiles.java index be3fb6636..e364c9f28 100644 --- a/src/integrationtest/org/apache/poi/TestAllFiles.java +++ b/src/integrationtest/org/apache/poi/TestAllFiles.java @@ -298,7 +298,10 @@ public class TestAllFiles { List files = new ArrayList(); for(String file : scanner.getIncludedFiles()) { file = file.replace('\\', '/'); // ... failures/handlers lookup doesn't work on windows otherwise - if (IGNORED.contains(file)) continue; + if (IGNORED.contains(file)) { + System.out.println("Ignoring " + file); + continue; + } FileHandler handler = HANDLERS.get(getExtension(file)); files.add(new Object[] { file, handler }); diff --git a/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java index be6039707..0e24f0486 100644 --- a/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java +++ b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java @@ -30,6 +30,7 @@ import javax.xml.transform.TransformerException; import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException; import org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.OPCPackage; @@ -134,6 +135,9 @@ public class XSSFFileHandler extends SpreadsheetHandler { EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/Simple.xlsb"); // TODO: good to ignore? EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/sample-beta.xlsx"); + + // corrupt/invalid + EXPECTED_ADDITIONAL_FAILURES.add("openxml4j/invalid.xlsx"); } @SuppressWarnings("resource") From 03b5dc68ebc6e23402d0163b5de42c04d774f3a6 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 19:24:49 +0000 Subject: [PATCH 32/43] bug 60128: remove forbidden-api Exception.printStackTrace() git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760744 13f79535-47bb-0310-9956-ffa450edef68 --- src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java index da053e6d1..33333c3c5 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java @@ -101,7 +101,6 @@ public final class ZipPackage extends OPCPackage { try { zis.close(); } catch (final IOException e2) { - e.printStackTrace(); throw new IOException("Failed to close zip input stream while cleaning up. " + e.getMessage(), e2); } throw new IOException("Failed to read zip entry source", e); From 91f2d5680e81b8c5ecff441d83c2581ae5c4db41 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 21:32:34 +0000 Subject: [PATCH 33/43] declare methods throw runtime exceptions for IDE hints git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760784 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/ss/usermodel/FormulaError.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/java/org/apache/poi/ss/usermodel/FormulaError.java b/src/java/org/apache/poi/ss/usermodel/FormulaError.java index 583ca06d9..fa102299e 100644 --- a/src/java/org/apache/poi/ss/usermodel/FormulaError.java +++ b/src/java/org/apache/poi/ss/usermodel/FormulaError.java @@ -166,19 +166,19 @@ public enum FormulaError { return false; } - public static FormulaError forInt(byte type){ + public static FormulaError forInt(byte type) throws IllegalArgumentException { FormulaError err = bmap.get(type); if(err == null) throw new IllegalArgumentException("Unknown error type: " + type); return err; } - public static FormulaError forInt(int type){ + public static FormulaError forInt(int type) throws IllegalArgumentException { FormulaError err = imap.get(type); if(err == null) err = bmap.get((byte)type); if(err == null) throw new IllegalArgumentException("Unknown error type: " + type); return err; } - public static FormulaError forString(String code){ + public static FormulaError forString(String code) throws IllegalArgumentException { FormulaError err = smap.get(code); if(err == null) throw new IllegalArgumentException("Unknown error code: " + code); return err; From 1de973e2a7c641b3ce4c46c4f691148233992709 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 21:44:06 +0000 Subject: [PATCH 34/43] declare methods throw runtime exceptions for IDE hints git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760798 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/xssf/usermodel/XSSFCell.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java index 7d2d6d25b..c7932d167 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -827,7 +827,7 @@ public final class XSSFCell implements Cell { * @throws IllegalStateException if the cell type returned by {@link #getCellTypeEnum()} isn't {@link CellType#ERROR} * @see FormulaError */ - public String getErrorCellString() { + public String getErrorCellString() throws IllegalStateException { CellType cellType = getBaseCellType(true); if(cellType != CellType.ERROR) throw typeMismatch(CellType.ERROR, cellType, false); @@ -845,13 +845,16 @@ public final class XSSFCell implements Cell { * @see FormulaError */ @Override - public byte getErrorCellValue() { + public byte getErrorCellValue() throws IllegalStateException { String code = getErrorCellString(); if (code == null) { return 0; } - - return FormulaError.forString(code).getCode(); + try { + return FormulaError.forString(code).getCode(); + } catch (final IllegalArgumentException e) { + throw new IllegalStateException("Unexpected error code", e); + } } /** From 16acf81b9e9dd6ae74473be2ce636e592d0d203a Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 22:01:11 +0000 Subject: [PATCH 35/43] convert TestXSSFPivotTable to junit4 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760806 13f79535-47bb-0310-9956-ffa450edef68 --- .../xssf/usermodel/AllXSSFUsermodelTests.java | 2 +- .../xssf/usermodel/TestXSSFPivotTable.java | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java index 96b363283..6ecad0a74 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java @@ -59,7 +59,7 @@ import org.junit.runners.Suite; TestXSSFSheetComments.class, TestColumnHelper.class, TestHeaderFooterHelper.class, - TestXSSFPivotTable.class, + //TestXSSFPivotTable.class, //converted to junit4 TestForkedEvaluator.class }) public final class AllXSSFUsermodelTests { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java index 55fe4a4fa..320ae68c9 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java @@ -16,6 +16,9 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.DataConsolidateFunction; @@ -23,20 +26,20 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.AreaReference; import org.apache.poi.ss.util.CellReference; +import org.junit.Before; +import org.junit.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageField; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageFields; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotTableDefinition; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataConsolidateFunction; -import junit.framework.TestCase; - -public class TestXSSFPivotTable extends TestCase { +public class TestXSSFPivotTable { private XSSFPivotTable pivotTable; private XSSFPivotTable offsetPivotTable; private Cell offsetOuterCell; - @Override + @Before public void setUp(){ Workbook wb = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet) wb.createSheet(); @@ -119,6 +122,7 @@ public class TestXSSFPivotTable extends TestCase { * Verify that when creating a row label it's created on the correct row * and the count is increased by one. */ + @Test public void testAddRowLabelToPivotTable() { int columnIndex = 0; @@ -141,6 +145,7 @@ public class TestXSSFPivotTable extends TestCase { /** * Verify that it's not possible to create a row label outside of the referenced area. */ + @Test public void testAddRowLabelOutOfRangeThrowsException() { int columnIndex = 5; @@ -155,6 +160,7 @@ public class TestXSSFPivotTable extends TestCase { /** * Verify that when creating one column label, no col fields are being created. */ + @Test public void testAddOneColumnLabelToPivotTableDoesNotCreateColField() { int columnIndex = 0; @@ -167,6 +173,7 @@ public class TestXSSFPivotTable extends TestCase { /** * Verify that it's possible to create three column labels with different DataConsolidateFunction */ + @Test public void testAddThreeDifferentColumnLabelsToPivotTable() { int columnOne = 0; int columnTwo = 1; @@ -184,6 +191,7 @@ public class TestXSSFPivotTable extends TestCase { /** * Verify that it's possible to create three column labels with the same DataConsolidateFunction */ + @Test public void testAddThreeSametColumnLabelsToPivotTable() { int columnOne = 0; int columnTwo = 1; @@ -200,6 +208,7 @@ public class TestXSSFPivotTable extends TestCase { /** * Verify that when creating two column labels, a col field is being created and X is set to -2. */ + @Test public void testAddTwoColumnLabelsToPivotTable() { int columnOne = 0; int columnTwo = 1; @@ -214,6 +223,7 @@ public class TestXSSFPivotTable extends TestCase { /** * Verify that a data field is created when creating a data column */ + @Test public void testColumnLabelCreatesDataField() { int columnIndex = 0; @@ -229,6 +239,7 @@ public class TestXSSFPivotTable extends TestCase { /** * Verify that it's possible to set a custom name when creating a data column */ + @Test public void testColumnLabelSetCustomName() { int columnIndex = 0; @@ -245,6 +256,7 @@ public class TestXSSFPivotTable extends TestCase { /** * Verify that it's not possible to create a column label outside of the referenced area. */ + @Test public void testAddColumnLabelOutOfRangeThrowsException() { int columnIndex = 5; @@ -260,6 +272,7 @@ public class TestXSSFPivotTable extends TestCase { * Verify when creating a data column set to a data field, the data field with the corresponding * column index will be set to true. */ + @Test public void testAddDataColumn() { int columnIndex = 0; boolean isDataField = true; @@ -272,6 +285,7 @@ public class TestXSSFPivotTable extends TestCase { /** * Verify that it's not possible to create a data column outside of the referenced area. */ + @Test public void testAddDataColumnOutOfRangeThrowsException() { int columnIndex = 5; boolean isDataField = true; @@ -301,6 +315,7 @@ public class TestXSSFPivotTable extends TestCase { /** * Verify that it's not possible to create a new filter outside of the referenced area. */ + @Test public void testAddReportFilterOutOfRangeThrowsException() { int columnIndex = 5; try { @@ -315,6 +330,7 @@ public class TestXSSFPivotTable extends TestCase { * Verify that the Pivot Table operates only within the referenced area, even when the * first column of the referenced area is not index 0. */ + @Test public void testAddDataColumnWithOffsetData() { offsetPivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1); assertEquals(CellType.NUMERIC, offsetOuterCell.getCellTypeEnum()); From 39752a5643c6fb9ed97de02764b17ae24ce70a1c Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 22:11:14 +0000 Subject: [PATCH 36/43] make sure workbook can be written out and read back for all TestXSSFPivotTable tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760811 13f79535-47bb-0310-9956-ffa450edef68 --- .../xssf/usermodel/TestXSSFPivotTable.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java index 320ae68c9..3248f2e1e 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java @@ -19,13 +19,17 @@ package org.apache.poi.xssf.usermodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import java.io.IOException; + +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.DataConsolidateFunction; import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.AreaReference; import org.apache.poi.ss.util.CellReference; +import org.apache.poi.xssf.XSSFITestDataProvider; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageField; @@ -35,14 +39,16 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotTableDefinitio import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataConsolidateFunction; public class TestXSSFPivotTable { + private static final XSSFITestDataProvider _testDataProvider = XSSFITestDataProvider.instance; + private XSSFWorkbook wb; private XSSFPivotTable pivotTable; private XSSFPivotTable offsetPivotTable; private Cell offsetOuterCell; @Before public void setUp(){ - Workbook wb = new XSSFWorkbook(); - XSSFSheet sheet = (XSSFSheet) wb.createSheet(); + wb = new XSSFWorkbook(); + XSSFSheet sheet = wb.createSheet(); Row row1 = sheet.createRow(0); // Create a cell and put a value in it. @@ -75,10 +81,10 @@ public class TestXSSFPivotTable { Cell cell12 = row1.createCell(3); cell12.setCellValue(12.12); - AreaReference source = new AreaReference("A1:C2"); + AreaReference source = new AreaReference("A1:C2", _testDataProvider.getSpreadsheetVersion()); pivotTable = sheet.createPivotTable(source, new CellReference("H5")); - XSSFSheet offsetSheet = (XSSFSheet) wb.createSheet(); + XSSFSheet offsetSheet = wb.createSheet(); Row tableRow_1 = offsetSheet.createRow(1); offsetOuterCell = tableRow_1.createCell(1); @@ -117,6 +123,13 @@ public class TestXSSFPivotTable { AreaReference offsetSource = new AreaReference(new CellReference("C2"), new CellReference("E4")); offsetPivotTable = offsetSheet.createPivotTable(offsetSource, new CellReference("C6")); } + + @After + public void tearDown() throws IOException { + XSSFWorkbook wb2 = _testDataProvider.writeOutAndReadBack(wb); + wb.close(); + wb2.close(); + } /** * Verify that when creating a row label it's created on the correct row From 5b79b4da902c7c8414de5d0715618cac270582f3 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 22:43:08 +0000 Subject: [PATCH 37/43] sheet names are case insensitive git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760814 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xssf/usermodel/XSSFSheet.java | 12 +++++++----- .../xssf/usermodel/TestXSSFPivotTable.java | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 98711c9dd..d72dca445 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -4165,9 +4165,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { * @return The pivot table */ @Beta - public XSSFPivotTable createPivotTable(AreaReference source, CellReference position, Sheet sourceSheet){ - - if(source.getFirstCell().getSheetName() != null && !source.getFirstCell().getSheetName().equals(sourceSheet.getSheetName())) { + public XSSFPivotTable createPivotTable(AreaReference source, CellReference position, Sheet sourceSheet) { + final String sourceSheetName = source.getFirstCell().getSheetName(); + if(sourceSheetName != null && !sourceSheetName.equalsIgnoreCase(sourceSheet.getSheetName())) { throw new IllegalArgumentException("The area is referenced in another sheet than the " + "defined source sheet " + sourceSheet.getSheetName() + "."); } @@ -4193,8 +4193,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { */ @Beta public XSSFPivotTable createPivotTable(AreaReference source, CellReference position){ - if(source.getFirstCell().getSheetName() != null && !source.getFirstCell().getSheetName().equals(this.getSheetName())) { - return createPivotTable(source, position, getWorkbook().getSheet(source.getFirstCell().getSheetName())); + final String sourceSheetName = source.getFirstCell().getSheetName(); + if(sourceSheetName != null && !sourceSheetName.equalsIgnoreCase(this.getSheetName())) { + final XSSFSheet sourceSheet = getWorkbook().getSheet(sourceSheetName); + return createPivotTable(source, position, sourceSheet); } return createPivotTable(source, position, this); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java index 3248f2e1e..851ca33d6 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java @@ -17,11 +17,11 @@ package org.apache.poi.xssf.usermodel; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import java.io.IOException; -import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.DataConsolidateFunction; @@ -350,4 +350,21 @@ public class TestXSSFPivotTable { offsetPivotTable.addColumnLabel(DataConsolidateFunction.SUM, 0); } + + @Test + public void testPivotTableSheetNamesAreCaseInsensitive() { + wb.setSheetName(0, "original"); + wb.setSheetName(1, "offset"); + XSSFSheet original = wb.getSheet("OriginaL"); + XSSFSheet offset = wb.getSheet("OffseT"); + // assume sheets are accessible via case-insensitive name + assertNotNull(original); + assertNotNull(offset); + + AreaReference source = new AreaReference("ORIGinal!A1:C2", _testDataProvider.getSpreadsheetVersion()); + // create a pivot table on the same sheet, case insensitive + original.createPivotTable(source, new CellReference("W1")); + // create a pivot table on a different sheet, case insensitive + offset.createPivotTable(source, new CellReference("W1")); + } } From 0784ab530aa06b4510d2c040886a0b622154b4de Mon Sep 17 00:00:00 2001 From: Tim Allison Date: Thu, 15 Sep 2016 00:19:52 +0000 Subject: [PATCH 38/43] POI 60140 Prevent unnecessary memory usage -- no need to cache HeapByteBuffer in FileBackedDataSource, thanks to Luis Filipe Nassif for diagnosing this git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760816 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java b/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java index 1b8660644..47637daa3 100644 --- a/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java +++ b/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java @@ -94,6 +94,8 @@ public class FileBackedDataSource extends DataSource { if (writable) { dst = channel.map(FileChannel.MapMode.READ_WRITE, position, length); worked = 0; + // remember the buffer for cleanup if necessary + buffersToClean.add(dst); } else { // Read channel.position(position); @@ -109,9 +111,6 @@ public class FileBackedDataSource extends DataSource { // Ready it for reading dst.position(0); - // remember the buffer for cleanup if necessary - buffersToClean.add(dst); - // All done return dst; } From 008a26d1bfb79a7ff5d74cb4b96e5fc013cda325 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Fri, 16 Sep 2016 00:32:40 +0000 Subject: [PATCH 39/43] bug 59705: consolidate bounds checking of column index into a helper method git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760986 13f79535-47bb-0310-9956-ffa450edef68 --- .../ss/usermodel/DataConsolidateFunction.java | 4 +- .../poi/xssf/usermodel/XSSFPivotTable.java | 74 +++++++++++-------- 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/java/org/apache/poi/ss/usermodel/DataConsolidateFunction.java b/src/java/org/apache/poi/ss/usermodel/DataConsolidateFunction.java index f54fb4f7b..d40a8d11c 100644 --- a/src/java/org/apache/poi/ss/usermodel/DataConsolidateFunction.java +++ b/src/java/org/apache/poi/ss/usermodel/DataConsolidateFunction.java @@ -38,8 +38,8 @@ public enum DataConsolidateFunction { VAR(10, "Var"), VARP(11, "Varp"); - private int value; - private String name; + private final int value; + private final String name; DataConsolidateFunction(int value, String name) { this.value = value; diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java index 9f6864919..bf85f65de 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java @@ -30,6 +30,7 @@ import javax.xml.namespace.QName; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.DataConsolidateFunction; @@ -213,24 +214,43 @@ public class XSSFPivotTable extends POIXMLDocumentPart { } protected AreaReference getPivotArea() { - AreaReference pivotArea = new AreaReference(getPivotCacheDefinition(). - getCTPivotCacheDefinition().getCacheSource().getWorksheetSource().getRef()); + AreaReference pivotArea = new AreaReference( + getPivotCacheDefinition() + .getCTPivotCacheDefinition() + .getCacheSource() + .getWorksheetSource() + .getRef(), + SpreadsheetVersion.EXCEL2007); return pivotArea; } + + /** + * Verify column index (relative to first column in pivot area) is within the + * pivot area + * + * @param columnIndex + * @throws IndexOutOfBoundsException + */ + private void checkColumnIndex(int columnIndex) throws IndexOutOfBoundsException { + AreaReference pivotArea = getPivotArea(); + int size = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol() + 1; + + if (columnIndex < 0 || columnIndex >= size) { + throw new IndexOutOfBoundsException("Column Index: " + columnIndex + ", Size: " + size); + } + } /** * Add a row label using data from the given column. - * @param columnIndex the index of the column to be used as row label. + * @param columnIndex the index of the source column to be used as row label. + * {@code columnIndex} is 0-based indexed and relative to the first column in the source. */ @Beta public void addRowLabel(int columnIndex) { + checkColumnIndex(columnIndex); + AreaReference pivotArea = getPivotArea(); - int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow(); - int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol(); - - if(columnIndex > lastColIndex) { - throw new IndexOutOfBoundsException(); - } + final int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow(); CTPivotFields pivotFields = pivotTableDefinition.getPivotFields(); CTPivotField pivotField = CTPivotField.Factory.newInstance(); @@ -238,7 +258,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart { pivotField.setAxis(STAxis.AXIS_ROW); pivotField.setShowAll(false); - for(int i = 0; i <= lastRowIndex; i++) { + for (int i = 0; i <= lastRowIndex; i++) { items.addNewItem().setT(STItemType.DEFAULT); } items.setCount(items.sizeOfItemArray()); @@ -270,7 +290,8 @@ public class XSSFPivotTable extends POIXMLDocumentPart { /** * Add a column label using data from the given column and specified function - * @param columnIndex the index of the column to be used as column label. + * @param columnIndex the index of the source column to be used as column label. + * {@code columnIndex} is 0-based indexed and relative to the first column in the source. * @param function the function to be used on the data * The following functions exists: * Sum, Count, Average, Max, Min, Product, Count numbers, StdDev, StdDevp, Var, Varp @@ -278,12 +299,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart { */ @Beta public void addColumnLabel(DataConsolidateFunction function, int columnIndex, String valueFieldName) { - AreaReference pivotArea = getPivotArea(); - int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol(); - - if(columnIndex > lastColIndex && columnIndex < 0) { - throw new IndexOutOfBoundsException(); - } + checkColumnIndex(columnIndex); addDataColumn(columnIndex, true); addDataField(function, columnIndex, valueFieldName); @@ -303,7 +319,8 @@ public class XSSFPivotTable extends POIXMLDocumentPart { /** * Add a column label using data from the given column and specified function - * @param columnIndex the index of the column to be used as column label. + * @param columnIndex the index of the source column to be used as column label + * {@code columnIndex} is 0-based indexed and relative to the first column in the source.. * @param function the function to be used on the data * The following functions exists: * Sum, Count, Average, Max, Min, Product, Count numbers, StdDev, StdDevp, Var, Varp @@ -323,12 +340,10 @@ public class XSSFPivotTable extends POIXMLDocumentPart { */ @Beta private void addDataField(DataConsolidateFunction function, int columnIndex, String valueFieldName) { + checkColumnIndex(columnIndex); + AreaReference pivotArea = getPivotArea(); - int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol(); - - if(columnIndex > lastColIndex && columnIndex < 0) { - throw new IndexOutOfBoundsException(); - } + CTDataFields dataFields; if(pivotTableDefinition.getDataFields() != null) { dataFields = pivotTableDefinition.getDataFields(); @@ -352,11 +367,8 @@ public class XSSFPivotTable extends POIXMLDocumentPart { */ @Beta public void addDataColumn(int columnIndex, boolean isDataField) { - AreaReference pivotArea = getPivotArea(); - int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol(); - if(columnIndex > lastColIndex && columnIndex < 0) { - throw new IndexOutOfBoundsException(); - } + checkColumnIndex(columnIndex); + CTPivotFields pivotFields = pivotTableDefinition.getPivotFields(); CTPivotField pivotField = CTPivotField.Factory.newInstance(); @@ -371,13 +383,11 @@ public class XSSFPivotTable extends POIXMLDocumentPart { */ @Beta public void addReportFilter(int columnIndex) { + checkColumnIndex(columnIndex); + AreaReference pivotArea = getPivotArea(); - int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol(); int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow(); - if(columnIndex > lastColIndex && columnIndex < 0) { - throw new IndexOutOfBoundsException(); - } CTPivotFields pivotFields = pivotTableDefinition.getPivotFields(); CTPivotField pivotField = CTPivotField.Factory.newInstance(); From d6a7b7d49dbbef6ec58604ab2c5e3e4f55b3cf0e Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Fri, 16 Sep 2016 00:41:25 +0000 Subject: [PATCH 40/43] +svnprops eol-style=native git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760987 13f79535-47bb-0310-9956-ffa450edef68 From 75e2fc77df086dfd062e143f174b68a53393aeee Mon Sep 17 00:00:00 2001 From: David North Date: Sat, 17 Sep 2016 07:49:02 +0000 Subject: [PATCH 41/43] release prepare for 3.15 - updating build.xml and status.xml git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1761142 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.xml b/build.xml index d3623395d..4392d39e1 100644 --- a/build.xml +++ b/build.xml @@ -40,7 +40,7 @@ under the License. The Apache POI project Ant build. - + From 4a3571bf566f4e2dbeeed4daa09828470cb37775 Mon Sep 17 00:00:00 2001 From: David North Date: Sat, 17 Sep 2016 07:49:52 +0000 Subject: [PATCH 42/43] prepare for 3.16-beta1 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1761144 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.xml b/build.xml index 4392d39e1..d3623395d 100644 --- a/build.xml +++ b/build.xml @@ -40,7 +40,7 @@ under the License. The Apache POI project Ant build. - + From 3b5bd602bdafc77a57affdf03cf4d76fce244d73 Mon Sep 17 00:00:00 2001 From: David North Date: Sat, 17 Sep 2016 08:50:18 +0000 Subject: [PATCH 43/43] release prepare for 3.15 - updating build.xml and status.xml git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1761161 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.xml b/build.xml index d3623395d..4392d39e1 100644 --- a/build.xml +++ b/build.xml @@ -40,7 +40,7 @@ under the License. The Apache POI project Ant build. - +