Fixed SlideShow#removeSlide to remove references to Notes, see Bugzilla #47261

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@786501 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2009-06-19 13:24:41 +00:00
parent 234735a414
commit 943f159293
7 changed files with 93 additions and 4 deletions

View File

@ -33,6 +33,7 @@
<changes> <changes>
<release version="3.5-beta7" date="2009-??-??"> <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">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">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> <action dev="POI-DEVELOPERS" type="fix">47372 - Fixed locale-sensitive unit tests to pass when running on non-US locale</action>

View File

@ -21,6 +21,7 @@ import org.apache.poi.util.POILogger;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList;
/** /**
* Master container for Document. There is one of these for every * Master container for Document. There is one of these for every
@ -189,6 +190,16 @@ public final class Document extends PositionDependentRecordContainer
slwts = nl; 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 * We are of type 1000

View File

@ -24,6 +24,7 @@ import org.apache.poi.hslf.util.MutableByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
/** /**
* Abstract class which all container records will extend. Providers * Abstract class which all container records will extend. Providers
@ -135,6 +136,23 @@ public abstract class RecordContainer extends Record
return null; 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 * External Move Methods
* =============================================================== * ===============================================================

View File

@ -601,10 +601,39 @@ public final class SlideShow {
removedSlide = _slides[i]; removedSlide = _slides[i];
} }
} }
if(sa.size() == 0){
_documentRecord.removeSlideListWithText(slwt);
} else {
slwt.setSlideAtomsSets( sa.toArray(new SlideAtomsSet[sa.size()]) ); slwt.setSlideAtomsSets( sa.toArray(new SlideAtomsSet[sa.size()]) );
slwt.setChildRecord(records.toArray(new Record[records.size()])); slwt.setChildRecord(records.toArray(new Record[records.size()]));
}
_slides = sl.toArray(new Slide[sl.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; return removedSlide;
} }

Binary file not shown.

View File

@ -136,6 +136,13 @@ public final class TestRecordContainer extends TestCase {
assertEquals(before, ncr[1]); assertEquals(before, ncr[1]);
} }
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 { protected void setUp() throws Exception {
super.setUp(); super.setUp();

View File

@ -20,12 +20,15 @@ package org.apache.poi.hslf.usermodel;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.File;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.*; import org.apache.poi.hslf.*;
import org.apache.poi.hslf.record.Record; import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordTypes; import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.hslf.record.UserEditAtom; import org.apache.poi.hslf.record.UserEditAtom;
import org.apache.poi.hslf.record.Document;
import org.apache.poi.hslf.model.*; import org.apache.poi.hslf.model.*;
/** /**
@ -269,4 +272,24 @@ public final class TestAddingSlides extends TestCase {
assertEquals(1, s3.length); 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());
}
} }