From: Nick Burch Date: Fri, 15 Jul 2011 15:08:51 +0000 (+0000) Subject: Fix bug #51514 - Allow HSSFObjectData to work with both POIFS and NPOIFS, and fix... X-Git-Tag: REL_3_8_BETA4~177 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=432167c031a0bcf013ddcb0c969622cbcfe1a17c;p=poi.git 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 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index bd5eb5bde1..707aca9543 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 51514 - allow HSSFObjectData to work with both POIFS and NPOIFS 51514 - avoid NPE when copying nodes from one HSSF workbook to a new one, when opened from NPOIFS 51504 - avoid NPE when DefaultRowHeight or DefaultColumnWidth records are missing 51502 - Correct Subtotal function javadoc entry diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFObjectData.java b/src/java/org/apache/poi/hssf/usermodel/HSSFObjectData.java index afcfc00ee8..5b2a463f4c 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFObjectData.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFObjectData.java @@ -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; } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 54f9c62e5d..0acaa140a7 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -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 objects) + private void getAllEmbeddedObjects(List records, List 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 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() {