Changeset 1555 for trunk/docx4j/src/main/java/org/docx4j/openpackaging
- Timestamp:
- 06/22/11 01:36:38 (11 months ago)
- Location:
- trunk/docx4j/src/main/java/org/docx4j/openpackaging
- Files:
-
- 2 edited
-
io/LoadFromZipNG.java (modified) (5 diffs)
-
parts/XmlPart.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/openpackaging/io/LoadFromZipNG.java
r1493 r1555 425 425 String relationshipType = r.getType(); 426 426 427 Part part = getRawPart(partByteArrays, ctm, resolvedPartUri, r); 427 Part part = getRawPart(partByteArrays, ctm, resolvedPartUri, r); // will throw exception if null 428 428 429 if (part instanceof BinaryPart 429 430 || part instanceof DefaultXmlPart) { … … 492 493 * @see To get a Part and all its related parts, and add all to a package, use 493 494 * getPart. 494 * @param zf 495 * @param partByteArrays 496 * @param ctm 495 497 * @param resolvedPartUri 498 * @param rel 496 499 * @return 497 * @throws URISyntaxException 498 * @throws InvalidFormatException 500 * @throws Docx4JException including if result is null 499 501 */ 500 //public static Part getRawPart(ZipFile zf, ContentTypeManager ctm, String resolvedPartUri)501 502 public static Part getRawPart(HashMap<String, ByteArray> partByteArrays, 502 503 ContentTypeManager ctm, String resolvedPartUri, Relationship rel) … … 617 618 } else if (part instanceof org.docx4j.openpackaging.parts.XmlPart ) { 618 619 619 try {620 // try { 620 621 ((XmlPart)part).setDocument(is); 621 } catch (Docx4JException d) { 622 // This isn't an XML part after all, 623 // even though ContentTypeManager detected it as such 624 // So get it as a binary part 625 part = getBinaryPart(partByteArrays, ctm, resolvedPartUri); 626 log.warn("Could not parse as XML, so using BinaryPart for " 627 + resolvedPartUri); 628 ((BinaryPart)part).setBinaryData(is); 629 } 622 623 // Experimental 22/6/2011; don't fall back to binary (which we used to) 624 625 // } catch (Docx4JException d) { 626 // // This isn't an XML part after all, 627 // // even though ContentTypeManager detected it as such 628 // // So get it as a binary part 629 // part = getBinaryPart(partByteArrays, ctm, resolvedPartUri); 630 // log.warn("Could not parse as XML, so using BinaryPart for " 631 // + resolvedPartUri); 632 // ((BinaryPart)part).setBinaryData(is); 633 // } 630 634 631 635 } else { … … 639 643 640 644 } catch (PartUnrecognisedException e) { 641 log. warn("PartUnrecognisedException shouldn't happen anymore!");645 log.error("PartUnrecognisedException shouldn't happen anymore!", e); 642 646 // Try to get it as a binary part 643 647 part = getBinaryPart(partByteArrays, ctm, resolvedPartUri); … … 660 664 } 661 665 } 666 667 if (part == null) { 668 throw new Docx4JException("cannot find part " + resolvedPartUri + " from rel "+ rel.getId() + "=" + rel.getTarget()); 669 } 670 662 671 return part; 663 672 } -
trunk/docx4j/src/main/java/org/docx4j/openpackaging/parts/XmlPart.java
r1399 r1555 70 70 super(); 71 71 } 72 72 73 73 /** 74 74 * This part's XML contents. Not guaranteed to be up to date. … … 80 80 private static XPathFactory xPathFactory; 81 81 private static XPath xPath; 82 82 83 83 private static DocumentBuilderFactory documentFactory; 84 private static DocumentBuilder documentBuilder; 84 85 85 86 86 static { … … 109 109 110 110 documentFactory.setNamespaceAware(true); 111 try { 112 documentBuilder = documentFactory.newDocumentBuilder(); 113 } catch (ParserConfigurationException e) { 114 e.printStackTrace(); 115 } 116 111 117 112 } 118 113 … … 129 124 public void setDocument(InputStream is) throws Docx4JException { 130 125 try { 131 doc = documentBuilder.parse(is); 126 DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder(); // DocumentBuilder is not thread safe, so it needs to be local 127 doc = documentBuilder.parse(is); 132 128 } catch (Exception e) { 133 129 throw new Docx4JException("Problems parsing InputStream for part " + this.partName.getName(), e);
Note: See TracChangeset
for help on using the changeset viewer.
