[CXF-7489] Use StaxUtils to parse, fix compile errors This closes #308
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/27a11b1e Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/27a11b1e Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/27a11b1e Branch: refs/heads/3.1.x-fixes Commit: 27a11b1e5838d7b1062dbb2f03fc105cb8c30d9f Parents: 87c8065 Author: Daniel Kulp <dk...@apache.org> Authored: Wed Aug 30 18:14:52 2017 -0400 Committer: Daniel Kulp <dk...@apache.org> Committed: Tue Sep 5 10:12:52 2017 -0400 ---------------------------------------------------------------------- .../staxutils/validation/Stax2ValidationUtils.java | 17 ++++++----------- .../validation/Stax2ValidationUtilsTest.java | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/27a11b1e/core/src/main/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtils.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtils.java b/core/src/main/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtils.java index 343cafa..38ac4ff 100644 --- a/core/src/main/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtils.java +++ b/core/src/main/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtils.java @@ -25,8 +25,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.XMLConstants; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; @@ -34,6 +32,8 @@ import javax.xml.stream.XMLStreamWriter; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.xml.sax.InputSource; + import org.apache.cxf.common.i18n.Message; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.endpoint.Endpoint; @@ -41,6 +41,7 @@ import org.apache.cxf.interceptor.Fault; import org.apache.cxf.service.model.SchemaInfo; import org.apache.cxf.service.model.ServiceInfo; import org.apache.cxf.staxutils.DepthXMLStreamReader; +import org.apache.cxf.staxutils.StaxUtils; import org.apache.ws.commons.schema.XmlSchema; import org.apache.ws.commons.schema.XmlSchemaExternal; import org.codehaus.stax2.XMLStreamReader2; @@ -185,15 +186,9 @@ class Stax2ValidationUtils { } private Element getElement(String path) throws XMLStreamException { - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - try { - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); - Document doc = dBuilder.parse(path); - return doc.getDocumentElement(); - } catch (Exception e) { - throw new XMLStreamException("There was an error trying to get external schemas " + e.getMessage()); - } - + InputSource in = new InputSource(path); + Document doc = StaxUtils.read(in); + return doc.getDocumentElement(); } } http://git-wip-us.apache.org/repos/asf/cxf/blob/27a11b1e/core/src/test/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtilsTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtilsTest.java b/core/src/test/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtilsTest.java index 703592d..e21bbf9 100644 --- a/core/src/test/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtilsTest.java +++ b/core/src/test/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtilsTest.java @@ -105,7 +105,7 @@ public class Stax2ValidationUtilsTest { @Parameterized.Parameters public static Collection<String[]> data() { - List<String[]> parameters = new ArrayList(); + List<String[]> parameters = new ArrayList<>(); parameters.add(new String[]{VALID_MESSAGE_ECHO, INVALID_MESSAGE_ECHO, ECHO_ERROR_MESSAGE, MULTI_IMPORT_SCHEMA}); parameters.add(new String[]{VALID_MESSAGE_LOG, INVALID_MESSAGE_LOG, LOG_ERROR_MESSAGE, MULTI_IMPORT_SCHEMA}); parameters.add(new String[]{VALID_MESSAGE_ECHO, INVALID_MESSAGE_ECHO, ECHO_ERROR_MESSAGE, ECHO_SCHEMA});