Spring for Android

org.springframework.http.converter.xml
Class SourceHttpMessageConverter<T extends javax.xml.transform.Source>

java.lang.Object
  extended by org.springframework.http.converter.AbstractHttpMessageConverter<T>
      extended by org.springframework.http.converter.xml.SourceHttpMessageConverter<T>
All Implemented Interfaces:
HttpMessageConverter<T>

public class SourceHttpMessageConverter<T extends javax.xml.transform.Source>
extends AbstractHttpMessageConverter<T>

Implementation of HttpMessageConverter that can read and write Source objects.

Since:
1.0
Author:
Arjen Poutsma, Rossen Stoyanchev Roy Clarkson

Constructor Summary
SourceHttpMessageConverter()
          Sets the supportedMediaTypes to text/xml and application/xml, and application/*-xml.
 
Method Summary
protected  java.lang.Long getContentLength(T t, MediaType contentType)
          Returns the content length for the given type.
 boolean isProcessExternalEntities()
          Returns the configured value for whether XML external entities are allowed.
protected  T readInternal(java.lang.Class<? extends T> clazz, HttpInputMessage inputMessage)
          Abstract template method that reads the actual object.
 void setProcessExternalEntities(boolean processExternalEntities)
          Indicates whether external XML entities are processed when converting to a Source.
 boolean supports(java.lang.Class<?> clazz)
          Indicates whether the given class is supported by this converter.
protected  void writeInternal(T t, HttpOutputMessage outputMessage)
          Abstract template method that writes the actual body.
 
Methods inherited from class org.springframework.http.converter.AbstractHttpMessageConverter
canRead, canRead, canWrite, canWrite, getDefaultContentType, getSupportedMediaTypes, read, setSupportedMediaTypes, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SourceHttpMessageConverter

public SourceHttpMessageConverter()
Sets the supportedMediaTypes to text/xml and application/xml, and application/*-xml.

Method Detail

setProcessExternalEntities

public void setProcessExternalEntities(boolean processExternalEntities)
Indicates whether external XML entities are processed when converting to a Source.

Default is false, meaning that external entities are not resolved.

Note: This feature is not supported when reading DOMSource entities and is only supported on Android 4.0 and newer when reading SAXSource.


isProcessExternalEntities

public boolean isProcessExternalEntities()
Returns the configured value for whether XML external entities are allowed.


supports

public boolean supports(java.lang.Class<?> clazz)
Description copied from class: AbstractHttpMessageConverter
Indicates whether the given class is supported by this converter.

Specified by:
supports in class AbstractHttpMessageConverter<T extends javax.xml.transform.Source>
Parameters:
clazz - the class to test for support
Returns:
true if supported; false otherwise

readInternal

protected T readInternal(java.lang.Class<? extends T> clazz,
                         HttpInputMessage inputMessage)
                                                     throws java.io.IOException,
                                                            HttpMessageNotReadableException
Description copied from class: AbstractHttpMessageConverter
Abstract template method that reads the actual object. Invoked from AbstractHttpMessageConverter.read(java.lang.Class, org.springframework.http.HttpInputMessage).

Specified by:
readInternal in class AbstractHttpMessageConverter<T extends javax.xml.transform.Source>
Parameters:
clazz - the type of object to return
inputMessage - the HTTP input message to read from
Returns:
the converted object
Throws:
java.io.IOException - in case of I/O errors
HttpMessageNotReadableException - in case of conversion errors

getContentLength

protected java.lang.Long getContentLength(T t,
                                          MediaType contentType)
Description copied from class: AbstractHttpMessageConverter
Returns the content length for the given type.

By default, this returns null, meaning that the content length is unknown. Can be overridden in subclasses.

Overrides:
getContentLength in class AbstractHttpMessageConverter<T extends javax.xml.transform.Source>
Parameters:
t - the type to return the content length for
Returns:
the content length, or null if not known

writeInternal

protected void writeInternal(T t,
                             HttpOutputMessage outputMessage)
                      throws java.io.IOException,
                             HttpMessageNotWritableException
Description copied from class: AbstractHttpMessageConverter
Abstract template method that writes the actual body. Invoked from AbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage).

Specified by:
writeInternal in class AbstractHttpMessageConverter<T extends javax.xml.transform.Source>
Parameters:
t - the object to write to the output message
outputMessage - the HTTP output message to write to
Throws:
java.io.IOException - in case of I/O errors
HttpMessageNotWritableException - in case of conversion errors

Spring for Android