Fix first part of bug #51514 - HSSF copy nodes from NPOIFS
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1147179 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
86988f78de
commit
441c444986
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.8-beta4" date="2011-??-??">
|
<release version="3.8-beta4" date="2011-??-??">
|
||||||
|
<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">51504 - avoid NPE when DefaultRowHeight or DefaultColumnWidth records are missing</action>
|
||||||
<action dev="poi-developers" type="fix">51502 - Correct Subtotal function javadoc entry</action>
|
<action dev="poi-developers" type="fix">51502 - Correct Subtotal function javadoc entry</action>
|
||||||
<action dev="poi-developers" type="add">Support for hyperlinks in SXSSF</action>
|
<action dev="poi-developers" type="add">Support for hyperlinks in SXSSF</action>
|
||||||
|
@ -239,19 +239,26 @@ public abstract class POIDocument {
|
|||||||
protected void copyNodes(POIFSFileSystem source, POIFSFileSystem target,
|
protected void copyNodes(POIFSFileSystem source, POIFSFileSystem target,
|
||||||
List<String> excepts) throws IOException {
|
List<String> excepts) throws IOException {
|
||||||
//System.err.println("CopyNodes called");
|
//System.err.println("CopyNodes called");
|
||||||
|
copyNodes(source.getRoot(), target.getRoot(), excepts);
|
||||||
DirectoryEntry root = source.getRoot();
|
|
||||||
DirectoryEntry newRoot = target.getRoot();
|
|
||||||
|
|
||||||
Iterator<Entry> entries = root.getEntries();
|
|
||||||
while (entries.hasNext()) {
|
|
||||||
Entry entry = entries.next();
|
|
||||||
if (!excepts.contains(entry.getName())) {
|
|
||||||
copyNodeRecursively(entry,newRoot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies nodes from one POIFS to the other minus the excepts
|
||||||
|
* @param source is the source POIFS to copy from
|
||||||
|
* @param target is the target POIFS to copy to
|
||||||
|
* @param excepts is a list of Strings specifying what nodes NOT to copy
|
||||||
|
*/
|
||||||
|
protected void copyNodes(DirectoryNode sourceRoot, DirectoryNode targetRoot,
|
||||||
|
List<String> excepts) throws IOException {
|
||||||
|
Iterator<Entry> entries = sourceRoot.getEntries();
|
||||||
|
while (entries.hasNext()) {
|
||||||
|
Entry entry = entries.next();
|
||||||
|
if (!excepts.contains(entry.getName())) {
|
||||||
|
copyNodeRecursively(entry,targetRoot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies an Entry into a target POIFS directory, recursively
|
* Copies an Entry into a target POIFS directory, recursively
|
||||||
*/
|
*/
|
||||||
|
@ -36,27 +36,27 @@ import org.apache.poi.ddf.EscherBlipRecord;
|
|||||||
import org.apache.poi.ddf.EscherRecord;
|
import org.apache.poi.ddf.EscherRecord;
|
||||||
import org.apache.poi.hssf.OldExcelFormatException;
|
import org.apache.poi.hssf.OldExcelFormatException;
|
||||||
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
||||||
import org.apache.poi.hssf.model.RecordStream;
|
|
||||||
import org.apache.poi.hssf.model.InternalSheet;
|
import org.apache.poi.hssf.model.InternalSheet;
|
||||||
import org.apache.poi.hssf.model.InternalWorkbook;
|
import org.apache.poi.hssf.model.InternalWorkbook;
|
||||||
|
import org.apache.poi.hssf.model.RecordStream;
|
||||||
import org.apache.poi.hssf.record.*;
|
import org.apache.poi.hssf.record.*;
|
||||||
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
|
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
|
||||||
import org.apache.poi.hssf.record.common.UnicodeString;
|
import org.apache.poi.hssf.record.common.UnicodeString;
|
||||||
|
import org.apache.poi.hssf.util.CellReference;
|
||||||
|
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||||
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.ss.formula.FormulaShifter;
|
import org.apache.poi.ss.formula.FormulaShifter;
|
||||||
|
import org.apache.poi.ss.formula.FormulaType;
|
||||||
|
import org.apache.poi.ss.formula.SheetNameFormatter;
|
||||||
import org.apache.poi.ss.formula.ptg.Area3DPtg;
|
import org.apache.poi.ss.formula.ptg.Area3DPtg;
|
||||||
import org.apache.poi.ss.formula.ptg.MemFuncPtg;
|
import org.apache.poi.ss.formula.ptg.MemFuncPtg;
|
||||||
import org.apache.poi.ss.formula.ptg.OperandPtg;
|
import org.apache.poi.ss.formula.ptg.OperandPtg;
|
||||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||||
import org.apache.poi.ss.formula.ptg.Ref3DPtg;
|
import org.apache.poi.ss.formula.ptg.Ref3DPtg;
|
||||||
import org.apache.poi.ss.formula.SheetNameFormatter;
|
|
||||||
import org.apache.poi.ss.formula.ptg.UnionPtg;
|
import org.apache.poi.ss.formula.ptg.UnionPtg;
|
||||||
import org.apache.poi.hssf.util.CellReference;
|
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|
||||||
import org.apache.poi.ss.formula.udf.AggregatingUDFFinder;
|
import org.apache.poi.ss.formula.udf.AggregatingUDFFinder;
|
||||||
import org.apache.poi.ss.formula.udf.UDFFinder;
|
import org.apache.poi.ss.formula.udf.UDFFinder;
|
||||||
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
|
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
|
||||||
import org.apache.poi.ss.formula.FormulaType;
|
|
||||||
import org.apache.poi.ss.util.WorkbookUtil;
|
import org.apache.poi.ss.util.WorkbookUtil;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
@ -1244,13 +1244,12 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
|||||||
// out correctly shortly, so don't include the old one
|
// out correctly shortly, so don't include the old one
|
||||||
excepts.add("WORKBOOK");
|
excepts.add("WORKBOOK");
|
||||||
|
|
||||||
POIFSFileSystem srcFs = this.directory.getFileSystem();
|
|
||||||
// Copy over all the other nodes to our new poifs
|
// Copy over all the other nodes to our new poifs
|
||||||
copyNodes(srcFs, fs, excepts);
|
copyNodes(this.directory, fs.getRoot(), excepts);
|
||||||
|
|
||||||
// YK: preserve StorageClsid, it is important for embedded workbooks,
|
// YK: preserve StorageClsid, it is important for embedded workbooks,
|
||||||
// see Bugzilla 47920
|
// see Bugzilla 47920
|
||||||
fs.getRoot().setStorageClsid(srcFs.getRoot().getStorageClsid());
|
fs.getRoot().setStorageClsid(this.directory.getStorageClsid());
|
||||||
}
|
}
|
||||||
fs.writeFilesystem(stream);
|
fs.writeFilesystem(stream);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user