poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1241372 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java java/org/apache/poi/ss/formula/WorkbookEvaluator.java testcases/org/apache/poi/ss/formula/TestMissingWorkbook.java
Date Tue, 07 Feb 2012 08:11:37 GMT
Author: yegor
Date: Tue Feb  7 08:11:37 2012
New Revision: 1241372

URL: http://svn.apache.org/viewvc?rev=1241372&view=rev
Log:
added HSSFFormulaEvaluator.setIgnoreMissingWorkbooks, see Bugzilla 52575

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
    poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/TestMissingWorkbook.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java?rev=1241372&r1=1241371&r2=1241372&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java Tue Feb  7
08:11:37 2012
@@ -369,4 +369,24 @@ public class HSSFFormulaEvaluator implem
 		}
 		throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")");
 	}
+
+    /**
+     * Whether to ignore missing references to external workbooks and
+     * use cached formula results in the main workbook instead.
+     * <p>
+     * In some cases exetrnal workbooks referenced by formulas in the main workbook are not
avaiable.
+     * With this method you can control how POI handles such missing references:
+     * <ul>
+     *     <li>by default ignoreMissingWorkbooks=false and POI throws {@link org.apache.poi.ss.formula.CollaboratingWorkbooksEnvironment.WorkbookNotFoundException}
+     *     if an external reference cannot be resolved</li>
+     *     <li>if ignoreMissingWorkbooks=true then POI uses cached formula result
+     *     that already exists in the main workbook</li>
+     * </ul>
+     *
+     * @param ignore whether to ignore missing references to external workbooks
+     */
+    public void setIgnoreMissingWorkbooks(boolean ignore){
+        _bookEvaluator.setIgnoreMissingWorkbooks(ignore);
+    }
+
 }

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java?rev=1241372&r1=1241371&r2=1241372&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java Tue Feb  7 08:11:37
2012
@@ -85,12 +85,6 @@ public final class WorkbookEvaluator {
 	
 	private static final POILogger LOG = POILogFactory.getLogger(WorkbookEvaluator.class);
 
-    /**
-     * Whether to use cached formula results if external workbook references in a formula
is not available.
-     * See Bugzilla 52575 for details.
-     */
-    private static final String IGNORE_MISSING_WORKBOOKS = WorkbookEvaluator.class.getName()
+ ".IGNORE_MISSING_WORKBOOKS";
-
     private final EvaluationWorkbook _workbook;
 	private EvaluationCache _cache;
 	/** part of cache entry key (useful when evaluating multiple workbooks) */
@@ -103,6 +97,8 @@ public final class WorkbookEvaluator {
 	private final IStabilityClassifier _stabilityClassifier;
 	private final AggregatingUDFFinder _udfFinder;
 
+    private boolean _ignoreMissingWorkbooks = false;
+
 	/**
 	 * @param udfFinder pass <code>null</code> for default (AnalysisToolPak only)
 	 */
@@ -310,9 +306,7 @@ public final class WorkbookEvaluator {
 			 catch (NotImplementedException e) {
 				throw addExceptionInfo(e, sheetIndex, rowIndex, columnIndex);
 			 } catch (RuntimeException re) {
-				 if (re.getCause() instanceof WorkbookNotFoundException 
-						 //To be replaced by configuration infrastructure
-						 && Boolean.valueOf(System.getProperty(IGNORE_MISSING_WORKBOOKS))) {
+				 if (re.getCause() instanceof WorkbookNotFoundException && _ignoreMissingWorkbooks)
{
  					logInfo(re.getCause().getMessage() + " - Continuing with cached value!");
  					switch(srcCell.getCachedFormulaResultType()) {
 	 					case Cell.CELL_TYPE_NUMERIC:
@@ -671,4 +665,24 @@ public final class WorkbookEvaluator {
 	public FreeRefFunction findUserDefinedFunction(String functionName) {
 		return _udfFinder.findFunction(functionName);
 	}
+
+    /**
+     * Whether to ignore missing references to external workbooks and
+     * use cached formula results in the main workbook instead.
+     * <p>
+     * In some cases exetrnal workbooks referenced by formulas in the main workbook are not
avaiable.
+     * With this method you can control how POI handles such missing references:
+     * <ul>
+     *     <li>by default ignoreMissingWorkbooks=false and POI throws {@link WorkbookNotFoundException}
+     *     if an external reference cannot be resolved</li>
+     *     <li>if ignoreMissingWorkbooks=true then POI uses cached formula result
+     *     that already exists in the main workbook</li>
+     * </ul>
+     *
+     * @param ignore whether to ignore missing references to external workbooks
+     * @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=52575">Bug
52575</a> for details
+     */
+    public void setIgnoreMissingWorkbooks(boolean ignore){
+        _ignoreMissingWorkbooks = ignore;
+    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/TestMissingWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/TestMissingWorkbook.java?rev=1241372&r1=1241371&r2=1241372&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/TestMissingWorkbook.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/TestMissingWorkbook.java Tue Feb  7
08:11:37 2012
@@ -72,9 +72,9 @@ public class TestMissingWorkbook extends
 		assertEquals(Cell.CELL_TYPE_FORMULA, lB1Cell.getCellType());
 		assertEquals(Cell.CELL_TYPE_FORMULA, lC1Cell.getCellType());
 		
-		FormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();
-		
-		System.setProperty(propertyKey, Boolean.toString(true));
+		HSSFFormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();
+        evaluator.setIgnoreMissingWorkbooks(true);
+
 		assertEquals(Cell.CELL_TYPE_NUMERIC, evaluator.evaluateFormulaCell(lA1Cell));
 		assertEquals(Cell.CELL_TYPE_STRING, evaluator.evaluateFormulaCell(lB1Cell));
 		assertEquals(Cell.CELL_TYPE_BOOLEAN, evaluator.evaluateFormulaCell(lC1Cell));



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message