} else {
//convert BINARY to XML
final File file = broker.getBinaryFile((BinaryDocument) doc);
FileInputSource is = new FileInputSource(file);
final IndexInfo info = destination.validateXMLResource(txn, broker, newName, is);
info.getDocument().getMetadata().setMimeType(mimeType.getName());
is = new FileInputSource(file);
destination.store(txn, broker, info, is, false);
source.removeBinaryResource(txn, broker, doc);
}
} else {
if (doc.getResourceType() == DocumentImpl.BINARY_FILE) {
//BINARY to BINARY
//move to same type as it
broker.moveResource(txn, doc, destination, newName);
} else {
//convert XML to BINARY
// xml file
final Serializer serializer = broker.getSerializer();
serializer.setUser(broker.getSubject());
serializer.setProperties(XML_OUTPUT_PROPERTIES);
File tempFile = null;
FileInputStream is = null;
try {
tempFile = File.createTempFile("eXist-resource-", ".xml");
tempFile.deleteOnExit();
final Writer w = new OutputStreamWriter(new FileOutputStream(tempFile), "UTF-8");
serializer.serialize(doc, w);
w.flush();
w.close();
is = new FileInputStream(tempFile);
final DocumentMetadata meta = doc.getMetadata();
final Date created = new Date(meta.getCreated());
final Date lastModified = new Date(meta.getLastModified());
BinaryDocument binary = destination.validateBinaryResource(txn, broker, newName, is, mimeType.getName(), -1, created, lastModified);
binary = destination.addBinaryResource(txn, broker, binary, is, mimeType.getName(), -1, created, lastModified);
source.removeXMLResource(txn, broker, doc.getFileURI());
} finally {
if (is != null)
{is.close();}
if (tempFile != null)
{tempFile.delete();}
}
}