() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ removePlaceHolder(txtLoadingPreview);
+
+ }
+
+ @Override
+ public void onSuccess(GWTWorkspaceItem item) {
+ GWT.log("Image loaded: " + item.getName() + " label: " + item.getLabel() + " type: "
+ + fileModel.getGXTFolderItemType());
+ if (fileModel.getGXTFolderItemType().equals(GXTFolderItemTypeEnum.IMAGE_DOCUMENT)) {
+ GWTImageDocument theItemImage = (GWTImageDocument) item;
+ htmlPanelImagePreview.add(new Image(theItemImage.getThumbnailUrl()));
+ htmlPanelImagePreview.setVisible(true);
+ }else {
+ GWTExternalImage theExternalImage = (GWTExternalImage) item;
+ htmlPanelImagePreview.add(new Image(theExternalImage.getThumbnailUrl()));
+ htmlPanelImagePreview.setVisible(true);
+ }
+ removePlaceHolder(txtLoadingPreview);
+ }
+ });
+ }
+
+ /**
+ * Sets the placeholder.
+ *
+ * @param html the html
+ * @param placeholder the placeholder
+ */
+ private void setPlaceholder(HTML html, boolean spinner, String placeholder) {
+ String loadingHMTL = placeholder;
+ if(spinner) {
+ loadingHMTL = ""+placeholder+"";
+ }
+ html.setHTML(loadingHMTL);
+ html.getElement().addClassName("placeholder-loading");
+ }
+
+ /**
+ * Removes the place holder.
+ *
+ * @param html the html
+ */
+ private void removePlaceHolder(HTML html) {
+ html.setHTML("");
+ html.getElement().removeClassName("placeholder-loading");
+ }
+
+
+ public static native String showPDFPreview(String pdfURL, String divId)/*-{
+ var theDivContainer = "#"+divId;
+ $wnd.PDFObject.embed(pdfURL, theDivContainer);
+ }-*/;
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfoBootstrap.ui.xml b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfoBootstrap.ui.xml
new file mode 100644
index 0000000..4a1a391
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfoBootstrap.ui.xml
@@ -0,0 +1,173 @@
+
+
+
+ .no-border {
+ border: 0px;
+ }
+
+
+
+ Details
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Name
+
+
+
+
+
+
+ Id
+
+
+
+
+
+
+ Location
+
+
+
+
+
+
+ Public
+
+
+
+
+
+
+ Type
+
+
+
+
+
+
+ Thredds Sync
+
+
+
+
+
+
+ Description
+
+
+
+
+ Edit
+
+
+ Save
+
+
+
+
+ Gcube Properties
+
+
+
+
+ Edit
+
+
+
+
+ Owner
+
+
+
+
+
+
+ Created
+
+
+
+
+
+
+ Modified
+
+
+
+
+
+
+ Size
+
+
+
+
+
+
+ Shared
+
+
+
+
+
+
+
+ Shared with
+
+
+
+
+ Share
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/accounting/AccoutingInfoContainer.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/accounting/AccoutingInfoContainer.java
index 39fe098..a089d53 100644
--- a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/accounting/AccoutingInfoContainer.java
+++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/accounting/AccoutingInfoContainer.java
@@ -13,7 +13,6 @@ import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel
import com.extjs.gxt.ui.client.Style.ButtonScale;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
-import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.ButtonEvent;
diff --git a/src/main/java/org/gcube/portlets/user/workspace/public/js/pdfobject.js b/src/main/java/org/gcube/portlets/user/workspace/public/js/pdfobject.js
new file mode 100644
index 0000000..b1e3ec5
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/workspace/public/js/pdfobject.js
@@ -0,0 +1,286 @@
+/*global ActiveXObject, window, console, define, module, jQuery */
+//jshint unused:false, strict: false
+
+/*
+ PDFObject v2.1.1
+ https://github.com/pipwerks/PDFObject
+ Copyright (c) 2008-2018 Philip Hutchison
+ MIT-style license: http://pipwerks.mit-license.org/
+ UMD module pattern from https://github.com/umdjs/umd/blob/master/templates/returnExports.js
+*/
+
+(function (root, factory) {
+ if (typeof define === 'function' && define.amd) {
+ // AMD. Register as an anonymous module.
+ define([], factory);
+ } else if (typeof module === 'object' && module.exports) {
+ // Node. Does not work with strict CommonJS, but
+ // only CommonJS-like environments that support module.exports,
+ // like Node.
+ module.exports = factory();
+ } else {
+ // Browser globals (root is window)
+ root.PDFObject = factory();
+ }
+}(this, function () {
+
+ "use strict";
+ //jshint unused:true
+
+ //PDFObject is designed for client-side (browsers), not server-side (node)
+ //Will choke on undefined navigator and window vars when run on server
+ //Return boolean false and exit function when running server-side
+
+ if(typeof window === "undefined" || typeof navigator === "undefined"){ return false; }
+
+ var pdfobjectversion = "2.1.1",
+ ua = window.navigator.userAgent,
+
+ //declare booleans
+ supportsPDFs,
+ isIE,
+ supportsPdfMimeType = (typeof navigator.mimeTypes['application/pdf'] !== "undefined"),
+ supportsPdfActiveX,
+ isModernBrowser = (function (){ return (typeof window.Promise !== "undefined"); })(),
+ isFirefox = (function (){ return (ua.indexOf("irefox") !== -1); } )(),
+ isFirefoxWithPDFJS = (function (){
+ //Firefox started shipping PDF.js in Firefox 19.
+ //If this is Firefox 19 or greater, assume PDF.js is available
+ if(!isFirefox){ return false; }
+ //parse userAgent string to get release version ("rv")
+ //ex: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:57.0) Gecko/20100101 Firefox/57.0
+ return (parseInt(ua.split("rv:")[1].split(".")[0], 10) > 18);
+ })(),
+ isIOS = (function (){ return (/iphone|ipad|ipod/i.test(ua.toLowerCase())); })(),
+
+ //declare functions
+ createAXO,
+ buildFragmentString,
+ log,
+ embedError,
+ embed,
+ getTargetElement,
+ generatePDFJSiframe,
+ generateEmbedElement;
+
+
+ /* ----------------------------------------------------
+ Supporting functions
+ ---------------------------------------------------- */
+
+ createAXO = function (type){
+ var ax;
+ try {
+ ax = new ActiveXObject(type);
+ } catch (e) {
+ ax = null; //ensure ax remains null
+ }
+ return ax;
+ };
+
+ //IE11 still uses ActiveX for Adobe Reader, but IE 11 doesn't expose
+ //window.ActiveXObject the same way previous versions of IE did
+ //window.ActiveXObject will evaluate to false in IE 11, but "ActiveXObject" in window evaluates to true
+ //so check the first one for older IE, and the second for IE11
+ //FWIW, MS Edge (replacing IE11) does not support ActiveX at all, both will evaluate false
+ //Constructed as a method (not a prop) to avoid unneccesarry overhead -- will only be evaluated if needed
+ isIE = function (){ return !!(window.ActiveXObject || "ActiveXObject" in window); };
+
+ //If either ActiveX support for "AcroPDF.PDF" or "PDF.PdfCtrl" are found, return true
+ //Constructed as a method (not a prop) to avoid unneccesarry overhead -- will only be evaluated if needed
+ supportsPdfActiveX = function (){ return !!(createAXO("AcroPDF.PDF") || createAXO("PDF.PdfCtrl")); };
+
+ //Determines whether PDF support is available
+ supportsPDFs = (
+ //as of iOS 12, inline PDF rendering is still not supported in Safari or native webview
+ //3rd-party browsers (eg Chrome, Firefox) use Apple's webview for rendering, and thus the same result as Safari
+ //Therefore if iOS, we shall assume that PDF support is not available
+ !isIOS && (
+ //Modern versions of Firefox come bundled with PDFJS
+ isFirefoxWithPDFJS ||
+ //Browsers that still support the original MIME type check
+ supportsPdfMimeType || (
+ //Pity the poor souls still using IE
+ isIE() && supportsPdfActiveX()
+ )
+ )
+ );
+
+ //Create a fragment identifier for using PDF Open parameters when embedding PDF
+ buildFragmentString = function(pdfParams){
+
+ var string = "",
+ prop;
+
+ if(pdfParams){
+
+ for (prop in pdfParams) {
+ if (pdfParams.hasOwnProperty(prop)) {
+ string += encodeURIComponent(prop) + "=" + encodeURIComponent(pdfParams[prop]) + "&";
+ }
+ }
+
+ //The string will be empty if no PDF Params found
+ if(string){
+
+ string = "#" + string;
+
+ //Remove last ampersand
+ string = string.slice(0, string.length - 1);
+
+ }
+
+ }
+
+ return string;
+
+ };
+
+ log = function (msg){
+ if(typeof console !== "undefined" && console.log){
+ console.log("[PDFObject] " + msg);
+ }
+ };
+
+ embedError = function (msg){
+ log(msg);
+ return false;
+ };
+
+ getTargetElement = function (targetSelector){
+
+ //Default to body for full-browser PDF
+ var targetNode = document.body;
+
+ //If a targetSelector is specified, check to see whether
+ //it's passing a selector, jQuery object, or an HTML element
+
+ if(typeof targetSelector === "string"){
+
+ //Is CSS selector
+ targetNode = document.querySelector(targetSelector);
+
+ } else if (typeof jQuery !== "undefined" && targetSelector instanceof jQuery && targetSelector.length) {
+
+ //Is jQuery element. Extract HTML node
+ targetNode = targetSelector.get(0);
+
+ } else if (typeof targetSelector.nodeType !== "undefined" && targetSelector.nodeType === 1){
+
+ //Is HTML element
+ targetNode = targetSelector;
+
+ }
+
+ return targetNode;
+
+ };
+
+ generatePDFJSiframe = function (targetNode, url, pdfOpenFragment, PDFJS_URL, id){
+
+ var fullURL = PDFJS_URL + "?file=" + encodeURIComponent(url) + pdfOpenFragment;
+ var scrollfix = (isIOS) ? "-webkit-overflow-scrolling: touch; overflow-y: scroll; " : "overflow: hidden; ";
+ var iframe = "";
+ targetNode.className += " pdfobject-container";
+ targetNode.style.position = "relative";
+ targetNode.style.overflow = "auto";
+ targetNode.innerHTML = iframe;
+ return targetNode.getElementsByTagName("iframe")[0];
+
+ };
+
+ generateEmbedElement = function (targetNode, targetSelector, url, pdfOpenFragment, width, height, id){
+
+ var style = "";
+
+ if(targetSelector && targetSelector !== document.body){
+ style = "width: " + width + "; height: " + height + ";";
+ } else {
+ style = "position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%;";
+ }
+
+ targetNode.className += " pdfobject-container";
+ targetNode.innerHTML = "";
+
+ return targetNode.getElementsByTagName("embed")[0];
+
+ };
+
+ embed = function(url, targetSelector, options){
+
+ //Ensure URL is available. If not, exit now.
+ if(typeof url !== "string"){ return embedError("URL is not valid"); }
+
+ //If targetSelector is not defined, convert to boolean
+ targetSelector = (typeof targetSelector !== "undefined") ? targetSelector : false;
+
+ //Ensure options object is not undefined -- enables easier error checking below
+ options = (typeof options !== "undefined") ? options : {};
+
+ //Get passed options, or set reasonable defaults
+ var id = (options.id && typeof options.id === "string") ? "id='" + options.id + "'" : "",
+ page = (options.page) ? options.page : false,
+ pdfOpenParams = (options.pdfOpenParams) ? options.pdfOpenParams : {},
+ fallbackLink = (typeof options.fallbackLink !== "undefined") ? options.fallbackLink : true,
+ width = (options.width) ? options.width : "100%",
+ height = (options.height) ? options.height : "100%",
+ assumptionMode = (typeof options.assumptionMode === "boolean") ? options.assumptionMode : true,
+ forcePDFJS = (typeof options.forcePDFJS === "boolean") ? options.forcePDFJS : false,
+ PDFJS_URL = (options.PDFJS_URL) ? options.PDFJS_URL : false,
+ targetNode = getTargetElement(targetSelector),
+ fallbackHTML = "",
+ pdfOpenFragment = "",
+ fallbackHTML_default = "This browser does not support inline PDFs. Please download the PDF to view it: Download PDF
";
+
+ //If target element is specified but is not valid, exit without doing anything
+ if(!targetNode){ return embedError("Target element cannot be determined"); }
+
+
+ //page option overrides pdfOpenParams, if found
+ if(page){
+ pdfOpenParams.page = page;
+ }
+
+ //Stringify optional Adobe params for opening document (as fragment identifier)
+ pdfOpenFragment = buildFragmentString(pdfOpenParams);
+
+ //Do the dance
+
+ //If the forcePDFJS option is invoked, skip everything else and embed as directed
+ if(forcePDFJS && PDFJS_URL){
+
+ return generatePDFJSiframe(targetNode, url, pdfOpenFragment, PDFJS_URL, id);
+
+ //If traditional support is provided, or if this is a modern browser and not iOS (see comment for supportsPDFs declaration)
+ } else if(supportsPDFs || (assumptionMode && isModernBrowser && !isIOS)){
+
+ return generateEmbedElement(targetNode, targetSelector, url, pdfOpenFragment, width, height, id);
+
+ //If everything else has failed and a PDFJS fallback is provided, try to use it
+ } else if(PDFJS_URL){
+
+ return generatePDFJSiframe(targetNode, url, pdfOpenFragment, PDFJS_URL, id);
+
+ } else {
+
+ //Display the fallback link if available
+ if(fallbackLink){
+
+ fallbackHTML = (typeof fallbackLink === "string") ? fallbackLink : fallbackHTML_default;
+ targetNode.innerHTML = fallbackHTML.replace(/\[url\]/g, url);
+
+ }
+
+ return embedError("This browser does not support embedded PDFs");
+
+ }
+
+ };
+
+ return {
+ embed: function (a,b,c){ return embed(a,b,c); },
+ pdfobjectversion: (function () { return pdfobjectversion; })(),
+ supportsPDFs: (function (){ return supportsPDFs; })()
+ };
+
+}));
\ No newline at end of file
diff --git a/src/main/java/org/gcube/portlets/user/workspace/public/workspacetree.css b/src/main/java/org/gcube/portlets/user/workspace/public/workspacetree.css
index ad9e41b..eb8e29e 100644
--- a/src/main/java/org/gcube/portlets/user/workspace/public/workspacetree.css
+++ b/src/main/java/org/gcube/portlets/user/workspace/public/workspacetree.css
@@ -273,18 +273,18 @@ table.userssuggest th {
top: 2% !important;
}
-.my-control-group .controls{
+.my-control-group .controls {
margin-left: 70px !important;
}
.my-control-group .control-label {
- width: 80px !important;
- text-align: center !important;
- padding-right: 10px !important;
+ width: 80px !important;
+ text-align: center !important;
+ padding-right: 10px !important;
}
-.my-control-group .add-on{
- width: 20px !important;
+.my-control-group .add-on {
+ width: 20px !important;
}
.my-control-group .gwt-TextBox {
@@ -300,4 +300,133 @@ table.userssuggest th {
cursor: default;
color: gray !important;
text-decoration: none;
+}
+
+.my-control-group-get-info {
+ margin-bottom: 5px !important;
+ margin-left: 15px;
+ font-size: 14px !important;
+ font-family: Arial, serif;
+ color: #222;
+
+}
+
+.my-control-group-get-info .controls {
+ margin-left: 70px !important;
+}
+
+.my-control-group-get-info .control-label {
+ width: 80px !important;
+ text-align: left !important;
+ padding-right: 10px !important;
+ font-family: Roboto, Arial, serif !important;
+ color: #959595;
+}
+
+.my-control-group-get-info .add-on {
+ width: 20px !important;
+}
+
+.my-control-group-get-info .gwt-HTML {
+ padding-top: 5px;
+ font-family: Roboto, Arial, serif !important;
+ word-wrap: break-word;
+ overflow-wrap: anywhere;
+ overflow: hidden;
+}
+
+.my-control-group-get-info .gwt-TextBox:hover {
+ cursor: text !important;
+}
+
+.my-control-group-get-info .gwt-TextArea {
+ width: 260px;
+ min-height: 60px;
+ height: 60px;
+}
+
+.my-control-group-get-info .btn-link {
+ margin-left: 7px !important;
+}
+
+.item-type-style {
+ margin-top: 1px;
+ margin-left: 10px;
+ margin-bottom: 10px;
+ padding-top: 5px;
+ padding-bottom: 5px;
+}
+
+.item-type-style td {
+ height: 30px;
+}
+
+.item-type-style td:first-child {
+ width: 30px;
+ padding-left: 5px;
+}
+
+.item-type-style td {
+ vertical-align: middle !important;
+}
+
+/*THIS IS THE SIZE OF DOWNLOAD ICON
+IN THE 'DETAILS' PANEL*/
+.item-type-style td a i{
+ font-size: 22px;
+}
+
+
+.item-details-header {
+ margin-top: 15px;
+ margin-left: 15px;
+ margin-right: 15px;
+}
+
+.item-details-header td {
+ vertical-align: middle !important;
+}
+
+.item-details-header td:last-child {
+ width: 85%;
+ color: #555;
+}
+
+.item-details-header .gwt-HTML {
+ font-size: 20px;
+ font-family: Roboto, Arial, serif !important;
+ color: #555;
+}
+
+.placeholder-loading {
+ color: rgb(142, 142, 142);
+}
+
+.shared-with-style{
+ width: 90% !important;
+ font-size: 12px !important;
+ display: inline-block !important;
+}
+
+.preview-image-style {
+ width: 95%;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+}
+
+.preview-image-style img {
+ max-width: 400px;
+}
+
+.preview-file-style {
+ width: 95%;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+}
+
+.my-preview-doc {
+ width: 350px;
+ height: 350px;
}
\ 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 c4be0d8..d71cd0a 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
@@ -53,6 +53,7 @@ import org.gcube.portlets.user.workspace.server.reader.ApplicationProfileReader;
import org.gcube.portlets.user.workspace.server.tostoragehub.FormatterUtil;
import org.gcube.portlets.user.workspace.server.tostoragehub.ObjectStorageHubToWorkpaceMapper;
import org.gcube.portlets.user.workspace.server.tostoragehub.StorageHubToWorkpaceConverter;
+import org.gcube.portlets.user.workspace.server.util.MimeTypeUtility;
import org.gcube.portlets.user.workspace.server.util.PortalContextInfo;
import org.gcube.portlets.user.workspace.server.util.StringUtil;
import org.gcube.portlets.user.workspace.server.util.WsUtil;
@@ -3075,5 +3076,58 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
throw new Exception(error);
}
}
+
+
+ /**
+ * Update description for item.
+ *
+ * @param itemId the item id
+ * @param newDescription the new description
+ * @return the string
+ * @throws Exception the exception
+ */
+ @Override
+ public String updateDescriptionForItem(String itemId, String newDescription) throws Exception {
+ workspaceLogger.info("Called updateDescriptionForItem for itemID: " + itemId);
+
+ if (itemId == null || itemId.isEmpty())
+ throw new Exception("I can't update the description, the itemId is null");
+
+ workspaceLogger.debug("New description is: " + newDescription);
+
+ try {
+
+ org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace = getWorkspaceFromStorageHub();
+ newDescription = workspace.updateDescriptionForItem(itemId, newDescription);
+
+ } catch (Exception e) {
+ workspaceLogger.error("Error on updating the description for item: " + itemId, e);
+ String error = ConstantsExplorer.SERVER_ERROR + " updating the description for item with id: "
+ + "" + itemId+". Error reported: "+e.getMessage();
+ throw new Exception(error);
+ }
+
+ return newDescription;
+ }
+
+
+
+ /**
+ * Gets the allowed mimetypes for preview.
+ *
+ * @return the allowed mimetypes for preview
+ */
+
+ @Override
+ public Map> getAllowedMimetypesForPreview(){
+ workspaceLogger.info("Called getAllowedMimetypesForPreview");
+
+ Map> map = MimeTypeUtility.getPreviewMimetypeExtensionMap();
+
+ workspaceLogger.debug("Returning allowed mimetypes for preview: "+map.keySet());
+
+ return map;
+
+ }
}
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 fe33f8a..57a4313 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
@@ -145,17 +145,21 @@ public class ImageServlet extends HttpServlet{
try{
streamDescr = wa.getThumbnailData(image.getId());
-
- /*TODO
- * UNCOMMENT THIS IF YOU WANT TO ADD MORE CONTROLS
- ReusableInputStream ris = new ReusableInputStream(streamDescr.getStream());
+ logger.debug("Thumbnail data has size: "+streamDescr.getSize());
+ //CHECKING IF THE STREAM IS A VALID IMAGE
+ /* TODO
+ * ReusableInputStream ris = new ReusableInputStream(streamDescr.getStream());
boolean isAvalidImage = isAnImage(ris, image.getName());
- if(!isAvalidImage)
+ if(!isAvalidImage) {
//CREATING THE THUMBNAIL
+ logger.debug("the stream seems not be a valid image, creating the thumbnail");
streamDescr = createThumbnailForImage(wa, image);
- else {
+ }else {
//ASSIGNING THE REUSABLE STREAM
- streamDescr = new org.gcube.common.storagehubwrapper.shared.tohl.impl.StreamDescriptor(ris, image.getName(), null, image.getMimeType());
+ logger.debug("using reusable stream");
+ size = streamDescr.getSize()==null?0:streamDescr.getSize();
+ logger.debug("ReusableInputStream has size: "+size);
+ streamDescr = new org.gcube.common.storagehubwrapper.shared.tohl.impl.StreamDescriptor(ris, image.getName(), size, streamDescr.getMimeType());
}*/
@@ -186,8 +190,9 @@ public class ImageServlet extends HttpServlet{
resp.setContentType(mimeType);
//if image/thumbnail size is 0, skipping setContentLength
- if(size!=0)
- resp.setContentLength((int)size);
+ //AVOIDING TO SET IT, SOME CASES THE SIZE MISMATCH
+// if(size!=0)
+// resp.setContentLength((int)size);
InputStream in = streamDescr.getStream();
diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/MimeTypeUtility.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/MimeTypeUtility.java
index 454d9f7..1d94814 100644
--- a/src/main/java/org/gcube/portlets/user/workspace/server/util/MimeTypeUtility.java
+++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/MimeTypeUtility.java
@@ -17,11 +17,10 @@ import org.apache.commons.io.FilenameUtils;
import org.apache.tika.config.TikaConfig;
import org.apache.tika.detect.Detector;
import org.apache.tika.io.TikaInputStream;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.mime.MediaType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+// TODO: Auto-generated Javadoc
/**
* The Class MimeTypeUtil.
*
@@ -48,15 +47,19 @@ public class MimeTypeUtility {
protected static final Map> mimetype_extension_map = new LinkedHashMap>();
protected static final Map extension_mimetype_map = new LinkedHashMap();
+ protected static final Map> preview_mimetype_extension_map = new LinkedHashMap>();
static {
InputStream extensionToMimetype = MimeTypeUtility.class
.getResourceAsStream("/WsExtensionToMimeTypeMap.properties");
InputStream mimetypeToExtension = MimeTypeUtility.class
.getResourceAsStream("/WsMimeTypeToExtensionMap.properties");
+ InputStream previewMimeTypeToExtension = MimeTypeUtility.class
+ .getResourceAsStream("/PreviewMimeTypeToExtensionMap.properties");
try {
loadExtensions(extensionToMimetype);
loadMimeTypes(mimetypeToExtension);
+ loadPreviewMimeTypes(previewMimeTypeToExtension);
} catch (IOException e) {
e.printStackTrace();
}
@@ -114,6 +117,35 @@ public class MimeTypeUtility {
}
br.close();
}
+
+
+ /**
+ * Load preview mime types.
+ *
+ * @param is the is
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ protected static void loadPreviewMimeTypes(InputStream is) throws IOException {
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));
+
+ String line = br.readLine();
+
+ while (line != null) {
+ String[] split = line.split("=");
+ if (split.length == 2) {
+ String mimeType = split[0];
+ String extension = split[1];
+ List toExtensions = preview_mimetype_extension_map.get(mimeType);
+ if (toExtensions == null) {
+ toExtensions = new ArrayList();
+ }
+ toExtensions.add(extension);
+ preview_mimetype_extension_map.put(mimeType, toExtensions);
+ }
+ line = br.readLine();
+ }
+ br.close();
+ }
/**
* Gets the extension.
@@ -279,5 +311,16 @@ public class MimeTypeUtility {
public static Map getExtensionToMimeTypeMap() {
return extension_mimetype_map;
}
+
+
+ /**
+ * Gets the preview mimetype extension map with the
+ * mime types allowed for preview displaying
+ *
+ * @return the preview mimetype extension map
+ */
+ public static Map> getPreviewMimetypeExtensionMap() {
+ return preview_mimetype_extension_map;
+ }
}
diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/ThumbnailGenerator.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/ThumbnailGenerator.java
index af11c18..b6e7932 100644
--- a/src/main/java/org/gcube/portlets/user/workspace/server/util/ThumbnailGenerator.java
+++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/ThumbnailGenerator.java
@@ -136,7 +136,7 @@ public class ThumbnailGenerator {
extension = extension.startsWith(".") ? extension : "." + extension;
final File tempFile = File.createTempFile(filename, extension);
- //tempFile.deleteOnExit();
+ tempFile.deleteOnExit();
try (FileOutputStream out = new FileOutputStream(tempFile)) {
IOUtils.copy(in, out);
}
diff --git a/src/main/resources/PreviewMimeTypeToExtensionMap.properties b/src/main/resources/PreviewMimeTypeToExtensionMap.properties
new file mode 100644
index 0000000..4f280e0
--- /dev/null
+++ b/src/main/resources/PreviewMimeTypeToExtensionMap.properties
@@ -0,0 +1,62 @@
+application/msword=doc
+application/pdf=pdf
+application/rtf=rtf
+application/vnd.ms-excel=xls
+application/vnd.ms-powerpoint=ppt
+application/vnd.openxmlformats-officedocument.wordprocessingml.document=docx
+application/vnd.openxmlformats-officedocument.spreadsheetml.sheet=xlsx
+application/vnd.openxmlformats-officedocument.presentationml.presentation=pptx
+application/x-javascript=js
+application/json=json
+audio/mid=mid
+audio/mpeg=mp3
+audio/x-wav=wav
+image/bmp=bmp
+image/gif=gif
+image/ief=ief
+image/jpeg=jpe
+image/jpeg=jpeg
+image/jpeg=jpg
+image/pipeg=jfif
+image/svg+xml=svg
+image/tiff=tif
+image/tiff=tiff
+image/x-cmu-raster=ras
+image/x-cmx=cmx
+image/x-icon=ico
+image/x-rgb=rgb
+text/css=css
+text/html=htm
+text/html=stm
+text/html=html
+text/plain=bas
+text/plain=c
+text/plain=h
+text/plain=txt
+text/richtext=rtx
+text/scriptlet=sct
+text/tab-separated-values=tsv
+text/uri-list=txt
+text/webviewhtml=htt
+text/x-component=htc
+video/mpeg=mp2
+video/mpeg=mpa
+video/mpeg=mpe
+video/mpeg=mpeg
+video/mpeg=mpg
+video/mpeg=mpv2
+video/quicktime=mov
+video/quicktime=qt
+video/x-la-asf=lsf
+video/x-la-asf=lsx
+video/x-ms-asf=asf
+video/x-ms-asf=asr
+video/x-ms-asf=asx
+video/x-msvideo=avi
+video/x-sgi-movie=movie
+x-world/x-vrml=flr
+x-world/x-vrml=vrml
+x-world/x-vrml=wrl
+x-world/x-vrml=wrz
+x-world/x-vrml=xaf
+x-world/x-vrml=xof
\ No newline at end of file