From 5b8fc241bf035c779335b0720369a1077deab317 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Fri, 14 Aug 2009 17:25:22 +0000 Subject: [PATCH] improved loading of package parts so that same logical parts correspond to the same physical instances, see followup in Bugzilla 47668 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@804303 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/POIXMLDocument.java | 4 ++-- .../java/org/apache/poi/POIXMLDocumentPart.java | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/POIXMLDocument.java b/src/ooxml/java/org/apache/poi/POIXMLDocument.java index a4da9c77b2..9e716e4cc8 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLDocument.java +++ b/src/ooxml/java/org/apache/poi/POIXMLDocument.java @@ -192,7 +192,7 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart{ } protected final void load(POIXMLFactory factory) throws IOException { - Map context = new HashMap(); + Map context = new HashMap(); try { read(factory, context); } catch (OpenXML4JException e){ @@ -211,7 +211,7 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart{ */ public final void write(OutputStream stream) throws IOException { //force all children to commit their changes into the underlying OOXML Package - Set context = new HashSet(); + Set context = new HashSet(); onSave(context); context.clear(); diff --git a/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java b/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java index 487bf533b8..6fccf1cb51 100755 --- a/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java +++ b/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java @@ -170,12 +170,14 @@ public class POIXMLDocumentPart { /** * Save changes in the underlying OOXML package. * Recursively fires {@link #commit()} for each package part + * + * @param alreadySaved context set containing already visited nodes */ - protected final void onSave(Set alreadySaved) throws IOException{ + protected final void onSave(Set alreadySaved) throws IOException{ commit(); - alreadySaved.add(this.getPackageRelationship()); + alreadySaved.add(this.getPackagePart()); for(POIXMLDocumentPart p : relations){ - if (!alreadySaved.contains(p.getPackageRelationship())) { + if (!alreadySaved.contains(p.getPackagePart())) { p.onSave(alreadySaved); } } @@ -229,8 +231,9 @@ public class POIXMLDocumentPart { * using the specified factory * * @param factory the factory object that creates POIXMLFactory instances + * @param context context map containing already visited noted keyed by targetURI */ - protected void read(POIXMLFactory factory, Map context) throws OpenXML4JException { + protected void read(POIXMLFactory factory, Map context) throws OpenXML4JException { PackageRelationshipCollection rels = packagePart.getRelationships(); for (PackageRelationship rel : rels) { if(rel.getTargetMode() == TargetMode.INTERNAL){ @@ -251,17 +254,17 @@ public class POIXMLDocumentPart { } } - if (!context.containsKey(rel)) { + if (!context.containsKey(p)) { POIXMLDocumentPart childPart = factory.createDocumentPart(rel, p); childPart.parent = this; addRelation(childPart); if(p != null){ - context.put(rel, childPart); + context.put(p, childPart); if(p.hasRelationships()) childPart.read(factory, context); } } else { - addRelation(context.get(rel)); + addRelation(context.get(p)); } } } -- 2.39.5