]> source.dussan.org Git - poi.git/commitdiff
improved loading of package parts so that same logical parts correspond to the same...
authorYegor Kozlov <yegor@apache.org>
Fri, 14 Aug 2009 17:25:22 +0000 (17:25 +0000)
committerYegor Kozlov <yegor@apache.org>
Fri, 14 Aug 2009 17:25:22 +0000 (17:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@804303 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/POIXMLDocument.java
src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java

index a4da9c77b21de37097af08b1a0a2704aa999e5ed..9e716e4cc847950992525712025af6d2e2af8d1a 100644 (file)
@@ -192,7 +192,7 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart{
     }
 
     protected final void load(POIXMLFactory factory) throws IOException {
-       Map<PackageRelationship, POIXMLDocumentPart> context = new HashMap<PackageRelationship, POIXMLDocumentPart>();
+       Map<PackagePart, POIXMLDocumentPart> context = new HashMap<PackagePart, POIXMLDocumentPart>();
         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<PackageRelationship> context = new HashSet<PackageRelationship>();
+        Set<PackagePart> context = new HashSet<PackagePart>();
         onSave(context);
         context.clear();
 
index 487bf533b8bced04d00d6bfecbcd228ccd379016..6fccf1cb51bbd353fcd40ead5e71905312ef9933 100755 (executable)
@@ -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<PackageRelationship> alreadySaved) throws IOException{
+    protected final void onSave(Set<PackagePart> 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<PackageRelationship, POIXMLDocumentPart> context) throws OpenXML4JException {
+    protected void read(POIXMLFactory factory, Map<PackagePart, POIXMLDocumentPart> 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));
                        }
                }
        }