diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/ImageServlet.java b/src/main/java/org/gcube/portlets/user/workspace/server/ImageServlet.java index 04ea18b..0b2c246 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/ImageServlet.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/ImageServlet.java @@ -30,11 +30,12 @@ import org.gcube.portlets.user.workspace.shared.SessionExpiredException; import org.gcube.vomanagement.usermanagement.model.GCubeUser; + /** * The Class ImageServlet. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Nov 30, 2016 + * Jun 6, 2017 */ public class ImageServlet extends HttpServlet{ @@ -62,16 +63,12 @@ public class ImageServlet extends HttpServlet{ String imageId = req.getParameter("id"); String imageType = req.getParameter("type"); String contextID = req.getParameter(ConstantsExplorer.CURRENT_CONTEXT_ID); + boolean viewContent = req.getParameter("viewContent")==null?false:req.getParameter("viewContent").equals("true"); //String currUserId = req.getParameter(ConstantsExplorer.CURRENT_USER_ID); logger.info("request image id: "+imageId+", type: "+imageType +", "+ConstantsExplorer.CURRENT_CONTEXT_ID+ ": "+contextID); - ImageRequestType requestType = null; - - if (imageType == null){ - logger.warn("No request type specified, return the complete image"); - requestType = ImageRequestType.IMAGE; - } else requestType = ImageRequestType.valueOf(imageType); + ImageRequestType requestType = getRequestType(imageType); Workspace wa = null; try { @@ -122,14 +119,19 @@ public class ImageServlet extends HttpServlet{ return; } - - Image image = (Image)folderItem; - + Image image = (Image) folderItem; // Get the MIME type of the image String mimeType = image.getMimeType(); - // Set content type resp.setContentType(mimeType); + String contentDisposition = viewContent?"inline":"attachment"; + + try { + resp.setHeader( "Content-Disposition", contentDisposition+"; filename=\"" + image.getName() + "\"" ); + } + catch (InternalErrorException e1) { + logger.warn("Image name not found skipping set header response"); + } // Set content size try { @@ -160,4 +162,26 @@ public class ImageServlet extends HttpServlet{ } } + + + /** + * Gets the request type. + * + * @param imageType the image type + * @return the request type + */ + private ImageRequestType getRequestType(String imageType){ + + if (imageType == null){ + logger.warn("No request type specified, return the complete image"); + return ImageRequestType.IMAGE; + } else + try{ + return ImageRequestType.valueOf(imageType); + }catch (Exception e) { + return ImageRequestType.IMAGE; + } + + } + }