if ((fDirectory != null) && fDirectory.trim().equals(""))
fDirectory = null;
final String directory = fDirectory;
final String suggestDir = directory != null ? directory : System.getProperty("user.home");
File file = new File(new File(suggestDir), suggestedName);
FileListEntry entry = new FileListEntry("", bibtexKey != null ? file.getCanonicalPath() : "",
suggestedType);
editor = new FileListEntryEditor(frame, entry, true, false, metaData);
editor.getProgressBar().setIndeterminate(true);
editor.setOkEnabled(false);
editor.setExternalConfirm(new ConfirmCloseFileListEntryEditor() {
public boolean confirmClose(FileListEntry entry) {
File f = directory != null ? expandFilename(directory, entry.getLink())
: new File(entry.getLink());
if (f.isDirectory()) {
JOptionPane.showMessageDialog(frame,
Globals.lang("Target file cannot be a directory."), Globals.lang("Download file"),
JOptionPane.ERROR_MESSAGE);
return false;
}
if (f.exists()) {
return JOptionPane.showConfirmDialog
(frame, "'"+f.getName()+"' "+Globals.lang("exists. Overwrite file?"),
Globals.lang("Download file"), JOptionPane.OK_CANCEL_OPTION)
== JOptionPane.OK_OPTION;
} else
return true;
}
});
if (!dontShowDialog) // If an error occured with the URL, this flag may have been set
editor.setVisible(true, false);
else
return;
// Editor closed. Go on:
if (editor.okPressed()) {
File toFile = directory != null ? expandFilename(directory, entry.getLink())
: new File(entry.getLink());
String dirPrefix;
if (directory != null) {
if (!directory.endsWith(System.getProperty("file.separator")))
dirPrefix = directory+System.getProperty("file.separator");
else
dirPrefix = directory;
} else
dirPrefix = null;
try {
boolean success = Util.copyFile(tmp, toFile, true);
if (!success) {
// OOps, the file exists!
System.out.println("File already exists! DownloadExternalFile.download()");
}
// If the local file is in or below the main file directory, change the
// path to relative:
if ((directory != null) && entry.getLink().startsWith(directory) &&
(entry.getLink().length() > dirPrefix.length())) {
entry.setLink(entry.getLink().substring(dirPrefix.length()));
}
callback.downloadComplete(entry);
} catch (IOException ex) {
ex.printStackTrace();