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.google.gwt.event.shared.HandlerManager;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jan 20, 2014
* The Class FileUploader.
*
* This class calls the widget file uploader
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 15, 2015
*/
public class FileUploader {
@ -22,11 +23,14 @@ public class FileUploader {
private final UploadProgressDialog dlg;
private FileModel folderParent;
private UpdateServiceUploader updateServiceUploader;
private FileUploader INSTANCE = this;
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) {
this.folderParent = folderParent;
@ -35,7 +39,7 @@ public class FileUploader {
/**
* Prepare new servlet uploader
*/
updateServiceUploader = new UpdateServiceUploader(INSTANCE, folderParent, uploadType);
updateServiceUploader = new UpdateServiceUploader(this, folderParent, uploadType);
String caption = "Upload ";
if(uploadType.compareTo(ConstantsExplorer.ARCHIVE)==0)
@ -45,58 +49,83 @@ public class FileUploader {
caption+= " in: "+folderParent.getName();
this.dlg = new UploadProgressDialog(caption, eventBus, true);
dlg = new UploadProgressDialog(caption, eventBus, true);
dlg.center();
dlg.show();
}
/**
* Submit form.
*/
public void submitForm() {
try {
dlg.submitForm();
} catch (Exception e) {
Info.display("Error", "Sorry an error occurred on the server "+e.getLocalizedMessage() + ". Please try again later");
e.printStackTrace();
}
}
/**
* Overwrite.
*/
public void overwrite(){
updateServiceUploader.setOverwrite();
}
/**
* Submit servlet form.
*
* @param absolutePathOnServer the absolute path of the file uploaded on the server
*/
public void submitServletForm(String absolutePathOnServer){
updateServiceUploader.setFileName(absolutePathOnServer);
try {
updateServiceUploader.submitForm();
} catch (Exception e) {
dlg.showRegisteringResult(false);
}
}
/**
* Gets the folder parent.
*
* @return the folder parent
*/
public FileModel getFolderParent() {
return folderParent;
}
/**
* Gets the upload type.
*
* @return the upload type
*/
public String getUploadType() {
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.parent = parent;
this.uploadType = uploadType;
}
public static String encodeUrlDelimiters(String s) {
if (s == null) {
return null;
}
s = s.replaceAll(";", "%2F");
s = s.replaceAll("/", "%2F");
s = s.replaceAll(":", "%3A");
@ -65,7 +63,6 @@ public class UpdateServiceUploader extends Window{
s = s.replaceAll("\\$", "%24");
s = s.replaceAll(",", "%2C");
s = s.replaceAll("#", "%23");
return s;
}
@ -78,11 +75,8 @@ public class UpdateServiceUploader extends Window{
String parameters = "";
String fileNameEscaped = URL.encodeQueryString(fileName);
// fileNameEscaped = encodeUrlDelimiters(fileNameEscaped);
parameters+=ConstantsExplorer.UPLOAD_FORM_ELEMENT+"="+fileNameEscaped+"&";
if(parent.getIdentifier()!=null && !parent.getIdentifier().isEmpty())
parameters+=ConstantsExplorer.ID_FOLDER+"="+parent.getIdentifier()+"&";
else
@ -95,19 +89,11 @@ public class UpdateServiceUploader extends Window{
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);
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.setHeader("Content-Type", "application/x-www-form-urlencoded");
// requestBuilder.setRequestData(parameters);
try {
@ -133,46 +119,35 @@ public class UpdateServiceUploader extends Window{
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
switch (resultMessage.getStatus()) {
case ERROR:
// new MessageBoxAlert("Error during upload", resultMessage.getMessage(), null);
GWT.log("Error during upload: "+resultMessage.getMessage());
// fileUploaderDlg.getDlg().showRegisteringResult(false);
fileUploaderDlg.getDlg().showRegisteringResult(false, resultMessage.getMessage());
break;
case UNKNOWN:
// new MessageBoxAlert("Error during upload", resultMessage.getMessage(), null);
GWT.log("Error during upload: "+resultMessage.getMessage());
// fileUploaderDlg.getDlg().showRegisteringResult(false);
fileUploaderDlg.getDlg().showRegisteringResult(false, "Error during upload: "+resultMessage.getMessage());
break;
case WARN: {
// new MessageBoxAlert("Upload completed with warnings", resultMessage.getMessage(), null);
GWT.log("Upload completed with warnings: "+resultMessage.getMessage());
// fileUploaderDlg.getDlg().showRegisteringResult(false);
fileUploaderDlg.getDlg().showRegisteringResult(false, "Upload completed with warnings: "+resultMessage.getMessage());
break;
}
case OK: {
Timer t = new Timer() {
public void run() {
AppControllerExplorer.getEventBus().fireEvent(new CompletedFileUploadEvent(parent, null));
fileUploaderDlg.getDlg().showRegisteringResult(true);
// new InfoDisplayMessage("Upload completed successfully", resultMessage.getMessage());
}
};
case ERROR:
GWT.log("Error during upload: "+resultMessage.getMessage());
fileUploaderDlg.showRegisteringResult(false, resultMessage.getMessage());
break;
case UNKNOWN:
GWT.log("Error during upload: "+resultMessage.getMessage());
fileUploaderDlg.showRegisteringResult(false, "Error during upload: "+resultMessage.getMessage());
break;
case WARN: {
GWT.log("Upload completed with warnings: "+resultMessage.getMessage());
fileUploaderDlg.showRegisteringResult(false, "Upload completed with warnings: "+resultMessage.getMessage());
break;
}
case OK: {
Timer t = new Timer() {
public void run() {
AppControllerExplorer.getEventBus().fireEvent(new CompletedFileUploadEvent(parent, null));
fileUploaderDlg.showRegisteringResult(true);
}
};
t.schedule(250);
}
t.schedule(250);
}
}
}
@Override
public void onError(Request request, Throwable exception) {
// MessageUtil.showErrorMessage("Error during upload", "An error occurred during file upload.");
fileUploaderDlg.getDlg().showRegisteringResult(false);
// new MessageBoxAlert("Error during upload", "An error occurred during file upload.", null);
fileUploaderDlg.showRegisteringResult(false);
return;
}
});