1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.webapp;
20
21 import java.io.IOException;
22 import java.net.MalformedURLException;
23
24 import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
25 import org.eclipse.jetty.servlet.ServletHandler;
26 import org.eclipse.jetty.util.log.Log;
27 import org.eclipse.jetty.util.log.Logger;
28 import org.eclipse.jetty.util.resource.Resource;
29
30
31
32
33
34
35 public class WebXmlConfiguration extends AbstractConfiguration
36 {
37 private static final Logger LOG = Log.getLogger(WebXmlConfiguration.class);
38
39
40
41
42
43
44 @Override
45 public void preConfigure (WebAppContext context) throws Exception
46 {
47
48 String defaultsDescriptor = context.getDefaultsDescriptor();
49 if (defaultsDescriptor != null && defaultsDescriptor.length() > 0)
50 {
51 Resource dftResource = Resource.newSystemResource(defaultsDescriptor);
52 if (dftResource == null)
53 dftResource = context.newResource(defaultsDescriptor);
54 context.getMetaData().setDefaults (dftResource);
55 }
56
57
58 Resource webxml = findWebXml(context);
59 if (webxml != null)
60 {
61 context.getMetaData().setWebXml(webxml);
62 }
63
64
65 for (String overrideDescriptor : context.getOverrideDescriptors())
66 {
67 if (overrideDescriptor != null && overrideDescriptor.length() > 0)
68 {
69 Resource orideResource = Resource.newSystemResource(overrideDescriptor);
70 if (orideResource == null)
71 orideResource = context.newResource(overrideDescriptor);
72 context.getMetaData().addOverride(orideResource);
73 }
74 }
75 }
76
77
78
79
80
81
82 @Override
83 public void configure (WebAppContext context) throws Exception
84 {
85
86 if (context.isStarted())
87 {
88 LOG.debug("Cannot configure webapp after it is started");
89 return;
90 }
91
92 context.getMetaData().addDescriptorProcessor(new StandardDescriptorProcessor());
93 }
94
95
96 protected Resource findWebXml(WebAppContext context) throws IOException, MalformedURLException
97 {
98 String descriptor = context.getDescriptor();
99 if (descriptor != null)
100 {
101 Resource web = context.newResource(descriptor);
102 if (web.exists() && !web.isDirectory()) return web;
103 }
104
105 Resource web_inf = context.getWebInf();
106 if (web_inf != null && web_inf.isDirectory())
107 {
108
109 Resource web = web_inf.addPath("web.xml");
110 if (web.exists()) return web;
111 if (LOG.isDebugEnabled())
112 LOG.debug("No WEB-INF/web.xml in " + context.getWar() + ". Serving files and default/dynamic servlets only");
113 }
114 return null;
115 }
116
117
118
119 @Override
120 public void deconfigure (WebAppContext context) throws Exception
121 {
122
123
124 ServletHandler _servletHandler = context.getServletHandler();
125
126 _servletHandler.setFilters(null);
127 _servletHandler.setFilterMappings(null);
128 _servletHandler.setServlets(null);
129 _servletHandler.setServletMappings(null);
130
131 context.setEventListeners(null);
132 context.setWelcomeFiles(null);
133
134 if (context.getErrorHandler() instanceof ErrorPageErrorHandler)
135 ((ErrorPageErrorHandler)
136 context.getErrorHandler()).setErrorPages(null);
137
138
139
140
141 }
142 }