Fix bug #51514 - Allow HSSFObjectData to work with both POIFS and NPOIFS, and fix some generics warnings

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1147183 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2011-07-15 15:08:51 +00:00
parent 441c444986
commit c8ee505300
3 changed files with 22 additions and 25 deletions

View File

@ -34,6 +34,7 @@
<changes>
<release version="3.8-beta4" date="2011-??-??">
<action dev="poi-developers" type="fix">51514 - allow HSSFObjectData to work with both POIFS and NPOIFS</action>
<action dev="poi-developers" type="fix">51514 - avoid NPE when copying nodes from one HSSF workbook to a new one, when opened from NPOIFS</action>
<action dev="poi-developers" type="fix">51504 - avoid NPE when DefaultRowHeight or DefaultColumnWidth records are missing</action>
<action dev="poi-developers" type="fix">51502 - Correct Subtotal function javadoc entry</action>

View File

@ -26,7 +26,6 @@ import org.apache.poi.hssf.record.ObjRecord;
import org.apache.poi.hssf.record.SubRecord;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.HexDump;
/**
@ -41,20 +40,20 @@ public final class HSSFObjectData {
private final ObjRecord _record;
/**
* Reference to the filesystem, required for retrieving the object data.
* Reference to the filesystem root, required for retrieving the object data.
*/
private final POIFSFileSystem _poifs;
private final DirectoryEntry _root;
/**
* Constructs object data by wrapping a lower level object record.
*
* @param record the low-level object record.
* @param poifs the filesystem, required for retrieving the object data.
* @param root the root of the filesystem, required for retrieving the object data.
*/
public HSSFObjectData(ObjRecord record, POIFSFileSystem poifs)
public HSSFObjectData(ObjRecord record, DirectoryEntry root)
{
_record = record;
_poifs = poifs;
_root = root;
}
/**
@ -77,7 +76,7 @@ public final class HSSFObjectData {
int streamId = subRecord.getStreamId().intValue();
String streamName = "MBD" + HexDump.toHex(streamId);
Entry entry = _poifs.getRoot().getEntry(streamName);
Entry entry = _root.getEntry(streamName);
if (entry instanceof DirectoryEntry) {
return (DirectoryEntry) entry;
}

View File

@ -1726,27 +1726,24 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @param records the list of records to search.
* @param objects the list of embedded objects to populate.
*/
private void getAllEmbeddedObjects(List records, List<HSSFObjectData> objects)
private void getAllEmbeddedObjects(List<RecordBase> records, List<HSSFObjectData> objects)
{
Iterator recordIter = records.iterator();
while (recordIter.hasNext())
{
Object obj = recordIter.next();
if (obj instanceof ObjRecord)
{
// TODO: More convenient way of determining if there is stored binary.
// TODO: Link to the data stored in the other stream.
Iterator subRecordIter = ((ObjRecord) obj).getSubRecords().iterator();
while (subRecordIter.hasNext())
for (RecordBase obj : records) {
if (obj instanceof ObjRecord)
{
// TODO: More convenient way of determining if there is stored binary.
// TODO: Link to the data stored in the other stream.
Iterator<SubRecord> subRecordIter = ((ObjRecord) obj).getSubRecords().iterator();
while (subRecordIter.hasNext())
{
SubRecord sub = subRecordIter.next();
if (sub instanceof EmbeddedObjectRefSubRecord)
{
Object sub = subRecordIter.next();
if (sub instanceof EmbeddedObjectRefSubRecord)
{
objects.add(new HSSFObjectData((ObjRecord) obj, directory.getFileSystem()));
}
objects.add(new HSSFObjectData((ObjRecord) obj, directory));
}
}
}
}
}
}
}
public HSSFCreationHelper getCreationHelper() {