1 package org.eclipse.jetty.deploy.bindings;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import java.net.URL;
19
20 import org.eclipse.jetty.deploy.App;
21 import org.eclipse.jetty.deploy.AppLifeCycle;
22 import org.eclipse.jetty.deploy.graph.Node;
23 import org.eclipse.jetty.server.handler.ContextHandler;
24 import org.eclipse.jetty.util.log.Log;
25 import org.eclipse.jetty.util.log.Logger;
26 import org.eclipse.jetty.util.resource.FileResource;
27 import org.eclipse.jetty.util.resource.Resource;
28 import org.eclipse.jetty.webapp.WebAppContext;
29 import org.eclipse.jetty.xml.XmlConfiguration;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 public class GlobalWebappConfigBinding implements AppLifeCycle.Binding
46 {
47 private static final Logger LOG = Log.getLogger(GlobalWebappConfigBinding.class);
48
49
50 private String _jettyXml;
51
52 public String getJettyXml()
53 {
54 return _jettyXml;
55 }
56
57 public void setJettyXml(String jettyXml)
58 {
59 this._jettyXml = jettyXml;
60 }
61
62 public String[] getBindingTargets()
63 {
64 return new String[] { "deploying" };
65 }
66
67 public void processBinding(Node node, App app) throws Exception
68 {
69 ContextHandler handler = app.getContextHandler();
70 if (handler == null)
71 {
72 throw new NullPointerException("No Handler created for App: " + app);
73 }
74
75 if (handler instanceof WebAppContext)
76 {
77 WebAppContext context = (WebAppContext)handler;
78
79 if (LOG.isDebugEnabled())
80 {
81 LOG.debug("Binding: Configuring webapp context with global settings from: " + _jettyXml);
82 }
83
84 if ( _jettyXml == null )
85 {
86 LOG.warn("Binding: global context binding is enabled but no jetty-web.xml file has been registered");
87 }
88
89 Resource globalContextSettings = Resource.newResource(_jettyXml);
90
91 if (globalContextSettings.exists())
92 {
93 XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings.getInputStream());
94
95 jettyXmlConfig.configure(context);
96 }
97 else
98 {
99 LOG.info("Binding: Unable to locate global webapp context settings: " + _jettyXml);
100 }
101 }
102 }
103
104 }