Renamed ExtensionToMimeTypeMap to WsExtensionToMimeTypeMap in order to avoid clashing with the files declared into HL

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@181150 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2019-07-08 10:02:45 +00:00
parent d4d0b5b2fc
commit e7613da62e
4 changed files with 15 additions and 7 deletions

View File

@ -33,6 +33,8 @@ import org.apache.tika.mime.MediaType;
*/
public class MimeTypeUtility {
private static final String DOT_STRING = ".";
protected static Logger logger = Logger.getLogger(MimeTypeUtility.class);
/**
@ -47,8 +49,8 @@ public class MimeTypeUtility {
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");
InputStream extensionToMimetype = MimeTypeUtility.class.getResourceAsStream("/WsExtensionToMimeTypeMap.properties");
InputStream mimetypeToExtension = MimeTypeUtility.class.getResourceAsStream("/WsMimeTypeToExtensionMap.properties");
try {
loadExtensions(extensionToMimetype);
loadMimeTypes(mimetypeToExtension);
@ -130,12 +132,18 @@ public class MimeTypeUtility {
*/
public static String getNameWithExtension(String name, String mimeType) throws IOException {
logger.trace("getNameWithExtension name: " + name + " mimeType: " + mimeType);
logger.debug("Deriving the file extension for file name: " + name + ", with mimeType: " + mimeType);
String declaredExtension = FilenameUtils.getExtension(name);
logger.debug("The name "+name+" contains the extension: "+declaredExtension);
if(declaredExtension.isEmpty()) {
declaredExtension = declaredExtension.replace(" ", "");
logger.debug("Purged extension without white space is: "+declaredExtension);
if(declaredExtension.isEmpty() || !(name.endsWith(DOT_STRING+declaredExtension))) {
logger.debug("The extension: "+declaredExtension+", is empty or it is not a valid extension");
if (mimeType == null)
return name;
@ -148,7 +156,7 @@ public class MimeTypeUtility {
}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;
extension = DOT_STRING + extension;
}
logger.trace("returning " + name + extension);

View File

@ -16,7 +16,7 @@ public class MimeTypeUtilityTest {
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");
fileNamesToMimeTypes.put("An .o extension file .take ext", "text/html");
}