just updated some comments

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@181152 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2019-07-08 13:54:28 +00:00
parent ccedaa3852
commit 7c9db3a9b0
1 changed files with 42 additions and 33 deletions

View File

@ -45,12 +45,14 @@ public class MimeTypeUtility {
"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, 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("/WsExtensionToMimeTypeMap.properties");
InputStream mimetypeToExtension = MimeTypeUtility.class.getResourceAsStream("/WsMimeTypeToExtensionMap.properties");
InputStream extensionToMimetype = MimeTypeUtility.class
.getResourceAsStream("/WsExtensionToMimeTypeMap.properties");
InputStream mimetypeToExtension = MimeTypeUtility.class
.getResourceAsStream("/WsMimeTypeToExtensionMap.properties");
try {
loadExtensions(extensionToMimetype);
loadMimeTypes(mimetypeToExtension);
@ -100,12 +102,12 @@ public class MimeTypeUtility {
String mimeType = split[0];
String extension = split[1];
List<String> toExtensions = mimetype_extension_map.get(mimeType);
if(toExtensions==null) {
if (toExtensions == null) {
toExtensions = new ArrayList<String>();
}
toExtensions.add(extension);
mimetype_extension_map.put(mimeType, toExtensions);
//mimetype_extension_map.put(mimeType, extension);
// mimetype_extension_map.put(mimeType, extension);
}
line = br.readLine();
}
@ -133,52 +135,60 @@ public class MimeTypeUtility {
public static String getNameWithExtension(String name, String mimeType) throws IOException {
logger.debug("Deriving the file extension for file name: " + name + ", with mimeType: " + mimeType);
if (mimeType == null || mimeType.isEmpty()) {
logger.debug("Input mime type is null or empty returning passed name: "+name);
logger.debug("Input mime type is null or empty returning passed name: " + name);
return name;
}
String declaredExtension = FilenameUtils.getExtension(name);
logger.debug("The name "+name+" contains the extension: "+declaredExtension);
logger.debug("The name " + name + " contains the extension: " + declaredExtension);
if (declaredExtension.equals("exe"))
return name;
List<String> extensions = MimeTypeUtility.getExtension(mimeType);
logger.trace("Extension/s available for input mimetype: "+mimeType+" into map is/are: " + extensions);
logger.trace("Extension/s available for input mimetype: " + mimeType + " into map is/are: " + extensions);
String toMimeTypeExtension = "";
if(extensions!=null) {
toMimeTypeExtension = extensions.get(extensions.size()-1); //I'm reading the last extension in the map (myme type - list of extensions)
if (extensions != null) {
toMimeTypeExtension = 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: " + toMimeTypeExtension);
}
//MANAGING ALREADY DECLARED EXTENSION IN THE FILE NAME
if(!declaredExtension.isEmpty() && !toMimeTypeExtension.isEmpty()) {
// MANAGING ALREADY DECLARED EXTENSION IN THE FILE NAME
if (!declaredExtension.isEmpty() && !toMimeTypeExtension.isEmpty()) {
String dEextL = declaredExtension.toLowerCase();
String mtExtL = toMimeTypeExtension.toLowerCase();
//The extension writes in the file name is matching the mime type extension declared in the map
if(dEextL.equals(mtExtL)) {
logger.trace("The Extension declared in the name "+name+" is matching derived mime type extension so returning the input name: "+name);
// The extension writes in the file name is matching the mime type extension
// declared in the map
if (dEextL.equals(mtExtL)) {
logger.trace("The Extension declared in the name " + name
+ " is matching derived mime type extension so returning the input name: " + name);
return name;
}
// if(!dEextL.trim().contains(" ")) {
// logger.trace("The Extension declared in the name "+name+" seems a valid suffix (without other spaces) so returning the input name: "+name);
// return name;
// }
logger.debug("No logic seems to match the extension declared in the name "+declaredExtension+" as a valid extension so I'm adding the extension derived from mime type map: "+toMimeTypeExtension);
logger.debug("No logic seems to match the extension declared in the name " + declaredExtension
+ " as a valid extension so I'm adding the extension derived from mime type map: "
+ toMimeTypeExtension);
}
//CHECKING THE FOLLOWING IN ORDER TO AVOID THE DOT AS LAST CHAR OF FILENAME
if(toMimeTypeExtension.isEmpty()) {
// CHECKING THE FOLLOWING IN ORDER TO AVOID THE DOT AS LAST CHAR OF FILENAME
if (toMimeTypeExtension.isEmpty()) {
return name;
}
String fullname = String.format("%s%s%s", name, DOT_STRING, toMimeTypeExtension);
logger.trace("returning full name:" +fullname);
logger.trace("returning full name:" + fullname);
return fullname;
}
/**
@ -250,7 +260,7 @@ public class MimeTypeUtility {
return mediaType.getBaseType().toString();
}
/**
* Gets the mime type to extension map.
*
@ -259,8 +269,7 @@ public class MimeTypeUtility {
public static Map<String, List<String>> getMimeTypeToExtensionMap() {
return mimetype_extension_map;
}
/**
* Gets the extension to mime type map.
*