Changeset 1467 for trunk/docx4j/src/main/java/org/docx4j/openpackaging
- Timestamp:
- 04/10/11 13:29:24 (14 months ago)
- Location:
- trunk/docx4j/src/main/java/org/docx4j/openpackaging
- Files:
-
- 5 edited
-
io/Load.java (modified) (2 diffs)
-
io/LoadFromVFSZipFile.java (modified) (1 diff)
-
io/LoadFromZipFile.java (modified) (12 diffs)
-
io/LoadFromZipNG.java (modified) (12 diffs)
-
packages/OpcPackage.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/openpackaging/io/Load.java
r1449 r1467 62 62 } 63 63 64 public ContentTypeManager ctm;64 //public ContentTypeManager ctm; 65 65 66 66 protected boolean loadExternalTargets = false; … … 69 69 } 70 70 71 /**72 * This HashMap is intended to prevent loops.73 */74 protected HashMap<String, String> handled = new HashMap<String, String>();75 71 76 72 /** -
trunk/docx4j/src/main/java/org/docx4j/openpackaging/io/LoadFromVFSZipFile.java
r1066 r1467 69 69 } 70 70 71 public LoadFromVFSZipFile(ContentTypeManager ctm, boolean loadExternalTargets) {72 _loadFromZipFile = new LoadFromZipFile(ctm);73 _loadFromZipFile.loadExternalTargets(loadExternalTargets);74 }71 // public LoadFromVFSZipFile(ContentTypeManager ctm, boolean loadExternalTargets) { 72 // _loadFromZipFile = new LoadFromZipFile(ctm); 73 // _loadFromZipFile.loadExternalTargets(loadExternalTargets); 74 // } 75 75 76 76 public OpcPackage get(String filepath) throws Docx4JException { -
trunk/docx4j/src/main/java/org/docx4j/openpackaging/io/LoadFromZipFile.java
r1421 r1467 86 86 // HashMap containing the names of all the zip entries, 87 87 // so we can tell whether there are any orphans 88 public HashMap unusedZipEntries = null;88 // public HashMap unusedZipEntries = null; 89 89 90 90 public LoadFromZipFile() { 91 this(new ContentTypeManager() );92 } 93 94 public LoadFromZipFile(ContentTypeManager ctm) {95 this.ctm = ctm;96 }91 // this(new ContentTypeManager() ); 92 } 93 94 // public LoadFromZipFile(ContentTypeManager ctm) { 95 // this.ctm = ctm; 96 // } 97 97 98 98 … … 123 123 // entries, so we can tick them off. 124 124 125 unusedZipEntries = new HashMap();125 // unusedZipEntries = new HashMap(); 126 126 Enumeration entries = zf.entries(); 127 127 while (entries.hasMoreElements()) { 128 128 ZipEntry entry = (ZipEntry) entries.nextElement(); 129 unusedZipEntries.put(entry.getName(), new Boolean(true) );129 // unusedZipEntries.put(entry.getName(), new Boolean(true) ); 130 130 } 131 131 … … 133 133 // Eventually, you'll also be able to create an Excel package etc 134 134 // but only the WordML package exists at present 135 ContentTypeManager ctm = new ContentTypeManager(); 135 136 136 137 try { … … 147 148 // each PartName, and use it in the Part constructor. 148 149 // p.setContentTypeManager(ctm); - 20080111 - done by ctm.createPackage(); 149 unusedZipEntries.put("[Content_Types].xml", new Boolean(false));150 // unusedZipEntries.put("[Content_Types].xml", new Boolean(false)); 150 151 151 152 // 4. Start with _rels/.rels … … 161 162 p.setRelationships(rp); 162 163 //rp.setPackageRelationshipPart(true); 163 unusedZipEntries.put(partName, new Boolean(false));164 // unusedZipEntries.put(partName, new Boolean(false)); 164 165 165 166 … … 172 173 // (ii) add the new Part to the package 173 174 // (iii) cross the PartName off unusedZipEntries 174 addPartsFromRelationships(zf, p, rp );175 addPartsFromRelationships(zf, p, rp, ctm ); 175 176 176 177 177 178 // 6. Check unusedZipEntries is empty 178 if (log.isDebugEnabled()) {179 Iterator myVeryOwnIterator = unusedZipEntries.keySet().iterator();180 while(myVeryOwnIterator.hasNext()) {181 String key = (String)myVeryOwnIterator.next();182 log.info( key + " " + unusedZipEntries.get(key));183 }184 }179 // if (log.isDebugEnabled()) { 180 // Iterator myVeryOwnIterator = unusedZipEntries.keySet().iterator(); 181 // while(myVeryOwnIterator.hasNext()) { 182 // String key = (String)myVeryOwnIterator.next(); 183 // log.info( key + " " + unusedZipEntries.get(key)); 184 // } 185 // } 185 186 try { 186 187 zf.close(); … … 254 255 (iii) cross the PartName off unusedZipEntries 255 256 */ 256 private void addPartsFromRelationships(ZipFile zf, Base source, RelationshipsPart rp) 257 private void addPartsFromRelationships(ZipFile zf, Base source, RelationshipsPart rp, 258 ContentTypeManager ctm) 257 259 throws Docx4JException { 258 260 … … 281 283 // a part, so start with a line break. 282 284 try { 283 getPart(zf, pkg, rp, r );285 getPart(zf, pkg, rp, r, ctm); 284 286 } catch (Exception e) { 285 287 throw new Docx4JException("Failed to add parts from relationships", e); … … 306 308 // private void getPart(ZipFile zf, Base source, 307 309 // Package pkg, String resolvedPartUri, String relationshipType) 308 private void getPart(ZipFile zf, OpcPackage pkg, RelationshipsPart rp, Relationship r) 310 private void getPart(ZipFile zf, OpcPackage pkg, RelationshipsPart rp, Relationship r, 311 ContentTypeManager ctm) 309 312 throws Docx4JException, InvalidFormatException, URISyntaxException { 310 313 … … 348 351 } 349 352 350 if ( handled.get(resolvedPartUri)!=null) return;353 if (pkg.handled.get(resolvedPartUri)!=null) return; 351 354 352 355 String relationshipType = r.getType(); … … 359 362 } 360 363 rp.loadPart(part, r); 361 handled.put(resolvedPartUri, resolvedPartUri);364 pkg.handled.put(resolvedPartUri, resolvedPartUri); 362 365 363 366 … … 369 372 } 370 373 371 unusedZipEntries.put(resolvedPartUri, new Boolean(false));372 log.info(".. added." );374 // unusedZipEntries.put(resolvedPartUri, new Boolean(false)); 375 // log.info(".. added." ); 373 376 374 377 RelationshipsPart rrp = getRelationshipsPart(zf, part); 375 378 if (rrp!=null) { 376 379 // recurse via this parts relationships, if it has any 377 addPartsFromRelationships(zf, part, rrp );380 addPartsFromRelationships(zf, part, rrp, ctm ); 378 381 String relPart = PartName.getRelationshipsPartName( 379 382 part.getPartName().getName().substring(1) ); 380 unusedZipEntries.put(relPart, new Boolean(false));383 // unusedZipEntries.put(relPart, new Boolean(false)); 381 384 } 382 385 } -
trunk/docx4j/src/main/java/org/docx4j/openpackaging/io/LoadFromZipNG.java
r1421 r1467 81 81 public class LoadFromZipNG extends Load { 82 82 83 public HashMap<String, ByteArray> partByteArrays = new HashMap<String, ByteArray>();83 //public HashMap<String, ByteArray> partByteArrays = new HashMap<String, ByteArray>(); 84 84 85 85 private static Logger log = Logger.getLogger(LoadFromZipNG.class); … … 99 99 100 100 public LoadFromZipNG() { 101 this(new ContentTypeManager() );102 } 103 104 public LoadFromZipNG(ContentTypeManager ctm) {105 this.ctm = ctm;106 }101 // this(new ContentTypeManager() ); 102 } 103 104 // public LoadFromZipNG(ContentTypeManager ctm) { 105 // this.ctm = ctm; 106 // } 107 107 108 108 … … 143 143 } 144 144 145 HashMap<String, ByteArray> partByteArrays = new HashMap<String, ByteArray>(); 145 146 Enumeration entries = zf.entries(); 146 147 while (entries.hasMoreElements()) { … … 163 164 164 165 165 return process( );166 return process(partByteArrays); 166 167 } 167 168 168 169 public OpcPackage get(InputStream is) throws Docx4JException { 169 170 171 HashMap<String, ByteArray> partByteArrays = new HashMap<String, ByteArray>(); 170 172 try { 171 173 ZipInputStream zis = new ZipInputStream(is); … … 187 189 // work the same way 188 190 189 return process( );190 } 191 192 private OpcPackage process( ) throws Docx4JException {191 return process(partByteArrays); 192 } 193 194 private OpcPackage process(HashMap<String, ByteArray> partByteArrays) throws Docx4JException { 193 195 194 196 // 2. Create a new Package 195 197 // Eventually, you'll also be able to create an Excel package etc 196 198 // but only the WordML package exists at present 199 200 ContentTypeManager ctm = new ContentTypeManager(); 197 201 198 202 try { … … 235 239 // (ii) add the new Part to the package 236 240 // (iii) cross the PartName off unusedZipEntries 237 addPartsFromRelationships(partByteArrays, p, rp );241 addPartsFromRelationships(partByteArrays, p, rp, ctm ); 238 242 239 243 … … 313 317 //private void addPartsFromRelationships(ZipFile zf, Base source, RelationshipsPart rp) 314 318 private void addPartsFromRelationships(HashMap<String, ByteArray> partByteArrays, 315 Base source, RelationshipsPart rp )319 Base source, RelationshipsPart rp, ContentTypeManager ctm) 316 320 throws Docx4JException { 317 321 … … 342 346 // a part, so start with a line break. 343 347 try { 344 getPart(partByteArrays, pkg, rp, r );348 getPart(partByteArrays, pkg, rp, r, ctm); 345 349 } catch (Exception e) { 346 350 throw new Docx4JException("Failed to add parts from relationships", e); … … 367 371 //private void getPart(ZipFile zf, Package pkg, RelationshipsPart rp, Relationship r) 368 372 private void getPart(HashMap<String, ByteArray> partByteArrays, OpcPackage pkg, RelationshipsPart rp, 369 Relationship r )373 Relationship r, ContentTypeManager ctm) 370 374 throws Docx4JException, InvalidFormatException, URISyntaxException { 371 375 … … 409 413 } 410 414 411 if ( handled.get(resolvedPartUri)!=null) return;415 if (pkg.handled.get(resolvedPartUri)!=null) return; 412 416 413 417 String relationshipType = r.getType(); … … 420 424 } 421 425 rp.loadPart(part, r); 422 handled.put(resolvedPartUri, resolvedPartUri);426 pkg.handled.put(resolvedPartUri, resolvedPartUri); 423 427 424 428 // The source Part (or Package) might have a convenience … … 434 438 if (rrp!=null) { 435 439 // recurse via this parts relationships, if it has any 436 addPartsFromRelationships(partByteArrays, part, rrp );440 addPartsFromRelationships(partByteArrays, part, rrp, ctm ); 437 441 String relPart = PartName.getRelationshipsPartName( 438 442 part.getPartName().getName().substring(1) ); -
trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/OpcPackage.java
r1307 r1467 63 63 64 64 /** 65 * This HashMap is intended to prevent loops during the loading 66 * of this package. TODO This doesn't really tell us anything that 67 * the contents of Parts couldn't also tell us (except that 68 * that doesn't contain the rels parts), so consider removing. 69 * At least replace it with a method, so this implementation 70 * detail is hidden! 71 */ 72 public HashMap<String, String> handled = new HashMap<String, String>(); 73 74 /** 65 75 * Package parts collection. This is a collection of _all_ 66 76 * parts in the package (_except_ relationship parts),
Note: See TracChangeset
for help on using the changeset viewer.
