stevedlawrence commented on code in PR #1060:
URL: https://github.com/apache/daffodil/pull/1060#discussion_r1273417261


##########
daffodil-lib/src/test/scala/org/apache/daffodil/lib/util/TestXMLCatalogAndValidate.scala:
##########
@@ -446,48 +452,56 @@ class SchemaAwareFactoryAdapter() extends 
NoBindingFactoryAdapter {
   f.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true)
   f.setValidating(true)
   val p = f.newSAXParser()
-  val xr = p.getXMLReader()
+  val r = p.getXMLReader()
+
+  // We must use XMLReader setProperty() function to set the entity 
resolver--calling
+  // setEntityResolver with the Xerces XML reader causes validation to fail 
for some
+  // reason. We call the right function below, but unfortunately, scala-xml 
calls
+  // setEntityResolver in loadDocument(), which cannot be disabled and 
scala-xml does not
+  // want to change. To avoid this, we wrap the Xerces XMLReader in an 
XMLFilterImpl and
+  // override setEntityResolver to a no-op. However, XMLFilterImpl parse() 
calls
+  // setEntityResolver() on the XMLReader, which for the same reason as before 
causes
+  // issues. To fix this, we can override parse() to just pass through to the 
parent, but
+  // that means we must override the various set/get handler functions to also 
pass
+  // through to the parent.

Review Comment:
   > I'm glad we have something that works, but I'd say scala-xml is a mess if 
it requires this. 
   
   I'd agree, however, it also wouldn't surprising me if we're just doing 
something really wrong in how we're setting features/properties on the SAX 
Parser/XMLReader. The fact that we set a property with name 
"**internal**/entity-resolver" in it, makes me feel like we're missing 
something that would allow `setEntitytResolver` to work. I did play around with 
it a bit, but couldn't figure it out.
   
   > Or are there sufficient test elsewhere of that, and the purpose of this 
really is to illustrate usage for this foolish resolver crud in scala-xml?
   
   I think this is the case. We do have a few tests (e.g. 
[TestXMLLoader.scala](https://github.com/apache/daffodil/blob/main/daffodil-lib/src/test/scala/org/apache/daffodil/lib/xml/test/unit/TestXMLLoader.scala)
  that are unit tests specifically around the use of the DaffodilXMLLoader. I 
think this file does act as a pretty good example of how to hook together 
scala-xml and Xerces + catalog manager/validation stuff and should probably 
stick around.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to