* @param link a String array with two elements that is modified so that the\r
* first position contains the opening tag and the second one the\r
* closing tag\r
+ * @param forceDownload If true, link will be such that browser should ask for filename\r
+ * and save location\r
*/\r
- void createDownloadLink(String[] link) {\r
+ void createDownloadLink(String[] link, boolean forceDownload) {\r
+ String downloadURL = getDownloadURL();\r
+ if (!downloadURL.isEmpty()) {\r
+ link[0] = "<a class='hidden-link' href='" + downloadURL\r
+ + (forceDownload ? "&dl=1" : "") + "' target='_blank'>";\r
+ link[1] = "</a>";\r
+ }\r
+ }\r
+\r
+ public String getDownloadURL() {\r
GSS app = GSS.get();\r
Object selection = app.getCurrentSelection();\r
if (selection != null && selection instanceof FileResource) {\r
FileResource file = (FileResource) selection;\r
+ return getDownloadURL(file);\r
+ }\r
+ return "";\r
+ }\r
+\r
+ public String getDownloadURL(FileResource file) {\r
+ GSS app = GSS.get();\r
+ if (file != null) {\r
String dateString = RestCommand.getDate();\r
String resource = file.getUri().substring(app.getApiPath().length()-1,file.getUri().length());\r
String sig = app.getCurrentUserResource().getUsername()+" "+RestCommand.calculateSig("GET", dateString, resource, RestCommand.base64decode(app.getToken()));\r
- link[0] = "<a class='hidden-link' href='" + file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString) + "' target='_blank'>";\r
- link[1] = "</a>";\r
+ return file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString);\r
}\r
+ return "";\r
}\r
\r
public MenuBar createMenu() {\r
boolean uploadVisible = GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource;\r
boolean propertiesNotVisible = selectedItem != null && (folders.isTrash(selectedItem) || folders.isMyShares(selectedItem) || folders.isOthersShared(selectedItem) || selectedItem.getUserObject() instanceof GroupUserResource);\r
contextMenu.addItem("<span>" + images.folderNew().getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images));\r
- if (uploadVisible) contextMenu.addItem("<span>" + images.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this, images));\r
+ contextMenu.addItem("<span>" + images.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this));\r
if (downloadVisible) {\r
String[] link = {"", ""};\r
- createDownloadLink(link);\r
+ createDownloadLink(link, false);\r
contextMenu.addItem("<span>" + link[0] + images.download().getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);\r
+ createDownloadLink(link, true);\r
+ contextMenu.addItem("<span>" + link[0] + images.download().getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);\r
}\r
contextMenu.addItem("<span>" + images.emptyTrash().getHTML() + " Empty Trash</span>", true, new EmptyTrashCommand(this));\r
contextMenu.addItem("<span>" + images.refresh().getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));\r