| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.component.validator; |
| 18 |
|
|
| 19 |
|
import java.io.IOException; |
| 20 |
|
|
| 21 |
|
import javax.xml.transform.Source; |
| 22 |
|
import javax.xml.transform.stream.StreamSource; |
| 23 |
|
|
| 24 |
|
import org.apache.camel.processor.validation.ValidatingProcessor; |
| 25 |
|
|
| 26 |
|
import org.springframework.core.io.Resource; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
2 |
public class SpringValidator extends ValidatingProcessor { |
| 32 |
|
private Resource schemaResource; |
| 33 |
|
|
| 34 |
|
public Resource getSchemaResource() { |
| 35 |
0 |
return schemaResource; |
| 36 |
|
} |
| 37 |
|
|
| 38 |
|
public void setSchemaResource(Resource schemaResource) { |
| 39 |
2 |
this.schemaResource = schemaResource; |
| 40 |
2 |
} |
| 41 |
|
|
| 42 |
|
@Override |
| 43 |
|
protected Source createSchemaSource() throws IOException { |
| 44 |
2 |
if (schemaResource != null) { |
| 45 |
2 |
if (schemaResource.getURL() == null) { |
| 46 |
0 |
return new StreamSource(schemaResource.getInputStream()); |
| 47 |
|
} else { |
| 48 |
2 |
return new StreamSource(schemaResource.getInputStream(), schemaResource.getURL().toExternalForm()); |
| 49 |
|
} |
| 50 |
|
} else { |
| 51 |
0 |
throw new IllegalArgumentException("You must specify a schema, schemaFile, schemaResource, schemaSource or schemaUrl property"); |
| 52 |
|
} |
| 53 |
|
} |
| 54 |
|
} |