Removed unused code

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@117259 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-07-15 15:41:00 +00:00
parent 2d93244574
commit 56dc022713
2 changed files with 73 additions and 69 deletions

View File

@ -10,11 +10,12 @@ import org.gcube.portlets.widgets.fileupload.client.view.UploadProgressDialog;
import com.extjs.gxt.ui.client.widget.Info; import com.extjs.gxt.ui.client.widget.Info;
import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.event.shared.HandlerManager;
/** /**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * The Class FileUploader.
* @Jan 20, 2014
* *
* This class calls the widget file uploader * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 15, 2015
*/ */
public class FileUploader { public class FileUploader {
@ -22,11 +23,14 @@ public class FileUploader {
private final UploadProgressDialog dlg; private final UploadProgressDialog dlg;
private FileModel folderParent; private FileModel folderParent;
private UpdateServiceUploader updateServiceUploader; private UpdateServiceUploader updateServiceUploader;
private FileUploader INSTANCE = this;
private String uploadType; private String uploadType;
/** /**
* * Instantiates a new file uploader.
*
* @param eventBus the event bus
* @param folderParent the folder parent
* @param uploadType the upload type
*/ */
public FileUploader(HandlerManager eventBus, FileModel folderParent, String uploadType) { public FileUploader(HandlerManager eventBus, FileModel folderParent, String uploadType) {
this.folderParent = folderParent; this.folderParent = folderParent;
@ -35,7 +39,7 @@ public class FileUploader {
/** /**
* Prepare new servlet uploader * Prepare new servlet uploader
*/ */
updateServiceUploader = new UpdateServiceUploader(INSTANCE, folderParent, uploadType); updateServiceUploader = new UpdateServiceUploader(this, folderParent, uploadType);
String caption = "Upload "; String caption = "Upload ";
if(uploadType.compareTo(ConstantsExplorer.ARCHIVE)==0) if(uploadType.compareTo(ConstantsExplorer.ARCHIVE)==0)
@ -45,58 +49,83 @@ public class FileUploader {
caption+= " in: "+folderParent.getName(); caption+= " in: "+folderParent.getName();
this.dlg = new UploadProgressDialog(caption, eventBus, true); dlg = new UploadProgressDialog(caption, eventBus, true);
dlg.center(); dlg.center();
dlg.show(); dlg.show();
} }
/**
* Submit form.
*/
public void submitForm() { public void submitForm() {
try { try {
dlg.submitForm(); dlg.submitForm();
} catch (Exception e) { } catch (Exception e) {
Info.display("Error", "Sorry an error occurred on the server "+e.getLocalizedMessage() + ". Please try again later"); Info.display("Error", "Sorry an error occurred on the server "+e.getLocalizedMessage() + ". Please try again later");
e.printStackTrace(); e.printStackTrace();
} }
} }
/**
* Overwrite.
*/
public void overwrite(){ public void overwrite(){
updateServiceUploader.setOverwrite(); updateServiceUploader.setOverwrite();
} }
/**
* Submit servlet form.
*
* @param absolutePathOnServer the absolute path of the file uploaded on the server
*/
public void submitServletForm(String absolutePathOnServer){ public void submitServletForm(String absolutePathOnServer){
updateServiceUploader.setFileName(absolutePathOnServer); updateServiceUploader.setFileName(absolutePathOnServer);
try { try {
updateServiceUploader.submitForm(); updateServiceUploader.submitForm();
} catch (Exception e) { } catch (Exception e) {
dlg.showRegisteringResult(false); dlg.showRegisteringResult(false);
} }
} }
/**
* Gets the folder parent.
*
* @return the folder parent
*/
public FileModel getFolderParent() { public FileModel getFolderParent() {
return folderParent; return folderParent;
} }
/**
* Gets the upload type.
*
* @return the upload type
*/
public String getUploadType() { public String getUploadType() {
return uploadType; return uploadType;
} }
public UpdateServiceUploader getUpdateServiceUploader() { /**
return updateServiceUploader; * Show registering result.
*
* @param b the b
* @param message the message
*/
public void showRegisteringResult(boolean b, String message) {
this.dlg.showRegisteringResult(b, message);
} }
public UploadProgressDialog getDlg() {
return dlg; /**
* Show registering result.
*
* @param b the b
*/
public void showRegisteringResult(boolean b) {
this.dlg.showRegisteringResult(b);
} }
} }

View File

@ -47,14 +47,12 @@ public class UpdateServiceUploader extends Window{
this.fileUploaderDlg = fileUploader; this.fileUploaderDlg = fileUploader;
this.parent = parent; this.parent = parent;
this.uploadType = uploadType; this.uploadType = uploadType;
} }
public static String encodeUrlDelimiters(String s) { public static String encodeUrlDelimiters(String s) {
if (s == null) { if (s == null) {
return null; return null;
} }
s = s.replaceAll(";", "%2F"); s = s.replaceAll(";", "%2F");
s = s.replaceAll("/", "%2F"); s = s.replaceAll("/", "%2F");
s = s.replaceAll(":", "%3A"); s = s.replaceAll(":", "%3A");
@ -65,7 +63,6 @@ public class UpdateServiceUploader extends Window{
s = s.replaceAll("\\$", "%24"); s = s.replaceAll("\\$", "%24");
s = s.replaceAll(",", "%2C"); s = s.replaceAll(",", "%2C");
s = s.replaceAll("#", "%23"); s = s.replaceAll("#", "%23");
return s; return s;
} }
@ -78,11 +75,8 @@ public class UpdateServiceUploader extends Window{
String parameters = ""; String parameters = "";
String fileNameEscaped = URL.encodeQueryString(fileName); String fileNameEscaped = URL.encodeQueryString(fileName);
// fileNameEscaped = encodeUrlDelimiters(fileNameEscaped);
parameters+=ConstantsExplorer.UPLOAD_FORM_ELEMENT+"="+fileNameEscaped+"&"; parameters+=ConstantsExplorer.UPLOAD_FORM_ELEMENT+"="+fileNameEscaped+"&";
if(parent.getIdentifier()!=null && !parent.getIdentifier().isEmpty()) if(parent.getIdentifier()!=null && !parent.getIdentifier().isEmpty())
parameters+=ConstantsExplorer.ID_FOLDER+"="+parent.getIdentifier()+"&"; parameters+=ConstantsExplorer.ID_FOLDER+"="+parent.getIdentifier()+"&";
else else
@ -95,19 +89,11 @@ public class UpdateServiceUploader extends Window{
parameters+=ConstantsExplorer.IS_OVERWRITE+"="+overwrite; parameters+=ConstantsExplorer.IS_OVERWRITE+"="+overwrite;
// String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+parameters;
// StringBuilder sb = new StringBuilder();
// sb.append(parameters);
GWT.log("Encoded parameters are: "+parameters); GWT.log("Encoded parameters are: "+parameters);
String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+parameters; // String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+parameters;
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE); RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE);
requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded"); requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded");
// requestBuilder.setRequestData(parameters);
try { try {
@ -133,46 +119,35 @@ public class UpdateServiceUploader extends Window{
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult); final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
switch (resultMessage.getStatus()) { switch (resultMessage.getStatus()) {
case ERROR: case ERROR:
// new MessageBoxAlert("Error during upload", resultMessage.getMessage(), null); GWT.log("Error during upload: "+resultMessage.getMessage());
GWT.log("Error during upload: "+resultMessage.getMessage()); fileUploaderDlg.showRegisteringResult(false, resultMessage.getMessage());
// fileUploaderDlg.getDlg().showRegisteringResult(false); break;
fileUploaderDlg.getDlg().showRegisteringResult(false, resultMessage.getMessage()); case UNKNOWN:
break; GWT.log("Error during upload: "+resultMessage.getMessage());
case UNKNOWN: fileUploaderDlg.showRegisteringResult(false, "Error during upload: "+resultMessage.getMessage());
// new MessageBoxAlert("Error during upload", resultMessage.getMessage(), null); break;
GWT.log("Error during upload: "+resultMessage.getMessage()); case WARN: {
// fileUploaderDlg.getDlg().showRegisteringResult(false); GWT.log("Upload completed with warnings: "+resultMessage.getMessage());
fileUploaderDlg.getDlg().showRegisteringResult(false, "Error during upload: "+resultMessage.getMessage()); fileUploaderDlg.showRegisteringResult(false, "Upload completed with warnings: "+resultMessage.getMessage());
break; break;
case WARN: { }
// new MessageBoxAlert("Upload completed with warnings", resultMessage.getMessage(), null); case OK: {
GWT.log("Upload completed with warnings: "+resultMessage.getMessage()); Timer t = new Timer() {
// fileUploaderDlg.getDlg().showRegisteringResult(false); public void run() {
fileUploaderDlg.getDlg().showRegisteringResult(false, "Upload completed with warnings: "+resultMessage.getMessage()); AppControllerExplorer.getEventBus().fireEvent(new CompletedFileUploadEvent(parent, null));
break; fileUploaderDlg.showRegisteringResult(true);
} }
case OK: { };
Timer t = new Timer() {
public void run() { t.schedule(250);
AppControllerExplorer.getEventBus().fireEvent(new CompletedFileUploadEvent(parent, null)); }
fileUploaderDlg.getDlg().showRegisteringResult(true);
// new InfoDisplayMessage("Upload completed successfully", resultMessage.getMessage());
}
};
t.schedule(250);
}
} }
} }
@Override @Override
public void onError(Request request, Throwable exception) { public void onError(Request request, Throwable exception) {
// MessageUtil.showErrorMessage("Error during upload", "An error occurred during file upload."); fileUploaderDlg.showRegisteringResult(false);
fileUploaderDlg.getDlg().showRegisteringResult(false);
// new MessageBoxAlert("Error during upload", "An error occurred during file upload.", null);
return; return;
} }
}); });