poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r786501 - in /poi/trunk/src: documentation/content/xdocs/ scratchpad/src/org/apache/poi/hslf/record/ scratchpad/src/org/apache/poi/hslf/usermodel/ scratchpad/testcases/org/apache/poi/hslf/data/ scratchpad/testcases/org/apache/poi/hslf/recor...
Date Fri, 19 Jun 2009 13:24:41 GMT
Author: yegor
Date: Fri Jun 19 13:24:41 2009
New Revision: 786501

URL: http://svn.apache.org/viewvc?rev=786501&view=rev
Log:
Fixed SlideShow#removeSlide to remove references to Notes, see Bugzilla #47261

Added:
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/47261.ppt   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestAddingSlides.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=786501&r1=786500&r2=786501&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Jun 19 13:24:41 2009
@@ -33,6 +33,7 @@
 
     <changes>
         <release version="3.5-beta7" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">47261 - Fixed SlideShow#removeSlide
to remove references to Notes</action>
            <action dev="POI-DEVELOPERS" type="fix">47375 - Fixed HSSFHyperlink to correctly
set inter-sheet and file links</action>
            <action dev="POI-DEVELOPERS" type="fix">47384 - Fixed ExternalNameRecord
to handle unicode names</action>
            <action dev="POI-DEVELOPERS" type="fix">47372 - Fixed locale-sensitive unit
tests to pass when running on non-US locale</action>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java?rev=786501&r1=786500&r2=786501&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java Fri Jun 19 13:24:41
2009
@@ -21,6 +21,7 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.ArrayList;
 
 /**
  * Master container for Document. There is one of these for every
@@ -189,6 +190,16 @@
 		slwts = nl;
 	}
 
+    public void removeSlideListWithText(SlideListWithText slwt) {
+        ArrayList<SlideListWithText> lst = new ArrayList<SlideListWithText>();
+        for(SlideListWithText s : slwts) {
+            if(s != slwt) lst.add(s);
+            else {
+                removeChild(slwt);
+            }
+        }
+        slwts = lst.toArray(new SlideListWithText[lst.size()]);
+    }
 
 	/**
 	 * We are of type 1000

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java?rev=786501&r1=786500&r2=786501&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java Fri Jun 19
13:24:41 2009
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
 
 /**
  * Abstract class which all container records will extend. Providers
@@ -135,7 +136,24 @@
 		return null;
 	}
 
-	/* ===============================================================
+    /**
+     * Remove a child record from this record container
+     *
+     * @param ch the child to remove
+     * @return the removed record
+     */
+    public Record removeChild(Record ch) {
+        Record rm = null;
+        ArrayList<Record> lst = new ArrayList<Record>();
+        for(Record r : _children) {
+            if(r != ch) lst.add(r);
+            else rm = r;
+        }
+        _children = lst.toArray(new Record[lst.size()]);
+        return rm;
+    }
+
+    /* ===============================================================
 	 *                   External Move Methods
 	 * ===============================================================
 	 */

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java?rev=786501&r1=786500&r2=786501&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java Fri Jun 19 13:24:41
2009
@@ -601,10 +601,39 @@
                 removedSlide = _slides[i];
             }
         }
-        slwt.setSlideAtomsSets( sa.toArray(new SlideAtomsSet[sa.size()]) );
-        slwt.setChildRecord(records.toArray(new Record[records.size()]));
+        if(sa.size() == 0){
+            _documentRecord.removeSlideListWithText(slwt);
+        } else {
+            slwt.setSlideAtomsSets( sa.toArray(new SlideAtomsSet[sa.size()]) );
+            slwt.setChildRecord(records.toArray(new Record[records.size()]));
+        }
         _slides = sl.toArray(new Slide[sl.size()]);
 
+        //if the removed slide had notes - remove references to them too
+        if(removedSlide != null){
+            int notesId = removedSlide.getSlideRecord().getSlideAtom().getNotesID();
+            if(notesId != 0){
+                SlideListWithText nslwt = _documentRecord.getNotesSlideListWithText();
+                records = new ArrayList<Record>();
+                ArrayList<SlideAtomsSet> na = new ArrayList<SlideAtomsSet>();
+                for (SlideAtomsSet ns : nslwt.getSlideAtomsSets()){
+                    if(ns.getSlidePersistAtom().getSlideIdentifier() != notesId) {
+                        na.add(ns);
+                        records.add(ns.getSlidePersistAtom());
+                        if(ns.getSlideRecords() != null) records.addAll(Arrays.asList(ns.getSlideRecords()));
+                    }
+                }
+                if(na.size() == 0){
+                    _documentRecord.removeSlideListWithText(nslwt);
+                } else {
+                    slwt.setSlideAtomsSets( na.toArray(new SlideAtomsSet[na.size()]) );
+                    slwt.setChildRecord(records.toArray(new Record[records.size()]));
+                }
+
+            }
+
+        }
+
         return removedSlide;
     }
 

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

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/47261.ppt
------------------------------------------------------------------------------
    svn:executable = *

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

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java?rev=786501&r1=786500&r2=786501&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java
Fri Jun 19 13:24:41 2009
@@ -136,7 +136,14 @@
 		assertEquals(before, ncr[1]);
 	}
 
-	protected void setUp() throws Exception {
+    public void testRemove() {
+        Record[] ch = recordContainer.getChildRecords();
+        Record removeRecord = recordContainer.removeChild(ch[0]);
+        assertSame(ch[0], removeRecord);
+        assertEquals(ch.length-1, recordContainer.getChildRecords().length);
+    }
+
+    protected void setUp() throws Exception {
 		super.setUp();
 
 		// Find a real RecordContainer record

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestAddingSlides.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestAddingSlides.java?rev=786501&r1=786500&r2=786501&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestAddingSlides.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestAddingSlides.java
Fri Jun 19 13:24:41 2009
@@ -20,12 +20,15 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.File;
 
 import junit.framework.TestCase;
 import org.apache.poi.hslf.*;
 import org.apache.poi.hslf.record.Record;
 import org.apache.poi.hslf.record.RecordTypes;
 import org.apache.poi.hslf.record.UserEditAtom;
+import org.apache.poi.hslf.record.Document;
 import org.apache.poi.hslf.model.*;
 
 /**
@@ -269,4 +272,24 @@
         assertEquals(1, s3.length);
     }
 
+
+    public void test47261() throws Exception {
+        File src = new File(System.getProperty("HSLF.testdata.path"), "47261.ppt");
+        SlideShow ppt = new SlideShow(new FileInputStream(src));
+        Slide[] slides = ppt.getSlides();
+        Document doc = ppt.getDocumentRecord();
+        assertNotNull(doc.getSlideSlideListWithText());
+        assertEquals(1, ppt.getSlides().length);
+        int notesId = slides[0].getSlideRecord().getSlideAtom().getNotesID();
+        assertTrue(notesId > 0);
+        assertNotNull(doc.getNotesSlideListWithText());
+        //the SLWT container for notes has one entry which will deleted
+        assertEquals(1, doc.getNotesSlideListWithText().getSlideAtomsSets().length);
+
+        ppt.removeSlide(0);
+        assertEquals(0, ppt.getSlides().length);
+        assertNull(doc.getSlideSlideListWithText());
+        assertNull(doc.getNotesSlideListWithText());
+
+    }
 }



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


Mime
View raw message