diff options
author | Nick Burch <nick@apache.org> | 2007-03-29 11:50:50 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2007-03-29 11:50:50 +0000 |
commit | 3ad3a22fd533582b63d82c43f5cb945a6927d59c (patch) | |
tree | 95b6f5a7994811b72107f6e9a93cde2612b24ddc | |
parent | 12dfa5656536c79f2f3a830014ca1403f2924f38 (diff) | |
download | poi-3ad3a22fd533582b63d82c43f5cb945a6927d59c.tar.gz poi-3ad3a22fd533582b63d82c43f5cb945a6927d59c.zip |
Don't NPE if we have a reference to a note, where there's no core record to go with that note's RefID. Instead, just log it, and pretend the note wasn't there.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@523678 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java | 28 | ||||
-rw-r--r-- | src/scratchpad/testcases/org/apache/poi/hslf/data/missing_core_records.ppt | bin | 0 -> 3012096 bytes | |||
-rw-r--r-- | src/scratchpad/testcases/org/apache/poi/hslf/extractor/TextExtractor.java | 30 |
3 files changed, 45 insertions, 13 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java index 400eecdc33..fdecb2bb04 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java @@ -273,8 +273,13 @@ public class SlideShow private Record getCoreRecordForRefID(int refID) { Integer coreRecordId = (Integer) _sheetIdToCoreRecordsLookup.get(new Integer(refID)); - Record r = _mostRecentCoreRecords[coreRecordId.intValue()]; - return r; + if(coreRecordId != null) { + Record r = _mostRecentCoreRecords[coreRecordId.intValue()]; + return r; + } else { + logger.log(POILogger.ERROR, "We tried to look up a reference to a core record, but there was no core ID for reference ID " + refID); + return null; + } } /** @@ -352,23 +357,26 @@ public class SlideShow } else { // Match up the records and the SlideAtomSets notesSets = notesSLWT.getSlideAtomsSets(); - notesRecords = new org.apache.poi.hslf.record.Notes[notesSets.length]; + ArrayList notesRecordsL = new ArrayList(); for(int i=0; i<notesSets.length; i++) { // Get the right core record Record r = getCoreRecordForSAS(notesSets[i]); // Ensure it really is a notes record - if(r instanceof org.apache.poi.hslf.record.Notes) { - notesRecords[i] = (org.apache.poi.hslf.record.Notes)r; + if(r != null && r instanceof org.apache.poi.hslf.record.Notes) { + notesRecordsL.add( (org.apache.poi.hslf.record.Notes)r ); + + // Record the match between slide id and these notes + SlidePersistAtom spa = notesSets[i].getSlidePersistAtom(); + Integer slideId = new Integer(spa.getSlideIdentifier()); + slideIdToNotes.put(slideId, new Integer(i)); } else { logger.log(POILogger.ERROR, "A Notes SlideAtomSet at " + i + " said its record was at refID " + notesSets[i].getSlidePersistAtom().getRefID() + ", but that was actually a " + r); } - - // Record the match between slide id and these notes - SlidePersistAtom spa = notesSets[i].getSlidePersistAtom(); - Integer slideId = new Integer(spa.getSlideIdentifier()); - slideIdToNotes.put(slideId, new Integer(i)); } + notesRecords = new org.apache.poi.hslf.record.Notes[notesRecordsL.size()]; + notesRecords = (org.apache.poi.hslf.record.Notes[]) + notesRecordsL.toArray(notesRecords); } // Now, do the same thing for our slides diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/missing_core_records.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/missing_core_records.ppt Binary files differnew file mode 100644 index 0000000000..67325ebcf6 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hslf/data/missing_core_records.ppt diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TextExtractor.java b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TextExtractor.java index 3ca3a19952..e0e0318e77 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TextExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TextExtractor.java @@ -29,13 +29,15 @@ import junit.framework.TestCase; * @author Nick Burch (nick at torchbox dot com) */ public class TextExtractor extends TestCase { - // Extractor primed on the 2 page basic test data + /** Extractor primed on the 2 page basic test data */ private PowerPointExtractor ppe; - // Extractor primed on the 1 page but text-box'd test data + /** Extractor primed on the 1 page but text-box'd test data */ private PowerPointExtractor ppe2; + /** Where to go looking for our test files */ + private String dirname; public TextExtractor() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); + dirname = System.getProperty("HSLF.testdata.path"); String filename = dirname + "/basic_test_ppt_file.ppt"; ppe = new PowerPointExtractor(filename); String filename2 = dirname + "/with_textbox.ppt"; @@ -70,6 +72,28 @@ public class TextExtractor extends TestCase { ensureTwoStringsTheSame(expectText, notesText); } + + /** + * Test that when presented with a PPT file missing the odd + * core record, we can still get the rest of the text out + * @throws Exception + */ + public void testMissingCoreRecords() throws Exception { + String filename = dirname + "/missing_core_records.ppt"; + ppe = new PowerPointExtractor(filename); + + String text = ppe.getText(true, false); + String nText = ppe.getNotes(); + + assertNotNull(text); + assertNotNull(nText); + + // Notes record were corrupt, so don't expect any + assertEquals(nText.length(), 0); + + // Slide records were fine + assertTrue(text.startsWith("Using Disease Surveillance and Response")); + } private void ensureTwoStringsTheSame(String exp, String act) throws Exception { assertEquals(exp.length(),act.length()); |