stevedlawrence closed pull request #62: Explicitly use the Xerces factories
that use our custom catalog resolver
URL: https://github.com/apache/incubator-daffodil/pull/62
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/daffodil-cli/src/it/scala/org/apache/daffodil/parsing/TestCLIParsing.scala
b/daffodil-cli/src/it/scala/org/apache/daffodil/parsing/TestCLIParsing.scala
index 1b91b78e5..7281d466b 100644
--- a/daffodil-cli/src/it/scala/org/apache/daffodil/parsing/TestCLIParsing.scala
+++ b/daffodil-cli/src/it/scala/org/apache/daffodil/parsing/TestCLIParsing.scala
@@ -929,5 +929,31 @@ class TestCLIparsing {
}
}
+ // These DAFFODIL_JAVA_OPTS values change the Java defaults classes like
+ // SAXParserFactory and SchemaFactory to be Java's internal classes instead
+ // of those provided by dependencies (e.g. Xerces) included with Daffodil.
+ // Some places require dependency version of these classes. This test ensures
+ // that we override defaults when necesssary
+ @Test def test_CLI_Parsing_JavaDefaults() {
+ val schemaFile =
Util.daffodilPath("daffodil-test/src/test/resources/org/apache/daffodil/section06/entities/charClassEntities.dfdl.xsd")
+ val testSchemaFile = if (Util.isWindows) Util.cmdConvert(schemaFile) else
schemaFile
+ val java_opts = Map("DAFFODIL_JAVA_OPTS" ->
+
("-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
" +
+
"-Djavax.xml.xml.validation.SchemaFactory=com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaFactory"))
+
+ val shell = Util.start("", envp = java_opts)
+
+ try {
+ val cmd = String.format("echo 0,1,2| %s parse -s %s -r matrix",
Util.binPath, testSchemaFile)
+ shell.sendLine(cmd)
+
+ shell.expect(contains(output1))
+ shell.sendLine("exit")
+ shell.expect(eof)
+ } finally {
+ shell.close()
+ }
+ }
+
}
diff --git
a/daffodil-lib/src/main/scala/org/apache/daffodil/externalvars/ExternalVariablesXMLValidator.scala
b/daffodil-lib/src/main/scala/org/apache/daffodil/externalvars/ExternalVariablesXMLValidator.scala
index 95e9ee2f4..acc0d75e1 100644
---
a/daffodil-lib/src/main/scala/org/apache/daffodil/externalvars/ExternalVariablesXMLValidator.scala
+++
b/daffodil-lib/src/main/scala/org/apache/daffodil/externalvars/ExternalVariablesXMLValidator.scala
@@ -18,7 +18,6 @@
package org.apache.daffodil.externalvars
import javax.xml.transform.stream.StreamSource
-import javax.xml.validation.SchemaFactory
import org.xml.sax.SAXException
import java.io.File
@@ -31,8 +30,7 @@ object ExternalVariablesValidator {
def validate(xmlFile: File): Either[java.lang.Throwable, _] = {
try {
- val schemaLang = "http://www.w3.org/2001/XMLSchema"
- val factory = SchemaFactory.newInstance(schemaLang)
+ val factory = new org.apache.xerces.jaxp.validation.XMLSchemaFactory()
val schema = factory.newSchema(new StreamSource(extVarXsd))
val validator = schema.newValidator()
validator.validate(new StreamSource(xmlFile))
diff --git
a/daffodil-lib/src/main/scala/org/apache/daffodil/util/Validator.scala
b/daffodil-lib/src/main/scala/org/apache/daffodil/util/Validator.scala
index 1d22190f8..9063ff21f 100644
--- a/daffodil-lib/src/main/scala/org/apache/daffodil/util/Validator.scala
+++ b/daffodil-lib/src/main/scala/org/apache/daffodil/util/Validator.scala
@@ -19,7 +19,6 @@ package org.apache.daffodil.util
import javax.xml.transform.stream.StreamSource
import javax.xml.XMLConstants
-import javax.xml.validation.SchemaFactory
import scala.xml.parsing.NoBindingFactoryAdapter
import java.io.StringReader
import java.net.URI
@@ -62,9 +61,7 @@ object Validator extends NoBindingFactoryAdapter {
}
}
- val schemaLang = "http://www.w3.org/2001/XMLSchema"
- val factory = SchemaFactory.newInstance(schemaLang)
- // val hdlr = new ContentHandler()
+ val factory = new
org.apache.xerces.jaxp.validation.XMLSchemaFactory()
factory.setErrorHandler(errHandler)
val resolver = DFDLCatalogResolver.get
factory.setResourceResolver(resolver)
diff --git
a/daffodil-lib/src/main/scala/org/apache/daffodil/xml/DaffodilXMLLoader.scala
b/daffodil-lib/src/main/scala/org/apache/daffodil/xml/DaffodilXMLLoader.scala
index b8d703fd3..941b530cc 100644
---
a/daffodil-lib/src/main/scala/org/apache/daffodil/xml/DaffodilXMLLoader.scala
+++
b/daffodil-lib/src/main/scala/org/apache/daffodil/xml/DaffodilXMLLoader.scala
@@ -43,8 +43,6 @@ import org.apache.daffodil.util.Logging
import org.apache.daffodil.util.Misc
import org.apache.daffodil.api.DaffodilSchemaSource
import javax.xml.XMLConstants
-import javax.xml.parsers.SAXParserFactory
-import javax.xml.validation.SchemaFactory
import java.io.InputStream
import java.io.BufferedInputStream
import java.io.Reader
@@ -376,10 +374,7 @@ trait SchemaAwareLoaderMixin {
def resolver = DFDLCatalogResolver.get
override lazy val parser: SAXParser = {
-
- // val x = new com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
-
- val f = SAXParserFactory.newInstance()
+ val f = new org.apache.xerces.jaxp.SAXParserFactoryImpl()
f.setNamespaceAware(true)
f.setFeature("http://xml.org/sax/features/namespace-prefixes", true)
@@ -427,7 +422,7 @@ trait SchemaAwareLoaderMixin {
* using the below SchemaFactory and SchemaFactory.newSchema calls. The
* newSchema call is what forces schema validation to take place.
*/
- protected val sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
+ protected val sf = new org.apache.xerces.jaxp.validation.XMLSchemaFactory()
sf.setResourceResolver(resolver)
sf.setErrorHandler(errorHandler)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services