This is an automated email from the ASF dual-hosted git repository.

solomax pushed a commit to branch fileCountMax-9.x
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit ceb2ab10077ed7fac397559058215e61be9bc1af
Author: Maxim Solodovnik <[email protected]>
AuthorDate: Mon Mar 20 16:23:41 2023 +0700

    fileCountMax is added
---
 .../org/apache/wicket/markup/html/form/Form.java   | 24 ++++++++++++++++++++++
 .../http/servlet/MultipartServletWebRequest.java   | 15 ++++++++++++++
 .../servlet/MultipartServletWebRequestImpl.java    |  6 ++++++
 3 files changed, 45 insertions(+)

diff --git 
a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
index edf7a37813..0a079357d9 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
@@ -283,6 +283,11 @@ public class Form<T> extends WebMarkupContainer
         */
        private Bytes fileMaxSize;
 
+       /**
+        * Maximum amount of files in request.
+        */
+       private Long fileCountMax;
+
        /** True if the form has enctype of multipart/form-data */
        private short multiPart = 0;
 
@@ -648,6 +653,15 @@ public class Form<T> extends WebMarkupContainer
                return fileMaxSize;
        }
 
+       /**
+        * Gets maximum count of files in the form
+        * 
+        * @return
+        */
+       public Long getFileCountMax() {
+               return fileCountMax;
+       }
+
        /**
         * Returns the root form or this, if this is the root form.
         * 
@@ -1128,6 +1142,15 @@ public class Form<T> extends WebMarkupContainer
                this.fileMaxSize = fileMaxSize;
        }
 
+       /**
+        * Sets maximum amount of files in upload request.
+        * 
+        * @param fileCountMax
+        */
+       public void setFileCountMax(Long fileCountMax) {
+               this.fileCountMax = fileCountMax;
+       }
+
        /**
         * Set to true to use enctype='multipart/form-data', and to process 
file uploads by default
         * multiPart = false
@@ -1461,6 +1484,7 @@ public class Form<T> extends WebMarkupContainer
                                final MultipartServletWebRequest 
multipartWebRequest = request.newMultipartWebRequest(
                                        getMaxSize(), getPage().getId());
                                
multipartWebRequest.setFileMaxSize(getFileMaxSize());
+                               
multipartWebRequest.setFileCountMax(getFileCountMax());
                                multipartWebRequest.parseFileParts();
 
                                // TODO: Can't this be detected from header?
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequest.java
 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequest.java
index 077cff441f..97fa39154c 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequest.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequest.java
@@ -48,6 +48,11 @@ public abstract class MultipartServletWebRequest extends 
ServletWebRequest
         */
        private Bytes fileMaxSize;
 
+       /**
+        * Maximum amount of files in request.
+        */
+       private Long fileCountMax;
+
        /**
         * Construct.
         * 
@@ -131,4 +136,14 @@ public abstract class MultipartServletWebRequest extends 
ServletWebRequest
        {
                this.fileMaxSize = fileMaxSize;
        }
+
+       public Long getFileCountMax()
+       {
+               return fileCountMax;
+       }
+
+       public void setFileCountMax(Long fileCountMax)
+       {
+               this.fileCountMax = fileCountMax;
+       }
 }
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequestImpl.java
 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequestImpl.java
index d0d5330b70..4b304f7ab9 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequestImpl.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequestImpl.java
@@ -298,6 +298,12 @@ public class MultipartServletWebRequestImpl extends 
MultipartServletWebRequest
                        fileUpload.setFileSizeMax(fileMaxSize.bytes());
                }
 
+               Long fileCountMax = getFileCountMax();
+               if (fileCountMax != null)
+               {
+                       fileUpload.setFileCountMax(fileCountMax);
+               }
+
                return fileUpload;
        }
 

Reply via email to