Skip to content

Commit 29e9690

Browse files
committed
SPR-8349 - Ability to specify ResourceResolver property for SchemaFactory in Jaxb2Marshaller
1 parent 7428b57 commit 29e9690

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

org.springframework.oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.oxm.jaxb;
1818

19-
import java.awt.*;
19+
import java.awt.Image;
2020
import java.io.ByteArrayInputStream;
2121
import java.io.IOException;
2222
import java.io.InputStream;
@@ -65,13 +65,6 @@
6565
import javax.xml.validation.Schema;
6666
import javax.xml.validation.SchemaFactory;
6767

68-
import org.apache.commons.logging.Log;
69-
import org.apache.commons.logging.LogFactory;
70-
import org.xml.sax.InputSource;
71-
import org.xml.sax.SAXException;
72-
import org.xml.sax.XMLReader;
73-
import org.xml.sax.helpers.XMLReaderFactory;
74-
7568
import org.springframework.beans.factory.BeanClassLoaderAware;
7669
import org.springframework.beans.factory.InitializingBean;
7770
import org.springframework.core.annotation.AnnotationUtils;
@@ -94,6 +87,14 @@
9487
import org.springframework.util.StringUtils;
9588
import org.springframework.util.xml.StaxUtils;
9689

90+
import org.apache.commons.logging.Log;
91+
import org.apache.commons.logging.LogFactory;
92+
import org.w3c.dom.ls.LSResourceResolver;
93+
import org.xml.sax.InputSource;
94+
import org.xml.sax.SAXException;
95+
import org.xml.sax.XMLReader;
96+
import org.xml.sax.helpers.XMLReaderFactory;
97+
9798
/**
9899
* Implementation of the <code>Marshaller</code> interface for JAXB 2.0.
99100
*
@@ -160,6 +161,8 @@ public class Jaxb2Marshaller
160161

161162
private boolean supportJaxbElementClass = false;
162163

164+
private LSResourceResolver schemaResourceResolver;
165+
163166

164167
/**
165168
* Set multiple JAXB context paths. The given array of context paths is converted to a
@@ -286,7 +289,17 @@ public void setSchemaLanguage(String schemaLanguage) {
286289
this.schemaLanguage = schemaLanguage;
287290
}
288291

289-
/**
292+
/**
293+
* Sets the resource resolver, as used to load the schema resources.
294+
* @see SchemaFactory#setResourceResolver(org.w3c.dom.ls.LSResourceResolver)
295+
* @see #setSchema(Resource)
296+
* @see #setSchemas(Resource[])
297+
*/
298+
public void setSchemaResourceResolver(LSResourceResolver schemaResourceResolver) {
299+
this.schemaResourceResolver = schemaResourceResolver;
300+
}
301+
302+
/**
290303
* Specify whether MTOM support should be enabled or not.
291304
* Default is <code>false</code>: marshalling using XOP/MTOM not being enabled.
292305
*/
@@ -407,6 +420,9 @@ private Schema loadSchema(Resource[] resources, String schemaLanguage) throws IO
407420
schemaSources[i] = new SAXSource(xmlReader, inputSource);
408421
}
409422
SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
423+
if (schemaResourceResolver != null) {
424+
schemaFactory.setResourceResolver(schemaResourceResolver);
425+
}
410426
return schemaFactory.newSchema(schemaSources);
411427
}
412428

0 commit comments

Comments
 (0)