[
https://issues.apache.org/jira/browse/DAFFODIL-3035?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18016759#comment-18016759
]
Steve Lawrence commented on DAFFODIL-3035:
------------------------------------------
Thinking more on this, I don't think we need a new "withValidator(Validator)"
API, but I think we do need to tweak our existing withValidation API to take a
URL instead of a URI.
The reasoning is because a URL has built-in knowledge about how to get an input
stream, which is exactly what our validators need. With a URI, we might not
necessarily know how to open it (for example with smooks custom "classpath://"
scheme). A URL is required to have a scheme URLStreamHandler for knowing how to
get an InputStream to it. And smooks already has the ability to get such URLs,
it just currently returns the associated stream, but it could be easily changed
to return the associated URL.
Additionally, if a Validator really needs a blob of bytes (mentioned above) or
some other custom URL scheme, it's not too difficult to do create a custom
URLStreamHandler. And there are a number of ways to provide custom stream
handlers, for example globally by setting URLStreamHandlerFactory and locally
via the URL constructor. There are other ways as well.
Lastly, requiring a URL in withValidation is a restriction that we actually
already have, since the first thing our validation API does is call toURL() to
convert the URI to a URL. This requirement is just implicit and not documented.
By changing the parameter to a URI we are explicit about it and we leave it up
to the user to provide something that gives us the information we need (e.g. a
path used to infer type of the file, and a way to open it as an InputStream).
> No way to create a Validator using a InputStream as a source
> ------------------------------------------------------------
>
> Key: DAFFODIL-3035
> URL: https://issues.apache.org/jira/browse/DAFFODIL-3035
> Project: Daffodil
> Issue Type: Bug
> Components: API
> Reporter: Steve Lawrence
> Priority: Major
> Fix For: 4.0.0
>
>
> The new Validator API configures validators by providing them a Java
> Properties instance, which is just a bunch of key/value pairs. There is no
> longer a way to directly create a validator using some other mechanism. The
> idea that key/value pairs should be sufficient may not be correct.
> Currently, the smooks library gets an InputStream to a schematron file,
> manually creates a custom schematron validator using that stream, and
> provides that to Daffodil. Smooks supports getting the schematron InputStream
> from a number of places, some of which might not be able to be represented as
> a string in a key/value Properties. For example, if has a custom
> "classpath:/..." uri schema that gets a stream from a classpath.
> We should figure out if there's a way we can support this. Properties only
> supports string key/values so we might need an alternative approach. Or
> possibly we just need a way to allow API users to manually create validators
> with something other than a Properties, and provide that Validator to
> Daffodil isntead of using withValidation.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)