Fixed PPT parser to tolerate Comment2000 containers with missing comment text, see Bugzilla 44770
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@811814 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
20ea9dce10
commit
4841ed0d47
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.5-beta7" date="2009-??-??">
|
<release version="3.5-beta7" date="2009-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">44770 - Fixed PPT parser to tolerate Comment2000 containers with missing comment text</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">47773 - Fix for extraction paragraphs and sections from headers/footers with XWPFWordExtractor</action>
|
<action dev="POI-DEVELOPERS" type="fix">47773 - Fix for extraction paragraphs and sections from headers/footers with XWPFWordExtractor</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">47727 - Support for extraction of header / footer images in HWPF</action>
|
<action dev="POI-DEVELOPERS" type="fix">47727 - Support for extraction of header / footer images in HWPF</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">moved all test data to a top-level directory</action>
|
<action dev="POI-DEVELOPERS" type="fix">moved all test data to a top-level directory</action>
|
||||||
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
import org.apache.poi.util.POILogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a comment on a slide, in the format used by
|
* This class represents a comment on a slide, in the format used by
|
||||||
@ -32,10 +33,24 @@ public final class Comment2000 extends RecordContainer {
|
|||||||
private static long _type = 12000;
|
private static long _type = 12000;
|
||||||
|
|
||||||
// Links to our more interesting children
|
// Links to our more interesting children
|
||||||
private CString authorRecord;
|
|
||||||
private CString authorInitialsRecord;
|
/**
|
||||||
private CString commentRecord;
|
* An optional string that specifies the name of the author of the presentation comment.
|
||||||
private Comment2000Atom commentAtom;
|
*/
|
||||||
|
private CString authorRecord;
|
||||||
|
/**
|
||||||
|
* An optional string record that specifies the text of the presentation comment
|
||||||
|
*/
|
||||||
|
private CString authorInitialsRecord;
|
||||||
|
/**
|
||||||
|
* An optional string record that specifies the initials of the author of the presentation comment
|
||||||
|
*/
|
||||||
|
private CString commentRecord;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Comment2000Atom record that specifies the settings for displaying the presentation comment
|
||||||
|
*/
|
||||||
|
private Comment2000Atom commentAtom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Comment2000Atom of this Comment
|
* Returns the Comment2000Atom of this Comment
|
||||||
@ -46,7 +61,7 @@ public final class Comment2000 extends RecordContainer {
|
|||||||
* Get the Author of this comment
|
* Get the Author of this comment
|
||||||
*/
|
*/
|
||||||
public String getAuthor() {
|
public String getAuthor() {
|
||||||
return authorRecord.getText();
|
return authorRecord == null ? null : authorRecord.getText();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Set the Author of this comment
|
* Set the Author of this comment
|
||||||
@ -59,7 +74,7 @@ public final class Comment2000 extends RecordContainer {
|
|||||||
* Get the Author's Initials of this comment
|
* Get the Author's Initials of this comment
|
||||||
*/
|
*/
|
||||||
public String getAuthorInitials() {
|
public String getAuthorInitials() {
|
||||||
return authorInitialsRecord.getText();
|
return authorInitialsRecord == null ? null : authorInitialsRecord.getText();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Set the Author's Initials of this comment
|
* Set the Author's Initials of this comment
|
||||||
@ -72,7 +87,7 @@ public final class Comment2000 extends RecordContainer {
|
|||||||
* Get the text of this comment
|
* Get the text of this comment
|
||||||
*/
|
*/
|
||||||
public String getText() {
|
public String getText() {
|
||||||
return commentRecord.getText();
|
return commentRecord == null ? null : commentRecord.getText();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Set the text of this comment
|
* Set the text of this comment
|
||||||
@ -100,30 +115,23 @@ public final class Comment2000 extends RecordContainer {
|
|||||||
* methods.
|
* methods.
|
||||||
*/
|
*/
|
||||||
private void findInterestingChildren() {
|
private void findInterestingChildren() {
|
||||||
// First child should be the author
|
|
||||||
if(_children[0] instanceof CString) {
|
for(Record r : _children){
|
||||||
authorRecord = (CString)_children[0];
|
if (r instanceof CString){
|
||||||
} else {
|
CString cs = (CString)r;
|
||||||
throw new IllegalStateException("First child record wasn't a CString, was of type " + _children[0].getRecordType());
|
int recInstance = cs.getOptions() >> 4;
|
||||||
}
|
switch(recInstance){
|
||||||
// Second child should be the text
|
case 0: authorRecord = cs; break;
|
||||||
if(_children[1] instanceof CString) {
|
case 1: commentRecord = cs; break;
|
||||||
commentRecord = (CString)_children[1];
|
case 2: authorInitialsRecord = cs; break;
|
||||||
} else {
|
}
|
||||||
throw new IllegalStateException("Second child record wasn't a CString, was of type " + _children[1].getRecordType());
|
} else if (r instanceof Comment2000Atom){
|
||||||
}
|
commentAtom = (Comment2000Atom)r;
|
||||||
// Third child should be the author's initials
|
} else {
|
||||||
if(_children[2] instanceof CString) {
|
logger.log(POILogger.WARN, "Unexpected record with type="+r.getRecordType()+" in Comment2000: " + r.getClass().getName());
|
||||||
authorInitialsRecord = (CString)_children[2];
|
}
|
||||||
} else {
|
}
|
||||||
throw new IllegalStateException("Third child record wasn't a CString, was of type " + _children[2].getRecordType());
|
|
||||||
}
|
|
||||||
// Fourth child should be the comment atom
|
|
||||||
if(_children[3] instanceof Comment2000Atom) {
|
|
||||||
commentAtom = (Comment2000Atom)_children[3];
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("Fourth child record wasn't a Comment2000Atom, was of type " + _children[3].getRecordType());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -192,4 +192,32 @@ public final class TestComment2000 extends TestCase {
|
|||||||
assertEquals(data_b[i],bn[i]);
|
assertEquals(data_b[i],bn[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Comment2000 records with missing commentTextAtom
|
||||||
|
*/
|
||||||
|
public void testBug44770() {
|
||||||
|
byte[] data = {
|
||||||
|
0x0F, 0x00, (byte)0xE0, 0x2E, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xBA, 0x0F,
|
||||||
|
0x08, 0x00, 0x00, 0x00, 0x4E, 0x00, 0x45, 0x00, 0x53, 0x00, 0x53, 0x00, 0x20,
|
||||||
|
0x00, (byte)0xBA, 0x0F, 0x02, 0x00, 0x00, 0x00, 0x4E, 0x00, 0x00, 0x00, (byte)0xE1, 0x2E,
|
||||||
|
0x1C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, (byte)0xD9, 0x07, 0x08, 0x00,
|
||||||
|
0x01, 0x00, 0x18, 0x00, 0x10, 0x00, 0x1F, 0x00, 0x05, 0x00, (byte)0x80, 0x03,
|
||||||
|
0x0A, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 00
|
||||||
|
};
|
||||||
|
Comment2000 ca = new Comment2000(data, 0, data.length);
|
||||||
|
Record[] ch = ca.getChildRecords();
|
||||||
|
assertEquals(3, ch.length);
|
||||||
|
|
||||||
|
assertTrue(ch[0] instanceof CString);
|
||||||
|
assertEquals(0, ((CString)ch[0]).getOptions() >> 4);
|
||||||
|
assertTrue(ch[1] instanceof CString);
|
||||||
|
assertEquals(2, ((CString)ch[1]).getOptions() >> 4);
|
||||||
|
assertTrue(ch[2] instanceof Comment2000Atom);
|
||||||
|
|
||||||
|
assertEquals("NESS", ca.getAuthor());
|
||||||
|
assertEquals("N", ca.getAuthorInitials());
|
||||||
|
assertNull(ca.getText()); //commentTextAtom is missing
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user