Skip to content

Commit 3e11385

Browse files
committed
SWS-409
1 parent 8fb6f09 commit 3e11385

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

xml/src/main/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaCollection.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,18 @@ public void afterPropertiesSet() throws IOException {
143143
for (int i = 0; i < xsdResources.length; i++) {
144144
Resource xsdResource = xsdResources[i];
145145
Assert.isTrue(xsdResource.exists(), xsdResource + " does not exit");
146-
XmlSchema xmlSchema = schemaCollection
147-
.read(SaxUtils.createInputSource(xsdResource), validationEventHandler);
148-
xmlSchemas.add(xmlSchema);
146+
try {
147+
XmlSchema xmlSchema = schemaCollection
148+
.read(SaxUtils.createInputSource(xsdResource), validationEventHandler);
149+
xmlSchemas.add(xmlSchema);
149150

150-
if (inline) {
151-
inlineIncludes(xmlSchema, processedIncludes, processedImports);
152-
findImports(xmlSchema, processedImports, processedIncludes);
151+
if (inline) {
152+
inlineIncludes(xmlSchema, processedIncludes, processedImports);
153+
findImports(xmlSchema, processedImports, processedIncludes);
154+
}
155+
}
156+
catch (Exception ex) {
157+
throw new CommonsXsdSchemaException("Schema [" + xsdResource + "] could not be loaded", ex);
153158
}
154159
}
155160
if (logger.isInfoEnabled()) {

xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaCollectionTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,16 @@ public void testCreateValidator() throws Exception {
108108
XmlValidator validator = collection.createValidator();
109109
assertNotNull("No XmlValidator returned", validator);
110110
}
111+
112+
public void testInvalidSchema() throws Exception {
113+
Resource invalid = new ClassPathResource("invalid.xsd", AbstractXsdSchemaTestCase.class);
114+
collection.setXsds(new Resource[]{invalid});
115+
try {
116+
collection.afterPropertiesSet();
117+
fail("CommonsXsdSchemaException expected");
118+
}
119+
catch (CommonsXsdSchemaException ex) {
120+
// expected
121+
}
122+
}
111123
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3+
targetNamespace="urn:1"
4+
xmlns="urn:1"
5+
xmlns:imported="urn:2" elementFormDefault="qualified">
6+
<xsd:include schemaLocation="X.xsd"/>
7+
<!--<xsd:import schemaLocation="D.xsd" namespace="urn:2"/>-->
8+
<xsd:complexType name="B">
9+
<xsd:sequence>
10+
<xsd:element type="C" name="c"/>
11+
<xsd:element type="imported:D" name="d"/>
12+
</xsd:sequence>
13+
</xsd:complexType>
14+
</xsd:schema>

0 commit comments

Comments
 (0)