From df479df6266b41980695671b76f37bad9808d9ab Mon Sep 17 00:00:00 2001 From: akhettar Date: Sun, 29 Dec 2013 21:03:45 +0000 Subject: [PATCH 01/17] first commit --- .../main/java/org/apache/camel/component/fop/FopEndpoint.java | 2 +- components/pom.xml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/components/camel-fop/src/main/java/org/apache/camel/component/fop/FopEndpoint.java b/components/camel-fop/src/main/java/org/apache/camel/component/fop/FopEndpoint.java index 7b291090c1eec..3e53460630e8a 100644 --- a/components/camel-fop/src/main/java/org/apache/camel/component/fop/FopEndpoint.java +++ b/components/camel-fop/src/main/java/org/apache/camel/component/fop/FopEndpoint.java @@ -76,7 +76,7 @@ protected void doStart() throws Exception { if (fopFactory == null) { fopFactory = FopFactory.newInstance(); - } + } if (userConfigURL != null) { InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext().getClassResolver(), userConfigURL); diff --git a/components/pom.xml b/components/pom.xml index 57cc1e4fc2c7b..40b8bb082b3ec 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -14,8 +14,7 @@ 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. ---> - +--> 4.0.0 From 9940a941c19698581c83544668dd3c18cdd5c0ae Mon Sep 17 00:00:00 2001 From: akhettar Date: Thu, 9 Jan 2014 22:12:12 +0000 Subject: [PATCH 02/17] first commit --- components/camel-schematron/README.md | 18 + components/camel-schematron/pom.xml | 123 + .../schematron/SchematronComponent.java | 28 + .../schematron/SchematronEndpoint.java | 76 + .../schematron/SchematronProducer.java | 75 + .../engine/ClassPathURIResolver.java | 29 + .../schematron/engine/SchematronEngine.java | 69 + .../engine/SchematronEngineFactory.java | 106 + .../schematron/engine/TemplatesFactory.java | 84 + .../schematron/engine/URIResolverImp.java | 30 + .../exception/SchematronConfigException.java | 18 + .../SchematronValidationException.java | 17 + .../component/schematron/util/Constants.java | 16 + .../component/schematron/util/Utils.java | 61 + .../org/apache/camel/component/schematron | 1 + .../ExtractSchFromRNG.xsl | 75 + .../ExtractSchFromXSD.xsl | 77 + .../iso_abstract_expand.xsl | 297 +++ .../iso-schematron-xslt1/iso_dsdl_include.xsl | 1509 +++++++++++ .../iso_schematron_message.xsl | 55 + .../iso_schematron_skeleton_for_xslt1.xsl | 1844 +++++++++++++ .../iso_svrl_for_xslt1.xsl | 605 +++++ .../resources/iso-schematron-xslt1/readme.txt | 101 + .../schematron-skeleton-api.htm | 723 ++++++ .../ExtractSchFromRNG-2.xsl | 75 + .../ExtractSchFromXSD-2.xsl | 77 + .../iso-schematron-xslt2/catalog-xslt-2.xml | 17 + .../iso_abstract_expand.xsl | 297 +++ .../iso-schematron-xslt2/iso_dsdl_include.xsl | 1508 +++++++++++ .../iso_schematron_message_xslt2.xsl | 55 + .../iso_schematron_skeleton_for_saxon.xsl | 2299 +++++++++++++++++ .../iso_svrl_for_xslt2.xsl | 684 +++++ .../resources/iso-schematron-xslt2/readme.txt | 100 + .../sch-messages-cs.xhtml | 56 + .../sch-messages-de.xhtml | 57 + .../sch-messages-en.xhtml | 57 + .../sch-messages-fr.xhtml | 54 + .../sch-messages-nl.xhtml | 58 + .../schematron-skeleton-api.htm | 723 ++++++ .../schematron/SchematronComponentTest.java | 69 + .../schematron/SchematronEndpointTest.java | 70 + .../schematron/SchematronProducerTest.java | 51 + .../engine/SchematronEngineTest.java | 56 + .../engine/TemplatesFactoryTest.java | 26 + .../src/test/resources/log4j.properties | 14 + .../resources/result/article-1-result.xml | 18 + .../test/resources/sch/sample-schematron.sch | 14 + .../src/test/resources/xml/article-1.xml | 15 + .../src/test/resources/xml/article-2.xml | 15 + 49 files changed, 12502 insertions(+) create mode 100644 components/camel-schematron/README.md create mode 100644 components/camel-schematron/pom.xml create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronComponent.java create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/ClassPathURIResolver.java create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/URIResolverImp.java create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Constants.java create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java create mode 100644 components/camel-schematron/src/main/resources/META-INF/services/org/apache/camel/component/schematron create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromRNG.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromXSD.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_abstract_expand.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_dsdl_include.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_message.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/readme.txt create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/schematron-skeleton-api.htm create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromRNG-2.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromXSD-2.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/catalog-xslt-2.xml create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_abstract_expand.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_dsdl_include.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_schematron_message_xslt2.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_schematron_skeleton_for_saxon.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_svrl_for_xslt2.xsl create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/readme.txt create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-cs.xhtml create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-de.xhtml create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-en.xhtml create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-fr.xhtml create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-nl.xhtml create mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/schematron-skeleton-api.htm create mode 100644 components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java create mode 100644 components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java create mode 100644 components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java create mode 100644 components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java create mode 100644 components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/TemplatesFactoryTest.java create mode 100644 components/camel-schematron/src/test/resources/log4j.properties create mode 100644 components/camel-schematron/src/test/resources/result/article-1-result.xml create mode 100644 components/camel-schematron/src/test/resources/sch/sample-schematron.sch create mode 100644 components/camel-schematron/src/test/resources/xml/article-1.xml create mode 100644 components/camel-schematron/src/test/resources/xml/article-2.xml diff --git a/components/camel-schematron/README.md b/components/camel-schematron/README.md new file mode 100644 index 0000000000000..7e3b1cd7ac9d7 --- /dev/null +++ b/components/camel-schematron/README.md @@ -0,0 +1,18 @@ +Schematron Component Project +============================ + +This project is a schematron camel component. Schematron is an XML-based language for validating XML instance documents. Schematron is used to make assertions about data in an XML document. Schematron is used to express operational and business rules. +Schematron is an ISO standard. +Use Schematron to verify data interdependencies (co-constraints), check data cardinality, and perform algorithmic checks. A co-constraint is a dependency between data within an XML document or across XML documents. Cardinality refers to the presence or absence of data. An algorithmic check determines data validity by performing an algorithm on the data. + +Schematron Tutorials +====================== + +http://www.schematron.com/spec.html +http://www.xml.com/pub/a/2003/11/12/schematron.html +http://www.data2type.de/en/xml-xslt-xslfo/schematron/ +http://www.mulberrytech.com/papers/schematron-Philly.pdf + +To build this project use + + mvn install diff --git a/components/camel-schematron/pom.xml b/components/camel-schematron/pom.xml new file mode 100644 index 0000000000000..ba8ed8ffebf1b --- /dev/null +++ b/components/camel-schematron/pom.xml @@ -0,0 +1,123 @@ + + + + 4.0.0 + + org.apache.camel + camel-schematron + bundle + 1.0-SNAPSHOT + + Camel schematron Component + http://www.myorganization.org + + + UTF-8 + UTF-8 + + + + + org.apache.camel + camel-core + 2.12.1 + + + + + org.slf4j + slf4j-api + 1.7.5 + + + org.slf4j + slf4j-log4j12 + 1.7.5 + test + + + net.sf.saxon + Saxon-HE + 9.5.1-3 + + + net.sf.saxon + saxon-dom + 8.7 + + + log4j + log4j + 1.2.17 + test + + + commons-io + commons-io + 2.4 + + + commons-lang + commons-lang + 2.6 + + + xmlunit + xmlunit + 1.5 + + + + + org.apache.camel + camel-test + 2.12.1 + test + + + + + + + install + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + 1.6 + 1.6 + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + UTF-8 + + + + + + org.apache.felix + maven-bundle-plugin + 2.3.7 + true + + + org.apache.camel.camel-schematron + org.apache.camel.spi.ComponentResolver;component=schematron + + + + + + + + diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronComponent.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronComponent.java new file mode 100644 index 0000000000000..15f8ae8bfa431 --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronComponent.java @@ -0,0 +1,28 @@ +package org.apache.camel.component.schematron; + +import java.util.Map; + +import org.apache.camel.Endpoint; +import org.apache.camel.impl.DefaultComponent; + +/** + * Represents the component that manages {@link SchematronEndpoint}. + */ +public class SchematronComponent extends DefaultComponent { + + + /** + * Creates the Schematron Endpoint. + * + * @param uri + * @param remaining + * @param parameters + * @return + * @throws Exception + */ + protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { + Endpoint endpoint = new SchematronEndpoint(uri,remaining,this); + setProperties(endpoint, parameters); + return endpoint; + } +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java new file mode 100644 index 0000000000000..08fa72c2d4d78 --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java @@ -0,0 +1,76 @@ +package org.apache.camel.component.schematron; + +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.component.schematron.engine.SchematronEngineFactory; +import org.apache.camel.component.schematron.exception.SchematronConfigException; +import org.apache.camel.impl.DefaultEndpoint; +import org.apache.camel.util.ResourceHelper; +import org.apache.commons.io.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.InputStream; + +/** + * Schematron Endpoint. + */ +public class SchematronEndpoint extends DefaultEndpoint { + + private Logger logger = LoggerFactory.getLogger(SchematronEndpoint.class); + private SchematronEngineFactory factory; + private String remaining; + + public SchematronEndpoint() { + } + + public SchematronEndpoint(String uri, String remaining, SchematronComponent component) { + super(uri, component); + this.remaining = remaining; + } + + public SchematronEndpoint(String endpointUri) { + super(endpointUri); + } + + public Producer createProducer() throws Exception { + return new SchematronProducer(this, factory); + } + + public Consumer createConsumer(Processor processor) throws Exception { + throw new UnsupportedOperationException("Consumer is not implemented for this component"); + } + + public boolean isSingleton() { + return true; + } + + @Override + protected void doStart() throws Exception { + super.doStart(); + + if (factory == null) { + + InputStream rules = null; + try { + // Attempt to read the schematron rules from the class path first. + logger.info("Reading schematron rules from class path {}", remaining); + rules = ResourceHelper.resolveMandatoryResourceAsInputStream + (getCamelContext().getClassResolver(), remaining); + } catch (Exception e) { + // Attempts from the file system. + logger.info("Schamatron rules not found in class path, attempting file system {}", remaining); + rules = FileUtils.openInputStream(new File(remaining)); + } + + if (rules == null) { + logger.error("Schematron rules not found {}", remaining); + throw new SchematronConfigException("Failed to load rules: " + remaining); + } + factory = SchematronEngineFactory.newInstance(rules); + } + + + } +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java new file mode 100644 index 0000000000000..e9c5abf6f4ba4 --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java @@ -0,0 +1,75 @@ +package org.apache.camel.component.schematron; + +import org.apache.camel.Exchange; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.component.schematron.engine.SchematronEngineFactory; +import org.apache.camel.component.schematron.util.Constants; +import org.apache.camel.component.schematron.engine.SchematronEngine; +import org.apache.camel.component.schematron.util.Utils; +import org.apache.camel.impl.DefaultProducer; +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.InputStream; + +/** + * The schematron producer. + */ +public class SchematronProducer extends DefaultProducer { + private static final Logger logger = LoggerFactory.getLogger(SchematronProducer.class); + private SchematronEndpoint endpoint; + private SchematronEngineFactory factory; + + /** + * + * @param endpoint the schematron endpoint. + * @param factory the schematron factory. + */ + public SchematronProducer(SchematronEndpoint endpoint, SchematronEngineFactory factory) { + super(endpoint); + this.endpoint = endpoint; + this.factory = factory; + } + + /** + * Processes the payload. Validates the XML using the SchematronEngine + * + * @param exchange + * @throws Exception + */ + public void process(Exchange exchange) throws Exception { + + String payload = getPayload(exchange); + SchematronEngine engine = factory.newScehamtronEngine(Constants.XSLT_VERSION_2_0); + String report = engine.validate(payload); + + // set the body out + exchange.getOut().setBody(report); + + // set all the incoming headers in the outbound message + exchange.getOut().setHeaders(exchange.getIn().getHeaders()); + Utils.setValidationStatus(report, exchange); + + } + + + + /** + * Gets the body payload either inputStream or String. + * + * @param exchange + * @return + */ + private String getPayload(Exchange exchange) { + Object body = exchange.getIn().getBody(); + try { + return (body instanceof InputStream) ? IOUtils.toString((InputStream) body) : (String) body; + } catch (IOException e) { + logger.error("Unknown payload type: {}", body); + throw new RuntimeCamelException("Unknown payload type", e); + } + } + +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/ClassPathURIResolver.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/ClassPathURIResolver.java new file mode 100644 index 0000000000000..1a2572a972dbc --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/ClassPathURIResolver.java @@ -0,0 +1,29 @@ +package org.apache.camel.component.schematron.engine; + +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; +import javax.xml.transform.URIResolver; +import javax.xml.transform.stream.StreamSource; +import java.io.File; + +/** + * Created by akhettar on 26/12/2013. + */ +public class ClassPathURIResolver implements URIResolver { + + private String RULES_DIR; + + /** + * Constructor setter for rules directory path. + * @param RULES_DIR + */ + public ClassPathURIResolver(final String RULES_DIR) + { + this.RULES_DIR = RULES_DIR; + } + + @Override + public Source resolve(String href, String base) throws TransformerException { + return new StreamSource(ClassLoader.getSystemResourceAsStream(RULES_DIR.concat(File.separator).concat(href))); + } +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java new file mode 100644 index 0000000000000..c70563395705d --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java @@ -0,0 +1,69 @@ +package org.apache.camel.component.schematron.engine; + +import org.apache.camel.component.schematron.exception.SchematronValidationException; +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; + +import javax.xml.transform.*; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamResult; +import java.io.StringWriter; + +/** + * The schematoron Engine. Validates an XML for given scheamtron + * rules using an XSLT implementation of the Schematron Engine. + * + * Created by akhettar on 20/12/2013. + */ +public class SchematronEngine { + + + private Logger logger = LoggerFactory.getLogger(SchematronEngine.class); + private XMLReader reader; + private String rules_dir; + private Templates templates; + + + /** + * Constructor setting the XSLT schematron templates. + * + * @param reader + * @param templates + */ + public SchematronEngine(XMLReader reader, String rules_dir, Templates templates) { + this.reader = reader; + this.rules_dir = rules_dir; + this.templates = templates; + } + + + /** + * Validates the given XML for given Rules. + * + * @param xml + * @return + */ + public String validate(final String xml) + { + + try { + final Source source = new SAXSource(reader, new InputSource(IOUtils.toInputStream(xml))); + final StringWriter writer = new StringWriter(); + final Result result = new StreamResult(writer); + final Transformer transformer = templates.newTransformer(); + transformer.setURIResolver(new URIResolverImp(rules_dir)); + transformer.transform(source, result); + return writer.toString(); + + } catch (TransformerException e) { + logger.error(e.getMessage()); + throw new SchematronValidationException("Failed to apply schematron validation transform", e); + + } + } + + +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java new file mode 100644 index 0000000000000..470a0efc93d2b --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java @@ -0,0 +1,106 @@ +package org.apache.camel.component.schematron.engine; + +import com.sun.org.apache.xerces.internal.util.XMLCatalogResolver; +import org.apache.camel.component.schematron.exception.SchematronConfigException; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.EntityResolver; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.Templates; +import java.io.InputStream; + +/** + * Created by akhettar on 22/12/2013. + */ +public final class SchematronEngineFactory { + + private Logger logger = LoggerFactory.getLogger(SchematronEngineFactory.class); + private static SchematronEngineFactory INSTANCE = new SchematronEngineFactory(); + private static final String SCHEMATRON_XSLT_DIR = "iso-schematron-xslt2//"; + private static String catalog; + private static String rules_dir; + private static Templates templates; + + + /** + * Singleton instance + * + * @return + */ + public static SchematronEngineFactory newInstance(final InputStream rules) { + templates = TemplatesFactory.newInstance(rules).newTemplates(); + return INSTANCE; + } + + /** + * Singleton instance for given catalogs and rule directory. + * + * @param catalogs + * @return + */ + public static SchematronEngineFactory newInstance(final String catalogs, final String ruleDir) { + catalog = catalog; + rules_dir = ruleDir; + return INSTANCE; + } + + /** + * Creates an instance of SchematronEngine + * + * @param version the XSLT version implementation of the schamtron rules. + * @return + */ + public SchematronEngine newScehamtronEngine(final String version) { + //TODO provide support for both xslt 1 and xslt2 + try { + + EntityResolver resolver = catalog == null ? null : getResolver(catalog); + return new SchematronEngine(getXMLReader(resolver), rules_dir, templates); + } catch (ParserConfigurationException e) { + logger.error("Failed to parse the configuration file"); + throw new SchematronConfigException(e); + } catch (SAXException e) { + logger.error("Failed to parse the configuration file"); + throw new SchematronConfigException(e); + } + } + + /** + * @param resolver + * @return + * @throws ParserConfigurationException + * @throws SAXException + */ + private XMLReader getXMLReader(EntityResolver resolver) throws ParserConfigurationException, SAXException { + final SAXParserFactory fac = SAXParserFactory.newInstance(); + fac.setValidating(false); + final SAXParser parser = fac.newSAXParser(); + XMLReader reader = parser.getXMLReader(); + if (resolver != null) + { + reader.setEntityResolver(resolver); + } + return reader; + } + + /** + * Creates an instance of Entity Resolver from given catalog. + * + * @param catlogs + * @return + */ + private EntityResolver getResolver(String catlogs) { + + XMLCatalogResolver resolver = new XMLCatalogResolver(StringUtils.split(catlogs, ",")); + resolver.setPreferPublic(true); + return resolver; + + } + +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java new file mode 100644 index 0000000000000..73e879a2db8cd --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java @@ -0,0 +1,84 @@ +package org.apache.camel.component.schematron.engine; + +import net.sf.saxon.lib.FeatureKeys; +import org.apache.camel.component.schematron.exception.SchematronConfigException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Node; + +import javax.xml.transform.*; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamSource; +import java.io.File; +import java.io.InputStream; + +/** + * Created by akhettar on 20/12/2013. + */ +public final class TemplatesFactory { + + + private Logger logger = LoggerFactory.getLogger(TemplatesFactory.class); + private static TemplatesFactory fac; + private static final String ROOT_DIR = "iso-schematron-xslt2"; + private static final String[] PIPELINE = new String[]{"iso_dsdl_include.xsl", "iso_abstract_expand.xsl", "iso_svrl_for_xslt2.xsl"}; + private Templates templates; + + + /** + * Creates singleton instance of the templates factory + * + * @param rules the path to the rules file: can be either class or file based path. + * @return + */ + public static TemplatesFactory newInstance(InputStream rules) { + + if (fac != null) { + return fac; + } + return new TemplatesFactory(rules); + } + + /** + * private constructor. + * + * @param rules + */ + private TemplatesFactory(InputStream rules) { + + // create new instance. + TransformerFactory fac = TransformerFactory.newInstance(); + fac.setURIResolver(new ClassPathURIResolver(ROOT_DIR)); + fac.setAttribute(FeatureKeys.LINE_NUMBERING, true); + Node node = null; + Transformer t = null; + Source source = new StreamSource(rules); + try { + for (String template : PIPELINE) { + Source xsl = new StreamSource(ClassLoader.getSystemResourceAsStream(ROOT_DIR.concat(File.separator).concat(template))); + t = fac.newTransformer(xsl); + DOMResult result = new DOMResult(); + t.transform(source, result); + source = new DOMSource(node = result.getNode()); + } + templates = fac.newTemplates(new DOMSource(node)); + } catch (TransformerConfigurationException e) { + logger.error(e.getMessage(), e); + throw new SchematronConfigException(e); + } catch (TransformerException e) { + logger.error(e.getMessage(), e); + throw new SchematronConfigException(e); + } + + } + + /** + * Returns an instance of compiled schematron templates. + * + * @return + */ + public Templates newTemplates() { + return templates; + } +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/URIResolverImp.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/URIResolverImp.java new file mode 100644 index 0000000000000..d99be1ce814bb --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/URIResolverImp.java @@ -0,0 +1,30 @@ +package org.apache.camel.component.schematron.engine; + +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; +import javax.xml.transform.URIResolver; +import javax.xml.transform.stream.StreamSource; +import java.io.File; + +/** + * Created by akhettar on 22/12/2013. + */ +public class URIResolverImp implements URIResolver { + + + private String RULES_DIR; + + /** + * Constructor setter for rules directory path. + * @param RULES_DIR + */ + public URIResolverImp(final String RULES_DIR) + { + this.RULES_DIR = RULES_DIR; + } + + @Override + public Source resolve(String href, String base) throws TransformerException { + return new StreamSource(new File(RULES_DIR.concat(File.separator).concat(href))); + } +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java new file mode 100644 index 0000000000000..6b35fd4cec598 --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java @@ -0,0 +1,18 @@ +package org.apache.camel.component.schematron.exception; + +import org.apache.camel.RuntimeCamelException; + +import javax.xml.transform.TransformerConfigurationException; + +/** + * Created by akhettar on 22/12/2013. + */ +public class SchematronConfigException extends RuntimeCamelException { + public SchematronConfigException(Throwable e) { + super(e); + } + + public SchematronConfigException(String message) { + super(message); + } +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java new file mode 100644 index 0000000000000..06e435f1b1cc1 --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java @@ -0,0 +1,17 @@ +package org.apache.camel.component.schematron.exception; + +import org.apache.camel.RuntimeCamelException; + +/** + * SchematronValidationException is thrown if option is set to true. + * + * Created by akhettar on 25/12/2013. + */ +public class SchematronValidationException extends RuntimeCamelException { + + + public SchematronValidationException(final String message, Throwable e) + { + super(message,e); + } +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Constants.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Constants.java new file mode 100644 index 0000000000000..e0a1181aaf532 --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Constants.java @@ -0,0 +1,16 @@ +package org.apache.camel.component.schematron.util; + +/** + * Utility class defining all constants needed for the schematron component. + * + * Created by akhettar on 29/12/2013. + */ +public final class Constants { + + public static final String XSLT_VERSION_2_0 = "2.0"; + public static final String VALIDATION_STATUS = "CamelSchematronStatus"; + public static final String HTTP_PURL_OCLC_ORG_DSDL_SVRL = "http://purl.oclc.org/dsdl/svrl"; + public static final String FAILED_ASSERT = "failed-assert"; + public static final String FAILED = "FAILED" ; + public static final String SUCCESS = "SUCCESS" ; +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java new file mode 100644 index 0000000000000..5ed628191d849 --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java @@ -0,0 +1,61 @@ +package org.apache.camel.component.schematron.util; + +import org.apache.camel.Exchange; +import org.apache.camel.RuntimeCamelException; +import org.apache.commons.lang.StringUtils; +import org.custommonkey.xmlunit.SimpleNamespaceContext; +import org.custommonkey.xmlunit.XMLUnit; +import org.custommonkey.xmlunit.XpathEngine; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; + +/** + * Utility Class. + *

+ * Created by akhettar on 29/12/2013. + */ +public final class Utils { + + private static final Logger logger = LoggerFactory.getLogger(Utils.class); + + + /** + * Evaluate an XPATH expression. + * + * @param xpath + * @param xml + * @return + */ + public static String evaluate(final String xpath, final String xml) { + Map m = new HashMap(); + m.put("svrl", Constants.HTTP_PURL_OCLC_ORG_DSDL_SVRL); + + org.custommonkey.xmlunit.NamespaceContext ctx = new SimpleNamespaceContext(m); + XpathEngine xpathEngine = XMLUnit.newXpathEngine(); + xpathEngine.setNamespaceContext(ctx); + + try { + return xpathEngine.evaluate(xpath, XMLUnit.buildControlDocument(xml)); + } catch (Exception e) { + logger.error("Failed to apply xpath {} on xml {}", xpath, xml); + throw new RuntimeCamelException(e); + } + } + + /** + * Sets schematron validation header status for given report. + * + * @param report + * @param exchange + */ + public static void setValidationStatus(final String report, final Exchange exchange) { + + String status = StringUtils.contains(report, + Constants.FAILED_ASSERT)? Constants.FAILED : Constants.SUCCESS; + logger.info("Schematron validation : {}", status); + exchange.getOut().setHeader(Constants.VALIDATION_STATUS,status); + } +} diff --git a/components/camel-schematron/src/main/resources/META-INF/services/org/apache/camel/component/schematron b/components/camel-schematron/src/main/resources/META-INF/services/org/apache/camel/component/schematron new file mode 100644 index 0000000000000..59b015c490a14 --- /dev/null +++ b/components/camel-schematron/src/main/resources/META-INF/services/org/apache/camel/component/schematron @@ -0,0 +1 @@ +class=org.apache.camel.component.schematron.SchematronComponent diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromRNG.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromRNG.xsl new file mode 100644 index 0000000000000..0f996f40f9a32 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromRNG.xsl @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromXSD.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromXSD.xsl new file mode 100644 index 0000000000000..5857b3ee2fbab --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromXSD.xsl @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_abstract_expand.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_abstract_expand.xsl new file mode 100644 index 0000000000000..f2f1667120aa2 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_abstract_expand.xsl @@ -0,0 +1,297 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Suppressed abstract pattern was here + + + + + + + Start pattern based on abstract + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_dsdl_include.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_dsdl_include.xsl new file mode 100644 index 0000000000000..ad757e24a10a2 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_dsdl_include.xsl @@ -0,0 +1,1509 @@ + + + + + + + + + + true + true + true + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in RELAX NG extRef + include + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + Schema error: Use include to + include fragments, not a whole + schema + + + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + Schema error: Use include to include + fragments, not a whole schema + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + Schema error: Use include to include + fragments, not a whole schema + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + Schema error: Use include to include + fragments, not a whole schema + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in DTLL include + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in CRDL include + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Fatal error: Xinclude href contains fragment + identifier # + + + + + + + Fatal error: Sorry, this software only + supports simple ids in XInclude xpointers + + + + + + + Fatal Error: Impossible URL in XInclude + include + + + + + + + + + + + + + + + + + + + + + + + + + + + Unable to open referenced included file and fallback + file: + + + + + + + Unable to open referenced included file: + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in XLink embedding + link + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XPath error. No XPath. + XPath error. Missing location step. Suggestion: remove '/' before '['. + + + XPath syntax error. Unclosed parenthesis. Suggestion: add ')'. + + XPath syntax error. Extra close parenthesis. Suggestion: remove ')'. + + + XPath syntax error. Unclosed left square bracket. Suggestion: add ']'. + + XPath syntax error. Extra right square bracket. Suggestion: remove ']'. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_message.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_message.xsl new file mode 100644 index 0000000000000..8a273bafb5684 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_message.xsl @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + ( + / + ) + + + \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl new file mode 100644 index 0000000000000..e337cbfdecf94 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl @@ -0,0 +1,1844 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #ALL + + + +false + +true + + + + + true + false + + + + + + + true + false + + + + + + + + + @*| + + * + node() + *|comment()|processing-instruction() + + + + + + + + + +false + + + + + +default + +false + + + +1 + + + + + Schema error: Schematron elements in old and new namespaces found + + + + + + + + + + + + + + + + + Schema error: in the queryBinding attribute, use 'xslt' + + + + + 1.0 + + + + + + + + + This XSLT was automatically generated from a Schematron schema. + + + + + 1.0 + + + + + + + + + + Fail: This implementation of ISO Schematron does not work with + schemas using the "" query language. + + + + + Implementers: please note that overriding process-prolog or process-root is + the preferred method for meta-stylesheets to use where possible. + + + + + + + + + + PHASES + + PROLOG + + KEYS + + DEFAULT RULES + + SCHEMA METADATA + + SCHEMATRON PATTERNS + + + + + + + + + + + + + + + + + + + + + + + Phase Error: no phase with name has been defined. + + + + + + + MODE: SCHEMATRON-SELECT-FULL-PATH + This mode can be used to generate an ugly though full XPath for locators + + + + + + + + + + + + + + + + + + + + + + + + + MODE: SCHEMATRON-FULL-PATH + This mode can be used to generate an ugly though full XPath for locators + + + + + + / + + + + + + [] + + + + *[local-name()=' + ' and namespace-uri()=' + + '] + + + [] + + + + + + + + + + / + + @ + + @*[local-name()=' + + ' and namespace-uri()=' + + '] + + + + + + + + + MODE: SCHEMATRON-FULL-PATH-2 + + This mode can be used to generate prefixed XPath for humans + + + + + + / + + + [ + + ] + + + + + /@ + + + + + MODE: GENERATE-ID-FROM-PATH + + + + + + + + + + + + + + + + + + + + + + . + + + + + + + MODE: SCHEMATRON-FULL-PATH-3 + + + This mode can be used to generate prefixed XPath for humans + (Top-level element has index) + + + + + + / + + + [ + + ] + + + + + /@ + + + + + MODE: GENERATE-ID-2 + + + U + + + U + + + + + U. + + n + + + + + U. + + _ + + _ + + + + + Strip characters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no pattern attribute in <active> + + + + Reference Error: the pattern "" has been activated but is not declared + + + + + + + + Markup Error: no test attribute in <assert + + + ASSERT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no test attribute in <report> + + + + REPORT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no id attribute in <diagnostic> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no rule attribute in <extends> + + + Reference Error: the abstract rule "" has been referenced but is not declared + + + + + + + + + + + + + + Markup Error: no name attribute in <key> + + + Markup Error: no path or use attribute in <key> + + + + + + + + + + + + + + + + Markup Error: no path or use attribute in <key> + + + + + + + + + + + + Schema error: The key element is not in the ISO Schematron namespace. Use the XSLT namespace. + + + + + + + + Schema error: Empty href= attribute for include directive. + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + Schema error: Use include to include fragments, not a whole schema + + + + + + + + + + Schema error: Use include to include fragments, not a whole schema + + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + Schema error: Use include to include fragments, not a whole schema + + + + + + + + + + + Schema error: Use include to include fragments, not a whole schema + + + + + + + + + + Warning: Variables should not be used with the "xpath" query language binding. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no uri attribute in <ns> + + + Markup Error: no prefix attribute in <ns> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + //( + + ( + + ) + | + + ) + [not(self::text())] + + + + + + + + + + + + + Schema implementation error: This schema has abstract patterns, yet they are supposed to be preprocessed out already + + + + + + + + + + PATTERN + + + + + + + + + + + + + + + + + + + + Markup Error: no id attribute in <phase> + + + + + + + + Markup Error: no context attribute in <rule> + + + RULE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no id attribute on abstract <rule> + + + Markup Error: (2) context attribute on abstract <rule> + + + + + + Markup Error: context attribute on abstract <rule> + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no select attribute in <value-of> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Warning: + + must not contain any child elements + + + + + + + + + + + + + + + + + + + + + + + + + Reference error: A diagnostic "" has been referenced but is not declared + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Using the XSLT namespace with a prefix other than "xsl" in + Schematron rules is not supported + in this processor: + + + + + + + + + + + + + + + + + + + + Error: unrecognized element in ISO Schematron namespace: check spelling + and capitalization + + + + + + + + + + + + + Warning: unrecognized element + + + + + + + + + + + + + + + Warning: unrecognized element + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TERMINATING + + + TERMINATING + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TERMINATING + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + title + + + + + + + schema-title + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl new file mode 100644 index 0000000000000..614649f0f32d3 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl @@ -0,0 +1,605 @@ + + + + + + + + + + + + + + + + +true + + + + + + + + + + + #ALL + + +false +true +true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + xslt1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +   +   +   + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TERMINATING + + + TERMINATING + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TERMINATING + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/readme.txt b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/readme.txt new file mode 100644 index 0000000000000..685c92e398e82 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/readme.txt @@ -0,0 +1,101 @@ +

ISO SCHEMATRON 2010

+ +XSLT implementation by Rick Jelliffe with assistance from members of Schematron-love-in maillist. + +2010-04-21 + +Two distributions are available. One is for XSLT1 engines. +The other is for XSLT2 engines, such as SAXON 9. + + +This version of Schematron splits the process into a pipeline of several different XSLT stages. + +1) First, preprocess your Schematron schema with iso_dsdl_include.xsl. +This is a macro processor to assemble the schema from various parts. +If your schema is not in separate parts, you can skip this stage. +This stage also generates error messages for some common XPath syntax problems. + +2) Second, preprocess the output from stage 1 with iso_abstract_expand.xsl. +This is a macro processor to convert abstract patterns to real patterns. +If your schema does not use abstract patterns, you can skip this +stage. + +3) Third, compile the Schematron schema into an XSLT script. +This will typically use iso_svrl_for_xslt1.xsl or iso_svrl_for_xslt2.xsl +(which in turn invoke iso_schematron_skeleton_for_xslt1.xsl or iso_schematron_skeleton_for_saxon.xsl) +However, other "meta-styleseets" are also in common use; the principle of operation is the same. +If your schema uses Schematron phases, supply these as command line/invocation parameters +to this process. + +4) Fourth, run the script generated by stage 3 against the document being validated. +If you are using the SVRL script, then the output of validation will be an XML document. +If your schema uses Schematron parameters, supply these as command line/invocation parameters +to this process. + + +The XSLT2 distribution also features several next generation features, +such as validating multiple documents. See the source code for details. + +Schematron assertions can be written in any language, of course; the file +sch-messages-en.xhtml contains the diagnostics messages from the XSLT2 skeleton +in English, and this can be used as template to localize the skeleton's +error messages. Note that typically programming errors in Schematron are XPath +errors, which requires localized messages from the XSLT engine. + +ANT +--- +To give an example of how to process a document, here is a sample ANT task. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +EXTRACTION SCHEMATRON FROM XSD OR RELAX NG + +The following files allow extracting of embedded schematron patterns +in XML Schemas or RELAX NG schemas. For details, see the at + article http://www.topologi.com/resources/schtrn_xsd_paper.html + +The following files are provided: + ExtractSchFromRNG.xsl Generate a Schematron schema from patterns + embedded in a RELAX NG schema. The schema uses XSLT1. + ExtractSchFromXSD.xsl Generate a Schematron schema from patterns + embedded in a W3C XML Schemas schema. The schema uses XSLT1. + + ExtractSchFromRNG-2.xsl Generate a Schematron schema from patterns + embedded in a RELAX NG schema. The schema uses XSLT2. + ExtractSchFromXSD-2.xsl Generate a Schematron schema from patterns + embedded in a W3C XML Schemas schema. The schema uses XSLT2. \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/schematron-skeleton-api.htm b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/schematron-skeleton-api.htm new file mode 100644 index 0000000000000..af8137783f7e4 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/schematron-skeleton-api.htm @@ -0,0 +1,723 @@ + + + + + The ISO Schematron Skeleton API + + + + + +

API for ISO Schematron Skeleton

+



+

+

Rick Jelliffe, 2010/04/14

+

This document provides documentation on the XSLT API available in +the implementation of Schematron called iso_schematron_skeleton.xsl. +(available in an XSLT1 and XSLT2 version). The API makes available as +much information from the schema, however there may be some edge +cases where it is not exhaustive. +

+

The skeleton is an XSLT script which provides all the basic +parsing and validating routines for compiling a Schematron schema +into XSLT. Schematron was designed to allow many different uses, and +the skeleton gives you a headstart in creating a customized +implementation. You just need to write XSLT templates to override the +default ones. (The program you write is sometimes called a +meta-stylesheet.) It is the meta-stylesheet that is called +as the XSLT script, not the skeleton. There are several +pre-processing stages which the Schematron schema should be processed +through first, to handle such things as include statements and +abstract patterns. +

+

Phases and error reporting for problems in the schema itself are +handled by the skeleton with no interaction with a “meta-stylesheet”. +Note that there is no guarantee that the context node is always the +element being handled: in most cases the only information available +is the information in the parameters. +

+

For an introductory tutorial on using this API, see Bob DuCharme's +Schematron 1.5: +Looking Under the Hood +

+

Superset of API for Schematron 1.5 and 1.6

+

(This is an updated version of the API for the Schematron 1.5 +implementation called skeleton1-5.xsl, which in turn comes +from the new architecture contributed by Oliver Becker for +Schematron 1.3.)

+

The current API contains only additions. Well-written +meta-stylesheets that use the new API will be be able to run on the +existing 1.5 and 1.6 skeletons. Similarly, it should be possible to +upgrade the skeleton from 1.5 or 1.6 to the iso-schematron-skeleton +only by correcting the import statement at the beginning of the +meta-stylsheet. Additions or re-groupings from the 1.5 schema are +shown in red. Deletions have overstrike.

+

Mooted addition: a parameter @action which for specifying +processing instructions on assertions and reports.

+
+

process-prolog

+

The process-prolog template gets called at the start of +the validation session. It has no parameters. The default +implementation is no action.

+
+

process-root

+

The process-root template processes the root element of +the schema (which is not the same thing as the root of the document / +and need not be the document element /*) .

+
+
node-list $contents +
+ string $schemaVersion +
+ The version of the schema, perhaps a datestamp. +
+ "xslt" | "xpath" | + "xslt2" | ... + $queryBinding +
+ The query language binding. +
+ string $title +
+ The title of this schema +
+ "iso" | "1.5" | + "1.6" | ... + $version +
+ The version of Schematron being used. +
+

+Rich properties:

+
+
XML SystemId + $icon +
+ The URI of an icon +
+ XML ID + $id +
+ The unique identifier with the schema for the + schema + element. +
+ SGML FPI + $fpi +
+ The Formal Public Identifier for this schema. +
+ IETF language + $lang +
+ The human language used in this schema, from + xml:lang +
+ URL + $see +
+ Link to documentation on WWW or file +
+ "preserve" | "default" + $space +
+ The value for xml:space +
+

+To print the documentation paragraphs, use <xsl:apply-templates +mode="do-schema-p" />

+

To output the results, use <xsl:copy-of select="$contents" +/>

+
+

process-assert

+

The process-assert template handles asserts whose test +has failed. +

+
+
XPath $test +
+ The test +
+ XML IDREFS $diagnostics +
+ A list of the idrefs diagnostic elements related to the current + assertion +
+ XML NMTOKEN + $flag +
+ The name of a flag that becomes true because + this assertion fails. The flag is true for the document if it is + flagged true on any assertion. For compatability, this parameter + should not be used with Schematron 1.5. +
+

+Rich properties:

+
+
XML SystemId + $icon +
+ The URI of an icon +
+ XML ID + $id +
+ The unique identifier with the schema for the + assert + element. +
+ SGML FPI + $fpi +
+ The Formal Public Identifier for this + assertion. +
+ IETF language + $lang +
+ The human language used in this assertion, + from xml:lang +
+ URL + $see +
+ Link to documentation on WWW or file +
+ "preserve" | "default" + $space +
+ The value for xml:space +
+

+Linking properties:

+
+
XML NMTOKEN + $role +
+ A name for the generic role of this assertion. + The schema creator would have their own vocabulary. +
+ XPath + $subject +
+ A path relative to the current context to some + interesting node considered the subject. +
+

+To print the text contents, use <xsl:apply-templates +mode="text" />

+
+

process-diagnostic

+

The process-diagnostic template handles diagnostic +messages for assert statements that have failed and report +statements that have succeeded. The diagnostics are evaluated in the +context of the rule.

+

Rich properties:

+
+
XML SystemId + $icon +
+ The URI of an icon +
+ XML ID + $id +
+ The unique identifier with the schema for the + assert + element. +
+ SGML FPI + $fpi +
+ The Formal Public Identifier for this + assertion. +
+ IETF language + $lang +
+ The human language used in this assertion, + from xml:lang +
+ URL + $see +
+ Link to documentation on WWW or file +
+ "preserve" | "default" + $space +
+ The value for xml:space +

+
+

process-dir

+

The process-dir template handles bi-directionality +markup, which is only needed by certain human scripts such as Arabic.

+
+
"ltr" or "rtl" or "" + $value +
+ Left-to-right or right-to-left or unspecified +

+
+

process-emph

+

The process-emph template handles the markup of +emphasized text in paragraphs, assertions and diagnostics. It has no +parameters.

+
+

process-message

+

The process-message handles default outputing of text.

+
+
string $pattern +
+ Some text that may be some kind of pattern +
+ string $role +
+ Some text that may be some kind of role +

+
+

process-name

+

The process-name templates handle name strings that can +be used in assertions. asssert and report only +provide name subelements rather than the more general +value-of elements to encourage plain language and generic +descriptions rather than specific diagnostics, for which purpose the +diagnostics elements are used.

+
+
string $name +
+ The name of the current element, or of the node specified by a name + element +

+
+

process-ns

+

The process-ns template reports on ns +declarations, which are used to transmit on namespace information by +the skeleton.

+
+
Namespace NCName $prefix +
+ The prefix of a namespace +
+ XML SystemId $uri +
+ The (internationalized) URI Reference of a namespace +

+
+

process-p

+

The process-p template handles paragraphs.

+
+
XML NMTOKEN $class +
+ An attribute that can be used for stylesheet style +
+ XML ID $id +
+ The unique identifier with the schema for the p element. +
+ XML SystemId $icon +
+ The URI of an icon +
+ IETF Language $lang +
+ The human language used in this paragraph +
+

+To print the text contents, use <xsl:apply-templates +mode="text" /> +

+
+

process-pattern

+

The process-pattern reports on the start of evaluation of +a pattern element.

+
+
string $name +
+ The title of the current pattern +
+ XML NCNAMES $is-a +
+ Empty or not provided if the pattern is not derived from an abstract + pattern. Otherwise the name of the abstract pattern. A list may be + used if there was a sequence of abstract patterns. +
+

+Rich properties:

+
+
XML SystemId + $icon +
+ The URI of an icon +
+ XML ID + $id +
+ The unique identifier with the schema for the + pattern + element. +
+ SGML FPI + $fpi +
+ The Formal Public Identifier for this pattern. + +
+ IETF language + $lang +
+ The human language used in this pattern, from + xml:lang +
+ URL + $see +
+ A (internationalized) URI reference to some + supporting or defining documentation +
+ "preserve" | "default" + $space +
+ The value for xml:space +
+

+To print the documentation contents, use <xsl:apply-templates +mode="do-pattern-p"/>

+
+

process-report

+

The process-report template handles report whose +test has succeeded. +

+
+
XPath $test +
+ The test +
+ XML IDREFS $diagnostics +
+ A list of the diagnostic elements related to the current assertion +
+ XML NMTOKEN + $flag +
+ The name of a flag that becomes true because + this assertion fails. The flag is true for the document if it is + flagged true on any assertion. For compatability, this parameter + should not be used with Schematron 1.5. +
+

+Rich properties:

+
+
XML SystemId + $icon +
+ The URI of an icon +
+ XML ID + $id +
+ The unique identifier with the schema for the + report + element. +
+ SGML FPI + $fpi +
+ The Formal Public Identifier for this report. +
+ IETF language + $lang +
+ The human language used in this report, from + xml:lang +
+ URL + $see +
+ Link to documentation on WWW or file +
+ "preserve" | "default" + $space +
+ The value for xml:space +
+

+Linking properties:

+
+
XML NMTOKEN + $role +
+ A name for the generic role of this assertion. + The schema creator would have their own vocabulary. +
+ XPath + $subject +
+ A path relative to the current context to some + interesting node considered the subject. +
+

+To print the text contents, use <xsl:apply-templates +mode="text" />

+
+

process-rule

+

The process-rule reports that a rule element has +fired: its context attribute matched some nodes. .

+
+
XSLT expression $context +
+ The expression that gives the context of the current +
+

+Rich properties:

+
+
XML SystemId + $icon +
+ The URI of an icon +
+ XML ID + $id +
+ The unique identifier with the schema for this + rule + element. +
+ SGML FPI + $fpi +
+ The Formal Public Identifier for this rule. +
+ IETF language + $lang +
+ The human language used in this rule, from + xml:lang +
+ URL + $see +
+ Link to documentation on WWW or file +
+ "preserve" | "default" + $space +
+ The value for xml:space +
+

+Linking properties:

+
+
XML NMTOKEN + $role +
+ A name for the generic role of this assertion. + The schema creator would have their own vocabulary. +
+ XPath + $subject +
+ A path relative to the current context to some + interesting node considered the subject. +

+
+

process-span

+

The process-span handles span elements, which are generic +elements for styling, like HTML's .

+
+
XML NMTOKEN $class +
+ An attribute that can be used for stylesheet style +

+
+

process-title

+

The process-title handles title elements, which are +generic elements for styling, like HTML's .

+
+
XML NMTOKEN $class +
+ An attribute that can be used for stylesheet style +
+

+By default, titles are handled by invocing process-p with +the parameter class with a value "title".

+
+

process-value-of

+

The process-value-of template handles value-of +elements, which are used in diagnostic messages to allow very +specific hinting .

+
+
XPath $select +
+ The path of some node that will be evaluated and printed.

+
+

Global Parameters

+

There are several global parameters that may be available for use. +However, it is not a requirement to follow these, and implementations +may not supply them with any value. So a test of +string-length(variable) < +0 is appropriate in each case.

+



+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Parameter

+
+

Value

+
+

Description

+
+

allow-foreign

+
+

"true" | "false" (default) +

+
+

Pass non-Schematron elements to the generated + stylesheet. Pass the Schematron elements span, emph and dir: to + the output SVRL. +

+
+

fileNameParameter

+
+

string

+
+

A parameter passed to the Validator and + potentially available as a variable in Schematron schemas as + $fileNameParameter

+
+

fileDirParameter

+
+

string

+
+

A parameter passed to the Validator and + potentially available as a variable in Schematron schemas as + $fileDirParameter

+
+

archiveNamePaameter

+
+

string

+
+

A parameter passed to the Validator and + potentially available as a variable in Schematron schemas as + $archiveNameParameter

+
+

archiveDirParameter

+
+

string

+
+

A parameter passed to the Validator and + potentially available as a variable in Schematron schemas as + $archivePathParameter

+
+

debug +

+
+

true” | “false” (default)

+
+

Verbose error messages (Note this may be + superceded by “verbose” at some stage in the future.)

+
+

generate-paths

+
+

true|false +

+
+

generate the SVRL @location attribute with XPaths

+
+

diagnose

+
+

yes | no +

+
+

Add the diagnostics to the assertion results

+
+

terminate

+
+

yes | no | true | false | assert +

+
+

Terminate on the first failed assertion or + successful report

+
+

message-newline +

+
+

"true" (default) | "false" +

+
+

Generate an extra newline at the end of messages

+
+

output-encoding

+
+

string

+
+

The encoding used for output, for example if the + output is XML

+
+
+
+
+ + \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromRNG-2.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromRNG-2.xsl new file mode 100644 index 0000000000000..38d2d8e4e3784 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromRNG-2.xsl @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromXSD-2.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromXSD-2.xsl new file mode 100644 index 0000000000000..7d1cbfbc7dc52 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromXSD-2.xsl @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/catalog-xslt-2.xml b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/catalog-xslt-2.xml new file mode 100644 index 0000000000000..cd093f1c5a5f1 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/catalog-xslt-2.xml @@ -0,0 +1,17 @@ + + + + + + catalog.xml: + + + + + \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_abstract_expand.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_abstract_expand.xsl new file mode 100644 index 0000000000000..f2f1667120aa2 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_abstract_expand.xsl @@ -0,0 +1,297 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Suppressed abstract pattern was here + + + + + + + Start pattern based on abstract + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_dsdl_include.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_dsdl_include.xsl new file mode 100644 index 0000000000000..d58f191f4e21c --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_dsdl_include.xsl @@ -0,0 +1,1508 @@ + + + + + + + + + + true + true + true + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in RELAX NG extRef + include + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + Schema error: Use include to + include fragments, not a whole + schema + + + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + Schema error: Use include to include + fragments, not a whole schema + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + Schema error: Use include to include + fragments, not a whole schema + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + Schema error: Use include to include + fragments, not a whole schema + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in DTLL include + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in CRDL include + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Fatal error: Xinclude href contains fragment + identifier # + + + + + + + Fatal error: Sorry, this software only + supports simple ids in XInclude xpointers + + + + + + + Fatal Error: Impossible URL in XInclude + include + + + + + + + + + + + + + + + + + + + + + + + + + + + Unable to open referenced included file and fallback + file: + + + + + + + Unable to open referenced included file: + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in XLink embedding + link + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XPath error. No XPath. + XPath error. Missing location step. Suggestion: remove '/' before '['. + + + XPath syntax error. Unclosed parenthesis. Suggestion: add ')'. + + XPath syntax error. Extra close parenthesis. Suggestion: remove ')'. + + + XPath syntax error. Unclosed left square bracket. Suggestion: add ']'. + + XPath syntax error. Extra right square bracket. Suggestion: remove ']'. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_schematron_message_xslt2.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_schematron_message_xslt2.xsl new file mode 100644 index 0000000000000..36082cc4d1910 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_schematron_message_xslt2.xsl @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + ( + / + ) + + + \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_schematron_skeleton_for_saxon.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_schematron_skeleton_for_saxon.xsl new file mode 100644 index 0000000000000..af0c843fdec09 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_schematron_skeleton_for_saxon.xsl @@ -0,0 +1,2299 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #ALL + + + +false + +true + + + + + true + false + + + + + + + true + false + + + + + + + + + @*| + + * + node() + *|comment()|processing-instruction() + + + + + + + + + + +false + + +default + + +1 + +false + + + + + + 1 + + + + + + + + + + + + + + + + + 2 + + + + + + 1.0 + + + + + + + + + This XSLT was automatically generated from a Schematron schema. + + + + + 1.0 + + + + + + + + + + + + 2.0 + + + + + + + + + + 3a + + 3b + + + + + Implementers: please note that overriding process-prolog or process-root is + the preferred method for meta-stylesheets to use where possible. + + + + + + + + + + + + PHASES + + PROLOG + + XSD TYPES FOR XSLT2 + + KEYS AND FUNCTIONS + + DEFAULT RULES + + SCHEMA SETUP + + SCHEMATRON PATTERNS + + + + + + + + + + + + + + + + + + + + + + + + 4a + + 4b + + + + + + + MODE: SCHEMATRON-SELECT-FULL-PATH + This mode can be used to generate an ugly though full XPath for locators + + + + + + + + + + + + + + + + + + + + + + + + + MODE: SCHEMATRON-FULL-PATH + This mode can be used to generate an ugly though full XPath for locators + + + + + + / + + + + *: + + [namespace-uri()=' + + '] + + + + [ + + ] + + + + + + / + + + + + + [] + + + + *[local-name()=' + + '] + + + [] + + + + + + + + + + + + + + + / + + @ + + @*[local-name()=' + + ' and namespace-uri()=' + + '] + + + + + + + / + + @ + + @*[local-name()=' + + ' and namespace-uri()=' + + '] + + + + + + + + + + MODE: SCHEMATRON-FULL-PATH-2 + + This mode can be used to generate prefixed XPath for humans + + + + + + / + + + [ + + ] + + + + + /@ + + + + + MODE: SCHEMATRON-FULL-PATH-3 + + + This mode can be used to generate prefixed XPath for humans + (Top-level element has index) + + + + + + / + + + [ + + ] + + + + + /@ + + + + + MODE: GENERATE-ID-FROM-PATH + + + + + + + + + + + + + + + + + + + + + + . + + + + + + + + MODE: GENERATE-ID-2 + + + U + + + U + + + + + U. + + n + + + + + U. + + _ + + _ + + + + + Strip characters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + + + + 6a + + 6b + + + + + + + + 7 + + + ASSERT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 8 + + + + REPORT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 9 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 10 + + + + 11a + + 11b + + + + + + + + + + + + + + + + + + + + + + 12 + + + 13 + + + + + + + + + + + + + + + + 14 + + + + + + + + + + + + 15 + + + + + + 16 + + + + + + + + 17 + + + + + + + + + 18 + + + + + + + + + + + + + + 19 + + + + + + + + 20a + + 20b + + + + 21 + + + + + + + + + + + + 20a + + 20b + + + + 21 + + + + + + + + + + + + + + + 19 + + + + + + + 21 + + + + + + + + + + + 21 + + + + + + + + + + + + + + + + 22 + + + + + + + + + 23 + + + + + + 24 + + + 25 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 26 + + + 27 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + //( + + ( + + ) + | + + ) + [not(self::text())] + + + + + + + + + //( + + ( + + ) + | + + ) + [not(self::text())] + + + + + + + + + + + + + + + + + + + + + + + 28 + + + + + + + + PATTERN + + + + + + + + + + + + + + + + + + + + 29 + + + + + + + + + + No property found with that ID + + + + + + + + + + + + + + + + + + + + + + + + + + 30 + + + + + RULE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 31 + + + 32 + + + + + + 33 + + + + + + + + + + + + + + + + + + + + + + + + + + + 34 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 35a + + 35b + + + + + + + + + + + + + + + + + + + + + + + + + 36a + + 36b + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 36a + + 36b + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 37a + + 37b + + + + + + + + + + + + + + + + + + + 38a + + 38b + + + + + + + + + + + + 39a + + 39b + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TERMINATING + + + TERMINATING + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TERMINATING + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + title + + + + + + + schema-title + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Schema error: Schematron elements in old and new namespaces found + Schema error: in the queryBinding attribute, use 'xslt' + Fail: This implementation of ISO Schematron does not work with schemas using the query language + + Phase Error: no phase has been defined with name + + Markup Error: no pattern attribute in <active> + Reference Error: the pattern " + " has been activated but is not declared + Markup Error: no test attribute in <assert + Markup Error: no test attribute in <report> + Markup Error: no id attribute in <diagnostic> + Markup Error: no rule attribute in <extends> + Reference Error: the abstract rule " + " has been referenced but is not declared + Markup Error: no name attribute in <key> + Markup Error: no path or use attribute in <key> + Markup Error: no path or use attribute in <key> + Schema error: The key element is not in the ISO Schematron namespace. Use the XSLT namespace. + Markup Error: no name attribute in <function> + Schema error: The function element is not in the ISO Schematron namespace. Use the XSLT namespace. + Schema error: Empty href= attribute for include directive. + Error: Impossible URL in Schematron include + Unable to open referenced included file: + + Schema error: Use include to include fragments, not a whole schema + Schema error: XSD schemas may only be imported if you are using the 'xslt2' query language binding + Schema error: The import-schema element is not available in the ISO Schematron namespace. Use the XSLT namespace. + Warning: Variables should not be used with the "xpath" query language binding. + Warning: Variables should not be used with the "xpath2" query language binding. + Markup Error: no uri attribute in <ns> + Markup Error: no prefix attribute in <ns> + Schema implementation error: This schema has abstract patterns, yet they are supposed to be preprocessed out already + Markup Error: no id attribute in <phase> + Markup Error: no context attribute in <rule> + Markup Error: no id attribute on abstract <rule> + Markup Error: (2) context attribute on abstract <rule> + Markup Error: context attribute on abstract <rule> + Markup Error: no select attribute in <value-of> + Warning: + must not contain any child elements + Reference error: A diagnostic " + " has been referenced but is not declared + Using the XSLT namespace with a prefix other than "xsl" in Schematron rules is not supported in this processor: + + Error: unrecognized element in ISO Schematron namespace: check spelling and capitalization + + Warning: unrecognized element + + + + + + diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_svrl_for_xslt2.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_svrl_for_xslt2.xsl new file mode 100644 index 0000000000000..2e8d8da68cf8b --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_svrl_for_xslt2.xsl @@ -0,0 +1,684 @@ + + + + + + + + + + + + + + + +true +true + + + + + + + + + + + #ALL + + +false +true +true + + + + +false + + +default + + + + +1 + + + + + + + + + + + + + + + + + + + + + + + + xslt1 + + + + + + + + + + + + + + + + + +   +   +   + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TERMINATING + + + TERMINATING + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TERMINATING + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/readme.txt b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/readme.txt new file mode 100644 index 0000000000000..5ce57c9eca254 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/readme.txt @@ -0,0 +1,100 @@ +

ISO SCHEMATRON 2010

+ +XSLT implementation by Rick Jelliffe with assistance from members of Schematron-love-in maillist. + +2010-04-14 + +Two distributions are available. One is for XSLT1 engines. +The other is for XSLT2 engines, such as SAXON 9. + + +This version of Schematron splits the process into a pipeline of several different XSLT stages. + +1) First, preprocess your Schematron schema with iso_dsdl_include.xsl. +This is a macro processor to assemble the schema from various parts. +If your schema is not in separate parts, you can skip this stage. + +2) Second, preprocess the output from stage 1 with iso_abstract_expand.xsl. +This is a macro processor to convert abstract patterns to real patterns. +If your schema does not use abstract patterns, you can skip this +stage. + +3) Third, compile the Schematron schema into an XSLT script. +This will typically use iso_svrl_for_xslt1.xsl or iso_svrl_for_xslt2.xsl +(which in turn invoke iso_schematron_skeleton_for_xslt1.xsl or iso_schematron_skeleton_for_saxon.xsl) +However, other "meta-styleseets" are also in common use; the principle of operation is the same. +If your schema uses Schematron phases, supply these as command line/invocation parameters +to this process. + +4) Fourth, run the script generated by stage 3 against the document being validated. +If you are using the SVRL script, then the output of validation will be an XML document. +If your schema uses Schematron parameters, supply these as command line/invocation parameters +to this process. + + +The XSLT2 distribution also features several next generation features, +such as validating multiple documents. See the source code for details. + +Schematron assertions can be written in any language, of course; the file +sch-messages-en.xhtml contains the diagnostics messages from the XSLT2 skeleton +in English, and this can be used as template to localize the skeleton's +error messages. Note that typically programming errors in Schematron are XPath +errors, which requires localized messages from the XSLT engine. + +ANT +--- +To give an example of how to process a document, here is a sample ANT task. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +EXTRACTION SCHEMATRON FROM XSD OR RELAX NG + +The following files allow extracting of embedded schematron patterns +in XML Schemas or RELAX NG schemas. For details, see the at + article http://www.topologi.com/resources/schtrn_xsd_paper.html + +The following files are provided: + ExtractSchFromRNG.xsl Generate a Schematron schema from patterns + embedded in a RELAX NG schema. The schema uses XSLT1. + ExtractSchFromXSD.xsl Generate a Schematron schema from patterns + embedded in a W3C XML Schemas schema. The schema uses XSLT1. + + ExtractSchFromRNG-2.xsl Generate a Schematron schema from patterns + embedded in a RELAX NG schema. The schema uses XSLT2. + ExtractSchFromXSD-2.xsl Generate a Schematron schema from patterns + embedded in a W3C XML Schemas schema. The schema uses XSLT2. \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-cs.xhtml b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-cs.xhtml new file mode 100644 index 0000000000000..93e181c8b9a59 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-cs.xhtml @@ -0,0 +1,56 @@ + + + Chyba ve schématu: nalezeny elementy Schematronu ve starém i novém jmenném prostoru + Chyba ve schématu: v atributu queryBinding použijte 'xslt' + Porucha: Tato implementace ISO Schematronu nefunguje se schématy, která používají dotazovací jazyk + + Fázová chyba: fáze jménem + není definována. + Chybný markup: v elementu <active> chybí atribut pattern + Chybný odkaz: vzor " + " byl aktivován, ne však deklarován + Chybný markup: v elementu <assert> chybí atribut test + Chybný markup: v elementu <report> chybí atribut test + Chybný markup: v elementu <diagnostic> chybí atribut id + Chybný markup: v elementu <extends> chybí atribut rule + Chybný odkaz: abstraktní pravidlo " + " není definováno, ačkoli se na ně odkazuje + Chybný markup: v elementu <key> chybí atribut name + Chybný markup: v elementu <key> chybí atribut path nebo use + Chybný markup: v elementu <key> chybí atribut path nebo use + Chyba ve schématu: element <key> není ve jmenném prostoru ISO Schematronu. Použijte jmenný prostor XSLT. + Chybný markup: v elementu <function> chybí atribut name + Chyba ve schématu: element <function> není ve jmenném prostoru ISO Schematronu. Použijte jmenný prostor XSLT. + Chyba ve schématu: direktiva <include> má prázdný atribut href + Chyba: Nesprávné URL v direktivě <include> + Chyba: Nelze otevřít vkládaný soubor + + Chyba ve schématu: <include> používejte ke vkládání fragmentů, ne celého schématu + Chyba ve schématu: Schémata XSD lze importovat pouze pokud používáte dotazovací jazyk "xslt2" + Chyba ve schématu: element <import-schema> není ve jmenném prostoru ISO Schematronu. Použijte jmenný prostor XSLT. + Varování: S dotazovacím jazykem "xpath" by se neměly používat proměnné + Varování: S dotazovacím jazykem "xpath2" by se neměly používat proměnné + Chybný markup: v elementu <ns> chybí atribut uri + Chybný markup: v elementu <ns> chybí atribut prefix + Chyba v implementaci schématu: toto schéma obsahuje abstraktní vzory, které však již měly být předchozím zpracováním odstraněny + Chybný markup: v elementu <phase> chybí atribut id + Chybný markup: v elementu <rule> chybí atribut context + Chybný markup: v abstraktním pravidlu chybí atribut id + Chybný markup: (2) Abstraktní pravidlo nesmí mít atribut context + Chybný markup: Abstraktní pravidlo nesmí mít atribut context + Chybný markup: v elementu <value-of> chybí atribut select + Varování: + nesmí obsahovat žádné podelementy + Chybný odkaz: Diagnostika " + " nebyla deklarována, ačkoli se na ni odkazuje + Chyba: procesor + nepodporuje použití jmenného prostoru XSLT s jiným prefixem než "xsl" + Chyba: neznámý element + ve jmenném prostoru ISO Schematronu: zkontrolujte, je-li správně zapsán + Varování: neznámý element + + + diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-de.xhtml b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-de.xhtml new file mode 100644 index 0000000000000..51caeb107f3b0 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-de.xhtml @@ -0,0 +1,57 @@ + + + + Fehler im Schema: Schematron Elemente sowohl im alten als auch neuen Namensraum gefunden + Fehler im Schema: Nutzen Sie 'xslt' im queryBinding-Attribut + Fehler: Diese Implementierung von ISO Schematron arbeitet nicht mit Schemas zusammen, die die Query Language + nutzen + Phasenfehler: Es gibt keine Phase mit Namen + + Fehler in der Annotation: Kein Attribut pattern in <active> + Referenzierungsfehler: Der Ausdruck " + " wurde aktiviert, ist aber nicht deklariert + Fehler in der Annotation: Kein Attribut test in <assert + Fehler in der Annotation: Kein Attribut test <report> + Fehler in der Annotation: Kein Attribut id in <diagnostic> + Fehler in der Annotation: Kein Attribut rule in <extends> + Referenzierungsfehler: Die abstrakte Regel " + " wurde referenziert, ist aber nicht deklariert + Fehler in der Annotation: Kein Attribut name in <key> + Fehler in der Annotation: Kein Attribut path oder use in <key> + Fehler in der Annotation: Kein Attribut path oder use in <key> + Fehler im Schema: Das Element key ist im ISO Schematron-Namensraum nicht vorhanden. Benutzen Sie den XSLT-Namensraum. + Fehler in der Annotation: Kein Attribut name in <function> + Fehler im Schema: Das Element function ist im ISO Schematron-Namensraum nicht vorhanden. Benutzen Sie den XSLT-Namensraum. + Fehler im Schema: Leeres Attribut href= für include Anweisung. + Fehler: Ungültige URL in Schematron include + Kann die referenzierte Datei nicht öffnen: + + Fehler im Schema: include darf nur zur Einbettung von Schemafragmenten genutzt werden, nicht für ganze Schemata + Fehler im Schema: XSD Schemata dürfen nur importiert werden, wenn das 'xslt2' Query Language Binding genutzt wird + Fehler im Schema: Das Element import-schema ist im ISO Schematron-Namensraum nicht vorhanden. Benutzen Sie den XSLT-Namensraum. + Warnung: Variablen sollten nicht zusammen mit dem "xpath" Query Language Binding genutzt werden. + Warnung: Variablen sollten nicht zusammen mit dem "xpath2" Query Language Binding genutzt werden. + Fehler in der Annotation: Fehlendes Attiribut uri in <ns> + Fehler in der Annotation: Fehlendes Attribut prefix in <ns> + Fehler bei der Schemaimplementierung: Dieses Schema enthält abstrakte Mustervergleiche, die bereits vorverarbeitet sein sollten. + Fehler in der Annotation: Fehlendes Attiribut id in <phase> + Fehler in der Annotation: Fehlendes Attiribut context in <rule> + Fehler in der Annotation: Fehlendes Attiribut id on abstract <rule> + Fehler in der Annotation: (2) context attribute on abstract <rule> + Fehler in der Annotation: Attribut context bei abstrakter <rule> + Fehler in der Annotation: Fehlendes Attiribut select in <value-of> + Warnung: + darf keine Kindelemente beinhalten + Referenzierungsfehler: Ein diagnostic-Element " + " wurde referenziert, ist aber nicht deklariert + Der Gebrauch des XSLT-Namensraums mit einem anderen Präfix als "xsl" in Schematron-Regeln wird von diesem Prozessor nicht unterstützt: + + Fehler: Unbekanntes Element im ISO Schematron-Namensraum: Überprüfen Sie die Schreibweise (inkl. Groß- und Kleinschreibung) + + Warnung: Unbekanntes Element + + diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-en.xhtml b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-en.xhtml new file mode 100644 index 0000000000000..6f777ed2b5646 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-en.xhtml @@ -0,0 +1,57 @@ + + + + Schema error: Schematron elements in old and new namespaces found + Schema error: in the queryBinding attribute, use 'xslt' + Fail: This implementation of ISO Schematron does not work with schemas using the query language + + Phase Error: no phase has been defined with name + + Markup Error: no pattern attribute in <active> + Reference Error: the pattern " + " has been activated but is not declared + Markup Error: no test attribute in <assert> + Markup Error: no test attribute in <report> + Markup Error: no id attribute in <diagnostic> + Markup Error: no rule attribute in <extends> + Reference Error: the abstract rule " + " has been referenced but is not declared + Markup Error: no name attribute in <key> + Markup Error: no path or use attribute in <key> + Markup Error: no path or use attribute in <key> + Schema error: The <key> element is not in the ISO Schematron namespace. Use the XSLT namespace. + Markup Error: no name attribute in <function> + Schema error: The <function> element is not in the ISO Schematron namespace. Use the XSLT namespace. + Schema error: Empty href attribute for <include> directive. + Error: Impossible URL in Schematron <include> + Error: Unable to open referenced included file: + + Schema error: Use <include> to include fragments, not a whole schema + Schema error: XSD schemas may only be imported if you are using the 'xslt2' query language binding + Schema error: The <import-schema> element is not available in the ISO Schematron namespace. Use the XSLT namespace. + Warning: Variables should not be used with the "xpath" query language binding. + Warning: Variables should not be used with the "xpath2" query language binding. + Markup Error: no uri attribute in <ns> + Markup Error: no prefix attribute in <ns> + Schema implementation error: This schema has abstract patterns, yet they are supposed to be preprocessed out already + Markup Error: no id attribute in <phase> + Markup Error: no context attribute in <rule> + Markup Error: no id attribute on abstract <rule> + Markup Error: (2) context attribute on abstract <rule> + Markup Error: context attribute on abstract <rule> + Markup Error: no select attribute in <value-of> + Warning: + must not contain any child elements + Reference error: A diagnostic " + " has been referenced but is not declared + Warning: Using the XSLT namespace with a prefix other than "xsl" in Schematron rules is not supported in this processor: + + Error: unrecognized element in ISO Schematron namespace: check spelling and capitalization + + Warning: unrecognized element + + \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-fr.xhtml b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-fr.xhtml new file mode 100644 index 0000000000000..a797db7bf372c --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-fr.xhtml @@ -0,0 +1,54 @@ + + + Erreur de schema: éléments Schematron à la fois dans l'ancien et le nouveau namespace + Erreur de schema: utilisez 'xslt' dans l'attribut queryBinding + Échec: Cette implémentation de Schematron ISO ne fonctionne pas avec des schemas utilisant le langage de query + + Erreur de phase: aucune phase n'a été définie avec le nom + + Erreur de balisage: pas d'attribut pattern dans <active> + Erreur de référence: le pattern " + " a été activé mais n'a pas été décalaré + Erreur de balisage: pas d'attribut test dans <assert> + Erreur de balisage: pas d'attribut test dans <report> + Erreur de balisage: pas d'attribut id dans <diagnostic> + Erreur de balisage: pas d'attribut rule dans <extends> + Erreur de référence: la règle abstraite " + " a été référencée mais pas déclarée + Erreur de balisage: pas d'attribut name dans <key> + Erreur de balisage: pas d'attribut path ou use dans <key> + Erreur de schema: L'élément key n'est pas dans le namespace Schematron ISO. Utilisez le namespace XSLT. + Erreur de balisage: pas d'attribut name dans <function> + Erreur de schema: L'élément function n'est pas dans le namespace Schematron ISO. Utilisez le namespace XSLT. + Erreur de schema: Attribut href vide sur a directive include. + Erreur: URL impossible dans la directive include de Schematron + Impossible d'ouvrir le fichier référencé pour l'inclusion: + + Erreur de schema: Utilisez include pour inclure des fragments et non un schema entier + Erreur de schema: Les schema XSD peuvent être importés seulement si vous utilisez the langage de query 'xslt2' + Erreur de schema: L'élément import-schema n'est pas disponible dans le namespace Schematron ISO. Utilisez le namespace XSLT. + Avertissement: Des variables ne devraient pas être utiliées avec le langage de query "xpath". + Avertissement: Des variables ne devraient pas être utiliées avec le langage de query "xpath2". + Erreur de balisage: pas d'attribut uri dans <ns> + Erreur de balisage: pas d'attribut prefix dans <ns> + Erreur d'implémentation de schema: Ce schema des patterns abstraits, bien qu'ils sont supposés avoir été préprocessés précédemment + Erreur de balisage: pas d'attribut id dans <phase> + Erreur de balisage: pas d'attribut context dans <rule> + Erreur de balisage: pas d'attribut id dans <rule> + Erreur de balisage: (2) attribut context dans une <rule> abstraite + Erreur de balisage: attribut context dans une <rule> abstraite + Erreur de balisage: pas d'attribut select dans <value-of> + Avertissement: + ne peut contenir aucun élément enfant + Erreur de référence: Un diagnostique " + " a été référencé mais n'est pas déclaré + Utiliser the namespace XSLT avec un autre préfixe que "xsl" dans les rules Schematron n'est pas supporté par ce processor: + + Erreur: élément inconnu dans le namespace Schematron ISO: vérifiez l'orthographe et la casse + + Avertissement: élément inconnu + + diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-nl.xhtml b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-nl.xhtml new file mode 100644 index 0000000000000..5f055771c2941 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-nl.xhtml @@ -0,0 +1,58 @@ + + + Schema fout: er werden Schematron elementen uit de oude en nieuwe + namespace gevonden + Schema fout: gebruik 'xslt' in het queryBinding attribute + Faling: Deze implementatie van ISO Schematron werkt niet met + schemas die gebruik maken van de query language + + Fase fout: er is geen 'phase' gedefinieerd met naam + + Markup fout: er is geen 'pattern' attribuut in <active> + Referentie fout: het 'pattern' " + " is geactiveerd maar niet gedeclareerd + Markup fout: er is geen 'test' attribuut in <assert + Markup fout: er is geen 'test' attribuut in <report> + Markup fout: er is geen 'id' attribuut in <diagnostic> + Markup fout: er is geen 'rule' attribuut in <extends> + Referentie fout: de abstracte regel " + " werd gerefereerd maar niet gedeclareerd + Markup fout: er is geen 'name' attribuut in <key> + Markup fout: er is geen 'path' of 'use' attribuut in <key> + Markup fout: er is geen 'path' of 'use' attribuut in <key> + Schema fout: Het 'key' element zit niet in de ISO Schematron namespace. Gebruik de XSLT namespace. + Markup fout: er is geen 'name' attribuut in <function> + Schema fout: Het 'function' element zit niet in de ISO Schematron namespace. Gebruik de XSLT namespace. + Schema fout: Leeg 'href=' attribuut bij de include opdracht. + Fout: Onmogelijke URL gebruikt bij de Schematron include + Kan de gerefereerde 'include' file niet openen: + + Schema fout: Gebruik include om fragmenten op te nemen, niet een volledig schema + Schema fout: XSD schemas kunnen enkel geïmporteerd worden indien de 'xslt2' query language binding gebruikt is + Schema fout: Het 'import-schema' element is niet beschikbaar in the ISO Schematron namespace. Gebruik de XSLT namespace. + Waarschuwing: Variabelen niet gebruiken met de "xpath" query language binding. + Waarschuwing: Variabelen niet gebruiken met de "xpath2" query language binding. + Markup fout: er is geen 'uri' attribute in <ns> + Markup fout: er is geen 'prefix' attribute in <ns> + Schema implementatie fout: Dit schema heeft abstracte patronen, die al gepreprocessed zouden moeten zijn + Markup fout: er is geen 'id' attribuut in <phase> + Markup fout: er is geen 'context' attribuut in <rule> + Markup fout: er is geen 'id' attribuut op abstracte <rule> + Markup fout: (2) context attributen op abstracte <rule> + Markup fout: context attribuut op abstracte <rule> + Markup fout: er is geen 'select' attribute in <value-of> + Waarschuwing: + mag geen kind elementen bevatten + Referentie fout: Een diagnostic " + " werd gerefereerd maar is niet gedeclareerd. + Het gebruik van de XSLT namespace met een prefix verschillend + van "xsl" in Schematron regels wordt niet ondersteund in deze processor: + + Fout: een niet herkend element in de ISO Schematron namespace: check spelling en hoofdlettergebruik + + Waarschuwing: een niet herkend element + + diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/schematron-skeleton-api.htm b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/schematron-skeleton-api.htm new file mode 100644 index 0000000000000..af8137783f7e4 --- /dev/null +++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/schematron-skeleton-api.htm @@ -0,0 +1,723 @@ + + + + + The ISO Schematron Skeleton API + + + + + +

API for ISO Schematron Skeleton

+



+

+

Rick Jelliffe, 2010/04/14

+

This document provides documentation on the XSLT API available in +the implementation of Schematron called iso_schematron_skeleton.xsl. +(available in an XSLT1 and XSLT2 version). The API makes available as +much information from the schema, however there may be some edge +cases where it is not exhaustive. +

+

The skeleton is an XSLT script which provides all the basic +parsing and validating routines for compiling a Schematron schema +into XSLT. Schematron was designed to allow many different uses, and +the skeleton gives you a headstart in creating a customized +implementation. You just need to write XSLT templates to override the +default ones. (The program you write is sometimes called a +meta-stylesheet.) It is the meta-stylesheet that is called +as the XSLT script, not the skeleton. There are several +pre-processing stages which the Schematron schema should be processed +through first, to handle such things as include statements and +abstract patterns. +

+

Phases and error reporting for problems in the schema itself are +handled by the skeleton with no interaction with a “meta-stylesheet”. +Note that there is no guarantee that the context node is always the +element being handled: in most cases the only information available +is the information in the parameters. +

+

For an introductory tutorial on using this API, see Bob DuCharme's +Schematron 1.5: +Looking Under the Hood +

+

Superset of API for Schematron 1.5 and 1.6

+

(This is an updated version of the API for the Schematron 1.5 +implementation called skeleton1-5.xsl, which in turn comes +from the new architecture contributed by Oliver Becker for +Schematron 1.3.)

+

The current API contains only additions. Well-written +meta-stylesheets that use the new API will be be able to run on the +existing 1.5 and 1.6 skeletons. Similarly, it should be possible to +upgrade the skeleton from 1.5 or 1.6 to the iso-schematron-skeleton +only by correcting the import statement at the beginning of the +meta-stylsheet. Additions or re-groupings from the 1.5 schema are +shown in red. Deletions have overstrike.

+

Mooted addition: a parameter @action which for specifying +processing instructions on assertions and reports.

+
+

process-prolog

+

The process-prolog template gets called at the start of +the validation session. It has no parameters. The default +implementation is no action.

+
+

process-root

+

The process-root template processes the root element of +the schema (which is not the same thing as the root of the document / +and need not be the document element /*) .

+
+
node-list $contents +
+ string $schemaVersion +
+ The version of the schema, perhaps a datestamp. +
+ "xslt" | "xpath" | + "xslt2" | ... + $queryBinding +
+ The query language binding. +
+ string $title +
+ The title of this schema +
+ "iso" | "1.5" | + "1.6" | ... + $version +
+ The version of Schematron being used. +
+

+Rich properties:

+
+
XML SystemId + $icon +
+ The URI of an icon +
+ XML ID + $id +
+ The unique identifier with the schema for the + schema + element. +
+ SGML FPI + $fpi +
+ The Formal Public Identifier for this schema. +
+ IETF language + $lang +
+ The human language used in this schema, from + xml:lang +
+ URL + $see +
+ Link to documentation on WWW or file +
+ "preserve" | "default" + $space +
+ The value for xml:space +
+

+To print the documentation paragraphs, use <xsl:apply-templates +mode="do-schema-p" />

+

To output the results, use <xsl:copy-of select="$contents" +/>

+
+

process-assert

+

The process-assert template handles asserts whose test +has failed. +

+
+
XPath $test +
+ The test +
+ XML IDREFS $diagnostics +
+ A list of the idrefs diagnostic elements related to the current + assertion +
+ XML NMTOKEN + $flag +
+ The name of a flag that becomes true because + this assertion fails. The flag is true for the document if it is + flagged true on any assertion. For compatability, this parameter + should not be used with Schematron 1.5. +
+

+Rich properties:

+
+
XML SystemId + $icon +
+ The URI of an icon +
+ XML ID + $id +
+ The unique identifier with the schema for the + assert + element. +
+ SGML FPI + $fpi +
+ The Formal Public Identifier for this + assertion. +
+ IETF language + $lang +
+ The human language used in this assertion, + from xml:lang +
+ URL + $see +
+ Link to documentation on WWW or file +
+ "preserve" | "default" + $space +
+ The value for xml:space +
+

+Linking properties:

+
+
XML NMTOKEN + $role +
+ A name for the generic role of this assertion. + The schema creator would have their own vocabulary. +
+ XPath + $subject +
+ A path relative to the current context to some + interesting node considered the subject. +
+

+To print the text contents, use <xsl:apply-templates +mode="text" />

+
+

process-diagnostic

+

The process-diagnostic template handles diagnostic +messages for assert statements that have failed and report +statements that have succeeded. The diagnostics are evaluated in the +context of the rule.

+

Rich properties:

+
+
XML SystemId + $icon +
+ The URI of an icon +
+ XML ID + $id +
+ The unique identifier with the schema for the + assert + element. +
+ SGML FPI + $fpi +
+ The Formal Public Identifier for this + assertion. +
+ IETF language + $lang +
+ The human language used in this assertion, + from xml:lang +
+ URL + $see +
+ Link to documentation on WWW or file +
+ "preserve" | "default" + $space +
+ The value for xml:space +

+
+

process-dir

+

The process-dir template handles bi-directionality +markup, which is only needed by certain human scripts such as Arabic.

+
+
"ltr" or "rtl" or "" + $value +
+ Left-to-right or right-to-left or unspecified +

+
+

process-emph

+

The process-emph template handles the markup of +emphasized text in paragraphs, assertions and diagnostics. It has no +parameters.

+
+

process-message

+

The process-message handles default outputing of text.

+
+
string $pattern +
+ Some text that may be some kind of pattern +
+ string $role +
+ Some text that may be some kind of role +

+
+

process-name

+

The process-name templates handle name strings that can +be used in assertions. asssert and report only +provide name subelements rather than the more general +value-of elements to encourage plain language and generic +descriptions rather than specific diagnostics, for which purpose the +diagnostics elements are used.

+
+
string $name +
+ The name of the current element, or of the node specified by a name + element +

+
+

process-ns

+

The process-ns template reports on ns +declarations, which are used to transmit on namespace information by +the skeleton.

+
+
Namespace NCName $prefix +
+ The prefix of a namespace +
+ XML SystemId $uri +
+ The (internationalized) URI Reference of a namespace +

+
+

process-p

+

The process-p template handles paragraphs.

+
+
XML NMTOKEN $class +
+ An attribute that can be used for stylesheet style +
+ XML ID $id +
+ The unique identifier with the schema for the p element. +
+ XML SystemId $icon +
+ The URI of an icon +
+ IETF Language $lang +
+ The human language used in this paragraph +
+

+To print the text contents, use <xsl:apply-templates +mode="text" /> +

+
+

process-pattern

+

The process-pattern reports on the start of evaluation of +a pattern element.

+
+
string $name +
+ The title of the current pattern +
+ XML NCNAMES $is-a +
+ Empty or not provided if the pattern is not derived from an abstract + pattern. Otherwise the name of the abstract pattern. A list may be + used if there was a sequence of abstract patterns. +
+

+Rich properties:

+
+
XML SystemId + $icon +
+ The URI of an icon +
+ XML ID + $id +
+ The unique identifier with the schema for the + pattern + element. +
+ SGML FPI + $fpi +
+ The Formal Public Identifier for this pattern. + +
+ IETF language + $lang +
+ The human language used in this pattern, from + xml:lang +
+ URL + $see +
+ A (internationalized) URI reference to some + supporting or defining documentation +
+ "preserve" | "default" + $space +
+ The value for xml:space +
+

+To print the documentation contents, use <xsl:apply-templates +mode="do-pattern-p"/>

+
+

process-report

+

The process-report template handles report whose +test has succeeded. +

+
+
XPath $test +
+ The test +
+ XML IDREFS $diagnostics +
+ A list of the diagnostic elements related to the current assertion +
+ XML NMTOKEN + $flag +
+ The name of a flag that becomes true because + this assertion fails. The flag is true for the document if it is + flagged true on any assertion. For compatability, this parameter + should not be used with Schematron 1.5. +
+

+Rich properties:

+
+
XML SystemId + $icon +
+ The URI of an icon +
+ XML ID + $id +
+ The unique identifier with the schema for the + report + element. +
+ SGML FPI + $fpi +
+ The Formal Public Identifier for this report. +
+ IETF language + $lang +
+ The human language used in this report, from + xml:lang +
+ URL + $see +
+ Link to documentation on WWW or file +
+ "preserve" | "default" + $space +
+ The value for xml:space +
+

+Linking properties:

+
+
XML NMTOKEN + $role +
+ A name for the generic role of this assertion. + The schema creator would have their own vocabulary. +
+ XPath + $subject +
+ A path relative to the current context to some + interesting node considered the subject. +
+

+To print the text contents, use <xsl:apply-templates +mode="text" />

+
+

process-rule

+

The process-rule reports that a rule element has +fired: its context attribute matched some nodes. .

+
+
XSLT expression $context +
+ The expression that gives the context of the current +
+

+Rich properties:

+
+
XML SystemId + $icon +
+ The URI of an icon +
+ XML ID + $id +
+ The unique identifier with the schema for this + rule + element. +
+ SGML FPI + $fpi +
+ The Formal Public Identifier for this rule. +
+ IETF language + $lang +
+ The human language used in this rule, from + xml:lang +
+ URL + $see +
+ Link to documentation on WWW or file +
+ "preserve" | "default" + $space +
+ The value for xml:space +
+

+Linking properties:

+
+
XML NMTOKEN + $role +
+ A name for the generic role of this assertion. + The schema creator would have their own vocabulary. +
+ XPath + $subject +
+ A path relative to the current context to some + interesting node considered the subject. +

+
+

process-span

+

The process-span handles span elements, which are generic +elements for styling, like HTML's .

+
+
XML NMTOKEN $class +
+ An attribute that can be used for stylesheet style +

+
+

process-title

+

The process-title handles title elements, which are +generic elements for styling, like HTML's .

+
+
XML NMTOKEN $class +
+ An attribute that can be used for stylesheet style +
+

+By default, titles are handled by invocing process-p with +the parameter class with a value "title".

+
+

process-value-of

+

The process-value-of template handles value-of +elements, which are used in diagnostic messages to allow very +specific hinting .

+
+
XPath $select +
+ The path of some node that will be evaluated and printed.

+
+

Global Parameters

+

There are several global parameters that may be available for use. +However, it is not a requirement to follow these, and implementations +may not supply them with any value. So a test of +string-length(variable) < +0 is appropriate in each case.

+



+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Parameter

+
+

Value

+
+

Description

+
+

allow-foreign

+
+

"true" | "false" (default) +

+
+

Pass non-Schematron elements to the generated + stylesheet. Pass the Schematron elements span, emph and dir: to + the output SVRL. +

+
+

fileNameParameter

+
+

string

+
+

A parameter passed to the Validator and + potentially available as a variable in Schematron schemas as + $fileNameParameter

+
+

fileDirParameter

+
+

string

+
+

A parameter passed to the Validator and + potentially available as a variable in Schematron schemas as + $fileDirParameter

+
+

archiveNamePaameter

+
+

string

+
+

A parameter passed to the Validator and + potentially available as a variable in Schematron schemas as + $archiveNameParameter

+
+

archiveDirParameter

+
+

string

+
+

A parameter passed to the Validator and + potentially available as a variable in Schematron schemas as + $archivePathParameter

+
+

debug +

+
+

true” | “false” (default)

+
+

Verbose error messages (Note this may be + superceded by “verbose” at some stage in the future.)

+
+

generate-paths

+
+

true|false +

+
+

generate the SVRL @location attribute with XPaths

+
+

diagnose

+
+

yes | no +

+
+

Add the diagnostics to the assertion results

+
+

terminate

+
+

yes | no | true | false | assert +

+
+

Terminate on the first failed assertion or + successful report

+
+

message-newline +

+
+

"true" (default) | "false" +

+
+

Generate an extra newline at the end of messages

+
+

output-encoding

+
+

string

+
+

The encoding used for output, for example if the + output is XML

+
+
+
+
+ + \ No newline at end of file diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java new file mode 100644 index 0000000000000..1b06fe47ba897 --- /dev/null +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java @@ -0,0 +1,69 @@ +package org.apache.camel.component.schematron; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.component.schematron.util.Utils; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.commons.io.IOUtils; +import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.DifferenceListener; +import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; +import org.junit.Test; + +/** + * Schematron Component Test. + */ +public class SchematronComponentTest extends CamelTestSupport { + + + /** + * @throws Exception + */ + @Test + public void testSendBodyAsString() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMinimumMessageCount(1); + + String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml")); + String expected = IOUtils.toString(ClassLoader.getSystemResourceAsStream("result/article-1-result.xml")); + template.sendBody("direct:start", payload); + assertMockEndpointsSatisfied(); + String result = mock.getExchanges().get(0).getIn().getBody(String.class); + DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener(); + Diff myDiff = new Diff(expected, result); + myDiff.overrideDifferenceListener(myDifferenceListener); + assertTrue(myDiff.similar()); + } + + /** + * @throws Exception + */ + @Test + public void testSendBodyAsInputStreamInvalidXML() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMinimumMessageCount(1); + + String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); + String expected = IOUtils.toString(ClassLoader.getSystemResourceAsStream("result/article-1-result.xml")); + template.sendBody("direct:start", payload); + assertMockEndpointsSatisfied(); + String result = mock.getExchanges().get(0).getIn().getBody(String.class); + + + // should throw two assertions because of the missing chapters in the XML. + assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert [@location='/doc[1]/chapter[1]']/svrl:text", result)); + assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert [@location='/doc[1]/chapter[2]']/svrl:text", result)); + + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + from("direct:start") + .to("schematron://sch/sample-schematron.sch") + .to("mock:result"); + } + }; + } +} diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java new file mode 100644 index 0000000000000..4e21ff7f2e8d0 --- /dev/null +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java @@ -0,0 +1,70 @@ +package org.apache.camel.component.schematron; + + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Producer; +import org.apache.camel.impl.DefaultExchange; +import org.apache.camel.test.junit4.CamelTestSupport; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; + +/** + * Created by akhettar on 20/12/2013. + */ +public class SchematronEndpointTest extends CamelTestSupport { + + + @Test + public void testSchematronFileReadFromClassPath()throws Exception { + + + String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml")); + Endpoint endpoint = context().getEndpoint("schematron://sch/sample-schematron.sch"); + Producer producer = endpoint.createProducer(); + Exchange exchange = new DefaultExchange(context); + + exchange.getIn().setBody(payload); + + // invoke the component. + producer.process(exchange); + + String report = extractReport(exchange); + assertNotNull(report); + } + + @Test + public void testSchematronFileReadFromFileSystem()throws Exception { + + + String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); + String path = ClassLoader.getSystemResource("sch/sample-schematron.sch").getPath(); + Endpoint endpoint = context().getEndpoint("schematron://" + path); + Producer producer = endpoint.createProducer(); + Exchange exchange = new DefaultExchange(context); + + exchange.getIn().setBody(payload); + + // invoke the component. + producer.process(exchange); + + String report = extractReport(exchange); + assertNotNull(report); + } + + /** + * Retrieves the body in string from format from the exchange. + * @param exchange + * @return + * @throws IOException + */ + private String extractReport(Exchange exchange) throws IOException { + + return IOUtils.toString(exchange.getOut().getBody(InputStream.class)); + } +} diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java new file mode 100644 index 0000000000000..b40507e75bd63 --- /dev/null +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java @@ -0,0 +1,51 @@ +package org.apache.camel.component.schematron; + +import org.apache.camel.Exchange; +import org.apache.camel.component.schematron.engine.SchematronEngineFactory; +import org.apache.camel.component.schematron.util.Constants; +import org.apache.camel.impl.DefaultExchange; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Schematron Producer Unit Test. + *

+ * Created by akhettar on 31/12/2013. + */ +public class SchematronProducerTest extends CamelTestSupport { + + private static SchematronProducer producer; + + @BeforeClass + public static void setUP() { + SchematronEngineFactory fac = SchematronEngineFactory.newInstance(ClassLoader. + getSystemResourceAsStream("sch/sample-schematron.sch")); + producer = new SchematronProducer(null, fac); + } + + @Test + public void testProcessValidXML() throws Exception { + Exchange exc = new DefaultExchange(context); + exc.getIn().setBody(ClassLoader.getSystemResourceAsStream("xml/article-1.xml")); + + // process xml payload + producer.process(exc); + + // assert + assertTrue(exc.getOut().getHeader(Constants.VALIDATION_STATUS).equals(Constants.SUCCESS)); + } + + @Test + public void testProcessInValidXML() throws Exception { + Exchange exc = new DefaultExchange(context); + exc.getIn().setBody(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); + + // process xml payload + producer.process(exc); + + // assert + assertTrue(exc.getOut().getHeader(Constants.VALIDATION_STATUS).equals(Constants.FAILED)); + + } +} diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java new file mode 100644 index 0000000000000..2d59a441a9dfa --- /dev/null +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java @@ -0,0 +1,56 @@ +package org.apache.camel.component.schematron.engine; + +import org.apache.camel.component.schematron.util.Utils; +import org.apache.commons.io.IOUtils; +import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.DifferenceListener; +import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.InputStream; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; + +/** + * Created by akhettar on 27/12/2013. + */ +public class SchematronEngineTest { + + private static SchematronEngine engine; + + @BeforeClass + public static void setUP() { + InputStream rules = ClassLoader.getSystemResourceAsStream("sch/sample-schematron.sch"); + engine = SchematronEngineFactory.newInstance(rules).newScehamtronEngine(null); + } + + @Test + public void testValidXML() throws Exception { + + String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml")); + String expected = IOUtils.toString(ClassLoader.getSystemResourceAsStream("result/article-1-result.xml")); + + // validate + String result = engine.validate(payload); + DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener(); + Diff myDiff = new Diff(expected, result); + myDiff.overrideDifferenceListener(myDifferenceListener); + assertTrue(myDiff.similar()); + } + + @Test + public void testInValidXML() throws Exception { + + String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); + + // validate + String result = engine.validate(payload); + + // should throw two assertions because of the missing chapters in the XML. + assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert [@location='/doc[1]/chapter[1]']/svrl:text", result)); + assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert [@location='/doc[1]/chapter[2]']/svrl:text", result)); + + } +} diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/TemplatesFactoryTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/TemplatesFactoryTest.java new file mode 100644 index 0000000000000..76b990e87878e --- /dev/null +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/TemplatesFactoryTest.java @@ -0,0 +1,26 @@ +package org.apache.camel.component.schematron.engine; + +import org.junit.Assert; +import org.junit.Test; + +import javax.xml.transform.Templates; + +/** + * Created by akhettar on 22/12/2013. + */ +public class TemplatesFactoryTest { + + private String rules = "sch/sample-schematron.sch"; + + + @Test + public void testInstantiateAnInstanceOfTemplates() throws Exception { + + + TemplatesFactory fac = TemplatesFactory.newInstance(ClassLoader.getSystemResourceAsStream(rules)); + Templates templates = fac.newTemplates(); + Assert.assertNotNull(templates); + + + } +} diff --git a/components/camel-schematron/src/test/resources/log4j.properties b/components/camel-schematron/src/test/resources/log4j.properties new file mode 100644 index 0000000000000..37c14479f5ce8 --- /dev/null +++ b/components/camel-schematron/src/test/resources/log4j.properties @@ -0,0 +1,14 @@ +# +# The logging properties used +# +log4j.rootLogger=TRACE, out + +# uncomment the following line to turn on Camel debugging +#log4j.logger.org.apache.camel=DEBUG + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n +#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + diff --git a/components/camel-schematron/src/test/resources/result/article-1-result.xml b/components/camel-schematron/src/test/resources/result/article-1-result.xml new file mode 100644 index 0000000000000..ec0670c75f45f --- /dev/null +++ b/components/camel-schematron/src/test/resources/result/article-1-result.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/components/camel-schematron/src/test/resources/sch/sample-schematron.sch b/components/camel-schematron/src/test/resources/sch/sample-schematron.sch new file mode 100644 index 0000000000000..4cc69e24a603a --- /dev/null +++ b/components/camel-schematron/src/test/resources/sch/sample-schematron.sch @@ -0,0 +1,14 @@ + + + + + + + + A chapter should have a title + + + + \ No newline at end of file diff --git a/components/camel-schematron/src/test/resources/xml/article-1.xml b/components/camel-schematron/src/test/resources/xml/article-1.xml new file mode 100644 index 0000000000000..3c95d568d6b9f --- /dev/null +++ b/components/camel-schematron/src/test/resources/xml/article-1.xml @@ -0,0 +1,15 @@ + + + + chapter title + Chapter content + + + chapter 2 title + Content + + + Title + Chapter 3 content + + \ No newline at end of file diff --git a/components/camel-schematron/src/test/resources/xml/article-2.xml b/components/camel-schematron/src/test/resources/xml/article-2.xml new file mode 100644 index 0000000000000..2867b9d1bcaa1 --- /dev/null +++ b/components/camel-schematron/src/test/resources/xml/article-2.xml @@ -0,0 +1,15 @@ + + + + + Chapter content + + + + Content + + + Title + Chapter 3 content + + \ No newline at end of file From 871c49fd198f2603c15c426b8c4974bb9782061d Mon Sep 17 00:00:00 2001 From: akhettar Date: Thu, 9 Jan 2014 22:14:16 +0000 Subject: [PATCH 03/17] First commit --- components/camel-schematron/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/camel-schematron/README.md b/components/camel-schematron/README.md index 7e3b1cd7ac9d7..9057bc91d8217 100644 --- a/components/camel-schematron/README.md +++ b/components/camel-schematron/README.md @@ -9,10 +9,14 @@ Schematron Tutorials ====================== http://www.schematron.com/spec.html + http://www.xml.com/pub/a/2003/11/12/schematron.html + http://www.data2type.de/en/xml-xslt-xslfo/schematron/ + http://www.mulberrytech.com/papers/schematron-Philly.pdf + To build this project use mvn install From 129fa260781ae340f88a838f80b64182522a2aa4 Mon Sep 17 00:00:00 2001 From: akhettar Date: Sun, 26 Jan 2014 21:28:57 +0000 Subject: [PATCH 04/17] adding abort parameter --- .../component/schematron/SchematronEndpoint.java | 8 +++++++- .../component/schematron/SchematronProducer.java | 12 +++++++++--- .../exception/SchematronValidationException.java | 4 ++++ .../camel/component/schematron/util/Utils.java | 14 ++++++-------- .../schematron/SchematronEndpointTest.java | 15 +++++++++++++++ .../schematron/SchematronProducerTest.java | 5 ++++- 6 files changed, 45 insertions(+), 13 deletions(-) diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java index 08fa72c2d4d78..d2eec356e0369 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java @@ -21,6 +21,7 @@ public class SchematronEndpoint extends DefaultEndpoint { private Logger logger = LoggerFactory.getLogger(SchematronEndpoint.class); private SchematronEngineFactory factory; private String remaining; + private boolean abort; public SchematronEndpoint() { } @@ -45,7 +46,12 @@ public Consumer createConsumer(Processor processor) throws Exception { public boolean isSingleton() { return true; } - + public void setAbort(boolean abort) { + this.abort = abort; + } + public boolean isAbort() { + return abort; + } @Override protected void doStart() throws Exception { super.doStart(); diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java index e9c5abf6f4ba4..6db4f59af887d 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java @@ -3,6 +3,7 @@ import org.apache.camel.Exchange; import org.apache.camel.RuntimeCamelException; import org.apache.camel.component.schematron.engine.SchematronEngineFactory; +import org.apache.camel.component.schematron.exception.SchematronValidationException; import org.apache.camel.component.schematron.util.Constants; import org.apache.camel.component.schematron.engine.SchematronEngine; import org.apache.camel.component.schematron.util.Utils; @@ -44,13 +45,18 @@ public void process(Exchange exchange) throws Exception { String payload = getPayload(exchange); SchematronEngine engine = factory.newScehamtronEngine(Constants.XSLT_VERSION_2_0); String report = engine.validate(payload); + String status = Utils.getValidationStatus(report); + + if (this.endpoint.isAbort() && Constants.FAILED.equals(status)) + { + throw new SchematronValidationException("Schematron validation failure \n" + report); + } // set the body out exchange.getOut().setBody(report); - - // set all the incoming headers in the outbound message + logger.info("Schematron validation status : {}", status); exchange.getOut().setHeaders(exchange.getIn().getHeaders()); - Utils.setValidationStatus(report, exchange); + exchange.getOut().setHeader(Constants.VALIDATION_STATUS,status); } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java index 06e435f1b1cc1..a45824d27a175 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java @@ -14,4 +14,8 @@ public SchematronValidationException(final String message, Throwable e) { super(message,e); } + + public SchematronValidationException(String message) { + super(message); + } } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java index 5ed628191d849..48d7a6f2b3ee8 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java @@ -45,17 +45,15 @@ public static String evaluate(final String xpath, final String xml) { } } + /** - * Sets schematron validation header status for given report. - * + * Get validation status SUCCESS OR FAILURE if there are any schematron validation errors. * @param report - * @param exchange + * @return */ - public static void setValidationStatus(final String report, final Exchange exchange) { - - String status = StringUtils.contains(report, + public static String getValidationStatus(final String report) + { + return StringUtils.contains(report, Constants.FAILED_ASSERT)? Constants.FAILED : Constants.SUCCESS; - logger.info("Schematron validation : {}", status); - exchange.getOut().setHeader(Constants.VALIDATION_STATUS,status); } } diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java index 4e21ff7f2e8d0..c7454af9ec5fd 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java @@ -4,6 +4,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.Producer; +import org.apache.camel.component.schematron.exception.SchematronValidationException; import org.apache.camel.impl.DefaultExchange; import org.apache.camel.test.junit4.CamelTestSupport; @@ -57,6 +58,20 @@ public void testSchematronFileReadFromFileSystem()throws Exception { assertNotNull(report); } + @Test(expected = SchematronValidationException.class) + public void testThrowSchematronValidationException() throws Exception + { + String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); + Endpoint endpoint = context().getEndpoint("schematron://sch/sample-schematron.sch?abort=true"); + Producer producer = endpoint.createProducer(); + Exchange exchange = new DefaultExchange(context); + + exchange.getIn().setBody(payload); + + // invoke the component. + producer.process(exchange); + + } /** * Retrieves the body in string from format from the exchange. * @param exchange diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java index b40507e75bd63..48a8b5a92cf4d 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java @@ -2,6 +2,7 @@ import org.apache.camel.Exchange; import org.apache.camel.component.schematron.engine.SchematronEngineFactory; +import org.apache.camel.component.schematron.exception.SchematronValidationException; import org.apache.camel.component.schematron.util.Constants; import org.apache.camel.impl.DefaultExchange; import org.apache.camel.test.junit4.CamelTestSupport; @@ -21,7 +22,8 @@ public class SchematronProducerTest extends CamelTestSupport { public static void setUP() { SchematronEngineFactory fac = SchematronEngineFactory.newInstance(ClassLoader. getSystemResourceAsStream("sch/sample-schematron.sch")); - producer = new SchematronProducer(null, fac); + SchematronEndpoint endpoint = new SchematronEndpoint(); + producer = new SchematronProducer(endpoint, fac); } @Test @@ -48,4 +50,5 @@ public void testProcessInValidXML() throws Exception { assertTrue(exc.getOut().getHeader(Constants.VALIDATION_STATUS).equals(Constants.FAILED)); } + } From 4367fa5f925b3c135749f0971be7ae78438b1a51 Mon Sep 17 00:00:00 2001 From: akhettar Date: Wed, 5 Feb 2014 22:06:08 +0000 Subject: [PATCH 05/17] setting report body in the header --- .../schematron/SchematronProducer.java | 59 ++++++++----------- .../engine/SchematronEngineFactory.java | 6 +- .../component/schematron/util/Constants.java | 3 +- .../schematron/SchematronComponentTest.java | 6 +- .../schematron/SchematronEndpointTest.java | 22 +++---- .../schematron/SchematronProducerTest.java | 5 +- .../engine/SchematronEngineTest.java | 2 +- 7 files changed, 42 insertions(+), 61 deletions(-) diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java index 6db4f59af887d..51c103dc5aab4 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java @@ -1,22 +1,16 @@ package org.apache.camel.component.schematron; import org.apache.camel.Exchange; -import org.apache.camel.RuntimeCamelException; import org.apache.camel.component.schematron.engine.SchematronEngineFactory; import org.apache.camel.component.schematron.exception.SchematronValidationException; import org.apache.camel.component.schematron.util.Constants; -import org.apache.camel.component.schematron.engine.SchematronEngine; import org.apache.camel.component.schematron.util.Utils; import org.apache.camel.impl.DefaultProducer; -import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.io.InputStream; - /** - * The schematron producer. + * The Schematron producer. */ public class SchematronProducer extends DefaultProducer { private static final Logger logger = LoggerFactory.getLogger(SchematronProducer.class); @@ -24,11 +18,10 @@ public class SchematronProducer extends DefaultProducer { private SchematronEngineFactory factory; /** - * * @param endpoint the schematron endpoint. - * @param factory the schematron factory. + * @param factory the schematron factory. */ - public SchematronProducer(SchematronEndpoint endpoint, SchematronEngineFactory factory) { + public SchematronProducer(final SchematronEndpoint endpoint, final SchematronEngineFactory factory) { super(endpoint); this.endpoint = endpoint; this.factory = factory; @@ -42,40 +35,36 @@ public SchematronProducer(SchematronEndpoint endpoint, SchematronEngineFactory f */ public void process(Exchange exchange) throws Exception { - String payload = getPayload(exchange); - SchematronEngine engine = factory.newScehamtronEngine(Constants.XSLT_VERSION_2_0); - String report = engine.validate(payload); - String status = Utils.getValidationStatus(report); + String payload = exchange.getIn().getBody(String.class); + String report = factory.newScehamtronEngine().validate(payload); - if (this.endpoint.isAbort() && Constants.FAILED.equals(status)) - { - throw new SchematronValidationException("Schematron validation failure \n" + report); - } - - // set the body out - exchange.getOut().setBody(report); + logger.debug("Schematron validation report \n {}", report); + String status = getValidationStatus(report); logger.info("Schematron validation status : {}", status); - exchange.getOut().setHeaders(exchange.getIn().getHeaders()); - exchange.getOut().setHeader(Constants.VALIDATION_STATUS,status); - - } + // if exchange pattern is In and Out set details on the Out message. + if (exchange.getPattern().isOutCapable()) { + exchange.getOut().setHeaders(exchange.getIn().getHeaders()); + exchange.getOut().setHeader(Constants.VALIDATION_STATUS, status); + exchange.getOut().setHeader(Constants.VALIDATION_REPORT, report); + } else { + exchange.getIn().setHeader(Constants.VALIDATION_STATUS, status); + exchange.getIn().setHeader(Constants.VALIDATION_REPORT, report); + } + } /** - * Gets the body payload either inputStream or String. + * Get validation status, SUCCESS or FAILURE * - * @param exchange + * @param report * @return */ - private String getPayload(Exchange exchange) { - Object body = exchange.getIn().getBody(); - try { - return (body instanceof InputStream) ? IOUtils.toString((InputStream) body) : (String) body; - } catch (IOException e) { - logger.error("Unknown payload type: {}", body); - throw new RuntimeCamelException("Unknown payload type", e); + private String getValidationStatus(final String report) { + String status = Utils.getValidationStatus(report); + if (this.endpoint.isAbort() && Constants.FAILED.equals(status)) { + throw new SchematronValidationException("Schematron validation failure \n" + report); } + return status; } - } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java index 470a0efc93d2b..5fe4c8eaef82e 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java @@ -53,11 +53,9 @@ public static SchematronEngineFactory newInstance(final String catalogs, final S /** * Creates an instance of SchematronEngine * - * @param version the XSLT version implementation of the schamtron rules. - * @return + * @return an instance of SchematronEngine */ - public SchematronEngine newScehamtronEngine(final String version) { - //TODO provide support for both xslt 1 and xslt2 + public SchematronEngine newScehamtronEngine() { try { EntityResolver resolver = catalog == null ? null : getResolver(catalog); diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Constants.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Constants.java index e0a1181aaf532..6f1c122e6341d 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Constants.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Constants.java @@ -8,9 +8,10 @@ public final class Constants { public static final String XSLT_VERSION_2_0 = "2.0"; - public static final String VALIDATION_STATUS = "CamelSchematronStatus"; + public static final String VALIDATION_STATUS = "CamelSchValidationStatus"; public static final String HTTP_PURL_OCLC_ORG_DSDL_SVRL = "http://purl.oclc.org/dsdl/svrl"; public static final String FAILED_ASSERT = "failed-assert"; public static final String FAILED = "FAILED" ; public static final String SUCCESS = "SUCCESS" ; + public static final String VALIDATION_REPORT = "CamelSchValidationReport"; } diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java index 1b06fe47ba897..1025c24242c5f 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java @@ -2,6 +2,7 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.component.schematron.util.Constants; import org.apache.camel.component.schematron.util.Utils; import org.apache.camel.test.junit4.CamelTestSupport; import org.apache.commons.io.IOUtils; @@ -28,7 +29,7 @@ public void testSendBodyAsString() throws Exception { String expected = IOUtils.toString(ClassLoader.getSystemResourceAsStream("result/article-1-result.xml")); template.sendBody("direct:start", payload); assertMockEndpointsSatisfied(); - String result = mock.getExchanges().get(0).getIn().getBody(String.class); + String result = mock.getExchanges().get(0).getIn().getHeader(Constants.VALIDATION_REPORT, String.class); DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener(); Diff myDiff = new Diff(expected, result); myDiff.overrideDifferenceListener(myDifferenceListener); @@ -44,10 +45,9 @@ public void testSendBodyAsInputStreamInvalidXML() throws Exception { mock.expectedMinimumMessageCount(1); String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); - String expected = IOUtils.toString(ClassLoader.getSystemResourceAsStream("result/article-1-result.xml")); template.sendBody("direct:start", payload); assertMockEndpointsSatisfied(); - String result = mock.getExchanges().get(0).getIn().getBody(String.class); + String result = mock.getExchanges().get(0).getIn().getHeader(Constants.VALIDATION_REPORT, String.class); // should throw two assertions because of the missing chapters in the XML. diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java index c7454af9ec5fd..0f76ab7a0508a 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java @@ -3,8 +3,10 @@ import org.apache.camel.Endpoint; import org.apache.camel.Exchange; +import org.apache.camel.ExchangePattern; import org.apache.camel.Producer; import org.apache.camel.component.schematron.exception.SchematronValidationException; +import org.apache.camel.component.schematron.util.Constants; import org.apache.camel.impl.DefaultExchange; import org.apache.camel.test.junit4.CamelTestSupport; @@ -28,14 +30,14 @@ public void testSchematronFileReadFromClassPath()throws Exception { String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml")); Endpoint endpoint = context().getEndpoint("schematron://sch/sample-schematron.sch"); Producer producer = endpoint.createProducer(); - Exchange exchange = new DefaultExchange(context); + Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut); exchange.getIn().setBody(payload); // invoke the component. producer.process(exchange); - String report = extractReport(exchange); + String report = exchange.getOut().getHeader(Constants.VALIDATION_REPORT, String.class); assertNotNull(report); } @@ -47,14 +49,14 @@ public void testSchematronFileReadFromFileSystem()throws Exception { String path = ClassLoader.getSystemResource("sch/sample-schematron.sch").getPath(); Endpoint endpoint = context().getEndpoint("schematron://" + path); Producer producer = endpoint.createProducer(); - Exchange exchange = new DefaultExchange(context); + Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut); exchange.getIn().setBody(payload); // invoke the component. producer.process(exchange); - String report = extractReport(exchange); + String report = exchange.getOut().getHeader(Constants.VALIDATION_REPORT, String.class); assertNotNull(report); } @@ -64,7 +66,7 @@ public void testThrowSchematronValidationException() throws Exception String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); Endpoint endpoint = context().getEndpoint("schematron://sch/sample-schematron.sch?abort=true"); Producer producer = endpoint.createProducer(); - Exchange exchange = new DefaultExchange(context); + Exchange exchange = new DefaultExchange(context, ExchangePattern.OutIn); exchange.getIn().setBody(payload); @@ -72,14 +74,4 @@ public void testThrowSchematronValidationException() throws Exception producer.process(exchange); } - /** - * Retrieves the body in string from format from the exchange. - * @param exchange - * @return - * @throws IOException - */ - private String extractReport(Exchange exchange) throws IOException { - - return IOUtils.toString(exchange.getOut().getBody(InputStream.class)); - } } diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java index 48a8b5a92cf4d..b8490f86d081a 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java @@ -1,6 +1,7 @@ package org.apache.camel.component.schematron; import org.apache.camel.Exchange; +import org.apache.camel.ExchangePattern; import org.apache.camel.component.schematron.engine.SchematronEngineFactory; import org.apache.camel.component.schematron.exception.SchematronValidationException; import org.apache.camel.component.schematron.util.Constants; @@ -28,7 +29,7 @@ public static void setUP() { @Test public void testProcessValidXML() throws Exception { - Exchange exc = new DefaultExchange(context); + Exchange exc = new DefaultExchange(context, ExchangePattern.InOut); exc.getIn().setBody(ClassLoader.getSystemResourceAsStream("xml/article-1.xml")); // process xml payload @@ -40,7 +41,7 @@ public void testProcessValidXML() throws Exception { @Test public void testProcessInValidXML() throws Exception { - Exchange exc = new DefaultExchange(context); + Exchange exc = new DefaultExchange(context, ExchangePattern.InOut); exc.getIn().setBody(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); // process xml payload diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java index 2d59a441a9dfa..e7c3b68528262 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java @@ -23,7 +23,7 @@ public class SchematronEngineTest { @BeforeClass public static void setUP() { InputStream rules = ClassLoader.getSystemResourceAsStream("sch/sample-schematron.sch"); - engine = SchematronEngineFactory.newInstance(rules).newScehamtronEngine(null); + engine = SchematronEngineFactory.newInstance(rules).newScehamtronEngine(); } @Test From ca6862fe8877dcf066f4c58ed80c76cb01021886 Mon Sep 17 00:00:00 2001 From: akhettar Date: Mon, 17 Feb 2014 22:50:33 +0000 Subject: [PATCH 06/17] checkstyle tidy up --- components/camel-schematron/README.md | 1 + components/camel-schematron/pom.xml | 113 +- .../schematron/SchematronComponent.java | 19 +- .../schematron/SchematronEndpoint.java | 56 +- .../schematron/SchematronProducer.java | 40 +- .../engine/ClassPathURIResolver.java | 30 +- .../schematron/engine/SchematronEngine.java | 53 +- .../engine/SchematronEngineFactory.java | 103 +- .../schematron/engine/TemplatesFactory.java | 73 +- .../schematron/engine/URIResolverImp.java | 30 - .../exception/SchematronConfigException.java | 18 +- .../SchematronValidationException.java | 21 +- .../component/schematron/util/Constants.java | 17 - .../component/schematron/util/Utils.java | 32 +- .../ExtractSchFromRNG.xsl | 75 - .../ExtractSchFromXSD.xsl | 77 - .../iso_abstract_expand.xsl | 297 --- .../iso-schematron-xslt1/iso_dsdl_include.xsl | 1509 -------------- .../iso_schematron_message.xsl | 55 - .../iso_schematron_skeleton_for_xslt1.xsl | 1844 ----------------- .../iso_svrl_for_xslt1.xsl | 605 ------ .../resources/iso-schematron-xslt1/readme.txt | 101 - .../schematron-skeleton-api.htm | 723 ------- .../iso-schematron-xslt2/catalog-xslt-2.xml | 17 - .../schematron/SchematronComponentTest.java | 18 +- .../schematron/SchematronEndpointTest.java | 28 +- .../schematron/SchematronProducerTest.java | 29 +- .../engine/SchematronEngineTest.java | 28 +- .../engine/TemplatesFactoryTest.java | 20 +- .../resources/result/article-1-result.xml | 2 +- .../test/resources/sch/sample-schematron.sch | 1 + components/pom.xml | 1 + 32 files changed, 423 insertions(+), 5613 deletions(-) delete mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/URIResolverImp.java delete mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Constants.java delete mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromRNG.xsl delete mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromXSD.xsl delete mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_abstract_expand.xsl delete mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_dsdl_include.xsl delete mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_message.xsl delete mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl delete mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl delete mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/readme.txt delete mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt1/schematron-skeleton-api.htm delete mode 100644 components/camel-schematron/src/main/resources/iso-schematron-xslt2/catalog-xslt-2.xml diff --git a/components/camel-schematron/README.md b/components/camel-schematron/README.md index 9057bc91d8217..af3b9a77dcfad 100644 --- a/components/camel-schematron/README.md +++ b/components/camel-schematron/README.md @@ -16,6 +16,7 @@ http://www.data2type.de/en/xml-xslt-xslfo/schematron/ http://www.mulberrytech.com/papers/schematron-Philly.pdf +http://www.ldodds.com/papers/schematron_xsltuk.html#c35e2592b6b7 To build this project use diff --git a/components/camel-schematron/pom.xml b/components/camel-schematron/pom.xml index ba8ed8ffebf1b..3c4bd47114653 100644 --- a/components/camel-schematron/pom.xml +++ b/components/camel-schematron/pom.xml @@ -1,45 +1,48 @@ + - + + + org.apache.camel + components + 2.13-SNAPSHOT + 4.0.0 - org.apache.camel camel-schematron bundle - 1.0-SNAPSHOT - - Camel schematron Component - http://www.myorganization.org - + Camel :: SCHEMATRON - UTF-8 - UTF-8 + org.apache.camel.component.schematron.* + org.apache.camel.spi.ComponentResolver;component=schematron - org.apache.camel camel-core - 2.12.1 - - org.slf4j - slf4j-api - 1.7.5 - - - org.slf4j - slf4j-log4j12 - 1.7.5 - test - net.sf.saxon Saxon-HE - 9.5.1-3 + ${saxon-version} net.sf.saxon @@ -47,27 +50,21 @@ 8.7 - log4j - log4j - 1.2.17 - test - - - commons-io - commons-io - 2.4 + xmlunit + xmlunit + ${xmlunit-version} commons-lang commons-lang - 2.6 + ${commons-lang-version} - xmlunit - xmlunit - 1.5 - + commons-io + commons-io + ${commons-io-version} + org.apache.camel @@ -76,48 +73,6 @@ test - - - install - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.5.1 - - 1.6 - 1.6 - - - - - org.apache.maven.plugins - maven-resources-plugin - 2.6 - - UTF-8 - - - - - - org.apache.felix - maven-bundle-plugin - 2.3.7 - true - - - org.apache.camel.camel-schematron - org.apache.camel.spi.ComponentResolver;component=schematron - - - - - - - diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronComponent.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronComponent.java index 15f8ae8bfa431..c1327d458500e 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronComponent.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronComponent.java @@ -1,7 +1,22 @@ +/** + * 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; import java.util.Map; - import org.apache.camel.Endpoint; import org.apache.camel.impl.DefaultComponent; @@ -21,7 +36,7 @@ public class SchematronComponent extends DefaultComponent { * @throws Exception */ protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { - Endpoint endpoint = new SchematronEndpoint(uri,remaining,this); + Endpoint endpoint = new SchematronEndpoint(uri, remaining, this); setProperties(endpoint, parameters); return endpoint; } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java index d2eec356e0369..36243e183f903 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java @@ -1,17 +1,37 @@ +/** + * 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; +import java.io.File; +import java.io.InputStream; +import javax.xml.transform.Templates; import org.apache.camel.Consumer; import org.apache.camel.Processor; import org.apache.camel.Producer; -import org.apache.camel.component.schematron.engine.SchematronEngineFactory; +import org.apache.camel.component.schematron.engine.TemplatesFactory; import org.apache.camel.component.schematron.exception.SchematronConfigException; import org.apache.camel.impl.DefaultEndpoint; import org.apache.camel.util.ResourceHelper; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.InputStream; + + + /** * Schematron Endpoint. @@ -19,9 +39,10 @@ public class SchematronEndpoint extends DefaultEndpoint { private Logger logger = LoggerFactory.getLogger(SchematronEndpoint.class); - private SchematronEngineFactory factory; private String remaining; private boolean abort; + private Templates rules; + public SchematronEndpoint() { } @@ -36,7 +57,7 @@ public SchematronEndpoint(String endpointUri) { } public Producer createProducer() throws Exception { - return new SchematronProducer(this, factory); + return new SchematronProducer(this); } public Consumer createConsumer(Processor processor) throws Exception { @@ -46,37 +67,46 @@ public Consumer createConsumer(Processor processor) throws Exception { public boolean isSingleton() { return true; } + public void setAbort(boolean abort) { this.abort = abort; } + public boolean isAbort() { return abort; } + + public Templates getRules() { + return rules; + } + + public void setRules(Templates rules) { + this.rules = rules; + } + @Override protected void doStart() throws Exception { super.doStart(); - if (factory == null) { - - InputStream rules = null; + if (rules == null) { try { // Attempt to read the schematron rules from the class path first. logger.info("Reading schematron rules from class path {}", remaining); - rules = ResourceHelper.resolveMandatoryResourceAsInputStream - (getCamelContext().getClassResolver(), remaining); + InputStream schRules = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext().getClassResolver(), remaining); + rules = TemplatesFactory.newInstance().newTemplates(schRules); } catch (Exception e) { // Attempts from the file system. logger.info("Schamatron rules not found in class path, attempting file system {}", remaining); - rules = FileUtils.openInputStream(new File(remaining)); + InputStream schRules = FileUtils.openInputStream(new File(remaining)); + rules = TemplatesFactory.newInstance().newTemplates(schRules); } + // rules not found in class path nor in file system. if (rules == null) { logger.error("Schematron rules not found {}", remaining); throw new SchematronConfigException("Failed to load rules: " + remaining); } - factory = SchematronEngineFactory.newInstance(rules); } - } } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java index 51c103dc5aab4..cac817c32c795 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java @@ -1,9 +1,25 @@ +/** + * 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; import org.apache.camel.Exchange; +import org.apache.camel.component.schematron.contant.Constants; import org.apache.camel.component.schematron.engine.SchematronEngineFactory; import org.apache.camel.component.schematron.exception.SchematronValidationException; -import org.apache.camel.component.schematron.util.Constants; import org.apache.camel.component.schematron.util.Utils; import org.apache.camel.impl.DefaultProducer; import org.slf4j.Logger; @@ -13,18 +29,16 @@ * The Schematron producer. */ public class SchematronProducer extends DefaultProducer { - private static final Logger logger = LoggerFactory.getLogger(SchematronProducer.class); + private Logger logger = LoggerFactory.getLogger(SchematronProducer.class); private SchematronEndpoint endpoint; - private SchematronEngineFactory factory; + /** * @param endpoint the schematron endpoint. - * @param factory the schematron factory. */ - public SchematronProducer(final SchematronEndpoint endpoint, final SchematronEngineFactory factory) { + public SchematronProducer(final SchematronEndpoint endpoint) { super(endpoint); this.endpoint = endpoint; - this.factory = factory; } /** @@ -36,12 +50,23 @@ public SchematronProducer(final SchematronEndpoint endpoint, final SchematronEng public void process(Exchange exchange) throws Exception { String payload = exchange.getIn().getBody(String.class); - String report = factory.newScehamtronEngine().validate(payload); + String report = SchematronEngineFactory.newScehamtronEngine(endpoint.getRules()).validate(payload); logger.debug("Schematron validation report \n {}", report); String status = getValidationStatus(report); logger.info("Schematron validation status : {}", status); + setValidationReport(exchange, report, status); + } + + /** + * Sets validation report and status + * + * @param exchange + * @param report + * @param status + */ + private void setValidationReport(Exchange exchange, String report, String status) { // if exchange pattern is In and Out set details on the Out message. if (exchange.getPattern().isOutCapable()) { exchange.getOut().setHeaders(exchange.getIn().getHeaders()); @@ -51,7 +76,6 @@ public void process(Exchange exchange) throws Exception { exchange.getIn().setHeader(Constants.VALIDATION_STATUS, status); exchange.getIn().setHeader(Constants.VALIDATION_REPORT, report); } - } /** diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/ClassPathURIResolver.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/ClassPathURIResolver.java index 1a2572a972dbc..6e05d290b5fdf 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/ClassPathURIResolver.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/ClassPathURIResolver.java @@ -1,29 +1,45 @@ +/** + * 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.engine; +import java.io.File; import javax.xml.transform.Source; import javax.xml.transform.TransformerException; import javax.xml.transform.URIResolver; import javax.xml.transform.stream.StreamSource; -import java.io.File; + /** * Created by akhettar on 26/12/2013. */ public class ClassPathURIResolver implements URIResolver { - private String RULES_DIR; + private String rulesDir; /** * Constructor setter for rules directory path. - * @param RULES_DIR + * @param rulesDir */ - public ClassPathURIResolver(final String RULES_DIR) - { - this.RULES_DIR = RULES_DIR; + public ClassPathURIResolver(final String rulesDir) { + this.rulesDir = rulesDir; } @Override public Source resolve(String href, String base) throws TransformerException { - return new StreamSource(ClassLoader.getSystemResourceAsStream(RULES_DIR.concat(File.separator).concat(href))); + return new StreamSource(ClassLoader.getSystemResourceAsStream(rulesDir.concat(File.separator).concat(href))); } } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java index c70563395705d..e381c4353d0a3 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java @@ -1,21 +1,43 @@ +/** + * 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.engine; +import java.io.StringWriter; +import org.xml.sax.InputSource; import org.apache.camel.component.schematron.exception.SchematronValidationException; import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; - -import javax.xml.transform.*; +import javax.xml.transform.Templates; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.Result; +import javax.xml.transform.Source; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; -import java.io.StringWriter; +import org.xml.sax.XMLReader; + + + /** * The schematoron Engine. Validates an XML for given scheamtron * rules using an XSLT implementation of the Schematron Engine. - * + *

* Created by akhettar on 20/12/2013. */ public class SchematronEngine { @@ -23,7 +45,6 @@ public class SchematronEngine { private Logger logger = LoggerFactory.getLogger(SchematronEngine.class); private XMLReader reader; - private String rules_dir; private Templates templates; @@ -33,10 +54,9 @@ public class SchematronEngine { * @param reader * @param templates */ - public SchematronEngine(XMLReader reader, String rules_dir, Templates templates) { - this.reader = reader; - this.rules_dir = rules_dir; - this.templates = templates; + public SchematronEngine(XMLReader reader, Templates templates) { + this.reader = reader; + this.templates = templates; } @@ -46,24 +66,17 @@ public SchematronEngine(XMLReader reader, String rules_dir, Templates templates) * @param xml * @return */ - public String validate(final String xml) - { - + public String validate(final String xml) { try { final Source source = new SAXSource(reader, new InputSource(IOUtils.toInputStream(xml))); final StringWriter writer = new StringWriter(); final Result result = new StreamResult(writer); final Transformer transformer = templates.newTransformer(); - transformer.setURIResolver(new URIResolverImp(rules_dir)); transformer.transform(source, result); return writer.toString(); - } catch (TransformerException e) { logger.error(e.getMessage()); - throw new SchematronValidationException("Failed to apply schematron validation transform", e); - + throw new SchematronValidationException("Failed to apply Schematron validation transform", e); } } - - } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java index 5fe4c8eaef82e..448718806e536 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java @@ -1,104 +1,81 @@ +/** + * 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.engine; -import com.sun.org.apache.xerces.internal.util.XMLCatalogResolver; -import org.apache.camel.component.schematron.exception.SchematronConfigException; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.xml.sax.EntityResolver; + + +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.Templates; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; - +import org.apache.camel.component.schematron.exception.SchematronConfigException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.transform.Templates; -import java.io.InputStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** + * Schematron Engine Factory + * * Created by akhettar on 22/12/2013. */ public final class SchematronEngineFactory { - private Logger logger = LoggerFactory.getLogger(SchematronEngineFactory.class); - private static SchematronEngineFactory INSTANCE = new SchematronEngineFactory(); - private static final String SCHEMATRON_XSLT_DIR = "iso-schematron-xslt2//"; - private static String catalog; - private static String rules_dir; - private static Templates templates; - + private static final Logger LOG = LoggerFactory.getLogger(SchematronEngineFactory.class); - /** - * Singleton instance - * - * @return - */ - public static SchematronEngineFactory newInstance(final InputStream rules) { - templates = TemplatesFactory.newInstance(rules).newTemplates(); - return INSTANCE; + private SchematronEngineFactory() { + throw new IllegalStateException(); } - /** - * Singleton instance for given catalogs and rule directory. - * - * @param catalogs - * @return - */ - public static SchematronEngineFactory newInstance(final String catalogs, final String ruleDir) { - catalog = catalog; - rules_dir = ruleDir; - return INSTANCE; - } /** * Creates an instance of SchematronEngine * - * @return an instance of SchematronEngine + * @param rules the given schematron rules + * @return an instance of SchematronEngine */ - public SchematronEngine newScehamtronEngine() { + public static SchematronEngine newScehamtronEngine(final Templates rules) { try { - - EntityResolver resolver = catalog == null ? null : getResolver(catalog); - return new SchematronEngine(getXMLReader(resolver), rules_dir, templates); + return new SchematronEngine(getXMLReader(), rules); } catch (ParserConfigurationException e) { - logger.error("Failed to parse the configuration file"); + LOG.error("Failed to parse the configuration file"); throw new SchematronConfigException(e); } catch (SAXException e) { - logger.error("Failed to parse the configuration file"); + LOG.error("Failed to parse the configuration file"); throw new SchematronConfigException(e); } } /** - * @param resolver - * @return + * Gets XMLReader. + * + * @return instance of XMLReader * @throws ParserConfigurationException * @throws SAXException */ - private XMLReader getXMLReader(EntityResolver resolver) throws ParserConfigurationException, SAXException { + private static XMLReader getXMLReader() throws ParserConfigurationException, SAXException { final SAXParserFactory fac = SAXParserFactory.newInstance(); fac.setValidating(false); final SAXParser parser = fac.newSAXParser(); XMLReader reader = parser.getXMLReader(); - if (resolver != null) - { - reader.setEntityResolver(resolver); - } + //reader.setEntityResolver(null); return reader; } - /** - * Creates an instance of Entity Resolver from given catalog. - * - * @param catlogs - * @return - */ - private EntityResolver getResolver(String catlogs) { - - XMLCatalogResolver resolver = new XMLCatalogResolver(StringUtils.split(catlogs, ",")); - resolver.setPreferPublic(true); - return resolver; - - } } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java index 73e879a2db8cd..0a61b7082b9cb 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java @@ -1,12 +1,34 @@ +/** + * 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.engine; -import net.sf.saxon.lib.FeatureKeys; + +import net.sf.saxon.FeatureKeys; +import org.apache.camel.component.schematron.contant.Constants; import org.apache.camel.component.schematron.exception.SchematronConfigException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Node; - -import javax.xml.transform.*; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.Templates; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamSource; @@ -14,49 +36,44 @@ import java.io.InputStream; /** + * Class generating Templates for given schematron rules + * * Created by akhettar on 20/12/2013. */ public final class TemplatesFactory { - + private static final TemplatesFactory INSTANCE = new TemplatesFactory(); + private String[] pipeline = new String[]{"iso_dsdl_include.xsl", "iso_abstract_expand.xsl", "iso_svrl_for_xslt2.xsl"}; private Logger logger = LoggerFactory.getLogger(TemplatesFactory.class); - private static TemplatesFactory fac; - private static final String ROOT_DIR = "iso-schematron-xslt2"; - private static final String[] PIPELINE = new String[]{"iso_dsdl_include.xsl", "iso_abstract_expand.xsl", "iso_svrl_for_xslt2.xsl"}; - private Templates templates; - /** - * Creates singleton instance of the templates factory + * Singleton constructor; * - * @param rules the path to the rules file: can be either class or file based path. * @return */ - public static TemplatesFactory newInstance(InputStream rules) { - - if (fac != null) { - return fac; - } - return new TemplatesFactory(rules); + public static TemplatesFactory newInstance() { + return INSTANCE; } /** - * private constructor. + * Returns an instance of compiled schematron templates. * - * @param rules + * @return */ - private TemplatesFactory(InputStream rules) { + public Templates newTemplates(final InputStream rules) { // create new instance. + Templates templates; TransformerFactory fac = TransformerFactory.newInstance(); - fac.setURIResolver(new ClassPathURIResolver(ROOT_DIR)); + fac.setURIResolver(new ClassPathURIResolver(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR)); fac.setAttribute(FeatureKeys.LINE_NUMBERING, true); Node node = null; Transformer t = null; Source source = new StreamSource(rules); try { - for (String template : PIPELINE) { - Source xsl = new StreamSource(ClassLoader.getSystemResourceAsStream(ROOT_DIR.concat(File.separator).concat(template))); + for (String template : pipeline) { + Source xsl = new StreamSource(ClassLoader.getSystemResourceAsStream(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR + .concat(File.separator).concat(template))); t = fac.newTransformer(xsl); DOMResult result = new DOMResult(); t.transform(source, result); @@ -70,15 +87,7 @@ private TemplatesFactory(InputStream rules) { logger.error(e.getMessage(), e); throw new SchematronConfigException(e); } - - } - - /** - * Returns an instance of compiled schematron templates. - * - * @return - */ - public Templates newTemplates() { return templates; } + } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/URIResolverImp.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/URIResolverImp.java deleted file mode 100644 index d99be1ce814bb..0000000000000 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/URIResolverImp.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apache.camel.component.schematron.engine; - -import javax.xml.transform.Source; -import javax.xml.transform.TransformerException; -import javax.xml.transform.URIResolver; -import javax.xml.transform.stream.StreamSource; -import java.io.File; - -/** - * Created by akhettar on 22/12/2013. - */ -public class URIResolverImp implements URIResolver { - - - private String RULES_DIR; - - /** - * Constructor setter for rules directory path. - * @param RULES_DIR - */ - public URIResolverImp(final String RULES_DIR) - { - this.RULES_DIR = RULES_DIR; - } - - @Override - public Source resolve(String href, String base) throws TransformerException { - return new StreamSource(new File(RULES_DIR.concat(File.separator).concat(href))); - } -} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java index 6b35fd4cec598..b2a355a34d84a 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java @@ -1,9 +1,23 @@ +/** + * 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.exception; import org.apache.camel.RuntimeCamelException; -import javax.xml.transform.TransformerConfigurationException; - /** * Created by akhettar on 22/12/2013. */ diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java index a45824d27a175..ba50df44ddf4b 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java @@ -1,3 +1,19 @@ +/** + * 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.exception; import org.apache.camel.RuntimeCamelException; @@ -10,9 +26,8 @@ public class SchematronValidationException extends RuntimeCamelException { - public SchematronValidationException(final String message, Throwable e) - { - super(message,e); + public SchematronValidationException(final String message, Throwable e) { + super(message, e); } public SchematronValidationException(String message) { diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Constants.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Constants.java deleted file mode 100644 index 6f1c122e6341d..0000000000000 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Constants.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.apache.camel.component.schematron.util; - -/** - * Utility class defining all constants needed for the schematron component. - * - * Created by akhettar on 29/12/2013. - */ -public final class Constants { - - public static final String XSLT_VERSION_2_0 = "2.0"; - public static final String VALIDATION_STATUS = "CamelSchValidationStatus"; - public static final String HTTP_PURL_OCLC_ORG_DSDL_SVRL = "http://purl.oclc.org/dsdl/svrl"; - public static final String FAILED_ASSERT = "failed-assert"; - public static final String FAILED = "FAILED" ; - public static final String SUCCESS = "SUCCESS" ; - public static final String VALIDATION_REPORT = "CamelSchValidationReport"; -} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java index 48d7a6f2b3ee8..c9da487d62e56 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java @@ -1,14 +1,29 @@ +/** + * 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.util; -import org.apache.camel.Exchange; import org.apache.camel.RuntimeCamelException; +import org.apache.camel.component.schematron.contant.Constants; import org.apache.commons.lang.StringUtils; import org.custommonkey.xmlunit.SimpleNamespaceContext; import org.custommonkey.xmlunit.XMLUnit; import org.custommonkey.xmlunit.XpathEngine; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import java.util.HashMap; import java.util.Map; @@ -19,8 +34,11 @@ */ public final class Utils { - private static final Logger logger = LoggerFactory.getLogger(Utils.class); + private static final Logger LOG = LoggerFactory.getLogger(Utils.class); + private Utils() { + throw new IllegalStateException("This is a utility class"); + } /** * Evaluate an XPATH expression. @@ -40,7 +58,7 @@ public static String evaluate(final String xpath, final String xml) { try { return xpathEngine.evaluate(xpath, XMLUnit.buildControlDocument(xml)); } catch (Exception e) { - logger.error("Failed to apply xpath {} on xml {}", xpath, xml); + LOG.error("Failed to apply xpath {} on xml {}", xpath, xml); throw new RuntimeCamelException(e); } } @@ -48,12 +66,12 @@ public static String evaluate(final String xpath, final String xml) { /** * Get validation status SUCCESS OR FAILURE if there are any schematron validation errors. + * * @param report * @return */ - public static String getValidationStatus(final String report) - { + public static String getValidationStatus(final String report) { return StringUtils.contains(report, - Constants.FAILED_ASSERT)? Constants.FAILED : Constants.SUCCESS; + Constants.FAILED_ASSERT) ? Constants.FAILED : Constants.SUCCESS; } } diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromRNG.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromRNG.xsl deleted file mode 100644 index 0f996f40f9a32..0000000000000 --- a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromRNG.xsl +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromXSD.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromXSD.xsl deleted file mode 100644 index 5857b3ee2fbab..0000000000000 --- a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/ExtractSchFromXSD.xsl +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_abstract_expand.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_abstract_expand.xsl deleted file mode 100644 index f2f1667120aa2..0000000000000 --- a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_abstract_expand.xsl +++ /dev/null @@ -1,297 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Suppressed abstract pattern was here - - - - - - - Start pattern based on abstract - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_dsdl_include.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_dsdl_include.xsl deleted file mode 100644 index ad757e24a10a2..0000000000000 --- a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_dsdl_include.xsl +++ /dev/null @@ -1,1509 +0,0 @@ - - - - - - - - - - true - true - true - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Error: Impossible URL in RELAX NG extRef - include - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - - - Unable to locate id attribute: - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - Unable to locate id attribute: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Error: Impossible URL in Schematron include - - - - - - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - - - - - - - Unable to locate id attribute: - - - - - - - - - - - Schema error: Use include to - include fragments, not a whole - schema - - - - - - - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - - - - Unable to locate id attribute: - - - - - - - - - - Schema error: Use include to include - fragments, not a whole schema - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Error: Impossible URL in Schematron include - - - - - - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - - - - - - - Unable to locate id attribute: - - - - - - - - - - - - - - - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - - - - Unable to locate id attribute: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Error: Impossible URL in Schematron include - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - - - Schema error: Use include to include - fragments, not a whole schema - - - - - Unable to locate id attribute: - - - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - Schema error: Use include to include - fragments, not a whole schema - - - - - Unable to locate id attribute: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Error: Impossible URL in DTLL include - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - - - Unable to locate id attribute: - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - Unable to locate id attribute: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Error: Impossible URL in CRDL include - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - - - - Unable to locate id attribute: - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - Unable to locate id attribute: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Fatal error: Xinclude href contains fragment - identifier # - - - - - - - Fatal error: Sorry, this software only - supports simple ids in XInclude xpointers - - - - - - - Fatal Error: Impossible URL in XInclude - include - - - - - - - - - - - - - - - - - - - - - - - - - - - Unable to open referenced included file and fallback - file: - - - - - - - Unable to open referenced included file: - - - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Error: Impossible URL in XLink embedding - link - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - - - Unable to locate id attribute: - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - Unable to locate id attribute: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - XPath error. No XPath. - XPath error. Missing location step. Suggestion: remove '/' before '['. - - - XPath syntax error. Unclosed parenthesis. Suggestion: add ')'. - - XPath syntax error. Extra close parenthesis. Suggestion: remove ')'. - - - XPath syntax error. Unclosed left square bracket. Suggestion: add ']'. - - XPath syntax error. Extra right square bracket. Suggestion: remove ']'. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_message.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_message.xsl deleted file mode 100644 index 8a273bafb5684..0000000000000 --- a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_message.xsl +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - ( - / - ) - - - \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl deleted file mode 100644 index e337cbfdecf94..0000000000000 --- a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl +++ /dev/null @@ -1,1844 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #ALL - - - -false - -true - - - - - true - false - - - - - - - true - false - - - - - - - - - @*| - - * - node() - *|comment()|processing-instruction() - - - - - - - - - -false - - - - - -default - -false - - - -1 - - - - - Schema error: Schematron elements in old and new namespaces found - - - - - - - - - - - - - - - - - Schema error: in the queryBinding attribute, use 'xslt' - - - - - 1.0 - - - - - - - - - This XSLT was automatically generated from a Schematron schema. - - - - - 1.0 - - - - - - - - - - Fail: This implementation of ISO Schematron does not work with - schemas using the "" query language. - - - - - Implementers: please note that overriding process-prolog or process-root is - the preferred method for meta-stylesheets to use where possible. - - - - - - - - - - PHASES - - PROLOG - - KEYS - - DEFAULT RULES - - SCHEMA METADATA - - SCHEMATRON PATTERNS - - - - - - - - - - - - - - - - - - - - - - - Phase Error: no phase with name has been defined. - - - - - - - MODE: SCHEMATRON-SELECT-FULL-PATH - This mode can be used to generate an ugly though full XPath for locators - - - - - - - - - - - - - - - - - - - - - - - - - MODE: SCHEMATRON-FULL-PATH - This mode can be used to generate an ugly though full XPath for locators - - - - - - / - - - - - - [] - - - - *[local-name()=' - ' and namespace-uri()=' - - '] - - - [] - - - - - - - - - - / - - @ - - @*[local-name()=' - - ' and namespace-uri()=' - - '] - - - - - - - - - MODE: SCHEMATRON-FULL-PATH-2 - - This mode can be used to generate prefixed XPath for humans - - - - - - / - - - [ - - ] - - - - - /@ - - - - - MODE: GENERATE-ID-FROM-PATH - - - - - - - - - - - - - - - - - - - - - - . - - - - - - - MODE: SCHEMATRON-FULL-PATH-3 - - - This mode can be used to generate prefixed XPath for humans - (Top-level element has index) - - - - - - / - - - [ - - ] - - - - - /@ - - - - - MODE: GENERATE-ID-2 - - - U - - - U - - - - - U. - - n - - - - - U. - - _ - - _ - - - - - Strip characters - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Markup Error: no pattern attribute in <active> - - - - Reference Error: the pattern "" has been activated but is not declared - - - - - - - - Markup Error: no test attribute in <assert - - - ASSERT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Markup Error: no test attribute in <report> - - - - REPORT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Markup Error: no id attribute in <diagnostic> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Markup Error: no rule attribute in <extends> - - - Reference Error: the abstract rule "" has been referenced but is not declared - - - - - - - - - - - - - - Markup Error: no name attribute in <key> - - - Markup Error: no path or use attribute in <key> - - - - - - - - - - - - - - - - Markup Error: no path or use attribute in <key> - - - - - - - - - - - - Schema error: The key element is not in the ISO Schematron namespace. Use the XSLT namespace. - - - - - - - - Schema error: Empty href= attribute for include directive. - - - - - - - - - - - - - - Error: Impossible URL in Schematron include - - - - - - - Schema error: Use include to include fragments, not a whole schema - - - - - - - - - - Schema error: Use include to include fragments, not a whole schema - - - - - - - - - - - - - - - Error: Impossible URL in Schematron include - - - - - - - Schema error: Use include to include fragments, not a whole schema - - - - - - - - - - - Schema error: Use include to include fragments, not a whole schema - - - - - - - - - - Warning: Variables should not be used with the "xpath" query language binding. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Markup Error: no uri attribute in <ns> - - - Markup Error: no prefix attribute in <ns> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //( - - ( - - ) - | - - ) - [not(self::text())] - - - - - - - - - - - - - Schema implementation error: This schema has abstract patterns, yet they are supposed to be preprocessed out already - - - - - - - - - - PATTERN - - - - - - - - - - - - - - - - - - - - Markup Error: no id attribute in <phase> - - - - - - - - Markup Error: no context attribute in <rule> - - - RULE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Markup Error: no id attribute on abstract <rule> - - - Markup Error: (2) context attribute on abstract <rule> - - - - - - Markup Error: context attribute on abstract <rule> - - - - - - - - - - - - - - - - - - - - - - - - - - - Markup Error: no select attribute in <value-of> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Warning: - - must not contain any child elements - - - - - - - - - - - - - - - - - - - - - - - - - Reference error: A diagnostic "" has been referenced but is not declared - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Using the XSLT namespace with a prefix other than "xsl" in - Schematron rules is not supported - in this processor: - - - - - - - - - - - - - - - - - - - - Error: unrecognized element in ISO Schematron namespace: check spelling - and capitalization - - - - - - - - - - - - - Warning: unrecognized element - - - - - - - - - - - - - - - Warning: unrecognized element - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TERMINATING - - - TERMINATING - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TERMINATING - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - title - - - - - - - schema-title - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl deleted file mode 100644 index 614649f0f32d3..0000000000000 --- a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl +++ /dev/null @@ -1,605 +0,0 @@ - - - - - - - - - - - - - - - - -true - - - - - - - - - - - #ALL - - -false -true -true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - xslt1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   -   -   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TERMINATING - - - TERMINATING - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TERMINATING - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/readme.txt b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/readme.txt deleted file mode 100644 index 685c92e398e82..0000000000000 --- a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/readme.txt +++ /dev/null @@ -1,101 +0,0 @@ -

ISO SCHEMATRON 2010

- -XSLT implementation by Rick Jelliffe with assistance from members of Schematron-love-in maillist. - -2010-04-21 - -Two distributions are available. One is for XSLT1 engines. -The other is for XSLT2 engines, such as SAXON 9. - - -This version of Schematron splits the process into a pipeline of several different XSLT stages. - -1) First, preprocess your Schematron schema with iso_dsdl_include.xsl. -This is a macro processor to assemble the schema from various parts. -If your schema is not in separate parts, you can skip this stage. -This stage also generates error messages for some common XPath syntax problems. - -2) Second, preprocess the output from stage 1 with iso_abstract_expand.xsl. -This is a macro processor to convert abstract patterns to real patterns. -If your schema does not use abstract patterns, you can skip this -stage. - -3) Third, compile the Schematron schema into an XSLT script. -This will typically use iso_svrl_for_xslt1.xsl or iso_svrl_for_xslt2.xsl -(which in turn invoke iso_schematron_skeleton_for_xslt1.xsl or iso_schematron_skeleton_for_saxon.xsl) -However, other "meta-styleseets" are also in common use; the principle of operation is the same. -If your schema uses Schematron phases, supply these as command line/invocation parameters -to this process. - -4) Fourth, run the script generated by stage 3 against the document being validated. -If you are using the SVRL script, then the output of validation will be an XML document. -If your schema uses Schematron parameters, supply these as command line/invocation parameters -to this process. - - -The XSLT2 distribution also features several next generation features, -such as validating multiple documents. See the source code for details. - -Schematron assertions can be written in any language, of course; the file -sch-messages-en.xhtml contains the diagnostics messages from the XSLT2 skeleton -in English, and this can be used as template to localize the skeleton's -error messages. Note that typically programming errors in Schematron are XPath -errors, which requires localized messages from the XSLT engine. - -ANT ---- -To give an example of how to process a document, here is a sample ANT task. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -EXTRACTION SCHEMATRON FROM XSD OR RELAX NG - -The following files allow extracting of embedded schematron patterns -in XML Schemas or RELAX NG schemas. For details, see the at - article http://www.topologi.com/resources/schtrn_xsd_paper.html - -The following files are provided: - ExtractSchFromRNG.xsl Generate a Schematron schema from patterns - embedded in a RELAX NG schema. The schema uses XSLT1. - ExtractSchFromXSD.xsl Generate a Schematron schema from patterns - embedded in a W3C XML Schemas schema. The schema uses XSLT1. - - ExtractSchFromRNG-2.xsl Generate a Schematron schema from patterns - embedded in a RELAX NG schema. The schema uses XSLT2. - ExtractSchFromXSD-2.xsl Generate a Schematron schema from patterns - embedded in a W3C XML Schemas schema. The schema uses XSLT2. \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/schematron-skeleton-api.htm b/components/camel-schematron/src/main/resources/iso-schematron-xslt1/schematron-skeleton-api.htm deleted file mode 100644 index af8137783f7e4..0000000000000 --- a/components/camel-schematron/src/main/resources/iso-schematron-xslt1/schematron-skeleton-api.htm +++ /dev/null @@ -1,723 +0,0 @@ - - - - - The ISO Schematron Skeleton API - - - - - -

API for ISO Schematron Skeleton

-



-

-

Rick Jelliffe, 2010/04/14

-

This document provides documentation on the XSLT API available in -the implementation of Schematron called iso_schematron_skeleton.xsl. -(available in an XSLT1 and XSLT2 version). The API makes available as -much information from the schema, however there may be some edge -cases where it is not exhaustive. -

-

The skeleton is an XSLT script which provides all the basic -parsing and validating routines for compiling a Schematron schema -into XSLT. Schematron was designed to allow many different uses, and -the skeleton gives you a headstart in creating a customized -implementation. You just need to write XSLT templates to override the -default ones. (The program you write is sometimes called a -meta-stylesheet.) It is the meta-stylesheet that is called -as the XSLT script, not the skeleton. There are several -pre-processing stages which the Schematron schema should be processed -through first, to handle such things as include statements and -abstract patterns. -

-

Phases and error reporting for problems in the schema itself are -handled by the skeleton with no interaction with a “meta-stylesheet”. -Note that there is no guarantee that the context node is always the -element being handled: in most cases the only information available -is the information in the parameters. -

-

For an introductory tutorial on using this API, see Bob DuCharme's -Schematron 1.5: -Looking Under the Hood -

-

Superset of API for Schematron 1.5 and 1.6

-

(This is an updated version of the API for the Schematron 1.5 -implementation called skeleton1-5.xsl, which in turn comes -from the new architecture contributed by Oliver Becker for -Schematron 1.3.)

-

The current API contains only additions. Well-written -meta-stylesheets that use the new API will be be able to run on the -existing 1.5 and 1.6 skeletons. Similarly, it should be possible to -upgrade the skeleton from 1.5 or 1.6 to the iso-schematron-skeleton -only by correcting the import statement at the beginning of the -meta-stylsheet. Additions or re-groupings from the 1.5 schema are -shown in red. Deletions have overstrike.

-

Mooted addition: a parameter @action which for specifying -processing instructions on assertions and reports.

-
-

process-prolog

-

The process-prolog template gets called at the start of -the validation session. It has no parameters. The default -implementation is no action.

-
-

process-root

-

The process-root template processes the root element of -the schema (which is not the same thing as the root of the document / -and need not be the document element /*) .

-
-
node-list $contents -
- string $schemaVersion -
- The version of the schema, perhaps a datestamp. -
- "xslt" | "xpath" | - "xslt2" | ... - $queryBinding -
- The query language binding. -
- string $title -
- The title of this schema -
- "iso" | "1.5" | - "1.6" | ... - $version -
- The version of Schematron being used. -
-

-Rich properties:

-
-
XML SystemId - $icon -
- The URI of an icon -
- XML ID - $id -
- The unique identifier with the schema for the - schema - element. -
- SGML FPI - $fpi -
- The Formal Public Identifier for this schema. -
- IETF language - $lang -
- The human language used in this schema, from - xml:lang -
- URL - $see -
- Link to documentation on WWW or file -
- "preserve" | "default" - $space -
- The value for xml:space -
-

-To print the documentation paragraphs, use <xsl:apply-templates -mode="do-schema-p" />

-

To output the results, use <xsl:copy-of select="$contents" -/>

-
-

process-assert

-

The process-assert template handles asserts whose test -has failed. -

-
-
XPath $test -
- The test -
- XML IDREFS $diagnostics -
- A list of the idrefs diagnostic elements related to the current - assertion -
- XML NMTOKEN - $flag -
- The name of a flag that becomes true because - this assertion fails. The flag is true for the document if it is - flagged true on any assertion. For compatability, this parameter - should not be used with Schematron 1.5. -
-

-Rich properties:

-
-
XML SystemId - $icon -
- The URI of an icon -
- XML ID - $id -
- The unique identifier with the schema for the - assert - element. -
- SGML FPI - $fpi -
- The Formal Public Identifier for this - assertion. -
- IETF language - $lang -
- The human language used in this assertion, - from xml:lang -
- URL - $see -
- Link to documentation on WWW or file -
- "preserve" | "default" - $space -
- The value for xml:space -
-

-Linking properties:

-
-
XML NMTOKEN - $role -
- A name for the generic role of this assertion. - The schema creator would have their own vocabulary. -
- XPath - $subject -
- A path relative to the current context to some - interesting node considered the subject. -
-

-To print the text contents, use <xsl:apply-templates -mode="text" />

-
-

process-diagnostic

-

The process-diagnostic template handles diagnostic -messages for assert statements that have failed and report -statements that have succeeded. The diagnostics are evaluated in the -context of the rule.

-

Rich properties:

-
-
XML SystemId - $icon -
- The URI of an icon -
- XML ID - $id -
- The unique identifier with the schema for the - assert - element. -
- SGML FPI - $fpi -
- The Formal Public Identifier for this - assertion. -
- IETF language - $lang -
- The human language used in this assertion, - from xml:lang -
- URL - $see -
- Link to documentation on WWW or file -
- "preserve" | "default" - $space -
- The value for xml:space -

-
-

process-dir

-

The process-dir template handles bi-directionality -markup, which is only needed by certain human scripts such as Arabic.

-
-
"ltr" or "rtl" or "" - $value -
- Left-to-right or right-to-left or unspecified -

-
-

process-emph

-

The process-emph template handles the markup of -emphasized text in paragraphs, assertions and diagnostics. It has no -parameters.

-
-

process-message

-

The process-message handles default outputing of text.

-
-
string $pattern -
- Some text that may be some kind of pattern -
- string $role -
- Some text that may be some kind of role -

-
-

process-name

-

The process-name templates handle name strings that can -be used in assertions. asssert and report only -provide name subelements rather than the more general -value-of elements to encourage plain language and generic -descriptions rather than specific diagnostics, for which purpose the -diagnostics elements are used.

-
-
string $name -
- The name of the current element, or of the node specified by a name - element -

-
-

process-ns

-

The process-ns template reports on ns -declarations, which are used to transmit on namespace information by -the skeleton.

-
-
Namespace NCName $prefix -
- The prefix of a namespace -
- XML SystemId $uri -
- The (internationalized) URI Reference of a namespace -

-
-

process-p

-

The process-p template handles paragraphs.

-
-
XML NMTOKEN $class -
- An attribute that can be used for stylesheet style -
- XML ID $id -
- The unique identifier with the schema for the p element. -
- XML SystemId $icon -
- The URI of an icon -
- IETF Language $lang -
- The human language used in this paragraph -
-

-To print the text contents, use <xsl:apply-templates -mode="text" /> -

-
-

process-pattern

-

The process-pattern reports on the start of evaluation of -a pattern element.

-
-
string $name -
- The title of the current pattern -
- XML NCNAMES $is-a -
- Empty or not provided if the pattern is not derived from an abstract - pattern. Otherwise the name of the abstract pattern. A list may be - used if there was a sequence of abstract patterns. -
-

-Rich properties:

-
-
XML SystemId - $icon -
- The URI of an icon -
- XML ID - $id -
- The unique identifier with the schema for the - pattern - element. -
- SGML FPI - $fpi -
- The Formal Public Identifier for this pattern. - -
- IETF language - $lang -
- The human language used in this pattern, from - xml:lang -
- URL - $see -
- A (internationalized) URI reference to some - supporting or defining documentation -
- "preserve" | "default" - $space -
- The value for xml:space -
-

-To print the documentation contents, use <xsl:apply-templates -mode="do-pattern-p"/>

-
-

process-report

-

The process-report template handles report whose -test has succeeded. -

-
-
XPath $test -
- The test -
- XML IDREFS $diagnostics -
- A list of the diagnostic elements related to the current assertion -
- XML NMTOKEN - $flag -
- The name of a flag that becomes true because - this assertion fails. The flag is true for the document if it is - flagged true on any assertion. For compatability, this parameter - should not be used with Schematron 1.5. -
-

-Rich properties:

-
-
XML SystemId - $icon -
- The URI of an icon -
- XML ID - $id -
- The unique identifier with the schema for the - report - element. -
- SGML FPI - $fpi -
- The Formal Public Identifier for this report. -
- IETF language - $lang -
- The human language used in this report, from - xml:lang -
- URL - $see -
- Link to documentation on WWW or file -
- "preserve" | "default" - $space -
- The value for xml:space -
-

-Linking properties:

-
-
XML NMTOKEN - $role -
- A name for the generic role of this assertion. - The schema creator would have their own vocabulary. -
- XPath - $subject -
- A path relative to the current context to some - interesting node considered the subject. -
-

-To print the text contents, use <xsl:apply-templates -mode="text" />

-
-

process-rule

-

The process-rule reports that a rule element has -fired: its context attribute matched some nodes. .

-
-
XSLT expression $context -
- The expression that gives the context of the current -
-

-Rich properties:

-
-
XML SystemId - $icon -
- The URI of an icon -
- XML ID - $id -
- The unique identifier with the schema for this - rule - element. -
- SGML FPI - $fpi -
- The Formal Public Identifier for this rule. -
- IETF language - $lang -
- The human language used in this rule, from - xml:lang -
- URL - $see -
- Link to documentation on WWW or file -
- "preserve" | "default" - $space -
- The value for xml:space -
-

-Linking properties:

-
-
XML NMTOKEN - $role -
- A name for the generic role of this assertion. - The schema creator would have their own vocabulary. -
- XPath - $subject -
- A path relative to the current context to some - interesting node considered the subject. -

-
-

process-span

-

The process-span handles span elements, which are generic -elements for styling, like HTML's .

-
-
XML NMTOKEN $class -
- An attribute that can be used for stylesheet style -

-
-

process-title

-

The process-title handles title elements, which are -generic elements for styling, like HTML's .

-
-
XML NMTOKEN $class -
- An attribute that can be used for stylesheet style -
-

-By default, titles are handled by invocing process-p with -the parameter class with a value "title".

-
-

process-value-of

-

The process-value-of template handles value-of -elements, which are used in diagnostic messages to allow very -specific hinting .

-
-
XPath $select -
- The path of some node that will be evaluated and printed.

-
-

Global Parameters

-

There are several global parameters that may be available for use. -However, it is not a requirement to follow these, and implementations -may not supply them with any value. So a test of -string-length(variable) < -0 is appropriate in each case.

-



-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

Parameter

-
-

Value

-
-

Description

-
-

allow-foreign

-
-

"true" | "false" (default) -

-
-

Pass non-Schematron elements to the generated - stylesheet. Pass the Schematron elements span, emph and dir: to - the output SVRL. -

-
-

fileNameParameter

-
-

string

-
-

A parameter passed to the Validator and - potentially available as a variable in Schematron schemas as - $fileNameParameter

-
-

fileDirParameter

-
-

string

-
-

A parameter passed to the Validator and - potentially available as a variable in Schematron schemas as - $fileDirParameter

-
-

archiveNamePaameter

-
-

string

-
-

A parameter passed to the Validator and - potentially available as a variable in Schematron schemas as - $archiveNameParameter

-
-

archiveDirParameter

-
-

string

-
-

A parameter passed to the Validator and - potentially available as a variable in Schematron schemas as - $archivePathParameter

-
-

debug -

-
-

true” | “false” (default)

-
-

Verbose error messages (Note this may be - superceded by “verbose” at some stage in the future.)

-
-

generate-paths

-
-

true|false -

-
-

generate the SVRL @location attribute with XPaths

-
-

diagnose

-
-

yes | no -

-
-

Add the diagnostics to the assertion results

-
-

terminate

-
-

yes | no | true | false | assert -

-
-

Terminate on the first failed assertion or - successful report

-
-

message-newline -

-
-

"true" (default) | "false" -

-
-

Generate an extra newline at the end of messages

-
-

output-encoding

-
-

string

-
-

The encoding used for output, for example if the - output is XML

-
-
-
-
- - \ No newline at end of file diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/catalog-xslt-2.xml b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/catalog-xslt-2.xml deleted file mode 100644 index cd093f1c5a5f1..0000000000000 --- a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/catalog-xslt-2.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - catalog.xml: - - - - - \ No newline at end of file diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java index 1025c24242c5f..ff69d5192338c 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java @@ -1,8 +1,24 @@ +/** + * 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; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.component.schematron.util.Constants; +import org.apache.camel.component.schematron.contant.Constants; import org.apache.camel.component.schematron.util.Utils; import org.apache.camel.test.junit4.CamelTestSupport; import org.apache.commons.io.IOUtils; diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java index 0f76ab7a0508a..7c7afa6fe5368 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java @@ -1,3 +1,19 @@ +/** + * 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; @@ -6,17 +22,12 @@ import org.apache.camel.ExchangePattern; import org.apache.camel.Producer; import org.apache.camel.component.schematron.exception.SchematronValidationException; -import org.apache.camel.component.schematron.util.Constants; +import org.apache.camel.component.schematron.contant.Constants; import org.apache.camel.impl.DefaultExchange; import org.apache.camel.test.junit4.CamelTestSupport; - import org.apache.commons.io.IOUtils; import org.junit.Test; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; - /** * Created by akhettar on 20/12/2013. */ @@ -26,7 +37,6 @@ public class SchematronEndpointTest extends CamelTestSupport { @Test public void testSchematronFileReadFromClassPath()throws Exception { - String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml")); Endpoint endpoint = context().getEndpoint("schematron://sch/sample-schematron.sch"); Producer producer = endpoint.createProducer(); @@ -44,7 +54,6 @@ public void testSchematronFileReadFromClassPath()throws Exception { @Test public void testSchematronFileReadFromFileSystem()throws Exception { - String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); String path = ClassLoader.getSystemResource("sch/sample-schematron.sch").getPath(); Endpoint endpoint = context().getEndpoint("schematron://" + path); @@ -61,8 +70,7 @@ public void testSchematronFileReadFromFileSystem()throws Exception { } @Test(expected = SchematronValidationException.class) - public void testThrowSchematronValidationException() throws Exception - { + public void testThrowSchematronValidationException() throws Exception { String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); Endpoint endpoint = context().getEndpoint("schematron://sch/sample-schematron.sch?abort=true"); Producer producer = endpoint.createProducer(); diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java index b8490f86d081a..d1ba8d8c93ef4 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java @@ -1,14 +1,30 @@ +/** + * 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; import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; -import org.apache.camel.component.schematron.engine.SchematronEngineFactory; -import org.apache.camel.component.schematron.exception.SchematronValidationException; -import org.apache.camel.component.schematron.util.Constants; +import org.apache.camel.component.schematron.contant.Constants; +import org.apache.camel.component.schematron.engine.TemplatesFactory; import org.apache.camel.impl.DefaultExchange; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.BeforeClass; import org.junit.Test; +import javax.xml.transform.Templates; /** * Schematron Producer Unit Test. @@ -21,10 +37,11 @@ public class SchematronProducerTest extends CamelTestSupport { @BeforeClass public static void setUP() { - SchematronEngineFactory fac = SchematronEngineFactory.newInstance(ClassLoader. - getSystemResourceAsStream("sch/sample-schematron.sch")); SchematronEndpoint endpoint = new SchematronEndpoint(); - producer = new SchematronProducer(endpoint, fac); + Templates templates = TemplatesFactory.newInstance().newTemplates(ClassLoader. + getSystemResourceAsStream("sch/sample-schematron.sch")); + endpoint.setRules(templates); + producer = new SchematronProducer(endpoint); } @Test diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java index e7c3b68528262..e03866e6d8341 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java @@ -1,3 +1,19 @@ +/** + * 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.engine; import org.apache.camel.component.schematron.util.Utils; @@ -7,9 +23,7 @@ import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; import org.junit.BeforeClass; import org.junit.Test; - -import java.io.InputStream; - +import javax.xml.transform.Templates; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; @@ -22,8 +36,8 @@ public class SchematronEngineTest { @BeforeClass public static void setUP() { - InputStream rules = ClassLoader.getSystemResourceAsStream("sch/sample-schematron.sch"); - engine = SchematronEngineFactory.newInstance(rules).newScehamtronEngine(); + Templates rules = TemplatesFactory.newInstance().newTemplates(ClassLoader.getSystemResourceAsStream("sch/sample-schematron.sch")); + engine = SchematronEngineFactory.newScehamtronEngine(rules); } @Test @@ -49,8 +63,8 @@ public void testInValidXML() throws Exception { String result = engine.validate(payload); // should throw two assertions because of the missing chapters in the XML. - assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert [@location='/doc[1]/chapter[1]']/svrl:text", result)); - assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert [@location='/doc[1]/chapter[2]']/svrl:text", result)); + assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert/svrl:text", result)); + } } diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/TemplatesFactoryTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/TemplatesFactoryTest.java index 76b990e87878e..deca278a04da0 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/TemplatesFactoryTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/TemplatesFactoryTest.java @@ -1,3 +1,19 @@ +/** + * 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.engine; import org.junit.Assert; @@ -17,8 +33,8 @@ public class TemplatesFactoryTest { public void testInstantiateAnInstanceOfTemplates() throws Exception { - TemplatesFactory fac = TemplatesFactory.newInstance(ClassLoader.getSystemResourceAsStream(rules)); - Templates templates = fac.newTemplates(); + TemplatesFactory fac = TemplatesFactory.newInstance(); + Templates templates = fac.newTemplates(ClassLoader.getSystemResourceAsStream(rules)); Assert.assertNotNull(templates); diff --git a/components/camel-schematron/src/test/resources/result/article-1-result.xml b/components/camel-schematron/src/test/resources/result/article-1-result.xml index ec0670c75f45f..d02a4bf8b01c9 100644 --- a/components/camel-schematron/src/test/resources/result/article-1-result.xml +++ b/components/camel-schematron/src/test/resources/result/article-1-result.xml @@ -15,4 +15,4 @@ - \ No newline at end of file + diff --git a/components/camel-schematron/src/test/resources/sch/sample-schematron.sch b/components/camel-schematron/src/test/resources/sch/sample-schematron.sch index 4cc69e24a603a..752c899d3a2eb 100644 --- a/components/camel-schematron/src/test/resources/sch/sample-schematron.sch +++ b/components/camel-schematron/src/test/resources/sch/sample-schematron.sch @@ -3,6 +3,7 @@ xmlns:xs="http://www.w3.org/2001/XMLSchema" queryBinding="xslt2"> + diff --git a/components/pom.xml b/components/pom.xml index 40b8bb082b3ec..b9b4889ea14c2 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -152,6 +152,7 @@ camel-saxon camel-salesforce camel-script + camel-schematron camel-servlet camel-servletlistener camel-shiro From 971d2a3ebc71be3f64922d291aa61fa706c5c1e0 Mon Sep 17 00:00:00 2001 From: Ayache Khettar Date: Tue, 18 Feb 2014 18:04:21 +0000 Subject: [PATCH 07/17] Update README.md --- components/camel-schematron/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/camel-schematron/README.md b/components/camel-schematron/README.md index af3b9a77dcfad..f465b5367eda3 100644 --- a/components/camel-schematron/README.md +++ b/components/camel-schematron/README.md @@ -1,7 +1,7 @@ Schematron Component Project ============================ -This project is a schematron camel component. Schematron is an XML-based language for validating XML instance documents. Schematron is used to make assertions about data in an XML document. Schematron is used to express operational and business rules. +Schematron is an XML-based language for validating XML instance documents. Schematron is used to make assertions about data in an XML document. Schematron is used to express operational and business rules. Schematron is an ISO standard. Use Schematron to verify data interdependencies (co-constraints), check data cardinality, and perform algorithmic checks. A co-constraint is a dependency between data within an XML document or across XML documents. Cardinality refers to the presence or absence of data. An algorithmic check determines data validity by performing an algorithm on the data. From 3060f9d9fd903cffaa4430dc9f50eff6c3bc22d2 Mon Sep 17 00:00:00 2001 From: Ayache Khettar Date: Tue, 18 Feb 2014 18:05:53 +0000 Subject: [PATCH 08/17] Update README.md --- components/camel-schematron/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/camel-schematron/README.md b/components/camel-schematron/README.md index f465b5367eda3..839e88b7d6c26 100644 --- a/components/camel-schematron/README.md +++ b/components/camel-schematron/README.md @@ -5,6 +5,12 @@ Schematron is an XML-based language for validating XML instance documents. Schem Schematron is an ISO standard. Use Schematron to verify data interdependencies (co-constraints), check data cardinality, and perform algorithmic checks. A co-constraint is a dependency between data within an XML document or across XML documents. Cardinality refers to the presence or absence of data. An algorithmic check determines data validity by performing an algorithm on the data. +Schematron engine +====================== + +Schemaron engine is an XSLT based implementation. XLST source code can be found here: https://code.google.com/p/schematron/ + + Schematron Tutorials ====================== From d06ee0d16f96f8e2f5ae853f341c2c06c56f1518 Mon Sep 17 00:00:00 2001 From: Ayache Khettar Date: Tue, 18 Feb 2014 18:06:32 +0000 Subject: [PATCH 09/17] Update README.md --- components/camel-schematron/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/camel-schematron/README.md b/components/camel-schematron/README.md index 839e88b7d6c26..d5dfc0ec8ad20 100644 --- a/components/camel-schematron/README.md +++ b/components/camel-schematron/README.md @@ -1,5 +1,5 @@ -Schematron Component Project -============================ +Schematron Component +==================== Schematron is an XML-based language for validating XML instance documents. Schematron is used to make assertions about data in an XML document. Schematron is used to express operational and business rules. Schematron is an ISO standard. @@ -26,4 +26,4 @@ http://www.ldodds.com/papers/schematron_xsltuk.html#c35e2592b6b7 To build this project use - mvn install + mvn clean install From a1852e2e748af66311824380d8fe1c038bbd3198 Mon Sep 17 00:00:00 2001 From: akhettar Date: Tue, 18 Feb 2014 21:28:19 +0000 Subject: [PATCH 10/17] tidy up --- .../schematron/contant/Constants.java | 38 +++++++++++++++++++ .../schematron/engine/SchematronEngine.java | 19 ++++++---- .../schematron/engine/TemplatesFactory.java | 1 + .../src/test/resources/catalog/catalog.xml | 8 ++++ .../src/test/resources/schema/article.xsd | 18 +++++++++ 5 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/contant/Constants.java create mode 100644 components/camel-schematron/src/test/resources/catalog/catalog.xml create mode 100644 components/camel-schematron/src/test/resources/schema/article.xsd diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/contant/Constants.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/contant/Constants.java new file mode 100644 index 0000000000000..0478aac4516f2 --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/contant/Constants.java @@ -0,0 +1,38 @@ +/** + * 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.contant; + +/** + * Utility class defining all constants needed for the schematron component. + *

+ * Created by akhettar on 29/12/2013. + */ +public final class Constants { + + public static final String VALIDATION_STATUS = "CamelSchValidationStatus"; + public static final String HTTP_PURL_OCLC_ORG_DSDL_SVRL = "http://purl.oclc.org/dsdl/svrl"; + public static final String FAILED_ASSERT = "failed-assert"; + public static final String FAILED = "FAILED"; + public static final String SUCCESS = "SUCCESS"; + public static final String VALIDATION_REPORT = "CamelSchValidationReport"; + public static final String SCHEMATRON_TEMPLATES_ROOT_DIR = "iso-schematron-xslt2"; + + private Constants() { + throw new IllegalStateException("Utility class should not be instantiated"); + } + +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java index e381c4353d0a3..6bf4852ab6099 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java @@ -16,20 +16,23 @@ */ package org.apache.camel.component.schematron.engine; -import java.io.StringWriter; -import org.xml.sax.InputSource; -import org.apache.camel.component.schematron.exception.SchematronValidationException; -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import javax.xml.transform.Result; +import javax.xml.transform.Source; import javax.xml.transform.Templates; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; -import javax.xml.transform.Result; -import javax.xml.transform.Source; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; import org.xml.sax.XMLReader; +import java.io.StringWriter; +import org.xml.sax.InputSource; +import org.apache.camel.component.schematron.exception.SchematronValidationException; +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java index 0a61b7082b9cb..6f72d779e65e0 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java @@ -35,6 +35,7 @@ import java.io.File; import java.io.InputStream; + /** * Class generating Templates for given schematron rules * diff --git a/components/camel-schematron/src/test/resources/catalog/catalog.xml b/components/camel-schematron/src/test/resources/catalog/catalog.xml new file mode 100644 index 0000000000000..ff50c0b2ab919 --- /dev/null +++ b/components/camel-schematron/src/test/resources/catalog/catalog.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/components/camel-schematron/src/test/resources/schema/article.xsd b/components/camel-schematron/src/test/resources/schema/article.xsd new file mode 100644 index 0000000000000..8eb79b3db3684 --- /dev/null +++ b/components/camel-schematron/src/test/resources/schema/article.xsd @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file From 6be0a9bf4d6954ef64f22e688376fd089724d0f0 Mon Sep 17 00:00:00 2001 From: Ayache Khettar Date: Sun, 6 Jul 2014 21:02:52 +0100 Subject: [PATCH 11/17] referencing 2.14-SNAPSHOT --- components/camel-schematron/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/camel-schematron/pom.xml b/components/camel-schematron/pom.xml index 3c4bd47114653..e624894bc967f 100644 --- a/components/camel-schematron/pom.xml +++ b/components/camel-schematron/pom.xml @@ -21,7 +21,7 @@ org.apache.camel components - 2.13-SNAPSHOT + 2.14-SNAPSHOT 4.0.0 org.apache.camel @@ -69,7 +69,7 @@ org.apache.camel camel-test - 2.12.1 + 2.13.1 test From 3e710c5d33d1dcaac913fc4d9a22d39d924c9909 Mon Sep 17 00:00:00 2001 From: Ayache Khettar Date: Sat, 2 Aug 2014 20:32:14 +0100 Subject: [PATCH 12/17] Refactoring --- components/camel-schematron/pom.xml | 8 -- .../schematron/SchematronEndpoint.java | 3 +- .../schematron/SchematronProducer.java | 22 +++-- .../{contant => constant}/Constants.java | 7 +- .../engine/ClassPathURIResolver.java | 45 --------- .../schematron/engine/SchematronEngine.java | 85 ---------------- .../schematron/engine/TemplatesFactory.java | 94 ------------------ .../exception/SchematronConfigException.java | 2 +- .../SchematronValidationException.java | 2 - .../processor/SchematronProcessor.java | 73 ++++++++++++++ .../SchematronProcessorFactory.java} | 24 +++-- .../processor/TemplatesFactory.java | 99 +++++++++++++++++++ .../component/schematron/util/Utils.java | 11 +-- .../org/apache/camel/component/schematron | 17 ++++ .../schematron/SchematronComponentTest.java | 6 +- .../schematron/SchematronEndpointTest.java | 11 ++- .../schematron/SchematronProducerTest.java | 7 +- .../SchematronProcessorTest.java} | 46 +++++---- .../TemplatesFactoryTest.java | 7 +- .../src/test/resources/catalog/catalog.xml | 8 -- .../article-1-report.xml} | 0 .../resources/report/article-2-report.xml | 17 ++++ ...sample-schematron.sch => schematron-1.sch} | 4 +- .../src/test/resources/sch/schematron-2.sch | 21 ++++ .../src/test/resources/xml/article-2.xml | 27 +++-- 25 files changed, 320 insertions(+), 326 deletions(-) rename components/camel-schematron/src/main/java/org/apache/camel/component/schematron/{contant => constant}/Constants.java (84%) delete mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/ClassPathURIResolver.java delete mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java delete mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessor.java rename components/camel-schematron/src/main/java/org/apache/camel/component/schematron/{engine/SchematronEngineFactory.java => processor/SchematronProcessorFactory.java} (78%) create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java rename components/camel-schematron/src/test/java/org/apache/camel/component/schematron/{engine/SchematronEngineTest.java => processor/SchematronProcessorTest.java} (65%) rename components/camel-schematron/src/test/java/org/apache/camel/component/schematron/{engine => processor}/TemplatesFactoryTest.java (89%) delete mode 100644 components/camel-schematron/src/test/resources/catalog/catalog.xml rename components/camel-schematron/src/test/resources/{result/article-1-result.xml => report/article-1-report.xml} (100%) create mode 100644 components/camel-schematron/src/test/resources/report/article-2-report.xml rename components/camel-schematron/src/test/resources/sch/{sample-schematron.sch => schematron-1.sch} (71%) create mode 100644 components/camel-schematron/src/test/resources/sch/schematron-2.sch diff --git a/components/camel-schematron/pom.xml b/components/camel-schematron/pom.xml index e624894bc967f..417550cef233d 100644 --- a/components/camel-schematron/pom.xml +++ b/components/camel-schematron/pom.xml @@ -44,11 +44,6 @@ Saxon-HE ${saxon-version} - - net.sf.saxon - saxon-dom - 8.7 - xmlunit xmlunit @@ -69,10 +64,7 @@ org.apache.camel camel-test - 2.13.1 test - - diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java index 36243e183f903..458f3e81413f8 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java @@ -15,6 +15,7 @@ * limitations under the License. */ package org.apache.camel.component.schematron; + import java.io.File; import java.io.InputStream; @@ -22,7 +23,7 @@ import org.apache.camel.Consumer; import org.apache.camel.Processor; import org.apache.camel.Producer; -import org.apache.camel.component.schematron.engine.TemplatesFactory; +import org.apache.camel.component.schematron.processor.TemplatesFactory; import org.apache.camel.component.schematron.exception.SchematronConfigException; import org.apache.camel.impl.DefaultEndpoint; import org.apache.camel.util.ResourceHelper; diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java index cac817c32c795..65f2827732353 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java @@ -17,14 +17,17 @@ package org.apache.camel.component.schematron; import org.apache.camel.Exchange; -import org.apache.camel.component.schematron.contant.Constants; -import org.apache.camel.component.schematron.engine.SchematronEngineFactory; +import org.apache.camel.component.schematron.constant.Constants; +import org.apache.camel.component.schematron.processor.SchematronProcessorFactory; import org.apache.camel.component.schematron.exception.SchematronValidationException; import org.apache.camel.component.schematron.util.Utils; import org.apache.camel.impl.DefaultProducer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashMap; +import java.util.Map; + /** * The Schematron producer. */ @@ -50,12 +53,11 @@ public SchematronProducer(final SchematronEndpoint endpoint) { public void process(Exchange exchange) throws Exception { String payload = exchange.getIn().getBody(String.class); - String report = SchematronEngineFactory.newScehamtronEngine(endpoint.getRules()).validate(payload); - + logger.debug("Applying schematron validation on payload: {}", payload); + String report = SchematronProcessorFactory.newScehamtronEngine(endpoint.getRules()).validate(payload); logger.debug("Schematron validation report \n {}", report); String status = getValidationStatus(report); logger.info("Schematron validation status : {}", status); - setValidationReport(exchange, report, status); } @@ -68,13 +70,15 @@ public void process(Exchange exchange) throws Exception { */ private void setValidationReport(Exchange exchange, String report, String status) { // if exchange pattern is In and Out set details on the Out message. + Map headers = new HashMap(); + headers.put(Constants.VALIDATION_STATUS, status); + headers.put(Constants.VALIDATION_REPORT, report); + exchange.getOut().setHeader(Constants.VALIDATION_REPORT, report); if (exchange.getPattern().isOutCapable()) { exchange.getOut().setHeaders(exchange.getIn().getHeaders()); - exchange.getOut().setHeader(Constants.VALIDATION_STATUS, status); - exchange.getOut().setHeader(Constants.VALIDATION_REPORT, report); + exchange.getOut().getHeaders().putAll(headers); } else { - exchange.getIn().setHeader(Constants.VALIDATION_STATUS, status); - exchange.getIn().setHeader(Constants.VALIDATION_REPORT, report); + exchange.getIn().getHeaders().putAll(headers); } } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/contant/Constants.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/constant/Constants.java similarity index 84% rename from components/camel-schematron/src/main/java/org/apache/camel/component/schematron/contant/Constants.java rename to components/camel-schematron/src/main/java/org/apache/camel/component/schematron/constant/Constants.java index 0478aac4516f2..bd3f07ae1c20c 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/contant/Constants.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/constant/Constants.java @@ -14,21 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.schematron.contant; +package org.apache.camel.component.schematron.constant; /** * Utility class defining all constants needed for the schematron component. *

- * Created by akhettar on 29/12/2013. */ public final class Constants { - public static final String VALIDATION_STATUS = "CamelSchValidationStatus"; + public static final String VALIDATION_STATUS = "CamelSchematronValidationStatus"; + public static final String VALIDATION_REPORT = "CamelSchematronValidationReport"; public static final String HTTP_PURL_OCLC_ORG_DSDL_SVRL = "http://purl.oclc.org/dsdl/svrl"; public static final String FAILED_ASSERT = "failed-assert"; public static final String FAILED = "FAILED"; public static final String SUCCESS = "SUCCESS"; - public static final String VALIDATION_REPORT = "CamelSchValidationReport"; public static final String SCHEMATRON_TEMPLATES_ROOT_DIR = "iso-schematron-xslt2"; private Constants() { diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/ClassPathURIResolver.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/ClassPathURIResolver.java deleted file mode 100644 index 6e05d290b5fdf..0000000000000 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/ClassPathURIResolver.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.engine; - -import java.io.File; -import javax.xml.transform.Source; -import javax.xml.transform.TransformerException; -import javax.xml.transform.URIResolver; -import javax.xml.transform.stream.StreamSource; - - -/** - * Created by akhettar on 26/12/2013. - */ -public class ClassPathURIResolver implements URIResolver { - - private String rulesDir; - - /** - * Constructor setter for rules directory path. - * @param rulesDir - */ - public ClassPathURIResolver(final String rulesDir) { - this.rulesDir = rulesDir; - } - - @Override - public Source resolve(String href, String base) throws TransformerException { - return new StreamSource(ClassLoader.getSystemResourceAsStream(rulesDir.concat(File.separator).concat(href))); - } -} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java deleted file mode 100644 index 6bf4852ab6099..0000000000000 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngine.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * 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.engine; - - -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Templates; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.sax.SAXSource; -import javax.xml.transform.stream.StreamResult; -import org.xml.sax.XMLReader; -import java.io.StringWriter; -import org.xml.sax.InputSource; -import org.apache.camel.component.schematron.exception.SchematronValidationException; -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - - - - - -/** - * The schematoron Engine. Validates an XML for given scheamtron - * rules using an XSLT implementation of the Schematron Engine. - *

- * Created by akhettar on 20/12/2013. - */ -public class SchematronEngine { - - - private Logger logger = LoggerFactory.getLogger(SchematronEngine.class); - private XMLReader reader; - private Templates templates; - - - /** - * Constructor setting the XSLT schematron templates. - * - * @param reader - * @param templates - */ - public SchematronEngine(XMLReader reader, Templates templates) { - this.reader = reader; - this.templates = templates; - } - - - /** - * Validates the given XML for given Rules. - * - * @param xml - * @return - */ - public String validate(final String xml) { - try { - final Source source = new SAXSource(reader, new InputSource(IOUtils.toInputStream(xml))); - final StringWriter writer = new StringWriter(); - final Result result = new StreamResult(writer); - final Transformer transformer = templates.newTransformer(); - transformer.transform(source, result); - return writer.toString(); - } catch (TransformerException e) { - logger.error(e.getMessage()); - throw new SchematronValidationException("Failed to apply Schematron validation transform", e); - } - } -} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java deleted file mode 100644 index 6f72d779e65e0..0000000000000 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/TemplatesFactory.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * 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.engine; - - -import net.sf.saxon.FeatureKeys; -import org.apache.camel.component.schematron.contant.Constants; -import org.apache.camel.component.schematron.exception.SchematronConfigException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Node; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.Templates; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamSource; -import java.io.File; -import java.io.InputStream; - - -/** - * Class generating Templates for given schematron rules - * - * Created by akhettar on 20/12/2013. - */ -public final class TemplatesFactory { - - private static final TemplatesFactory INSTANCE = new TemplatesFactory(); - private String[] pipeline = new String[]{"iso_dsdl_include.xsl", "iso_abstract_expand.xsl", "iso_svrl_for_xslt2.xsl"}; - private Logger logger = LoggerFactory.getLogger(TemplatesFactory.class); - - /** - * Singleton constructor; - * - * @return - */ - public static TemplatesFactory newInstance() { - return INSTANCE; - } - - /** - * Returns an instance of compiled schematron templates. - * - * @return - */ - public Templates newTemplates(final InputStream rules) { - - // create new instance. - Templates templates; - TransformerFactory fac = TransformerFactory.newInstance(); - fac.setURIResolver(new ClassPathURIResolver(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR)); - fac.setAttribute(FeatureKeys.LINE_NUMBERING, true); - Node node = null; - Transformer t = null; - Source source = new StreamSource(rules); - try { - for (String template : pipeline) { - Source xsl = new StreamSource(ClassLoader.getSystemResourceAsStream(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR - .concat(File.separator).concat(template))); - t = fac.newTransformer(xsl); - DOMResult result = new DOMResult(); - t.transform(source, result); - source = new DOMSource(node = result.getNode()); - } - templates = fac.newTemplates(new DOMSource(node)); - } catch (TransformerConfigurationException e) { - logger.error(e.getMessage(), e); - throw new SchematronConfigException(e); - } catch (TransformerException e) { - logger.error(e.getMessage(), e); - throw new SchematronConfigException(e); - } - return templates; - } - -} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java index b2a355a34d84a..f94621be3b33e 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java @@ -19,7 +19,7 @@ import org.apache.camel.RuntimeCamelException; /** - * Created by akhettar on 22/12/2013. + * Schematron configuration Exception. */ public class SchematronConfigException extends RuntimeCamelException { public SchematronConfigException(Throwable e) { diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java index ba50df44ddf4b..d8554d79c5066 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java @@ -20,8 +20,6 @@ /** * SchematronValidationException is thrown if option is set to true. - * - * Created by akhettar on 25/12/2013. */ public class SchematronValidationException extends RuntimeCamelException { diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessor.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessor.java new file mode 100644 index 0000000000000..795ba879027a1 --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessor.java @@ -0,0 +1,73 @@ +/** + * 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.StringWriter; + +import javax.xml.transform.*; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamResult; + +import org.apache.camel.component.schematron.exception.SchematronValidationException; +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; + +/** + * The schematoron Engine. Validates an XML for given scheamtron rules using an XSLT implementation of the Schematron + * Engine. + *

+ */ +public class SchematronProcessor { + + private Logger logger = LoggerFactory.getLogger(SchematronProcessor.class); + private XMLReader reader; + private Templates templates; + + /** + * Constructor setting the XSLT schematron templates. + * + * @param reader + * @param templates + */ + public SchematronProcessor(XMLReader reader, Templates templates) { + + this.reader = reader; + this.templates = templates; + } + + /** + * Validates the given XML for given Rules. + * + * @param xml + * @return + */ + public String validate(final String xml) { + + try { + final Source source = new SAXSource(reader, new InputSource(IOUtils.toInputStream(xml))); + final StringWriter writer = new StringWriter(); + templates.newTransformer().transform(source, new StreamResult(writer)); + return writer.toString(); + } catch (TransformerException e) { + logger.error(e.getMessage()); + throw new SchematronValidationException("Failed to apply Schematron validation transform", e); + } + } +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessorFactory.java similarity index 78% rename from components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java rename to components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessorFactory.java index 448718806e536..9e69b1b1ee8f3 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/engine/SchematronEngineFactory.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessorFactory.java @@ -14,12 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.schematron.engine; +package org.apache.camel.component.schematron.processor; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.Templates; + import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.apache.camel.component.schematron.exception.SchematronConfigException; @@ -32,30 +33,28 @@ /** * Schematron Engine Factory * - * Created by akhettar on 22/12/2013. */ -public final class SchematronEngineFactory { +public final class SchematronProcessorFactory { - private static final Logger LOG = LoggerFactory.getLogger(SchematronEngineFactory.class); + private static final Logger LOG = LoggerFactory.getLogger(SchematronProcessorFactory.class); - private SchematronEngineFactory() { + /** + * Private constructor. + */ + private SchematronProcessorFactory() { throw new IllegalStateException(); } - /** * Creates an instance of SchematronEngine * * @param rules the given schematron rules * @return an instance of SchematronEngine */ - public static SchematronEngine newScehamtronEngine(final Templates rules) { + public static SchematronProcessor newScehamtronEngine(final Templates rules) { try { - return new SchematronEngine(getXMLReader(), rules); - } catch (ParserConfigurationException e) { - LOG.error("Failed to parse the configuration file"); - throw new SchematronConfigException(e); - } catch (SAXException e) { + return new SchematronProcessor(getXMLReader(), rules); + } catch (Exception e) { LOG.error("Failed to parse the configuration file"); throw new SchematronConfigException(e); } @@ -73,7 +72,6 @@ private static XMLReader getXMLReader() throws ParserConfigurationException, SAX fac.setValidating(false); final SAXParser parser = fac.newSAXParser(); XMLReader reader = parser.getXMLReader(); - //reader.setEntityResolver(null); return reader; } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java new file mode 100644 index 0000000000000..b05a1d765a68a --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java @@ -0,0 +1,99 @@ +/** + * 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.Templates; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamSource; + +import org.apache.camel.component.schematron.constant.Constants; +import org.apache.camel.component.schematron.exception.SchematronConfigException; +import org.apache.camel.component.schematron.util.ClassPathURIResolver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Node; + +/** + * Class generating Templates for a given schematron rules + */ +public final class TemplatesFactory { + + private Logger logger = LoggerFactory.getLogger(TemplatesFactory.class); + private static final String LINE_NUMBERING = "http://saxon.sf.net/feature/linenumbering"; + private static final TemplatesFactory INSTANCE = new TemplatesFactory(); + private static final String[] PIPELINE = new String[] { "iso_dsdl_include.xsl", "iso_abstract_expand.xsl", + "iso_svrl_for_xslt2.xsl" }; + + /** + * Singleton constructor; + * + * @return + */ + public static TemplatesFactory newInstance() { + + return INSTANCE; + } + + /** + * Returns an instance of compiled schematron templates. + * + * @return + */ + public Templates newTemplates(final InputStream rules) { + + TransformerFactory fac = TransformerFactory.newInstance(); + fac.setURIResolver(new ClassPathURIResolver(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR)); + fac.setAttribute(LINE_NUMBERING, true); + return getTemplates(rules, fac); + } + + /** + * Generate the schematron template for given rule. + * + * @param rules + * the schematron rules + * @param fac + * the transformer factory. + * @return schematron template. + */ + private Templates getTemplates(InputStream rules, TransformerFactory fac) { + + Node node = null; + Source source = new StreamSource(rules); + try { + for (String template : PIPELINE) { + Source xsl = new StreamSource(ClassLoader.getSystemResourceAsStream(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR + .concat(File.separator).concat(template))); + Transformer t = fac.newTransformer(xsl); + DOMResult result = new DOMResult(); + t.transform(source, result); + source = new DOMSource(node = result.getNode()); + } + return fac.newTemplates(new DOMSource(node)); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new SchematronConfigException(e); + } + } +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java index c9da487d62e56..424d73f862040 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java @@ -17,7 +17,7 @@ package org.apache.camel.component.schematron.util; import org.apache.camel.RuntimeCamelException; -import org.apache.camel.component.schematron.contant.Constants; +import org.apache.camel.component.schematron.constant.Constants; import org.apache.commons.lang.StringUtils; import org.custommonkey.xmlunit.SimpleNamespaceContext; import org.custommonkey.xmlunit.XMLUnit; @@ -30,7 +30,6 @@ /** * Utility Class. *

- * Created by akhettar on 29/12/2013. */ public final class Utils { @@ -48,13 +47,10 @@ private Utils() { * @return */ public static String evaluate(final String xpath, final String xml) { - Map m = new HashMap(); + Map m = new HashMap(); m.put("svrl", Constants.HTTP_PURL_OCLC_ORG_DSDL_SVRL); - - org.custommonkey.xmlunit.NamespaceContext ctx = new SimpleNamespaceContext(m); XpathEngine xpathEngine = XMLUnit.newXpathEngine(); - xpathEngine.setNamespaceContext(ctx); - + xpathEngine.setNamespaceContext(new SimpleNamespaceContext(m)); try { return xpathEngine.evaluate(xpath, XMLUnit.buildControlDocument(xml)); } catch (Exception e) { @@ -63,7 +59,6 @@ public static String evaluate(final String xpath, final String xml) { } } - /** * Get validation status SUCCESS OR FAILURE if there are any schematron validation errors. * diff --git a/components/camel-schematron/src/main/resources/META-INF/services/org/apache/camel/component/schematron b/components/camel-schematron/src/main/resources/META-INF/services/org/apache/camel/component/schematron index 59b015c490a14..5f2af4c85c5af 100644 --- a/components/camel-schematron/src/main/resources/META-INF/services/org/apache/camel/component/schematron +++ b/components/camel-schematron/src/main/resources/META-INF/services/org/apache/camel/component/schematron @@ -1 +1,18 @@ +/** + * 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. + */ + class=org.apache.camel.component.schematron.SchematronComponent diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java index ff69d5192338c..1f0a57704cdcf 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java @@ -18,7 +18,7 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.component.schematron.contant.Constants; +import org.apache.camel.component.schematron.constant.Constants; import org.apache.camel.component.schematron.util.Utils; import org.apache.camel.test.junit4.CamelTestSupport; import org.apache.commons.io.IOUtils; @@ -42,7 +42,7 @@ public void testSendBodyAsString() throws Exception { mock.expectedMinimumMessageCount(1); String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml")); - String expected = IOUtils.toString(ClassLoader.getSystemResourceAsStream("result/article-1-result.xml")); + String expected = IOUtils.toString(ClassLoader.getSystemResourceAsStream("result/article-1-report.xml")); template.sendBody("direct:start", payload); assertMockEndpointsSatisfied(); String result = mock.getExchanges().get(0).getIn().getHeader(Constants.VALIDATION_REPORT, String.class); @@ -77,7 +77,7 @@ protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() { from("direct:start") - .to("schematron://sch/sample-schematron.sch") + .to("schematron://sch/schematron-1.sch") .to("mock:result"); } }; diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java index 7c7afa6fe5368..6ac1389274c4d 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java @@ -22,14 +22,15 @@ import org.apache.camel.ExchangePattern; import org.apache.camel.Producer; import org.apache.camel.component.schematron.exception.SchematronValidationException; -import org.apache.camel.component.schematron.contant.Constants; +import org.apache.camel.component.schematron.constant.Constants; import org.apache.camel.impl.DefaultExchange; import org.apache.camel.test.junit4.CamelTestSupport; import org.apache.commons.io.IOUtils; import org.junit.Test; /** - * Created by akhettar on 20/12/2013. + * Unit test for SchematronEndpoint. + * */ public class SchematronEndpointTest extends CamelTestSupport { @@ -38,7 +39,7 @@ public class SchematronEndpointTest extends CamelTestSupport { public void testSchematronFileReadFromClassPath()throws Exception { String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml")); - Endpoint endpoint = context().getEndpoint("schematron://sch/sample-schematron.sch"); + Endpoint endpoint = context().getEndpoint("schematron://sch/schematron-1.sch"); Producer producer = endpoint.createProducer(); Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut); @@ -55,7 +56,7 @@ public void testSchematronFileReadFromClassPath()throws Exception { public void testSchematronFileReadFromFileSystem()throws Exception { String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); - String path = ClassLoader.getSystemResource("sch/sample-schematron.sch").getPath(); + String path = ClassLoader.getSystemResource("sch/schematron-1.sch").getPath(); Endpoint endpoint = context().getEndpoint("schematron://" + path); Producer producer = endpoint.createProducer(); Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut); @@ -72,7 +73,7 @@ public void testSchematronFileReadFromFileSystem()throws Exception { @Test(expected = SchematronValidationException.class) public void testThrowSchematronValidationException() throws Exception { String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); - Endpoint endpoint = context().getEndpoint("schematron://sch/sample-schematron.sch?abort=true"); + Endpoint endpoint = context().getEndpoint("schematron://sch/schematron-1.sch?abort=true"); Producer producer = endpoint.createProducer(); Exchange exchange = new DefaultExchange(context, ExchangePattern.OutIn); diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java index d1ba8d8c93ef4..5bdf9a7441400 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java @@ -18,8 +18,8 @@ import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; -import org.apache.camel.component.schematron.contant.Constants; -import org.apache.camel.component.schematron.engine.TemplatesFactory; +import org.apache.camel.component.schematron.constant.Constants; +import org.apache.camel.component.schematron.processor.TemplatesFactory; import org.apache.camel.impl.DefaultExchange; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.BeforeClass; @@ -29,7 +29,6 @@ /** * Schematron Producer Unit Test. *

- * Created by akhettar on 31/12/2013. */ public class SchematronProducerTest extends CamelTestSupport { @@ -39,7 +38,7 @@ public class SchematronProducerTest extends CamelTestSupport { public static void setUP() { SchematronEndpoint endpoint = new SchematronEndpoint(); Templates templates = TemplatesFactory.newInstance().newTemplates(ClassLoader. - getSystemResourceAsStream("sch/sample-schematron.sch")); + getSystemResourceAsStream("sch/schematron-1.sch")); endpoint.setRules(templates); producer = new SchematronProducer(endpoint); } diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java similarity index 65% rename from components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java rename to components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java index e03866e6d8341..e5e32de3f9c5b 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/SchematronEngineTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java @@ -14,40 +14,38 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.schematron.engine; +package org.apache.camel.component.schematron.processor; import org.apache.camel.component.schematron.util.Utils; import org.apache.commons.io.IOUtils; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.DifferenceListener; import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; -import org.junit.BeforeClass; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import javax.xml.transform.Templates; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; /** - * Created by akhettar on 27/12/2013. + * SchematronEngine Unit Test. + * */ -public class SchematronEngineTest { - - private static SchematronEngine engine; - - @BeforeClass - public static void setUP() { - Templates rules = TemplatesFactory.newInstance().newTemplates(ClassLoader.getSystemResourceAsStream("sch/sample-schematron.sch")); - engine = SchematronEngineFactory.newScehamtronEngine(rules); - } +public class SchematronProcessorTest { + private Logger logger = LoggerFactory.getLogger(SchematronProcessorTest.class); @Test public void testValidXML() throws Exception { String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml")); - String expected = IOUtils.toString(ClassLoader.getSystemResourceAsStream("result/article-1-result.xml")); + logger.info("Validating payload: {}", payload); + String expected = IOUtils.toString(ClassLoader.getSystemResourceAsStream("report/article-1-report.xml")); // validate - String result = engine.validate(payload); + String result = getProcessor("sch/schematron-1.sch").validate(payload); + logger.info("Schematron Report: {}", result); DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener(); Diff myDiff = new Diff(expected, result); myDiff.overrideDifferenceListener(myDifferenceListener); @@ -58,13 +56,27 @@ public void testValidXML() throws Exception { public void testInValidXML() throws Exception { String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); - + logger.info("Validating payload: {}", payload); // validate - String result = engine.validate(payload); - + String result = getProcessor("sch/schematron-2.sch").validate(payload); + logger.info("Schematron Report: {}", result); // should throw two assertions because of the missing chapters in the XML. assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert/svrl:text", result)); + assertEquals("'chapter' element has more than one title present", Utils.evaluate("//svrl:successful-report/svrl:text", result).trim()); + + + } + /** + * Returns schematron processor + * + * @param schematron + * @return + */ + private SchematronProcessor getProcessor(final String schematron) + { + Templates rules = TemplatesFactory.newInstance().newTemplates(ClassLoader.getSystemResourceAsStream(schematron)); + return SchematronProcessorFactory.newScehamtronEngine(rules); } } diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/TemplatesFactoryTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/TemplatesFactoryTest.java similarity index 89% rename from components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/TemplatesFactoryTest.java rename to components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/TemplatesFactoryTest.java index deca278a04da0..543869dc61f78 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/engine/TemplatesFactoryTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/TemplatesFactoryTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.schematron.engine; +package org.apache.camel.component.schematron.processor; import org.junit.Assert; import org.junit.Test; @@ -22,11 +22,12 @@ import javax.xml.transform.Templates; /** - * Created by akhettar on 22/12/2013. + * TemplateFactory Unit Test. + * */ public class TemplatesFactoryTest { - private String rules = "sch/sample-schematron.sch"; + private String rules = "sch/schematron-1.sch"; @Test diff --git a/components/camel-schematron/src/test/resources/catalog/catalog.xml b/components/camel-schematron/src/test/resources/catalog/catalog.xml deleted file mode 100644 index ff50c0b2ab919..0000000000000 --- a/components/camel-schematron/src/test/resources/catalog/catalog.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/components/camel-schematron/src/test/resources/result/article-1-result.xml b/components/camel-schematron/src/test/resources/report/article-1-report.xml similarity index 100% rename from components/camel-schematron/src/test/resources/result/article-1-result.xml rename to components/camel-schematron/src/test/resources/report/article-1-report.xml diff --git a/components/camel-schematron/src/test/resources/report/article-2-report.xml b/components/camel-schematron/src/test/resources/report/article-2-report.xml new file mode 100644 index 0000000000000..d3069cbe5c90c --- /dev/null +++ b/components/camel-schematron/src/test/resources/report/article-2-report.xml @@ -0,0 +1,17 @@ + + + + + + + A chapter should have a title + + + + A chapter should have a title + + + \ No newline at end of file diff --git a/components/camel-schematron/src/test/resources/sch/sample-schematron.sch b/components/camel-schematron/src/test/resources/sch/schematron-1.sch similarity index 71% rename from components/camel-schematron/src/test/resources/sch/sample-schematron.sch rename to components/camel-schematron/src/test/resources/sch/schematron-1.sch index 752c899d3a2eb..e3ba48093c70c 100644 --- a/components/camel-schematron/src/test/resources/sch/sample-schematron.sch +++ b/components/camel-schematron/src/test/resources/sch/schematron-1.sch @@ -1,9 +1,9 @@ - + Sample Schematron using XPath 2.0 + diff --git a/components/camel-schematron/src/test/resources/sch/schematron-2.sch b/components/camel-schematron/src/test/resources/sch/schematron-2.sch new file mode 100644 index 0000000000000..18f4bca82b66a --- /dev/null +++ b/components/camel-schematron/src/test/resources/sch/schematron-2.sch @@ -0,0 +1,21 @@ + + + + Sample Schematron using XPath 2.0 + + + + + + + + + A chapter should have a title + + 'chapter' element has more than one title present + + + + + \ No newline at end of file diff --git a/components/camel-schematron/src/test/resources/xml/article-2.xml b/components/camel-schematron/src/test/resources/xml/article-2.xml index 2867b9d1bcaa1..33698b532978d 100644 --- a/components/camel-schematron/src/test/resources/xml/article-2.xml +++ b/components/camel-schematron/src/test/resources/xml/article-2.xml @@ -1,15 +1,14 @@ - - - - Chapter content - - - - Content - - - Title - Chapter 3 content - - \ No newline at end of file + + + Chapter content + + + Content + + + Title + Title2 + Chapter 3 content + + \ No newline at end of file From ee21d460620c954190a14ad10273294a73ea414e Mon Sep 17 00:00:00 2001 From: Ayache Khettar Date: Sun, 3 Aug 2014 12:34:02 +0100 Subject: [PATCH 13/17] Refactoring --- components/camel-schematron/pom.xml | 1 + .../schematron/SchematronProducer.java | 14 +++--- .../processor/ClassPathURIResolver.java | 46 +++++++++++++++++++ .../processor/TemplatesFactory.java | 1 - .../schematron/SchematronComponentTest.java | 14 +++--- .../processor/SchematronProcessorTest.java | 7 ++- .../processor/TemplatesFactoryTest.java | 1 - .../component/schematron/util/Utils.java | 13 +----- .../resources/report/article-1-report.xml | 13 ++++-- .../src/test/resources/sch/schematron-1.sch | 6 ++- 10 files changed, 79 insertions(+), 37 deletions(-) create mode 100644 components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/ClassPathURIResolver.java rename components/camel-schematron/src/{main => test}/java/org/apache/camel/component/schematron/util/Utils.java (84%) diff --git a/components/camel-schematron/pom.xml b/components/camel-schematron/pom.xml index 417550cef233d..82d352c94af2d 100644 --- a/components/camel-schematron/pom.xml +++ b/components/camel-schematron/pom.xml @@ -48,6 +48,7 @@ xmlunit xmlunit ${xmlunit-version} + test commons-lang diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java index 65f2827732353..670d081d71496 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java @@ -16,18 +16,18 @@ */ package org.apache.camel.component.schematron; +import java.util.HashMap; +import java.util.Map; + import org.apache.camel.Exchange; import org.apache.camel.component.schematron.constant.Constants; -import org.apache.camel.component.schematron.processor.SchematronProcessorFactory; import org.apache.camel.component.schematron.exception.SchematronValidationException; -import org.apache.camel.component.schematron.util.Utils; +import org.apache.camel.component.schematron.processor.SchematronProcessorFactory; import org.apache.camel.impl.DefaultProducer; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashMap; -import java.util.Map; - /** * The Schematron producer. */ @@ -89,10 +89,12 @@ private void setValidationReport(Exchange exchange, String report, String status * @return */ private String getValidationStatus(final String report) { - String status = Utils.getValidationStatus(report); + String status = StringUtils.contains(report, + Constants.FAILED_ASSERT) ? Constants.FAILED : Constants.SUCCESS;; if (this.endpoint.isAbort() && Constants.FAILED.equals(status)) { throw new SchematronValidationException("Schematron validation failure \n" + report); } return status; } + } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/ClassPathURIResolver.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/ClassPathURIResolver.java new file mode 100644 index 0000000000000..db506f7bbcb20 --- /dev/null +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/ClassPathURIResolver.java @@ -0,0 +1,46 @@ +/** + * 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 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 String rulesDir; + + /** + * Constructor setter for rules directory path. + * @param rulesDir + */ + public ClassPathURIResolver(final String rulesDir) { + this.rulesDir = rulesDir; + } + + @Override + public Source resolve(String href, String base) throws TransformerException { + return new StreamSource(ClassLoader.getSystemResourceAsStream(rulesDir.concat(File.separator).concat(href))); + } +} diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java index b05a1d765a68a..896acc12bd526 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java @@ -29,7 +29,6 @@ import org.apache.camel.component.schematron.constant.Constants; import org.apache.camel.component.schematron.exception.SchematronConfigException; -import org.apache.camel.component.schematron.util.ClassPathURIResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Node; diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java index 1f0a57704cdcf..70f8ac2414a54 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java @@ -27,6 +27,8 @@ import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; import org.junit.Test; +import static junit.framework.Assert.assertEquals; + /** * Schematron Component Test. */ @@ -42,14 +44,12 @@ public void testSendBodyAsString() throws Exception { mock.expectedMinimumMessageCount(1); String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml")); - String expected = IOUtils.toString(ClassLoader.getSystemResourceAsStream("result/article-1-report.xml")); + String expected = IOUtils.toString(ClassLoader.getSystemResourceAsStream("report/article-1-report.xml")); template.sendBody("direct:start", payload); assertMockEndpointsSatisfied(); String result = mock.getExchanges().get(0).getIn().getHeader(Constants.VALIDATION_REPORT, String.class); - DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener(); - Diff myDiff = new Diff(expected, result); - myDiff.overrideDifferenceListener(myDifferenceListener); - assertTrue(myDiff.similar()); + assertEquals(0, Integer.valueOf(Utils.evaluate("count(//svrl:failed-assert)", result)).intValue()); + assertEquals(0, Integer.valueOf(Utils.evaluate("count(//svrl:successful-report)", result)).intValue()); } /** @@ -67,8 +67,8 @@ public void testSendBodyAsInputStreamInvalidXML() throws Exception { // should throw two assertions because of the missing chapters in the XML. - assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert [@location='/doc[1]/chapter[1]']/svrl:text", result)); - assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert [@location='/doc[1]/chapter[2]']/svrl:text", result)); + assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert[1]/svrl:text", result)); + assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert[2]/svrl:text", result)); } diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java index e5e32de3f9c5b..4577a9a20c95d 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java @@ -46,10 +46,9 @@ public void testValidXML() throws Exception { // validate String result = getProcessor("sch/schematron-1.sch").validate(payload); logger.info("Schematron Report: {}", result); - DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener(); - Diff myDiff = new Diff(expected, result); - myDiff.overrideDifferenceListener(myDifferenceListener); - assertTrue(myDiff.similar()); + assertEquals(0, Integer.valueOf(Utils.evaluate("count(//svrl:failed-assert)", result)).intValue()); + assertEquals(0, Integer.valueOf(Utils.evaluate("count(//svrl:successful-report)", result)).intValue()); + } @Test diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/TemplatesFactoryTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/TemplatesFactoryTest.java index 543869dc61f78..5c536ee3a8051 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/TemplatesFactoryTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/TemplatesFactoryTest.java @@ -29,7 +29,6 @@ public class TemplatesFactoryTest { private String rules = "sch/schematron-1.sch"; - @Test public void testInstantiateAnInstanceOfTemplates() throws Exception { diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/util/Utils.java similarity index 84% rename from components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java rename to components/camel-schematron/src/test/java/org/apache/camel/component/schematron/util/Utils.java index 424d73f862040..1754e444aaf9c 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/util/Utils.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/util/Utils.java @@ -18,7 +18,6 @@ import org.apache.camel.RuntimeCamelException; import org.apache.camel.component.schematron.constant.Constants; -import org.apache.commons.lang.StringUtils; import org.custommonkey.xmlunit.SimpleNamespaceContext; import org.custommonkey.xmlunit.XMLUnit; import org.custommonkey.xmlunit.XpathEngine; @@ -53,20 +52,12 @@ public static String evaluate(final String xpath, final String xml) { xpathEngine.setNamespaceContext(new SimpleNamespaceContext(m)); try { return xpathEngine.evaluate(xpath, XMLUnit.buildControlDocument(xml)); + } catch (Exception e) { LOG.error("Failed to apply xpath {} on xml {}", xpath, xml); throw new RuntimeCamelException(e); } } - /** - * Get validation status SUCCESS OR FAILURE if there are any schematron validation errors. - * - * @param report - * @return - */ - public static String getValidationStatus(final String report) { - return StringUtils.contains(report, - Constants.FAILED_ASSERT) ? Constants.FAILED : Constants.SUCCESS; - } + } diff --git a/components/camel-schematron/src/test/resources/report/article-1-report.xml b/components/camel-schematron/src/test/resources/report/article-1-report.xml index d02a4bf8b01c9..1f40fe8e4d6ed 100644 --- a/components/camel-schematron/src/test/resources/report/article-1-report.xml +++ b/components/camel-schematron/src/test/resources/report/article-1-report.xml @@ -2,17 +2,20 @@ + title="Sample Schematron using XPath 2.0"> + + - + \ No newline at end of file diff --git a/components/camel-schematron/src/test/resources/sch/schematron-1.sch b/components/camel-schematron/src/test/resources/sch/schematron-1.sch index e3ba48093c70c..49b329c548c89 100644 --- a/components/camel-schematron/src/test/resources/sch/schematron-1.sch +++ b/components/camel-schematron/src/test/resources/sch/schematron-1.sch @@ -4,11 +4,13 @@ Sample Schematron using XPath 2.0 + + - - A chapter should have a title + + A chapter should have a title From b05774c7fa6a2b9c03b50fdd7a9c0f915d7db16e Mon Sep 17 00:00:00 2001 From: Ayache Khettar Date: Sun, 3 Aug 2014 13:07:38 +0100 Subject: [PATCH 14/17] checkstyle fix --- .../schematron/SchematronProducer.java | 2 +- .../processor/SchematronProcessor.java | 65 +++++----- .../processor/TemplatesFactory.java | 112 +++++++++--------- .../processor/SchematronProcessorTest.java | 13 +- 4 files changed, 93 insertions(+), 99 deletions(-) diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java index 670d081d71496..0fdb2090aff1e 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java @@ -90,7 +90,7 @@ private void setValidationReport(Exchange exchange, String report, String status */ private String getValidationStatus(final String report) { String status = StringUtils.contains(report, - Constants.FAILED_ASSERT) ? Constants.FAILED : Constants.SUCCESS;; + Constants.FAILED_ASSERT) ? Constants.FAILED : Constants.SUCCESS; if (this.endpoint.isAbort() && Constants.FAILED.equals(status)) { throw new SchematronValidationException("Schematron validation failure \n" + report); } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessor.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessor.java index 795ba879027a1..8ba23ea122d44 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessor.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessor.java @@ -17,8 +17,9 @@ package org.apache.camel.component.schematron.processor; import java.io.StringWriter; - -import javax.xml.transform.*; +import javax.xml.transform.Source; +import javax.xml.transform.Templates; +import javax.xml.transform.TransformerException; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; @@ -29,6 +30,8 @@ import org.xml.sax.InputSource; import org.xml.sax.XMLReader; + + /** * The schematoron Engine. Validates an XML for given scheamtron rules using an XSLT implementation of the Schematron * Engine. @@ -36,38 +39,38 @@ */ public class SchematronProcessor { - private Logger logger = LoggerFactory.getLogger(SchematronProcessor.class); - private XMLReader reader; - private Templates templates; + private Logger logger = LoggerFactory.getLogger(SchematronProcessor.class); + private XMLReader reader; + private Templates templates; - /** - * Constructor setting the XSLT schematron templates. - * - * @param reader - * @param templates - */ - public SchematronProcessor(XMLReader reader, Templates templates) { + /** + * Constructor setting the XSLT schematron templates. + * + * @param reader + * @param templates + */ + public SchematronProcessor(XMLReader reader, Templates templates) { - this.reader = reader; - this.templates = templates; - } + this.reader = reader; + this.templates = templates; + } - /** - * Validates the given XML for given Rules. - * - * @param xml - * @return - */ - public String validate(final String xml) { + /** + * Validates the given XML for given Rules. + * + * @param xml + * @return + */ + public String validate(final String xml) { - try { - final Source source = new SAXSource(reader, new InputSource(IOUtils.toInputStream(xml))); - final StringWriter writer = new StringWriter(); - templates.newTransformer().transform(source, new StreamResult(writer)); - return writer.toString(); - } catch (TransformerException e) { - logger.error(e.getMessage()); - throw new SchematronValidationException("Failed to apply Schematron validation transform", e); + try { + final Source source = new SAXSource(reader, new InputSource(IOUtils.toInputStream(xml))); + final StringWriter writer = new StringWriter(); + templates.newTransformer().transform(source, new StreamResult(writer)); + return writer.toString(); + } catch (TransformerException e) { + logger.error(e.getMessage()); + throw new SchematronValidationException("Failed to apply Schematron validation transform", e); + } } - } } diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java index 896acc12bd526..b461c3b74b644 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java @@ -16,8 +16,11 @@ */ package org.apache.camel.component.schematron.processor; -import java.io.File; -import java.io.InputStream; +import org.apache.camel.component.schematron.constant.Constants; +import org.apache.camel.component.schematron.exception.SchematronConfigException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Node; import javax.xml.transform.Source; import javax.xml.transform.Templates; @@ -26,73 +29,66 @@ import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamSource; - -import org.apache.camel.component.schematron.constant.Constants; -import org.apache.camel.component.schematron.exception.SchematronConfigException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Node; +import java.io.File; +import java.io.InputStream; /** * Class generating Templates for a given schematron rules */ public final class TemplatesFactory { - private Logger logger = LoggerFactory.getLogger(TemplatesFactory.class); - private static final String LINE_NUMBERING = "http://saxon.sf.net/feature/linenumbering"; - private static final TemplatesFactory INSTANCE = new TemplatesFactory(); - private static final String[] PIPELINE = new String[] { "iso_dsdl_include.xsl", "iso_abstract_expand.xsl", - "iso_svrl_for_xslt2.xsl" }; + private static final String LINE_NUMBERING = "http://saxon.sf.net/feature/linenumbering"; + private static final TemplatesFactory INSTANCE = new TemplatesFactory(); + private static final String[] PIPELINE = new String[]{"iso_dsdl_include.xsl", "iso_abstract_expand.xsl", "iso_svrl_for_xslt2.xsl"}; + private Logger logger = LoggerFactory.getLogger(TemplatesFactory.class); - /** - * Singleton constructor; - * - * @return - */ - public static TemplatesFactory newInstance() { + /** + * Singleton constructor; + * + * @return + */ + public static TemplatesFactory newInstance() { - return INSTANCE; - } + return INSTANCE; + } - /** - * Returns an instance of compiled schematron templates. - * - * @return - */ - public Templates newTemplates(final InputStream rules) { + /** + * Returns an instance of compiled schematron templates. + * + * @return + */ + public Templates newTemplates(final InputStream rules) { - TransformerFactory fac = TransformerFactory.newInstance(); - fac.setURIResolver(new ClassPathURIResolver(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR)); - fac.setAttribute(LINE_NUMBERING, true); - return getTemplates(rules, fac); - } + TransformerFactory fac = TransformerFactory.newInstance(); + fac.setURIResolver(new ClassPathURIResolver(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR)); + fac.setAttribute(LINE_NUMBERING, true); + return getTemplates(rules, fac); + } - /** - * Generate the schematron template for given rule. - * - * @param rules - * the schematron rules - * @param fac - * the transformer factory. - * @return schematron template. - */ - private Templates getTemplates(InputStream rules, TransformerFactory fac) { + /** + * Generate the schematron template for given rule. + * + * @param rules the schematron rules + * @param fac the transformer factory. + * @return schematron template. + */ + private Templates getTemplates(InputStream rules, TransformerFactory fac) { - Node node = null; - Source source = new StreamSource(rules); - try { - for (String template : PIPELINE) { - Source xsl = new StreamSource(ClassLoader.getSystemResourceAsStream(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR - .concat(File.separator).concat(template))); - Transformer t = fac.newTransformer(xsl); - DOMResult result = new DOMResult(); - t.transform(source, result); - source = new DOMSource(node = result.getNode()); - } - return fac.newTemplates(new DOMSource(node)); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new SchematronConfigException(e); + Node node = null; + Source source = new StreamSource(rules); + try { + for (String template : PIPELINE) { + Source xsl = new StreamSource(ClassLoader.getSystemResourceAsStream(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR + .concat(File.separator).concat(template))); + Transformer t = fac.newTransformer(xsl); + DOMResult result = new DOMResult(); + t.transform(source, result); + source = new DOMSource(node = result.getNode()); + } + return fac.newTemplates(new DOMSource(node)); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new SchematronConfigException(e); + } } - } } diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java index 4577a9a20c95d..198a176ff2799 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java @@ -18,24 +18,21 @@ import org.apache.camel.component.schematron.util.Utils; import org.apache.commons.io.IOUtils; -import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.DifferenceListener; -import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.xml.transform.Templates; + import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; /** * SchematronEngine Unit Test. - * */ public class SchematronProcessorTest { private Logger logger = LoggerFactory.getLogger(SchematronProcessorTest.class); + @Test public void testValidXML() throws Exception { @@ -57,7 +54,7 @@ public void testInValidXML() throws Exception { String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); logger.info("Validating payload: {}", payload); // validate - String result = getProcessor("sch/schematron-2.sch").validate(payload); + String result = getProcessor("sch/schematron-2.sch").validate(payload); logger.info("Schematron Report: {}", result); // should throw two assertions because of the missing chapters in the XML. assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert/svrl:text", result)); @@ -72,10 +69,8 @@ public void testInValidXML() throws Exception { * @param schematron * @return */ - private SchematronProcessor getProcessor(final String schematron) - { + private SchematronProcessor getProcessor(final String schematron) { Templates rules = TemplatesFactory.newInstance().newTemplates(ClassLoader.getSystemResourceAsStream(schematron)); return SchematronProcessorFactory.newScehamtronEngine(rules); - } } From 472af755f88f6e8b8a358e8ca3fc5487e29226eb Mon Sep 17 00:00:00 2001 From: Ayache Khettar Date: Sun, 3 Aug 2014 14:15:27 +0100 Subject: [PATCH 15/17] tidy up --- components/camel-schematron/pom.xml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/components/camel-schematron/pom.xml b/components/camel-schematron/pom.xml index 82d352c94af2d..5400290e007d5 100644 --- a/components/camel-schematron/pom.xml +++ b/components/camel-schematron/pom.xml @@ -37,19 +37,11 @@ org.apache.camel camel-core - - net.sf.saxon Saxon-HE ${saxon-version} - - xmlunit - xmlunit - ${xmlunit-version} - test - commons-lang commons-lang @@ -67,5 +59,11 @@ camel-test test + + xmlunit + xmlunit + ${xmlunit-version} + test + From 1889b2d830b914f34adab8e9b8e28e28a630cf1a Mon Sep 17 00:00:00 2001 From: Ayache Khettar Date: Sun, 3 Aug 2014 14:20:53 +0100 Subject: [PATCH 16/17] removing redundant libraries --- components/camel-schematron/pom.xml | 10 +++++----- .../camel/component/schematron/SchematronProducer.java | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/components/camel-schematron/pom.xml b/components/camel-schematron/pom.xml index 5400290e007d5..5d6e5adf0d0d7 100644 --- a/components/camel-schematron/pom.xml +++ b/components/camel-schematron/pom.xml @@ -42,11 +42,11 @@ Saxon-HE ${saxon-version} - - commons-lang - commons-lang - ${commons-lang-version} - + + + + + commons-io commons-io diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java index 0fdb2090aff1e..e5d000b534ee3 100644 --- a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java +++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java @@ -24,7 +24,6 @@ import org.apache.camel.component.schematron.exception.SchematronValidationException; import org.apache.camel.component.schematron.processor.SchematronProcessorFactory; import org.apache.camel.impl.DefaultProducer; -import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -89,8 +88,8 @@ private void setValidationReport(Exchange exchange, String report, String status * @return */ private String getValidationStatus(final String report) { - String status = StringUtils.contains(report, - Constants.FAILED_ASSERT) ? Constants.FAILED : Constants.SUCCESS; + + String status = report.contains(Constants.FAILED_ASSERT) ? Constants.FAILED : Constants.SUCCESS; if (this.endpoint.isAbort() && Constants.FAILED.equals(status)) { throw new SchematronValidationException("Schematron validation failure \n" + report); } From 8464137cab2d52ce3e15aea6342826cbf0bbf6cb Mon Sep 17 00:00:00 2001 From: Ayache Khettar Date: Sun, 3 Aug 2014 14:55:06 +0100 Subject: [PATCH 17/17] adding camel-schematron feature --- components/camel-schematron/pom.xml | 5 ----- .../karaf/features/src/main/resources/features.xml | 10 ++++++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/components/camel-schematron/pom.xml b/components/camel-schematron/pom.xml index 5d6e5adf0d0d7..88440dc9174ee 100644 --- a/components/camel-schematron/pom.xml +++ b/components/camel-schematron/pom.xml @@ -42,11 +42,6 @@ Saxon-HE ${saxon-version} - - - - - commons-io commons-io diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml index 9b640324e59ab..36b9ac414b046 100644 --- a/platforms/karaf/features/src/main/resources/features.xml +++ b/platforms/karaf/features/src/main/resources/features.xml @@ -216,7 +216,7 @@ mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.castor/${castor-bundle-version} mvn:org.apache.camel/camel-castor/${project.version} -