aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorEvgeniy Berlog <berlog@apache.org>2012-09-04 21:00:41 +0000
committerEvgeniy Berlog <berlog@apache.org>2012-09-04 21:00:41 +0000
commit5bff0701fc08dcded7f38a709ad1147851e88918 (patch)
tree0532a4a8bf8012d0d181e7108b371908d11ec11e /src/java/org
parent03d0088065d5cbd0c4e5620d527358584d3bcf5e (diff)
downloadpoi-5bff0701fc08dcded7f38a709ad1147851e88918.tar.gz
poi-5bff0701fc08dcded7f38a709ad1147851e88918.zip
resolved bugzilla ticket 53642
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1380882 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java11
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java26
-rw-r--r--src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java55
-rw-r--r--src/java/org/apache/poi/util/POILogger.java19
-rw-r--r--src/java/org/apache/poi/util/SystemOutLogger.java4
5 files changed, 97 insertions, 18 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
index 5d01e7a63a..ba27d82445 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
@@ -389,4 +389,15 @@ public class HSSFFormulaEvaluator implements FormulaEvaluator {
_bookEvaluator.setIgnoreMissingWorkbooks(ignore);
}
+ /**
+ * @param value whether perform detailed output
+ *
+ * Perform detailed output of formula evaluation for next evaluation only?
+ * Is for developer use only (also developers using POI for their XLS files).
+ * Log-Level WARN is for basic info, INFO for detailed information. These quite
+ * high levels are used because you have to explicitly enable this specific logging.
+ */
+ public void setDebugEvaluationOutputForNextEval(boolean value){
+ _bookEvaluator.setDebugEvaluationOutputForNextEval(value);
+ }
}
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
index 7fc4882551..5e53c022ad 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
@@ -171,9 +171,10 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
Iterator<CellValueRecordInterface> iter = sheet.getCellValueIterator();
long timestart = System.currentTimeMillis();
- if (log.check(POILogger.DEBUG))
+ if (log.check( POILogger.DEBUG )) {
log.log(DEBUG, "Time at start of cell creating in HSSF sheet = ",
Long.valueOf(timestart));
+ }
HSSFRow lastrow = null;
// Add every cell to its row
@@ -199,17 +200,24 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
hrow = createRowFromRecord(rowRec);
}
}
- if (log.check(POILogger.DEBUG))
- log.log(DEBUG, "record id = " + Integer.toHexString(((Record) cval).getSid()));
- hrow.createCellFromRecord(cval);
- if (log.check(POILogger.DEBUG))
- log.log(DEBUG, "record took ",
- Long.valueOf(System.currentTimeMillis() - cellstart));
+ if (log.check( POILogger.DEBUG )) {
+ if (cval instanceof Record) {
+ log.log( DEBUG, "record id = " + Integer.toHexString( ( (Record) cval ).getSid() ) );
+ } else {
+ log.log( DEBUG, "record = " + cval );
+ }
+ }
+ hrow.createCellFromRecord( cval );
+ if (log.check( POILogger.DEBUG )) {
+ log.log( DEBUG, "record took ",
+ Long.valueOf( System.currentTimeMillis() - cellstart ) );
+ }
}
- if (log.check(POILogger.DEBUG))
+ if (log.check( POILogger.DEBUG )) {
log.log(DEBUG, "total sheet cell creation took ",
- Long.valueOf(System.currentTimeMillis() - timestart));
+ Long.valueOf(System.currentTimeMillis() - timestart));
+ }
}
/**
diff --git a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
index 79676d6a07..e3c812ad5f 100644
--- a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
+++ b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
@@ -70,6 +70,7 @@ import org.apache.poi.util.POILogger;
* For POI internal use only
*
* @author Josh Micich
+ * @author Thies Wellpott (debug output enhancements)
*/
public final class WorkbookEvaluator {
@@ -384,14 +385,47 @@ public final class WorkbookEvaluator {
}
throw new RuntimeException("Unexpected cell type (" + cellType + ")");
}
+
+
+ /**
+ * whether print detailed messages about the next formula evaluation
+ */
+ private boolean dbgEvaluationOutputForNextEval = false;
+
+ // special logger for formula evaluation output (because of possibly very large output)
+ private final POILogger EVAL_LOG = POILogFactory.getLogger("POI.FormulaEval");
+ // current indent level for evalution; negative value for no output
+ private int dbgEvaluationOutputIndent = -1;
+
// visibility raised for testing
/* package */ ValueEval evaluateFormula(OperationEvaluationContext ec, Ptg[] ptgs) {
+ String dbgIndentStr = ""; // always init. to non-null just for defensive avoiding NPE
+ if (dbgEvaluationOutputForNextEval) {
+ // first evaluation call when ouput is desired, so iit. this evaluator instance
+ dbgEvaluationOutputIndent = 1;
+ dbgEvaluationOutputForNextEval = false;
+ }
+ if (dbgEvaluationOutputIndent > 0) {
+ // init. indent string to needed spaces (create as substring vom very long space-only string;
+ // limit indendation for deep recursions)
+ dbgIndentStr = " ";
+ dbgIndentStr = dbgIndentStr.substring(0, Math.min(dbgIndentStr.length(), dbgEvaluationOutputIndent*2));
+ EVAL_LOG.log(POILogger.WARN, dbgIndentStr
+ + "- evaluateFormula('" + ec.getRefEvaluatorForCurrentSheet().getSheetName()
+ + "'/" + new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString()
+ + "): " + Arrays.toString(ptgs).replaceAll("\\Qorg.apache.poi.ss.formula.ptg.\\E", ""));
+ dbgEvaluationOutputIndent++;
+ }
+
Stack<ValueEval> stack = new Stack<ValueEval>();
for (int i = 0, iSize = ptgs.length; i < iSize; i++) {
// since we don't know how to handle these yet :(
Ptg ptg = ptgs[i];
+ if (dbgEvaluationOutputIndent > 0) {
+ EVAL_LOG.log(POILogger.INFO, dbgIndentStr + " * ptg " + i + ": " + ptg);
+ }
if (ptg instanceof AttrPtg) {
AttrPtg attrPtg = (AttrPtg) ptg;
if (attrPtg.isSum()) {
@@ -497,13 +531,28 @@ public final class WorkbookEvaluator {
}
// logDebug("push " + opResult);
stack.push(opResult);
+ if (dbgEvaluationOutputIndent > 0) {
+ EVAL_LOG.log(POILogger.INFO, dbgIndentStr + " = " + opResult);
+ }
}
ValueEval value = stack.pop();
if (!stack.isEmpty()) {
throw new IllegalStateException("evaluation stack not empty");
}
- return dereferenceResult(value, ec.getRowIndex(), ec.getColumnIndex());
+ ValueEval result = dereferenceResult(value, ec.getRowIndex(), ec.getColumnIndex());
+ if (dbgEvaluationOutputIndent > 0) {
+ EVAL_LOG.log(POILogger.INFO, dbgIndentStr + "finshed eval of "
+ + new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString()
+ + ": " + result);
+ dbgEvaluationOutputIndent--;
+ if (dbgEvaluationOutputIndent == 1) {
+ // this evaluation is done, reset indent to stop logging
+ dbgEvaluationOutputIndent = -1;
+ }
+ } // if
+ return result;
+
}
/**
@@ -723,4 +772,8 @@ public final class WorkbookEvaluator {
public static void registerFunction(String name, Function func){
FunctionEval.registerFunction(name, func);
}
+
+ public void setDebugEvaluationOutputForNextEval(boolean value){
+ dbgEvaluationOutputForNextEval = value;
+ }
}
diff --git a/src/java/org/apache/poi/util/POILogger.java b/src/java/org/apache/poi/util/POILogger.java
index cf722c4653..4088ec290c 100644
--- a/src/java/org/apache/poi/util/POILogger.java
+++ b/src/java/org/apache/poi/util/POILogger.java
@@ -17,7 +17,8 @@
package org.apache.poi.util;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
/**
* A logger interface that strives to make it as easy as possible for
@@ -31,11 +32,17 @@ import java.util.*;
*/
public abstract class POILogger {
- public static int DEBUG = 1;
- public static int INFO = 3;
- public static int WARN = 5;
- public static int ERROR = 7;
- public static int FATAL = 9;
+ public static final int DEBUG = 1;
+ public static final int INFO = 3;
+ public static final int WARN = 5;
+ public static final int ERROR = 7;
+ public static final int FATAL = 9;
+
+ /** Short strings for numeric log level. Use level as array index. */
+ protected static final String LEVEL_STRINGS_SHORT[] = {"?", "D", "?", "I", "?", "W", "?", "E", "?", "F", "?"};
+ /** Long strings for numeric log level. Use level as array index. */
+ protected static final String LEVEL_STRINGS[] = {"?0?", "DEBUG", "?2?", "INFO", "?4?", "WARN", "?6?", "ERROR", "?8?", "FATAL", "?10+?"};
+
/**
* package scope so it cannot be instantiated outside of the util
diff --git a/src/java/org/apache/poi/util/SystemOutLogger.java b/src/java/org/apache/poi/util/SystemOutLogger.java
index bf88036f31..7804334273 100644
--- a/src/java/org/apache/poi/util/SystemOutLogger.java
+++ b/src/java/org/apache/poi/util/SystemOutLogger.java
@@ -60,8 +60,8 @@ public class SystemOutLogger extends POILogger
public void log(final int level, final Object obj1,
final Throwable exception) {
if (check(level)) {
- System.out.println("["+_cat+"] "+obj1);
- if(exception != null) {
+ System.out.println("[" + _cat + "]" + LEVEL_STRINGS_SHORT[Math.min(LEVEL_STRINGS_SHORT.length-1, level)] + " " + obj1);
+ if (exception != null) {
exception.printStackTrace(System.out);
}
}