This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch maintenance-branch
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/maintenance-branch by this
push:
new 51f9ef0c18d CAUSEWAY-3950: [v2] allows specific mime types to be
excluded from file upload preview (backport from v4)
51f9ef0c18d is described below
commit 51f9ef0c18d8b0b57d335bcd37090da51d08ae0b
Author: andi-huber <[email protected]>
AuthorDate: Sun Jan 18 19:57:51 2026 +0100
CAUSEWAY-3950: [v2] allows specific mime types to be excluded from file
upload preview (backport from v4)
---
.../core/config/CausewayConfiguration.java | 24 +++++++++++++
.../blobclob/CausewayBlobOrClobPanelAbstract.java | 2 +-
.../apache/causeway/viewer/wicket/ui/util/Wkt.java | 41 +++++++++++++++++-----
3 files changed, 57 insertions(+), 10 deletions(-)
diff --git
a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
index 4b6e86e4e73..123056dcc64 100644
---
a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
+++
b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
@@ -3355,6 +3355,30 @@ public static class DevelopmentUtilities {
private boolean enable = false;
}
+ private final FileUpload fileUpload = new FileUpload();
+ @Data
+ public static class FileUpload {
+ /**
+ * If left empty, the default allows ['image', 'html', 'text',
'video', 'audio', 'flash', 'object'],
+ * where 'object' enables fallback behavior. We remove this
here.
+ *
+ * @see
https://plugins.krajee.com/file-input/plugin-options#disabledPreviewTypes
+ */
+ private List<String> disabledPreviewTypes = List.of("object");
+ /**
+ * Some mime types can trigger unwanted download behavior,
dependent on browser and or OS settings.
+ *
+ * <p>We have seen CSV files causing issues, so we disallow
those by default.
+ *
+ * @see
https://plugins.krajee.com/file-input/plugin-options#disabledPreviewMimeTypes
+ */
+ private List<String> disabledPreviewMimeTypes =
List.of("object");
+ /**
+ * If <code>false</code> disables the file upload preview frame
entirely.
+ */
+ private boolean showPreview = true;
+ }
+
private final RememberMe rememberMe = new RememberMe();
@Data
public static class RememberMe {
diff --git
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/scalars/blobclob/CausewayBlobOrClobPanelAbstract.java
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/scalars/blobclob/CausewayBlobOrClobPanelAbstract.java
index d55563aa7f8..4feb9b8544b 100644
---
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/scalars/blobclob/CausewayBlobOrClobPanelAbstract.java
+++
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/scalars/blobclob/CausewayBlobOrClobPanelAbstract.java
@@ -71,7 +71,7 @@ protected Optional<InputFragment> getInputFragmentType() {
@Override
protected FormComponent createFormComponent(final String id, final
ScalarModel scalarModel) {
val initialCaption = outputFormatAsString();
- val fileUploadField = Wkt.fileUploadField(id, initialCaption,
fileUploadModel());
+ val fileUploadField = Wkt.fileUploadField(id, initialCaption,
getWicketViewerSettings(), fileUploadModel());
addAcceptFilterTo(fileUploadField);
return fileUploadField;
}
diff --git
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/util/Wkt.java
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/util/Wkt.java
index f980b40189a..f995977f2b2 100644
---
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/util/Wkt.java
+++
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/util/Wkt.java
@@ -131,6 +131,7 @@
import
de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkboxx.CheckBoxXConfig;
import
de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkboxx.CheckBoxXConfig.Sizes;
import
de.agilecoders.wicket.extensions.markup.html.bootstrap.form.fileinput.FileInputConfig;
+import de.agilecoders.wicket.jquery.IKey;
import de.agilecoders.wicket.jquery.Key;
/**
@@ -678,21 +679,43 @@ private FileResourceStream fileResourceStream(final File
file, final CommonMimeT
public FileUploadField fileUploadField(
final String id,
final String initialCaption,
+ final Wicket settings,
final IModel<List<FileUpload>> model) {
val fileUploadField = new FileUploadFieldWithNestingFix(
id,
model,
- new FileInputConfig()
- .maxFileCount(1)
- .mainClass("input-group-sm")
- .initialCaption(initialCaption)
- .captionClass("form-control-sm")
- .showUpload(false)
- //[CAUSEWAY-3950] preview may trigger unwanted downloads
of the file that just got uploaded
- // we were seeing this with Chrome browser and files of
type CSV
- .showPreview(false));
+ createFileInputConfig(initialCaption,
settings.getFileUpload()));
return fileUploadField;
}
+
+ /**
+ * @see https://plugins.krajee.com/file-input/plugin-options
+ */
+ static final class FileInputConfigWithPreviewControl extends
FileInputConfig {
+ private static final long serialVersionUID = 1L;
+ static final IKey<List<String>> DisabledPreviewTypes =
newKey("disabledPreviewTypes", null);
+ static final IKey<List<String>> DisabledPreviewMimeTypes =
newKey("disabledPreviewMimeTypes", null);
+ public FileInputConfigWithPreviewControl
disabledPreviewTypes(List<String> disabledPreviewTypes) {
+ put(DisabledPreviewTypes, disabledPreviewTypes);
+ return this;
+ }
+ public FileInputConfigWithPreviewControl
disabledPreviewMimeTypes(List<String> disabledPreviewMimeTypes) {
+ put(DisabledPreviewMimeTypes, disabledPreviewMimeTypes);
+ return this;
+ }
+ }
+
+ private FileInputConfig createFileInputConfig(final String initialCaption,
final Wicket.FileUpload fileUploadSettings) {
+ return new FileInputConfigWithPreviewControl()
+
.disabledPreviewTypes(fileUploadSettings.getDisabledPreviewTypes())
+
.disabledPreviewMimeTypes(fileUploadSettings.getDisabledPreviewMimeTypes())
+ .maxFileCount(1)
+ .mainClass("input-group-sm")
+ .initialCaption(initialCaption)
+ .captionClass("form-control-sm")
+ .showUpload(false)
+ .showPreview(fileUploadSettings.isShowPreview());
+ }
// -- FONT AWESOME