- 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/LoadFromZipFile.java
r1003 r1004 51 51 import org.docx4j.openpackaging.parts.relationships.RelationshipsPart; 52 52 import org.docx4j.relationships.Relationship; 53 import org.dom4j.Document;54 import org.dom4j.DocumentException;55 import org.dom4j.io.SAXReader;56 53 57 54 … … 130 127 // but only the WordML package exists at present 131 128 132 Document ctmDocument = null;133 129 try { 134 ctmDocument = deprecatedGetDocumentFromZippedPart(zf, "[Content_Types].xml"); 135 } catch (Exception e) { 136 // Shouldn't happen 137 throw new Docx4JException("Couldn't get [Content_Types].xml", e); 138 } 139 debugPrint(ctmDocument); 140 ctm.parseContentTypesFile(ctmDocument); 130 InputStream is = getInputStreamFromZippedPart( zf, "[Content_Types].xml"); 131 ctm.parseContentTypesFile(is); 132 } catch (IOException e) { 133 throw new Docx4JException("Couldn't get [Content_Types].xml from ZipFile", e); 134 } 135 141 136 Package p = ctm.createPackage(); 142 137 … … 236 231 237 232 private static InputStream getInputStreamFromZippedPart(ZipFile zf, String partName) 238 throws DocumentException,IOException {233 throws IOException { 239 234 240 235 InputStream in = null; … … 244 239 245 240 246 private static Document deprecatedGetDocumentFromZippedPart(ZipFile zf, String partName)247 throws DocumentException, IOException {248 249 InputStream in = null;250 in = zf.getInputStream( zf.getEntry(partName ) );251 SAXReader xmlReader = new SAXReader();252 Document contents = null;253 try {254 contents = xmlReader.read(in);255 } catch (DocumentException e) {256 // Will land here for binary files eg gif file257 // These do get handled ..258 log.error("DocumentException on " + partName + " . Check this is binary content.");259 //e.printStackTrace() ;260 throw e;261 } finally {262 if (in != null) {263 try {264 in.close();265 } catch (IOException exc) {266 exc.printStackTrace();267 }268 }269 }270 return contents;271 }272 241 273 242 /* recursively … … 579 548 } 580 549 581 private void dumpZipFileContents(ZipFile zf) {582 Enumeration entries = zf.entries();583 // Enumerate through the Zip entries until we find the one named584 // '[Content_Types].xml'.585 while (entries.hasMoreElements()) {586 ZipEntry entry = (ZipEntry) entries.nextElement();587 log.info( "\n\n" + entry.getName() + "\n" );588 InputStream in = null;589 try {590 in = zf.getInputStream(entry);591 } catch (IOException e) {592 e.printStackTrace() ;593 }594 SAXReader xmlReader = new SAXReader();595 Document xmlDoc = null;596 try {597 xmlDoc = xmlReader.read(in);598 } catch (DocumentException e) {599 // Will land here for binary files eg gif file600 e.printStackTrace() ;601 } finally {602 if (in != null) {603 try {604 in.close();605 } catch (IOException exc) {606 exc.printStackTrace();607 }608 }609 }610 debugPrint(xmlDoc);611 612 }613 614 }615 616 617 618 619 620 550 621 551 }
Note: See TracChangeset
for help on using the changeset viewer.
