View | Details | Raw Unified | Return to bug 47668
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/POIXMLDocument.java (+26 lines)
Lines 17-23 Link Here
17
package org.apache.poi;
17
package org.apache.poi;
18
18
19
import java.io.*;
19
import java.io.*;
20
import java.util.HashMap;
20
import java.util.List;
21
import java.util.List;
22
import java.util.Map;
23
import java.util.Set;
21
24
22
import org.apache.poi.poifs.common.POIFSConstants;
25
import org.apache.poi.poifs.common.POIFSConstants;
23
import org.apache.poi.util.IOUtils;
26
import org.apache.poi.util.IOUtils;
Lines 53-58 Link Here
53
        this.pkg = pkg;
56
        this.pkg = pkg;
54
    }
57
    }
55
58
59
    public void load(POIXMLFactory factory) throws IOException, OpenXML4JException {
60
    	Map<PackagePart, POIXMLDocumentPart> context = new HashMap<PackagePart, POIXMLDocumentPart> ();
61
    	read(factory, context);
62
    	onDocumentRead();
63
    	context.clear();
64
    }
65
    
56
    /**
66
    /**
57
     * Wrapper to open a package, returning an IOException
67
     * Wrapper to open a package, returning an IOException
58
     *  in the event of a problem.
68
     *  in the event of a problem.
Lines 207-211 Link Here
207
217
208
        getPackage().save(stream);
218
        getPackage().save(stream);
209
    }
219
    }
220
	
221
    /**
222
     * Write out this document to an Outputstream.
223
     *
224
     * @param stream - the java OutputStream you wish to write the XLS to
225
     *
226
     * @exception IOException if anything can't be written.
227
     */
228
    public final void write(OutputStream stream, Set<PackagePart> alreadySaved) throws IOException {
229
    	//force all children to commit their changes into the underlying OOXML Package
230
    	onSave(alreadySaved);
210
231
232
        //save extended and custom properties
233
        getProperties().commit();
234
    	
235
    	getPackage().save(stream);
236
    }
211
}
237
}
(-)src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java (-1 / +39 lines)
Lines 19-25 Link Here
19
import java.io.IOException;
19
import java.io.IOException;
20
import java.util.LinkedList;
20
import java.util.LinkedList;
21
import java.util.List;
21
import java.util.List;
22
import java.net.URI;
22
import java.util.Map;
23
import java.util.Set;
23
24
24
import org.apache.xmlbeans.XmlOptions;
25
import org.apache.xmlbeans.XmlOptions;
25
import org.apache.poi.util.POILogger;
26
import org.apache.poi.util.POILogger;
Lines 180-185 Link Here
180
    }
181
    }
181
182
182
    /**
183
    /**
184
     * Save changes in the underlying OOXML package.
185
     * Recursively fires {@link #commit()} for each package part
186
     */
187
    protected final void onSave(Set<PackagePart> alreadySaved) throws IOException{
188
    	commit();
189
    	alreadySaved.add(this.getPackagePart());
190
    	for(POIXMLDocumentPart p : relations){
191
    		if (!alreadySaved.contains(p.getPackagePart())) {
192
    			p.onSave(alreadySaved);
193
    		}
194
    	}
195
    }
196
197
    /**
183
     * Create a new child POIXMLDocumentPart
198
     * Create a new child POIXMLDocumentPart
184
     *
199
     *
185
     * @param descriptor the part descriptor
200
     * @param descriptor the part descriptor
Lines 258-263 Link Here
258
        }
273
        }
259
    }
274
    }
260
275
276
    protected final void read(POIXMLFactory factory, Map<PackagePart, POIXMLDocumentPart> context) throws OpenXML4JException {
277
    	PackageRelationshipCollection rels = packagePart.getRelationships();
278
    	for (PackageRelationship rel : rels) {
279
    		if(rel.getTargetMode() == TargetMode.INTERNAL){
280
    			PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
281
    			PackagePart p = packagePart.getPackage().getPart(relName);
282
    			if(p == null) {
283
    				logger.log(POILogger.ERROR, "Skipped invalid entry " + rel.getTargetURI());
284
    				continue;
285
    			}
286
    			if (!context.containsKey(p)) {
287
    				POIXMLDocumentPart childPart = factory.createDocumentPart(rel, p);
288
    				context.put(p, childPart);
289
    				childPart.parent = this;
290
    				addRelation(childPart);
291
    				if(p.hasRelationships()) childPart.read(factory, context);
292
    			}
293
    			else {
294
    				addRelation(context.get(p));
295
    			}
296
    		}
297
    	}
298
    }
261
299
262
    /**
300
    /**
263
     * Fired when a new package part is created
301
     * Fired when a new package part is created

Return to bug 47668