]> source.dussan.org Git - poi.git/commitdiff
Fix bug #44201 - support cloning of DVRecord, so validation enabled sheets can be...
authorNick Burch <nick@apache.org>
Tue, 15 Jan 2008 16:42:44 +0000 (16:42 +0000)
committerNick Burch <nick@apache.org>
Tue, 15 Jan 2008 16:42:44 +0000 (16:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@612152 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/AbstractEscherHolderRecord.java
src/java/org/apache/poi/hssf/record/DVRecord.java
src/java/org/apache/poi/hssf/record/Record.java
src/testcases/org/apache/poi/hssf/data/44201.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

index 2617fbb43b3d9057b1ea90e502885ae353c16115..be8df6576382a27734c34309997e6a8f4255dbbf 100644 (file)
@@ -36,7 +36,8 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.0.2-FINAL" date="2008-??-??">
-            <action dev="POI-DEVELOPERS" type="fix">44200 - Enable cloning of sheets with notes </action>
+            <action dev="POI-DEVELOPERS" type="fix">44201 - Enable cloning of sheets with data validation rules</action>
+            <action dev="POI-DEVELOPERS" type="fix">44200 - Enable cloning of sheets with notes</action>
             <action dev="POI-DEVELOPERS" type="add">43008 - Add a moveCell method to HSSFRow, and deprecate setCellNum(), which didn't update things properly</action>
             <action dev="POI-DEVELOPERS" type="fix">43058 - Support setting row grouping on files from CR IX, which lack GutsRecords</action>
             <action dev="POI-DEVELOPERS" type="fix">31795 - Support cloning of sheets with certain drawing objects on them</action>
index 9e93592fc42699ead7a40ddee8d52e8a004e60c5..5868b0eb2d6983c19bfe3e8aeb6dfa066582dc2a 100644 (file)
@@ -33,7 +33,8 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.0.2-FINAL" date="2008-??-??">
-            <action dev="POI-DEVELOPERS" type="fix">44200 - Enable cloning of sheets with notes </action>
+            <action dev="POI-DEVELOPERS" type="fix">44201 - Enable cloning of sheets with data validation rules</action>
+            <action dev="POI-DEVELOPERS" type="fix">44200 - Enable cloning of sheets with notes</action>
             <action dev="POI-DEVELOPERS" type="add">43008 - Add a moveCell method to HSSFRow, and deprecate setCellNum(), which didn't update things properly</action>
             <action dev="POI-DEVELOPERS" type="fix">43058 - Support setting row grouping on files from CR IX, which lack GutsRecords</action>
             <action dev="POI-DEVELOPERS" type="fix">31795 - Support cloning of sheets with certain drawing objects on them</action>
index 0260fc915bd69a4f188669091b8947c24a7660f6..c5fae27ae37415af86d613ae58aa57e2b72c7f75 100644 (file)
@@ -18,7 +18,6 @@
 
 package org.apache.poi.hssf.record;
 
-import java.io.ByteArrayInputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -232,19 +231,7 @@ public abstract class AbstractEscherHolderRecord
 
     public Object clone()
     {
-       // Do it via a re-serialise
-       // It's a cheat, but it works...
-       byte[] b = serialize();
-       RecordInputStream rinp = new RecordInputStream(
-                       new ByteArrayInputStream(b)
-       );
-       rinp.nextRecord();
-
-       Record[] r = RecordFactory.createRecord(rinp);
-       if(r.length != 1) {
-               throw new IllegalStateException("Re-serialised a record to clone it, but got " + r.length + " records back!");
-       }
-       return r[0];
+       return cloneViaReserialise();
     }
 
     public void addEscherRecord(int index, EscherRecord element)
index 0bae009bd3f9382c58dd031d7ab2f7411af26dfb..e5527d61f19a0429d3c00c42c163bcdc7d7b7831 100644 (file)
 
 package org.apache.poi.hssf.record;
 
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Stack;
+
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.util.HSSFCellRangeAddress;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.StringUtil;
-import org.apache.poi.hssf.util.HSSFCellRangeAddress;
-import org.apache.poi.hssf.record.formula.Ptg;
-
-import java.io.IOException;
-import java.util.Stack;
-import java.util.Hashtable;
-import java.util.Enumeration;
 
 /**
  * Title:        DV Record<P>
@@ -502,6 +502,14 @@ public class DVRecord extends Record
     {
         return this.sid;
     }
+    
+    /**
+     * Clones the object. Uses serialisation, as the
+     *  contents are somewhat complex
+     */
+    public Object clone() {
+       return cloneViaReserialise();
+    }
 
     /**@todo DVRecord = Serializare */
 
index 3205c5774041578eee7b6ed329afa1c71981e21d..c1b8a0cfdab32a34c5e20a9eb6735125b10c3496 100644 (file)
@@ -19,6 +19,8 @@
 
 package org.apache.poi.hssf.record;
 
+import java.io.ByteArrayInputStream;
+
 /**
  * Title: Record
  * Description: All HSSF Records inherit from this class.  It
@@ -147,4 +149,30 @@ public abstract class Record
     public Object clone() {
       throw new RuntimeException("The class "+getClass().getName()+" needs to define a clone method");
     }
+    
+    /**
+     * Clone the current record, via a call to serialise
+     *  it, and another to create a new record from the
+     *  bytes.
+     * May only be used for classes which don't have
+     *  internal counts / ids in them. For those which
+     *  do, a full record-aware serialise is needed, which
+     *  allocates new ids / counts as needed.
+     */
+    public Record cloneViaReserialise()
+    {
+       // Do it via a re-serialise
+       // It's a cheat, but it works...
+       byte[] b = serialize();
+       RecordInputStream rinp = new RecordInputStream(
+                       new ByteArrayInputStream(b)
+       );
+       rinp.nextRecord();
+
+       Record[] r = RecordFactory.createRecord(rinp);
+       if(r.length != 1) {
+               throw new IllegalStateException("Re-serialised a record to clone it, but got " + r.length + " records back!");
+       }
+       return r[0];
+    }
 }
diff --git a/src/testcases/org/apache/poi/hssf/data/44201.xls b/src/testcases/org/apache/poi/hssf/data/44201.xls
new file mode 100644 (file)
index 0000000..593d5aa
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/44201.xls differ
index a3154e306342fb8265fa75a09d67efb0fa0a1a65..006b60c3dd6c38eaac3c18b356cb113ddb1be024 100644 (file)
@@ -934,6 +934,26 @@ extends TestCase {
 
     }
 
+    /**
+     * Bug 44201: Sheet not cloneable when validation added to excel cell
+     */
+    public void test44201() throws Exception {
+        FileInputStream in = new FileInputStream(new File(cwd, "44201.xls"));
+        HSSFWorkbook wb = new HSSFWorkbook(in);
+        in.close();
+
+        wb.cloneSheet(0);
+        assertTrue("No Exceptions while cloning sheet", true);
+
+        //serialize and read again
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        wb.write(out);
+        out.close();
+
+        wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+        assertTrue("No Exceptions while reading file", true);
+
+    }
 }