Bug fixing issues #23676, #23789

Feature/26521
Francesco Mangiacrapa 2 years ago
parent 506d129cbc
commit 040b2c3817

@ -4,6 +4,13 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v6.35.2-SNAPSHOT] - 2022-07-27
#### Bug fixed
- [#23676] Fixed - Added extension .txt to ASC files when dowloaded
- [#23789] Fixed - Notebook files (.ipynb) are downloaded with .txt attached.
## [v6.35.1] - 2022-06-27
- [#23523] Updated to maven-portal-bom 3.6.4

@ -11,7 +11,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>workspace-tree-widget</artifactId>
<version>6.35.1</version>
<version>6.35.2-SNAPSHOT</version>
<name>gCube Workspace Tree Widget</name>
<description>
gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace
@ -46,7 +46,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.6.4</version>
<version>3.7.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>

@ -22,7 +22,6 @@ import org.apache.tika.mime.MediaType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/**
* The Class MimeTypeUtil.
@ -120,7 +119,6 @@ public class MimeTypeUtility {
}
br.close();
}
/**
* Load preview mime types.
@ -169,7 +167,6 @@ public class MimeTypeUtility {
* @throws IOException Signals that an I/O exception has occurred.
*/
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()) {
@ -178,52 +175,29 @@ public class MimeTypeUtility {
}
String declaredExtension = FilenameUtils.getExtension(name);
logger.debug("The name " + name + " contains the extension: " + declaredExtension);
logger.info("The name " + name + " contains the extension: " + declaredExtension);
if (declaredExtension.equals("exe"))
if (declaredExtension != null && !declaredExtension.isEmpty()) {
logger.debug(
"The name contains a not empty extension: " + declaredExtension + ", so returning the name like it is");
return name;
}
logger.debug("The name does not contains the extension, deriving it from mimeType");
List<String> extensions = MimeTypeUtility.getExtension(mimeType);
logger.trace("Extension/s available for input mimetype: " + mimeType + " into map is/are: " + extensions);
logger.debug("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)
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();
// 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);
String fullName = name;
if (extensions != null && extensions.size() > 0) {
// I'm reading the last extension in the map (myme type - list of extensions)
toMimeTypeExtension = extensions.get(extensions.size() - 1);
logger.info("Using the last extension read into list of available extensions: " + toMimeTypeExtension);
fullName = String.format("%s%s%s", name, DOT_STRING, 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;
logger.info("returning full name:" + fullName);
return fullName;
}
@ -314,11 +288,10 @@ public class MimeTypeUtility {
public static Map<String, String> getExtensionToMimeTypeMap() {
return extension_mimetype_map;
}
/**
* Gets the preview mimetype extension map with the
* mime types allowed for preview displaying
* Gets the preview mimetype extension map with the mime types allowed for
* preview displaying
*
* @return the preview mimetype extension map
*/

@ -181,6 +181,7 @@ text/iuls=uls
text/plain=bas
text/plain=c
text/plain=h
text/plain=asc
text/plain=txt
text/richtext=rtx
text/scriptlet=sct

@ -149,6 +149,7 @@ text/iuls=uls
text/plain=bas
text/plain=c
text/plain=h
text/plain=asc
text/plain=txt
text/richtext=rtx
text/scriptlet=sct

Loading…
Cancel
Save