View Javadoc

1   // ========================================================================
2   // Copyright (c) 2000-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.webapp;
15  
16  import org.eclipse.jetty.util.log.Log;
17  import org.eclipse.jetty.util.resource.Resource;
18  import org.eclipse.jetty.xml.XmlConfiguration;
19  
20  
21  /**
22   * 
23   * JettyWebConfiguration.
24   * 
25   * Looks for Xmlconfiguration files in WEB-INF.  Searches in order for the first of jetty6-web.xml, jetty-web.xml or web-jetty.xml
26   *
27   * 
28   *
29   */
30  public class JettyWebXmlConfiguration implements Configuration
31  {
32      public void preConfigure(WebAppContext context) throws Exception
33      {
34          // TODO Auto-generated method stub
35          
36      }
37  
38      
39      /** 
40       * Configure
41       * Apply web-jetty.xml configuration
42       * @see Configuration#configure(WebAppContext)
43       */
44      public void configure (WebAppContext context) throws Exception
45      {
46          //cannot configure if the _context is already started
47          if (context.isStarted())
48          {
49              if (Log.isDebugEnabled()){Log.debug("Cannot configure webapp after it is started");}
50              return;
51          }
52          
53          if(Log.isDebugEnabled())
54              Log.debug("Configuring web-jetty.xml");
55          
56          Resource web_inf = context.getWebInf();
57          // handle any WEB-INF descriptors
58          if(web_inf!=null&&web_inf.isDirectory())
59          {
60              // do jetty.xml file
61              Resource jetty=web_inf.addPath("jetty7-web.xml");
62              if(!jetty.exists())
63                  jetty=web_inf.addPath("jetty-web.xml");
64              if(!jetty.exists())
65                  jetty=web_inf.addPath("web-jetty.xml");
66  
67              if(jetty.exists())
68              {
69                  // No server classes while configuring 
70                  String[] old_server_classes = context.getServerClasses();
71                  try
72                  {
73                      context.setServerClasses(null);
74                      if(Log.isDebugEnabled())
75                          Log.debug("Configure: "+jetty);
76                      XmlConfiguration jetty_config=new XmlConfiguration(jetty.getURL());
77                      jetty_config.configure(context);
78                  }
79                  finally
80                  {
81                      if (context.getServerClasses()==null)
82                          context.setServerClasses(old_server_classes);
83                  }
84              }
85          }
86      }
87      
88      
89      public void postConfigure(WebAppContext context) throws Exception
90      {
91          // TODO Auto-generated method stub
92          
93      }
94  
95  
96      public void deconfigure(WebAppContext context) throws Exception
97      {
98          // TODO Auto-generated method stub
99          
100     } 
101 }