Changed the pom

Updated the logic in the Task #17135

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@181151 82a268e6-3cf1-43bd-a215-b396298e98cf
task/19600
Francesco Mangiacrapa 5 years ago
parent e7613da62e
commit ccedaa3852

@ -333,6 +333,12 @@
<include>**/*.*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>

@ -134,37 +134,51 @@ public class MimeTypeUtility {
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);
return name;
}
String declaredExtension = FilenameUtils.getExtension(name);
logger.debug("The name "+name+" contains the extension: "+declaredExtension);
declaredExtension = declaredExtension.replace(" ", "");
logger.debug("Purged extension without white space is: "+declaredExtension);
List<String> extensions = MimeTypeUtility.getExtension(mimeType);
logger.trace("Extension/s available for input mimetype: "+mimeType+" into map is/are: " + extensions);
if(declaredExtension.isEmpty() || !(name.endsWith(DOT_STRING+declaredExtension))) {
logger.debug("The extension: "+declaredExtension+", is empty or it is not a valid extension");
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)
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()) {
String dEextL = declaredExtension.toLowerCase();
String mtExtL = toMimeTypeExtension.toLowerCase();
if (mimeType == null)
//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;
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 = DOT_STRING + extension;
}
logger.trace("returning " + name + extension);
return name + extension;
}else {
logger.trace("extension already declared in the name "+name+", returning name like is it");
// 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);
}
//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);
return fullname;
}
/**

@ -33,6 +33,7 @@ application/x-bcpio=bcpio
application/x-cdf=cdf
application/x-compress=z
application/x-compressed=tgz
application/x-compressed-tar=tar.gz
application/x-cpio=cpio
application/x-csh=csh
application/x-director=dcr
@ -46,6 +47,7 @@ application/x-internet-signup=ins
application/x-internet-signup=isp
application/x-iphone=iii
application/x-javascript=js
application/json=json
application/x-latex=latex
application/x-msaccess=mdb
application/x-mscardfile=crd
@ -86,6 +88,7 @@ application/x-tcl=tcl
application/x-tex=tex
application/x-texinfo=texi
application/x-texinfo=texinfo
application/x-tika-java-web-archive=war
application/x-troff=roff
application/x-troff=t
application/x-troff=tr

@ -17,6 +17,8 @@ public class MimeTypeUtilityTest {
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 .take ext", "text/html");
fileNamesToMimeTypes.put("workspace-6.19.1-4.12.1-169702", "application/x-tika-java-web-archive");
fileNamesToMimeTypes.put("workspace.o", "application/json");
}

Loading…
Cancel
Save