poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r811814 - in /poi/trunk/src: documentation/content/xdocs/status.xml scratchpad/src/org/apache/poi/hslf/record/Comment2000.java scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java
Date Sun, 06 Sep 2009 11:35:01 GMT
Author: yegor
Date: Sun Sep  6 11:35:01 2009
New Revision: 811814

URL: http://svn.apache.org/viewvc?rev=811814&view=rev
Log:
Fixed PPT parser to tolerate Comment2000 containers with missing comment text, see Bugzilla
44770

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=811814&r1=811813&r2=811814&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Sun Sep  6 11:35:01 2009
@@ -33,6 +33,7 @@
 
     <changes>
         <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">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>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java?rev=811814&r1=811813&r2=811814&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java Sun Sep  6 11:35:01
2009
@@ -21,6 +21,7 @@
 import java.io.OutputStream;
 
 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
@@ -32,10 +33,24 @@
 	private static long _type = 12000;
 
 	// Links to our more interesting children
-	private CString authorRecord;
-	private CString authorInitialsRecord;
-	private CString commentRecord;
-	private Comment2000Atom commentAtom;
+
+    /**
+     * An optional string that specifies the name of the author of the presentation comment.
+     */
+    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
@@ -46,7 +61,7 @@
 	 * Get the Author of this comment
 	 */
 	public String getAuthor() {
-		return authorRecord.getText();
+		return authorRecord == null ? null : authorRecord.getText();
 	}
 	/**
 	 * Set the Author of this comment
@@ -59,7 +74,7 @@
 	 * Get the Author's Initials of this comment
 	 */
 	public String getAuthorInitials() {
-		return authorInitialsRecord.getText();
+		return authorInitialsRecord == null ? null : authorInitialsRecord.getText();
 	}
 	/**
 	 * Set the Author's Initials of this comment
@@ -72,7 +87,7 @@
 	 * Get the text of this comment
 	 */
 	public String getText() {
-		return commentRecord.getText();
+		return commentRecord == null ? null : commentRecord.getText();
 	}
 	/**
 	 * Set the text of this comment
@@ -100,30 +115,23 @@
 	 *  methods.
 	 */
 	private void findInterestingChildren() {
-		// First child should be the author
-		if(_children[0] instanceof CString) {
-			authorRecord = (CString)_children[0];
-		} else {
-			throw new IllegalStateException("First child record wasn't a CString, was of type " +
_children[0].getRecordType());
-		}
-		// Second child should be the text
-		if(_children[1] instanceof CString) {
-			commentRecord = (CString)_children[1];
-		} else {
-			throw new IllegalStateException("Second child record wasn't a CString, was of type " +
_children[1].getRecordType());
-		}
-		// Third child should be the author's initials
-		if(_children[2] instanceof CString) {
-			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());
-		}
+
+        for(Record r : _children){
+            if (r instanceof CString){
+                CString cs = (CString)r;
+                int recInstance = cs.getOptions() >> 4;
+                switch(recInstance){
+                    case 0: authorRecord = cs; break;
+                    case 1: commentRecord = cs; break;
+                    case 2: authorInitialsRecord = cs; break;
+                }
+            } else if (r instanceof Comment2000Atom){
+                commentAtom = (Comment2000Atom)r;
+            } else {
+                logger.log(POILogger.WARN, "Unexpected record with type="+r.getRecordType()+"
in Comment2000: " + r.getClass().getName());
+            }
+        }
+
 	}
 
 	/**

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java?rev=811814&r1=811813&r2=811814&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java Sun
Sep  6 11:35:01 2009
@@ -192,4 +192,32 @@
 			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
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message