1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.delta;
35
36 import info.magnolia.cms.util.WebXmlUtil;
37
38 import java.util.Arrays;
39 import java.util.Collections;
40 import java.util.List;
41
42
43
44
45
46
47
48
49 public class WebXmlConditionsUtil {
50 private final WebXmlUtil webXmlUtil;
51 private final List<Condition> conditions;
52
53 public WebXmlConditionsUtil(List<Condition> conditions) {
54 this(new WebXmlUtil(), conditions);
55 }
56
57 WebXmlConditionsUtil(WebXmlUtil webXmlUtil, List<Condition> conditions) {
58 this.webXmlUtil = webXmlUtil;
59 this.conditions = conditions;
60 }
61
62 public void servletIsNowWrapped(final String servletName) {
63 if (webXmlUtil.isServletOrMappingRegistered(servletName)) {
64 conditions.add(new FalseCondition("web.xml updates", "Since Magnolia 3.5, servlets are wrapped in ServletDispatchingFilter; please remove the <servlet> and <servlet-mapping> elements for " + servletName + " from your web.xml file."));
65 }
66 }
67
68 public void servletIsDeprecated(final String servletName) {
69 if (webXmlUtil.isServletOrMappingRegistered(servletName)) {
70 conditions.add(new FalseCondition("web.xml updates", "The " + servletName + " servlet is deprecated and not in use; please remove the corresponding <servlet> and <servlet-mapping> elements from your web.xml file."));
71 }
72 }
73
74 public void servletIsRemoved(final String servletName) {
75 if (webXmlUtil.isServletOrMappingRegistered(servletName)) {
76 conditions.add(new FalseCondition("web.xml updates", "The " + servletName + " servlet does not exist anymore; please remove the corresponding <servlet> and <servlet-mapping> elements from your web.xml file."));
77 }
78 }
79
80 public void servletIsPresent(String servletName) {
81 if (!webXmlUtil.isServletRegistered(servletName)) {
82 conditions.add(new FalseCondition("web.xml updates", "The " + servletName + " servlet is not installed. Please configure a <servlet> and an appropriate mapping with name " + servletName + " in your web.xml file."));
83 }
84 }
85
86 public void filterMustBeRegisteredWithCorrectDispatchers(final String filterClass) {
87 final String conditionName = "web.xml updates";
88 final String message = "Since Magnolia 3.5, the main Magnolia filter is " + filterClass + ", and it must be mapped with dispatchers REQUEST, FORWARD and, optionally, ERROR. The INCLUDE dispatcher is not supported.";
89 final String additionalMessage = " Please add \n"
90 + " <dispatcher>REQUEST</dispatcher>\n"
91 + " <dispatcher>FORWARD</dispatcher>\n"
92 + " <dispatcher>ERROR</dispatcher>\n"
93 + " to the filter-mapping element in your web.xml file.";
94
95 if (!webXmlUtil.isFilterRegistered(filterClass)) {
96 conditions.add(new FalseCondition(conditionName, message));
97 } else {
98 final int result = webXmlUtil.checkFilterDispatchersConfiguration(filterClass, Arrays.asList(new String[]{"REQUEST", "FORWARD"}), Collections.singletonList("ERROR"));
99 if (result > 0) {
100 conditions.add(new TrueCondition(conditionName, message));
101 } else if (result == 0) {
102 conditions.add(new WarnCondition(conditionName, message));
103 } else if (result < 0) {
104 conditions.add(new FalseCondition(conditionName + additionalMessage, message));
105 }
106 }
107 }
108
109 public void filterIsDeprecated(final String deprecatedFilterClass, final String replacementFilterClass) {
110 if (webXmlUtil.isFilterRegistered(deprecatedFilterClass)) {
111 conditions.add(new FalseCondition("web.xml updates", "The " + deprecatedFilterClass + " filter class is now deprecated. Please replace it with " + replacementFilterClass + ": please update the corresponding <filter-class> element in your web.xml file."));
112 }
113 }
114
115 public void listenerIsDeprecated(final String deprecatedListenerClass, final String replacementListenerClass) {
116 if (webXmlUtil.isListenerRegistered(deprecatedListenerClass)) {
117 conditions.add(new FalseCondition("web.xml updates", "The " + deprecatedListenerClass + " listener class is now deprecated. Please replace it with " + replacementListenerClass + ": please update the corresponding <listener> element in your web.xml file."));
118 }
119 }
120
121 public void listenerMustBeRegistered(String listenerClass) {
122 if (!webXmlUtil.isListenerRegistered(listenerClass)) {
123 conditions.add(new FalseCondition("web.xml updates", "The " + listenerClass + " listener is not installed. Please configure a <listener> with class " + listenerClass + " in your web.xml file."));
124 }
125 }
126 }