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 public class WebXmlConditionsUtil {
47 private final WebXmlUtil webXmlUtil;
48 private final List<Condition> conditions;
49
50 public WebXmlConditionsUtil(List<Condition> conditions) {
51 this(new WebXmlUtil(), conditions);
52 }
53
54 WebXmlConditionsUtil(WebXmlUtil webXmlUtil, List<Condition> conditions) {
55 this.webXmlUtil = webXmlUtil;
56 this.conditions = conditions;
57 }
58
59 public void servletIsNowWrapped(final String servletName) {
60 if (webXmlUtil.isServletOrMappingRegistered(servletName)) {
61 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."));
62 }
63 }
64
65 public void servletIsDeprecated(final String servletName) {
66 if (webXmlUtil.isServletOrMappingRegistered(servletName)) {
67 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."));
68 }
69 }
70
71 public void servletIsRemoved(final String servletName) {
72 if (webXmlUtil.isServletOrMappingRegistered(servletName)) {
73 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."));
74 }
75 }
76
77 public void servletIsPresent(String servletName) {
78 if (!webXmlUtil.isServletRegistered(servletName)) {
79 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."));
80 }
81 }
82
83 public void filterMustBeRegisteredWithCorrectDispatchers(final String filterClass) {
84 final String conditionName = "web.xml updates";
85 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.";
86 final String additionalMessage = " Please add \n"
87 + " <dispatcher>REQUEST</dispatcher>\n"
88 + " <dispatcher>FORWARD</dispatcher>\n"
89 + " <dispatcher>INCLUDE</dispatcher>\n"
90 + " <dispatcher>ERROR</dispatcher>\n"
91 + " to the filter-mapping element in your web.xml file.";
92
93 if (!webXmlUtil.isFilterRegistered(filterClass)) {
94 conditions.add(new FalseCondition(conditionName, message));
95 } else {
96 final int result = webXmlUtil.checkFilterDispatchersConfiguration(filterClass, Arrays.asList("REQUEST", "FORWARD", "INCLUDE"), Collections.singletonList("ERROR"));
97 if (result > 0) {
98 conditions.add(new TrueCondition(conditionName, message));
99 } else if (result == 0) {
100 conditions.add(new WarnCondition(conditionName, message));
101 } else if (result < 0) {
102 conditions.add(new FalseCondition(conditionName, message + additionalMessage));
103 }
104 }
105 }
106
107 public void filterIsDeprecated(final String deprecatedFilterClass, final String replacementFilterClass) {
108 if (webXmlUtil.isFilterRegistered(deprecatedFilterClass)) {
109 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."));
110 }
111 }
112
113 public void listenerIsDeprecated(final String deprecatedListenerClass, final String replacementListenerClass) {
114 if (webXmlUtil.isListenerRegistered(deprecatedListenerClass)) {
115 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."));
116 }
117 }
118
119 public void listenerMustBeRegistered(String listenerClass) {
120 if (!webXmlUtil.isListenerRegistered(listenerClass)) {
121 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."));
122 }
123 }
124 }