payload.addElement("size").setText(Long.toString(pContentLength));
XMPPServer.getInstance().getMessageRouter().route(message);
}
public void commitFile(JID user, File file, String name, String requestId) {
FileEntry entry = new PersistentFileEntry();
entry.setId(file.getName());
entry.setOwner(user.toBareJID());
entry.setName(name);
entry.setSize(file.length());
entry.setType("unknown/unknown");
// Attemtp to detect the mime type
MimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
try {
Collection<?> mimeTypes = MimeUtil.getMimeTypes(file);
if (!mimeTypes.isEmpty()) {
Iterator<?> i = mimeTypes.iterator();
if (i.hasNext()) {
MimeType mimeType = (MimeType) i.next();
entry.setType(mimeType.toString());
}
}
} catch (Exception e) {};
// Store the file in the database
// Initialize then entity manager
EntityManager em = OswPlugin.getEmFactory().createEntityManager();
em.getTransaction().begin();
em.persist(entry);
em.getTransaction().commit();
em.close();
Message message = new Message();
message.setTo(user);
Element payload = message.addChildElement("upload", "http://onesocialweb.org/spec/1.0/upload");
payload.addElement("request-id").setText(requestId);
payload.addElement("status").setText("completed");
payload.addElement("file-id").setText(file.getName());
payload.addElement("size").setText(Long.toString(entry.getSize()));
payload.addElement("mime-type").setText(entry.getType());
XMPPServer.getInstance().getMessageRouter().route(message);
}