diff options
-rw-r--r-- | build.xml | 2 | ||||
-rw-r--r-- | sonar/examples/pom.xml | 2 | ||||
-rw-r--r-- | sonar/excelant/pom.xml | 2 | ||||
-rw-r--r-- | sonar/main/pom.xml | 2 | ||||
-rw-r--r-- | sonar/ooxml-schema-encryption/pom.xml | 2 | ||||
-rw-r--r-- | sonar/ooxml-schema-security/pom.xml | 2 | ||||
-rw-r--r-- | sonar/ooxml-schema/pom.xml | 2 | ||||
-rw-r--r-- | sonar/ooxml/pom.xml | 2 | ||||
-rw-r--r-- | sonar/pom.xml | 2 | ||||
-rw-r--r-- | sonar/scratchpad/pom.xml | 2 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/record/FilePassRecord.java | 4 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/record/RecordInputStream.java | 1 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java | 87 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java | 3 | ||||
-rw-r--r-- | src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java | 74 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java | 11 | ||||
-rw-r--r-- | src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryption.java | 1 |
17 files changed, 32 insertions, 169 deletions
@@ -40,7 +40,7 @@ under the License. <description>The Apache POI project Ant build.</description> - <property name="version.id" value="3.15-beta4"/> + <property name="version.id" value="3.16-beta1"/> <property name="release.rc" value="RC1"/> <property environment="env"/> diff --git a/sonar/examples/pom.xml b/sonar/examples/pom.xml index cac1dc446c..ea53c05970 100644 --- a/sonar/examples/pom.xml +++ b/sonar/examples/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.apache.poi</groupId> <artifactId>poi-parent</artifactId> - <version>3.15-beta4-SNAPSHOT</version> + <version>3.16-beta1-SNAPSHOT</version> </parent> <artifactId>poi-examples</artifactId> <packaging>jar</packaging> diff --git a/sonar/excelant/pom.xml b/sonar/excelant/pom.xml index 2cbeec7280..a7b9408dc4 100644 --- a/sonar/excelant/pom.xml +++ b/sonar/excelant/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.apache.poi</groupId> <artifactId>poi-parent</artifactId> - <version>3.15-beta4-SNAPSHOT</version> + <version>3.16-beta1-SNAPSHOT</version> </parent> <artifactId>poi-excelant</artifactId> <packaging>jar</packaging> diff --git a/sonar/main/pom.xml b/sonar/main/pom.xml index 26a8f2ba40..36422a83c8 100644 --- a/sonar/main/pom.xml +++ b/sonar/main/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.apache.poi</groupId> <artifactId>poi-parent</artifactId> - <version>3.15-beta4-SNAPSHOT</version> + <version>3.16-beta1-SNAPSHOT</version> </parent> <artifactId>poi-main</artifactId> <packaging>jar</packaging> diff --git a/sonar/ooxml-schema-encryption/pom.xml b/sonar/ooxml-schema-encryption/pom.xml index d704a6525d..cbb2eff7d3 100644 --- a/sonar/ooxml-schema-encryption/pom.xml +++ b/sonar/ooxml-schema-encryption/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.apache.poi</groupId> <artifactId>poi-parent</artifactId> - <version>3.15-beta4-SNAPSHOT</version> + <version>3.16-beta1-SNAPSHOT</version> <relativePath>..</relativePath> </parent> <artifactId>poi-ooxml-schema-encryption</artifactId> diff --git a/sonar/ooxml-schema-security/pom.xml b/sonar/ooxml-schema-security/pom.xml index 7aae600f41..a822c73435 100644 --- a/sonar/ooxml-schema-security/pom.xml +++ b/sonar/ooxml-schema-security/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.apache.poi</groupId> <artifactId>poi-parent</artifactId> - <version>3.15-beta4-SNAPSHOT</version> + <version>3.16-beta1-SNAPSHOT</version> <relativePath>..</relativePath> </parent> <artifactId>poi-ooxml-schema-security</artifactId> diff --git a/sonar/ooxml-schema/pom.xml b/sonar/ooxml-schema/pom.xml index e1d6526da9..5e2b9fef56 100644 --- a/sonar/ooxml-schema/pom.xml +++ b/sonar/ooxml-schema/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.apache.poi</groupId> <artifactId>poi-parent</artifactId> - <version>3.15-beta4-SNAPSHOT</version> + <version>3.16-beta1-SNAPSHOT</version> <relativePath>..</relativePath> </parent> <artifactId>poi-ooxml-schema</artifactId> diff --git a/sonar/ooxml/pom.xml b/sonar/ooxml/pom.xml index 305695ff1a..27636cdfa1 100644 --- a/sonar/ooxml/pom.xml +++ b/sonar/ooxml/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.apache.poi</groupId> <artifactId>poi-parent</artifactId> - <version>3.15-beta4-SNAPSHOT</version> + <version>3.16-beta1-SNAPSHOT</version> </parent> <artifactId>poi-ooxml</artifactId> <packaging>jar</packaging> diff --git a/sonar/pom.xml b/sonar/pom.xml index 5acb3a5da2..8e2a9fc42f 100644 --- a/sonar/pom.xml +++ b/sonar/pom.xml @@ -3,7 +3,7 @@ <groupId>org.apache.poi</groupId> <artifactId>poi-parent</artifactId> <packaging>pom</packaging> - <version>3.15-beta4-SNAPSHOT</version> + <version>3.16-beta1-SNAPSHOT</version> <name>Apache POI - the Java API for Microsoft Documents</name> <description>Maven build of Apache POI for Sonar checks</description> <url>http://poi.apache.org/</url> diff --git a/sonar/scratchpad/pom.xml b/sonar/scratchpad/pom.xml index 91ede69a1c..6760762d67 100644 --- a/sonar/scratchpad/pom.xml +++ b/sonar/scratchpad/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.apache.poi</groupId> <artifactId>poi-parent</artifactId> - <version>3.15-beta4-SNAPSHOT</version> + <version>3.16-beta1-SNAPSHOT</version> </parent> <artifactId>poi-scratchpad</artifactId> <packaging>jar</packaging> diff --git a/src/java/org/apache/poi/hssf/record/FilePassRecord.java b/src/java/org/apache/poi/hssf/record/FilePassRecord.java index acb5c8da46..99f37e535f 100644 --- a/src/java/org/apache/poi/hssf/record/FilePassRecord.java +++ b/src/java/org/apache/poi/hssf/record/FilePassRecord.java @@ -83,7 +83,8 @@ public final class FilePassRecord extends StandardRecord implements Cloneable { } } - @Override + @SuppressWarnings("resource") + @Override public void serialize(LittleEndianOutput out) { out.writeShort(encryptionType); @@ -116,7 +117,6 @@ public final class FilePassRecord extends StandardRecord implements Cloneable { } @Override - @SuppressWarnings("resource") protected int getDataSize() { ByteArrayOutputStream bos = new ByteArrayOutputStream(); LittleEndianOutputStream leos = new LittleEndianOutputStream(bos); diff --git a/src/java/org/apache/poi/hssf/record/RecordInputStream.java b/src/java/org/apache/poi/hssf/record/RecordInputStream.java index a3d84863e6..8fd0423933 100644 --- a/src/java/org/apache/poi/hssf/record/RecordInputStream.java +++ b/src/java/org/apache/poi/hssf/record/RecordInputStream.java @@ -24,7 +24,6 @@ import java.util.Locale; import org.apache.poi.hssf.dev.BiffViewer; import org.apache.poi.hssf.record.crypto.Biff8DecryptingStream; -import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.poifs.crypt.EncryptionInfo; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndianConsts; diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java index fa5082635d..20c7ffa1e4 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java @@ -32,6 +32,7 @@ import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.ss.usermodel.Cell; 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; /** @@ -79,6 +80,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); + } /** @@ -134,87 +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 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 <em>formula result</em> is returned, so you know what kind of - * cached formula result is also stored with the formula. - * <pre> - * CellType evaluatedCellType = evaluator.evaluateFormulaCell(cell); - * </pre> - * 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 <em>formula result</em> - * @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) { - return CellType._NONE; - } - CellValue cv = evaluateFormulaCellValue(cell); - // cell remains a formula cell, but the cached value is changed - setCellValue(cell, cv); - return cv.getCellType(); - } - - /** - * 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: - * <pre> - * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType(); - * </pre> - * 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; - } - - private static void setCellValue(Cell cell, CellValue cv) { - CellType cellType = cv.getCellType(); - 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 + ")"); - } + return (HSSFCell) super.evaluateInCell(cell); } /** diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index b4339587b9..f6b8f1f292 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -23,7 +23,6 @@ import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAME import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -105,7 +104,6 @@ import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.WorkbookUtil; import org.apache.poi.util.Configurator; import org.apache.poi.util.HexDump; -import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianByteArrayInputStream; @@ -128,7 +126,6 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss * The maximum number of cell styles in a .xls workbook. * The 'official' limit is 4,000, but POI allows a slightly larger number. * This extra delta takes into account built-in styles that are automatically - * created for new workbooks * * See http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HP005199291.aspx */ 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 11fe3efadf..780126c3d5 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,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.util.Internal; +import org.apache.poi.ss.usermodel.RichTextString; /** * Internal POI use only - parent of XSSF and SXSSF formula evaluators @@ -53,78 +53,6 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator { } /** - * 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. - * <pre> - * CellType evaluatedCellType = evaluator.evaluateFormulaCellEnum(cell); - * </pre> - * 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. - */ - @Internal(since="POI 3.15 beta 3") - 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.getCellType(); - } - - /** - * 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); - } - } - - private static void setCellValue(Cell cell, CellValue cv) { - CellType cellType = cv.getCellType(); - 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 */ protected abstract EvaluationCell toEvaluationCell(Cell cell); 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 6dcaef9603..84a4aa6800 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/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryption.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryption.java index 62db5cb85a..80e9f53d0f 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryption.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryption.java @@ -25,7 +25,6 @@ import static org.junit.Assert.fail; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
import java.security.MessageDigest;
import java.util.List;
|