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 4.4, the main Magnolia filter is " + filterClass + ", and it must be mapped with dispatchers REQUEST, FORWARD, INCLUDE and, optionally, ERROR.";
89 final String additionalMessage = " Please add \n"
90 + " <dispatcher>REQUEST</dispatcher>\n"
91 + " <dispatcher>FORWARD</dispatcher>\n"
92 + " <dispatcher>INCLUDE</dispatcher>\n"
93 + " <dispatcher>ERROR</dispatcher>\n"
94 + " to the filter-mapping element in your web.xml file.";
95
96 if (!webXmlUtil.isFilterRegistered(filterClass)) {
97 conditions.add(new FalseCondition(conditionName, message));
98 } else {
99 final int result = webXmlUtil.checkFilterDispatchersConfiguration(filterClass, Arrays.asList("REQUEST", "FORWARD", "INCLUDE"), Collections.singletonList("ERROR"));
100 if (result > 0) {
101 conditions.add(new TrueCondition(conditionName, message));
102 } else if (result == 0) {
103 conditions.add(new WarnCondition(conditionName, message));
104 } else if (result < 0) {
105 conditions.add(new FalseCondition(conditionName, message + additionalMessage));
106 }
107 }
108 }
109
110 public void filterIsDeprecated(final String deprecatedFilterClass, final String replacementFilterClass) {
111 if (webXmlUtil.isFilterRegistered(deprecatedFilterClass)) {
112 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."));
113 }
114 }
115
116 public void listenerIsDeprecated(final String deprecatedListenerClass, final String replacementListenerClass) {
117 if (webXmlUtil.isListenerRegistered(deprecatedListenerClass)) {
118 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."));
119 }
120 }
121
122 public void listenerMustBeRegistered(String listenerClass) {
123 if (!webXmlUtil.isListenerRegistered(listenerClass)) {
124 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."));
125 }
126 }
127 }