1 /*
2  * Copyright (c) 2017, 2018 Oracle and/or its affiliates and others.
3  * All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v. 2.0, which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * This Source Code may also be made available under the following Secondary
10  * Licenses when the conditions for such availability set forth in the
11  * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
12  * version 2 with the GNU Classpath Exception, which is available at
13  * https://www.gnu.org/software/classpath/license.html.
14  *
15  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16  */

17
18 package javax.servlet;
19
20 import javax.servlet.annotation.MultipartConfig;
21
22 /**
23  * Java Class represntation of an {@link MultipartConfig} annotation value.
24  *
25  * @since Servlet 3.0
26  */

27 public class MultipartConfigElement {
28
29     private String location;
30     private long maxFileSize;
31     private long maxRequestSize;
32     private int fileSizeThreshold;
33
34     /**
35      * Constructs an instance with defaults for all but location.
36      *
37      * @param location defualts to "" if values is null.
38      */

39     public MultipartConfigElement(String location) {
40         if (location == null) {
41             this.location = "";
42         } else {
43             this.location = location;
44         }
45         this.maxFileSize = -1L;
46         this.maxRequestSize = -1L;
47         this.fileSizeThreshold = 0;
48     }
49
50     /**
51      * Constructs an instance with all values specified.
52      *
53      * @param location          the directory location where files will be stored
54      * @param maxFileSize       the maximum size allowed for uploaded files
55      * @param maxRequestSize    the maximum size allowed for multipart/form-data requests
56      * @param fileSizeThreshold the size threshold after which files will be written to disk
57      */

58     public MultipartConfigElement(String location, long maxFileSize, long maxRequestSize, int fileSizeThreshold) {
59         if (location == null) {
60             this.location = "";
61         } else {
62             this.location = location;
63         }
64         this.maxFileSize = maxFileSize;
65         this.maxRequestSize = maxRequestSize;
66         this.fileSizeThreshold = fileSizeThreshold;
67     }
68
69     /**
70      * Constructs an instance from a {@link MultipartConfig} annotation value.
71      *
72      * @param annotation the annotation value
73      */

74     public MultipartConfigElement(MultipartConfig annotation) {
75         this.location = annotation.location();
76         this.fileSizeThreshold = annotation.fileSizeThreshold();
77         this.maxFileSize = annotation.maxFileSize();
78         this.maxRequestSize = annotation.maxRequestSize();
79     }
80
81     /**
82      * Gets the directory location where files will be stored.
83      *
84      * @return the directory location where files will be stored
85      */

86     public String getLocation() {
87         return this.location;
88     }
89
90     /**
91      * Gets the maximum size allowed for uploaded files.
92      *
93      * @return the maximum size allowed for uploaded files
94      */

95     public long getMaxFileSize() {
96         return this.maxFileSize;
97     }
98
99     /**
100      * Gets the maximum size allowed for multipart/form-data requests.
101      *
102      * @return the maximum size allowed for multipart/form-data requests
103      */

104     public long getMaxRequestSize() {
105         return this.maxRequestSize;
106     }
107
108     /**
109      * Gets the size threshold after which files will be written to disk.
110      *
111      * @return the size threshold after which files will be written to disk
112      */

113     public int getFileSizeThreshold() {
114         return this.fileSizeThreshold;
115     }
116 }
117