- Timestamp:
- 01/09/10 18:15:02 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/openpackaging/io/LoadFromZipNG.java
r1003 r1004 59 59 import org.docx4j.relationships.Relationship; 60 60 61 import org.dom4j.Document;62 import org.dom4j.DocumentException;63 import org.dom4j.io.SAXReader;64 61 65 62 … … 187 184 // Eventually, you'll also be able to create an Excel package etc 188 185 // but only the WordML package exists at present 189 190 Document ctmDocument = null; 186 191 187 try { 192 ctmDocument = deprecatedGetDocumentFromZippedPart(partByteArrays, "[Content_Types].xml"); 193 } catch (Exception e) { 194 // Shouldn't happen 195 throw new Docx4JException("Couldn't get [Content_Types].xml", e); 196 } 197 debugPrint(ctmDocument); 198 ctm.parseContentTypesFile(ctmDocument); 188 InputStream is = getInputStreamFromZippedPart( partByteArrays, "[Content_Types].xml"); 189 ctm.parseContentTypesFile(is); 190 } catch (IOException e) { 191 throw new Docx4JException("Couldn't get [Content_Types].xml from ZipFile", e); 192 } 193 199 194 Package p = ctm.createPackage(); 200 195 … … 290 285 String partName) 291 286 //private static InputStream getInputStreamFromZippedPart(ZipFile zf, String partName) 292 throws DocumentException,IOException {287 throws IOException { 293 288 294 289 InputStream in = null; … … 298 293 } 299 294 300 301 private static Document deprecatedGetDocumentFromZippedPart(HashMap<String, ByteArray> partByteArrays, 302 String partName) 303 //private static Document deprecatedGetDocumentFromZippedPart(ZipFile zf, String partName) 304 throws DocumentException, IOException { 305 306 InputStream in = null; 307 // in = zf.getInputStream( zf.getEntry(partName ) ); 308 in = partByteArrays.get(partName).getInputStream(); 309 SAXReader xmlReader = new SAXReader(); 310 Document contents = null; 311 try { 312 contents = xmlReader.read(in); 313 } catch (DocumentException e) { 314 // Will land here for binary files eg gif file 315 // These do get handled .. 316 log.error("DocumentException on " + partName + " . Check this is binary content."); 317 //e.printStackTrace() ; 318 throw e; 319 } finally { 320 if (in != null) { 321 try { 322 in.close(); 323 } catch (IOException exc) { 324 exc.printStackTrace(); 325 } 326 } 327 } 328 return contents; 329 } 330 295 331 296 /* recursively 332 297 (i) create new Parts for each thing listed … … 632 597 return part; 633 598 } 634 635 private void dumpZipFileContents(ZipFile zf) { 636 Enumeration entries = zf.entries(); 637 // Enumerate through the Zip entries until we find the one named 638 // '[Content_Types].xml'. 639 while (entries.hasMoreElements()) { 640 ZipEntry entry = (ZipEntry) entries.nextElement(); 641 log.info( "\n\n" + entry.getName() + "\n" ); 642 InputStream in = null; 643 try { 644 in = zf.getInputStream(entry); 645 } catch (IOException e) { 646 e.printStackTrace() ; 647 } 648 SAXReader xmlReader = new SAXReader(); 649 Document xmlDoc = null; 650 try { 651 xmlDoc = xmlReader.read(in); 652 } catch (DocumentException e) { 653 // Will land here for binary files eg gif file 654 e.printStackTrace() ; 655 } finally { 656 if (in != null) { 657 try { 658 in.close(); 659 } catch (IOException exc) { 660 exc.printStackTrace(); 661 } 662 } 663 } 664 debugPrint(xmlDoc); 665 666 } 667 668 } 669 599 670 600 class ByteArray { 671 601
Note: See TracChangeset
for help on using the changeset viewer.
