View Javadoc

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  /** Context directory App Provider.
14   * <p>This specialization of {@link ScanningAppProvider} is the
15   * replacement for the old (and deprecated) <code>org.eclipse.jetty.deploy.ContextDeployer</code> and it will scan a directory
16   * only for context.xml files.
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                  return  (lowername.endsWith(".xml") && !new File(dir,name).isDirectory());
32              }
33          });
34      }
35  
36  
37      /* ------------------------------------------------------------ */
38      public ConfigurationManager getConfigurationManager()
39      {
40          return _configurationManager;
41      }
42      
43      /* ------------------------------------------------------------ */
44      /** Set the configurationManager.
45       * @param configurationManager the configurationManager to set
46       */
47      public void setConfigurationManager(ConfigurationManager configurationManager)
48      {
49          _configurationManager = configurationManager;
50      }
51  
52      /* ------------------------------------------------------------ */
53      public ContextHandler createContextHandler(App app) throws Exception
54      {
55          Resource resource = Resource.newResource(app.getOriginId());
56          File file = resource.getFile();
57          
58          if (resource.exists() && FileID.isXmlFile(file))
59          {
60              XmlConfiguration xmlc = new XmlConfiguration(resource.getURL());
61              
62              xmlc.getIdMap().put("Server",getDeploymentManager().getServer());
63              if (getConfigurationManager() != null)
64                  xmlc.getProperties().putAll(getConfigurationManager().getProperties());
65              return (ContextHandler)xmlc.configure();
66          }
67          
68          throw new IllegalStateException("App resouce does not exist "+resource);
69      }
70      
71  }