Author: nick
Date: Tue Sep 26 08:53:21 2006
New Revision: 450097

URL: http://svn.apache.org/viewvc?view=rev&rev=450097
Log:
Fix for NPE in bug #40036. The TextBox will still be fairly useless though

Added:
    
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/empty_textbox.ppt
   (with props)
Modified:
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java
    
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java

Modified: 
jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java
URL: 
http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java?view=diff&rev=450097&r1=450096&r2=450097
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java 
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java 
Tue Sep 26 08:53:21 2006
@@ -84,6 +84,12 @@
      * TextHeaderAtom, TextBytesAtom ot TextCharsAtom, StyleTextPropAtom etc.

      */

     protected EscherTextboxWrapper _txtbox;

+    

+    /**

+     * Is the TextBox missing the text records which actually

+     *  store the text?

+     */

+    private boolean _missingTextRecords = false;

 

     /**

      * Create a TextBox object and initialize it from the supplied Record 
container.

@@ -544,10 +550,20 @@
     public void setSheet(Sheet sheet){

         _sheet = sheet;

 

-        //initialize _txtrun object.

-        //we can't do it in the constructor because the sheet is not assigned 
yet

+        // Initialize _txtrun object.

+        // (We can't do it in the constructor because the sheet

+        //  is not assigned then, it's only built once we have

+        //  all the records)

         if(_txtrun == null) initTextRun();

-

+        if(_txtrun == null) {

+               // No text records found, skip

+               _missingTextRecords = true;

+               return;

+        } else {

+               _missingTextRecords = false;

+        }

+        

+        // Supply the sheet to our child RichTextRuns

         RichTextRun[] rt = _txtrun.getRichTextRuns();

         for (int i = 0; i < rt.length; i++) {

             rt[i].supplySlideShow(_sheet.getSlideShow());

@@ -555,12 +571,13 @@
     }

 

     private void initTextRun(){

-

         TextHeaderAtom tha = null;

         TextCharsAtom tca = null;

         TextBytesAtom tba = null;

         StyleTextPropAtom sta = null;

         OutlineTextRefAtom ota = null;

+        

+        // Find the interesting child records 

         Record[] child = _txtbox.getChildRecords();

         for (int i = 0; i < child.length; i++) {

             if (child[i] instanceof TextHeaderAtom) tha = 
(TextHeaderAtom)child[i];

@@ -570,8 +587,10 @@
             else if (child[i] instanceof TextCharsAtom) tca = 
(TextCharsAtom)child[i];

         }

 

-        if (ota != null){

-            //TextHeaderAtom, TextBytesAtom and  StyleTextPropAtom are stored 
outside of  EscherContainerRecord

+        // Special handling for cases where there's an OutlineTextRefAtom

+        if (ota != null) {

+            // TextHeaderAtom, TextBytesAtom and StyleTextPropAtom are

+               //  stored outside of  EscherContainerRecord

             int idx = ota.getTextIndex();

             Slide sl = (Slide)getSheet();

             Record[] rec = sl.getSlideAtomsSet().getSlideRecords();

@@ -591,7 +610,17 @@
                 }

             }

         }

-        if(tba != null) _txtrun = new TextRun(tha,tba,sta);

-        else if (tca != null) _txtrun = new TextRun(tha,tca,sta);

+        

+        // If we found the records we needed, create a TextRun

+        if(tba != null) {

+               // Bytes based Text Run

+               _txtrun = new TextRun(tha,tba,sta);

+        } else if (tca != null) {

+               // Characters (unicode) based Text Run

+               _txtrun = new TextRun(tha,tca,sta);

+        } else {

+               // Empty text box

+               System.err.println("Warning - no text records found for 
TextBox");

+        }

     }

 }


Added: 
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/empty_textbox.ppt
URL: 
http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/empty_textbox.ppt?view=auto&rev=450097
==============================================================================
Binary file - no diff available.

Propchange: 
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/empty_textbox.ppt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: 
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
URL: 
http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java?view=diff&rev=450097&r1=450096&r2=450097
==============================================================================
--- 
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
 (original)
+++ 
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
 Tue Sep 26 08:53:21 2006
@@ -33,11 +33,15 @@
  */

 public class TestShapes extends TestCase {

     private SlideShow ppt;

+    private SlideShow pptB;

 

     protected void setUp() throws Exception {

                String dirname = System.getProperty("HSLF.testdata.path");

                String filename = dirname + "/empty.ppt";

                ppt = new SlideShow(new HSLFSlideShow(filename));

+               

+               String filenameB = dirname + "/empty_textbox.ppt";

+               pptB = new SlideShow(new HSLFSlideShow(filenameB));

     }

 

     public void testGraphics() throws Exception {

@@ -168,6 +172,19 @@
         assertFalse(rt.isUnderlined());

         assertEquals("Arial", rt.getFontName());

         assertEquals(Color.red, txtbox.getFontColor());

+    }

+    

+    /**

+     * Test with an empty text box

+     */

+    public void testEmptyTextBox() throws Exception {

+       assertEquals(2, pptB.getSlides().length);

+       Slide s1 = pptB.getSlides()[0];

+       Slide s2 = pptB.getSlides()[1];

+       

+       // Check we can get the shapes count

+       assertEquals(2, s1.getShapes().length);

+       assertEquals(2, s2.getShapes().length);

     }

 

     /**




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/

Reply via email to