<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>
import java.io.IOException;
import java.io.OutputStream;
+import java.util.ArrayList;
/**
* Master container for Document. There is one of these for every
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
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
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
* ===============================================================
*/
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;
}
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
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.*;
/**
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());
+
+ }
}