mirror of https://github.com/apache/poi.git
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
This commit is contained in:
parent
12dfa56565
commit
3ad3a22fd5
|
@ -273,8 +273,13 @@ public class SlideShow
|
||||||
private Record getCoreRecordForRefID(int refID) {
|
private Record getCoreRecordForRefID(int refID) {
|
||||||
Integer coreRecordId = (Integer)
|
Integer coreRecordId = (Integer)
|
||||||
_sheetIdToCoreRecordsLookup.get(new Integer(refID));
|
_sheetIdToCoreRecordsLookup.get(new Integer(refID));
|
||||||
|
if(coreRecordId != null) {
|
||||||
Record r = _mostRecentCoreRecords[coreRecordId.intValue()];
|
Record r = _mostRecentCoreRecords[coreRecordId.intValue()];
|
||||||
return r;
|
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,24 +357,27 @@ public class SlideShow
|
||||||
} else {
|
} else {
|
||||||
// Match up the records and the SlideAtomSets
|
// Match up the records and the SlideAtomSets
|
||||||
notesSets = notesSLWT.getSlideAtomsSets();
|
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++) {
|
for(int i=0; i<notesSets.length; i++) {
|
||||||
// Get the right core record
|
// Get the right core record
|
||||||
Record r = getCoreRecordForSAS(notesSets[i]);
|
Record r = getCoreRecordForSAS(notesSets[i]);
|
||||||
|
|
||||||
// Ensure it really is a notes record
|
// Ensure it really is a notes record
|
||||||
if(r instanceof org.apache.poi.hslf.record.Notes) {
|
if(r != null && r instanceof org.apache.poi.hslf.record.Notes) {
|
||||||
notesRecords[i] = (org.apache.poi.hslf.record.Notes)r;
|
notesRecordsL.add( (org.apache.poi.hslf.record.Notes)r );
|
||||||
} 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
|
// Record the match between slide id and these notes
|
||||||
SlidePersistAtom spa = notesSets[i].getSlidePersistAtom();
|
SlidePersistAtom spa = notesSets[i].getSlidePersistAtom();
|
||||||
Integer slideId = new Integer(spa.getSlideIdentifier());
|
Integer slideId = new Integer(spa.getSlideIdentifier());
|
||||||
slideIdToNotes.put(slideId, new Integer(i));
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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
|
// Now, do the same thing for our slides
|
||||||
org.apache.poi.hslf.record.Slide[] slidesRecords;
|
org.apache.poi.hslf.record.Slide[] slidesRecords;
|
||||||
|
|
Binary file not shown.
|
@ -29,13 +29,15 @@ import junit.framework.TestCase;
|
||||||
* @author Nick Burch (nick at torchbox dot com)
|
* @author Nick Burch (nick at torchbox dot com)
|
||||||
*/
|
*/
|
||||||
public class TextExtractor extends TestCase {
|
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;
|
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;
|
private PowerPointExtractor ppe2;
|
||||||
|
/** Where to go looking for our test files */
|
||||||
|
private String dirname;
|
||||||
|
|
||||||
public TextExtractor() throws Exception {
|
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";
|
String filename = dirname + "/basic_test_ppt_file.ppt";
|
||||||
ppe = new PowerPointExtractor(filename);
|
ppe = new PowerPointExtractor(filename);
|
||||||
String filename2 = dirname + "/with_textbox.ppt";
|
String filename2 = dirname + "/with_textbox.ppt";
|
||||||
|
@ -71,6 +73,28 @@ public class TextExtractor extends TestCase {
|
||||||
ensureTwoStringsTheSame(expectText, notesText);
|
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 {
|
private void ensureTwoStringsTheSame(String exp, String act) throws Exception {
|
||||||
assertEquals(exp.length(),act.length());
|
assertEquals(exp.length(),act.length());
|
||||||
char[] expC = exp.toCharArray();
|
char[] expC = exp.toCharArray();
|
||||||
|
|
Loading…
Reference in New Issue