URL parameters chars encoding fixed

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@90496 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2014-01-24 15:01:15 +00:00
parent c97cc55b6c
commit 7c7ce1cb49
14 changed files with 334 additions and 95 deletions

View File

@ -102,6 +102,8 @@ import org.gcube.portlets.user.workspace.client.model.SmartFolderModel;
import org.gcube.portlets.user.workspace.client.model.SubTree; import org.gcube.portlets.user.workspace.client.model.SubTree;
import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService; import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService;
import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceServiceAsync; import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceServiceAsync;
import org.gcube.portlets.user.workspace.client.uploader.FileUploader;
import org.gcube.portlets.user.workspace.client.uploader.UpdateServiceUploader;
import org.gcube.portlets.user.workspace.client.util.RequestBuilderWorkspaceValidateItem; import org.gcube.portlets.user.workspace.client.util.RequestBuilderWorkspaceValidateItem;
import org.gcube.portlets.user.workspace.client.util.WindowOpenParameter; import org.gcube.portlets.user.workspace.client.util.WindowOpenParameter;
import org.gcube.portlets.user.workspace.client.view.BasicDNDExample; import org.gcube.portlets.user.workspace.client.view.BasicDNDExample;
@ -117,12 +119,10 @@ import org.gcube.portlets.user.workspace.client.view.windows.DialogPublicLink;
import org.gcube.portlets.user.workspace.client.view.windows.DialogShareLink; import org.gcube.portlets.user.workspace.client.view.windows.DialogShareLink;
import org.gcube.portlets.user.workspace.client.view.windows.DialogText; import org.gcube.portlets.user.workspace.client.view.windows.DialogText;
import org.gcube.portlets.user.workspace.client.view.windows.DialogWebDavUrl; import org.gcube.portlets.user.workspace.client.view.windows.DialogWebDavUrl;
import org.gcube.portlets.user.workspace.client.view.windows.FileUploader;
import org.gcube.portlets.user.workspace.client.view.windows.InfoDisplay; import org.gcube.portlets.user.workspace.client.view.windows.InfoDisplay;
import org.gcube.portlets.user.workspace.client.view.windows.InfoDisplayMessage; import org.gcube.portlets.user.workspace.client.view.windows.InfoDisplayMessage;
import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxAlert; import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxAlert;
import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxConfirm; import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxConfirm;
import org.gcube.portlets.user.workspace.client.view.windows.UpdateServiceUploader;
import org.gcube.portlets.user.workspace.client.view.windows.WindowImagePreview; import org.gcube.portlets.user.workspace.client.view.windows.WindowImagePreview;
import org.gcube.portlets.user.workspace.client.view.windows.WindowOpenUrl; import org.gcube.portlets.user.workspace.client.view.windows.WindowOpenUrl;
import org.gcube.portlets.user.workspace.client.view.windows.accounting.WindowAccountingInfo; import org.gcube.portlets.user.workspace.client.view.windows.accounting.WindowAccountingInfo;
@ -583,45 +583,96 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
eventBus.addHandler(PasteItemEvent.TYPE, new PasteItemEventHandler() { eventBus.addHandler(PasteItemEvent.TYPE, new PasteItemEventHandler() {
@Override @Override
public void onCopyAndPaste(PasteItemEvent pasteItemEvent) { public void onCutCopyAndPaste(PasteItemEvent pasteItemEvent) {
GWT.log("PasteItemEvent is fired on : "+pasteItemEvent.getIds().size()+ "items, DestinationId: "+pasteItemEvent.getFolderDestinationId()); GWT.log("PasteItemEvent is fired on : "+pasteItemEvent.getIds().size()+ "items, DestinationId: "+pasteItemEvent.getFolderDestinationId());
doCopyAndPaste(pasteItemEvent); doCutCopyAndPaste(pasteItemEvent);
} }
private void doCopyAndPaste(final PasteItemEvent pasteItemEvent) { private void doCutCopyAndPaste(final PasteItemEvent pasteItemEvent) {
Info.display("Info", "Paste working..."); if(pasteItemEvent.getIds()==null)
return;
rpcWorkspaceService.copyItems(pasteItemEvent.getIds(), pasteItemEvent.getFolderDestinationId(), new AsyncCallback<Boolean>() { Info.display("Info", "Paste working...");
@Override switch(pasteItemEvent.getOperationType()){
public void onFailure(Throwable caught) {
case CUT:
//TODO remove this comments
// if(pasteItemEvent.getFolderSourceId()==null || pasteItemEvent.getFolderSourceId().isEmpty())
// return;
rpcWorkspaceService.moveItems(pasteItemEvent.getIds(), pasteItemEvent.getFolderDestinationId(), new AsyncCallback<Boolean>() {
if(caught instanceof SessionExpiredException){ public void onFailure(Throwable caught) {
GWT.log("Session expired");
eventBus.fireEvent(new SessionExpiredEvent()); if(caught instanceof SessionExpiredException){
return; GWT.log("Session expired");
eventBus.fireEvent(new SessionExpiredEvent());
return;
}
new MessageBoxAlert("Error", caught.getMessage()+"." , null);
System.out.println(caught.getMessage());
explorerPanel.getAsycTreePanel().reloadTreeLevelAndExpandFolder(pasteItemEvent.getFolderDestinationId(), false);
explorerPanel.getAsycTreePanel().reloadTreeLevelAndExpandFolder(pasteItemEvent.getFolderSourceId(), true);
} }
new MessageBoxAlert("Error", caught.getMessage(), null); @Override
public void onSuccess(Boolean result) {
eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, true, false));
if(result){
notifySubscriber(pasteItemEvent);
}
@Override eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, false, false));
public void onSuccess(Boolean result) { // explorerPanel.getAsycTreePanel().setExpandTreeLevel(event.getTargetParentFileModel(), true); //Expand level drop
}
notifySubscriber(pasteItemEvent);
}
});
break;
case COPY:
rpcWorkspaceService.copyItems(pasteItemEvent.getIds(), pasteItemEvent.getFolderDestinationId(), new AsyncCallback<Boolean>() {
if(result) @Override
eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, false, false)); public void onFailure(Throwable caught) {
notifySubscriber(pasteItemEvent); if(caught instanceof SessionExpiredException){
} GWT.log("Session expired");
eventBus.fireEvent(new SessionExpiredEvent());
return;
}
new MessageBoxAlert("Error", caught.getMessage(), null);
eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, true, false));
notifySubscriber(pasteItemEvent);
}
@Override
public void onSuccess(Boolean result) {
if(result)
eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, false, false));
notifySubscriber(pasteItemEvent);
}
});
break;
default:
}
});
} }
}); });

View File

@ -4,6 +4,7 @@ import java.util.List;
import org.gcube.portlets.user.workspace.client.interfaces.EventsTypeEnum; import org.gcube.portlets.user.workspace.client.interfaces.EventsTypeEnum;
import org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface; import org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface;
import org.gcube.portlets.user.workspace.client.view.tree.CutCopyAndPaste.OperationType;
import com.google.gwt.event.shared.GwtEvent; import com.google.gwt.event.shared.GwtEvent;
@ -14,15 +15,21 @@ public class PasteItemEvent extends GwtEvent<PasteItemEventHandler> implements G
private String folderDestinationId; private String folderDestinationId;
private List<String> ids; private List<String> ids;
private OperationType operationType;
private String folderSourceId; //Used to move
// public PasteItemEvent(String itemId, String folderDestinationId) { // public PasteItemEvent(String itemId, String folderDestinationId) {
// this.itemId = itemId; // this.itemId = itemId;
// this.folderDestinationId = folderDestinationId; // this.folderDestinationId = folderDestinationId;
// } // }
public PasteItemEvent(List<String> ids, String folderDestinationId) { public PasteItemEvent(List<String> ids, String folderDestinationId, OperationType operation) {
this.ids = ids; this.ids = ids;
this.folderDestinationId = folderDestinationId; this.folderDestinationId = folderDestinationId;
this.operationType = operation;
} }
@Override @Override
@ -32,7 +39,7 @@ public class PasteItemEvent extends GwtEvent<PasteItemEventHandler> implements G
@Override @Override
protected void dispatch(PasteItemEventHandler handler) { protected void dispatch(PasteItemEventHandler handler) {
handler.onCopyAndPaste(this); handler.onCutCopyAndPaste(this);
} }
@ -60,4 +67,16 @@ public class PasteItemEvent extends GwtEvent<PasteItemEventHandler> implements G
this.ids = ids; this.ids = ids;
} }
public OperationType getOperationType() {
return operationType;
}
public String getFolderSourceId() {
return folderSourceId;
}
public void setFolderSourceId(String folderSourceId) {
this.folderSourceId = folderSourceId;
}
} }

View File

@ -3,5 +3,5 @@ package org.gcube.portlets.user.workspace.client.event;
import com.google.gwt.event.shared.EventHandler; import com.google.gwt.event.shared.EventHandler;
public interface PasteItemEventHandler extends EventHandler { public interface PasteItemEventHandler extends EventHandler {
void onCopyAndPaste(PasteItemEvent pasteItemEvent); void onCutCopyAndPaste(PasteItemEvent pasteItemEvent);
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 618 B

View File

@ -184,4 +184,12 @@ public interface GWTWorkspaceService extends RemoteService{
boolean copyItems(List<String> idsItem, String destinationFolderId) boolean copyItems(List<String> idsItem, String destinationFolderId)
throws Exception; throws Exception;
/**
* @param ids
* @param destinationId
* @return
* @throws Exception
*/
Boolean moveItems(List<String> ids, String destinationId) throws Exception;
} }

View File

@ -167,4 +167,7 @@ public interface GWTWorkspaceServiceAsync {
void copyItems(List<String> idsItem, String destinationFolderId, void copyItems(List<String> idsItem, String destinationFolderId,
AsyncCallback<Boolean> callback); AsyncCallback<Boolean> callback);
void moveItems(List<String> ids, String destinationId,
AsyncCallback<Boolean> callback);
} }

View File

@ -1,7 +1,7 @@
/** /**
* *
*/ */
package org.gcube.portlets.user.workspace.client.view.windows; package org.gcube.portlets.user.workspace.client.uploader;
import org.gcube.portlets.user.workspace.client.model.FileModel; import org.gcube.portlets.user.workspace.client.model.FileModel;
import org.gcube.portlets.widgets.fileupload.client.view.UploadProgressDialog; import org.gcube.portlets.widgets.fileupload.client.view.UploadProgressDialog;

View File

@ -1,4 +1,4 @@
package org.gcube.portlets.user.workspace.client.view.windows; package org.gcube.portlets.user.workspace.client.uploader;
import org.gcube.portlets.user.workspace.client.AppControllerExplorer; import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
@ -14,6 +14,7 @@ import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback; import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException; import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response; import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTML;
@ -49,6 +50,25 @@ public class UpdateServiceUploader extends Window{
} }
public static String encodeUrlDelimiters(String s) {
if (s == null) {
return null;
}
s = s.replaceAll(";", "%2F");
s = s.replaceAll("/", "%2F");
s = s.replaceAll(":", "%3A");
s = s.replaceAll("\\?", "%3F");
s = s.replaceAll("&", "%26");
s = s.replaceAll("\\=", "%3D");
s = s.replaceAll("\\+", "%2B");
s = s.replaceAll("\\$", "%24");
s = s.replaceAll(",", "%2C");
s = s.replaceAll("#", "%23");
return s;
}
public void submitForm() throws Exception{ public void submitForm() throws Exception{
@ -57,7 +77,7 @@ public class UpdateServiceUploader extends Window{
String parameters = ""; String parameters = "";
parameters+=ConstantsExplorer.UPLOAD_FORM_ELEMENT+"="+fileName+"&"; /* parameters+=ConstantsExplorer.UPLOAD_FORM_ELEMENT+"="+fileName+"&";
if(parent.getIdentifier()!=null && !parent.getIdentifier().isEmpty()) if(parent.getIdentifier()!=null && !parent.getIdentifier().isEmpty())
@ -72,18 +92,47 @@ public class UpdateServiceUploader extends Window{
parameters+=ConstantsExplorer.IS_OVERWRITE+"="+overwrite; parameters+=ConstantsExplorer.IS_OVERWRITE+"="+overwrite;
// String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+URL.encodeQueryString(parameters); String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+URL.encodeQueryString(parameters);
String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+parameters; String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+parameters;
*/
GWT.log("Encoded url request is: "+urlRequest); String fileNameEscaped = URL.encodeQueryString(fileName);
// fileNameEscaped = encodeUrlDelimiters(fileNameEscaped);
parameters+=ConstantsExplorer.UPLOAD_FORM_ELEMENT+"="+fileNameEscaped+"&";
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, urlRequest); if(parent.getIdentifier()!=null && !parent.getIdentifier().isEmpty())
// requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded"); parameters+=ConstantsExplorer.ID_FOLDER+"="+parent.getIdentifier()+"&";
else
throw new Exception("Parent Folder ID parameter is null or empty");
if(uploadType!=null && !uploadType.isEmpty())
parameters+=ConstantsExplorer.UPLOAD_TYPE+"="+uploadType+"&";
else
throw new Exception("UploadType parameter is null or empty");
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;
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE);
requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded");
// requestBuilder.setRequestData(parameters);
try { try {
requestBuilder.sendRequest("", new RequestCallback() { requestBuilder.sendRequest(parameters, new RequestCallback() {
@Override @Override
public void onResponseReceived(Request request, Response response) { public void onResponseReceived(Request request, Response response) {
@ -147,7 +196,7 @@ public class UpdateServiceUploader extends Window{
}); });
} catch (RequestException e) { } catch (RequestException e) {
e.printStackTrace();
} }
} }

View File

@ -32,6 +32,7 @@ import org.gcube.portlets.user.workspace.client.event.WebDavUrlEvent;
import org.gcube.portlets.user.workspace.client.model.FileModel; import org.gcube.portlets.user.workspace.client.model.FileModel;
import org.gcube.portlets.user.workspace.client.resources.Resources; import org.gcube.portlets.user.workspace.client.resources.Resources;
import org.gcube.portlets.user.workspace.client.util.FileModelUtils; import org.gcube.portlets.user.workspace.client.util.FileModelUtils;
import org.gcube.portlets.user.workspace.client.view.tree.CutCopyAndPaste.OperationType;
import com.extjs.gxt.ui.client.event.MenuEvent; import com.extjs.gxt.ui.client.event.MenuEvent;
import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.event.SelectionListener;
@ -332,7 +333,7 @@ public class ContextMenuTree {
List<String> ids = FileModelUtils.convertFileModelsToIds(listSelectedItems); List<String> ids = FileModelUtils.convertFileModelsToIds(listSelectedItems);
if(ids.size()>0){ if(ids.size()>0){
CopyAndPaste.copy(ids); CutCopyAndPaste.copy(ids, OperationType.COPY);
eventBus.fireEvent(new CopytemEvent(ids)); eventBus.fireEvent(new CopytemEvent(ids));
} }
@ -353,9 +354,9 @@ public class ContextMenuTree {
FileModel parentTarget = getDirectoryOrParent(target); FileModel parentTarget = getDirectoryOrParent(target);
if(parentTarget!=null){ if(parentTarget!=null){
eventBus.fireEvent(new PasteItemEvent(CopyAndPaste.getCopiedIdsFilesModel(), parentTarget.getIdentifier())); eventBus.fireEvent(new PasteItemEvent(CutCopyAndPaste.getCopiedIdsFilesModel(), parentTarget.getIdentifier(), CutCopyAndPaste.getOperationType()));
CopyAndPaste.setCopiedIdsFileModels(null); CutCopyAndPaste.setCopiedIdsFileModels(null);
CutCopyAndPaste.setOperationType(null);
} }
} }
@ -792,7 +793,7 @@ public class ContextMenuTree {
} }
if(CopyAndPaste.getCopiedIdsFilesModel()!=null) if(CutCopyAndPaste.getCopiedIdsFilesModel()!=null)
contextMenu.getItemByItemId(WorkspaceOperation.PASTE.getId()).setEnabled(true); //enable paste button contextMenu.getItemByItemId(WorkspaceOperation.PASTE.getId()).setEnabled(true); //enable paste button
} }

View File

@ -1,38 +0,0 @@
package org.gcube.portlets.user.workspace.client.view.tree;
import java.util.List;
public class CopyAndPaste {
// private static String copiedfileModelId = null;
private static List<String> idsFilesModel = null;
// public static void copy(String fileModelId){
// copiedfileModelId = fileModelId;
// }
public static void copy(List<String> idsFileModel){
idsFilesModel = idsFileModel;
}
public static List<String> getCopiedIdsFilesModel() {
return idsFilesModel;
}
// public static void setCopiedfileModelId(String copiedfileModelId) {
// CopyAndPaste.copiedfileModelId = copiedfileModelId;
// }
// public static String getCopiedfileModelId() {
// return copiedfileModelId;
// }
public static void setCopiedIdsFileModels(List<String> idsFileModel) {
CopyAndPaste.idsFilesModel = idsFileModel;
}
}

View File

@ -0,0 +1,35 @@
package org.gcube.portlets.user.workspace.client.view.tree;
import java.util.List;
public class CutCopyAndPaste {
private static List<String> idsFilesModel = null;
public enum OperationType {CUT, COPY};
private static OperationType operationType;
public static void copy(List<String> idsFileModel, OperationType operationType){
CutCopyAndPaste.idsFilesModel = idsFileModel;
CutCopyAndPaste.operationType = operationType;
}
public static List<String> getCopiedIdsFilesModel() {
return idsFilesModel;
}
public static void setCopiedIdsFileModels(List<String> idsFileModel) {
CutCopyAndPaste.idsFilesModel = idsFileModel;
}
public static OperationType getOperationType() {
return operationType;
}
public static void setOperationType(OperationType operationType) {
CutCopyAndPaste.operationType = operationType;
}
}

View File

@ -484,6 +484,81 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} }
@Override
public Boolean moveItems(List<String> ids, String destinationId) throws Exception {
workspaceLogger.trace("moveItems "+ids.size()+ ", destination: "+destinationId);
if(isSessionExpired())
throw new SessionExpiredException();
boolean error = false;
try {
Workspace workspace = getWorkspace();
for (String itemId : ids) {
if(itemId == null)
throw new Exception(IDENTIFIER_IS_NULL);
workspaceLogger.trace("moveItem item: "+itemId+" destination: "+destinationId);
WorkspaceItem sourceItem = workspace.getItem(itemId); //GET SOURCE ITEM BEFORE OF MOVE
if(sourceItem==null){
error = true;
break;
}
String sourceSharedId = null;
boolean sourceItemIsShared = sourceItem.isShared();
if(sourceItemIsShared)
sourceSharedId = sourceItem.getIdSharedFolder(); //GET SHARED ID BEFORE OF MOVE
//System.out.println("moveItem item: "+itemId+" sourceItem name "+sourceItem.getName() + " shared: "+sourceItemIsShared+ " destination: "+destinationId);
workspace.moveItem(itemId, destinationId); //move item
WorkspaceItem folderDestinationItem = workspace.getItem(destinationId); //retrieve folder destination
//System.out.println("sourceItem.isShared() "+sourceItemIsShared );
//System.out.println("folderDestinationItem item: "+destinationId+" folderDestinationItem name "+folderDestinationItem.getName() + " folderDestinationItem shared: "+folderDestinationItem.isShared());
if(folderDestinationItem!=null){
try{
checkNotifyAddItemToShare(sourceItem, sourceSharedId, folderDestinationItem);
checkNotifyMoveItemFromShare(sourceItemIsShared, sourceItem, sourceSharedId, folderDestinationItem);
}catch (Exception e) {
workspaceLogger.error("An error occurred in checkNotify ", e);
}
}
}
if(error)
return Boolean.FALSE;
return Boolean.TRUE;
}catch (InsufficientPrivilegesException e) {
workspaceLogger.error("Error in server Item move", e);
String error1 = "An error occurred on moving item. "+e.getMessage();
throw new Exception(error1);
} catch (Exception e) {
workspaceLogger.error("Error in server Item move", e);
String error2 = ConstantsExplorer.SERVER_ERROR + " moving item. "+e.getMessage();
throw new Exception(error2);
}
}
private void checkNotifyAddItemToShare(final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem) { private void checkNotifyAddItemToShare(final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem) {
workspaceLogger.trace("checkNotifyAddItemToShare"); workspaceLogger.trace("checkNotifyAddItemToShare");

View File

@ -44,6 +44,8 @@ import org.gcube.portlets.user.workspace.server.notifications.NotificationsUtil;
import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil;
import org.gcube.portlets.user.workspace.shared.HandlerResultMessage; import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
import com.google.gwt.http.client.URL;
/** /**
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
@ -93,11 +95,23 @@ public class LocalUploadServlet extends HttpServlet {
@Override @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// System.out.println("GET on LocalUploadServlet"); // System.out.println("GET on LocalUploadServlet");
logger.trace("GET on LocalUploadServlet"); logger.trace("GET method in LocalUploadServlet is running");
String absolutePathFile = URLDecoder.decode(request.getParameter(UPLOAD_FORM_ELEMENT), UTF_8); String absolutePathFile = "";
String destinationId = URLDecoder.decode(request.getParameter(ID_FOLDER), UTF_8); String destinationId = "";
String uploadType = URLDecoder.decode(request.getParameter(UPLOAD_TYPE), UTF_8); String uploadType = "";
boolean isOverwrite = Boolean.parseBoolean(URLDecoder.decode(request.getParameter(IS_OVERWRITE), UTF_8)); boolean isOverwrite = false;
try{
absolutePathFile = request.getParameter(UPLOAD_FORM_ELEMENT);
destinationId = request.getParameter(ID_FOLDER);
uploadType = request.getParameter(UPLOAD_TYPE);
isOverwrite = Boolean.parseBoolean(request.getParameter(IS_OVERWRITE));
}catch (Exception e) {
logger.error("Error processing GET parameters", e);
sendError(response, "Internal error: Error during request processing");
return;
}
uploadData(request, response, absolutePathFile, destinationId, uploadType, isOverwrite); uploadData(request, response, absolutePathFile, destinationId, uploadType, isOverwrite);
} }
@ -106,23 +120,35 @@ public class LocalUploadServlet extends HttpServlet {
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// System.out.println("POST on LocalUploadServlet"); logger.trace("POST method in LocalUploadServlet is running");
logger.trace("POST on LocalUploadServlet"); String absolutePathFile = "";
String absolutePathFile = request.getParameter(UPLOAD_FORM_ELEMENT); String destinationId = "";
String destinationId = request.getParameter(ID_FOLDER); String uploadType = "";
String uploadType = request.getParameter(UPLOAD_TYPE); boolean isOverwrite = false;
boolean isOverwrite = Boolean.parseBoolean(request.getParameter(IS_OVERWRITE)); try{
absolutePathFile = request.getParameter(UPLOAD_FORM_ELEMENT);
destinationId = request.getParameter(ID_FOLDER);
uploadType = request.getParameter(UPLOAD_TYPE);
isOverwrite = Boolean.parseBoolean(request.getParameter(IS_OVERWRITE));
}catch (Exception e) {
logger.error("Error processing POST parameters", e);
sendError(response, "Internal error: Error during request processing");
return;
}
uploadData(request, response, absolutePathFile, destinationId, uploadType, isOverwrite); uploadData(request, response, absolutePathFile, destinationId, uploadType, isOverwrite);
} }
private void uploadData(HttpServletRequest request, HttpServletResponse response, String absolutePathFile,String destinationId,String uploadType,boolean isOverwrite) throws ServletException, IOException{ private void uploadData(HttpServletRequest request, HttpServletResponse response, String absolutePathFile, String destinationId,String uploadType,boolean isOverwrite) throws ServletException, IOException{
File file = null; File file = null;
InputStream fileUploadIS = null; InputStream fileUploadIS = null;
try { try {
logger.trace("Upload servlet parameters: [uploadItem: "+absolutePathFile +", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+"]");
if(absolutePathFile==null || absolutePathFile.isEmpty()) if(absolutePathFile==null || absolutePathFile.isEmpty())
throw new FileUploadException("Absolute path is null or empty"); throw new FileUploadException("Absolute path is null or empty");
@ -133,9 +159,9 @@ public class LocalUploadServlet extends HttpServlet {
if(!file.exists()) if(!file.exists())
throw new FileUploadException("File dosn't exists"); throw new FileUploadException("File dosn't exists");
fileUploadIS = FileUtils.openInputStream(file); fileUploadIS = FileUtils.openInputStream(file);
logger.trace("Upload servlet parameters: [uploadItem: "+file.getAbsolutePath() +", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+"]");
} catch (Exception e) { } catch (Exception e) {
logger.error("Error processing request in upload servlet", e); logger.error("Error processing request in upload servlet", e);
sendError(response, "Internal error: Error during request processing"); sendError(response, "Internal error: Error during request processing");

View File

@ -1,5 +1,7 @@
package org.gcube.portlets.user.workspace.shared; package org.gcube.portlets.user.workspace.shared;
import com.google.gwt.safehtml.shared.UriUtils;
/** /**
* <p> * <p>
* FieldVerifier validates that the name the user enters is valid. * FieldVerifier validates that the name the user enters is valid.
@ -47,4 +49,12 @@ public class FieldVerifier {
} }
return true; return true;
} }
public static String uriUtilsEncode(String uri, boolean allowEscape){
if(!allowEscape)
return UriUtils.encodeAllowEscapes(uri);
return UriUtils.encode(uri);
}
} }