Changeset 1605 for trunk/docx4j/src/main/java/org/docx4j/openpackaging
- Timestamp:
- 07/09/11 08:46:46 (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/MainDocumentPart.java
r1505 r1605 33 33 import javax.xml.bind.JAXBElement; 34 34 import javax.xml.bind.JAXBException; 35 import javax.xml.bind.UnmarshalException; 35 36 import javax.xml.bind.Unmarshaller; 37 import javax.xml.bind.util.JAXBResult; 36 38 import javax.xml.parsers.DocumentBuilderFactory; 39 import javax.xml.transform.Result; 40 import javax.xml.transform.Templates; 41 import javax.xml.transform.dom.DOMResult; 37 42 38 43 import org.apache.log4j.Logger; … … 42 47 import org.docx4j.dml.CTNonVisualDrawingProps; 43 48 import org.docx4j.jaxb.Context; 49 import org.docx4j.jaxb.JaxbValidationEventHandler; 44 50 import org.docx4j.model.PropertyResolver; 45 51 import org.docx4j.model.listnumbering.AbstractListNumberingDefinition; … … 269 275 binder = jc.createBinder(); 270 276 271 binder.setEventHandler( 272 new org.docx4j.jaxb.JaxbValidationEventHandler()); 273 274 jaxbElement = (org.docx4j.wml.Document) binder.unmarshal( doc ); 277 JaxbValidationEventHandler eventHandler = new JaxbValidationEventHandler(); 278 eventHandler.setContinue(false); 279 binder.setEventHandler(eventHandler); 280 281 try { 282 jaxbElement = (org.docx4j.wml.Document) binder.unmarshal( doc ); 283 } catch (UnmarshalException ue) { 284 285 // mimic docx4j 2.7.0 and earlier behaviour 286 eventHandler.setContinue(true); 287 288 if (ue.getMessage().contains(JaxbValidationEventHandler.UNEXPECTED_MC_ALTERNATE_CONTENT)) { 289 // Try our preprocessor 290 log.info("encountered mc:AlternateContent; pre-processing"); 291 292 // There is no JAXBResult(binder), 293 // so use a 294 DOMResult result = new DOMResult(); 295 296 Templates mcPreprocessorXslt = JaxbValidationEventHandler.getMcPreprocessor(); 297 XmlUtils.transform(doc, mcPreprocessorXslt, null, result); 298 299 doc = (org.w3c.dom.Document)result.getNode(); 300 301 } else { 302 log.error(ue); 303 log.info("trying again; likely attribute/element loss"); 304 } 305 jaxbElement = (org.docx4j.wml.Document) binder.unmarshal( doc ); 306 307 } 275 308 276 309 return jaxbElement;
Note: See TracChangeset
for help on using the changeset viewer.
