|
|
|
@ -42,6 +42,9 @@ import javax.xml.XMLConstants; |
|
|
|
import javax.xml.datatype.Duration; |
|
|
|
import javax.xml.datatype.Duration; |
|
|
|
import javax.xml.datatype.XMLGregorianCalendar; |
|
|
|
import javax.xml.datatype.XMLGregorianCalendar; |
|
|
|
import javax.xml.namespace.QName; |
|
|
|
import javax.xml.namespace.QName; |
|
|
|
|
|
|
|
import javax.xml.parsers.ParserConfigurationException; |
|
|
|
|
|
|
|
import javax.xml.parsers.SAXParser; |
|
|
|
|
|
|
|
import javax.xml.parsers.SAXParserFactory; |
|
|
|
import javax.xml.stream.XMLEventReader; |
|
|
|
import javax.xml.stream.XMLEventReader; |
|
|
|
import javax.xml.stream.XMLEventWriter; |
|
|
|
import javax.xml.stream.XMLEventWriter; |
|
|
|
import javax.xml.stream.XMLStreamReader; |
|
|
|
import javax.xml.stream.XMLStreamReader; |
|
|
|
@ -575,8 +578,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation") |
|
|
|
private Schema loadSchema(Resource[] resources, String schemaLanguage) throws IOException, SAXException, ParserConfigurationException { |
|
|
|
private Schema loadSchema(Resource[] resources, String schemaLanguage) throws IOException, SAXException { |
|
|
|
|
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
logger.debug("Setting validation schema to " + |
|
|
|
logger.debug("Setting validation schema to " + |
|
|
|
StringUtils.arrayToCommaDelimitedString(this.schemaResources)); |
|
|
|
StringUtils.arrayToCommaDelimitedString(this.schemaResources)); |
|
|
|
@ -584,8 +586,11 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi |
|
|
|
Assert.notEmpty(resources, "No resources given"); |
|
|
|
Assert.notEmpty(resources, "No resources given"); |
|
|
|
Assert.hasLength(schemaLanguage, "No schema language provided"); |
|
|
|
Assert.hasLength(schemaLanguage, "No schema language provided"); |
|
|
|
Source[] schemaSources = new Source[resources.length]; |
|
|
|
Source[] schemaSources = new Source[resources.length]; |
|
|
|
XMLReader xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader(); |
|
|
|
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); |
|
|
|
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); |
|
|
|
saxParserFactory.setNamespaceAware(true); |
|
|
|
|
|
|
|
saxParserFactory.setFeature("http://xml.org/sax/features/namespace-prefixes", true); |
|
|
|
|
|
|
|
SAXParser saxParser = saxParserFactory.newSAXParser(); |
|
|
|
|
|
|
|
XMLReader xmlReader = saxParser.getXMLReader(); |
|
|
|
for (int i = 0; i < resources.length; i++) { |
|
|
|
for (int i = 0; i < resources.length; i++) { |
|
|
|
Resource resource = resources[i]; |
|
|
|
Resource resource = resources[i]; |
|
|
|
Assert.isTrue(resource != null && resource.exists(), () -> "Resource does not exist: " + resource); |
|
|
|
Assert.isTrue(resource != null && resource.exists(), () -> "Resource does not exist: " + resource); |
|
|
|
@ -854,7 +859,6 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation") |
|
|
|
|
|
|
|
private Source processSource(Source source) { |
|
|
|
private Source processSource(Source source) { |
|
|
|
if (StaxUtils.isStaxSource(source) || source instanceof DOMSource) { |
|
|
|
if (StaxUtils.isStaxSource(source) || source instanceof DOMSource) { |
|
|
|
return source; |
|
|
|
return source; |
|
|
|
@ -881,17 +885,20 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
if (xmlReader == null) { |
|
|
|
if (xmlReader == null) { |
|
|
|
xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader(); |
|
|
|
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); |
|
|
|
|
|
|
|
saxParserFactory.setNamespaceAware(true); |
|
|
|
|
|
|
|
saxParserFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", !isSupportDtd()); |
|
|
|
|
|
|
|
String name = "http://xml.org/sax/features/external-general-entities"; |
|
|
|
|
|
|
|
saxParserFactory.setFeature(name, isProcessExternalEntities()); |
|
|
|
|
|
|
|
SAXParser saxParser = saxParserFactory.newSAXParser(); |
|
|
|
|
|
|
|
xmlReader = saxParser.getXMLReader(); |
|
|
|
} |
|
|
|
} |
|
|
|
xmlReader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", !isSupportDtd()); |
|
|
|
|
|
|
|
String name = "http://xml.org/sax/features/external-general-entities"; |
|
|
|
|
|
|
|
xmlReader.setFeature(name, isProcessExternalEntities()); |
|
|
|
|
|
|
|
if (!isProcessExternalEntities()) { |
|
|
|
if (!isProcessExternalEntities()) { |
|
|
|
xmlReader.setEntityResolver(NO_OP_ENTITY_RESOLVER); |
|
|
|
xmlReader.setEntityResolver(NO_OP_ENTITY_RESOLVER); |
|
|
|
} |
|
|
|
} |
|
|
|
return new SAXSource(xmlReader, inputSource); |
|
|
|
return new SAXSource(xmlReader, inputSource); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (SAXException ex) { |
|
|
|
catch (SAXException | ParserConfigurationException ex) { |
|
|
|
logger.info("Processing of external entities could not be disabled", ex); |
|
|
|
logger.info("Processing of external entities could not be disabled", ex); |
|
|
|
return source; |
|
|
|
return source; |
|
|
|
} |
|
|
|
} |
|
|
|
|