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.resource.FileResource;
26 import org.eclipse.jetty.util.resource.Resource;
27 import org.eclipse.jetty.webapp.WebAppContext;
28 import org.eclipse.jetty.xml.XmlConfiguration;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 public class GlobalWebappConfigBinding implements AppLifeCycle.Binding
45 {
46
47 private String _jettyXml;
48
49 public String getJettyXml()
50 {
51 return _jettyXml;
52 }
53
54 public void setJettyXml(String jettyXml)
55 {
56 this._jettyXml = jettyXml;
57 }
58
59 public String[] getBindingTargets()
60 {
61 return new String[] { "deploying" };
62 }
63
64 public void processBinding(Node node, App app) throws Exception
65 {
66 ContextHandler handler = app.getContextHandler();
67 if (handler == null)
68 {
69 throw new NullPointerException("No Handler created for App: " + app);
70 }
71
72 if (handler instanceof WebAppContext)
73 {
74 WebAppContext context = (WebAppContext)handler;
75
76 if (Log.isDebugEnabled())
77 {
78 Log.debug("Binding: Configuring webapp context with global settings from: " + _jettyXml);
79 }
80
81 if ( _jettyXml == null )
82 {
83 Log.warn("Binding: global context binding is enabled but no jetty-web.xml file has been registered");
84 }
85
86 Resource globalContextSettings = Resource.newResource(_jettyXml);
87
88 if (globalContextSettings.exists())
89 {
90 XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings.getInputStream());
91
92 jettyXmlConfig.configure(context);
93 }
94 else
95 {
96 Log.info("Binding: Unable to locate global webapp context settings: " + _jettyXml);
97 }
98 }
99 }
100
101 }