/** * Download the file offer given a file ID. * * <p>package-private for testing * * @param fileId identifier to look up the file offer message */ void downloadFileOffer(String fileId) { Map<String, MessageFileOffer> fileOffers = conversation.getFileOfferMessages(); MessageFileOffer msgWithfileOffer = fileOffers.get(fileId); SearchResult file = null; try { file = remoteFileItemFactory.create( msgWithfileOffer.getPresence(), msgWithfileOffer.getFileOffer()); DownloadItem dl = downloader.addDownload(null, Collections.singletonList(file)); // Track download states by adding listeners to dl item addPropertyListener(dl, msgWithfileOffer); } catch (DownloadException e) { final SearchResult remoteFileItem = file; final MessageFileOffer messageFileOffer = msgWithfileOffer; downloadExceptionHandler .get() .handleDownloadException( new DownloadAction() { @Override public void download(File saveFile, boolean overwrite) throws DownloadException { DownloadItem dl = downloader.addDownload( null, Collections.singletonList(remoteFileItem), saveFile, overwrite); addPropertyListener(dl, messageFileOffer); } @Override public void downloadCanceled(DownloadException ignored) { // nothing to do } }, e, true); } catch (InvalidDataException ide) { // this means the FileMetaData we received isn't well-formed. LOG.error("Unable to access remote file", ide); FocusJOptionPane.showMessageDialog( null, I18n.tr("Unable to access remote file"), I18n.tr("Hyperlink"), JOptionPane.WARNING_MESSAGE); } }
private void addFileOfferMessage(MessageFileOffer msgWithFileOffer) { String fileOfferID = msgWithFileOffer.getFileOffer().getId(); idToMessageWithFileOffer.put(fileOfferID, msgWithFileOffer); }