Updated pom version at 6.26.0
Completed Task #17135 git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@181149 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ee6f99b53c
commit
d4d0b5b2fc
|
@ -1,9 +1,17 @@
|
||||||
<ReleaseNotes>
|
<ReleaseNotes>
|
||||||
|
<Changeset
|
||||||
|
component="org.gcube.portlets-user.workspace-portlet-tree.6-26-0"
|
||||||
|
date="${buildDate}">
|
||||||
|
<Change>[Task #17135] Workspace: assign the file extension during the
|
||||||
|
download
|
||||||
|
</Change>
|
||||||
|
</Changeset>
|
||||||
<Changeset
|
<Changeset
|
||||||
component="org.gcube.portlets-user.workspace-portlet-tree.6-25-1"
|
component="org.gcube.portlets-user.workspace-portlet-tree.6-25-1"
|
||||||
date="${buildDate}">
|
date="${buildDate}">
|
||||||
<Change>[Task #17018] Move some methods to SHUB due to backward
|
<Change>[Task #17018] Move some methods to SHUB due to backward
|
||||||
compatibility broken between SHUB and HL</Change>
|
compatibility broken between SHUB and HL
|
||||||
|
</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset
|
<Changeset
|
||||||
component="org.gcube.portlets-user.workspace-portlet-tree.6-25-0"
|
component="org.gcube.portlets-user.workspace-portlet-tree.6-25-0"
|
||||||
|
|
10
pom.xml
10
pom.xml
|
@ -1,4 +1,5 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
|
@ -10,7 +11,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.portlets.user</groupId>
|
<groupId>org.gcube.portlets.user</groupId>
|
||||||
<artifactId>workspace-tree-widget</artifactId>
|
<artifactId>workspace-tree-widget</artifactId>
|
||||||
<version>6.25.1-SNAPSHOT</version>
|
<version>6.26.0-SNAPSHOT</version>
|
||||||
<name>gCube Workspace Tree Widget</name>
|
<name>gCube Workspace Tree Widget</name>
|
||||||
<description>
|
<description>
|
||||||
gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace
|
gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace
|
||||||
|
@ -263,6 +264,11 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- LOGGER -->
|
<!-- LOGGER -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
|
|
|
@ -17,7 +17,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.gcube.common.homelibrary.util.MimeTypeUtil;
|
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
||||||
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
|
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
|
||||||
|
@ -31,6 +30,7 @@ import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem;
|
||||||
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
||||||
import org.gcube.portlets.user.workspace.server.property.PortalUrlGroupGatewayProperty;
|
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.AllowedMimeTypeToInline;
|
||||||
|
import org.gcube.portlets.user.workspace.server.util.MimeTypeUtility;
|
||||||
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 org.gcube.portlets.user.workspace.shared.SessionExpiredException;
|
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
|
||||||
|
@ -154,7 +154,7 @@ public class DownloadServlet extends HttpServlet{
|
||||||
logger.info("Downloading the folder: "+workspaceFolder);
|
logger.info("Downloading the folder: "+workspaceFolder);
|
||||||
String contentDisposition = viewContent?"inline":"attachment";
|
String contentDisposition = viewContent?"inline":"attachment";
|
||||||
String mimeType = "application/zip";
|
String mimeType = "application/zip";
|
||||||
String itemName = MimeTypeUtil.getNameWithExtension(item.getName(), mimeType);
|
String itemName = MimeTypeUtility.getNameWithExtension(item.getName(), mimeType);
|
||||||
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
||||||
resp.setContentType(mimeType);
|
resp.setContentType(mimeType);
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ public class DownloadServlet extends HttpServlet{
|
||||||
String mimeType = pdfFile.getMimeType();
|
String mimeType = pdfFile.getMimeType();
|
||||||
logger.trace("EXTERNAL_FILE DOWNLOAD FOR "+pdfFile.getId());
|
logger.trace("EXTERNAL_FILE DOWNLOAD FOR "+pdfFile.getId());
|
||||||
String contentDisposition = viewContent?"inline":"attachment";
|
String contentDisposition = viewContent?"inline":"attachment";
|
||||||
String itemName = MimeTypeUtil.getNameWithExtension(descr.getItemName(), mimeType);
|
String itemName = MimeTypeUtility.getNameWithExtension(descr.getItemName(), mimeType);
|
||||||
|
|
||||||
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
||||||
resp.setContentType(mimeType);
|
resp.setContentType(mimeType);
|
||||||
|
@ -223,7 +223,7 @@ public class DownloadServlet extends HttpServlet{
|
||||||
ImageFileItem imageFile = (ImageFileItem) workspaceFileItem;
|
ImageFileItem imageFile = (ImageFileItem) workspaceFileItem;
|
||||||
logger.info("Downloading: "+imageFile);
|
logger.info("Downloading: "+imageFile);
|
||||||
String mimeType = imageFile.getMimeType();
|
String mimeType = imageFile.getMimeType();
|
||||||
String itemName = MimeTypeUtil.getNameWithExtension(descr.getItemName(), mimeType);
|
String itemName = MimeTypeUtility.getNameWithExtension(descr.getItemName(), mimeType);
|
||||||
String contentDisposition = viewContent?"inline":"attachment";
|
String contentDisposition = viewContent?"inline":"attachment";
|
||||||
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
||||||
resp.setContentType(mimeType);
|
resp.setContentType(mimeType);
|
||||||
|
@ -247,7 +247,7 @@ public class DownloadServlet extends HttpServlet{
|
||||||
URLFileItem externalUrl = (URLFileItem) workspaceFileItem;
|
URLFileItem externalUrl = (URLFileItem) workspaceFileItem;
|
||||||
logger.info("Downloading: "+externalUrl);
|
logger.info("Downloading: "+externalUrl);
|
||||||
String urlMimeType = "text/uri-list";
|
String urlMimeType = "text/uri-list";
|
||||||
String itemName = MimeTypeUtil.getNameWithExtension(descr.getItemName(), urlMimeType);
|
String itemName = MimeTypeUtility.getNameWithExtension(descr.getItemName(), urlMimeType);
|
||||||
String contentDisposition = viewContent?"inline":"attachment";
|
String contentDisposition = viewContent?"inline":"attachment";
|
||||||
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
||||||
resp.setContentType(urlMimeType);
|
resp.setContentType(urlMimeType);
|
||||||
|
@ -296,7 +296,7 @@ public class DownloadServlet extends HttpServlet{
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
String itemName = MimeTypeUtil.getNameWithExtension(descr.getItemName(), workspaceFileItem.getMimeType());
|
String itemName = MimeTypeUtility.getNameWithExtension(descr.getItemName(), workspaceFileItem.getMimeType());
|
||||||
logger.info("Downloading default item: "+workspaceFileItem);
|
logger.info("Downloading default item: "+workspaceFileItem);
|
||||||
|
|
||||||
//String contentDisposition = viewContent?"inline":"attachment";
|
//String contentDisposition = viewContent?"inline":"attachment";
|
||||||
|
|
|
@ -0,0 +1,251 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.workspace.server.util;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class MimeTypeUtil.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||||
|
*
|
||||||
|
* Copied from org.gcube.common.homelibrary.util.MimeTypeUtil
|
||||||
|
* @author Federico De Faveri defaveri@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Jul 5, 2019
|
||||||
|
*/
|
||||||
|
public class MimeTypeUtility {
|
||||||
|
|
||||||
|
protected static Logger logger = Logger.getLogger(MimeTypeUtility.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String BINARY_MIMETYPE = "application/octet-stream";
|
||||||
|
public static final String[] ZIP_MIMETYPES = new String[] { "application/octet-stream", "application/x-compress",
|
||||||
|
"application/x-compressed", "application/x-zip-compressed", "application/x-gzip", "application/x-winzip",
|
||||||
|
"application/x-zip", "application/zip", "multipart/x-zip" };
|
||||||
|
|
||||||
|
protected static final Map<String, List<String>> mimetype_extension_map = new LinkedHashMap<String, List<String>>();
|
||||||
|
protected static final Map<String, String> extension_mimetype_map = new LinkedHashMap<String, String>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
InputStream extensionToMimetype = MimeTypeUtility.class.getResourceAsStream("/ExtensionToMimeTypeMap.properties");
|
||||||
|
InputStream mimetypeToExtension = MimeTypeUtility.class.getResourceAsStream("/MimeTypeToExtensionMap.properties");
|
||||||
|
try {
|
||||||
|
loadExtensions(extensionToMimetype);
|
||||||
|
loadMimeTypes(mimetypeToExtension);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load extensions.
|
||||||
|
*
|
||||||
|
* @param is the is
|
||||||
|
* @throws IOException Signals that an I/O exception has occurred.
|
||||||
|
*/
|
||||||
|
protected static void loadExtensions(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];
|
||||||
|
extension_mimetype_map.put(extension, mimeType);
|
||||||
|
}
|
||||||
|
line = br.readLine();
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load mime types.
|
||||||
|
*
|
||||||
|
* @param is the is
|
||||||
|
* @throws IOException Signals that an I/O exception has occurred.
|
||||||
|
*/
|
||||||
|
protected static void loadMimeTypes(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<String> toExtensions = mimetype_extension_map.get(mimeType);
|
||||||
|
if(toExtensions==null) {
|
||||||
|
toExtensions = new ArrayList<String>();
|
||||||
|
}
|
||||||
|
toExtensions.add(extension);
|
||||||
|
mimetype_extension_map.put(mimeType, toExtensions);
|
||||||
|
//mimetype_extension_map.put(mimeType, extension);
|
||||||
|
}
|
||||||
|
line = br.readLine();
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the extension.
|
||||||
|
*
|
||||||
|
* @param mimeType the mime type.
|
||||||
|
* @return the related list of Extensions.
|
||||||
|
*/
|
||||||
|
public static List<String> getExtension(String mimeType) {
|
||||||
|
return mimetype_extension_map.get(mimeType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name with extension.
|
||||||
|
*
|
||||||
|
* @param name the file name.
|
||||||
|
* @param mimeType the mime type.
|
||||||
|
* @return the right name.
|
||||||
|
* @throws IOException Signals that an I/O exception has occurred.
|
||||||
|
*/
|
||||||
|
public static String getNameWithExtension(String name, String mimeType) throws IOException {
|
||||||
|
|
||||||
|
logger.trace("getNameWithExtension name: " + name + " mimeType: " + mimeType);
|
||||||
|
|
||||||
|
String declaredExtension = FilenameUtils.getExtension(name);
|
||||||
|
|
||||||
|
if(declaredExtension.isEmpty()) {
|
||||||
|
|
||||||
|
if (mimeType == null)
|
||||||
|
return name;
|
||||||
|
|
||||||
|
List<String> extensions = MimeTypeUtility.getExtension(mimeType);
|
||||||
|
logger.trace("Available into map extensions is/are: " + extensions);
|
||||||
|
|
||||||
|
String extension;
|
||||||
|
if(extensions==null) {
|
||||||
|
extension = "";
|
||||||
|
}else {
|
||||||
|
extension = extensions.get(extensions.size()-1); //I'm reading the last extension in the map (myme type - list of extensions)
|
||||||
|
logger.debug("Using the last extension read into list of available extensions: " + extension);
|
||||||
|
extension = "." + extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.trace("returning " + name + extension);
|
||||||
|
return name + extension;
|
||||||
|
}else {
|
||||||
|
logger.trace("extension already declared in the name "+name+", returning name like is it");
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the content type is a zip type.
|
||||||
|
*
|
||||||
|
* @param contentType the content type to check.
|
||||||
|
* @return <code>true</code> if is a zip file, <code>false</code> otherwise.
|
||||||
|
*/
|
||||||
|
public static boolean isZipContentType(String contentType) {
|
||||||
|
for (String zip_mimetype : ZIP_MIMETYPES)
|
||||||
|
if (zip_mimetype.equals(contentType))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get mime type by file.
|
||||||
|
*
|
||||||
|
* @param filenameWithExtension the filename with extension
|
||||||
|
* @param tmpFile the tmp file
|
||||||
|
* @return the mime type of the given file
|
||||||
|
*/
|
||||||
|
public static String getMimeType(String filenameWithExtension, File tmpFile) {
|
||||||
|
MediaType mediaType = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
TikaConfig config = TikaConfig.getDefaultConfig();
|
||||||
|
Detector detector = config.getDetector();
|
||||||
|
TikaInputStream stream = TikaInputStream.get(tmpFile);
|
||||||
|
Metadata metadata = new Metadata();
|
||||||
|
metadata.add(Metadata.RESOURCE_NAME_KEY, filenameWithExtension);
|
||||||
|
|
||||||
|
mediaType = detector.detect(stream, metadata);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Error detecting mime type for file " + filenameWithExtension);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mediaType.getBaseType().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get mime type by inpustream.
|
||||||
|
*
|
||||||
|
* @param filenameWithExtension the filename with extension
|
||||||
|
* @param input the input
|
||||||
|
* @return the mime type of the given file
|
||||||
|
* @throws IOException Signals that an I/O exception has occurred.
|
||||||
|
*/
|
||||||
|
public static String getMimeType(String filenameWithExtension, InputStream input) throws IOException {
|
||||||
|
|
||||||
|
MediaType mediaType = null;
|
||||||
|
try {
|
||||||
|
TikaConfig config = TikaConfig.getDefaultConfig();
|
||||||
|
Detector detector = config.getDetector();
|
||||||
|
TikaInputStream stream = TikaInputStream.get(input);
|
||||||
|
Metadata metadata = new Metadata();
|
||||||
|
metadata.add(Metadata.RESOURCE_NAME_KEY, filenameWithExtension);
|
||||||
|
|
||||||
|
mediaType = detector.detect(stream, metadata);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Error detecting mime type for file " + filenameWithExtension);
|
||||||
|
} finally {
|
||||||
|
// if (file!=null)
|
||||||
|
// file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return mediaType.getBaseType().toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the mime type to extension map.
|
||||||
|
*
|
||||||
|
* @return the mime type to extension map
|
||||||
|
*/
|
||||||
|
public static Map<String, List<String>> getMimeTypeToExtensionMap() {
|
||||||
|
return mimetype_extension_map;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the extension to mime type map.
|
||||||
|
*
|
||||||
|
* @return the extension to mime type map
|
||||||
|
*/
|
||||||
|
public static Map<String, String> getExtensionToMimeTypeMap() {
|
||||||
|
return extension_mimetype_map;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,212 @@
|
||||||
|
application/envoy =evy
|
||||||
|
application/fractals=fif
|
||||||
|
application/futuresplash=spl
|
||||||
|
application/hta=hta
|
||||||
|
application/internet-property-stream=acx
|
||||||
|
application/mac-binhex40=hqx
|
||||||
|
application/msword=doc
|
||||||
|
application/msword=dot
|
||||||
|
application/octet-stream=*
|
||||||
|
application/octet-stream=bin
|
||||||
|
application/octet-stream=class
|
||||||
|
application/octet-stream=dms
|
||||||
|
application/octet-stream=exe
|
||||||
|
application/octet-stream=lha
|
||||||
|
application/octet-stream=lzh
|
||||||
|
application/oda=oda
|
||||||
|
application/olescript=axs
|
||||||
|
application/pdf=pdf
|
||||||
|
application/pics-rules=prf
|
||||||
|
application/pkcs10=p10
|
||||||
|
application/pkix-crl=crl
|
||||||
|
application/postscript=ai
|
||||||
|
application/postscript=eps
|
||||||
|
application/postscript=ps
|
||||||
|
application/rtf=rtf
|
||||||
|
application/set-payment-initiation=setpay
|
||||||
|
application/set-registration-initiation=setreg
|
||||||
|
application/vnd.ms-excel=xla
|
||||||
|
application/vnd.ms-excel=xlc
|
||||||
|
application/vnd.ms-excel=xlm
|
||||||
|
application/vnd.ms-excel=xls
|
||||||
|
application/vnd.ms-excel=xlt
|
||||||
|
application/vnd.ms-excel=xlw
|
||||||
|
application/vnd.ms-outlook=msg
|
||||||
|
application/vnd.ms-pkicertstore=sst
|
||||||
|
application/vnd.ms-pkiseccat=cat
|
||||||
|
application/vnd.ms-pkistl=stl
|
||||||
|
application/vnd.ms-powerpoint=pot
|
||||||
|
application/vnd.ms-powerpoint=pps
|
||||||
|
application/vnd.ms-powerpoint=ppt
|
||||||
|
application/vnd.ms-project=mpp
|
||||||
|
application/vnd.ms-works=wcm
|
||||||
|
application/vnd.ms-works=wdb
|
||||||
|
application/vnd.ms-works=wks
|
||||||
|
application/vnd.ms-works=wps
|
||||||
|
application/vnd.openxmlformats-officedocument.wordprocessingml.document=docx
|
||||||
|
application/vnd.ms-word.document.macroEnabled.12=docm
|
||||||
|
application/vnd.openxmlformats-officedocument.wordprocessingml.template=dotx
|
||||||
|
application/vnd.ms-powerpoint.template.macroEnabled.12=potm
|
||||||
|
application/vnd.openxmlformats-officedocument.presentationml.template=potx
|
||||||
|
application/vnd.ms-powerpoint.addin.macroEnabled.12=ppam
|
||||||
|
application/vnd.ms-powerpoint.slideshow.macroEnabled.12=ppsm
|
||||||
|
application/vnd.openxmlformats-officedocument.presentationml.slideshow=ppsx
|
||||||
|
application/vnd.ms-powerpoint.presentation.macroEnabled.12=pptm
|
||||||
|
application/vnd.openxmlformats-officedocument.presentationml.presentation=pptx
|
||||||
|
application/vnd.ms-excel.addin.macroEnabled.12=xlam
|
||||||
|
application/vnd.ms-excel.sheet.binary.macroEnabled.12=xlsb
|
||||||
|
application/vnd.ms-excel.sheet.macroEnabled.12=xlsm
|
||||||
|
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet=xlsx
|
||||||
|
application/vnd.ms-excel.template.macroEnabled.12=xltm
|
||||||
|
application/vnd.openxmlformats-officedocument.spreadsheetml.template=xltx
|
||||||
|
application/winhlp=hlp
|
||||||
|
application/x-bcpio=bcpio
|
||||||
|
application/x-cdf=cdf
|
||||||
|
application/x-compress=z
|
||||||
|
application/x-compressed=tgz
|
||||||
|
application/x-cpio=cpio
|
||||||
|
application/x-csh=csh
|
||||||
|
application/x-director=dcr
|
||||||
|
application/x-director=dir
|
||||||
|
application/x-director=dxr
|
||||||
|
application/x-dvi=dvi
|
||||||
|
application/x-gtar=gtar
|
||||||
|
application/x-gzip=gz
|
||||||
|
application/x-hdf=hdf
|
||||||
|
application/x-internet-signup=ins
|
||||||
|
application/x-internet-signup=isp
|
||||||
|
application/x-iphone=iii
|
||||||
|
application/x-javascript=js
|
||||||
|
application/x-latex=latex
|
||||||
|
application/x-msaccess=mdb
|
||||||
|
application/x-mscardfile=crd
|
||||||
|
application/x-msclip=clp
|
||||||
|
application/x-msdownload=dll
|
||||||
|
application/x-msmediaview=m13
|
||||||
|
application/x-msmediaview=m14
|
||||||
|
application/x-msmediaview=mvb
|
||||||
|
application/x-msmetafile=wmf
|
||||||
|
application/x-msmoney=mny
|
||||||
|
application/x-mspublisher=pub
|
||||||
|
application/x-msschedule=scd
|
||||||
|
application/x-msterminal=trm
|
||||||
|
application/x-mswrite=wri
|
||||||
|
application/x-netcdf=cdf
|
||||||
|
application/x-netcdf=nc
|
||||||
|
application/x-perfmon=pma
|
||||||
|
application/x-perfmon=pmc
|
||||||
|
application/x-perfmon=pml
|
||||||
|
application/x-perfmon=pmr
|
||||||
|
application/x-perfmon=pmw
|
||||||
|
application/x-pkcs12=p12
|
||||||
|
application/x-pkcs12=pfx
|
||||||
|
application/x-pkcs7-certificates=p7b
|
||||||
|
application/x-pkcs7-certificates=spc
|
||||||
|
application/x-pkcs7-certreqresp=p7r
|
||||||
|
application/x-pkcs7-mime=p7c
|
||||||
|
application/x-pkcs7-mime=p7m
|
||||||
|
application/x-pkcs7-signature=p7s
|
||||||
|
application/x-sh=sh
|
||||||
|
application/x-shar=shar
|
||||||
|
application/x-shockwave-flash=swf
|
||||||
|
application/x-stuffit=sit
|
||||||
|
application/x-sv4cpio=sv4cpio
|
||||||
|
application/x-sv4crc=sv4crc
|
||||||
|
application/x-tar=tar
|
||||||
|
application/x-tcl=tcl
|
||||||
|
application/x-tex=tex
|
||||||
|
application/x-texinfo=texi
|
||||||
|
application/x-texinfo=texinfo
|
||||||
|
application/x-troff=roff
|
||||||
|
application/x-troff=t
|
||||||
|
application/x-troff=tr
|
||||||
|
application/x-troff-man=man
|
||||||
|
application/x-troff-me=me
|
||||||
|
application/x-troff-ms=ms
|
||||||
|
application/x-ustar=ustar
|
||||||
|
application/x-wais-source=src
|
||||||
|
application/x-x509-ca-cert=cer
|
||||||
|
application/x-x509-ca-cert=crt
|
||||||
|
application/x-x509-ca-cert=der
|
||||||
|
application/ynd.ms-pkipko=pko
|
||||||
|
application/zip=zip
|
||||||
|
application/x-java-archive=jar
|
||||||
|
application/x-java-archive=war
|
||||||
|
audio/basic=au
|
||||||
|
audio/basic=snd
|
||||||
|
audio/mid=mid
|
||||||
|
audio/mid=rmi
|
||||||
|
audio/mpeg=mp3
|
||||||
|
audio/x-aiff=aif
|
||||||
|
audio/x-aiff=aifc
|
||||||
|
audio/x-aiff=aiff
|
||||||
|
audio/x-mpegurl=m3u
|
||||||
|
audio/x-pn-realaudio=ra
|
||||||
|
audio/x-pn-realaudio=ram
|
||||||
|
audio/x-wav=wav
|
||||||
|
image/bmp=bmp
|
||||||
|
image/cis-cod=cod
|
||||||
|
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-portable-anymap=pnm
|
||||||
|
image/x-portable-bitmap=pbm
|
||||||
|
image/x-portable-graymap=pgm
|
||||||
|
image/x-portable-pixmap=ppm
|
||||||
|
image/x-rgb=rgb
|
||||||
|
image/x-xbitmap=xbm
|
||||||
|
image/x-xpixmap=xpm
|
||||||
|
image/x-xwindowdump=xwd
|
||||||
|
message/rfc822=mht
|
||||||
|
message/rfc822=mhtml
|
||||||
|
message/rfc822=nws
|
||||||
|
text/css=css
|
||||||
|
text/csv=csv
|
||||||
|
application/xml=xml
|
||||||
|
application/xhtml+xml=xhtml
|
||||||
|
text/h323=323
|
||||||
|
text/html=htm
|
||||||
|
text/html=html
|
||||||
|
text/html=stm
|
||||||
|
text/iuls=uls
|
||||||
|
text/plain=bas
|
||||||
|
text/plain=c
|
||||||
|
text/plain=h
|
||||||
|
text/plain=txt
|
||||||
|
text/richtext=rtx
|
||||||
|
text/scriptlet=sct
|
||||||
|
text/tab-separated-values=tsv
|
||||||
|
text/webviewhtml=htt
|
||||||
|
text/x-component=htc
|
||||||
|
text/x-setext=etx
|
||||||
|
text/x-vcard=vcf
|
||||||
|
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
|
|
@ -0,0 +1,177 @@
|
||||||
|
application/envoy =evy
|
||||||
|
application/fractals=fif
|
||||||
|
application/futuresplash=spl
|
||||||
|
application/hta=hta
|
||||||
|
application/internet-property-stream=acx
|
||||||
|
application/mac-binhex40=hqx
|
||||||
|
application/msword=doc
|
||||||
|
application/octet-stream=bin
|
||||||
|
application/oda=oda
|
||||||
|
application/olescript=axs
|
||||||
|
application/pdf=pdf
|
||||||
|
application/pics-rules=prf
|
||||||
|
application/pkcs10=p10
|
||||||
|
application/pkix-crl=crl
|
||||||
|
application/postscript=ps
|
||||||
|
application/rtf=rtf
|
||||||
|
application/set-payment-initiation=setpay
|
||||||
|
application/set-registration-initiation=setreg
|
||||||
|
application/vnd.ms-excel=xls
|
||||||
|
application/vnd.ms-outlook=msg
|
||||||
|
application/vnd.ms-pkicertstore=sst
|
||||||
|
application/vnd.ms-pkiseccat=cat
|
||||||
|
application/vnd.ms-pkistl=stl
|
||||||
|
application/vnd.ms-powerpoint=ppt
|
||||||
|
application/vnd.ms-project=mpp
|
||||||
|
application/vnd.ms-works=wcm
|
||||||
|
application/vnd.ms-works=wdb
|
||||||
|
application/vnd.ms-works=wks
|
||||||
|
application/vnd.ms-works=wps
|
||||||
|
application/vnd.openxmlformats-officedocument.wordprocessingml.document=docx
|
||||||
|
application/winhlp=hlp
|
||||||
|
application/x-bcpio=bcpio
|
||||||
|
application/x-cdf=cdf
|
||||||
|
application/x-compress=z
|
||||||
|
application/x-compressed=tgz
|
||||||
|
application/x-cpio=cpio
|
||||||
|
application/x-csh=csh
|
||||||
|
application/x-director=dcr
|
||||||
|
application/x-director=dir
|
||||||
|
application/x-director=dxr
|
||||||
|
application/x-dvi=dvi
|
||||||
|
application/x-gtar=gtar
|
||||||
|
application/x-gzip=gz
|
||||||
|
application/x-hdf=hdf
|
||||||
|
application/x-internet-signup=ins
|
||||||
|
application/x-internet-signup=isp
|
||||||
|
application/x-iphone=iii
|
||||||
|
application/x-javascript=js
|
||||||
|
application/x-latex=latex
|
||||||
|
application/x-msaccess=mdb
|
||||||
|
application/x-mscardfile=crd
|
||||||
|
application/x-msclip=clp
|
||||||
|
application/x-msdownload=dll
|
||||||
|
application/x-msmediaview=m13
|
||||||
|
application/x-msmediaview=m14
|
||||||
|
application/x-msmediaview=mvb
|
||||||
|
application/x-msmetafile=wmf
|
||||||
|
application/x-msmoney=mny
|
||||||
|
application/x-mspublisher=pub
|
||||||
|
application/x-msschedule=scd
|
||||||
|
application/x-msterminal=trm
|
||||||
|
application/x-mswrite=wri
|
||||||
|
application/x-netcdf=cdf
|
||||||
|
application/x-netcdf=nc
|
||||||
|
application/x-perfmon=pma
|
||||||
|
application/x-perfmon=pmc
|
||||||
|
application/x-perfmon=pml
|
||||||
|
application/x-perfmon=pmr
|
||||||
|
application/x-perfmon=pmw
|
||||||
|
application/x-pkcs12=p12
|
||||||
|
application/x-pkcs12=pfx
|
||||||
|
application/x-pkcs7-certificates=p7b
|
||||||
|
application/x-pkcs7-certificates=spc
|
||||||
|
application/x-pkcs7-certreqresp=p7r
|
||||||
|
application/x-pkcs7-mime=p7c
|
||||||
|
application/x-pkcs7-mime=p7m
|
||||||
|
application/x-pkcs7-signature=p7s
|
||||||
|
application/x-sh=sh
|
||||||
|
application/x-shar=shar
|
||||||
|
application/x-shockwave-flash=swf
|
||||||
|
application/x-stuffit=sit
|
||||||
|
application/x-sv4cpio=sv4cpio
|
||||||
|
application/x-sv4crc=sv4crc
|
||||||
|
application/x-tar=tar
|
||||||
|
application/x-tcl=tcl
|
||||||
|
application/x-tex=tex
|
||||||
|
application/x-texinfo=texi
|
||||||
|
application/x-texinfo=texinfo
|
||||||
|
application/x-troff=roff
|
||||||
|
application/x-troff=t
|
||||||
|
application/x-troff=tr
|
||||||
|
application/x-troff-man=man
|
||||||
|
application/x-troff-me=me
|
||||||
|
application/x-troff-ms=ms
|
||||||
|
application/x-ustar=ustar
|
||||||
|
application/x-wais-source=src
|
||||||
|
application/x-x509-ca-cert=cer
|
||||||
|
application/x-x509-ca-cert=crt
|
||||||
|
application/x-x509-ca-cert=der
|
||||||
|
application/ynd.ms-pkipko=pko
|
||||||
|
application/zip=zip
|
||||||
|
audio/basic=au
|
||||||
|
audio/basic=snd
|
||||||
|
audio/mid=mid
|
||||||
|
audio/mid=rmi
|
||||||
|
audio/mpeg=mp3
|
||||||
|
audio/x-aiff=aif
|
||||||
|
audio/x-aiff=aifc
|
||||||
|
audio/x-aiff=aiff
|
||||||
|
audio/x-mpegurl=m3u
|
||||||
|
audio/x-pn-realaudio=ra
|
||||||
|
audio/x-pn-realaudio=ram
|
||||||
|
audio/x-wav=wav
|
||||||
|
image/bmp=bmp
|
||||||
|
image/cis-cod=cod
|
||||||
|
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-portable-anymap=pnm
|
||||||
|
image/x-portable-bitmap=pbm
|
||||||
|
image/x-portable-graymap=pgm
|
||||||
|
image/x-portable-pixmap=ppm
|
||||||
|
image/x-rgb=rgb
|
||||||
|
image/x-xbitmap=xbm
|
||||||
|
image/x-xpixmap=xpm
|
||||||
|
image/x-xwindowdump=xwd
|
||||||
|
message/rfc822=mht
|
||||||
|
message/rfc822=mhtml
|
||||||
|
message/rfc822=nws
|
||||||
|
text/css=css
|
||||||
|
text/csv=csv
|
||||||
|
text/h323=323
|
||||||
|
text/html=htm
|
||||||
|
text/html=stm
|
||||||
|
text/html=html
|
||||||
|
text/iuls=uls
|
||||||
|
text/plain=bas
|
||||||
|
text/plain=c
|
||||||
|
text/plain=h
|
||||||
|
text/plain=txt
|
||||||
|
text/richtext=rtx
|
||||||
|
text/scriptlet=sct
|
||||||
|
text/tab-separated-values=tsv
|
||||||
|
text/webviewhtml=htt
|
||||||
|
text/x-component=htc
|
||||||
|
text/x-setext=etx
|
||||||
|
text/x-vcard=vcf
|
||||||
|
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
|
|
@ -0,0 +1,47 @@
|
||||||
|
package org.gcube.portlets.user.workspace;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.workspace.server.util.MimeTypeUtility;
|
||||||
|
|
||||||
|
public class MimeTypeUtilityTest {
|
||||||
|
|
||||||
|
static Map<String, String> fileNamesToMimeTypes = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
|
||||||
|
fileNamesToMimeTypes.put("An html page of D4science.html", "text/html");
|
||||||
|
fileNamesToMimeTypes.put("No Extension File of kind CSV", "text/csv");
|
||||||
|
fileNamesToMimeTypes.put("No Extension File of kind PDF", "application/pdf");
|
||||||
|
fileNamesToMimeTypes.put("An .o extension file", "text/html");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Map<String, List<String>> mimetype_extension_map = MimeTypeUtility.getMimeTypeToExtensionMap();
|
||||||
|
|
||||||
|
System.out.println("Mime types: ");
|
||||||
|
for (String mimeType : mimetype_extension_map.keySet()) {
|
||||||
|
System.out.println(mimeType + " -> " + mimetype_extension_map.get(mimeType));
|
||||||
|
}
|
||||||
|
|
||||||
|
String mimeType = "text/html";
|
||||||
|
System.out.println("\n\nGet " + mimeType + " returing list of exstensions: " + mimetype_extension_map.get(mimeType));
|
||||||
|
|
||||||
|
|
||||||
|
for (String keyFileName : fileNamesToMimeTypes.keySet()) {
|
||||||
|
try {
|
||||||
|
System.out.println("\nResolving file name with extension for name: "+keyFileName);
|
||||||
|
String toFileName = MimeTypeUtility.getNameWithExtension(keyFileName, fileNamesToMimeTypes.get(keyFileName));
|
||||||
|
System.out.println("Assigned the file name: "+toFileName);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue