From e738d34535d9993d812014f8caf91d44fe76ad04 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Thu, 14 Oct 2010 11:41:08 -0400 Subject: [PATCH] INT-1519 removed XmlValidator and dependency on it in favor of XmlValidator startegy in Spring --- .../xml/router/SchemaValidator.java | 52 ----------------- .../integration/xml/router/XmlValidator.java | 25 -------- .../xml/router/SchemaValidatorTests.java | 57 ------------------- 3 files changed, 134 deletions(-) delete mode 100644 spring-integration-xml/src/main/java/org/springframework/integration/xml/router/SchemaValidator.java delete mode 100644 spring-integration-xml/src/main/java/org/springframework/integration/xml/router/XmlValidator.java delete mode 100644 spring-integration-xml/src/test/java/org/springframework/integration/xml/router/SchemaValidatorTests.java diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/router/SchemaValidator.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/router/SchemaValidator.java deleted file mode 100644 index e6fd201bbf..0000000000 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/router/SchemaValidator.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed 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.springframework.integration.xml.router; - -import java.io.IOException; - -import javax.xml.transform.Source; - -import org.springframework.core.io.Resource; -import org.springframework.integration.MessagingException; -import org.springframework.xml.validation.XmlValidationException; -import org.springframework.xml.validation.XmlValidatorFactory; -import org.xml.sax.SAXParseException; - -public class SchemaValidator implements XmlValidator { - - private final org.springframework.xml.validation.XmlValidator xmlValidator; - - public SchemaValidator(Resource schemaResource, String schemaLanguage) - throws IOException { - super(); - this.xmlValidator = XmlValidatorFactory.createValidator(schemaResource, - schemaLanguage); - } - - public boolean isValid(Source source) { - try { - SAXParseException[] exceptions = xmlValidator.validate(source); - return exceptions.length < 1; - } catch (IOException ioE) { - throw new MessagingException( - "Exception applying schema validation", ioE); - } catch (XmlValidationException validationException){ - return false; - } - } - -} diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/router/XmlValidator.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/router/XmlValidator.java deleted file mode 100644 index b32ddb8816..0000000000 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/router/XmlValidator.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed 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.springframework.integration.xml.router; - -import javax.xml.transform.Source; - -public interface XmlValidator { - - public boolean isValid(Source source) ; - -} diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/router/SchemaValidatorTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/router/SchemaValidatorTests.java deleted file mode 100644 index 92642fab79..0000000000 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/router/SchemaValidatorTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed 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.springframework.integration.xml.router; - -import static org.junit.Assert.*; - -import javax.xml.XMLConstants; -import javax.xml.transform.Source; - -import org.junit.Test; -import org.springframework.core.io.ClassPathResource; -import org.springframework.integration.xml.util.XmlTestUtil; -import org.springframework.xml.transform.StringSource; - -public class SchemaValidatorTests { - - - - - - @Test - public void testValidMessageWithXsd() throws Exception{ - SchemaValidator validator = new SchemaValidator(new ClassPathResource("validationTestsSchema.xsd", SchemaValidator.class), XMLConstants.W3C_XML_SCHEMA_NS_URI); - Source source = XmlTestUtil.getDomSourceForString("hello"); - assertTrue("Document expected to be valid " ,validator.isValid(source)) ; - } - - @Test - public void testInvalidMessageWithXsd() throws Exception{ - SchemaValidator validator = new SchemaValidator(new ClassPathResource("validationTestsSchema.xsd", SchemaValidator.class), XMLConstants.W3C_XML_SCHEMA_NS_URI); - Source source = XmlTestUtil.getDomSourceForString("hello"); - assertFalse("Document not expected to be valid " ,validator.isValid(source)) ; - } - - @Test - public void testInvalidXml() throws Exception { - SchemaValidator validator = new SchemaValidator(new ClassPathResource("validationTestsSchema.xsd", SchemaValidator.class), XMLConstants.W3C_XML_SCHEMA_NS_URI); - Source source =new StringSource("something else"); - assertFalse("Document not expected to be valid " ,validator.isValid(source)) ; - } - - -}