]> source.dussan.org Git - poi.git/commitdiff
Bugzilla 54625 - Register user-defined functions in instance scope instead of static
authorYegor Kozlov <yegor@apache.org>
Sun, 3 Mar 2013 16:16:12 +0000 (16:16 +0000)
committerYegor Kozlov <yegor@apache.org>
Sun, 3 Mar 2013 16:16:12 +0000 (16:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1452060 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
src/java/org/apache/poi/ss/formula/udf/IndexedUDFFinder.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/xssf/model/IndexedUDFFinder.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java

index f3076d3ccc0a3ac8521608e06fc017d031a6516e..8f2a33f6b56af521454d52b56879abd7aece943c 100644 (file)
@@ -57,6 +57,7 @@ import org.apache.poi.ss.util.WorkbookUtil;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.poi.ss.formula.udf.IndexedUDFFinder;
 
 
 /**
@@ -145,7 +146,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
      * The locator of user-defined functions.
      * By default includes functions from the Excel Analysis Toolpack
      */
-    private UDFFinder _udfFinder = UDFFinder.DEFAULT;
+    private UDFFinder _udfFinder = new IndexedUDFFinder(UDFFinder.DEFAULT);
 
     public static HSSFWorkbook create(InternalWorkbook book) {
        return new HSSFWorkbook(book);
diff --git a/src/java/org/apache/poi/ss/formula/udf/IndexedUDFFinder.java b/src/java/org/apache/poi/ss/formula/udf/IndexedUDFFinder.java
new file mode 100644 (file)
index 0000000..279df4f
--- /dev/null
@@ -0,0 +1,54 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.ss.formula.udf;
+
+import org.apache.poi.ss.formula.functions.FreeRefFunction;
+import org.apache.poi.util.Internal;
+
+import java.util.HashMap;
+
+/**
+ * A UDFFinder that can retrieve functions both by name and by fake index.
+ *
+ * @author Yegor Kozlov
+ */
+@Internal
+public class IndexedUDFFinder extends AggregatingUDFFinder {
+    private final HashMap<Integer, String> _funcMap;
+
+    public IndexedUDFFinder(UDFFinder... usedToolPacks) {
+        super(usedToolPacks);
+        _funcMap = new HashMap<Integer, String>();
+    }
+
+    public FreeRefFunction findFunction(String name) {
+        FreeRefFunction func = super.findFunction(name);
+        if (func != null) {
+            int idx = getFunctionIndex(name);
+            _funcMap.put(idx, name);
+        }
+        return func;
+    }
+
+    public String getFunctionName(int idx) {
+        return _funcMap.get(idx);
+    }
+
+    public int getFunctionIndex(String name) {
+        return name.hashCode();
+    }
+}
index 2814a89a845925ce3ee240446604a9293b46c307..475c0612c04bcc3a613d55fd8a9b83c32e3a6a5d 100644 (file)
@@ -1,56 +1,37 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-package org.apache.poi.xssf.model;
-
-import org.apache.poi.ss.formula.functions.FreeRefFunction;
-import org.apache.poi.ss.formula.udf.AggregatingUDFFinder;
-import org.apache.poi.ss.formula.udf.UDFFinder;
-import org.apache.poi.util.Internal;
-
-import java.util.HashMap;
-
-/**
- * A UDFFinder that can retrieve functions both by name and by fake index.
- *
- * @author Yegor Kozlov
- */
-@Internal
-public final class IndexedUDFFinder extends AggregatingUDFFinder {
-    private final HashMap<Integer, String> _funcMap;
-
-    public IndexedUDFFinder(UDFFinder... usedToolPacks) {
-        super(usedToolPacks);
-        _funcMap = new HashMap<Integer, String>();
-    }
-
-    public FreeRefFunction findFunction(String name) {
-        FreeRefFunction func = super.findFunction(name);
-        if (func != null) {
-            int idx = getFunctionIndex(name);
-            _funcMap.put(idx, name);
-        }
-        return func;
-    }
-
-    public String getFunctionName(int idx) {
-        return _funcMap.get(idx);
-    }
-
-    public int getFunctionIndex(String name) {
-        return name.hashCode();
-    }
-}
+/*\r
+ *  ====================================================================\r
+ *    Licensed to the Apache Software Foundation (ASF) under one or more\r
+ *    contributor license agreements.  See the NOTICE file distributed with\r
+ *    this work for additional information regarding copyright ownership.\r
+ *    The ASF licenses this file to You under the Apache License, Version 2.0\r
+ *    (the "License"); you may not use this file except in compliance with\r
+ *    the License.  You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ * ====================================================================\r
+ */\r
+\r
+package org.apache.poi.xssf.model;\r
+\r
+import org.apache.poi.ss.formula.udf.UDFFinder;\r
+\r
+\r
+/**\r
+ * IndexedUDFFinder was moved to the org.apache.poi.ss.formula.udf package.\r
+ * This class is left ONLY for backwards compatibity with existing code.\r
+ *\r
+ * @author Yegor Kozlov\r
+ * @deprecated\r
+ */\r
+@Deprecated\r
+public final class IndexedUDFFinder extends org.apache.poi.ss.formula.udf.IndexedUDFFinder{\r
+    public IndexedUDFFinder(UDFFinder... usedToolPacks) {\r
+        super(usedToolPacks);\r
+    }\r
+}\r
index e9ba3c7bb1df222e2a1e46a78a70e7b28fe5b58e..a49502f73763275aa933474e1f7f9b3acf2c8810 100644 (file)
@@ -31,7 +31,7 @@ import org.apache.poi.ss.formula.FormulaParsingWorkbook;
 import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
 import org.apache.poi.ss.formula.FormulaType;
 import org.apache.poi.ss.formula.udf.UDFFinder;
-import org.apache.poi.xssf.model.IndexedUDFFinder;
+import org.apache.poi.ss.formula.udf.IndexedUDFFinder;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
 
 /**
index d7a0e00b98f72cbccc9a634ce7874cf43d80af69..ab23bbf36f3d4d8340793e172a829abe2fad11c6 100644 (file)
@@ -41,6 +41,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationship;
 import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
 import org.apache.poi.openxml4j.opc.PackagingURIHelper;
 import org.apache.poi.openxml4j.opc.TargetMode;
+import org.apache.poi.ss.formula.udf.IndexedUDFFinder;
 import org.apache.poi.ss.formula.udf.UDFFinder;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
@@ -50,7 +51,6 @@ import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.ss.util.WorkbookUtil;
 import org.apache.poi.util.*;
-import org.apache.poi.xslf.usermodel.XSLFPictureData;
 import org.apache.poi.xssf.model.*;
 import org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils;
 import org.apache.xmlbeans.XmlException;