1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers;
12
13 import jakarta.inject.Inject;
14 import jakarta.servlet.http.HttpServletRequest;
15
16 import java.util.Locale;
17
18 import org.apache.tomcat.util.http.fileupload.servlet.ServletRequestContext;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21 import org.springframework.web.servlet.mvc.AbstractController;
22
23 import psiprobe.beans.ContainerWrapperBean;
24
25
26
27
28 public abstract class AbstractTomcatContainerController extends AbstractController {
29
30
31
32 @SuppressWarnings("HidingField")
33 protected final Logger logger = LoggerFactory.getLogger(getClass());
34
35
36 @Inject
37 private ContainerWrapperBean containerWrapper;
38
39
40 private String viewName;
41
42
43 private static final String MULTIPART = "multipart/";
44
45
46 private static final String POST_METHOD = "POST";
47
48
49
50
51
52
53 public ContainerWrapperBean getContainerWrapper() {
54 return containerWrapper;
55 }
56
57
58
59
60
61
62 public void setContainerWrapper(ContainerWrapperBean containerWrapper) {
63 this.containerWrapper = containerWrapper;
64 }
65
66
67
68
69
70
71 public String getViewName() {
72 return viewName;
73 }
74
75
76
77
78
79
80 public void setViewName(String viewName) {
81 this.viewName = viewName;
82 }
83
84
85
86
87
88
89
90
91
92 public boolean isMultipartContent(final HttpServletRequest request) {
93 if (!POST_METHOD.equalsIgnoreCase(request.getMethod())) {
94 return false;
95 }
96 final String contentType = new ServletRequestContext(request).getContentType();
97 if (contentType == null) {
98 return false;
99 }
100 return contentType.toLowerCase(Locale.ENGLISH).startsWith(MULTIPART);
101 }
102
103 }