Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -37,7 +37,6 @@ import java.util.Calendar;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.activation.DataHandler;
|
import javax.activation.DataHandler;
|
||||||
import javax.activation.DataSource;
|
import javax.activation.DataSource;
|
||||||
import javax.xml.XMLConstants;
|
import javax.xml.XMLConstants;
|
||||||
@@ -78,6 +77,7 @@ import org.xml.sax.InputSource;
|
|||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.xml.sax.XMLReader;
|
import org.xml.sax.XMLReader;
|
||||||
import org.xml.sax.helpers.XMLReaderFactory;
|
import org.xml.sax.helpers.XMLReaderFactory;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.core.JdkVersion;
|
import org.springframework.core.JdkVersion;
|
||||||
@@ -111,6 +111,7 @@ import org.springframework.util.xml.StaxUtils;
|
|||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
* @see #setContextPath(String)
|
* @see #setContextPath(String)
|
||||||
* @see #setClassesToBeBound(Class[])
|
* @see #setClassesToBeBound(Class[])
|
||||||
@@ -893,7 +894,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
|||||||
|
|
||||||
private final MimeContainer mimeContainer;
|
private final MimeContainer mimeContainer;
|
||||||
|
|
||||||
private Jaxb2AttachmentMarshaller(MimeContainer mimeContainer) {
|
public Jaxb2AttachmentMarshaller(MimeContainer mimeContainer) {
|
||||||
this.mimeContainer = mimeContainer;
|
this.mimeContainer = mimeContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -947,7 +948,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
|||||||
|
|
||||||
private final MimeContainer mimeContainer;
|
private final MimeContainer mimeContainer;
|
||||||
|
|
||||||
private Jaxb2AttachmentUnmarshaller(MimeContainer mimeContainer) {
|
public Jaxb2AttachmentUnmarshaller(MimeContainer mimeContainer) {
|
||||||
this.mimeContainer = mimeContainer;
|
this.mimeContainer = mimeContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -997,7 +998,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
|||||||
|
|
||||||
private final int length;
|
private final int length;
|
||||||
|
|
||||||
private ByteArrayDataSource(String contentType, byte[] data, int offset, int length) {
|
public ByteArrayDataSource(String contentType, byte[] data, int offset, int length) {
|
||||||
this.contentType = contentType;
|
this.contentType = contentType;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
@@ -1025,6 +1026,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final EntityResolver NO_OP_ENTITY_RESOLVER = new EntityResolver() {
|
private static final EntityResolver NO_OP_ENTITY_RESOLVER = new EntityResolver() {
|
||||||
@Override
|
@Override
|
||||||
public InputSource resolveEntity(String publicId, String systemId) {
|
public InputSource resolveEntity(String publicId, String systemId) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -26,7 +26,6 @@ import java.util.LinkedHashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.UnmarshalException;
|
import javax.xml.bind.UnmarshalException;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
@@ -54,6 +53,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException;
|
|||||||
* does not support writing.
|
* does not support writing.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@@ -62,6 +62,7 @@ public class Jaxb2CollectionHttpMessageConverter<T extends Collection>
|
|||||||
|
|
||||||
private final XMLInputFactory inputFactory = createXmlInputFactory();
|
private final XMLInputFactory inputFactory = createXmlInputFactory();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Always returns {@code false} since Jaxb2CollectionHttpMessageConverter
|
* Always returns {@code false} since Jaxb2CollectionHttpMessageConverter
|
||||||
* required generic type information in order to read a Collection.
|
* required generic type information in order to read a Collection.
|
||||||
@@ -166,7 +167,6 @@ public class Jaxb2CollectionHttpMessageConverter<T extends Collection>
|
|||||||
/**
|
/**
|
||||||
* Create a Collection of the given type, with the given initial capacity
|
* Create a Collection of the given type, with the given initial capacity
|
||||||
* (if supported by the Collection type).
|
* (if supported by the Collection type).
|
||||||
*
|
|
||||||
* @param collectionClass the type of Collection to instantiate
|
* @param collectionClass the type of Collection to instantiate
|
||||||
* @return the created Collection instance
|
* @return the created Collection instance
|
||||||
*/
|
*/
|
||||||
@@ -224,10 +224,8 @@ public class Jaxb2CollectionHttpMessageConverter<T extends Collection>
|
|||||||
/**
|
/**
|
||||||
* Create a {@code XMLInputFactory} that this converter will use to create {@link
|
* Create a {@code XMLInputFactory} that this converter will use to create {@link
|
||||||
* javax.xml.stream.XMLStreamReader} and {@link javax.xml.stream.XMLEventReader} objects.
|
* javax.xml.stream.XMLStreamReader} and {@link javax.xml.stream.XMLEventReader} objects.
|
||||||
* <p/> Can be overridden in subclasses, adding further initialization of the factory.
|
* <p>Can be overridden in subclasses, adding further initialization of the factory.
|
||||||
* The resulting factory is cached, so this method will only be called once.
|
* The resulting factory is cached, so this method will only be called once.
|
||||||
*
|
|
||||||
* @return the created factory
|
|
||||||
*/
|
*/
|
||||||
protected XMLInputFactory createXmlInputFactory() {
|
protected XMLInputFactory createXmlInputFactory() {
|
||||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||||
|
|||||||
@@ -32,6 +32,12 @@ import javax.xml.transform.Source;
|
|||||||
import javax.xml.transform.sax.SAXSource;
|
import javax.xml.transform.sax.SAXSource;
|
||||||
import javax.xml.transform.stream.StreamSource;
|
import javax.xml.transform.stream.StreamSource;
|
||||||
|
|
||||||
|
import org.xml.sax.EntityResolver;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
import org.xml.sax.XMLReader;
|
||||||
|
import org.xml.sax.helpers.XMLReaderFactory;
|
||||||
|
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@@ -39,21 +45,17 @@ import org.springframework.http.converter.HttpMessageConversionException;
|
|||||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||||
import org.springframework.http.converter.HttpMessageNotWritableException;
|
import org.springframework.http.converter.HttpMessageNotWritableException;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.xml.sax.EntityResolver;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
import org.xml.sax.XMLReader;
|
|
||||||
import org.xml.sax.helpers.XMLReaderFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverter} that can read
|
* Implementation of {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverter}
|
||||||
* and write XML using JAXB2.
|
* that can read and write XML using JAXB2.
|
||||||
*
|
*
|
||||||
* <p>This converter can read classes annotated with {@link XmlRootElement} and {@link XmlType}, and write classes
|
* <p>This converter can read classes annotated with {@link XmlRootElement} and {@link XmlType},
|
||||||
* annotated with with {@link XmlRootElement}, or subclasses thereof.
|
* and write classes annotated with with {@link XmlRootElement}, or subclasses thereof.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessageConverter<Object> {
|
public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessageConverter<Object> {
|
||||||
@@ -69,10 +71,14 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa
|
|||||||
this.processExternalEntities = processExternalEntities;
|
this.processExternalEntities = processExternalEntities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the configured value for whether XML external entities are allowed.
|
||||||
|
*/
|
||||||
public boolean isProcessExternalEntities() {
|
public boolean isProcessExternalEntities() {
|
||||||
return this.processExternalEntities;
|
return this.processExternalEntities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRead(Class<?> clazz, MediaType mediaType) {
|
public boolean canRead(Class<?> clazz, MediaType mediaType) {
|
||||||
return (clazz.isAnnotationPresent(XmlRootElement.class) || clazz.isAnnotationPresent(XmlType.class)) &&
|
return (clazz.isAnnotationPresent(XmlRootElement.class) || clazz.isAnnotationPresent(XmlType.class)) &&
|
||||||
@@ -81,7 +87,7 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
|
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
|
||||||
return AnnotationUtils.findAnnotation(clazz, XmlRootElement.class) != null && canWrite(mediaType);
|
return (AnnotationUtils.findAnnotation(clazz, XmlRootElement.class) != null && canWrite(mediaType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -61,6 +61,7 @@ import org.springframework.util.StreamUtils;
|
|||||||
* that can read and write {@link Source} objects.
|
* that can read and write {@link Source} objects.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class SourceHttpMessageConverter<T extends Source> extends AbstractHttpMessageConverter<T> {
|
public class SourceHttpMessageConverter<T extends Source> extends AbstractHttpMessageConverter<T> {
|
||||||
@@ -99,12 +100,13 @@ public class SourceHttpMessageConverter<T extends Source> extends AbstractHttpMe
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the configured value for whether XML external entities are allowed.
|
* Returns the configured value for whether XML external entities are allowed.
|
||||||
*/
|
*/
|
||||||
public boolean isProcessExternalEntities() {
|
public boolean isProcessExternalEntities() {
|
||||||
return this.processExternalEntities;
|
return this.processExternalEntities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(Class<?> clazz) {
|
public boolean supports(Class<?> clazz) {
|
||||||
return SUPPORTED_CLASSES.contains(clazz);
|
return SUPPORTED_CLASSES.contains(clazz);
|
||||||
|
|||||||
Reference in New Issue
Block a user