]> source.dussan.org Git - poi.git/commitdiff
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-63924...
authorNick Burch <nick@apache.org>
Tue, 5 Aug 2008 23:05:00 +0000 (23:05 +0000)
committerNick Burch <nick@apache.org>
Tue, 5 Aug 2008 23:05:00 +0000 (23:05 +0000)
https://svn.apache.org/repos/asf/poi/trunk

........
  r682999 | nick | 2008-08-05 23:29:20 +0100 (Tue, 05 Aug 2008) | 1 line

  More tests for bug #45365, but still not able to reproduce it
........
  r683020 | nick | 2008-08-05 23:49:24 +0100 (Tue, 05 Aug 2008) | 1 line

  With help from Yegor, fix bug #45537 - Include headers and footers (of slides and notes) in the extracted text from HSLF
........

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@683024 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java
src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java
src/scratchpad/src/org/apache/poi/hslf/model/HeadersFooters.java
src/scratchpad/testcases/org/apache/poi/hslf/extractor/TextExtractor.java
src/testcases/org/apache/poi/hssf/data/45365-2.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java

index 0317cd9d27b875fa8ac4719baf064ec04a9970fa..85e9d58f85d3ee73812d9fb872d752a51d27ec91 100644 (file)
@@ -54,6 +54,7 @@
            <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
         </release>
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">45537 - Include headers and footers (of slides and notes) in the extracted text from HSLF</action>
            <action dev="POI-DEVELOPERS" type="fix">45472 - Fixed incorrect default row height in OpenOffice 2.3</action>
            <action dev="POI-DEVELOPERS" type="fix">44692 - HSSFPicture.resize() stretched image when there was a text next to it</action>
            <action dev="POI-DEVELOPERS" type="add">45543 - Optionally extract comment text with PowerPointExtractor, and initial hslf model support for comments</action>
index ce1869e2c0908f5b5cb8d3f30763b590eba1668a..09f91c20fe294ee99031b3d072625f5f5a852d1e 100644 (file)
@@ -51,6 +51,7 @@
            <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
         </release>
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">45537 - Include headers and footers (of slides and notes) in the extracted text from HSLF</action>
            <action dev="POI-DEVELOPERS" type="fix">45472 - Fixed incorrect default row height in OpenOffice 2.3</action>
            <action dev="POI-DEVELOPERS" type="fix">44692 - HSSFPicture.resize() stretched image when there was a text next to it</action>
            <action dev="POI-DEVELOPERS" type="add">45543 - Optionally extract comment text with PowerPointExtractor, and initial hslf model support for comments</action>
index 355a9b71f034f210e519b165f63fa9ba3af3b6f4..ff34958e6e405414da78f2f50ad92a803e87a24d 100644 (file)
 ==================================================================== */
 package org.apache.poi.hssf.eventusermodel;
 
-import java.text.DateFormat;
-import java.text.DecimalFormat;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
@@ -33,7 +29,6 @@ import org.apache.poi.hssf.record.NumberRecord;
 import org.apache.poi.hssf.record.Record;
 import org.apache.poi.hssf.usermodel.HSSFDataFormat;
 import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
-import org.apache.poi.hssf.usermodel.HSSFDateUtil;
 
 /**
  * A proxy HSSFListener that keeps track of the document
@@ -50,6 +45,13 @@ public class FormatTrackingHSSFListener implements HSSFListener {
                this.childListener = childListener;
        }
        
+       protected int getNumberOfCustomFormats() {
+               return customFormatRecords.size();
+       }
+       protected int getNumberOfExtendedFormats() {
+               return xfRecords.size();
+       }
+       
        /**
         * Process this record ourselves, and then
         *  pass it on to our child listener
index 95900a45efa4b495c58bb39f4ee7942dc44cd62b..865471eefe745f44618c8da0308b3502722476e4 100644 (file)
@@ -176,11 +176,13 @@ public class PowerPointExtractor extends POIOLE2TextExtractor
                for(int i=0; i<_slides.length; i++) {
                        Slide slide = _slides[i];
                        
+                       // Slide header, if set
                        HeadersFooters hf = slide.getHeadersFooters();
-                       if(hf != null && hf.getHeaderText() != null) {
+                       if(hf != null && hf.isHeaderVisible() && hf.getHeaderText() != null) {
                                ret.append(hf.getHeaderText() + "\n");
                        }
                        
+                       // Slide text
                        TextRun[] runs = slide.getTextRuns();
                        for(int j=0; j<runs.length; j++) {
                                TextRun run = runs[j];
@@ -193,10 +195,12 @@ public class PowerPointExtractor extends POIOLE2TextExtractor
                                }
                        }
                        
-                       if(hf != null && hf.getFooterText() != null) {
+                       // Slide footer, if set
+                       if(hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
                                ret.append(hf.getFooterText() + "\n");
                        }
                        
+                       // Comments, if requested and present
                        if(getCommentText) {
                                Comment[] comments = slide.getComments();
                                for(int j=0; j<comments.length; j++) {
@@ -219,13 +223,21 @@ public class PowerPointExtractor extends POIOLE2TextExtractor
                //  master sheets in. Grab Slide list, then work from there,
                //  but ensure no duplicates
                HashSet seenNotes = new HashSet();
+               HeadersFooters hf = _show.getNotesHeadersFooters();
+               
                for(int i=0; i<_slides.length; i++) {
                        Notes notes = _slides[i].getNotesSheet();
                        if(notes == null) { continue; }
                        Integer id = new Integer(notes._getSheetNumber());
                        if(seenNotes.contains(id)) { continue; }
                        seenNotes.add(id);
+                       
+                       // Repeat the Notes header, if set
+                       if(hf != null && hf.isHeaderVisible() && hf.getHeaderText() != null) {
+                               ret.append(hf.getHeaderText() + "\n");
+                       }
 
+                       // Notes text
                        TextRun[] runs = notes.getTextRuns();
                        if(runs != null && runs.length > 0) {
                                for(int j=0; j<runs.length; j++) {
@@ -237,6 +249,11 @@ public class PowerPointExtractor extends POIOLE2TextExtractor
                                        }
                                }
                        }
+                       
+                       // Repeat the notes footer, if set
+                       if(hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
+                               ret.append(hf.getFooterText() + "\n");
+                       }
                }
        }
 
index e94bcb981ae1348f5dcaadc000b936a687e1ac37..90aee3421d0e14b9ce890e2be52a04978bd93468 100644 (file)
@@ -22,6 +22,8 @@ import org.apache.poi.hslf.usermodel.SlideShow;
 \r
 /**\r
  * Header / Footer settings.\r
+ * \r
+ * You can get these on slides, or across all notes\r
  *\r
  * @author Yegor Kozlov\r
  */\r
index 2fbdb6af9217feb69318bc4b93e2caab8bb539a6..fe995fe12115c0d80cae4ca10c09646d3a91602a 100644 (file)
@@ -253,32 +253,42 @@ public class TextExtractor extends TestCase {
     /**
      * From bug #45537
      */
-    public void DISABLEDtestHeaderFooter() throws Exception {
+    public void testHeaderFooter() throws Exception {
                String filename, text;
                
-               // With a header
+               // With a header on the notes
                filename = dirname + "/45537_Header.ppt";
                HSLFSlideShow hslf = new HSLFSlideShow(new FileInputStream(filename));
                SlideShow ss = new SlideShow(hslf);
-               assertNotNull(ss.getSlides()[0].getHeadersFooters());
-               assertEquals("testdoc test phrase", ss.getSlides()[0].getHeadersFooters().getHeaderText());
+               assertNotNull(ss.getNotesHeadersFooters());
+               assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getHeaderText());
                
                ppe = new PowerPointExtractor(hslf);
 
+               text = ppe.getText();
+               assertFalse("Unable to find expected word in text\n" + text, text.contains("testdoc"));
+        assertFalse("Unable to find expected word in text\n" + text, text.contains("test phrase"));
+        
+        ppe.setNotesByDefault(true);
                text = ppe.getText();
                assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc"));
         assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
 
         
-               // And with a footer
+               // And with a footer, also on notes
                filename = dirname + "/45537_Footer.ppt";
                hslf = new HSLFSlideShow(new FileInputStream(filename));
                ss = new SlideShow(hslf);
-               assertNotNull(ss.getSlides()[0].getHeadersFooters());
-               assertEquals("testdoc test phrase", ss.getSlides()[0].getHeadersFooters().getFooterText());
+               assertNotNull(ss.getNotesHeadersFooters());
+               assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getFooterText());
                
                ppe = new PowerPointExtractor(filename);
 
+               text = ppe.getText();
+               assertFalse("Unable to find expected word in text\n" + text, text.contains("testdoc"));
+        assertFalse("Unable to find expected word in text\n" + text, text.contains("test phrase"));
+
+        ppe.setNotesByDefault(true);
                text = ppe.getText();
                assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc"));
         assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
diff --git a/src/testcases/org/apache/poi/hssf/data/45365-2.xls b/src/testcases/org/apache/poi/hssf/data/45365-2.xls
new file mode 100644 (file)
index 0000000..b5e66c1
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/45365-2.xls differ
index 60f5d2ca72d7c227cbff61d48d21d7587526ffca..0c28c484129fc8de0d5286222536a123c16172bd 100644 (file)
@@ -62,31 +62,45 @@ public final class TestFormatTrackingHSSFListener extends TestCase {
        
        /**
         * Ensure that all number and formula records can be
-        *  turned into strings without problems
+        *  turned into strings without problems.
+        * For now, we're just looking to get text back, no
+        *  exceptions thrown, but in future we might also
+        *  want to check the exact strings!
         */
        public void testTurnToString() throws Exception {
-               processFile("45365.xls");
-               
-               for(int i=0; i<mockListen._records.size(); i++) {
-                       Record r = (Record)mockListen._records.get(i);
-                       CellValueRecordInterface cvr = null;
+               String[] files = new String[] { 
+                               "45365.xls", "45365-2.xls", "MissingBits.xls" 
+               };
+               for(int k=0; k<files.length; k++) {
+                       processFile(files[k]);
                        
-                       if(r instanceof NumberRecord) {
-                               cvr = (CellValueRecordInterface)r;
-                       }
-                       if(r instanceof FormulaRecord) {
-                               cvr = (CellValueRecordInterface)r;
-                       }
+                       // Check we found our formats
+                       assertTrue(listener.getNumberOfCustomFormats() > 5);
+                       assertTrue(listener.getNumberOfExtendedFormats() > 5);
                        
-                       if(cvr != null) {
-                               // Should always give us a string 
-                               String s = listener.formatNumberDateCell(cvr);
-                               assertNotNull(s);
-                               assertTrue(s.length() > 0);
+                       // Now check we can turn all the numeric
+                       //  cells into strings without error
+                       for(int i=0; i<mockListen._records.size(); i++) {
+                               Record r = (Record)mockListen._records.get(i);
+                               CellValueRecordInterface cvr = null;
+                               
+                               if(r instanceof NumberRecord) {
+                                       cvr = (CellValueRecordInterface)r;
+                               }
+                               if(r instanceof FormulaRecord) {
+                                       cvr = (CellValueRecordInterface)r;
+                               }
+                               
+                               if(cvr != null) {
+                                       // Should always give us a string 
+                                       String s = listener.formatNumberDateCell(cvr);
+                                       assertNotNull(s);
+                                       assertTrue(s.length() > 0);
+                               }
                        }
+                       
+                       // TODO - test some specific format strings
                }
-               
-               // TODO - test some specific format strings
        }
        
        private static final class MockHSSFListener implements HSSFListener {