You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by jb...@apache.org on 2010/03/05 13:43:43 UTC
svn commit: r919393 -
/servicemix/components/engines/servicemix-validation/trunk/src/main/java/org/apache/servicemix/validation/ValidationEndpoint.java
Author: jbonofre
Date: Fri Mar 5 12:43:43 2010
New Revision: 919393
URL: http://svn.apache.org/viewvc?rev=919393&view=rev
Log:
[SMXCOMP-720] Enable validation when no namespace information is present in the XML (patch on behalf of Axel Irriger).
Modified:
servicemix/components/engines/servicemix-validation/trunk/src/main/java/org/apache/servicemix/validation/ValidationEndpoint.java
Modified: servicemix/components/engines/servicemix-validation/trunk/src/main/java/org/apache/servicemix/validation/ValidationEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-validation/trunk/src/main/java/org/apache/servicemix/validation/ValidationEndpoint.java?rev=919393&r1=919392&r2=919393&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-validation/trunk/src/main/java/org/apache/servicemix/validation/ValidationEndpoint.java (original)
+++ servicemix/components/engines/servicemix-validation/trunk/src/main/java/org/apache/servicemix/validation/ValidationEndpoint.java Fri Mar 5 12:43:43 2010
@@ -81,6 +81,8 @@
private Source schemaSource;
private Resource schemaResource;
+
+ private Resource noNamespaceSchemaResource;
private MessageAwareErrorHandlerFactory errorHandlerFactory = new CountingErrorHandlerFactory();
@@ -102,19 +104,20 @@
if (schemaSource == null) {
if (schemaResource == null) {
- throw new JBIException(
- "You must specify a schema, schemaSource or schemaResource property");
- }
- if (schemaResource.getURL() == null) {
- schemaSource = new StreamSource(schemaResource
- .getInputStream());
+ if (noNamespaceSchemaResource == null) {
+ throw new JBIException("You must specify schema, schemaSource, schemaResource or noNamespaceSchemaResource property.");
+ }
+ // Don't instantiate the schema here
+ schema = factory.newSchema();
} else {
- schemaSource = new StreamSource(schemaResource
- .getInputStream(), schemaResource.getURL()
- .toExternalForm());
+ if (schemaResource.getURL() == null) {
+ schemaSource = new StreamSource(schemaResource.getInputStream());
+ } else {
+ schemaSource = new StreamSource(schemaResource.getInputStream(), schemaResource.getURL().toExternalForm());
+ }
+ schema = factory.newSchema(schemaSource);
}
}
- schema = factory.newSchema(schemaSource);
}
} catch (IOException e) {
throw new JBIException("Failed to load schema: " + e, e);
@@ -180,7 +183,14 @@
public void startValidation(MessageExchange exchange, NormalizedMessage in,
NormalizedMessage out, Fault fault) throws Exception {
Validator validator = schema.newValidator();
-
+
+ if (noNamespaceSchemaResource != null) {
+ logger.info("Enabling validation for noNamespace-XML documents.");
+ validator.setFeature("http://xml.org/sax/features/validation", true);
+ validator.setFeature("http://apache.org/xml/features/validation/schema", true);
+ validator.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", noNamespaceSchemaResource.getURL().toExternalForm());
+ }
+
// create a new errorHandler and set it on the validator
MessageAwareErrorHandler errorHandler = errorHandlerFactory
.createMessageAwareErrorHandler();
@@ -374,6 +384,14 @@
public void setSchemaResource(Resource schemaResource) {
this.schemaResource = schemaResource;
}
+
+ public Resource getNoNamespaceSchemaResource() {
+ return noNamespaceSchemaResource;
+ }
+
+ public void setNoNamespaceSchemaResource(Resource schemaResource) {
+ this.noNamespaceSchemaResource = schemaResource;
+ }
public MessageAwareErrorHandlerFactory getErrorHandlerFactory() {
return errorHandlerFactory;