diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java index 422e919..fb37af4 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java @@ -42,6 +42,8 @@ import org.gcube.portlets.user.workspace.client.event.FilterScopeEvent; import org.gcube.portlets.user.workspace.client.event.FilterScopeEventHandler; import org.gcube.portlets.user.workspace.client.event.GetInfoEvent; import org.gcube.portlets.user.workspace.client.event.GetInfoEventHandler; +import org.gcube.portlets.user.workspace.client.event.GetPublicLinkEvent; +import org.gcube.portlets.user.workspace.client.event.GetPublicLinkEventHandler; import org.gcube.portlets.user.workspace.client.event.GetShareLinkEvent; import org.gcube.portlets.user.workspace.client.event.GetSharedLinkEventHandler; import org.gcube.portlets.user.workspace.client.event.ImagePreviewEvent; @@ -106,6 +108,7 @@ import org.gcube.portlets.user.workspace.client.view.windows.DialogAddFolderAndS import org.gcube.portlets.user.workspace.client.view.windows.DialogAddFolderAndSmart.AddType; import org.gcube.portlets.user.workspace.client.view.windows.DialogAddUrl; import org.gcube.portlets.user.workspace.client.view.windows.DialogGetInfo; +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.DialogText; import org.gcube.portlets.user.workspace.client.view.windows.DialogUpload; @@ -441,7 +444,20 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt } } }); - + + + eventBus.addHandler(GetPublicLinkEvent.TYPE, new GetPublicLinkEventHandler() { + + @Override + public void onGetPublicLink(GetPublicLinkEvent getPublicLinkEvent) { + // TODO Auto-generated method stub + if(getPublicLinkEvent.getSourceFile()!=null){ + DialogPublicLink dialog = new DialogPublicLink("Copy to clipboard Public Link: Ctrl+C", getPublicLinkEvent.getSourceFile().getIdentifier()); + dialog.show(); + } + } + }); + eventBus.addHandler(RefreshFolderEvent.TYPE, new RefreshItemEventHandler() { diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java index b6cc612..ef1ca67 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java @@ -61,6 +61,7 @@ public class ConstantsExplorer { public static final String PASTEITEM = "Paste"; public static final String MESSAGE_REFRESH_FOLDER = "Refresh Folder"; public static final String MESSAGE_GET_INFO = "Get Info"; + public static final String MESSAGE_PUBLIC_LINK = "Get Public Link"; public static final String LISTATTACHMENTSNAMES = "Attachments Names"; public static final String LISTCONTACTSTOSTRING = "ListContactToString"; public static final String STATUS = "Status"; @@ -205,4 +206,5 @@ public class ConstantsExplorer { public static final String UPLOAD_TYPE = "uploadType"; public static final String ID_FOLDER = "idFolder"; public static final String UPLOAD_FORM_ELEMENT = "uploadFormElement"; + } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/constant/WorkspaceOperation.java b/src/main/java/org/gcube/portlets/user/workspace/client/constant/WorkspaceOperation.java index c81949c..909a92b 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/constant/WorkspaceOperation.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/constant/WorkspaceOperation.java @@ -32,7 +32,8 @@ public enum WorkspaceOperation { GET_INFO("GTI", "GTI"), // GET INFO HISTORY("HST", "HST"), //HISTORY ACCREAD("ACR", "ACR"), //ACCOUNTING READ - SHARE_LINK("SLK", "SLK"); //SHARE URL LINK + SHARE_LINK("SLK", "SLK"), //SHARE URL LINK + PUBLIC_LINK("PLK", "PLK"); //PUBLIC LINK // //ID CONTEXT MENU diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/resources/Icons.java b/src/main/java/org/gcube/portlets/user/workspace/client/resources/Icons.java index 150b2ca..bfbe687 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/resources/Icons.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/resources/Icons.java @@ -280,5 +280,8 @@ public interface Icons extends ClientBundle { @Source("icons/sharelink.png") ImageResource shareLink(); + + @Source("icons/public-link.png") + ImageResource publicLink(); } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/resources/Resources.java b/src/main/java/org/gcube/portlets/user/workspace/client/resources/Resources.java index c8fa1a6..6937632 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/resources/Resources.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/resources/Resources.java @@ -410,6 +410,10 @@ public class Resources { return AbstractImagePrototype.create(ICONS.replyMail()); } + public static AbstractImagePrototype getIconPublicLink() { + return AbstractImagePrototype.create(ICONS.publicLink()); + } + public static AbstractImagePrototype getIconReplyAllMail() { return AbstractImagePrototype.create(ICONS.replyAllMail()); } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/resources/icons/public-link.png b/src/main/java/org/gcube/portlets/user/workspace/client/resources/icons/public-link.png new file mode 100644 index 0000000..400c68d Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/workspace/client/resources/icons/public-link.png differ diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/ContextMenuTree.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/ContextMenuTree.java index 23e7e15..e8f9fb9 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/ContextMenuTree.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/ContextMenuTree.java @@ -17,6 +17,7 @@ import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent.Download import org.gcube.portlets.user.workspace.client.event.FileUploadEvent; import org.gcube.portlets.user.workspace.client.event.FileUploadEvent.UploadType; import org.gcube.portlets.user.workspace.client.event.GetInfoEvent; +import org.gcube.portlets.user.workspace.client.event.GetPublicLinkEvent; import org.gcube.portlets.user.workspace.client.event.GetShareLinkEvent; import org.gcube.portlets.user.workspace.client.event.ImagePreviewEvent; import org.gcube.portlets.user.workspace.client.event.OpenReportsEvent; @@ -184,6 +185,24 @@ public class ContextMenuTree { }); contextMenu.add(mnGetLink); + contextMenu.add(new SeparatorMenuItem()); + + //PUBLIC LINK + MenuItem mnPublicLink = new MenuItem(); + mnPublicLink.setId(WorkspaceOperation.PUBLIC_LINK.getId()); + mnPublicLink.setText(ConstantsExplorer.MESSAGE_PUBLIC_LINK); + mnPublicLink.setIcon(Resources.getIconPublicLink()); + + mnPublicLink.addSelectionListener(new SelectionListener() { + public void componentSelected(MenuEvent ce) { + + for (FileModel sel : listSelectedItems) { + eventBus.fireEvent(new GetPublicLinkEvent(sel)); + } + } + }); + + contextMenu.add(mnPublicLink); contextMenu.add(new SeparatorMenuItem()); @@ -655,7 +674,7 @@ public class ContextMenuTree { contextMenu.getItemByItemId(WorkspaceOperation.OPEN_REPORT_TEMPLATE.getId()).setVisible(false); //open report template contextMenu.getItemByItemId(WorkspaceOperation.PASTE.getId()).setEnabled(false); //paste contextMenu.getItemByItemId(WorkspaceOperation.REFRESH_FOLDER.getId()).setVisible(false); //refresh - + contextMenu.getItemByItemId(WorkspaceOperation.PUBLIC_LINK.getId()).setVisible(false); //public link contextMenu.getItemByItemId(WorkspaceOperation.SHARE.getId()).setVisible(false); //SHARE contextMenu.getItemByItemId(WorkspaceOperation.UNSHARE.getId()).setVisible(false); //UNSHARE @@ -710,10 +729,13 @@ public class ContextMenuTree { case EXTERNAL_IMAGE: contextMenu.getItemByItemId(WorkspaceOperation.PREVIEW.getId()).setVisible(true); + contextMenu.getItemByItemId(WorkspaceOperation.PUBLIC_LINK.getId()).setVisible(true); //public link break; case EXTERNAL_FILE: + contextMenu.getItemByItemId(WorkspaceOperation.PUBLIC_LINK.getId()).setVisible(true); //public link break; case EXTERNAL_PDF_FILE: + contextMenu.getItemByItemId(WorkspaceOperation.PUBLIC_LINK.getId()).setVisible(true); //public link break; case EXTERNAL_URL: contextMenu.getItemByItemId(WorkspaceOperation.LINK.getId()).setVisible(true); diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogPublicLink.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogPublicLink.java new file mode 100644 index 0000000..3059f3e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogPublicLink.java @@ -0,0 +1,107 @@ +package org.gcube.portlets.user.workspace.client.view.windows; + +import org.gcube.portlets.user.workspace.client.AppControllerExplorer; +import org.gcube.portlets.user.workspace.client.resources.Resources; + +import com.extjs.gxt.ui.client.Style.HorizontalAlignment; +import com.extjs.gxt.ui.client.Style.VerticalAlignment; +import com.extjs.gxt.ui.client.event.ButtonEvent; +import com.extjs.gxt.ui.client.event.SelectionListener; +import com.extjs.gxt.ui.client.widget.Dialog; +import com.extjs.gxt.ui.client.widget.VerticalPanel; +import com.extjs.gxt.ui.client.widget.form.TextArea; +import com.extjs.gxt.ui.client.widget.form.TextField; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.user.client.rpc.AsyncCallback; + +/** + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * + */ +public class DialogPublicLink extends Dialog { + + private TextField txt; + private int widht = 450; + private int height = 150; + private VerticalPanel vp = new VerticalPanel(); +// private Label label = new Label(); + + public DialogPublicLink(String headingTxt, final String itemId) { + setButtonAlign(HorizontalAlignment.CENTER); + setIcon(Resources.getIconShareLink()); + vp.setHorizontalAlign(HorizontalAlignment.CENTER); + vp.setVerticalAlign(VerticalAlignment.MIDDLE); + vp.getElement().getStyle().setPadding(1, Unit.PX); + setHeading(headingTxt); + setModal(true); + setBodyStyle("padding: 3px; background: none"); + setWidth(widht); + setHeight(height); + setResizable(false); + setButtons(Dialog.CLOSE); + +// label.setText(msgTitle); +// label.setStyleName("myWebDavStyle"); + + txt = new TextArea(); +// txt.setStyleAttribute("padding-top", "3px"); + txt.setWidth(widht-20); + txt.setHeight(height-74); +// txt.setFieldLabel(msgTitle); + + txt.setReadOnly(true); + + + txt.mask("Shorting link..."); + + if(itemId!=null && !itemId.isEmpty()){ + AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFolderItemId(itemId, true, new AsyncCallback() { + + @Override + public void onSuccess(String url) { + txt.unmask(); + txt.setValue(url); + selectTxt(); + + } + + @Override + public void onFailure(Throwable caught) { + txt.unmask(); + new MessageBoxAlert("Error", caught.getMessage(), null); + } + }); + + }else{ + txt.unmask(); + new MessageBoxAlert("Error", "The item identifier is null", null); + } + + this.getButtonById(Dialog.CLOSE).addSelectionListener(new SelectionListener() { + + @Override + public void componentSelected(ButtonEvent ce) { + hide(); + } + + }); + + +// vp.add(label); + vp.add(txt); + + setFocusWidget(txt); + add(vp); + } + + public String getTxtValue() { + + return txt.getValue(); + } + + public void selectTxt(){ + + if(txt.getValue()!=null) + txt.select(0, txt.getValue().length()); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index 0845fdc..71b6647 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -52,6 +52,7 @@ import org.gcube.portlets.user.workspace.server.notifications.NotificationsProdu import org.gcube.portlets.user.workspace.server.notifications.NotificationsUtil; import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameter; import org.gcube.portlets.user.workspace.server.shortener.UrlShortener; +import org.gcube.portlets.user.workspace.server.util.StringUtil; import org.gcube.portlets.user.workspace.server.util.UserUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter; @@ -2253,7 +2254,12 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT String uriRequest = ""; if(uriResolver!=null && uriResolver.isAvailable()){ - uriRequest = uriResolver.resolveAsUriRequest(smpUri, folderItem.getName(), folderItem.getMimeType(), true); + + String itemName = StringUtil.removeSpecialCharacters(folderItem.getName()); + + itemName = StringUtil.replaceAllWhiteSpace(itemName, "_"); + uriRequest = uriResolver.resolveAsUriRequest(smpUri, itemName, folderItem.getMimeType(), true); + if(shortenUrl) return getShortUrl(uriRequest); diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/StringUtil.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/StringUtil.java new file mode 100644 index 0000000..d829197 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/StringUtil.java @@ -0,0 +1,41 @@ +/** + * + */ +package org.gcube.portlets.user.workspace.server.util; + +/** + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * @Jul 9, 2013 + * + */ +public class StringUtil { + + public static String regx = ",@+^'?!\"%&$£/#()"; + + + public static String removeSpecialCharacters(String input) { + + char[] ca = regx.toCharArray(); + for (char c : ca) { + input = input.replace(""+c, ""); + } + return input; + } + + public static void main(String[] args) { + String input = "Just to clarify, Iì13ì? will have strings of varying " + + "lengths. I want to strip characters from it, the exact " + + "ones to be determined at !\"%&$£/ runtime, and return the " + + "resulting string..."; + + input = removeSpecialCharacters(input); + System.out.println(input); + System.out.println(replaceAllWhiteSpace(input, "_")); + + } + + public static String replaceAllWhiteSpace(String input, String replacement){ + return input.replaceAll("\\s",replacement); + } + +}