camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Johan Mörén (JIRA) <j...@apache.org>
Subject [jira] [Comment Edited] (CAMEL-8287) Schematron component does not work with includes in schematron
Date Tue, 09 Aug 2016 14:30:20 GMT

    [ https://issues.apache.org/jira/browse/CAMEL-8287?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15413612#comment-15413612
] 

Johan Mörén edited comment on CAMEL-8287 at 8/9/16 2:30 PM:
------------------------------------------------------------

I'v been trying some things out and found that a possible way to fix this issue is to allow
the user to configure the endpoint with an optional "Client" URIResolver. 

{code:xml}
...
<to id="DD_METS-schematron-validation" uri="schematron:metadata/schematron/identifier_checks.sch?uriResolver=#customUriResolver"/>
...
{code}

This resolver would then be included in the components ClassPathURIResolver and be used as
a fallback if the first resolve fail and the clientUriResolver is not null. 

like this :
{code}
/**
 * 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.camel.component.schematron.processor;

import java.io.File;
import java.io.InputStream;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
import javax.xml.transform.stream.StreamSource;

/**
 * Class path resolver for schematron templates
 */
public class ClassPathURIResolver implements URIResolver {

    private final String rulesDir;
    private final URIResolver clientUriResolver;

    /**
     * Constructor setter for rules directory path.
     */
    public ClassPathURIResolver(final String rulesDir, URIResolver clientUriResolver) {
        this.rulesDir = rulesDir;
        this.clientUriResolver = clientUriResolver;
    }

    @Override
    public Source resolve(String href, String base) throws TransformerException {
        InputStream stream = ClassPathURIResolver.class.getClassLoader()
                .getResourceAsStream(rulesDir.concat(File.separator).concat(href));

        if (null != stream) {
            return new StreamSource(stream);
        } else {
            if (null != clientUriResolver) {
                return clientUriResolver.resolve(href, base);
            } else {
                return new StreamSource(stream);
            }
        }
    }
}

{code}

We use version 2.15.x of camel so i've based my experiments on this version of the component.


was (Author: hutchkintoot):
I'v been trying some things out and found that a possible way to fix this issue is to allow
the user to configure the endpoint with an optional "Client" URIResolver. 

{code:xml}
...
<to id="DD_METS-schematron-validation" uri="schematron:metadata/schematron/identifier_checks.sch?uriResolver=#customUriResolver"/>
...
{code}

This resolver would then be included in the components ClassPathURIResolver and be used as
a fallback if the first resolve fail and the clientUriResolver is not null. 

like this :
{code}
/**
 * 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.camel.component.schematron.processor;

import java.io.File;
import java.io.InputStream;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
import javax.xml.transform.stream.StreamSource;

/**
 * Class path resolver for schematron templates
 */
public class ClassPathURIResolver implements URIResolver {

    private final String rulesDir;
    private final URIResolver clientUriResolver;

    /**
     * Constructor setter for rules directory path.
     */
    public ClassPathURIResolver(final String rulesDir, URIResolver clientUriResolver) {
        this.rulesDir = rulesDir;
        this.clientUriResolver = clientUriResolver;
    }

    @Override
    public Source resolve(String href, String base) throws TransformerException {
        InputStream stream = ClassPathURIResolver.class.getClassLoader()
                .getResourceAsStream(rulesDir.concat(File.separator).concat(href));

        if (null != stream) {
            return new StreamSource(stream);
        } else {
            if (null != clientUriResolver) {
                return clientUriResolver.resolve(href, base);
            } else {
                return new StreamSource(stream);
            }
        }
    }
}

{code}

We use version 2.15.3 of camel so i've based my experiments on this version of the component.

> Schematron component does not work with includes in schematron
> --------------------------------------------------------------
>
>                 Key: CAMEL-8287
>                 URL: https://issues.apache.org/jira/browse/CAMEL-8287
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-schematron
>    Affects Versions: 2.14.1
>            Reporter: Thomas Walzer
>            Assignee: ayache khettar
>            Priority: Minor
>         Attachments: 0001-add-test-for-schematron-with-includes.patch
>
>
> I have a schematron with includes:
>  <pattern>
>       <include href="include/DTr1_ANY.sch"/>
> ....
> </pattern>
> when I run against this schematron I get the following error:
> Recoverable error on line 472 
>   FODC0002: I/O error reported by XML parser processing null: null
> Unable to open referenced included file: include/DTr1_ANY.sch
> Unable to locate id attribute: include/DTr1_ANY.sch
> Recoverable error on line 472 
> There is question with an answer on stackoverflow that seems applicable to me:
> http://stackoverflow.com/questions/7236291/saxon-error-with-xslt-import-statement
> BTW: camel-schematron is not yet a component in JIRA.
> Many thanks in advance!
> Thomas.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message