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      private WebAppContext _context;
33  
34      
35      /**
36       * @see Configuration#setWebAppContext
37       */
38      public void setWebAppContext (WebAppContext context)
39      {
40         _context = context;
41      }
42  
43      public WebAppContext getWebAppContext ()
44      {
45          return _context;
46      }
47      
48      /** configureClassPath
49       * Not used.
50       * @see Configuration#configureClassLoader
51       */
52      public void configureClassLoader () throws Exception
53      {
54      }
55  
56      /** configureDefaults
57       * Not used.
58       * @see Configuration#configureDefaults
59       */
60      public void configureDefaults () throws Exception
61      {
62      }
63  
64      /** configureWebApp
65       * Apply web-jetty.xml configuration
66       * @see Configuration#configureWebApp()
67       */
68      public void configureWebApp () throws Exception
69      {
70          //cannot configure if the _context is already started
71          if (_context.isStarted())
72          {
73              if (Log.isDebugEnabled()){Log.debug("Cannot configure webapp after it is started");}
74              return;
75          }
76          
77          if(Log.isDebugEnabled())
78              Log.debug("Configuring web-jetty.xml");
79          
80          Resource web_inf=getWebAppContext().getWebInf();
81          // handle any WEB-INF descriptors
82          if(web_inf!=null&&web_inf.isDirectory())
83          {
84              // do jetty.xml file
85              Resource jetty=web_inf.addPath("jetty6-web.xml");
86              if(!jetty.exists())
87                  jetty=web_inf.addPath("jetty-web.xml");
88              if(!jetty.exists())
89                  jetty=web_inf.addPath("web-jetty.xml");
90  
91              if(jetty.exists())
92              {
93                  // No server classes while configuring 
94                  String[] old_server_classes = _context.getServerClasses();
95                  try
96                  {
97                      _context.setServerClasses(null);
98                      if(Log.isDebugEnabled())
99                          Log.debug("Configure: "+jetty);
100                     XmlConfiguration jetty_config=new XmlConfiguration(jetty.getURL());
101                     jetty_config.configure(getWebAppContext());
102                 }
103                 finally
104                 {
105                     if (_context.getServerClasses()==null)
106                         _context.setServerClasses(old_server_classes);
107                 }
108             }
109         }
110     }
111     
112     
113     /** deconfigureWebApp
114      * @see Configuration#deconfigureWebApp()
115      */
116     public void deconfigureWebApp () throws Exception
117     {
118     
119     }
120     
121 }