1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.deploy.providers;
20
21 import java.io.File;
22 import java.io.FilenameFilter;
23 import java.util.Locale;
24
25 import org.eclipse.jetty.deploy.App;
26 import org.eclipse.jetty.deploy.ConfigurationManager;
27 import org.eclipse.jetty.deploy.util.FileID;
28 import org.eclipse.jetty.server.handler.ContextHandler;
29 import org.eclipse.jetty.util.resource.Resource;
30 import org.eclipse.jetty.xml.XmlConfiguration;
31
32
33
34
35
36
37 public class ContextProvider extends ScanningAppProvider
38 {
39 private ConfigurationManager _configurationManager;
40
41 public ContextProvider()
42 {
43 super( new FilenameFilter()
44 {
45 public boolean accept(File dir, String name)
46 {
47 if (!dir.exists())
48 return false;
49 String lowername = name.toLowerCase(Locale.ENGLISH);
50 if (lowername.startsWith("."))
51 return false;
52
53 return (lowername.endsWith(".xml") && !new File(dir,name).isDirectory());
54 }
55 });
56 }
57
58
59
60 public ConfigurationManager getConfigurationManager()
61 {
62 return _configurationManager;
63 }
64
65
66
67
68
69 public void setConfigurationManager(ConfigurationManager configurationManager)
70 {
71 _configurationManager = configurationManager;
72 }
73
74
75 public ContextHandler createContextHandler(App app) throws Exception
76 {
77 Resource resource = Resource.newResource(app.getOriginId());
78 File file = resource.getFile();
79
80 if (resource.exists() && FileID.isXmlFile(file))
81 {
82 XmlConfiguration xmlc = new XmlConfiguration(resource.getURL());
83
84 xmlc.getIdMap().put("Server",getDeploymentManager().getServer());
85 if (getConfigurationManager() != null)
86 xmlc.getProperties().putAll(getConfigurationManager().getProperties());
87 return (ContextHandler)xmlc.configure();
88 }
89
90 throw new IllegalStateException("App resouce does not exist "+resource);
91 }
92
93 }