Skip to content

Commit

Permalink
fixup! Fix Resolve Schema Location for xsi:SchemaLocation in Config f…
Browse files Browse the repository at this point in the history
…iles

- convert systemId to a URI and get its path when comparing with resolvedURI
- undo change to resolveSchemaLocation

DAFFODIL-2339
  • Loading branch information
olabusayoT committed Oct 15, 2024
1 parent cdc9b81 commit 6137cf8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class DFDLCatalogResolver private ()
resolvedSystem
} else if (
resolvedUri != null && ((systemId == null) || (systemId != null && resolvedUri.endsWith(
systemId
(new URI(systemId)).getPath
)))
) {
resolvedUri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1459,27 +1459,34 @@ Differences were (path, expected, actual):
)
}

val uriIsJustPathComponent =
uri.getScheme == null &&
uri.getAuthority == null &&
uri.getQuery == null &&
uri.getFragment == null &&
uri.getPath != null

val optResolved: Option[(URISchemaSource, Boolean)] =
if (uri.isAbsolute && uri.getScheme.contains("jar")) {
// an absolute URI is one with a scheme. In the case that it is a jar uri
// we expect to be able to resolve the URI and do not try anything else
// (e.g. filesystem, classpath). Since this function
if (uri.isAbsolute) {
// an absolute URI is one with a scheme. In this case, we expect to be able to resolve
// the URI and do not try anything else (e.g. filesystem, classpath). Since this function
// is for schemaLocation attributes, we may eventually want to disallow this, and only
// allow relative URIs (i.e. URIs without a scheme). We do have some places that use
// absolute URIs in includes/imports and cannot remove this yet.
try {
uri.toURL.openStream.close()
uri.toURL.openStream.close
val uss = URISchemaSource(Misc.uriToDiagnosticFile(uri), uri)
Some(uss, false)
} catch {
case e: IOException => None
}
}
// we want to attempt to resolve the URI whether the non-jar uri has a scheme or not,
// this is relevant for when we are validating with Xerces, and it calls resolvesEntity
// we get URIs that look like file:/path/to/not/absolute/path ex: file:/org/apache/daffodil/xsd/dafext.xsd
// that fail to be found in the above case, so we have to look them up
else if (uri.getPath.startsWith("/")) {
} else if (!uriIsJustPathComponent) {
// this is not an absolute URI so we don't have a scheme. This should just be a path, so
// throw an IllegalArgumentException if that's not the case
val msg =
s"Non-absolute schemaLocation URI can only contain a path component: $schemaLocation"
throw new IllegalArgumentException(msg)
} else if (uri.getPath.startsWith("/")) {
// The None.orElse{ ... }.orElse { ... } pattern below is useful to evaluate each
// alternative way to resolve a schema location, stopping only when a Some is returned.
// This makes for easily adding/removing/reordering resolution approaches by changing
Expand All @@ -1499,7 +1506,7 @@ Differences were (path, expected, actual):
.orElse {
// Search for the schemaLocation path on the file system. This path is absolute so it
// must exist. If it does not exist, this orElse block results in a None
val file = new File(uri.getPath)
val file = Paths.get(uri.getPath).toFile
if (file.exists) {
val uss = URISchemaSource(file, file.toURI)
Some((uss, false))
Expand Down

0 comments on commit 6137cf8

Please sign in to comment.