Ignore:
Timestamp:
06/22/11 01:36:38 (11 months ago)
Author:
jharrop
Message:

Apply Dave Brown's "assorted patches" of 28 April, as described at
 http://dev.plutext.org/forums/docx-java-f6/assorted-patches-t712.html

Location:
trunk/docx4j/src/main/java/org/docx4j/openpackaging
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/io/LoadFromZipNG.java

    r1493 r1555  
    425425                String relationshipType = r.getType();           
    426426                         
    427                 Part part = getRawPart(partByteArrays, ctm, resolvedPartUri, r); 
     427                Part part = getRawPart(partByteArrays, ctm, resolvedPartUri, r); // will throw exception if null 
     428 
    428429                if (part instanceof BinaryPart 
    429430                                || part instanceof DefaultXmlPart) { 
     
    492493         * @see  To get a Part and all its related parts, and add all to a package, use 
    493494         * getPart. 
    494          * @param zf 
     495         * @param partByteArrays 
     496         * @param ctm 
    495497         * @param resolvedPartUri 
     498         * @param rel 
    496499         * @return 
    497          * @throws URISyntaxException 
    498          * @throws InvalidFormatException 
     500         * @throws Docx4JException including if result is null 
    499501         */ 
    500         //public static Part getRawPart(ZipFile zf, ContentTypeManager ctm, String resolvedPartUri) 
    501502        public static Part getRawPart(HashMap<String, ByteArray> partByteArrays, 
    502503                        ContentTypeManager ctm, String resolvedPartUri, Relationship rel)        
     
    617618                                } else if (part instanceof org.docx4j.openpackaging.parts.XmlPart ) { 
    618619                                         
    619                                         try { 
     620//                                      try { 
    620621                                                ((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//                                      } 
    630634                                         
    631635                                } else { 
     
    639643                         
    640644                        } catch (PartUnrecognisedException e) { 
    641                                 log.warn("PartUnrecognisedException shouldn't happen anymore!"); 
     645                                log.error("PartUnrecognisedException shouldn't happen anymore!", e); 
    642646                                // Try to get it as a binary part 
    643647                                part = getBinaryPart(partByteArrays, ctm, resolvedPartUri); 
     
    660664                        } 
    661665                } 
     666                 
     667        if (part == null) { 
     668            throw new Docx4JException("cannot find part " + resolvedPartUri + " from rel "+ rel.getId() + "=" + rel.getTarget()); 
     669        } 
     670                 
    662671                return part; 
    663672        } 
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/parts/XmlPart.java

    r1399 r1555  
    7070                super(); 
    7171        } 
    72          
     72 
    7373        /** 
    7474         * This part's XML contents.  Not guaranteed to be up to date. 
     
    8080        private static XPathFactory xPathFactory; 
    8181        private static XPath xPath; 
    82          
     82 
    8383        private static DocumentBuilderFactory documentFactory; 
    84         private static DocumentBuilder documentBuilder; 
     84 
    8585         
    8686        static { 
     
    109109                 
    110110                documentFactory.setNamespaceAware(true); 
    111                 try { 
    112                         documentBuilder = documentFactory.newDocumentBuilder(); 
    113                 } catch (ParserConfigurationException e) { 
    114                         e.printStackTrace(); 
    115                 }                
    116                  
     111 
    117112        } 
    118113         
     
    129124        public void setDocument(InputStream is) throws Docx4JException { 
    130125                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); 
    132128                } catch (Exception e) { 
    133129                        throw new Docx4JException("Problems parsing InputStream for part " + this.partName.getName(), e); 
Note: See TracChangeset for help on using the changeset viewer.