From 6bb6bfcc3fa905e40c199721b37418396e0c4267 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Thu, 4 Apr 2019 13:28:47 +0000 Subject: [PATCH] trying to solve [Support #16430] git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@178839 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 184 ++++++++++++------ .../workspace/server/DownloadServlet.java | 18 +- .../server/util/AllowedMimeTypeToInline.java | 86 ++++++++ .../MimeTypePrefixToInline.properties | 6 + 4 files changed, 232 insertions(+), 62 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/workspace/server/util/AllowedMimeTypeToInline.java create mode 100644 src/main/resources/MimeTypePrefixToInline.properties diff --git a/distro/changelog.xml b/distro/changelog.xml index a24776e..ad08958 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,9 +1,12 @@ - Updated to StorageHub [ticket: #13226] + [Support #16430] fixed - Updated regular expression to validate Folder and File names @@ -13,7 +16,8 @@ [Task #13106] Provide public links for versioned files - [Task #12521] Migrate the tree view @@ -39,7 +43,8 @@ [Incident #12922] Workspace get link not working - [Task #12489] Migrate delete operation to StorageHub @@ -47,65 +52,76 @@ Switchboard service discovery - [Task #12089] Migrate to workspace-uploader 2.0 [Release #12006] Removed Send to - [Project Activity #11690] Integrated with Task Executor Widget - Managed case of Exception in order to avoid failure on checkItemLocked - [Task #11127] Porting to new ws-thredds engine [Feature #11325] Workspace: add New URL feature in the context menu of right pane - Issue #10831, Workspace download folder tomcat temp occupation issue - Feature #9760: WS-Thredds synch folder integration - Incident #9676: fixed. Removed check on get sub-folder public link when operation is performed by an administrator - Added regex in order to remove list of chars when renaming or creating new item. It is different for folder and item name - [Feature #5207] Integrate Image Preview Widget - Quick fix to set folder as public Updated messages to history including version of file if it is present - Removed no longer used dependency: accesslogger [Feature #7006] File Versioning @@ -115,7 +131,8 @@ [Task #7382] Added a quick fix to 'Edit Permissions' 'Edit Permissions' can be performed by Administrators - Added a loader on share window when contacts are loading from server @@ -124,12 +141,14 @@ external servlets - Removed message box shown in case of failure on getAllContatcs - [Feature #5873] Remove ASL Session from the Workspace and its components @@ -138,7 +157,8 @@ access is granted for owner or admin - [Feature #2335] Added "Get Folder Link" facility [Incident #4878] Fixed: Workspace tree not displaying user's @@ -155,33 +175,39 @@ [Bug #5218] Fixed return to the Workspace root Folder - [Feature #4128] Migration to Liferay 6.2 Data Catalogue publishing supported - Integrated with new workspace uploader Bug fixed: Css for Dialog Cancel multiple files - Added icons for: .odt, .ods, .ott, .odg, .odp - [Feature #1925] Added, new public link format: http://host/storageID [Feature #1298] Update public link generation - Bug Fixing - #1804; #1808; #1822; #1333 - [Feature #124] Remove a user from shared folder [Feature #1259] Enhancement to workspace item history @@ -194,7 +220,8 @@ [Bug: #1459] Fixed: get link disabled - [Bug #718] Fixed breadcrumb path [Bug #546] Fixed bug @@ -205,7 +232,8 @@ after an delete multiple - [Feature #129] Porting to HL 2.0 @@ -213,12 +241,14 @@ complete link - Integrated with Contact Edit Permissions - Added user storage usage @@ -226,14 +256,16 @@ shared folder - Support Ticket #813: Broken Breadcrumb for long path Ticket #3053: Load current ACL stored to Shared Folder - #2798 Sharing Panel usability improved @@ -241,7 +273,8 @@ https://support.social.isti.cnr.it/ticket/126 - Added Trash: https://issue.imarine.research-infrastructures.eu/ticket/2497 @@ -250,7 +283,8 @@ 3.2) - Fixed: https://support.d4science.research-infrastructures.eu/ticket/843 @@ -259,12 +293,14 @@ https://issue.imarine.research-infrastructures.eu/ticket/282 - Management of My Special Folder Added change permissions to VRE shared folder - #2634 Workspace: support for setting permissions over shared folders @@ -274,18 +310,21 @@ session validation - Changed several labels into Logger - #Ticket 2223. This project was enhancements to gwt 2.5.1 GCF dependency was removed - Provide support for public link, Related ticket: #1993 @@ -294,20 +333,23 @@ Fixed bug on shared links, Ticket #630 - Provide support for share link, Related ticket: #1504 Edit description on sharing, Related ticket: #1822 Bugs fixed, Related Tickets: #628, #633, #630 - Provide support for accounting, related ticket: #1752 Enable notification for file upload in shared folder, related ticket: #1732 - Workspace portlet was enhanced to meet the requests coming from the User Community @@ -316,20 +358,23 @@ #1497, #1536 - #1247 The workspace tree was mavenized #230, #205 The Workspace environment now supports the sharing of folder between users - Old Send Message removed, added support for new mail sender Bug fixed: upload file/archive - #216 New version of Workspace Tree is developed using the GXT framework @@ -337,38 +382,45 @@ #216 New tree is asynchronous #216 Reviews tree GUI and adding new features - #1740: ICIS / Download csv / added extension .xlw - #1555: WorkflowTemplate and WorkflowReport required in Workspace Portlet - Synch with others changes in HomeLibrary GWT 2.2.0 - Removed Workspace and Basket type, replaced with folder option Synch with others changes in HomeLibrary - Added more checks on GWT model construction - Enabled details panel for Report, ReportTemplate and AquaMapsItem workspace items - #36: ICIS / Workspace / Upload an archive Merged ThumbnailServlet and ImageServlet @@ -376,13 +428,15 @@ link not working - Ported to GWT 2.0 Updated project structure to WebPortlet Update to LifeRay portal - #424: Workspace code refactoring an enanchement refactored code @@ -391,35 +445,43 @@ Report Template - gcube release 1.7.0 - gcube release 1.6.0 - gcube release 1.5.0 - gcube release - gcube release 1.2.2 - gcube release 1.2.0 - gcube release 1.2.0 rc1 - first release diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java b/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java index 4baf2ef..ff5f5e8 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.StringReader; +import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -29,6 +30,7 @@ import org.gcube.common.storagehubwrapper.shared.tohl.items.PDFFileItem; import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem; import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.server.property.PortalUrlGroupGatewayProperty; +import org.gcube.portlets.user.workspace.server.util.AllowedMimeTypeToInline; import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.shared.HandlerResultMessage; import org.gcube.portlets.user.workspace.shared.SessionExpiredException; @@ -296,10 +298,24 @@ public class DownloadServlet extends HttpServlet{ String itemName = MimeTypeUtil.getNameWithExtension(descr.getItemName(), workspaceFileItem.getMimeType()); logger.info("Downloading default item: "+workspaceFileItem); + + //String contentDisposition = viewContent?"inline":"attachment"; //Support #16430 - //The 'inline' option may be badly managed by browser, so I'm forcing the 'attachment' option + //The 'inline' option may be badly managed by browser String contentDisposition = "attachment"; + List allowedPrefixes = AllowedMimeTypeToInline.getAllowedMimeTypePrefixes(); + if(viewContent) { + logger.info("Checking if the mime type "+workspaceFileItem.getMimeType()+" exists among Mime Type Prefixes"); + for (String prefix : allowedPrefixes) { + if(workspaceFileItem.getMimeType().startsWith(prefix)) { + logger.info("yes, the prefix "+prefix+" is matching the mimetype "+workspaceFileItem.getMimeType()+", so returning 'Content-Disposition' at 'inline'"); + contentDisposition = "inline"; + break; + } + } + } + resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" ); if(workspaceFileItem.getSize()!=null && workspaceFileItem.getSize()>0) resp = setContentLength(resp, workspaceFileItem.getSize()); diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/AllowedMimeTypeToInline.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/AllowedMimeTypeToInline.java new file mode 100644 index 0000000..c0ef6cc --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/AllowedMimeTypeToInline.java @@ -0,0 +1,86 @@ +package org.gcube.portlets.user.workspace.server.util; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +import org.apache.log4j.Logger; + + +/** + * The Class AllowedMimeTypeToInline. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Apr 4, 2019 + */ +public class AllowedMimeTypeToInline { + + public static final String filename = "MimeTypePrefixToInline.properties"; + + protected static Logger logger = Logger.getLogger(WsUtil.class); + + /** + * Load mime type prefix. + * + * @return the properties + */ + private static Properties loadMimeTypePrefix(){ + + Properties prop = new Properties(); + InputStream input = null; + + try { + + input = AllowedMimeTypeToInline.class.getClassLoader().getResourceAsStream(filename); + if(input==null){ + logger.error("Sorry, unable to find " + filename); + return null; + } + //load a properties file from class path, inside static method + prop.load(input); + return prop; + + } catch (IOException ex) { + logger.error("Sorry, error: ", ex); + return null; + + } finally{ + + if(input!=null){ + try { + input.close(); + } catch (IOException e) { + //silent + } + } + } + } + + + /** + * Gets the allowed mime type prefixes. + * + * @return the allowed mime type prefixes + */ + public static List getAllowedMimeTypePrefixes(){ + Properties prop = loadMimeTypePrefix(); + List prefixes = new ArrayList(); + if(prop==null) + return prefixes; + + for (Object keyObj : prop.keySet()) { + prefixes.add((String) keyObj); + } + + return prefixes; + } +} + + + + diff --git a/src/main/resources/MimeTypePrefixToInline.properties b/src/main/resources/MimeTypePrefixToInline.properties new file mode 100644 index 0000000..e8438d0 --- /dev/null +++ b/src/main/resources/MimeTypePrefixToInline.properties @@ -0,0 +1,6 @@ +image=prefix to image file +text=prefix to text file +video=prefix to video file +application/pdf=prefix to pdf file +application/xml=prefix to xml file +application/json=prefix to json file \ No newline at end of file