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