package jnpf.dmsEntity.preview.enums;
|
|
import java.util.Locale;
|
|
/** Selects watermark handling. IMAGE candidates may still be rejected by the image codec. */
|
public enum DmsWatermarkTargetType {
|
DOCX,
|
PDF,
|
IMAGE,
|
UNSUPPORTED;
|
|
public static DmsWatermarkTargetType fromFileName(String fileName) {
|
return from(fileName, null);
|
}
|
|
public static DmsWatermarkTargetType from(String fileName, String mimeType) {
|
String normalized = fileName == null ? "" : fileName.trim().toLowerCase(Locale.ROOT);
|
int extensionSeparator = normalized.lastIndexOf('.');
|
String extension = extensionSeparator < 0 || extensionSeparator == normalized.length() - 1
|
? "" : normalized.substring(extensionSeparator + 1);
|
if ("docx".equals(extension)) {
|
return DOCX;
|
}
|
if ("pdf".equals(extension)) {
|
return PDF;
|
}
|
switch (extension) {
|
case "bmp":
|
case "gif":
|
case "jpeg":
|
case "jpg":
|
case "png":
|
case "webp":
|
return IMAGE;
|
default:
|
break;
|
}
|
String normalizedMime = mimeType == null ? "" : mimeType.trim().toLowerCase(Locale.ROOT);
|
int parameters = normalizedMime.indexOf(';');
|
if (parameters >= 0) {
|
normalizedMime = normalizedMime.substring(0, parameters).trim();
|
}
|
if ("application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
.equals(normalizedMime)) {
|
return DOCX;
|
}
|
if ("application/pdf".equals(normalizedMime)) {
|
return PDF;
|
}
|
return normalizedMime.startsWith("image/") ? IMAGE : UNSUPPORTED;
|
}
|
}
|