X-Git-Url: https://code.grnet.gr/git/pithos/blobdiff_plain/22eb1f84c4c0548329b1113b8fac6995292db299..b4b6e89f4ac9275f96613cc1a645b5d7c867af7d:/src/gr/ebs/gss/client/FileUploadGearsDialog.java diff --git a/src/gr/ebs/gss/client/FileUploadGearsDialog.java b/src/gr/ebs/gss/client/FileUploadGearsDialog.java index 027e317..25203a8 100644 --- a/src/gr/ebs/gss/client/FileUploadGearsDialog.java +++ b/src/gr/ebs/gss/client/FileUploadGearsDialog.java @@ -39,6 +39,7 @@ import com.google.gwt.gears.client.httprequest.HttpRequest; import com.google.gwt.gears.client.httprequest.ProgressEvent; import com.google.gwt.gears.client.httprequest.ProgressHandler; import com.google.gwt.gears.client.httprequest.RequestCallback; +import com.google.gwt.http.client.URL; import com.google.gwt.json.client.JSONObject; import com.google.gwt.json.client.JSONString; import com.google.gwt.user.client.Command; @@ -83,6 +84,8 @@ public class FileUploadGearsDialog extends FileUploadDialog implements Updateabl private Map toRename; + private List requests = new ArrayList(); + /** * The widget's constructor. */ @@ -135,7 +138,7 @@ public class FileUploadGearsDialog extends FileUploadDialog implements Updateabl Button cancel = new Button("Cancel", new ClickListener() { public void onClick(Widget sender) { - hide(); + cancelUpload(); } }); buttons.add(cancel); @@ -174,6 +177,15 @@ public class FileUploadGearsDialog extends FileUploadDialog implements Updateabl } /** + * Cancels the file upload. + */ + private void cancelUpload() { + for (HttpRequest request: requests) + request.abort(); + hide(); + } + + /** * Check whether the specified file name exists in the selected folder. */ private boolean canContinue(File file) { @@ -338,19 +350,15 @@ public class FileUploadGearsDialog extends FileUploadDialog implements Updateabl protected void doPut(final File file, final int index) { final GSS app = GSS.get(); HttpRequest request = factory.createHttpRequest(); + requests.add(request); String method = "PUT"; String path; final String filename = getFilename(file.getName()); - FileResource selectedResource = getFileForName(filename); - if (selectedResource == null ) { - // We are going to create a file. - path = folder.getUri(); - if (!path.endsWith("/")) - path = path + "/"; - path = path + encodeComponent(filename); - } else - path = selectedResource.getUri(); + path = folder.getUri(); + if (!path.endsWith("/")) + path = path + "/"; + path = path + encode(filename); String token = app.getToken(); String resource = path.substring(app.getApiPath().length()-1, path.length()); @@ -409,4 +417,15 @@ public class FileUploadGearsDialog extends FileUploadDialog implements Updateabl GSS.get().showFileList(true); GSS.get().getStatusPanel().updateStats(); } + + /** + * Same as URL.encode, but also encode apostrophe since browsers aren't + * consistent about it (FF encodes, IE does not). + */ + private String encode(String decodedURL) { + String retv = URL.encode(decodedURL); + retv = retv.replaceAll("'", "%27"); + return retv; + } + }