Skip to content

Commit

Permalink
StAX: Woodstox doesn't like XMLReporter to be empty string, so implem…
Browse files Browse the repository at this point in the history
…ent it
  • Loading branch information
plutext committed Dec 16, 2016
1 parent 527341c commit d34815a
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/main/java/org/docx4j/openpackaging/parts/JaxbXmlPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.stream.Location;
import javax.xml.stream.StreamFilter;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLReporter;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
Expand Down Expand Up @@ -392,11 +394,25 @@ public void pipe(StAXHandlerInterface handler, StreamFilter filter) throws XMLSt

XMLInputFactory xmlif = null;
xmlif = XMLInputFactory.newInstance();
xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES,Boolean.TRUE);
xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,Boolean.FALSE);
xmlif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
xmlif.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
xmlif.setProperty(XMLInputFactory.REPORTER,"");
xmlif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);

// Nonfatal errors and warnings
xmlif.setXMLReporter(
(new XMLReporter() {

@Override
public void report(String message, String errorType, Object relatedInformation, Location location) throws XMLStreamException {
log.warn("Error:" + errorType + ", " + message + " at line " + location.getLineNumber() + ", col " + location.getColumnNumber());
}
})
);

// xmlif.setProperty(XMLInputFactory.RESOLVER
// xmlif.setProperty(XMLInputFactory.ALLOCATOR

// First, set up stream reader
XMLStreamReader xmlr = null;
Expand Down Expand Up @@ -455,8 +471,12 @@ public void pipe(StAXHandlerInterface handler, StreamFilter filter) throws XMLSt
}

try {
log.debug("StAX implementation details:");
log.debug(xmlr.getClass().getName());
log.debug(xmlWriter.getClass().getName());
handler.handle(xmlr, xmlWriter);
} catch (LocationAwareXMLStreamException e) {

} catch (/* fatal error */ LocationAwareXMLStreamException e) {

log.error(e.getMessage() + " at line " + e.getLocation().getLineNumber() + ", col " + e.getLocation().getColumnNumber());
e.getCause().printStackTrace();
Expand Down Expand Up @@ -556,7 +576,6 @@ public void pipe(StAXHandlerInterface handler, StreamFilter filter) throws XMLSt
}



/**
* Marshal the content tree rooted at <tt>jaxbElement</tt> into a DOM tree.
*
Expand Down

0 comments on commit d34815a

Please sign in to comment.