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