]> source.dussan.org Git - poi.git/commitdiff
Follow on from bug 44675 - regenerated functionMetadata.txt from new ooo excelfilefor...
authorJosh Micich <josh@apache.org>
Thu, 22 May 2008 03:26:25 +0000 (03:26 +0000)
committerJosh Micich <josh@apache.org>
Thu, 22 May 2008 03:26:25 +0000 (03:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@658986 13f79535-47bb-0310-9956-ffa450edef68

src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata-asGenerated.txt
src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata.txt
src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java
src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java
src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java

index 475131e1c0e4d347cd092cfde7691414384848b1..8a85f42841a8405a4e591145d67cc359a6750462 100644 (file)
@@ -14,7 +14,7 @@
 # limitations under the License.\r
 \r
 # Created by (org.apache.poi.hssf.record.formula.function.ExcelFileFormatDocFunctionExtractor)\r
-# from source file 'excelfileformat.odt' (size=355750, crc=0x2FAEA65A)\r
+# from source file 'excelfileformat.odt' (size=356107, md5=0x8f789cb6e75594caf068f8e193004ef4)\r
 #\r
 #Columns: (index, name, minParams, maxParams, returnClass, paramClasses, isVolatile, hasFootnote )\r
 \r
@@ -37,7 +37,7 @@
 15     SIN     1       1       V       V               \r
 16     COS     1       1       V       V               \r
 17     TAN     1       1       V       V               \r
-18     ARCTAN  1       1       V       V               \r
+18     ATAN    1       1       V       V               \r
 19     PI      0       0       V       -               \r
 20     SQRT    1       1       V       V               \r
 21     EXP     1       1       V       V               \r
 169    COUNTA  0       30      V       R               \r
 183    PRODUCT 0       30      V       R               \r
 184    FACT    1       1       V       V               \r
-191    DPRODUCT        3       3       V       R R R           \r
-192    ISNONTEXT       1       1       V       V               \r
+189    DPRODUCT        3       3       V       R R R           \r
+190    ISNONTEXT       1       1       V       V               \r
 193    STDEVP  1       30      V       R               \r
 194    VARP    1       30      V       R               \r
 195    DSTDEVP 3       3       V       R R R           \r
 244    INFO    1       1       V       V               \r
 # New Built-In Sheet Functions in BIFF4\r
 14     FIXED   2       3       V       V V V           x\r
+204    USDOLLAR        1       2       V       V V             x\r
+215    DBCS    1       1       V       V               x\r
 216    RANK    2       3       V       V R V           \r
 247    DB      4       5       V       V V V V V               \r
 252    FREQUENCY       2       2       A       R R             \r
index 6902027de974b8925260c978be952f9cc2a79cce..8a85f42841a8405a4e591145d67cc359a6750462 100644 (file)
 # limitations under the License.\r
 \r
 # Created by (org.apache.poi.hssf.record.formula.function.ExcelFileFormatDocFunctionExtractor)\r
-# from source file 'excelfileformat.odt' (size=355750, crc=0x2FAEA65A)\r
+# from source file 'excelfileformat.odt' (size=356107, md5=0x8f789cb6e75594caf068f8e193004ef4)\r
 #\r
 #Columns: (index, name, minParams, maxParams, returnClass, paramClasses, isVolatile, hasFootnote )\r
-#\r
-# + some manual edits !\r
 \r
 # Built-In Sheet Functions in BIFF2\r
 0      COUNT   0       30      V       R               \r
 244    INFO    1       1       V       V               \r
 # New Built-In Sheet Functions in BIFF4\r
 14     FIXED   2       3       V       V V V           x\r
-204    USDOLLAR        1       1       V       V               x\r
+204    USDOLLAR        1       2       V       V V             x\r
 215    DBCS    1       1       V       V               x\r
 216    RANK    2       3       V       V R V           \r
 247    DB      4       5       V       V V V V V               \r
index 47137df4f6440d3f6299e7639e3920fa28d76161..7702fce3d4db5487ca056bcd9e4950c269028794 100644 (file)
@@ -26,9 +26,12 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
+import java.math.BigInteger;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -37,7 +40,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.Stack;
-import java.util.zip.CRC32;
 import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
 
@@ -149,7 +151,6 @@ public final class ExcelFileFormatDocFunctionExtractor {
        
        private static final class FunctionDataCollector {
 
-
                private final Map _allFunctionsByIndex;
                private final Map _allFunctionsByName;
                private final Set _groupFunctionIndexes;
@@ -184,25 +185,29 @@ public final class ExcelFileFormatDocFunctionExtractor {
                        _allFunctionsByName.put(funcName, fd);
                }
 
+               /**
+                * Some extra validation here.
+                * Any function which changes definition will have a footnote in the source document
+                */
                private void checkRedefinedFunction(boolean hasNote, String funcName, Integer funcIxKey) {
                        FunctionData fdPrev;
+                       // check by index
                        fdPrev = (FunctionData) _allFunctionsByIndex.get(funcIxKey);
                        if(fdPrev != null) {
-                               if(fdPrev.hasFootnote() && hasNote) {
-                                       // func def can change if both have a foot-note
-                                       _allFunctionsByName.remove(fdPrev.getName());
-                               } else {
-                                       throw new RuntimeException("changing function definition without foot-note");
+                               if(!fdPrev.hasFootnote() || !hasNote) {
+                                       throw new RuntimeException("changing function [" 
+                                                       + funcIxKey + "] definition without foot-note");
                                }
+                               _allFunctionsByName.remove(fdPrev.getName());
                        }
+                       // check by name
                        fdPrev = (FunctionData) _allFunctionsByName.get(funcName);
                        if(fdPrev != null) {
-                               if(fdPrev.hasFootnote() && hasNote) {
-                                       // func def can change if both have a foot-note
-                                       _allFunctionsByIndex.remove(new Integer(fdPrev.getIndex()));
-                               } else {
-                                       throw new RuntimeException("changing function definition without foot-note");
+                               if(!fdPrev.hasFootnote() || !hasNote) {
+                                       throw new RuntimeException("changing function '" 
+                                                       + funcName + "' definition without foot-note");
                                }
+                               _allFunctionsByIndex.remove(new Integer(fdPrev.getIndex()));
                        }
                }
 
@@ -237,9 +242,13 @@ public final class ExcelFileFormatDocFunctionExtractor {
                private static final String[] TABLE_CELL_RELPATH_NAMES = {
                        "table:table-row", "table:table-cell", "text:p",        
                };
-               private static final String[] NOTE_REF_RELPATH_NAMES = {
+               // after May 2008 there was one more style applied to the footnotes
+               private static final String[] NOTE_REF_RELPATH_NAMES_OLD = { 
                        "table:table-row", "table:table-cell", "text:p", "text:span", "text:note-ref",
                };
+               private static final String[] NOTE_REF_RELPATH_NAMES = {
+                       "table:table-row", "table:table-cell", "text:p", "text:span", "text:span", "text:note-ref",
+               };
 
 
                private final Stack _elemNameStack;
@@ -368,6 +377,8 @@ public final class ExcelFileFormatDocFunctionExtractor {
                        } else if(matchesRelPath(TABLE_CELL_RELPATH_NAMES)) {
                                _textNodeBuffer.setLength(0);
                                _cellHasNote = false;
+                       } else if(matchesRelPath(NOTE_REF_RELPATH_NAMES_OLD)) {
+                               _cellHasNote = true;
                        } else if(matchesRelPath(NOTE_REF_RELPATH_NAMES)) {
                                _cellHasNote = true;
                        }
@@ -456,6 +467,9 @@ public final class ExcelFileFormatDocFunctionExtractor {
        }
 
        private static void processFile(File effDocFile, File outFile) {
+               if(!effDocFile.exists()) {
+                       throw new RuntimeException("file '" + effDocFile.getAbsolutePath() + "' does not exist");
+               }
                OutputStream os;
                try {
                        os = new FileOutputStream(outFile);
@@ -475,7 +489,7 @@ public final class ExcelFileFormatDocFunctionExtractor {
                ps.println("# Created by (" + genClass.getName() + ")");
                // identify the source file
                ps.print("# from source file '" + SOURCE_DOC_FILE_NAME + "'");
-               ps.println(" (size=" + effDocFile.length() + ", crc=" + getFileCRC(effDocFile) + ")");
+               ps.println(" (size=" + effDocFile.length() + ", md5=" + getFileMD5(effDocFile) + ")");
                ps.println("#");
                ps.println("#Columns: (index, name, minParams, maxParams, returnClass, paramClasses, isVolatile, hasFootnote )");
                ps.println("");
@@ -490,6 +504,14 @@ public final class ExcelFileFormatDocFunctionExtractor {
                        throw new RuntimeException(e);
                }
                ps.close();
+               
+               String canonicalOutputFileName;
+               try {
+                       canonicalOutputFileName = outFile.getCanonicalPath();
+               } catch (IOException e) {
+                       throw new RuntimeException(e);
+               }
+               System.out.println("Successfully output to '" + canonicalOutputFileName + "'");
        }
 
        private static void outputLicenseHeader(PrintStream ps) {
@@ -519,8 +541,14 @@ public final class ExcelFileFormatDocFunctionExtractor {
        /**
         * Helps identify the source file
         */
-       private static String getFileCRC(File f) {
-               CRC32 crc = new CRC32();
+       private static String getFileMD5(File f) {
+               MessageDigest m;
+               try {
+                       m = MessageDigest.getInstance("MD5");
+               } catch (NoSuchAlgorithmException e) {
+                       throw new RuntimeException(e);
+               }
+
                byte[]buf = new byte[2048];
                try {
                        InputStream is = new FileInputStream(f);
@@ -529,21 +557,17 @@ public final class ExcelFileFormatDocFunctionExtractor {
                                if(bytesRead<1) { 
                                        break;
                                }
-                               crc.update(buf, 0, bytesRead);
+                               m.update(buf, 0, bytesRead);
                        }
                        is.close();
                } catch (IOException e) {
                        throw new RuntimeException(e);
                }
-               return "0x" + Long.toHexString(crc.getValue()).toUpperCase();
+               
+               return "0x" + new BigInteger(1, m.digest()).toString(16);
        }
 
-       private static File getSourceFile() {
-               if (false) {
-                       File dir = new File("c:/temp");
-                       File effDocFile = new File(dir, SOURCE_DOC_FILE_NAME);
-                       return effDocFile;
-               }
+       private static File downloadSourceFile() {
                URL url;
                try {
                        url = new URL("http://sc.openoffice.org/" + SOURCE_DOC_FILE_NAME);
@@ -557,7 +581,7 @@ public final class ExcelFileFormatDocFunctionExtractor {
                        URLConnection conn = url.openConnection();
                        InputStream is = conn.getInputStream();
                        System.out.println("downloading " + url.toExternalForm());
-                       result = File.createTempFile("excelfileformat", "odt");
+                       result = File.createTempFile("excelfileformat", ".odt");
                        OutputStream os = new FileOutputStream(result);
                        while(true) {
                                int bytesRead = is.read(buf);
@@ -577,12 +601,17 @@ public final class ExcelFileFormatDocFunctionExtractor {
 
        public static void main(String[] args) {
 
-               File effDocFile = getSourceFile();
-               if(!effDocFile.exists()) {
-                       throw new RuntimeException("file '" + effDocFile.getAbsolutePath() + "' does not exist");
-               }
-
                File outFile = new File("functionMetadata-asGenerated.txt");
-               processFile(effDocFile, outFile);
+
+               if (false) { // set true to use local file
+                       File dir = new File("c:/temp");
+                       File effDocFile = new File(dir, SOURCE_DOC_FILE_NAME);
+                       processFile(effDocFile, outFile);
+                       return;
+               }
+               
+               File tempEFFDocFile = downloadSourceFile();
+               processFile(tempEFFDocFile, outFile);
+               tempEFFDocFile.delete();
        }
 }
index 1e26fa706ed1f90cb79111b85e42a388969bb31a..7030c5a508c0ca189a08780b4bd68e8a7e348847 100644 (file)
@@ -21,7 +21,6 @@ import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.model.FormulaParser;
-import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
 import org.apache.poi.hssf.record.formula.FuncPtg;
 import org.apache.poi.hssf.record.formula.FuncVarPtg;
@@ -29,7 +28,7 @@ import org.apache.poi.hssf.record.formula.Ptg;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 /**
  * Tests parsing of some built-in functions that were not properly
- * registered in POI as bug #44675, #44733 (March/April 2008).
+ * registered in POI as of bug #44675, #44733 (March/April 2008).
  * 
  * @author Josh Micich
  */
@@ -76,7 +75,7 @@ public final class TestParseMissingBuiltInFuncs extends TestCase {
        }
        
        public void testUsdollar() {
-               confirmFunc("USDOLLAR(1)", 2, false, 204);
+               confirmFunc("USDOLLAR(1)", 2, true, 204);
        }
 
        public void testDBCS() {
index 6766f2fc073b9ebe7f4146125fd3a7720b4b979f..0a62d64cdbfba944ab39c668c5551c1419e34bfb 100644 (file)
 
 package org.apache.poi.hssf.record.formula.function;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.RecordFormatException;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
 /**
  * Tests reading from a sample spreadsheet some built-in functions that were not properly
- * registered in POI as bug #44675, #44733 (March/April 2008).
+ * registered in POI as of bug #44675, #44733 (March/April 2008).
  * 
  * @author Josh Micich
  */