*/
public OutboundVariable convertOutbound(final Object object, OutboundContext outboundContext) throws ConversionException
{
if (object == null)
{
return new NonNestedOutboundVariable("null");
}
try
{
FileTransfer transfer;
if (object instanceof BufferedImage)
{
transfer = new FileTransfer((BufferedImage) object, "png");
}
else if (object instanceof InputStream)
{
final InputStream in = (InputStream) object;
transfer = new FileTransfer("download.dat", "binary/octet-stream", -1, new InputStreamFactory()
{
public InputStream getInputStream() throws IOException
{
return in;
}
public void close() throws IOException
{
in.close();
}
});
}
else if (object instanceof FileTransfer)
{
transfer = (FileTransfer) object;
}
else if (object.getClass().isArray() && object.getClass().getComponentType() == Byte.TYPE)
{
transfer = new FileTransfer("download.dat", "binary/octet-stream", (byte[]) object);
}
else
{
throw new ConversionException(object.getClass());
}
Container container = WebContextFactory.get().getContainer();
boolean preferDataUrlSchema = ContainerUtil.getBooleanSetting(container, "preferDataUrlSchema", false);
DownloadManager downloadManager;
if (preferDataUrlSchema && isDataUrlAvailable())
{
downloadManager = new DataUrlDownloadManager();
}
else
{
downloadManager = container.getBean(DownloadManager.class);
}
String url = downloadManager.addFileTransfer(transfer);
return new NonNestedOutboundVariable(url);
}
catch (IOException ex)
{
throw new ConversionException(getClass(), ex);
}