jw3 commented on a change in pull request #431:
URL: https://github.com/apache/incubator-daffodil/pull/431#discussion_r512205715



##########
File path: 
daffodil-lib/src/main/scala/org/apache/daffodil/util/DefaultValidator.scala
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.daffodil.util
+
+import java.net.URI
+
+import com.typesafe.config.Config
+
+import scala.xml.parsing.NoBindingFactoryAdapter
+import javax.xml.XMLConstants
+import javax.xml.transform.stream.StreamSource
+import org.apache.daffodil.api.SaxValidationError
+import org.apache.daffodil.api.SaxValidationWarning
+import org.apache.daffodil.api.ValidationFailure
+import org.apache.daffodil.api.ValidationResult
+import org.apache.daffodil.api.ValidationWarning
+import org.apache.daffodil.api.Validator
+import org.apache.daffodil.api.ValidatorFactory
+import org.apache.daffodil.xml.DFDLCatalogResolver
+import org.xml.sax.ErrorHandler
+import org.xml.sax.SAXException
+import org.xml.sax.SAXParseException
+
+import scala.collection.JavaConverters._
+
+/**
+ * Use this for extra validation passes in the TDML Runner
+ * to do a validation pass on the TDML expected Infoset w.r.t. the model and to
+ * do a validation pass on the actual result w.r.t. the model as an XML 
document.
+ */
+class DefaultValidator(schemaFileNames: Seq[String])
+  extends NoBindingFactoryAdapter // todo;; do we need this adapter?
+  with Validator
+  with ErrorHandler {
+
+  private var errors = List.empty[ValidationFailure]
+  private var warnings = List.empty[ValidationWarning]
+
+  def validateXML(document: java.io.InputStream): ValidationResult = {
+    val schemaSources: Seq[javax.xml.transform.Source] = schemaFileNames.map { 
fn =>
+      val uri = new URI(fn)
+      val is = uri.toURL.openStream()
+      val stream = new StreamSource(is)
+      stream.setSystemId(uri.toString) // must set this so that relative URIs 
will be created for import/include files.
+      stream
+    }
+
+    val factory = new org.apache.xerces.jaxp.validation.XMLSchemaFactory()
+    factory.setErrorHandler(this)
+    val resolver = DFDLCatalogResolver.get
+    factory.setResourceResolver(resolver)
+    val schema = factory.newSchema(schemaSources.toArray)
+    val validator = initializeValidator(schema.newValidator(), this, resolver)
+

Review comment:
       How about in the validator but handled at init time?  Simplifies some 
things this way (pushed an update).




----------------------------------------------------------------
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.

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


Reply via email to