]> source.dussan.org Git - poi.git/commitdiff
fixed bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0
authorYegor Kozlov <yegor@apache.org>
Tue, 29 May 2007 08:32:56 +0000 (08:32 +0000)
committerYegor Kozlov <yegor@apache.org>
Tue, 29 May 2007 08:32:56 +0000 (08:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@542453 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
src/scratchpad/testcases/org/apache/poi/hslf/data/38256.ppt [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java

index 84a03e7a52848c6c389731c1066d162e5484319c..e41bc3d5d0b27e041b4b59dbb39c39cd892ee22d 100644 (file)
@@ -219,11 +219,42 @@ public class HSLFSlideShow extends POIDocument
                // If you don't know about the type, play safe and skip over it (using
                //  its length to know where the next record will start)
                //
-               // For now, this work is handled by Record.findChildRecords
-       
-               _records = Record.findChildRecords(_docstream,0,_docstream.length);
+
+        _records = read(_docstream, (int)currentUser.getCurrentEditOffset());
        }
 
+    private Record[] read(byte[] docstream, int usrOffset){
+        ArrayList lst = new ArrayList();
+        while (usrOffset != 0){
+            UserEditAtom usr = (UserEditAtom) Record.buildRecordAtOffset(docstream, usrOffset);
+            lst.add(new Integer(usrOffset));
+            int psrOffset = usr.getPersistPointersOffset();
+
+            PersistPtrHolder ptr = (PersistPtrHolder)Record.buildRecordAtOffset(docstream, psrOffset);
+            lst.add(new Integer(psrOffset));
+            Hashtable entries = ptr.getSlideLocationsLookup();
+            for (Iterator it = entries.keySet().iterator(); it.hasNext(); ) {
+                Integer id = (Integer)it.next();
+                Integer offset = (Integer)entries.get(id);
+
+                lst.add(offset);
+            }
+
+            usrOffset = usr.getLastUserEditAtomOffset();
+        }
+        //sort found records by offset.
+        //(it is not necessary but SlideShow.findMostRecentCoreRecords() expects them sorted)
+        Object a[] = lst.toArray();
+        Arrays.sort(a);
+        Record[] rec = new Record[lst.size()];
+        for (int i = 0; i < a.length; i++) {
+            Integer offset = (Integer)a[i];
+            rec[i] = (Record)Record.buildRecordAtOffset(docstream, offset.intValue());
+        }
+
+        return rec;
+    }
+
        /**
         * Find the "Current User" stream, and load it 
         */
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/38256.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/38256.ppt
new file mode 100644 (file)
index 0000000..a0883bd
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/38256.ppt differ
index 800194e585746fc994d72b6df30d8ad999f26d8b..cd1d9fd6b0df663a6d5db55faff32750bd3e1816 100644 (file)
@@ -269,4 +269,33 @@ public class TestBugs extends TestCase {
 \r
     }\r
 \r
+    /**\r
+     * Bug 38256:  RuntimeException: Couldn't instantiate the class for type with id 0.\r
+     * ( also fixed followup: getTextRuns() returns no text )\r
+     */\r
+    public void test38256 () throws Exception {\r
+        FileInputStream is = new FileInputStream(new File(cwd, "38256.ppt"));\r
+        SlideShow ppt = new SlideShow(is);\r
+        is.close();\r
+\r
+        assertTrue("No Exceptions while reading file", true);\r
+\r
+        Slide[] slide = ppt.getSlides();\r
+        assertEquals(1, slide.length);\r
+        TextRun[] runs = slide[0].getTextRuns();\r
+        assertEquals(4, runs.length);\r
+\r
+        HashSet txt = new HashSet();\r
+        txt.add("\93HAPPY BIRTHDAY SCOTT\94");\r
+        txt.add("Have a HAPPY DAY");\r
+        txt.add("PS Nobody is allowed to hassle Scott TODAY\85");\r
+        txt.add("Drinks will be in the Boardroom at 5pm today to celebrate Scott\92s B\92Day\85  See you all there!");\r
+\r
+        for (int i = 0; i < runs.length; i++) {\r
+            String text = runs[i].getRawText();\r
+            assertTrue(txt.contains(text));\r
+        }\r
+\r
+    }\r
+\r
 }\r