|
|
|
@ -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
|
|
|
|
|
*/
|
|
|
|
|