Skip to content

Commit

Permalink
Resolve Main Schema URI used for Validation
Browse files Browse the repository at this point in the history
- currently we pass it in directly without trying to resolve it, which was ok in  3.8.0 because the URI got resolved before we ever got to validation, so we call resolveSchemaLocation on the uriForLoading so that Xerces Validation can use that.
- added tests to verify

DAFFODIL-2950
  • Loading branch information
olabusayoT committed Nov 1, 2024
1 parent 357f224 commit c11f8d3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.apache.daffodil.core.runtime1
import org.apache.daffodil.core.dsom.SchemaSet
import org.apache.daffodil.core.dsom.SequenceTermBase
import org.apache.daffodil.lib.util.Logger
import org.apache.daffodil.lib.xml.XMLUtils
import org.apache.daffodil.runtime1.api.DFDL
import org.apache.daffodil.runtime1.layers.LayerRuntimeCompiler
import org.apache.daffodil.runtime1.layers.LayerRuntimeData
Expand Down Expand Up @@ -79,7 +80,14 @@ trait SchemaSetRuntime1Mixin {
"The root element cannot have the dfdl:outputValueCalc property."
)
// stored transiently in the SSRD, only used for full validation
val mainSchemaURI = self.schemaSource.uriForLoading
val mainSchemaURI =
XMLUtils.resolveSchemaLocation(self.schemaSource.uriForLoading.toString, None) match {
case Some((uss, _)) => uss.uri
case None =>
throw new IllegalArgumentException(

Check warning on line 87 in daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/SchemaSetRuntime1Mixin.scala

View check run for this annotation

Codecov / codecov/patch

daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/SchemaSetRuntime1Mixin.scala#L87

Added line #L87 was not covered by tests
s"Could not find file or resource ${self.schemaSource.uriForLoading}"
)
}
val p = if (!root.isError) parser else null
val u = if (!root.isError) unparser else null
val ssrd =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
Expand Down Expand Up @@ -1444,5 +1446,25 @@ public void testJavaAPICompileResource() throws IOException, ClassNotFoundExcept
}
}

@Test
public void testJavaAPICompileSource() throws IOException, URISyntaxException, InvalidUsageException {
org.apache.daffodil.japi.Compiler c = Daffodil.compiler();
URI uri = new URI("/test/japi/mySchema1.dfdl.xsd");
ProcessorFactory pf = c.compileSource(uri);
DataProcessor dp = pf.onPath("/").withValidationMode(ValidationMode.Full);

java.io.File file = getResource("/test/japi/myDataBroken.dat");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
try (InputSourceDataInputStream dis = new InputSourceDataInputStream(fis)) {
JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
ParseResult res = dp.parse(dis, outputter);
assertTrue(res.isError());

Diagnostic d = res.getDiagnostics().get(0);
LocationInSchemaFile loc = d.getLocationsInSchemaFiles().get(0);
assertTrue(loc.toString().replace("\\", "/").contains("in " + uri.getPath()));
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream
import java.io.File
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import java.net.URI
import java.nio.ByteBuffer
import java.nio.channels.Channels
import java.nio.charset.StandardCharsets
Expand Down Expand Up @@ -1407,4 +1408,24 @@ class TestScalaAPI {
}
}

@Test
def testScalaAPICompileSource(): Unit = {
val c = Daffodil.compiler()
val uri = new URI("/test/sapi/mySchema1.dfdl.xsd")
val pf = c.compileSource(uri)
val dp = pf.onPath("/").withValidationMode(ValidationMode.Full)

val file = getResource("/test/sapi/myDataBroken.dat")
val fis = new java.io.FileInputStream(file)
using(new InputSourceDataInputStream(fis)) { input =>
val outputter = new ScalaXMLInfosetOutputter()
val res = dp.parse(input, outputter)
assertTrue(res.isError())

val d = res.getDiagnostics(0)
val loc = d.getLocationsInSchemaFiles(0)
assertTrue(loc.toString().replace("\\", "/").contains("in " + uri.getPath))
}
}

}

0 comments on commit c11f8d3

Please sign in to comment.